//  (c) 2005 Wilke/Thornton, Inc.
//
//  File:      ContactUs.js
//  Created:   October 18, 2005 - Alan J. Stein
//  Modified:  Jan 05, 2007 - Anne D. Ryan - converted HABI page from FrontPage
//                            to our standard Contact Us which uses js & asp.
//

var scRequiredFields = 'imp_first_name,First Name|imp_last_name,Last Name|' +
                       'imp_address,Address|imp_city,City|imp_state,State/Province|imp_zip,Zip/Postal Code|imp_country,Country|' +
                       'imp_phone,Daytime Phone|imp_email,Email|imp_verify_email,Verify Email|' +
                       'imp_product,Product|imp_comments,Comments';
var scState = 'load';
var siCommentsMaxLength = 1000;
var siMaxUrlFields = 9;

function AnyErrors() {
    var bReturn;
    var caFieldLabel;
    var caRequiredFields;
    var cField;
    var cLabel;
    var iField;
    var oElem;

    bReturn = false;
    cMsg = '';
    caRequiredFields = scRequiredFields.split("|");
    for (iField = 0; iField < caRequiredFields.length; iField++) {
        caFieldLabel = caRequiredFields[iField].split(",");
        cField = caFieldLabel[0];
        cLabel = caFieldLabel[1];
        if (document.getElementById(cField).value == "") {
            cMsg = cMsg + '\n' + cLabel;
        }
        else if (document.getElementById(cField).value == "Select one...") {
            cMsg = cMsg + '\n' + cLabel;
        }
    }
    if (cMsg.length > 0) {
        alert ("Please enter values for the following required fields:" + cMsg);
        bReturn = true;
    }

    if (document.frmEntry.imp_email.value != document.frmEntry.imp_verify_email.value) {
        alert ("The values for 'Email' and 'Verify Email' do not match.");
        bReturn = true;
    }

    return bReturn;
}



function bdyPage_OnLoad() {
    var cFieldName;
    var cFieldValue;
    var iUrlField;
    var iPosBeg;
    var iPosEnd;
    var oElem;
    var sUrlSearch;
    var sUrlFields;

    sUrlSearch = document.location.search;
    if (sUrlSearch.length > 1) {
        sUrlFields = '&' + sUrlSearch.substr(1) + '&';
        for (iUrlField = 1; iUrlField <= siMaxUrlFields; iUrlField++) {
            cFieldName = "F" + iUrlField;
            iPosBeg = sUrlFields.indexOf("&" + cFieldName + "=", 0);
            if (iPosBeg > -1) {
                iPosBeg = sUrlFields.indexOf("=", iPosBeg);
                iPosEnd = sUrlFields.indexOf("&", iPosBeg);
                cFieldValue = sUrlFields.substring(iPosBeg + 1, iPosEnd);
                oElem = document.getElementById(cFieldName);
                oElem.value = cFieldValue;
            }
        }
    }
    scState = 'ready';
}

function frmEntry_OnSubmit() {
    if (scState == 'post') {
        return false;
    }

    scState = 'post';
    if (AnyErrors() == true) {
        scState = 'ready';
        return false;
    }

    document.frmEntry.method = 'post';
    document.frmEntry.target = "fmeResponse";
    document.frmEntry.action = "ProcessContactUs.asp";
    document.frmEntry.submit();
    return false;
}

function imp_comments_OnKeyPress() {
    var bReturn;
    var sValue;

    bReturn = true;
    sValue = document.frmEntry.imp_comments.value;
    if (sValue.length >= siCommentsMaxLength ) {
        alert ('Only ' + siCommentsMaxLength + ' characters may be entered.');
        document.frmEntry.imp_comments.value = sValue.substring(0, siCommentsMaxLength - 1);
        bReturn = false;
    }
    return bReturn;
}

