

function validateDormNewsletter(){
    if ((document.getElementById("txtNewsletter").value == "") || (document.getElementById("txtNewsletter").value == "join our mailing list")) {
        // document.getElementById("awf_field-7122314").value = "Email *";
        document.getElementById("txtNewsletter").style.color = '#FD0000';
        document.getElementById("txtNewsletter").style.borderColor = '#FD0000';
        document.getElementById("txtNewsletter").style.border = '1px solid';
        flagError = "1";

    }
    else if (validateEmailAddress(document.getElementById("txtNewsletter")) == false) {
        // document.getElementById("awf_field-7122314").value = "Illegal Characters";
        document.getElementById("txtNewsletter").style.color = '#FD0000';
        document.getElementById("txtNewsletter").style.borderColor = '#FD0000';
        document.getElementById("txtNewsletter").style.border = '1px solid';
        flagError = "1";

    }

    if (flagError == "1") {
        flagError = "0";
        return false;
    }
    else {
        return true;
    }
}


function validateFormQuote() {

    if ((document.getElementById("name").value == "") || (document.getElementById("name").value == "name")) {
        // document.getElementById("awf_field-7122313").value = "Name *";
        document.getElementById("name").style.color = '#FD0000';
        document.getElementById("name").style.borderColor = '#FD0000';
        document.getElementById("name").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("company").value == "") || (document.getElementById("company").value == "company")) {
        // document.getElementById("awf_field-7122313").value = "Name *";
        document.getElementById("company").style.color = '#FD0000';
        document.getElementById("company").style.borderColor = '#FD0000';
        document.getElementById("company").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("phone").value == "") || (document.getElementById("phone").value == "phone")) {
        // document.getElementById("awf_field-7122313").value = "Name *";
        document.getElementById("phone").style.color = '#FD0000';
        document.getElementById("phone").style.borderColor = '#FD0000';
        document.getElementById("phone").style.border = '1px solid';
        flagError = "1";
    }
    if (document.getElementById("phoneblank").value == "")  {
        document.getElementById("phoneblank").style.color = '#FD0000';
        document.getElementById("phoneblank").style.borderColor = '#FD0000';
        document.getElementById("phoneblank").style.border = '1px solid';
        flagError = "1";
    }
    if (document.getElementById("inquiry").value == "") {
        document.getElementById("inquiry").style.color = '#FD0000';
        document.getElementById("inquiry").style.borderColor = '#FD0000';
        document.getElementById("inquiry").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("quantity").value == "") || (document.getElementById("quantity").value == "quantity")) {
        document.getElementById("quantity").style.color = '#FD0000';
        document.getElementById("quantity").style.borderColor = '#FD0000';
        document.getElementById("quantity").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("size").value == "") || (document.getElementById("size").value == "size")) {
        document.getElementById("size").style.color = '#FD0000';
        document.getElementById("size").style.borderColor = '#FD0000';
        document.getElementById("size").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("special").value == "") || (document.getElementById("special").value == "Special Instructions")) {
        document.getElementById("special").style.color = '#FD0000';
        document.getElementById("special").style.borderColor = '#FD0000';
        document.getElementById("special").style.border = '1px solid';
        flagError = "1";
    }
    if ((document.getElementById("email").value == "") || (document.getElementById("email").value == "email")) {
        // document.getElementById("awf_field-7122314").value = "Email *";
        document.getElementById("email").style.color = '#FD0000';
        document.getElementById("email").style.borderColor = '#FD0000';
        document.getElementById("email").style.border = '1px solid';
        flagError = "1";

    }
    else if (validateEmailAddress(document.getElementById("email")) == false) {
        // document.getElementById("awf_field-7122314").value = "Illegal Characters";
        document.getElementById("email").style.color = '#FD0000';
        document.getElementById("email").style.borderColor = '#FD0000';
        document.getElementById("email").style.border = '1px solid';
        flagError = "1";

    }

    if (flagError == "1") {
        flagError = "0";
        return false;
    }
    else {
        return true;
    }
}

