function mValidaEmail(id){
	var email = document.getElementById(id).value;
	var erro = 0;
	
	if (typeof(email) != "string") erro++;
    else if (!email.match(/^[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/)) erro++;

	if(erro != 0){
		if (document.getElementById(id).value != "") {
			alert ("Email inválido!");
			document.getElementById(id).focus();
		}
		return false;
	}else return true;
}

function mMascaraTelefone(Campo, e) {
    var key = "";
    var len = 0;
    var strCheck = "0123456789";
    var aux = "";
    var whichCode = (window.Event) ? e.which : e.keyCode;
    
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true; 
    key = String.fromCharCode(whichCode); 
    if (strCheck.indexOf(key) == -1) return false;
    
    aux =  Telefone_Remove_Format(Campo.value); 
    
    len = aux.length; 
    if(len >= 10) return false;
    aux += key; 
     
    Campo.value = Telefone_Mont_Format(aux); 
    return false; 
} 
function Telefone_Mont_Format(Telefone){ 
    var aux = len = ""; 
    len = Telefone.length; 
    
    if(len <= 9) tmp = 6; 
    else tmp = 6;
    
    aux = ""; 
    for(i = 0; i < len; i++){ 
        if(i == 0)aux = "("; 
        aux += Telefone.charAt(i); 
        if(i+1 == 2) aux += ") "; 
        
        if(i+1==tmp) aux += "-";
    } 
    return aux ; 
} 
function Telefone_Remove_Format(Telefone){ 
    var strCheck = "0123456789"; 
    var len = i = aux = ""; 
    len = Telefone.length; 
    for(i = 0; i < len; i++){ 
        if (strCheck.indexOf(Telefone.charAt(i))!= -1) aux += Telefone.charAt(i);
    } 
    return aux; 
}

//para inforamtivo
function confere(id,param,valor) {
	if (param == 1) {
		if (document.getElementById(id).value == valor) document.getElementById(id).value = "";
	} else {
		if (document.getElementById(id).value == "") document.getElementById(id).value = valor;
	}
}

//para inforamtivo
function mEnviaEmail() {
	if (mValidaEmail("emailEmail")) {
		ajaxForm("cadastro","formEmails");
	}
	return false;
}
/*
* Função para alternar style.diplay
*/
function mDisplay(id) {
	if (document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "";
	} else {
		document.getElementById(id).style.display = "none";
	}
}
var ultimo;
function mControlaLayer(id){
	vis = document.getElementById(id).style.display;
	if(vis == "none"){
		$('div#'+id).fadeIn("slow");
		if(ultimo != id && ultimo != undefined){
			$('div#'+ultimo).slideUp("fast");
		}
	} else {
		$('div#'+id).slideUp("fast");
	}
	ultimo = id;
}
var ultimo2;
