function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

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
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que nao é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parenteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}






function checkrequired(form) {
	var pass = true;
	for(i = 0; i < form.length; i++) {
		var tempobj = form.elements[i];
		if(tempobj.alt == "required") {
			if(tempobj.value == '') {
				pass = false;
				break;
			}
		}
	}
	if(!pass) {
		alert("Entre com as informaçoes solicitadas.");
		tempobj.focus(); 
		return false;
	}
	else { return true; } 
}


function checkemail(form,campo) {
 if (campo.value!=""){	
	if (campo.value.indexOf ('@',0) == -1 ||  campo.value.indexOf ('.',0) == -1) {
		alert ("Por Favor, preencha corretamente o seu e-mail!");
		campo.value="";
		campo.focus();
		return false;
	}
 }
}

function toUnicode ( elmnt,content ){ 
     if ( content.length==elmnt.maxLength ){ 
       next=elmnt.tabIndex 
       if ( next<document.forms [ 0 ] .elements.length ){ 
         document.forms [ 0 ] .elements [ next ] .focus () 
     } 
   } 
} 



try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}



function grava(obj){
if (document.getElementById('email').value=="Email")	
   { alert('Informe seu email');
     document.getElementById('email').focus();
	 return false;
   }
else
  {
   document.getElementById('email').className = 'pass';  
  }


if (document.getElementById('email').value.indexOf ('@',0) == -1 ||  document.getElementById('email').value.indexOf ('.',0) == -1) {
    alert ("Por Favor, preencha corretamente o seu e-mail!");
	document.getElementById('email').focus();
	return false;
}
    ecampo1 = document.getElementById('email').value; //recupera o segundo campo
	
	url = "news.php?email="+ecampo1;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
			if (xmlhttp.responseText==1) {
  			   alert('Obrigado por se cadastrar em nosso newsletter');
		       document.getElementById("email").value = 'Email';
	          }
		    else{
			    alert('Email já cadastrado em nosso banco');
		  	    return false;
			    }
	  	  }
	}
	 xmlhttp.send(null)
}


function login_projetos(obj){
if (document.getElementById('usuario').value=="Usuário")	
   { alert('Informe seu usuário');
     document.getElementById('usuario').focus();
	 return false;
   }

if (document.getElementById('senha').value=="Senha")	
   { alert('Informe sua senha');
     document.getElementById('senha').focus();
	 return false;
   }


    ecampo1 = document.getElementById('usuario').value; //recupera o segundo campo
    ecampo2 = document.getElementById('senha').value; //recupera o segundo campo
	
	url = "login.php?username="+ecampo1+"&password="+ecampo2;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
			if (xmlhttp.responseText==1) {
		       document.getElementById("usuario").value = 'Usuário';
		       document.getElementById("senha").value = 'Senha';
			   window.location = '?idkey=55';
	          }
		    else{
			    alert('Usuário năo cadastrado');
		  	    return false;
			    }
	  	  }
	}
	 xmlhttp.send(null)
}


