// _________________________________________________________________________________________
// || Código JAVASCRIPT Desenvolvido por CoringaDesign.com - Todos os Direitos Reservados ||
// || ----------------------------------------------------------------------------------- ||
// || Tecnologia utilizada: PHP, MySQL, JavaScript Assíncrono (AJAX)                      ||
// || Direitos de Uso     : Soltege Soluções em Informática                               ||
// || Distribuição        : Soltege Soluções em Informática, FCDL-MG, CoringaDesign       ||
// || ----------------------------------------------------------------------------------- ||
// ||         CoringadeDesign - A Qualidade em Seu Site - www.coringadesign.com           ||
// ||                          contato:rodrigo@coringadesign.com                          ||
// ||_____________________________________________________________________________________||
try{
    xmlhttp = new XMLHttpRequest();// Mozilla, Safari, Firefox, etc...
    try {
        if (xmlhttp.overrideMimeType) {
            //Se possível, ignora cabecalho usado pelo servidor e forca o padrao "text/xml". Alguns navegadores exigem esse padrao e pode dar erro se o servidor nao utilizar ele
            xmlhttp.overrideMimeType('text/xml');
        }
    } catch (e1) { }
}catch(e2){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");// Internet Explorer
    }catch(e3){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");// Internet Explorer
        }catch(e4){
            //tratamento para alguma outra forma de implementar XMLHTTP
            xmlhttp = false;
        }
    }
}
if (!xmlhttp){
    //Nao conseguiu instanciar o objeto xmlhttp para fazer as solicitacoes
    alert("Erro no AJAX. Seu navegador não dá suporte ao AJAX. Recomendamos usar o Internet Explorer para Windows");
}

/////////////////////////////////////////////////////////////
//	Função Automatiza AJAX
////////////////////////////////////////////////////////////
function getxmlhttp(){
var xmlhttp = false;
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
					
	
			
		}
	}
if (!xmlhttp && typeof XMLHttpRequest !='undefined') {
	xmlhttp = new XMLHttpRequest();
			
	}
return xmlhttp;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function processajax (obj, serverPage){
	
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage);
	xmlhttp.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
	xmlhttp.setRequestHeader("Cache-Control", "no-cache");
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			   // coloca o valor no objeto requisitado
            texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
            document.getElementById(obj).innerHTML=texto;
            // executa scripts
            extraiScript(texto);

			document.getElementById(obj).innerHTML = xmlhttp.responseText;
			
		}
	}
	xmlhttp.send(null);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
function extraiScript(texto){

    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
    
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}

///////////////////////////////////////////////
//Funções do Formulario de Cadastro
//Necessita de Spry
///////////////////////////////////////////////
checkdomain = function(valor){
	valor = document.getElementById('dominio').value+'.'+document.getElementById('extensao').value;
	local = "/scripts/checkdomain.php?dominio="+valor;
	processajax('result',local);
}
some = function(){
	setTimeout("apagadiv()",5000);
}
apagadiv = function(){
	document.getElementById('result').innerHTML ='';
}
visu = function(valor){
	
	 if(valor=='cpf'){
		 document.getElementById('bcpf').style.display = 'block';
		 document.getElementById('bcnpj').style.display = 'none';
	 }else{
		 document.getElementById('bcpf').style.display = 'none';
		 document.getElementById('bcnpj').style.display = 'block';
	 }
	 document.getElementById('tcpf').value ='';
	 document.getElementById('tcnpj').value ='';
	 setTimeout("document.getElementById('result_cnpj').innerHTML=''",300);
}


vdoc = function(valor,tipo){
	if(valor!=''){
	local = '/scripts/confirmcnpj.php?mode='+tipo+'&valor='+valor;
	processajax('result_cnpj',local);
	}
}
vercep = function(valor){
	document.getElementById('endereco').value = 'Aguarde... verificando CEP';
	if(valor!=''){
		local = '/scripts/ceps.php?cep='+valor;
		processajax('result_cnpj',local);
	}
}
selcidade = function(valor){
	document.getElementById('divcity').innerHTML = '<select  style="width:300px"><option>Aguarde... selecionando cidades</option></select>';
	local = '/scripts/selcidade.php?idref='+valor;
	processajax('divcity',local);
	
	
}
vermail =function(valor){
	local = '/scripts/vermail.php?email='+valor;
	processajax('result_mail',local);
}
///////////// FIM DO FORMULARIO DE CADASTRO //////////////////////
// Carregando Pagina
var img_interval;
function erase() {
document.getElementById("loading_text").style.display = "none";
document.getElementById("loading_parent").style.display = "none";

}

function startCheck() {
img_interval = setInterval("checkImages()", 10); 

}
function checkImages() {
	document.getElementById('carregar').style.display = "block";
	
var imgs = document.getElementsByTagName("img"); 
var total = imgs.length;

var num_loaded = 0;
var i;
for(i=0; i<total; i++) {
if(imgs[i].complete) 
num_loaded++; 
}
var per_cent = (num_loaded / total) * 100;   
var per_cent = Math.round(per_cent);
document.getElementById("loading_bar").style.width = per_cent + "%"; 
//setTimeout("esconder_div()", 1);
esconder_div(per_cent);
if(num_loaded == total) {
clearInterval(img_interval);

document.getElementById("loading_text").innerHTML = "completo";
document.getElementById('carregar').style.display = "none";

setTimeout("erase()", 1000);
} else {
document.getElementById("loading_text").innerHTML = per_cent+"%";
}
}


// valor inicial do filtro no div
var valor = 100;

function esconder_div(val) {

// a cada refresh na função diminui 1% no filtro
valor=100-val;

// quando o valor chegar a 9, esconde a div
if(valor == 0) {
valor = 1;
document.getElementById("carregar").style.display="none";
return false;
}

// 1 é o tempo em milisegundos de atualização do fade


document.getElementById("carregar").style.filter = "alpha(opacity="+valor+");";
document.getElementById("carregar").style.opacity = "."+valor+"";

}
/////////////////////////////////////////////////////////////////