﻿
function isBlank(val) {
    if (val == null) { return true; }
    for (var i = 0; i < val.length; i++) {
        if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) { return false; }
    }
    return true;
}
function setNullIfBlank(obj) { if (isBlank(obj.value)) { obj.value = ""; } }


function valCharNumb(strValue) {
    var blnValid = true;
    var strChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789'-";
    var strCheck;
    var i, j, ch;
    if (strValue.length == 0) {
        blnValid = false
    }
    strCheck = strValue
    for (i = 0; i < strCheck.length; i++) {
        ch = strCheck.charAt(i);
        for (j = 0; j < strChars.length; j++)
            if (ch == strChars.charAt(j)) {
            break
        }
        if (j == strChars.length) {
            blnValid = false;
            break
        }
    }
    return blnValid
}

function Validate(theForm) {

    if (theForm.FirstName.value == "") {
        alert("Introduzca su nombre de pila");
        theForm.FirstName.focus();
        return (false);
    }


    if (!valCharNumb(theForm.FirstName.value)) {
        alert("Nombre: Introduzca caracteres válidos.");
        theForm.FirstName.focus();
        return (false);
    }



    if (theForm.LastName.value == "") {
        alert("Introduzca su apellido");
        theForm.LastName.focus();
        return (false);
    }


    if (!valCharNumb(theForm.LastName.value)) {
        alert("Apellido: Introduzca caracteres válidos.");
        theForm.LastName.focus();
        return (false);
    }


    // BEGIN: email validation

    var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

    function checkmail(e) {
        var returnval = emailfilter.test(e)
        if (returnval == false) {
        }
        return returnval
    }

    if (!checkmail(theForm.EMail.value)) {
        alert("Introduzca una dirección de correo electrónico válida, \n por ejemplo, usuario@dominio.com. ");
        theForm.EMail.focus();
        return (false);
    }


    // END: email validation

    function PhoneNumber(strValue) {
        var blnValid = true;
        var strChars = "0123456789-+(). ";
        var strCheck;
        var i, j, ch;
        if (strValue.length == 0) {
            blnValid = false
        }
        strCheck = strValue
        for (i = 0; i < strCheck.length; i++) {
            ch = strCheck.charAt(i);
            for (j = 0; j < strChars.length; j++)
                if (ch == strChars.charAt(j)) {
                break
            }
            if (j == strChars.length) {
                blnValid = false;
                break
            }
        }
        return blnValid
    }


    if (!PhoneNumber(theForm.Phone.value)) {
        alert("Introduzca un número de teléfono válido");
        theForm.Phone.focus();
        theForm.Phone.value = ""
        return (false);
    }

    if (theForm.HomeCountry.value == "0") {
        alert("Seleccione un país");
        theForm.HomeCountry.focus();
        return (false);
    }

    if (typeof theForm.btn_submit != 'undefined') { // disable demo form submit button 
        document.getElementById("btn_submit").disabled = true;
    }

    gotham_demo_form_submit_btn(); //gotham form submission
    OmnitureDemoFormSubmission(this); // omniture function in s_code (pass uk confirmation to report suite)


    setTimeout("pause()", 1750); // pause the form submission 
    return false;
}

function pause() {
    document.forms[0].submit();
    return false;
}
//-->
