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;

   if(site != ""){
        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 + " já está cadastrado em nosso sistema";
            document.cadastro.site.value = "";
        } else {
            document.getElementById("carregando").style.display = "none";
        }
    }
}


// ######################################## email ###########################################

ajax.prototype.ocupado_e = function() {
    estadoAtual = this.xmlhttp.readyState;
	document.getElementById("carregando_e").style.display = "block";
    return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa_e = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {        
    return true;
    }
}

ajax.prototype.enviar_e = function(url, metodo, modo) {
    if (!this.xmlhttp) {
        this.iniciar();
    }
    if (!this.ocupado_e()) {
        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_e) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}

function envia_e(url, metodo, modo)
{
    var email = document.getElementById("email").value;
    if(email != ""){
	remoto  = new ajax();
	xmlhttp = remoto.enviar_e(url + "?email=" + email, metodo, modo );	
	if(xmlhttp) {
		    document.getElementById("carregando_e").style.display = "none";
		    document.getElementById("alerta_e").style.display = "block";      
		    document.getElementById("alerta_e").innerHTML = "O email <b>"+email+"</b> já está cadastrado.<br />Caso não lembre de sua senha <a href='http://www.netmultimidia.com.br/?remember=true' target='_blank'>clique aqui</a> para solicitar sua senha.<br />Caso queira cadastrar outro anúncio favor informar um email diferente.";
		    document.cadastro.email.value = "";
		    document.cadastro.email.focus();
	} else {
		    document.getElementById("carregando_e").style.display = "none";
		    document.getElementById("alerta_e").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 n�o 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 Secund�rio deve conter um email correto, ou deixe em branco caso n�o queira colocar um email secund�rio!");
			   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 digitadas n�o 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;
		
	 } 
	   
	   
	    return true;
	    
	
	
}


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 eletronico)
	 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.netmultimidia.com.br/processamento?contato=novo";
	d.submit();
	
}


function validaFormContatoAnunciante(){
	
	d = document.contato_anunciante;
	
	if (d.nome_contato.value == ""){
			alert("Favor preencher seu nome");
			d.nome_contato.focus();
			return false;
	}
	
	//validar email
	 if (d.email_contato.value == ""){
			   alert("O campo Email deve ser preenchido!");			  
			   d.email_contato.focus();
			   return false;
	 }
	
	//validar email(verificao de endereco eletr�nico)
	 parte1 = d.email_contato.value.indexOf("@");
	 parte2 = d.email_contato.value.indexOf(".");
	 parte3 = d.email_contato.value.length;
	 if (!(parte1 >= 1 && parte2 >= 1 && parte3 >= 7)) {
			   alert ("O campo email deve conter um email correto!");			   
			   d.email_contato.focus();
			   return false;
	 }
	 
	 
	  if (d.ddd_contato.value == ""){
				alert("O campo DDD deve ser preenchido!");				
				d.ddd_contato.focus();
				return false;
	 }
	
	if (d.ddd_contato.value.length <= 1 || d.ddd_contato.value == "00" ) {
			   alert ("Favor preencher um DDD correto!");			   
			   d.ddd_contato.value = "";
			   d.ddd_contato.focus();
			   return false;
	}	
		 
	if (d.telefone_contato.value == ""){
				alert("O campo Telefone Principal deve ser preenchido!");				
				d.telefone_contato.focus();
				return false;
	 }
	
	if (d.telefone_contato.value.length <= 8 || d.telefone_contato.value == "1111-1111" || d.telefone_contato.value == "2222-2222" || d.telefone_contato.value == "3333-3333" || d.telefone_contato.value == "4444-4444" || d.telefone_contato.value == "5555-5555" || d.telefone_contato.value == "6666-6666" || d.telefone_contato.value == "7777-7777" || d.telefone_contato.value == "8888-8888" || d.telefone_contato.value == "9999-9999" || d.telefone_contato.value == "0000-0000" ) {
			   alert ("O campo Telefone Principal deve conter um telefone correto!");			  
			   d.telefone_contato.value = "";
			   d.telefone_contato.focus();
			   return false;
	}
	 
	 
	 if ( d.assunto_contato.value == "" ){
			alert("Favor preencher um assunto. Ex: Orcamento");
			d.assunto_contato.focus();
			return false;
	 }
	 
	if ( d.mensagem_contato.value == "" ) {
			   alert ("Favor preecher sua solicitacao no campo mensagem");
			   d.mensagem_contato.focus();
			   return false;
	} 
	 
	 
	if ( d.mensagem_contato.value.length <= 30 ) {
			   alert ("Favor preecher sua solicitacao no campo mensagem com pelo menos 30 caracteres"); 			   
			   d.mensagem_contato.focus();
			   return false;
	}
	
	 
	
	d.action = "http://www.netmultimidia.com.br/processamento?contatoanunciante=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";
        document.getElementById('alerta').style.display = "none";
		d.nsite.value = 1;
		d.site.value = "";
		
		} else {
		
		document.getElementById('site').disabled = false;
		document.getElementById('site').style.backgroundColor = "#ffffff";
		d.nsite.value = 0;
		
		}	
	}	