function changeValue(id,value) {


    if ((value == "join our mailing list") || (value == "name") || (value == "company") || (value == "email") || (value == "phone") || (value == "quantity") || (value == "size") || (value == "Special Instructions")) {
        document.getElementById(id).value = "";
    } 

    
}
function putDefault(id,value) {


    if (id == "txtNewsletter") {

        if (value == "") {
            document.getElementById(id).value = "join our mailing list";
        }
    }
    else if (id == "name") {
        if (value == "") {
            document.getElementById(id).value = "name";
        }
    }
    else if (id == "company") {
        if (value == "") {
            document.getElementById(id).value = "company";
        }
    }
    else if (id == "email") {
        if (value == "") {
            document.getElementById(id).value = "email";
        }
    }
    else if (id == "phone") {
        if (value == "") {
            document.getElementById(id).value = "phone";
        }
    }
    else if (id == "quantity") {
        if (value == "") {
            document.getElementById(id).value = "quantity";
        }
    }
    else if (id == "size") {
        if (value == "") {
            document.getElementById(id).value = "size";
        }
    }
    else if (id == "special") {
        if (value == "") {
            document.getElementById(id).value = "Special Instructions";
        }
    }
   
   
    
}
function validateFormRequest()
{

    if ((document.getElementById("awf_field-7122313").value == "")||(document.getElementById("awf_field-7122313").value == "Name *"))
    {
       // document.getElementById("awf_field-7122313").value = "Name *";
        document.getElementById("awf_field-7122313").style.color = '#FD0000';
        document.getElementById("awf_field-7122313").style.borderColor = '#FD0000';

        flagError = "1";


    }
    else if ((document.getElementById("awf_field-7122313").value != "")||(document.getElementById("awf_field-7122313").value != "Name *"))
    {
        var validation_return = checkForSpecialCharactersRegistration(document.getElementById("awf_field-7122313"));
        if (validation_return == true)
        {
          //  document.getElementById("awf_field-7122313").value = "Illegal Characters";
        document.getElementById("awf_field-7122313").style.color = '#FD0000';
        document.getElementById("awf_field-7122313").style.borderColor = '#FD0000';;
            flagError = "1";

        }
    }
    

    if ((document.getElementById("awf_field-7122314").value == "")||(document.getElementById("awf_field-7122314").value == "Email *"))
    {
        // document.getElementById("awf_field-7122314").value = "Email *";
        document.getElementById("awf_field-7122314").style.color = '#FD0000';
        document.getElementById("awf_field-7122314").style.borderColor = '#FD0000';
        flagError = "1";

    }
     else if (validateEmailAddress(document.getElementById("awf_field-7122314")) == false)  {
       // document.getElementById("awf_field-7122314").value = "Illegal Characters";
        document.getElementById("awf_field-7122314").style.color = '#FD0000';
        document.getElementById("awf_field-7122314").style.borderColor = '#FD0000';
        flagError = "1";

    }
    

if ((document.getElementById("awf_field-7122315").value == "")||(document.getElementById("awf_field-7122315").value == "Phone *"))
    {
        // document.getElementById("awf_field-7122315").value = "Phone *";
        document.getElementById("awf_field-7122315").style.color = '#FD0000';
        document.getElementById("awf_field-7122315").style.borderColor = '#FD0000';
        flagError = "1";

    }

    else if ((document.getElementById("awf_field-7122315").value != "")||(document.getElementById("awf_field-7122315").value != "Phone *")) 
    {
        var validation_return = checkForSpecialCharactersPhone(document.getElementById("awf_field-7122315"));
        if (validation_return == true)
        {
          //  document.getElementById("awf_field-7122315").value = "Illegal Characters";
        document.getElementById("awf_field-7122315").style.color = '#FD0000';
        document.getElementById("awf_field-7122315").style.borderColor = '#FD0000';
            flagError = "1";

        }
    }

if ((document.getElementById("awf_field-7122316").value == "")||(document.getElementById("awf_field-7122316").value == "Company Website *"))
    {
        //document.getElementById("awf_field-7122316").value = "Company Website *";
        document.getElementById("awf_field-7122316").style.color = '#FD0000';
        document.getElementById("awf_field-7122316").style.borderColor = '#FD0000';
        flagError = "1";
    }
    else if (document.getElementById("awf_field-7122316").value != "")
    {
        var validation_return = validateURL(document.getElementById("awf_field-7122316"));
        //alert("validation_return ="+validation_return);
        if (validation_return == false)
        {
           // document.getElementById("awf_field-7122316").value = "Illegal Characters";
        document.getElementById("awf_field-7122316").style.color = '#FD0000';
        document.getElementById("awf_field-7122316").style.borderColor = '#FD0000';
            flagError = "1";
        }
    }

    if (flagError == "1")
    {
        flagError = "0";
        return false;
    }
    else
    {
        return true;
    }

}


function validateFormContact()
{

    if (document.getElementById("firstname").value == "")
    {
        document.getElementById("error1").style.display = "block";
        flagError = "1";


    }
    else if (document.getElementById("firstname").value != "")
    {
        var validation_return = checkForSpecialCharactersRegistration(document.getElementById("firstname"));
        if (validation_return == true)
        {
            document.getElementById("illerror1").style.display = "block";
            flagError = "1";

        }
    }
    if (document.getElementById("lastname").value == "")
    {
        document.getElementById("error2").style.display = "block";
        flagError = "1";

    }
    else if (document.getElementById("lastname").value != "")
    {
        var validation_return = checkForSpecialCharactersRegistration(document.getElementById("lastname"));
        if (validation_return == true)
        {
            document.getElementById("illerror2").style.display = "block";
            flagError = "1";

        }
    }

    if (document.getElementById("email").value == "")
    {
        document.getElementById("error3").style.display = "block";
        flagError = "1";

    }
    else if (validateEmailAddress (document.getElementById("email")) == false) {
        document.getElementById("illerror3").style.display = "block";
        flagError = "1";

    }
    if (document.getElementById("company").value == "")
    {
        document.getElementById("error5").style.display = "block";
        flagError = "1";

    }
    if (document.getElementById("query").value == "")
    {
        document.getElementById("error4").style.display = "block";
        flagError = "1";

    }
    else if (document.getElementById("query").value != "")
    {
        var validation_return = checkForSpecialCharactersCompanyAddress(document.getElementById("query"));
        if (validation_return == true)
        {
            document.getElementById("illerror4").style.display = "block";
            flagError = "1";

        }
    }


    if (flagError == "1")
    {
        flagError = "0";
        return false;
    }
    else
    {
        return true;
    }

}

