﻿//jQuery START >>>
var blnDoStuff = false;

$(function() {
    // validate contact form on keyup and submit
    $("#aspnetForm").validate({
        //set the rules for the field names
        rules: {
            inpNewsletter_Email: {
                email: true,
                required: true
            }
        },
        //set messages to appear inline
        messages: {
            inpNewsletter_Email: {
                email: "Please enter valid email address",
                required: "Please enter an email address"
            }
        }
    });

    //Check if show form or not
    //ShowSendToUserInp('newsletter');

    if (blnDoStuff == true) {
        clickSubmit();
    }

    $("a.btnSubmit").click(function() {
        clickSubmit();
        return false;
    });

    function clickSubmit() {
        if ($("#aspnetForm").valid()) {
            $("#div_processing").modal({ onOpen: function(dialog) {
                dialog.overlay.fadeIn('fast', function() {
                    dialog.container.slideDown('fast', function() {
                        dialog.data.fadeIn('fast');
                    });
                });
            }
            });
            SendCallback();
        }
        else {
            alert('Please correct invalid input');
        }
    }


});

//jQuery END <<<

function SendCallback() {
    PageMethod("uISendNewsletter", ["strEmail", escape(document.getElementById('inpNewsletter_Email').value)], goSendNewsletter_Good, Ui_Bad, "0"); //With parameters
}

function goSendNewsletter_Good(result) {
    var strHtml = UiProcessRtnCode(result.d);
    var a = strHtml.a;
    var b = strHtml.b;

    $.modal.close();

    switch (a) {
        case 't':
            //            GetAddrPopulateInput(b);
            //alert('Thanks for updating your details.');
            window.location = "processing complete.aspx?me=Processing Complete";
            break;
        case 'f':
            alert('Sorry unable to procss, please try again laterzzz');
            break;
        default:
            alert('Sorry unable to procss, please try again laterqqq');
            break;
    }
}



function Ui_Bad(result) {

    //    alert('Sorry unable to procss, please try again laterggg:' + result);
}

