var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-2292081-2");
pageTracker._trackPageview();
} catch(err) {}

// Verifica forms
function verificacao(nomeForm){

var msgBranco = "Favor preencher o campo";//Mensagem para campos vazios
var msgBrancoRadio = "Favor selecionar o campo";//Mensagem para radio buttons
var msgEmail = "com um e-mail válido";
var msgNumero = "Somente com números";
var msgCPF = "com um CPF válido";
var msgCEP = "com um CEP válido";
var msgCNPJ = "com um CNPJ válido";
var msgFone = "com um telefone válido";
var msgCaracteres = "com no mínimo";
var msgLink = "com um link válido";
var msgData = "com uma data válida";
var msgCkecked = "Favor selecionar ao menos uma opção do campo";
var msgHora = "com uma hora válida";
var msgCompara1 = "O campo";
var msgCompara2 = "deve ser idêntico ao campo";
var msgArquivo1 = "O nome de arquivo no campo"
var msgArquivo2 = "não pode conter espaços ou acentos"
var msgFormato1 = "O formato de arquivo no campo"
var msgFormato2 = "deve ser"

fv = document.getElementById(nomeForm);

for(q=0;q<fv.length;q++){
	if(fv[q].getAttribute("verificar")!='' && fv[q].getAttribute("verificar")!=undefined ){
		if(fv[q].value==''){
			alert(msgBranco+' "'+fv[q].getAttribute("verificar")+'".');
			fv[q].focus();
			return false;
		}
		if(fv[q].getAttribute("type")=='checkbox' || fv[q].getAttribute("type")=='radio'){
			h=0;
			for(y=1;y<=fv[q].getAttribute("quantCampos");y++){
					if(fv[q+y-1].checked==false){
						h++
					}
			}
			if(h==fv[q].getAttribute("quantCampos")){
				if(fv[q].getAttribute("type")=='checkbox'){
					alert(msgCkecked+' "'+fv[q].getAttribute("verificar")+'".');
				}else{
					alert(msgBrancoRadio+' "'+fv[q].getAttribute("verificar")+'".');
				}
				fv[q].focus();
				return false;	
			}
		}
	}
	if(fv[q].getAttribute("email")!=undefined && fv[q].value!=""){
		formatoEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(fv[q].value)
		if(formatoEmail==false ){
			alert(msgBranco+' "'+fv[q].getAttribute("email")+'" ' + msgEmail+'.');
			fv[q].focus();
			return false;
		}
	}
	if (fv[q].getAttribute("numero")!=undefined && fv[q].value!=""){
		if((fv[q].value * 0)!=0){					
			alert(msgBranco+'"'+fv[q].getAttribute("numero")+'" '+msgNumero+'.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("cpf")!=undefined && fv[q].value!=""){
		valorCPF = String(fv[q].value).replace(/\D/g,"");
		if(valorCPF.length!=11){
			alert(msgBranco +' "' + fv[q].getAttribute("cpf") + '" '+ msgCPF+'.');
			fv[q].focus();
			return false;
		}
		var i; 
		s = valorCPF; 
		var c = s.substr(0,9); 
		var dv = s.substr(9,2); 
		var d1 = 0; 
		for (i = 0; i < 9; i++){ 
			d1 += c.charAt(i)*(10-i); 
		} 
		if (d1 == 0){ 
			alert(msgBranco +' "' + fv[q].getAttribute("cpf") + '" '+ msgCPF+'.');
			fv[q].focus();
			return false;
		} 
		d1 = 11 - (d1 % 11); 
		if (d1 > 9){d1 = 0}; 
		if (dv.charAt(0) != d1){ 
			alert(msgBranco +' "' + fv[q].getAttribute("cpf") + '" '+ msgCPF+'.');
			fv[q].focus();
			return false;
		}
		d1 *= 2; 
		for (i = 0; i < 9; i++){ 
			d1 += c.charAt(i)*(11-i); 
		} 
		d1 = 11 - (d1 % 11); 
		if (d1 > 9) {d1 = 0}; 
		if (dv.charAt(1) != d1){ 
			alert(msgBranco +' "' + fv[q].getAttribute("cpf") + '" '+ msgCPF+'.');
			fv[q].focus();
			return false; 
		} 
	}
	if(fv[q].getAttribute("cep")!=undefined && fv[q].value!=""){
		valorCEP = String(fv[q].value).replace(/[.-]/g,"");
		if(valorCEP.length!=8){
			alert(msgBranco+' "'+fv[q].getAttribute("cep")+'" '+msgCEP+'.');
			fv[q].focus();
			return false;
		}
		if(valorCEP == "00000000" || valorCEP == "11111111" || valorCEP == "22222222" || valorCEP == "33333333" || valorCEP == "44444444" || valorCEP == "55555555" || valorCEP == "66666666" || valorCEP == "77777777" || valorCEP == "88888888" || valorCEP == "99999999"){
			alert(msgBranco+' "'+fv[q].getAttribute("cep")+'" '+msgCEP+'.');
			fv[q].focus();
			return false;	
		}
		if((valorCEP.charAt(0)==valorCEP.charAt(2) && valorCEP.charAt(1)==valorCEP.charAt(3) && valorCEP.charAt(2)==valorCEP.charAt(4))){
			alert(msgBranco+' "'+fv[q].getAttribute("cep")+'" '+msgCEP+'.');
			fv[q].focus();
			return false;	
		}
	}
	if(fv[q].getAttribute("cnpj")!=undefined && fv[q].value!=""){
		valorCNPJ = String(fv[q].value).replace(/\D/g,"");
		if(valorCNPJ.length!=14){
			alert(msgBranco+' "'+fv[q].getAttribute("cnpj")+'" '+msgCNPJ+'.');
			fv[q].focus();
			return false;
		}
		a = [];
		b = new Number;
		c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		for (i=0; i<12; i++){
			a[i] = valorCNPJ.charAt(i);
			b += a[i] * c[i+1];
		}
		if ((x = b % 11) < 2){
			a[12] = 0
		}else{ 
			a[12] = 11-x 
		}
		b = 0;
		for (y=0; y<13; y++){
			b += (a[y] * c[y]);
		}
		if ((x = b % 11) < 2){ 
			a[13] = 0; 
		}else{ 
			a[13] = 11-x; 
		}
		if((valorCNPJ.charAt(12) != a[12]) || (valorCNPJ.charAt(13) != a[13])){
			alert(msgBranco+' "'+fv[q].getAttribute("cnpj")+'" '+msgCNPJ+'.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("fone")!=undefined && fv[q].value!=""){
		valorFone = String(fv[q].value).replace(/\D/g,"");
		if((/[a-z]/g).test(valorFone)==true){
			alert(msgBranco+' "'+fv[q].getAttribute("fone")+'" '+msgFone+'.');
			fv[q].focus();
			return false;	
		}
		if(valorFone == "0000000000" || valorFone == "1111111111" || valorFone == "2222222222"|| valorFone == "3333333333" || valorFone == "4444444444" || valorFone == "5555555555" || valorFone == "6666666666" || valorFone == "7777777777" || valorFone == "8888888888" || valorFone == "9999999999"){
			alert(msgBranco+' "'+fv[q].getAttribute("fone")+'" '+msgFone+'.');
			fv[q].focus();
			return false;	
		}
		if((valorFone.charAt(0)==valorFone.charAt(2) && valorFone.charAt(1)==valorFone.charAt(3) && valorFone.charAt(2)==valorFone.charAt(4) &&valorFone.charAt(3)==valorFone.charAt(5) && valorFone.charAt(4)==valorFone.charAt(6))){
			alert(msgBranco+' "'+fv[q].getAttribute("fone")+'" '+msgFone+'.');
			fv[q].focus();
			return false;	
		}
	}
	if(fv[q].getAttribute("caracteres")!=undefined && fv[q].value!=""){
		numeroCaractere = fv[q].getAttribute("quantCaracteres");
		valorCaractere = String(fv[q].value).replace(/[ ]/g,"");
		if(valorCaractere.length<numeroCaractere){
			alert(msgBranco+' "'+fv[q].getAttribute("caracteres")+'" '+msgCaracteres+' "'+fv[q].getAttribute("quantCaracteres")+'" caracteres.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("link")!=undefined && fv[q].value!=""){
		testeURL_a = /^http:\/\//;
		testeURL_b = /^https:\/\//;
		testeURL_c = /[^a-z:\/\/]/g;
		if(testeURL_a.test(fv[q].value)==false || testeURL_b.test(fv[q].value)==false && testeURL_c.test(fv[q].value)==true){
			alert(msgBranco+' "'+fv[q].getAttribute("link")+'" '+msgLink+'.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("data")!=undefined && fv[q].value!=""){
		valorData = String(fv[q].value).replace(/\D/g,"");
		dataTeste_a = valorData.charAt(0) + valorData.charAt(1);
		dataTeste_b = valorData.charAt(2) + valorData.charAt(3);
		dataTeste_c = valorData.charAt(4) + valorData.charAt(5) + valorData.charAt(6) + valorData.charAt(7);
		dataTesteBi = dataTeste_c / 4;
		if(dataTeste_b>12){
			alert(msgBranco+' "'+fv[q].getAttribute("data")+'" '+msgData+'.');
			fv[q].focus();
			return false;
		}
		if(dataTeste_b==01 || dataTeste_b==03 || dataTeste_b==05 || dataTeste_b==07 || dataTeste_b==08 || dataTeste_b==10 || dataTeste_b==12){
			valorMes=31
		}
		if(dataTeste_b==04 || dataTeste_b==06 || dataTeste_b==09 || dataTeste_b==11){
			valorMes=30
		}
		if(dataTeste_b==02){
			if((/\D/g).test(dataTesteBi)==false){
				valorMes=29;
			}else{
				valorMes=28;
			}
		}
		dataTeste_c = /-/g;
		if(dataTeste_a>valorMes || dataTeste_c.test(fv[q].value)==true){
			alert(msgBranco+' "'+fv[q].getAttribute("data")+'" '+msgData+'.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("hora")!=undefined && fv[q].getAttribute("hora")!="" && fv[q].value!=""){//hora
		valorHora = String(fv[q].value).replace(/\D/g,"");
		horaTeste_a = valorHora.charAt(0) + valorHora.charAt(1);
		horaTeste_b = valorHora.charAt(2) + valorHora.charAt(3);
		horaTeste_c = /-/g;
		if(horaTeste_a>24 || horaTeste_b>59 || horaTeste_c.test(fv[q].value)==true){
			alert(msgBranco+' "'+fv[q].getAttribute("hora")+'" '+msgHora+'.');
			fv[q].focus();
			return false;
		}
	}
	if(fv[q].getAttribute("verificaNomeArquivo")!=undefined && fv[q].getAttribute("verificaNomeArquivo")!="" && fv[q].value!=""){//hora
		var arq = fv[q].value.split("\\")
		var nome = arq[arq.length-1]
		if(nome.split(" ").length > 1){
			alert(msgArquivo1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " " + msgArquivo2 + ".")
			fv[q].focus();
			return false;
		}
		var ext = nome.split(".")
		switch(fv[q].getAttribute("formato")){
			case "audio":
				if(ext[ext.length-1].toLowerCase()!="mp3"){
					alert(msgFormato1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " " + msgFormato2 + " mp3.")
					fv[q].focus();
					return false;
				}
				break;
			case "video":
				if(ext[ext.length-1].toLowerCase()!="flv"){
					alert(msgFormato1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " " + msgFormato2 + " mp3.")
					fv[q].focus();
					return false;
				}
				break;
			case "arquivo":
				if(ext[ext.length-1].toLowerCase()=="exe" || ext[ext.length-1].toLowerCase()=="bat" || ext[ext.length-1].toLowerCase()=="dll" || ext[ext.length-1].toLowerCase()=="vbs" || ext[ext.length-1].toLowerCase()=="scr"){
					alert(msgFormato1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " não " + msgFormato2 + " " + ext[ext.length-1].toLowerCase() + ".")
					fv[q].focus();
					return false;
				}
				break;
			case "imagem":
				if(ext[ext.length-1].toLowerCase()!="jpg" && ext[ext.length-1].toLowerCase()!="gif"){
					alert(msgFormato1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " " + msgFormato2 + " jpg ou gif.")
					fv[q].focus();
					return false;
				}
				break;
		}
		acentos = /[áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÅÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ=+^~&%$#@]/
		if(nome.search(acentos)!=-1){
			alert(msgArquivo1 + " " + fv[q].getAttribute("verificaNomeArquivo") + " " + msgArquivo2 + ".")
			fv[q].focus();
			return false;
		}			
	}
	if(fv[q].getAttribute("comparar")!=undefined && fv[q].getAttribute("comparar")!="" && fv[q].value!=""){
		campoComp = fv[q].getAttribute("campo")
		switch(fv[q].getAttribute("modoComparar")){
		case "maior":
			if(fv[q].value < document.getElementById(campoComp).value){
				alert(msgCompara1+' "'+fv[q].getAttribute("comparar")+'" '+msgCompara2+' "'+document.getElementById(campoComp).getAttribute("nomeComparar")+'".');
				fv[q].focus();
				return false;
			}			
			break;
		case "menor":
			if(fv[q].value > document.getElementById(campoComp).value){
				alert(msgCompara1+' "'+fv[q].getAttribute("comparar")+'" '+msgCompara2+' "'+document.getElementById(campoComp).getAttribute("nomeComparar")+'".');
				fv[q].focus();
				return false;
			}			
			break;
		case "igual":
			if(fv[q].value != document.getElementById(campoComp).value){
				alert(msgCompara1+' "'+fv[q].getAttribute("comparar")+'" '+msgCompara2+' "'+document.getElementById(campoComp).getAttribute("nomeComparar")+'".');
				fv[q].focus();
				return false;
			}		
			break;		
		}

	}
}}


function mascaras(id,tipo,parametro){

campo = document.getElementById(id);
switch(tipo){
	case 'numeros':	
		valorCampoSomenteNumeros = String(campo.value).replace(/\D/g,"");
		if((/\D/g).test(campo.value)==true){
			campo.value = valorCampoSomenteNumeros;
		}
		break;
	case 'naoLetras':
		valorLetras = String(campo.value).replace(/[a-zA-Z]/g,"")
		if(window.event && (/[a-z]/gi).test(campo.value)==true){
				campo.value = valorLetras;
		}
		break;
	case 'cep':
		if(campo.value.length==5){
			campo.value = campo.value+'-';
		}
		break;
	case 'cpf':
		switch(campo.value.length){
			case 3:
				campo.value = campo.value+'.';
				break;
			case 7:
				if(campo.value.charAt(3)=='.'){
					campo.value = campo.value+'.';
				}
				break;
			case 11:
				if(campo.value.charAt(3)=='.' && campo.value.charAt(7)=='.'){
					campo.value = campo.value+'-';
				}else{
					
				}
		}
		break;
	case 'cnpj':
		switch(campo.value.length){
			case 2:
				campo.value = campo.value+'.';
				break;
			case 6:
				if(campo.value.charAt(2)=='.'){
					campo.value = campo.value+'.';
				}				
				break;
			case 10:
				if(campo.value.charAt(2)=='.' && campo.value.charAt(6)=='.'){
					campo.value = campo.value+'/';
				}
				break;
			case 14:

				break;
			case 15:
				if(campo.value.charAt(2)=='.' && campo.value.charAt(6)=='.' && campo.value.charAt(10)=='/'){
					campo.value = campo.value+'-';
				}	
				break;
		}
		break;
	case 'fone':
		if(campo.value.length==4){
			campo.value = campo.value+'-';
		}
		break;
	case 'data':
		if(campo.value.length==2){
			campo.value = campo.value+'/';
		}
		if(campo.value.length==5 && campo.value.charAt(2)=='/'){
			campo.value = campo.value+'/';
		}
		break;
	case 'hora':
		if(campo.value.length==2){
			campo.value = campo.value+':';
		}
	case 'pular':
		if(campo.value.length==campo.getAttribute('maxlength')){
			document.getElementById(parametro).focus();
		}
		break;
}		
}

function trocaVal(c,nc){
	campo = document.getElementById(c).value
	document.getElementById(nc).value = campo	
}