function ajax() {
};
ajax.prototype.iniciar = function() {

    try{
        this.xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                this.xmlhttp = false;
            }
        }
    }
    return true;
}

ajax.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
	document.getElementById("carregando").style.display = "block";
    return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {        
		return true;
    }
}

ajax.prototype.enviar = function(url, metodo, modo) {
    if (!this.xmlhttp) {
        this.iniciar();
    }
    if (!this.ocupado()) {
        if(metodo == "GET") {
            this.xmlhttp.open("GET", url, modo);
            this.xmlhttp.send(null);
        } else {        
            this.xmlhttp.open("POST", url, modo);
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
            this.xmlhttp.setRequestHeader("Pragma", "no-cache");
            this.xmlhttp.send(url);
        }    

        if (this.processa) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}

function envia(url, metodo, modo)
{
    var site = document.getElementById("site").value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?site=" + site, metodo, modo );	
    if(xmlhttp) {
		document.getElementById("carregando").style.display = "none";
		document.getElementById("alerta").style.display = "block";      
        document.getElementById("alerta").innerHTML = "O site " + site + " ja esta cadastrado em nosso sistema";
		document.cadastro.site.value = "";
    } else {
		document.getElementById("carregando").style.display = "none";        
    }    
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

function validaForm(){
          
	d = document.cadastro;
	
	//validar categoria
	if (d.cat.value == "-1"){
			alert("Escolha uma categoria por favor!");					
			document.getElementById("cp_cat").style.background = "#FFE57F";
			d.cat.focus();
			return false;
	}			
	
	//validar url	
	if(d.nsite.value == 0){
	
		if(!isValidURL(d.site.value)){
        alert("Digite um SITE valido ou caso nao tenha site favor clicar em: 'Nao possuo site'");
		document.getElementById("cp_site").style.background = "#FFE57F";
		d.nsite.focus();
		return false;		
		}
	
	}
	
	//validar titulo
	if (d.titulo.value == ""){
			alert("O campo " + d.titulo.name + " deve ser preenchido!");					
			document.getElementById("cp_titulo").style.background = "#FFE57F";
			d.titulo.focus();
			return false;
	}
	
	if (d.titulo.value.length <= 10) {
		   alert ("O campo titulo deve conter no minimo 10 caracteres!");
		   document.getElementById("cp_titulo").style.background = "#FFE57F";
		   d.titulo.focus();
		   return false;
	}
	
	//validar resumo
	if (d.resumo.value == ""){
			alert("O campo " + d.resumo.name + " deve ser preenchido!");					
			document.getElementById("cp_resumo").style.background = "#FFE57F";
			d.resumo.focus();
			return false;
	}
		
	if (d.resumo.value.length <= 60) {
		   alert ("O campo resumo deve conter no minimo 60 caracteres!");
		   document.getElementById("cp_resumo").style.background = "#FFE57F";
		   d.resumo.focus();
		   return false;
	}
	
	//validar nome
	if (d.nome.value == ""){
			alert("O campo " + d.nome.name + " deve ser preenchido!");					
			document.getElementById("cp_nome").style.background = "#FFE57F";
			d.nome.focus();
			return false;
	}
	 
	 
	 //validar cep
	if (d.cep.value == ""){
			alert("O campo " + d.cep.name + " deve ser preenchido!");					
			document.getElementById("cp_cep").style.background = "#FFE57F";
			d.cep.focus();
			return false;
	}

	if (d.cep.value.length <= 8) {
		   alert ("O campo cep deve conter no cep valido!");
		   document.getElementById("cp_cep").style.background = "#FFE57F";
		   d.cep.focus();
		   return false;
	}
	
	//validar cep
	if (d.rua.value == ""){
			alert("O campo Endereco deve ser preenchido!");					
			document.getElementById("cp_rua").style.background = "#FFE57F";
			d.rua.focus();
			return false;
	}
	
	if (d.numero.value == ""){
			alert("O campo numero deve ser preenchido!");					
			document.getElementById("cp_rua").style.background = "#FFE57F";
			d.numero.focus();
			return false;
	}
		
	if (d.bairro.value == ""){
			alert("O campo Bairro deve ser preenchido!");					
			document.getElementById("cp_bairro").style.background = "#FFE57F";
			d.bairro.focus();
			return false;
	}
		
	if (d.cidade.value == ""){
			alert("O campo Cidade deve ser preenchido!");					
			document.getElementById("cp_cidade").style.background = "#FFE57F";
			d.cidade.focus();
			return false;
	}
	
	if (d.estado.value == ""){
			alert("O campo Estado deve ser preenchido!");					
			document.getElementById("cp_cidade").style.background = "#FFE57F";
			d.estado.focus();
			return false;
	}
	
	 if (d.ddd1.value == ""){
				alert("O campo DDD deve ser preenchido!");
				document.getElementById("cp_telefone").style.background = "#FFE57F";
				d.ddd1.focus();
				return false;
	 }
	
	if (d.ddd1.value.length <= 1 || d.ddd1.value == "00" ) {
			   alert ("O campo DDD deve conter um DDD correto!");
			   document.getElementById("cp_telefone").style.background = "#FFE57F";
			   d.ddd1.value = "";
			   d.ddd1.focus();
			   return false;
	}	
		 
	if (d.telefone1.value == ""){
				alert("O campo Telefone Principal deve ser preenchido!");
				document.getElementById("cp_telefone").style.background = "#FFE57F";
				d.telefone1.focus();
				return false;
	 }
	
	if (d.telefone1.value.length <= 8 || d.telefone1.value == "1111-1111" || d.telefone1.value == "2222-2222" || d.telefone1.value == "3333-3333" || d.telefone1.value == "4444-4444" || d.telefone1.value == "5555-5555" || d.telefone1.value == "6666-6666" || d.telefone1.value == "7777-7777" || d.telefone1.value == "8888-8888" || d.telefone1.value == "9999-9999" || d.telefone1.value == "0000-0000" ) {
			   alert ("O campo Telefone Principal deve conter um telefone correto!");
			   document.getElementById("cp_telefone").style.background = "#FFE57F";
			   d.telefone1.value = "";
			   d.telefone1.focus();
			   return false;
	}
	
	//validar email
	 if (d.email.value == ""){
			   alert("O campo Email deve ser preenchido!");
			   document.getElementById("cp_email").style.background = "#FFE57F";
			   d.email.focus();
			   return false;
	 }
	
	//validar email(verificao de endereco eletrônico)
	 parte1 = d.email.value.indexOf("@");
	 parte2 = d.email.value.indexOf(".");
	 parte3 = d.email.value.length;
	 if (!(parte1 >= 1 && parte2 >= 1 && parte3 >= 7)) {
			   alert ("O campo Email deve conter um email correto!");
			   document.getElementById("cp_email").style.background = "#FFE57F";
			   d.email.focus();
			   return false;
	 } else {
		 
	if(d.email.value != d.emailc.value){
		alert ("Confirme seu Email novamente, pois os emails digitados nao conferem!");
		document.getElementById("cp_emailc").style.background = "#FFE57F";
		d.emailc.focus();
		return false;
		}	
	 }
	
		
	//validar email secundario
	 if (d.emailsecundario.value != ""){
	 partesec1 = d.emailsecundario.value.indexOf("@");
	 partesec2 = d.emailsecundario.value.indexOf(".");
	 partesec3 = d.emailsecundario.value.length;
	 if (!(partesec1 >= 1 && partesec2 >= 1 && partesec3 >= 7)) {
			   alert ("O campo Email Secundario deve conter um email correto, ou deixe em branco caso nao queira colocar um email secundario!");
			   document.getElementById("cp_emailsecundario").style.background = "#FFE57F";
			   d.emailsecundario.focus();
			   return false;
	 }
	 }
	
	
	//validar senha
	if (d.password.value == ""){
			alert("Favor criar uma senha");					
			document.getElementById("cp_password").style.background = "#FFE57F";
			d.password.focus();
			return false;
	}
	
	if (d.password.value.length <= 5 ) {
			   alert ("Sua senha deve possuir pelo menos 6 caracteres");
			   document.getElementById("cp_password").style.background = "#FFE57F";			   
			   d.password.focus();
			   return false;
	}
	
	if (d.passwordc.value == ""){
			alert("Favor confirmar sua senha");					
			document.getElementById("cp_passwordc").style.background = "#FFE57F";
			d.passwordc.focus();
			return false;
	} else {
	
	if(d.password.value != d.passwordc.value){
		alert ("Confirme sua senha novamente, pois as senhas digitados nao conferem!");
		document.getElementById("cp_passwordc").style.background = "#FFE57F";
		d.passwordc.focus();
		return false;
		}	
	 }
	 
	 if(d.aceite.checked == false){
		alert ("Por favor aceite o termo de cadastro de anuncio");
		document.getElementById("cp_aceite").style.background = "#FFE57F";
		d.aceite.focus();
		return false;
		
	 }
	
	
	d.action = "http://www.zunz.com.br/anuncios-gratis/processamento?cadastro=novo";   
	d.submit(); 
	
}


function validaFormContato(){
	
	d = document.contato;
	
	if (d.nome.value == ""){
			alert("Favor preencher seu nome");
			d.nome.focus();
			return false;
	}
	
	//validar email
	 if (d.email.value == ""){
			   alert("O campo Email deve ser preenchido!");			  
			   d.email.focus();
			   return false;
	 }
	
	//validar email(verificao de endereco eletrônico)
	 parte1 = d.email.value.indexOf("@");
	 parte2 = d.email.value.indexOf(".");
	 parte3 = d.email.value.length;
	 if (!(parte1 >= 1 && parte2 >= 1 && parte3 >= 7)) {
			   alert ("O campo Email deve conter um email correto!");			   
			   d.email.focus();
			   return false;
	 }
	
	d.action = "http://www.zunz.com.br/anuncios-gratis/processamento?contato=novo";   
	d.submit();
	
}

/*
*    Script:    Mascaras em Javascript
*    Autor:    Matheus Biagini de Lima Dias
*    Data:    26/08/2008
*    Obs:    
*/
    /*Função Pai de Mascaras*/
    function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }
    
    /*Função que padroniza telefone (11) 4184-1241*/
    function Telefone(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
        v=v.replace(/(\d{4})(\d)/,"$1-$2")    
        return v
    }
	
	/*Função que padroniza telefone 4184-1241*/
	function TelefoneSemDdd(v){       
		v=v.replace(/\D/g,"")
        v=v.replace(/(\d{4})(\d)/,"$1-$2")		
        return v
    }
	
	function Ddd(v){        
		v=v.replace(/\D/g,"")		
        return v
    }
    
    /*Função que padroniza telefone (11) 41841241*/
    function TelefoneCall(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2")    
        return v
    }
    
    /*Função que padroniza CPF*/
    function Cpf(v){
        v=v.replace(/\D/g,"")                    
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
                                                 
        v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CEP*/
    function Cep(v){
		v=v.replace(/\D/g,"")
        //v=v.replace(/D/g,"")                
        v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CNPJ*/
    function Cnpj(v){
        v=v.replace(/\D/g,"")                   
        v=v.replace(/^(\d{2})(\d)/,"$1.$2")     
        v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
        v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           
        v=v.replace(/(\d{4})(\d)/,"$1-$2")              
        return v
    }
    
    /*Função que permite apenas numeros Romanos*/
    function Romanos(v){
        v=v.toUpperCase()             
        v=v.replace(/[^IVXLCDM]/g,"") 
        
        while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
            v=v.replace(/.$/,"")
        return v
    }
    
    /*Função que padroniza o Site*/
    function Site(v){
        v=v.replace(/^http:\/\/?/,"")
        dominio=v
        caminho=""
        if(v.indexOf("/")>-1)
            dominio=v.split("/")[0]
            caminho=v.replace(/[^\/]*/,"")
            dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
            caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
            caminho=caminho.replace(/([\?&])=/,"$1")
        if(caminho!="")dominio=dominio.replace(/\.+$/,"")
            v="http://"+dominio+caminho
			document.getElementById("site").style.background = "none";
        return v
    }

    /*Função que padroniza DATA*/
    function Data(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        return v
    }
    
    /*Função que padroniza DATA*/
    function Hora(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1:$2")  
        return v
    }
    
    /*Função que padroniza valor monétario*/
    function Valor(v){
        v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
        v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
        //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
        v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
        return v
    }
    
    /*Função que padroniza Area*/
    function Area(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d)(\d{2})$/,"$1.$2") 
        return v
        
    }
	
	function msg(campo){	
		document.getElementById(campo).style.display = "block";	
	}
	
	function msg_out(campo){	
		document.getElementById(campo).style.display = "none";	
	}
		
	function disable() {	
		d = document.cadastro;
		
		if (d.nsite.checked == true){
		
		document.getElementById('site').disabled = true;		
		document.getElementById('site').style.backgroundColor = "#cfcfcf";
		d.nsite.value = 1;
		d.site.value = "";
		
		} else {
		
		document.getElementById('site').disabled = false;
		document.getElementById('site').style.backgroundColor = "#ffffff";
		d.nsite.value = 0;
		
		}	
	}
	
	
	var wlaczone=0;
	
	function policz(){
	document.cadastro.caracteres.value=document.cadastro.resumo.value.length	
	var x = document.cadastro.resumo;
	var n = x.value.length;
	var limite = 160;
	
	if (navigator.appName=="Netscape" && wlaczone!=0) {
		x.blur();
		x.focus();
	}
	if (n > limite ){
		alert("Passou o limite do tamanho do texto! Caso deseje escreva mais no campo abaixo");
		document.getElementById("cp_content").style.background = "#FFE57F";
		document.cadastro.qtd.value = 0;
		x.value = x.value.substring(0,limite);
	}
	
	if (n <=limite) document.cadastro.qtd.value = '' + (limite - n);
	if (wlaczone != 0) setTimeout('policz()', 100);
	else setTimeout('policz()', 1000);
	}
	setTimeout('policz()', 1000);

	
	var wlaczonemais=0;
	
	function policzmais(){		
	
	var x = document.cadastro.mais_informacao;
	var n = x.value.length;
	var limite = 2000;
		
	if (navigator.appName=="Netscape" && wlaczonemais!=0) {
		x.blur();
		x.focus();
	}
	if (n > limite ){
		alert("Limite de 2000 caracteres ultrapassado!");
		document.getElementById("cp_content").style.background = "#FFE57F";
		document.cadastro.qtdmais.value = 0;
		x.value = x.value.substring(0,limite);
	}
	
	if (n <=limite) document.cadastro.qtdmais.value = '' + (limite - n);
	if (wlaczonemais != 0) setTimeout('policzmais()', 2000);
	else setTimeout('policzmais()', 1000);
	}
	setTimeout('policzmais()', 1000);