function jsLeadZipValidate() {
    var zip = document.getElementById("szip").value;
    //alert(zip);
    piLandingPageTemplate.LandingPageService.LeadZipValidate(zip, jsLeadValidateCallback);
}

function jsLeadPromoValidate() {
    var result = "invalid promo code";
    var promoEntry = document.getElementById("spromo").value;
    var promoCode = document.getElementById("promocode").value;
    if ((promoCode == "allvalid") || (promoCode == promoEntry))
        result = "valid";
    result = "valid"; // allow everything to pass
    jsLeadValidateCallback(result);
    //alert("code was " + promoCode);
    //piLandingPageTemplate.LandingPageService.LeadPromoValidate(promo, campaignKey, jsLeadValidateCallback);
}

function jsLeadValidate() {
    var fname = document.getElementById("sfname").value;
    var lname = document.getElementById("slname").value;
    var email = document.getElementById("email").value;
    var zip = document.getElementById("szip").value;
    var sph1 = document.getElementById("sph1").value;
    var sph11 = document.getElementById("sph11").value;
    var sph111 = document.getElementById("sph111").value;
    var phone = sph1 + sph11 + sph111;
    var privacy = 'false';
    if (document.getElementById("AcceptPrivacyPolicy"));
       privacy = document.getElementById("AcceptPrivacyPolicy").checked;
    var existUser = "No";
    if (document.getElementById("exist_user"))
       existUser = document.getElementById("exist_user").value;
    var hasCC = "Yes";
    if(document.getElementById("HasCC"))
       hasCC = document.getElementById("HasCC").value;
    //alert(fname +" "+ lname +" "+ email +" "+ zip +" "+ phone +" eu:"+ existUser +" cc:"+ hasCC);
    piLandingPageTemplate.LandingPageService.LeadValidate(fname, lname, email, zip, phone, existUser, hasCC, privacy, jsLeadValidateCallback);
}

function jsLeadShortValidate() {
    var fname = document.getElementById("sfname").value;
    var lname = document.getElementById("slname").value;
    var email = document.getElementById("email").value;
    var zip = "nozip"; // document.getElementById("szip").value;
    var sph1 = document.getElementById("sph1").value;
    var sph11 = document.getElementById("sph11").value;
    var sph111 = document.getElementById("sph111").value;
    var phone = sph1 + sph11 + sph111;
    var privacy = 'false';
    if (document.getElementById("AcceptPrivacyPolicy"));
    privacy = document.getElementById("AcceptPrivacyPolicy").checked;
    var existUser = "No";
    if (document.getElementById("exist_user"))
        existUser = document.getElementById("exist_user").value;
    var hasCC = "Yes";
    if (document.getElementById("HasCC"))
        hasCC = document.getElementById("HasCC").value;
    //alert(fname +" "+ lname +" "+ email +" "+ zip +" "+ phone +" eu:"+ existUser +" cc:"+ hasCC);
    piLandingPageTemplate.LandingPageService.LeadValidate(fname, lname, email, zip, phone, existUser, hasCC, privacy, jsLeadValidateCallback);
}

function jsLeadPhoneValidate() {
    var sph1 = document.getElementById("sph1").value;
    var sph11 = document.getElementById("sph11").value;
    var sph111 = document.getElementById("sph111").value;
    var phone = sph1 + sph11 + sph111;
    //alert(phone);
    piLandingPageTemplate.LandingPageService.LeadPhoneValidate(phone, jsLeadValidateCallback);
}

function jsLeadValidateCallback(result) {
    if (result == "valid")
        __bspPostBack('LeadSubmit', '')
    else
        alert(result);
}

function __bspPostBack(eventTarget, eventArgument) 
{
    var theform = document.forms['bspForm'];
    if (!theform)
        theForm = document.bspForm;
    theform.__BSPEVENTTARGET.value = eventTarget;
    theform.__BSPEVENTARGUMENT.value = eventArgument;
    theform.submit();  
}

function jsValidateEnterKey(type,e) 
{
    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) // enter key
    {
        if (type == 'lead')
            jsLeadValidate()
        else if (type == 'zip')
            jsLeadZipValidate()
        else if (type == 'phone')
            jsLeadPhoneValidate()
        else if (type == 'promo')
            jsLeadPromoValidate()
    }
}

// changes the cursor to a finger on mouseover
if (window.addEventListener) 
{ // Mozilla, Netscape, Firefox
    window.addEventListener('load', WindowLoad, false);
}
else if (window.attachEvent) 
{ // IE
    window.attachEvent('onload', WindowLoad);
}

function WindowLoad(event) 
{
    btn = document.getElementById("imgSubmit");
    if (btn)
        btn.onmouseover = btn.style.cursor = 'pointer';
}

