function validaCampos(qual){
	if(qual == "2"){
		with (document.frm_busca_rapida){
			if(ls_opcao.value == '0'){
				alert('Por favor selecione a opção de negócio.');
				ls_opcao.focus();
				return false;
			}else{
				submit();
				return true;
			}
		}
	}else if(qual == "1"){
		with (document.frm_contato){
			if(txt_nome.value == ""){
				alert('Por favor informe seu nome');
				txt_nome.focus();
				return false;
			}
			if(txt_email.value == ""){
				alert('Por favor informe seu e-mail');
				txt_email.focus();
				return false;
			}else if (!validaEmail(txt_email, "frm_contato", 2)){
				txt_email.focus();
				txt_email.select();
				return false;
			}
// 			if(txt_cidade.value == ""){
// 				alert('Por favor informe sua cidade');
// 				txt_cidade.focus();
// 				return false;
// 			}
// 			if(ls_uf.value == "0"){
// 				alert('Por favor informe seu estado');
// 				ls_uf.focus();
// 				return false;
// 			}
 			//if(txt_fone.value == ""){
// 				alert('Por favor informe seu telefone');
// 				txt_fone.focus();
// 				return false;
// 			}
//			if(ls_assunto.value == "0"){
//				alert('Por favor selecione o assunto');
//				ls_assunto.focus();
//				return false;
//			}
			if(txt_mensagem.value == ""){
				alert('Por favor digite uma mensagem');
				txt_mensagem.focus();
				return false;
			}else{
				submit();
				return true;
			}
		}
	}
}

function mostraImagem(a,l,pg){
	l = eval(l) + 17;
	a = eval(a) + 4;
	if(a > 520) a = 520
	if(l > 650) l = 650
	nova_janela = window.open('','mostra_imagem','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width=' +l+ ',height=' + a);
	nova_janela.document.writeln('<HTML><HEAD><TITLE></TITLE></HEAD><BODY style="margin=0px;text-align=center;"><IMG style="cursor=hand;" src="'+pg+'" onClick="window.close()" alt="Clique na imagem para fechar"></BODY></HTML>');
	nova_janela.document.close();
}

function validaEmail(email, formu, tipo){
	var sMail = new String(email.value)
	var index = sMail.indexOf("@");
	if (index > 0){
		var pindex = sMail.indexOf(".",index);
		if ((pindex > index+1) && (sMail.length > pindex+1)){
			result = true;
		}else{
			result = false;
		}
	}else{
		result = false;
	}
	if(!result){
		alert('EMAIL inexistente, por favor insira um e-mail válido.');
		if(tipo == 1){
			formu.elements[0].focus();
			formu.elements[0].select();
		}
	}else{
		if(tipo == 1){
			formu.submit();
		}else{
			return result;
		}
	}
}

var eMaior;
var posicaoVert="acima";
var aux6=(document.getElementById&&!document.all);
var initVal=(document.all);
var realTi=(document.all);
var initVal5=(initVal && (eMaior==4) && (agt.indexOf("msie 5.0")!=-1));
var initVal4=(initVal && (eMaior<=4) && (agt.indexOf("msie 5.0")==-1) && (agt.indexOf("msie 6.0")==-1));
var aux=(navigator.appName=="Netscape");
var tempoLimite;
var posIncialY=-200;

if(document.documentElement && document.documentElement.scrollTop){
	var iniciaSc=document.documentElement.scrollTop;

}else if(document.body && document.documentElement.scrollTop){
	var iniciaSc=document.body.scrollTop;

}else if(aux){
	var iniciaSc=window.pageYOffset;
}

function verificaCarga(){
	if(document.documentElement && document.documentElement.scrollTop){
		var scrollCurrent=document.documentElement.scrollTop;

	}else if(document.body && document.body.scrollTop){
		var scrollCurrent=document.body.scrollTop;

	}else if(aux){
		var scrollCurrent=window.pageYOffset;
	}

	if(scrollCurrent!=iniciaSc){
		mostraTempo=setTimeout("mostraFlutuante()",50);

	}else{
		tempoLimite=setTimeout("verificaCarga()",50);
	}
}

function mostraFlutuante(){
	mostrar("flutuante");
}

