function checkchars(nomeCampo, maxlen) { 
	len = nomeCampo.value.length;
	if (len > maxlen) { 
		nomeCampo.value = nomeCampo.value.substr(0, maxlen);
		alert("Você atingiu o número maximo de caracters. \nO máximo de caracteres é "+maxlen); 
    } 

} 
function addFav(){
    var url      = "http://www.politicasimaodiense.com.br";
    var title    = "Site a venda 224,00";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

function formatanumeros(campo,tipo){
	if(tipo=="DATA"){
		var configuracao = new Array(2,5);
		var caracteres = new Array("/","/");
		var tamanhomax = 10;
	}
	if(tipo=="CNPJ"){
		var configuracao = new Array(2,6,10,15);
		var caracteres = new Array(".",".","/","-");
		var tamanhomax = 18;
	}
	if(tipo=="HORA"){
		var configuracao = new Array(2,"");
		var caracteres = new Array(":");
		var tamanhomax = 5;
	}
	if(tipo=="CPF"){
		var configuracao = new Array(3,7,11);
		var caracteres = new Array(".",".","-");
		var tamanhomax = 14;
	}
	if(tipo=="CEP"){
		var configuracao = new Array(2,6);
		var caracteres = new Array(".","-");
		var tamanhomax = 10;
	}
	if(tipo=="TELEFONE"){
		if(campo.value.substring(0, 2)=="08")
		{
			var configuracao = new Array(4,8);
			var caracteres = new Array("-","-");
		}
		else
		{
			var configuracao = new Array(0,2,8);
			var caracteres = new Array("(", ")", "-");
		}
		var tamanhomax = 13;
	}
	if(tipo=="PROCESSO"){
		var configuracao = new Array(4,7,9,16);
		var caracteres = new Array(".",".",".","-");
		var tamanhomax = 18;
	}
	/////////Executa a configuração
	campo.maxLength = tamanhomax;
	for(i = 0; i < configuracao.length; i++){
		if(campo.value.length==configuracao[i]){
			if(campo.value.length>1)
			{
				if(configuracao[0]==0 && campo.value.substr(0, 1)!=caracteres[0])
					campo.value = caracteres[0]+campo.value;
				campo.value = campo.value+caracteres[i];
			}
		}//if
	}// for
}


//funcao de redirecionamento
function redireciona(pag){
	document.location.href=pag;
	}
	
// formata valor 0.00
function formataValor(campo,tammax,teclapres) {
	//exemplo FormataValor("saldo",13,event)
	//campo definido em id
	var tecla = teclapres.keyCode;	
	vr = document.getElementById(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.getElementById(campo).value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.getElementById(campo).value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.getElementById(campo).value = vr.substr( 0, tam - 5 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.getElementById(campo).value = vr.substr( 0, tam - 8 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.getElementById(campo).value = vr.substr( 0, tam - 11 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.getElementById(campo).value = vr.substr( 0, tam - 14 ) + '' + vr.substr( tam - 14, 3 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;}
	}
		

}

//funcao para mostrar caixa de atualizando ou com o texto necessário
function atualizando(texto){
	
	d =document.getElementById("atualizando").style.display;
	w = (screen.width/2)-75;
	h = 200;
	document.getElementById("atualizando").innerHTML = texto;
	document.getElementById("atualizando").style.top=h+"px";
	document.getElementById("atualizando").style.left=w+"px";	
	if(d=="none")
		document.getElementById("atualizando").style.display="";
	else	
		document.getElementById("atualizando").style.display="none";
}


function semvalor(campo,valor){			
	if(valor){
		document.getElementById(campo).value = "0";
		document.getElementById(campo).readOnly = true;
	}else{
		document.getElementById(campo).value = "0";
		document.getElementById(campo).readOnly = false;
	}

}

// funcao para limitar tamanho de textarea
function limite(maximo,campo_id,container){
	valor = document.getElementById(campo_id).value
	if(valor.length>maximo){
		document.getElementById(campo_id).value = valor.substring(0,maximo);
	}
	document.getElementById(container).innerHTML =  " "+document.getElementById(campo_id).value.length+" ";
}

function numeros(id,dbl){
	strCampo = document.getElementById(id);
	vr = strCampo.value;
	texto = "";
	for(n=0;n<vr.length;n++){						
		ch = vr.charCodeAt(n);
		if(dbl){
			if((ch>47 && ch < 58) || ch==46) texto += vr.charAt(n);
		}else{
			if(ch>47 && ch < 58) texto += vr.charAt(n);
		}
		
	}
	strCampo.value = texto;
	
}

function maskdata(campo,k){

	tecla = k.keyCode;
	//eval("strCampo = document.form1."+campo);
	strCampo = document.getElementById(campo);
	vr = strCampo.value;
	tamanhoMaximo = 8;

	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	vr = vr.replace("/","");
	tam = vr.length;

	if(tam < tamanhoMaximo && tecla != 8 ){
	tam = vr.length + 1;
	}

	if(tecla == 8){
	tam = vr.length -1;
	}

	if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105){
		if(tam <=2 ) strCampo.value = vr;
		if(tam > 2 && tam <4) strCampo.value = vr.substr(0,2) + "/" + vr.substr(2,tam);
		if(tam >= 4 ) strCampo.value = vr.substr(0,2) + "/" + vr.substr(2,2) + "/" + vr.substr(4,tam);
	}
	
}
function userName(id){
	x = document.getElementById(id).value;
	tam = x.length;
faltam = 7 - tam;
var zeros = "";
if (tam<7) {
	for (var i =0; i< faltam; i++) {
		zeros += "0";
	}
	novo = zeros + x;
	document.getElementById(id).value = novo;
}
}

function verifica(fm){
	// verifica(formulario,'nome do campo','nome do campo',...)	
	eval("fm=document."+fm+";");
	args = arguments.length;
	cancela = false;
	for(a=0;a<fm.length;a++){
		pula = false;
		for(b=1;b<args;b++){
			
			if(fm.elements[a].name ==arguments[b]) pula = true;
		}
		if(!pula){
			if(trim(fm.elements[a].value)==""){
				cancela = true;				
				fm.elements[a].style.border="1px solid red";
				fm.elements[a].style.backgroundColor = "#FEE8E7";
			}else{
				fm.elements[a].style.border="1px solid black";
				fm.elements[a].style.backgroundColor = "transparent";
			}
		}
	}
	
	if(cancela){
		alert("Preencha os campos marcados com a borda vermelha");
	}else{
		fm.submit();
	}
}

//##########################################################3

function verEmail(email1,email2){
	eval("e1="+email1+";");
	eval("e2="+email2+";");
	vr1 = e1.value;
	vr2 = e2.value;
	if(vr1!=""){
		if(vr1==vr2){
			alert("O E-mail(2) deve ser diferente do E-mail(1).\n Caso não possua mais de um e-mail deixar o campo Email(2) vazio");
			e1.value = "";
			e1.focus();
		}
	}
	
	
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

	
//funcao para mostrar caixa de atualizando ou com o texto necessário
function atualizando(texto){
	
	d =document.getElementById("atualizando").style.display;
	w = (screen.width/2)-75;
	h = 200;
	document.getElementById("atualizando").innerHTML = texto;
	document.getElementById("atualizando").style.top=h+"px";
	document.getElementById("atualizando").style.left=w+"px";	
	if(d=="none")
		document.getElementById("atualizando").style.display="";
	else	
		document.getElementById("atualizando").style.display="none";
}


//FUNCOES AJAX

//PRIVATE
// função criando o objeto e enviando a requisição
function xmlrequest(url,div){

	req = null;
	dv = div
	if(window.ActiveXObject){ //IE
		req = new ActiveXObject("MSXML2.XMLHTTP");
		if(req){
			req.onreadystatechange = escreve;
			req.open("POST",url,true);
			req.send();
		}
	}else if(window.XMLHttpRequest){//mozilla 
		req = new XMLHttpRequest(); //incializa objeto
		req.onreadystatechange = escreve; //chama funcao para escrever
		req.open("POST",url,true); //chama pagina para pegar dados
		req.send(null);	//faz requisicao
		
	}
}

//private
// função chamada pela xmlrequest
// recebe os valores e escreve no html
x = 1
function escreve(){
	if(req.readyState ==4){//caso status seja "completado"
		top.document.getElementById(dv).innerHTML = req.statusText;
		if(req.status==200){ //caso o servidor retornar OK
			top.document.getElementById(dv).innerHTML = req.responseText;			
		}else{
			top.document.getElementById(dv).innerHMTL = req.status;
		}
	}
		
}

//funcao que chama o ajax
function ajax(url,div){
	req = null;
	xmlrequest(url,div);	
	
}

//votacao da enquete
function vota(id){
	resposta = document.getElementById('enquete_id'+id).value;
	if (resposta != "")
		//ajax("inc/enquete.php?ajax=true&funcao=vota&resposta="+resposta+"&id="+id,"divEnq"+id);				
		redireciona("index.php?id_enq="+id+"&resposta="+resposta);
	else
		alert('Escolha uma das Opções.');
}

//Valida Email
 function validaemail(e)
{   var str = e.value;
  
       if (str == "")
            return true;
       
      
      if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
      else{
        alert(str + "\n É um e-mail inválido");
        e.focus() ;
        return false;
        }
}

//FORMULÁRIO MURAL
function VerificaCamposObrigatoriosFormMural()
{
if (document.form_mural.nome.value =='')
  {
    alert('Campo "Nome" obrigatório.');
    document.form_mural.nome.focus();
    return false;
  }

if (document.form_mural.email.value =='')
  {
    alert('Campo "Email" obrigatório.');
    document.form_mural.email.focus();
    return false;
  }
  

  if (document.form_mural.mensagem.value =='')
  {
    alert('Campo "Mensagem" obrigatório.');
    document.form_mural.mensagem.focus();
    return false;
  }
  if (document.form_mural.email.value != '')
  {
	var str = document.form_mural.email.value;  	
    if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		
	}else{
        alert(str + "\n É um e-mail inválido");
        document.form_mural.email.focus();
        return false;
        }    
  }
}

//Formulário FALE CONOSCO
function VerificaCamposObrigatoriosFormFaleConosco()
{
  if (document.form1.email.value =='')
  {
    alert('Campo "Email" obrigatório.');
    document.form1.email.focus();
    return false;
  }
  
  if (document.form1.assunto.value =='')
  {
    alert('Campo "Assunto" obrigatório.');
    document.form1.assunto.focus();
    return false;
  }
  
  if (document.form1.msg.value =='')
  {
    alert('Campo "Mensagem" obrigatório.');
    document.form1.msg.focus();
    return false;
  }  
  if (document.form1.email.value != '')
  {
	var str = document.form1.email.value;  	
    if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		
	}else{
        alert(str + "\n É um e-mail inválido");
        document.form1.email.focus();
        return false;
        }    
  }
}

function VerificaCamposObrigatoriosFormOportunidades()
{
  if (document.form1.nome.value =='')
  {
    alert('Campo "Nome" obrigatório.');
    document.form1.nome.focus();
    return false;
  }    
  if (document.form1.tel.value =='')
  {
    alert('Campo "Telefone" obrigatório.');
    document.form1.tel.focus();
    return false;
  }
  if (document.form1.email.value =='')
  {
    alert('Campo "Email" obrigatório.');
    document.form1.email.focus();
    return false;
  }
  
  if (document.form1.sexo.value =='')
  {
    alert('Campo "Sexo" obrigatório.');
    document.form1.sexo.focus();
    return false;
  } 
   if (document.form1.datadenasc.value =='')
  {
    alert('Campo "Data de Nascimento" obrigatório.');
    document.form1.datadenasc.focus();
    return false;
  }
   if (document.form1.estadoCivil.value =='')
  {
    alert('Campo "Estado Civil" obrigatório.');
    document.form1.estadoCivil.focus();
    return false;
  }
   if (document.form1.escolaridade.value =='')
  {
    alert('Campo "Escolaridade" obrigatório.');
    document.form1.escolaridade.focus();
    return false;
  }
  if (document.form1.curso.value =='')
  {
    alert('Campo "Curso" obrigatório.');
    document.form1.curso.focus();
    return false;
  }
  if (document.form1.instituicao.value =='')
  {
    alert('Campo "Instituição" obrigatório.');
    document.form1.instituicao.focus();
    return false;
  }  
  if (document.form1.email.value != '')
  {
	var str = document.form1.email.value;  	
    if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		
	}else{
        alert(str + "\n É um e-mail inválido");
        document.form1.email.focus();
        return false;
        }    
  }
}

// Coloca mascara na data
function mascaradata (i)
 {
 var texto = i.value
   //if (event.keyCode  == 47 || event.keyCode == 46) event.returnValue = false;
  

  if (i.value.length >= 10)
		 event.returnValue = false;

  if (event.keyCode  < 48 || event.keyCode > 57) event.returnValue = false;
    
  if (texto == "." || texto == "/" ) event.returnValue = false;
 
  if (texto.length == 2 || texto.length == 5 ) 
   {
   i.value = texto +"/";
   }   
 }
 
 function mascaradataMesAno (i)
 {
 var texto = i.value
   //if (event.keyCode  == 47 || event.keyCode == 46) event.returnValue = false;
  

  if (i.value.length >= 7)
		 event.returnValue = false;

  if (event.keyCode  < 48 || event.keyCode > 57) event.returnValue = false;
    
  if (texto == "." || texto == "/" ) event.returnValue = false;
 
  if (texto.length == 2) 
   {
   i.value = texto +"/";
   }   
 }

//verifica formulario de enquete
function verifica_enquete(id,obrigatorio){	
	erro = "";
	eval("form =  document.formenq"+id+";");
	if(obrigatorio>0){
	
		if(form.nome.value=="") erro += "O nome é de preenchimento obrigatório\n";
		if(form.email.value=="") erro += "O e-mail é de preenchimento obrigatório\n";
		//if(form.telefone.value=="") erro += "O telefone é de preenchimento obrigatório\n";		
		if(erro) {
			erro = "Houve erro(s) ao enviar o formulário:\n"+erro;
			envia = false;
			alert(erro);
		}else			
			envia = true;
	}else{
		envia = true;
	}
	
	if(envia){
		if(obrigatorio>0)
		{
		  nome = form.nome.value;
		  email = form.email.value;
		  telefone = form.telefone.value;
		  resposta = form.resposta.value;
		  enque_id = form.enquete_id.value; 
		  	  redireciona("index.php?nome="+nome+"&email="+email+"&telefone="+telefone+"&resposta="+resposta+"&enque_id="+enque_id);			//ajax("inc/enquete.php?ajax=true&funcao=grava&nome="+form.nome.value+"&email="+form.email.value+"&telefone="+form.telefone.value+"&enquete_item_id="+form.resposta.value+"&enquete_id="+id,"divEnq"+id);		

		}
//		else
//			redireciona("index.php?resposta="+resposta+"&enque_id="+enque_id);	
	}
	
}

function muda_cidade(estado,sel){
	document.getElementById("newcity").value = "false";
	ajax("inc/pontosdesaque.php?acao=pegacidade&estado="+estado+"&seleciona="+sel,"div_cidade");
	}
	
function novacidade(valor){
	if(valor=="new"){
		document.getElementById("div_cidade").innerHTML = "<input type='text' name='cidade' id='cidade' size='30'>";
		document.getElementById("newcity").value = "true";
	}else{
		return false;	
	}
}
	



// FIM DA FUNCAO AJAX

// funções do formulario de seguro
function data(d,m,a,data){
		document.getElementById(data).value = document.getElementById(d).value + "/" + document.getElementById(m).value + "/" + document.getElementById(a).value;
}

function valorMin(id,valor){
	campo = document.getElementById(id)
	v = parseFloat(campo.value);
	if(v<valor){
		alert("O valor mínimo para "+id+" é de R$ "+valor);
		campo.value = "";
		campo.focus;
	}
	
}
// fim das funcoes de seguro




//FUNÇÃO QUE RETORNA DATA POR EXTENSO
function dataPorExtenso() {
hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getFullYear()
if (dia < 10)
dia = "0" + dia
if (ano < 2000)
ano = "19" + ano
function CriaArray (n) {
this.length = n }
NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Terça-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "Sábado"
//
NomeMes = new CriaArray(12)
NomeMes[0] = "Janeiro"
NomeMes[1] = "Fevereiro"
NomeMes[2] = "Março"
NomeMes[3] = "Abril"
NomeMes[4] = "Maio"
NomeMes[5] = "Junho"
NomeMes[6] = "Julho"
NomeMes[7] = "Agosto"
NomeMes[8] = "Setembro"
NomeMes[9] = "Outubro"
NomeMes[10] = "Novembro"
NomeMes[11] = "Dezembro"

document.write (NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano)

}
//Fim das funcao de data por extenso






