//  (c) 2007 Wilke/Thornton, Inc.
//
//  File:      ContactUs.js
//  Created:   July 9, 2007 - Alan J. Stein
//  Modified:  mmmm dd, yyyy - developer - projnum - comment
//

var scRequiredFields = 'imp_first_name,First Name|imp_last_name,Last Name|' +
                       'imp_email,E-mail Address|' +
                       'imp_company,Company';
var scState = 'load';
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;
        }
    }
    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';
    document.getElementById('imp_first_name').focus();
}

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;

}
