// JavaScript Document

function formValidator_contactus()
{
    // Make quick references to our fields
    var fname = document.getElementById('fname');
    var lname = document.getElementById('lname');
    var workPhone = document.getElementById('workPhone');
    var email = document.getElementById('email');
    var cu_captcha = document.getElementById('cu_captcha');
    // Check each input in the order that it appears in the form!
    if(isNotEmpty(fname, "Please enter your first name."))
        if(isNotEmpty(lname, "Please enter your last name."))
            if(isNotEmpty(workPhone, "Please Enter Phone."))
                if(emailValidator(email, "Please enter valid Email id."))
                    if(isNotEmpty(cu_captcha, "Please Enter Security Code."))
                        return true;
    return false;
}

function formValidator_customerregistration()
{
    // Make quick references to our fields
    var txtusername = document.getElementById('txtusername');
    var txtpwd = document.getElementById('txtpwd');
    var txtcpwd = document.getElementById('txtcpwd');
    var txtfname = document.getElementById('txtfname');
    var txtlname = document.getElementById('txtlname');
    var txtlname = document.getElementById('txtlname');
    var txtphone = document.getElementById('txtphone');
    var txtemail = document.getElementById('txtemail');
    var txtcemail2 = document.getElementById('txtcemail2');
    var crcaptcha = document.getElementById('crcaptcha');
    // Check each input in the order that it appears in the form!
    if(isNotEmpty(txtusername, "Please enter your login name."))
        if(isNotEmpty(txtpwd, "Please enter your password"))
        if(isNotEmpty(txtcpwd, "Please enter your Retype password."))
        if(CompairValidator(txtpwd,txtcpwd, "Password do not match with each other."))
        if(isNotEmpty(txtfname, "Please enter your first name."))
        if(isNotEmpty(txtlname, "Please enter your last name."))
        if(isNotEmpty(txtphone, "Please enter phone no."))
        if(emailValidator(txtemail, "Please enter your valid email id."))
        if(emailValidator(txtcemail2, "Please enter Confirm Email id."))
        if(CompairValidator(txtemail,txtcemail2, "Email do not match with each other."))
        if(isNotEmpty(crcaptcha, "Please Enter security letter code."))
        return true;

    return false;
}


function isAlphabet(elem, helperMsg){
    var alphaExp = /^[a-zA-Z ]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function emailValidator(elem, helperMsg){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}
function isNumeric(elem, helperMsg){
    var numericExpression = /^[0-9]+$/;
    if(elem.value.match(numericExpression)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}
function isNotEmpty(elem, helperMsg)
{
    if (elem.value.trim()=='')
        {
        alert(helperMsg);
        elem.focus();
        return false;
    }
    else
        {
        return true;
    }
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function radioValidation(radiosbtn, helperMsg)
{
    var ctr=0;
    for(var i=0;i<radiosbtn.length;i++)
        {
        if(radiosbtn[i].checked)
            {
            ctr=1;
        }
    }
    if(ctr <= 0)
        {
        alert(helperMsg);
        return false;
    }
    else return true;
}

function CompairValidator(ele1,ele2, helperMsg)
{
    var ctr=0;
    if(ele1.value!=ele2.value)
        {
        alert(helperMsg);
        return false;
    }
    return true;
}