function mostrar(tempId){
	var element=null;
	var id=tempId;

	clearTimeout(tempoLimite);

	if(document.getElementById){
		element=document.getElementById(id);

	}else if(document.all){
		element=document.all[id];

	}else if(document.layers){
		element=document.layers[id];
	}

	if(element){
		if(posIncialY==-200){
			posIncialY=0;
		}
		
		element.style.visibility="visible";
		levaTopoPos(id);
	}
}

function levaTopoPos(tempId){
	var id=tempId;

	var inicioX=0;

	if(aux){
		inicioY=0;

	}else{
		if(realTi){
			inicioY=-520;

		}else{
			inicioY=0;
		}
	}

	var ns=(navigator.appName.indexOf("Netscape")!=-1);
	var x=inicioX;
	var y=inicioY;

	function ml(id){
		var el;
		if(aux6){
			el=document.getElementById(id);

		}else if(initVal){
			el=document.all[id];

		}else if (aux){
			el.style=el;
		}

		el.sP=function(x,y){
			if(y>=posIncialY){
				if(el.style){
					el.style.left=x+"px";
					el.style.top=y+"px";

				}else{
					el.left=x;
					el.top=y;
				}
			}
		}

		el.x=inicioX;
		if(posicaoVert=="acima"){
			el.y=inicioY;

		}else{
			el.y=(ns)?pageYOffset+innerHeight:document.body.scrollTop+document.body.clientHeight;
			el.y-=inicioY;
		}

		return el;
	}

	window.manterEsquerda=function(){
		if(posicaoVert=="acima"){
			if(document.documentElement && document.documentElement.scrollTop){
				var pY=document.documentElement.scrollTop;
				objFlutuante.y+=(pY+inicioY-objFlutuante.y)/10;
				if(objFlutuante.y<posIncialY){
					objFlutuante.y=posIncialY
				}

			}else if(document.body){
				var pY=document.body.scrollTop;
				objFlutuante.y+=(pY+inicioY-objFlutuante.y)/10;
				if(objFlutuante.y<=posIncialY){
					objFlutuante.y=posIncialY
				}

			}else if(aux){
				var pY=window.pageYOffset;
				objFlutuante.y+=(pY+inicioY-objFlutuante.y)/10;
				if(objFlutuante.y<posIncialY){
					objFlutuante.y=posIncialY
				}
			}

		}else{
			pY=(ns)?window.pageYOffset+innerHeight:document.documentElement.scrollTop;
			objFlutuante.y+=(pY-inicioY-objFlutuante.y)/20;
		}

		objFlutuante.sP(objFlutuante.x,objFlutuante.y);
		setTimeout("manterEsquerda()", 10);
	}

	var objFlutuante=ml(id);
	manterEsquerda();
}

function ajustarFone(input, evento){
	var tecla = evento.keyCode;
	valor = input.value;
	valor = valor.replace( "(", "" );
	valor = valor.replace( ")", "" );
	valor = valor.replace( " ", "" );
	valor = valor.replace( "-", "" );
	tamanhoMaximo = 10;
	tamanho = valor.length;
    if(!soNumero(evento)){
	    return false;
	} else { 
		if (tamanho < tamanhoMaximo && tecla != 8) {
		tamanho = valor.length + 1 ;
		}
		if (tecla == 8 ) {
			tamanho = tamanho - 1 ;
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
			if ( tamanho <= 4 ) { 
		 		input.value = valor ;
			}
		 	if ( (tamanho > 4) && (tamanho <= 8) ) {
		 		input.value = valor.substr(0,tamanho-4) + '-' + valor.substr( tamanho - 4, tamanho ) ;
			}
		 	if ( (tamanho >= 9) && (tamanho <= 10) ) {
				input.value = '(' + valor.substr(0,2) + ') ' + valor.substr(2,tamanho-6) + '-' + valor.substr(tamanho-4,tamanho) ;			
			}
		}
	}
	return true;
}

//Completa a data com as barras "/"
function ajustarData(input, evento){
    if(!soNumero(evento)){
	    return false;
	} else { 
		if ((input.value.length == 2)||(input.value.length == 5)) {
		   input.value = input.value + "/" ;
		   }
	}
	return true;
}

//Formata CEP
function ajustarCep(input, evento){
    if(!soNumero(evento)){
	    return false;
	} else { 
		if (input.value.length == 5) {
		   input.value = input.value + "-";
		}
	}
	return true;
}

