//$(function () {
//    $("form input").keypress(function (e) {
//        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
//            var oBtn = new getObj(GetKeyDownButton());
//            if (oBtn.obj != null
//                && oBtn.obj.disabled != true
//                && oBtn.style.visibility != "hidden"
//                && oBtn.style.display != "none") {
//                oBtn.obj.click();
//                oBtn.obj.focus();
//            }
//            return false;
//        } else {
//            return true;
//        }
//    });
//});


//function keypresshandler(e) {
//    // if Enter-Key is pressed, click the passed button
//    if (e.keyCode == 13) {
//        var oBtn = new getObj(GetKeyDownButton());
//        if (oBtn.obj != null
//            && oBtn.obj.disabled != true
//            && oBtn.style.visibility != "hidden"
//            && oBtn.style.display != "none") {
//            oBtn.obj.focus();
//            oBtn.obj.click();
//        }
//    }
//}

//// Cross-browser event listener
//if (document.addEventListener) {
//    document.addEventListener('keypress', keypresshandler, false); // For Presto and Gecko
//}
//else if (document.attachEvent) {
//    document.attachEvent("onkeypress", keypresshandler); // For Trident/IE
//}

//this function will disable all submit buttons on a form and replace them with spans, once a submit button
// has been pressed 
// Update: submit button is now disabled, no span swapping occurs.

//function DisableFormMethod() {
//    var theForm = document.forms['form1'];
//    if (!theForm) {
//        theForm = document.forms['Form1'];
//    }
//    if (!theForm) {
//        theForm = document.form1;
//    }

//    var SubmitOnce = false;
//    for (var i = 0; i < theForm.length; i++) {
//        var oButton = theForm.elements[i];
//        if (oButton.type.toLowerCase() == "submit" && oButton.style.display != "none") {
//            SubmitOnce = true;
//            var oSpan = new getObj(oButton.id + "_span");
//            if (oSpan.obj != null) {
//                oButton.style.display = "none";
//                //oButton.obj.disabled="true";
//                oSpan.obj.innerHTML = oButton.value;
//                oSpan.style.display = "inline";
//                oSpan.style.width = oButton.style.width;
//            }
//        }
//    }
//    if (SubmitOnce) {
//        theForm.submit();
//    }
//}

function expired(endDateId, strMessage) {
    var EndDateObj = document.getElementById(endDateId);

    if (EndDateObj != null && EndDateObj.value.length > 0) {
        var today = new Date();
        var expDate = Date.parse(EndDateObj.value);

        if (today > expDate) {
            //expired promo date
            return confirm(strMessage);
        }
    }

    return true;
}

function XMLHttpRequestor() {
    var xmlhttp;
    if (window.ActiveXObject) {
        // use the ActiveX control for IE5.x and IE6
        // Esoteric Javascript to grab the proper version of the ActiveX control
        /*@cc_on@*/
        /*@if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
            return xmlhttp;

        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                return xmlhttp;

            } catch (E) {
                return null;
            }
        }
        @else
             return null;
     @end
        @*/
    }
    else {
        if (window.XMLHttpRequest) {
            // If IE7, Mozilla, Safari, etc: Use native object
            xmlhttp = new XMLHttpRequest();
            xmlhttp.isDOM = true;
            return xmlhttp;
        }
    }
}
var req;

function SynchRequestXML(url, parameters) {
    // Grab a valid ActiveX XMLHTTPRequest object
    req = XMLHttpRequestor();
    // IF a valid ActiveX object was not returned then return false
    if (!req)
        return null;
    // Call the web page
    //req.onreadystatechange = LookupZipCallback(); *** for ASYNC only


    req.open("POST", url, false);
    if (req.overrideMimeType) {
        req.setRequestHeader("Connection", "close");
        req.overrideMimeType("text/xml");
    }
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Content-length", parameters.length);
    req.send(parameters);
    // return the XML as text
    if (req.status == 200) {
        return req.responseText;
    }
    else {
        return null;
    }
}

function LookupZip() {
    //Lookup the city, state, country by the zipcode
    var zip = new getObj("txtPostalCode");
    if (zip.obj != null
      && zip.obj.value.length > 0) {
        //validate the zipcode
        var zipcode = zip.obj.value;
        if (zipcode.length > 5) {
            zipcode = zipcode.substring(0, 5);
        }
        if (!IsNumeric(zipcode)) {
            return;
        }
        //add files in this folder to the listbox **note: does not work in //localhost
        var result = SynchRequestXML("/admin/XMLRequest.aspx?zip=" + zipcode, "&zip=" + zipcode);
        if (result != null) {
            result = result.replace("<Result>", "");
            result = result.replace("</Result>", "");
            var arrResult = result.split("|");
            var city = new getObj("txtCity");
            if (city.obj != null) {
                city.obj.value = arrResult[0];
            }
            var state = new getObj("dropState");
            var index;
            if (state.obj != null) {
                for (i = 0; i < state.obj.options.length; i++) {
                    if (state.obj.options[i].value == arrResult[1]) {
                        //set state drop to the returned state
                        state.obj.options[i].selected = true;
                        index = i;
                        break;
                    }
                }
            }

            var license = new getObj("dropLicense");
            if (license.obj != null) {
                for (i = 0; i < license.obj.options.length; i++) {
                    if (license.obj.options[i].text == state.obj.options[index].text) {
                        //set license drop to the returned state as set by dropstate
                        license.obj.options[i].selected = true;
                    }
                }
            }

            var country = new getObj("dropCountry");
            if (country.obj != null) {
                for (i = 0; i < country.obj.options.length; i++) {
                    if (country.obj.options[i].value == arrResult[2]) {
                        //set state drop to the returned state
                        country.obj.options[i].selected = true;
                    }
                }
            }
        }
    }
}

function IsNumeric(strString)
//  check for valid numeric strings     
{
    return !/\D/.test(strString);
}

function openremoteWindow(which) {
    win = window.open(which, "viewdoc", "height=500,width=700,scrollbars=yes,toolbar=no,resizable=yes,menubar=no,status=no,left=100,top=100");
    window.setTimeout("win.focus()", 250);
}


function popitup(url) {
    newwindow = window.open(url, 'images', 'width=800,height=600,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes,left,top');
    if (window.focus) {
        newwindow.focus();
    }
}


