// JavaScript Document
setTimeout("window.location.reload()", 600000);

function abreMenu(titulo, tag){
	var x = document.getElementsByTagName(tag);
	
	for(var i = 0; i < x.length; i++){
		if(x[i].title == "sub" + titulo){
			if(x[i].style.display == "none"){
				x[i].style.display = "block";
			}else{
				x[i].style.display = "none";
			}
		}
	}
	
	//Efetua a abertura das tags <br />
	if(tag == "a"){
		abreMenu(titulo, "br");
	}
}

function newBox(tag, titulo, titleA){
	var x = document.getElementsByTagName("div");
	for(var i = 0; i < x.length; i++){
		if(x[i].title == titleA){
			x[i].style.position = "relative";
		}
	}
	
	x = document.getElementsByTagName(tag);
	for(var i = 0; i < x.length; i++){
		if(x[i].title == titulo){
			x[i].style.display = "block";
		}
	}
}

function apagaBox(tag, titulo, titleA){
	var x = document.getElementsByTagName("div");
	for(var i = 0; i < x.length; i++){
		if(x[i].title == titleA){
			x[i].style.position = "static";
		}
	}
	
	x = document.getElementsByTagName(tag);
	for(var i = 0; i < x.length; i++){
		if(x[i].title == titulo){
			x[i].style.display = "none";
		}
	}
}

function runAjax(id, url){
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(err1){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(err2){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(err3){
				xmlhttp = false;
				if(err3){
					alert("Desculpe! Mais o seu browser não suporta todas as funcionalidades dessa página.");
				}
			}
		}
	}
	
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var retorno = xmlhttp.responseText;
			document.getElementById(id).value = retorno;
		}
	}
	
	xmlhttp.send(null);
	return false;
}

function validaForm(tipoCampo){
	var x = document.getElementsByTagName(tipoCampo);
	for(var i = 0; i < x.length; i++){
		if(x[i].title != ""){
			if(x[i].value == ""){
				alert("Por favor, preencha o campo " + x[i].title + " corretamente.");
				x[i].focus();
				return false;
			}
		}
	}
	
	if(tipoCampo == "input"){
		if(document.formCadastro){
			with(document.formCadastro){
				if(txtSenha){
					if(txtSenha.value != txtConfirma.value){
						alert("O campo Confirmar Senha deve ser igual ao Campo Senha!");
						txtConfirma.focus();
						return false;
					}
				}
			}
		}
	}
	
	if(tipoCampo == "input") return validaForm("select");
	if(tipoCampo == "select") return validaForm("textarea");
}

function formatCNPJ(id){
	var cnpj = document.getElementById(id).value;
	cnpj = cnpj.replace(/\./gi, "");
	cnpj = cnpj.replace(/\//gi, "");
	cnpj = cnpj.replace(/\-/gi, "");

	var x = document.getElementById(id);
	x.value = cnpj.substr(0, 2) + "." + cnpj.substr(2, 3) + "." + cnpj.substr(5, 3) + "/" + cnpj.substr(8, 4) + "-" + cnpj.substr(12, 2);
}

function validaCNPJ(id){
	var cnpj = document.getElementById(id).value;
	cnpj = cnpj.replace(/\./gi, "");
	cnpj = cnpj.replace(/\//gi, "");
	cnpj = cnpj.replace(/\-/gi, "");
	var nonNumbers = /\D/;
	if (nonNumbers.test(cnpj)){
		alert("A verificação de CNPJ suporta apenas números");
		document.getElementById(id).focus();
	}
	var verificador = cnpj.substr(0, cnpj.length - 2);
	var arVerifica = [];
	var peso = 5;
	var confirmaDados = false;
	var resultadoFinal = new Number;
	for(var o = 1; o < 3; o++){
		for(var i = 0; i < verificador.length; i++){
			arVerifica[i] = Number(verificador.substr(i, 1)) * peso;
			if(confirmaDados){
				peso = 10;
				confirmaDados = false;
			}
			peso--;
			if(peso == 2) confirmaDados = true;
		}
		for(var i = 0; i < arVerifica.length; i++){
			resultadoFinal = resultadoFinal + arVerifica[i];
		}
		resultadoFinal = resultadoFinal % 11;
		if(resultadoFinal < 2) resultadoFinal = 0;
		if(resultadoFinal > 2) resultadoFinal = 11 - resultadoFinal;
		if(String(resultadoFinal) != cnpj.substr(verificador.length, 1)){
			alert("Você deve digitar um CNPJ válido!");
			document.getElementById(id).focus();
			return false;
			break;
		}
		peso = 6;
		verificador = cnpj.substr(0, cnpj.length - 1);
		resultadoFinal = 0;
	}
	
	var x = document.getElementById(id);
	x = cnpj.substr(0, 2) + "." + cnpj.substr(2, 3) + "." + cnpj.substr(5, 3) + "/" + cnpj.substr(8, 4) + "-" + cnpj.substr(12, 2);
}

function openPop(url){
	window.open(url, "newSite", "directories=no, height=200, left=20, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, top=20, width=300");
}