function soNumero(evento){
	var BACKSPACE=  8; 
	var TAB= 9;
    var DEL=  46; 
    var FRENTE=  39; 
    var TRAS=  37; 
    var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
    
    if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)||(tecla == TAB)){
         return true; 
	}
    if ( tecla == 13 )     return false; 

	if ((tecla >= 48 && tecla <= 57) || (tecla == 44)) {
		return true;
	}else{
		evento.returnValue = false; 
		return false;
	}
}

// Funções usadas no formulário de inscricao

function valida(form) {
	for (var i = 0; i < form.length; i++) {
		campo = form[i].name;
		
		if (campo == "st_complemento" || campo == "st_cep" || campo == "st_celular" || campo == "st_email" || campo.substr(0, 3) == "aco") { 
			// Campos que podem ficar em branco
			continue;
		} else if (campo == "Submit") { 
			// Pára quando chega no botão enviar, as informações posteriores a este não interessam
			break; 
		} else if (form[i].value == "" || form[i].value == undefined) {
			alert("É necessário preencher todos os campos com sublinhado.");
			return false;
		} 
		
//		document.getElementById("teste").innerHTML += form[i].name +" - "+ form[i].value +" - "+ form[i].type +"<br />";
	}
	
	if (!confirm("O cadastro será efetuado, verifique se as informações estão corretas.")) {
		return false;
	} else {
		return true;
	}
}

function vlEvento(state, valor) {
	var soma = parseInt(document.getElementById("soma").value);
	
	if (state) {
		soma += valor;
	} else {
		soma -= valor;
	}
	
	document.getElementById("soma").value = soma;
	
	soma = soma.toFixed(2);
	soma = soma.replace(".", ",");
	
	document.getElementById("mostraSoma").innerHTML = soma;
	
}


function subForm(formulario){

	if (formulario == "frm_convenio"){
		with(document.frm_convenio){
			if (nome.value == ""){
				alert('Por favor insira seu nome.');
				nome.focus();
				return false;
			}else if (end.value == ""){
				alert('Por favor insira o endereço.');
				end.focus();
				return false;
			}else if (telefone.value.length != 14){
				alert('Digite seu telefone corretamente.');
				telefone.focus();
				return false;
			}else if (categ.value == ""){
				alert('Escolha uma categoria.');
				categ.focus();
				return false;
			}else{
				//alert('aki');
				submit();
				return true;
			}
		}
	}

}

//Formata CPF / CNPJ
function ajustarCpf(input, evento){
	var ie = (typeof window.ActiveXObject != 'undefined');  

	if (ie)
		tecla = evento.keyCode;
	else
		tecla = evento.which; 

	//alert(tecla);
	if(!soNumero(evento)){
		return false;
	}else{
		if((tecla<48)||(tecla>57)){
			evento.returnValue =false;
			return false;
		}else{
			if ((input.value.length == 3)||(input.value.length == 7)) {
				input.value = input.value + "." ;
			}
			if (input.value.length == 11) {
				input.value = input.value + "-" ;
			}
			if(input.value.length == 15){
				input.value = input.value.replace('.','');
				input.value = input.value.replace('.','');
				input.value = input.value.replace('-','');
				input.value = input.value.substr(0, 2) + '.' + input.value.substr(2, 3) + '.' + input.value.substr(5, 3) + '/' + input.value.substr(8, 4);
				input.value = input.value + "-" ;
			}
		}
	}
	return true;
}
//valida CPF
function validaCpf(cpf){ 
	var i;
	cpf = cpf.substr(0,3) + cpf.substr(4,3) + cpf.substr(8,3) + cpf.substr(12,2);
	var c = cpf.substr(0,9); 
	var dv = cpf.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(10-i); 
	} 
	if (d1 == 0){
		alert("CPF Invalido") 
		return false; 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1){ 
		alert("CPF Invalido") 
		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("CPF Invalido")
		return false; 
	} 
	return true; 
} 

function validaFormulario(){
	with(document.frm_boleto){
		if(cpf.value == ""){
			alert("Informe seu CPF.");
			cpf.focus();
			return false
		}else if(!validaCpf(cpf.value)){
			cpf.focus();
			return false;
		}else{
			submit();
			return true;
		}
	}
}

