/**
 * @author Rodrigo
 */


 function envioDatos(){

 	var res1 = ValidaTXT(document.getElementById("txtNombre"));
 	var res2 = ValidaEmail(document.getElementById("txtEmail"));
	var res3 = ValidaTXT(document.getElementById("txtMensaje"));
	var res4 = ValidaTXT(document.getElementById("txtCiudad"));
	var res6 = document.getElementById("ddlDepartamento").value != "--";
			
	var campos = "";
	
	if (!res1) {
		campos += ", Nombre";
	}
	if (!res2) {
		campos += ", E-mail";
	}
	if (!res4) {
		campos += ", Ciudad";
	}
	if (!res6) {
		campos += ", Departamento";
	}
	if (!res3) {
		campos += ", Mensaje";
	}			
 	
	if ((res1) && (res2) && (res3) && (res4) && (res6)) {
 		document.getElementById("frmContacto").submit();
 	}
	else {
		ErrormailContacto(campos.substr(1));
	}
		
 }
 
 function activarControl(id) {
 	
	document.getElementById(id).className += "off";
	
 }
 
 function desactivarControl(id) {
 	
	if (document.getElementById(id).value == "") {
		document.getElementById(id).className = document.getElementById(id).className.replace(/off/g,"");
	}
 }
 
 function OKmailContacto() {
	document.getElementById("divEnviadoOK").style.display = "";
	document.getElementById("divEnviadoERROR").style.display = "none";
 }
 
 function ErrormailContacto(campos) {
 	
	document.getElementById("divEnviadoERROR").innerHTML = "Error el enviar el formulario por favor revise los campos:" + campos + ", para confirmar que haya ingresado correctamente la información requerida"
	
	document.getElementById("divEnviadoERROR").style.display = "";
	document.getElementById("divEnviadoOK").style.display = "none";
 }

 function ValidaTXT(txt) {
	
	if (txt.value=="") {
		return false;
	}
	else {
		return true;
	}
		
 }
 
 function ValidaEmail(txtMail){
       
        if ((txtMail.value==null)||(txtMail.value=="")){
	        return false;
        }
        if (echeck(txtMail.value)==false){
			return false;
        }

        return true;
        
}

function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            return false
         }

         if (str.indexOf(" ")!=-1){
            return false
         }

          return true
          
}
