	//Cria uma variavel booleana para verificar se existe uma instância IE válida
var xmlhttp	= false;
//verifica se esta usando IE

try{
	//se a versão Js é maior q a 5
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	//alert('Você esta usando IE');
}catch(e){
	//se não, usa o object active x mais antigo
	try{
		//Se estiver usando IE
		xmlhttp	= new ActiveXObject("Microsoft.XMLHTTP");
		//alert('Você esta usando IE');
	}catch (E){
		// Ou devemos star usando um navegador que não eh o IE
		xmlhttp = false;
	}
}
// Se não estiver usando IE, cria uma instância JS
if(!xmlhttp && typeof XMLHttpRequest != "undefined"){
	xmlhttp = new XMLHttpRequest();
	//alert('Você NÃO esta usando IE');
}

var ajax = {
	excluirImagem : function(img){

		//alert(img);
		xmlhttp.open('GET','__controler/clnewsletter.php?acao=excluirImagem&img='+img,true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 1) document.getElementById('miniGaleria').innerHTML = "Carregando..."
			//if(xmlhttp.readyState == 1) document.getElementById('miniGaleria').innerHTML = "<img src='__img/loading.gif' />";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('miniGaleria').innerHTML = xmlhttp.responseText;
					}else{
						document.getElementById('miniGaleria').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	InsereCategoria : function(cat_nome){
		num = 0;
		
		var fileDIV = document.createElement('div');
		
		xmlhttp.open('GET','__controler/clprodutoscategoria.php?acao=InsereCategoria&cat_nome='+ cat_nome,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) document.getElementById('categoria_campos').innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						
							fileDIV.setAttribute("div", fileID);
							fileDIV.innerHTML = xmlhttp.responseText;
						document.getElementById('categoria_campos').appendChild();
						num += 1;
					}else{
						document.getElementById('categoria_campos').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	
	DeletaCategoria : function(cat_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) document.getElementById('cat_id').innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						cat_id.style.display = 'none';
					}else{
						cat_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	DeletaEstados : function(est_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) document.getElementById('est_id').innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						est_id.style.display = 'none';
					}else{
						est_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	
	DeletaFoto : function(fot_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) fot_id.innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						fot_id.style.display = 'none';
					}else{
						fot_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	DeletaConteudo : function(fot_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) fot_id.innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						fot_id.style.display = 'none';
					}else{
						fot_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	DeletaCidades : function(fot_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) fot_id.innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						fot_id.style.display = 'none';
					}else{
						fot_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	DeletaLojas : function(loj_id,pagina){
		xmlhttp.open('GET',pagina,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) loj_id.innerHTML = "Processando...";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						loj_id.style.display = 'none';
					}else{
						loj_id.innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	MostraDescricao: function(fot_id){
		xmlhttp.open('GET','admin/__controler/clprodutosfotos.php?acao=MostraFoto&foto_id='+fot_id,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) document.getElementById('mais-info').innerHTML = "<img src='http://www.sanny.ind.br/site/imgs/loader.gif' />";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						setTimeout(function(){
							document.getElementById('mais-info').innerHTML = xmlhttp.responseText;					
						}, 10000);
						
					}else{
						document.getElementById('mais-info').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	SelecionaEstados: function(est_id){
		xmlhttp.open('GET','admin/__controler/cllojas.php?acao=SelecionaEstados&est_id='+est_id,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			//if(xmlhttp.readyState == 1) document.getElementById('select_cidades').innerHTML = "<option>Carregando...</option>";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('select_cidades').innerHTML = xmlhttp.responseText;					
					}else{
						document.getElementById('select_cidades').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	SelecionaCidade: function(est_id){
		xmlhttp.open('GET','admin/__controler/cllojas.php?acao=SelecionaCidade&est_id='+est_id,true);
		xmlhttp.onreadystatechange = function(){
			//if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='loading.gif' />"
			if(xmlhttp.readyState == 1) document.getElementById('Lojas').innerHTML = "<img src='http://www.sanny.ind.br/site/imgs/loader.gif' style='margin-lerf:20px;' />";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('Lojas').innerHTML = xmlhttp.responseText;					
					}else{
						document.getElementById('Lojas').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	},
	
	FazPaginacao : function(p,tipo){
		xmlhttp.open('GET','admin/__controler/cllojas.php?acao=fazPaginacao&p='+p+'&est_id='+tipo,true);

		xmlhttp.onreadystatechange = function(){

		if(xmlhttp.readyState == 1) document.getElementById('Lojas').innerHTML = "<img src='http://www.sanny.ind.br/site/imgs/loader.gif' style='margin-lerf:20px;' />";

			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('Lojas').innerHTML = xmlhttp.responseText;
					}else{
						document.getElementById('Lojas').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}

		}
		xmlhttp.send(null);
	},
	ConteudoPaginacao : function(p){
		xmlhttp.open('GET','admin/__controler/clsaladeconteudo.php?acao=fazPaginacao&p='+p,true);

		xmlhttp.onreadystatechange = function(){

		if(xmlhttp.readyState == 1) document.getElementById('conteudo_t').innerHTML = "<img src='http://www.sanny.ind.br/site/imgs/loader.gif' style='margin-lerf:20px;' />";

			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('conteudo_t').innerHTML = xmlhttp.responseText;
					}else{
						document.getElementById('conteudo_t').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}

		}
		xmlhttp.send(null);
	},
	MostraFoto : function(fot_id){
		xmlhttp.open('GET','admin/__controler/clprodutosfotos.php?acao=MostraFoto&foto_id='+fot_id,true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 1) document.getElementById('altura').innerHTML = "<img src='http://www.sanny.ind.br/site/imgs/loading.gif' />";
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText){
						document.getElementById('mfzoom').innerHTML = '__imgs/colecao/grande/'+ xmlhttp.responseText;
						document.getElementById('foto_g_zoom').innerHTML = '__imgs/colecao/grande/'+ xmlhttp.responseText;
					}else{
						document.getElementById('preview').innerHTML = "Nenhum resultado encontrado!";
					}
				}
			}
		}
		xmlhttp.send(null);
	}
}
