//===========================================================================
// FUNÇÕES GENÉRICAS
//===========================================================================
function validaVazio(obj, msgErro) {
    if (obj.value == "") {
	   alert(msgErro);
	   obj.focus();
	   return true;
    }
    return false;
}
function valida_mail(valor) {
	   prim = valor.indexOf("@")
	   if(prim < 1) return false;
	   if(valor.indexOf("@",prim + 1) != -1) return false;
	   if(valor.indexOf(".") < 1) return false;
	   if(valor.indexOf("zipmeil.com") > 0) return false;
	   if(valor.indexOf("hotmeil.com") > 0) return false;
	   if(valor.indexOf(".@") > 0) return false;
	   if(valor.indexOf("@.") > 0) return false;
	   if(valor.indexOf(".com.br.") > 0) return false;
	   if(valor.indexOf("/") > 0) return false;
	   if(valor.indexOf("[") > 0) return false;
	   if(valor.indexOf("]") > 0) return false;
	   if(valor.indexOf("(") > 0) return false;
	   if(valor.indexOf(")") > 0) return false;
	   if(valor.indexOf("..") > 0) return false;
	   if(valor.indexOf(",") > 0) return false;
	   return true;
}

function formata(campo, mask, evt) { 

    if(document.all) { // Internet Explorer 
	  key = evt.keyCode; } 
	  else{ // Nestcape 
           key = evt.which; 
    } 

    teclasPermitidas = Array(0, 8, 13);
    for (i=0; i < teclasPermitidas.length; i++) {
		if (key == teclasPermitidas[i]) return true;
    }

    string = campo.value;  
    i	   = string.length;

    if (i < mask.length) {
    	if (mask.charAt(i) == '§') {

    return (key > 47 && key < 58);

    } else {

    if (mask.charAt(i) == '!') {  return true;  }

    for (c = i; c < mask.length; c++) {

    if (mask.charAt(c) != '§' && mask.charAt(c) != '!')

    campo.value = campo.value + mask.charAt(c);

    else if (mask.charAt(c) == '!'){

    return true;

    } else {

    return (key > 47 && key < 58);

    }

    }

    }

    } else return false;

}

//===========================================================================

//===========================================================================
// FORMULÁRIO DE CONTATO
//===========================================================================
function validaContato(form) {

	var erro 	  = false;
	var cont_erro = 0;	
	
	if (form.nome.value == "") {
		cont_erro++;
		msg  = "<li>" + cont_erro + "- Campo nome é <strong>obrigatório</strong></li>";
		erro = true;
	}

	if (form.sobrenome.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo sobrenome é <strong>obrigatório</strong></li>";
		erro = true;
	}
	
	if (form.email.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo email é <strong>obrigatório</strong></li>";
		erro = true;
	}else if (!valida_mail(form.email.value)) {
		  cont_erro++;
		  msg += "<li>" + cont_erro + "- Campo email parece ser <strong>inválido</strong></li>";
		  erro = true;
	}	
	if (form.mensagem.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo mensagem é <strong>obrigatório</strong></li>";
		erro = true;
	}	

	if (erro) {
		document.getElementById("erro").style.display = "block";
		document.getElementById("ulErro").innerHTML   = msg;
		return false;
	} else {
		/*url = "login.php";
		tipo = "checaUsuario";
		tipo_envio = "POST";
		form_envio = form;
		loadXMLDoc(url);*/
	
		return true;
	}

}
//===========================================================================