function allGood(email,id)
{
    if(id)
    {
//document.getElementById(id).value = "";
       
document.getElementById("error"+id).style.display = 'none';
document.getElementById("illerror"+id).style.display = 'none';
       
    
    }


}

function checkForSpecialCharactersRegistration (field) {

    var entry = field.value;

    for (var i = 0; i < entry.length; i++) {

        var j = entry.charCodeAt(i);

        if (j < 32) { // allowing . SPACE

            return true;
        }

        if (j >32 && j < 65) { // allowing . SPACE

            return true;
        }

        if (j > 90 && j < 97) {

            return true;

        }

        if (j > 122) {
            return true;
        }
    }

    return false;
}

function validateEmailAddress (field) {


    if (spacesInEntry(field)) {

        // alert ('Invalid Email Address! No spaces are allowed');
        field.select();
        field.focus();
        return false;
    }


    var emailAddress = field.value.split("@");
    if (emailAddress.length != 2) {

        // alert ('Invalid Email Address!');
        field.select();
        field.focus();
        return false;
    } else {

        if (emailAddress[0] == '') {

            //alert ('Invalid Email Address!');
            field.select();
            field.focus();
            return false;
        }

        emailAddress[0] = emailAddress[0].replace ( / /g, ""); // replace spaces globablly

        if (emailAddress[0].length == 0) {

            // alert ('Invalid Email Address!');
            field.select();
            field.focus();
            return false;
        }

        if (checkEmailUserName(emailAddress[0]) == false) {
            //alert ('Invalid username for the email address!');
            field.select();
            field.focus();
            return false;
        }
    }
    var domainAddress = emailAddress[emailAddress.length - 1].split(".");

    if (domainAddress.length < 2) {
        // alert ('Invalid Email Address!');
        field.select();
        field.focus();
        return false;
    } else {

        for (var j = 0; j < domainAddress.length; j++) {

            if (domainAddress[j] == '') {

                // alert ('Invalid Email Address!');
                field.select();
                field.focus();
                return false;
            }
        }
    }
    return true;
}

function checkForSpecialCharactersPhone (field) {

    var entry = field.value;

    for (var i = 0; i < entry.length; i++) {

        var j = entry.charCodeAt(i);

        if (j < 32) { // allowing . SPACE

            return true;
        }
        if (j < 45 && j > 32) { // allowing . SPACE

            return true;
        }
        if (j > 46 && j < 48) {
            return true;
        }
        if (j > 57) {
            return true;
        }
    }
    return false;
}

function validateURL(field)
{
    return /^(ftp|https?:\/\/)?(www\.){0,1}[a-z0-9\-\.]{3,}\.[a-z]{2,}[\:^0-9]{0,7}$/.test(field.value);
//return /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(field.value);
//return /^[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(field.value);

}

function spacesInEntry (field) {
    var entry = field.value;
    var originalLength = entry.length;

    var temp = entry.replace (/ /g, "");
    var tempLength = temp.length;

    if (originalLength != tempLength) {


        return true;
    }
    return false;
}

function checkEmailUserName(emailId) {


    //letters(a-z),numbers(0-9),underscore(_),dot(.) and hyphen(-)


    for (var i = 0; i < emailId.length; i++) {

        var j = emailId.charCodeAt(i);
        if (j == 45 || j == 46 || j == 95) { // . - _ allowed
            continue;
        }
        if (isCharacterAlpha(j) == false && isCharacterNumerical(j) == false) {
            return false;

        }

    }
    return true;
}

function isCharacterAlpha (charCode) {

    var upperCase = false, lowerCase = false;

    // A - Z : 65 - 90, a -z : 97 - 122

    if (charCode >= 65 && charCode <= 90) {
        upperCase = true;
    }

    if (charCode >= 97 && charCode <= 122) {
        lowerCase = true;
    }

    return lowerCase || upperCase;
}

function checkForSpecialCharactersCompanyAddress (field) {

    var entry = field.value;

    for (var i = 0; i < entry.length; i++) {

        var j = entry.charCodeAt(i);

        if (j < 32) { // allowing . SPACE

            return true;
        }
        if (j>32 && j < 35) { // allowing . SPACE

            return true;
        }
        if (j>57 && j < 65) { // allowing . SPACE

            return true;
        }
        if (j>125) { // allowing . SPACE

            return true;
        }
    }
    return false;
}
