
/* validator */

var regExps = new Array();
regExps["text1"] = new RegExp("(.)+");
/*regExps["number1"] = new RegExp("^([0-9]+[- /.]*?)+$");
regExps["date"] = new RegExp("^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$");
regExps["time"] = new RegExp("^(0[1-9]|1\\d|2[0-3]):([0-5]\\d)$");
regExps["number2"] = new RegExp("^([0-9]+[- /.]*?)+$");*/
regExps["email"] = new RegExp("^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$");



/* ---------------------------------------------------- */

var contacto_value = new Array();
contacto_value[0] = "name";
contacto_value[1] = "mail";
contacto_value[2] = "message";



var contacto_type = new Array();
contacto_type[0] = "text1";
contacto_type[1] = "email";
contacto_type[2] = "text1";




function checkRegex(str, rxp) {
    if(str.search(rxp)==-1){
        return false;
    } else {
		document.getElementById("imahuman").value = "1";
        return true;
    }
}


function validate(formName, formArr, regexArr) {

    var validated = true
    
    for(var i=0; i<formArr.length; i++) {
        var theLmnt = document.getElementById(formArr[i]);
        var theCheck = checkRegex(theLmnt.value, regExps[regexArr[i]]);
        if(theCheck == false) {
            validated = false;
			theLmnt.style.backgroundImage = "none";
            theLmnt.style.backgroundColor = "#e2eef3";
			 
        } else {
			theLmnt.style.backgroundImage = "none";
            theLmnt.style.backgroundColor = "#ffffff";
        }
    }	
    if( document.getElementById('ok_privacity').checked == true){
    	if(validated == false){
			alert("Por favor, revisa los campos en azul. Hay algo que no está del todo bien.");
		} else if (validated == true){
			/*alert("Gracias, te contestaremos lo antes posible.");	*/
    	    document.forms[formName].submit();
		}
	}
    if (document.getElementById('ok_privacity').checked == false){
    	if(validated == false) {
        	alert("Por favor, revisa los campos en azul. Y no olvides aceptar la política de privacidad.");	
    	} else if (validated == true) {
        	alert("No olvides aceptar la política de privacidad.");	
        }
    }


}
