﻿function getHTTPObject() {
    var xmlhttp = false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e) {
                alert(e);
            }
        }
    }
    return xmlhttp;
}

var a = null; //holds the unprocessed response string
var http = getHTTPObject(); //instantiate the object

function Showdiv(id, hideId) {
    document.getElementById(id).style.display = "block";
    document.getElementById(hideId).style.display = "none";
}

function ValidatePreviousRegistered(sender, args) {
    var PreviousRegisteredYesID = jQuery("input:radio[id$='rdoPreviousRegisteredYes']").attr("id");
    var PreviousRegisteredNoID = jQuery("input:radio[id$='rdoPreviousRegisteredNo']").attr("id");
    args.IsValid = !(document.getElementById(PreviousRegisteredYesID).checked == false && document.getElementById(PreviousRegisteredNoID).checked == false)

    return args.IsValid;
}

function ValidateEverOnJCProgram(sender, args) {
    var PreviousRegisteredNoID = jQuery("input:radio[id$='rdoPreviousRegisteredNo']").attr("id");

    if (document.getElementById(PreviousRegisteredNoID).checked) {
        var EverOnJCProgramYesID = jQuery("input:radio[id$='rdoEverOnJCProgramYes']").attr("id");
        var EverOnJCProgramNoID = jQuery("input:radio[id$='rdoEverOnJCProgramNo']").attr("id");
        args.IsValid = !(document.getElementById(EverOnJCProgramYesID).checked == false && document.getElementById(EverOnJCProgramNoID).checked == false)
        return args.IsValid;
    }
    else {
        args.IsValid = true;
        return args.IsValid;
    }

}

function ValidateCenter(sender, args) {
    var EverOnJCProgramYesID = jQuery("input:radio[id$='rdoEverOnJCProgramYes']").attr("id");
    
    if (document.getElementById(EverOnJCProgramYesID).checked) {
        args.IsValid = (args.Value != "0");
    }
    else {
        args.IsValid = true;
    }

    return args.IsValid;
}


function ShowRegistrationDiv(showDivID) {
    jQuery("div[id$='" + showDivID + "']").removeAttr("style");
    return false;
}

function ValidatePhysicallimitations(sender, args) {
    var PhLimitationYesID = jQuery("input:radio[id$='rdoPhLimitationYes']").attr("id");
    var PhLimitationNoID = jQuery("input:radio[id$='rdoPhLimitationNo']").attr("id");

    args.IsValid = !(document.getElementById(PhLimitationYesID).checked == false && document.getElementById(PhLimitationNoID).checked == false)

    return args.IsValid;
}

function ResetFoodConstrarint(IsYes) {
    jQuery("#divFood").find("input:radio").attr("checked", false);
    jQuery(".group").hide();
}

function ValidateFoodConstrarint(sender, args) {
    var FoodConstrarintYesID = jQuery("input:radio[id$='rdoFoodConstrarintYes']").attr("id");
    var FoodConstrarintNoID = jQuery("input:radio[id$='rdoFoodConstrarintNo']").attr("id");
    var IsValid = true;
    
    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery(".food-constrarint").css("display") == "block") {
            IsValid = !(document.getElementById(FoodConstrarintYesID).checked == false && document.getElementById(FoodConstrarintNoID).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}


function ValidateLactoseIntolerant(sender, args) {
    var yes = jQuery("input:radio[id$='rdoliyes']").attr("id");
    var No = jQuery("input:radio[id$='rdoliNo']").attr("id");
    var IsValid = true;

    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divlactoseIntolerant").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}

function ValidateConsumeMilk(sender, args) {
    var yes = jQuery("input:radio[id$='rdomilkcupYes']").attr("id");
    var No = jQuery("input:radio[id$='rdomilkcupNo']").attr("id");
    var IsValid = true;
    
    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divMilkcup").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}


function ValidateDietaryRequirement(sender, args) {
    var yes = jQuery("input:radio[id$='rdodietrequireYes']").attr("id");
    var No = jQuery("input:radio[id$='rdodietrequireNo']").attr("id");
    var IsValid = true;

    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divdietrequire").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}

function ValidateVeganMenu(sender, args) {
    var yes = jQuery("input:radio[id$='rdoVeganYes']").attr("id");
    var No = jQuery("input:radio[id$='rdoVeganNo']").attr("id");
    var IsValid = true;

    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divVeganMenu").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}

function ValidateVegetarianMenu(sender, args) {
    var yes = jQuery("input:radio[id$='rdoVegetarianYes']").attr("id");
    var No = jQuery("input:radio[id$='rdoVegetarianNo']").attr("id");
    var IsValid = true;

    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divVegetarian").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}

function ValidateAnimalIngr(sender, args) {
    var yes = jQuery("input:radio[id$='rdoanimalingrYes']").attr("id");
    var No = jQuery("input:radio[id$='rdoanimalingrNo']").attr("id");
    var IsValid = true;

    if (jQuery("#divFood").css("display") == "block") {
        if (jQuery("#divAnimalIngr").css("display") == "block") {
            IsValid = !(document.getElementById(yes).checked == false && document.getElementById(No).checked == false)
        }
    }
    args.IsValid = IsValid;
    return args.IsValid;
}




//function ValidateDeliveryAddress(sender, args)
//{
//     var chkDiffrID = jQuery("input:checkbox[id$='chkDiifrentDeliveryAddress']").attr("id");
//     
//     if(document.getElementById(chkDiffrID).checked)
//     {
//        args.IsValid = args.Value.length > 0;
//        return args.IsValid; 
//     }
//     else
//     {
//        args.IsValid = true;
//        return true; 
//     }
//} 

////function OpenPostcodeList(url,textID)
////{
////  var win = window.open(url+"?textID="+textID.toString(),null,"height=400,width=500,status=yes,toolbar=no,menubar=no,location=no");
////  return false;
////}
////function ClosePostcodeList(value,txtID)
////{
////  var parentWindow = window.opener;
////  parentWindow.document.getElementById(txtID).value = value;
////  window.close();
////  return false;
////}

//function pp(forgotEmailID)
//{
//    alert("yes");
//}

function CopyAddress(checked, url) {
    if (checked) {
        var address = jQuery("input:text[id$='txtDeliveryAddress']").val();
        var address2 = jQuery("input:text[id$='txtDeliveryAddress2']").val();
        var state = jQuery("select[id$='ddlDeliveryState']").val();
        var suburb = jQuery("select[id$='ddlDeliverySubUrb']").val();
        var postcode = jQuery("select[id$='ddlDeliveryPostcode']").val();

        jQuery("input:text[id$='txtAddress']").val(address);
        jQuery("input:text[id$='txtAddress2']").val(address2);
        jQuery("select[id$='ddlState']").val(state);
        if (suburb != "0")
            jQuery("input:text[id$='txtSubUrb']").val(suburb);
        if (postcode != "0")
            jQuery("input:text[id$='txtPostcode']").val(postcode);
    }
    else {
        ResetAddress();
    }
}

function ResetAddress() {
//    jQuery("input:checkbox[id$='chkDiifrentDeliveryAddress']").removeAttr("checked");

//    jQuery("input:text[id$='txtAddress']").val("");
//    jQuery("input:text[id$='txtAddress2']").val("");
//    jQuery("select[id$='ddlState']").val("0");
//    jQuery("input:text[id$='txtSubUrb']").val("");
//    jQuery("input:text[id$='txtPostcode']").val("");

    //    jQuery("textarea[id$='txtDeliveryAddress']").val("");
    //    jQuery("textarea[id$='txtDeliveryAddress2']").val("");
    //    jQuery("select[id$='ddlDeliveryState']").val("0");
    //    jQuery("select[id$='ddlDeliverySubUrb']").attr("disabled",true);
    //    jQuery("select[id$='ddlDeliverySubUrb']").val("0");
    //    jQuery("select[id$='ddlDeliveryPostcode']").val("0");
    //    jQuery("select[id$='ddlDeliveryPostcode']").attr("disabled",true);
}


function ValidatePhone(sender, args) {
    var HomePhone = jQuery("input:text[id$='txtHomePhone']").val();
    var WorkPhone = jQuery("input:text[id$='txtWorkPhone']").val();
    var MobilePhone = jQuery("input:text[id$='txtMobilePhone']").val();

//    if (jQuery.trim(WorkPhone).length > 0 && jQuery.trim(MobilePhone).length > 0) {
//        args.IsValid = true;
//        return true;
//    }
//    if (jQuery.trim(HomePhone).length > 0 && jQuery.trim(MobilePhone).length > 0) {
//        args.IsValid = true;
//        return true;
//    }
//    if (jQuery.trim(HomePhone).length > 0 && jQuery.trim(WorkPhone).length > 0) {
//        args.IsValid = true;
//        return true;
//    }

    if (jQuery.trim(WorkPhone).length > 0) {
        args.IsValid = true;
        return true;
    }
    if (jQuery.trim(HomePhone).length > 0 ) {
        args.IsValid = true;
        return true;
    }
    if (jQuery.trim(MobilePhone).length > 0) {
        args.IsValid = true;
        return true;
    }

    args.IsValid = false;
    return false;
}

function SendUserPassword(forgotEmailID, btnID, resultSpanID, waitIconID) {
    var success = Page_ClientValidate("Group2");

    if (!success) {
        return false;
    }
    else {
        var mixid = forgotEmailID + "#" + btnID + "#" + resultSpanID + "#" + waitIconID;
        document.getElementById(forgotEmailID).disabled = true;
        document.getElementById(btnID).disabled = true;
        document.getElementById(waitIconID).style.display = "inline";

        SendPassword(document.getElementById(forgotEmailID).value, mixid);
    }
    return false;
}


function ReceiveSendPasswordResult(arg, context) {
    var arID = context.split("#");

    document.getElementById(arID[2]).innerHTML = arg;

    document.getElementById(arID[0]).disabled = false;
    document.getElementById(arID[1]).disabled = false;
    document.getElementById(arID[3]).style.display = "none";

}
function CallBackErrorInSendPassword(arg, context) {
    var arID = context.split("#");
    document.getElementById(arID[2]).innerHTML = arg;

    document.getElementById(arID[0]).disabled = false;
    document.getElementById(arID[1]).disabled = false;
    document.getElementById(arID[3]).style.display = "none"
}



function SendUserPassword(forgotEmailID, btnID, resultSpanID, waitIconID) {
    var success = Page_ClientValidate("Group2");

    if (!success) {
        return false;
    }
    else {
        var mixid = forgotEmailID + "#" + btnID + "#" + resultSpanID + "#" + waitIconID;
        document.getElementById(forgotEmailID).disabled = true;
        document.getElementById(btnID).disabled = true;
        document.getElementById(waitIconID).style.display = "inline";

        SendPassword(document.getElementById(forgotEmailID).value, mixid);
    }
    return false;
}

function GetPostcodeDetailBySuburb(ddl, target) {
    var ctx = target + ";" + ddl;
    var objddl = document.getElementById(ddl);

    objddl.disabled = true;
    document.getElementById(target).disabled = true;
    GetPostcodeBySuburb(objddl.value, ctx);
}
function ReceivePostcodeBySuburb(arg, context) {
    var arId = context.split(';');

    $('#' + arId[0]).empty();
    $('#' + arId[0]).html(arg);

    document.getElementById(arId[0]).disabled = false;

    if (arId.length > 1) {
        document.getElementById(arId[1]).disabled = false;
    }

    //   $('#'+context).empty();  
    //   $('#'+context).html(arg);
}
function CallBackErrorInReceivePostcodeBySuburb(arg, context) {
    alert("Error in callback");
}



function GetPostcodeSuburbOption(rqurl, val, id,stateid, clientid) {
    var arId = clientid.split('#');
    
    for (var i = 0; i < arId.length; ++i) {
        document.getElementById(arId[i]).value = "0";
        document.getElementById(arId[i]).disabled = true;
    }
    
    if (val != "0") {
        if (http) {
            try {
                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                var parameters = "{'value':'" + val + "','id':'" + id + "','stateid':'" + stateid + "'}";

                http.send(parameters);
                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        for (var i = 0; i < arId.length; ++i) {
            if (i == 0) {
                $('#' + arId[i]).html(a.d);
                document.getElementById(arId[i]).disabled = false;
            }
            if (i > 0) {
                $('#' + arId[i]).html("<option value=\"0\">Select</option>");
                document.getElementById(arId[i]).disabled = true;
            }
        }
    }
    else {

        for (var i = 0; i < arId.length; ++i) {
            $('#' + arId[i]).empty();
            $('#' + arId[i]).html("<option value=\"0\">Select</option>");
            document.getElementById(arId[i]).disabled = true;
        }
    }

}

function ValidateDeclaration(sender, args) {
    var id = jQuery("input:checkbox[id$='chkDeclaration']").attr("id");
    args.IsValid = document.getElementById(id).checked;
    return args.IsValid;
}

function ValidateConfirmPassword(sender, args) {
    var password = jQuery("input:password[id$='txtPasword']").val();
    args.IsValid = (password == args.Value);
    return args.IsValid;
}

function GetSuburbPricevalue(rqurl, val, id) {

    if (parseInt(val) > 0) {

        if (http) {
            try {

                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");

                var SuburbName = $("#" + id).val();

                var parameters = "{'value':'" + val + "','SuburbName':'" + SuburbName + "'}";

                http.send(parameters);

                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        var Currency = $("#hdnCurrency").val().substring(0, 1);

        alert("at This suburb delivery charge will be " + Currency + a.d);

    }
    //    GetSuburbPostcode(val+'#'+id,clientid);
}

function ValidatePurchaseMembership(source, args) {
    var flag = false;
    jQuery("input:radio[name$='rdoMembership']").each(function() {
        if (flag == false && this.checked) {
            flag = true;
        }
    });
    args.IsValid = flag;
    return flag;

}

function ShowPopUp(id, url, status) {
    
    jQuery('#' + id).modal();
    var iframe_id = "#" + id + "_iframe";
    jQuery(iframe_id).attr("src", url);
    return false;
}

function showPopup(id, url, status) {
    jQuery('#' + id).modal();
    var iframe_id = "#" + id + "_iframe";
    jQuery(iframe_id).attr("src", url);
    jQuery(iframe_id).width(400)
    return false
}

function ShowPopUp2(id, url, status) {
    jQuery('#' + id).modal();
    return false
}

function EnableDisableHealthComment(obj, txtHealth) {
    if (obj.checked) {
        document.getElementById(txtHealth).readOnly = false;
        document.getElementById(txtHealth).readOnly = false;
        document.getElementById(txtHealth).style.backgroundColor = "transparent";

    }
    else {
        document.getElementById(txtHealth).value = "";
        document.getElementById(txtHealth).style.backgroundColor = "#666";
        document.getElementById(txtHealth).readOnly = true;
    }
}

function ValidateSelectingPhLevel(source, args) {
    var lightID = jQuery("input:radio[id$='rdoLight']").attr("id");
    var ModerateID = jQuery("input:radio[id$='rdoModerate']").attr("id");
    var HeavyID = jQuery("input:radio[id$='rdoHeavy']").attr("id");
    
    var light=false;
    if(lightID !=null)
    {
        light=document.getElementById(lightID).checked;
    }
    var Moderate=false;
    if(ModerateID !=null)
    {
        Moderate=document.getElementById(ModerateID).checked;
    }
    
    var Heavy=false;
    if(HeavyID !=null)
    {
        Heavy=document.getElementById(HeavyID).checked;
    }

    args.IsValid = (light || Moderate || Heavy);
    return args.IsValid;
}

//jQuery(document).ready(function() {
//    var outerclass = ".join-today";
//    jQuery(outerclass).find("input[id$='btnSignUp']").click(function() {
//    
//        pageTracker._trackPageview();
//        pageTracker._trackEvent('Registration', 'Postcode Submit');
//    
//        var suburb = jQuery(outerclass).find("select[id$='ddlSuburb']").val();
//        var postcode =jQuery(outerclass).find("select[id$='ddlPostcode']").val(); 
//         
//        var pageurl = jQuery(outerclass).find("input:hidden[id$='hfSignupPageUrl']").val();

//        if (suburb != '0' && postcode != '0') {
//            postcode=jQuery(outerclass).find("select[id$='ddlPostcode']").find('option').filter(':selected').text();
//            //self.parent.location = pageurl+'?suburb='+suburb+'&postcode='+postcode;
//            window.location.href = pageurl+'?suburb='+suburb+'&postcode='+postcode;
//            //parent.jQuery(".modalCloseImg").trigger("click");
//            //return true;
//        }
//        return false;
//    });
//});

function PopupWindow() {
    parent.jQuery(".modalCloseImg").trigger("click")
}

function accordionfn(index) {
    var nextIndex = index + 1;

    //Inactive all step which are not equals to index
    $('#accordion:eq(0)> div.c:gt(' + index.toString() + ')').removeClass("step-active").addClass("step-inactive");
    $('#accordion:eq(0)> div.c:lt(' + index.toString() + ')').removeClass("step-active").addClass("step-inactive");

    // 20110817 LN - registration refrsh (bugsy #3915) - always show all step headers
    //hide all header which is greater then (index+1) 
    //$('#accordion:eq(0)> div.c:gt(' + nextIndex.toString() + ')').hide();

    //hide all stepheader
    $('#accordion:eq(0)> div.c > div.reg-step-header').hide();

    //active indexed step
    $('#accordion:eq(0)> div.c:eq(' + index.toString() + ')').removeClass("step-inactive").addClass("step-active");

    //show step show link whose index less then index
    $('#accordion:eq(0)> div.c:lt(' + index.toString() + ') > div.reg-step-header').show().find('a.show').show().parent().find("span.step-complete").show().parent().find('div.blue-btn-outer').hide();

    //show next index button
    $('#accordion:eq(0)> div.c:eq(' + nextIndex.toString() + ') > div.reg-step-header').show().find('a.show').hide().parent().find("span.step-complete").hide().parent().find('div.blue-btn-outer').show();


    //Inactive all content which are not equals to index

    $('#accordion:eq(0)> div.content:gt(' + index.toString() + ')').hide();
    $('#accordion:eq(0)> div.content:lt(' + index.toString() + ')').hide();

    //show indexed content
    $('#accordion:eq(0)> div.content:eq(' + index.toString() + ')').show();



    $('#accordion:eq(0)').find('a.show').click(function() {

        $(this).parent().parent().next('div:hidden').slideDown('fast')
            .siblings('div.content').slideUp('fast');

        $(this).parent().find("span.step-complete").hide();
        $(this).parent().parent().removeClass("step-inactive").addClass("step-active");

        var blnNextStepActive = false;
        var $o = $(this).parent().parent().next();
        while ($o.length != 0) {
            if ($o.hasClass("c") && blnNextStepActive == false) {
                $o.removeClass("step-active").addClass("step-inactive");
                $o.find("div.er-msg").text("");
                $o.find("div.reg-step-header").show().find("div.blue-btn-outer").show().parent().find("span.step-complete").hide().parent().find('a.show').hide();
                blnNextStepActive = true;
            }
            else if ($o.hasClass("c")) {
                // 20110817 LN - registration refrsh (bugsy #3915) - always show all step headers
                // $o.hide();
                $o.removeClass("step-active").addClass("step-inactive");
                $o.find("div.er-msg").text("");
                $o.find("div.reg-step-header").hide();//.find("div.blue-btn-outer").show().parent().find("span.step-complete").hide().parent().find('a.show').hide();
                blnNextStepActive = true;
            }
            $o = $o.next();
        }
        $(this).hide();

    });

    $('#accordion:eq(0)').find('div.blue-btn-outer').click(function() {
        var group = $(this).parent().find("span:eq(0)").text();
        
        if(group == "vg1")
        {
            pageTracker._trackPageview();
            pageTracker._trackEvent('Registration', 'Step 1 Proceed');
        }
        else if(group == "vgPInfo")
        {
            pageTracker._trackPageview();
            pageTracker._trackEvent('Registration', 'Step 2 Proceed');
        }
        else if(group == "vg3")
        {
            pageTracker._trackPageview();
            pageTracker._trackEvent('Registration', 'Step 3 Proceed');
        }
        
        var result = Page_ClientValidate(group);
        //var result = true;
        if (result == true) {
            toggleErrorMessage($(this), true);


            //GoogleCode
            if(group == "vg1")
            {
                var healthInfoID = $(this).parent().parent().next('div:hidden').attr("id");
                if(healthInfoID == "divHealthInfo")
                {
                  var email = jQuery('#txtEmail').val(); 
                  $(this).parent().parent().next('div:hidden').append("<img width='1' height='1' src='https://track.polenord.net/transform.php?idc=586&lead=3&var1="+email+" />");
                }
            }

            $(this).parent().parent().next('div:hidden').slideDown('fast')
                .siblings('div.content').slideUp('fast');


            if ($(this).parent().parent().hasClass("step-final") == false)
                $(this).parent().parent().removeClass("step-inactive").addClass("step-active");

            var blnFirst = false;
            var $o = $(this).parent().parent().next();
            while ($o.length != 0 && blnFirst == false) {
                if ($o.hasClass("c")) {
                    blnFirst = true;
                    $o.removeClass("step-active").addClass("step-inactive").show().find("div.reg-step-header").show().find("div.blue-btn-outer").show().parent().find('a.show').hide().parent().find("span.step-complete").hide();
                }
                $o = $o.next();
            }

            $o = $(this).parent().parent().prev();
            while ($o.length != 0) {
                if ($o.hasClass("c")) {
                    $o.removeClass("step-active").addClass("step-inactive");
                    $o.find("div.reg-step-header").find('a.show').show().parent().find("span.step-complete").show();
                    $o.find("div.reg-step-header").show().find("div.blue-btn-outer").hide();
                }
                $o = $o.prev();
            }
            if ($(this).find("input").hasClass("PaymentPageContinueCheckoutButton") == false)
                $(this).hide();
        }
        else {
            toggleErrorMessage($(this), false);
        }

    });

}
function toggleErrorMessage($obj, isdelete) {
    var isfirst = false;
    var $o = $obj.parent().parent();

    if ($o.hasClass("step-final") == true) {
        $o = $o.parent();
    }
    else {
        $o = $o.prev();

    }
    while ($o.length != 0) {
        if ($o.hasClass("c") && isfirst == false) {
            isfirst = true;
            if (isdelete == false) {
                $o.find("div.er-msg").focus().text("Error! - Either Required Information Missing or Information is not valid.");
            }
            else
                $o.find("div.er-msg").text("");
        }
        $o = $o.prev();
    }

}

function JCUserQuestion(divID, Index) {
    this.Div = divID;
    this.Ind = Index;
    this.process = cclProceed;
}
function cclProceed() {
    $("#" + this.Div).find("div").hide();

    $("#" + this.Div).find(".y").click(function() {
        $(this).parent().find("div:eq(0)").show().siblings("div").hide();
    });
    $("#" + this.Div).find(".n").click(function() {
        $(this).parent().find("div:gt(0)").show().siblings("div").hide();
    });
}


jQuery(document).ready(function() {

    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

    if (jQuery.browser.msie && (ie55 || ie6)) {

        jQuery(".blue-btn-outer").find(".blue-btn-left").removeClass().addClass("blue-btn-left-png");
        jQuery(".blue-btn-outer").find(".blue-btn-right").removeClass().addClass("blue-btn-right-png");

        jQuery(".white-btn-outer").find(".white-btn-left").removeClass().addClass("white-btn-left-png");
         jQuery(".white-btn-outer").find(".white-btn-right").removeClass().addClass("white-btn-right-png");
         
         jQuery(".yellow-btn-outer").find(".yellow-btn-left").removeClass().addClass("yellow-btn-left-png");
         jQuery(".yellow-btn-outer").find(".yellow-btn-right").removeClass().addClass("yellow-btn-right-png");
             
             
             
             
        jQuery(document).pngFix();
        
        
        
        
    }

});




jQuery(document).ready(function() {
    var $outer = jQuery(".profile");
    $outer.find(".profile-details").hide();
    $outer.find(".close").hide();

    $outer.find(".view-edit").click(function() {
        $outer.find(".profile-details").show();
        $outer.find("input:text[id$='txtEmail']").focus();
        $outer.find(".close").show();
        $outer.find(".view-edit").hide();
    })

    $outer.find(".close").click(function() {
        $outer.find(".profile-details").slideUp();
        $outer.find(".view-edit").show();
        $outer.find(".close").hide();
    })

    // 20110916 LN - registration refrsh (bugsy #3915)
    // show/hide medical condition drop-out/expand
	// Registration > Step 2 > YOUR HEALTH (Jc_CreateAccount - medical conditions)
	// MY Jenny > My Profile > YOUR HEALTH (MyProfile - medical conditions)
        var $divExpand = jQuery('.expand-link-div');
	    jQuery("a.expand-link").click(function() {
            $divExpand.fadeOut();
            $divExpand.filter(this.hash).fadeIn();
            return false;
        });
	    jQuery("a.collapse-link").click(function() {
            $divExpand.fadeOut();
            return false;
        });

    // 20110817 LN - registration refresh (bugsy #3915) - value page blinky text
    if(jQuery().blink) jQuery('.blink').blink(); // default is 500ms blink interval.
    //jQuery('.blink').blink({delay:100}); // causes a 100ms blink interval.
});





function ShowForgotPassord(id, url, status) {
    jQuery('#' + id).modal();
    var iframe_id = "#" + id + "_iframe";
    jQuery(iframe_id).attr("src", url);
    return false;
}


function ShowJoinUp(url) {
    var joinUp=jQuery("div[id='modlJoinUp']");
    jQuery(joinUp).modal();
    var iframe_id = '#Joinup_iframe';
    jQuery(iframe_id).attr("src", url);
    return false;
}

function ShowEmailUsPopup(url) {
    var joinUp=jQuery("div[id='modlEmailus']");
    jQuery(joinUp).modal();
    var iframe_id = '#EmailUsIframe';
    jQuery(iframe_id).attr("src", url);
    return false;
}





function AddToBreadCrumb(id, sibiling) {

    var bcsibilibing = jQuery("input:hidden[id$='hdbQBreadcsibiling']").val(); //sibling
    var bc = jQuery("input:hidden[id$='hdbQBreadcrumb']").val(); //id

    if (bcsibilibing.length > 0 && id.length > 0 && sibiling.length > 0) {
        var arr = bcsibilibing.split(',');
        var arBc = bc.split(',');

        var i = 0;

        for (i = 0; i < arr.length; i++) {
            if (arr[i] == id) {
                arr[i] = arBc[i];
                arBc[i] = id;
                break;
            }
        }

        var arr2 = '';
        for (var j = 0; j < arr.length; j++) {
            if (j <= i) {
                arr2 = arr2 + arr[j] + ",";
            }
            else {
                if (arr[j].length > 0) {
                    jQuery('div.' + arr[j]).hide().find("input:radio").each(function() {
                        this.checked = false;
                    });
                }
            }
        }

        bcsibilibing = arr2.toString();

        var arBc2 = '';
        for (var j = 0; j < arBc.length; j++) {
            if (j <= i) {
                arBc2 = arBc2 + arBc[j] + ",";
            }
            else {
                if (arBc[j].length > 0) {
                    jQuery('div.' + arBc[j]).hide().find("input:radio").each(function() {
                        this.checked = false;
                    });
                }
            }
        }
        bc = arBc2.toString();
    }

    if (id.length > 0 && sibiling.length > 0) {
        if (bc.search(id + ',') == -1) {
            bc = bc + id + ',';
        }
        if (bcsibilibing.search(sibiling + ',') == -1) {
            bcsibilibing = bcsibilibing + sibiling + ',';
        }
    }
    
    jQuery("input:hidden[id$='hdbQBreadcrumb']").val(bc);
    jQuery("input:hidden[id$='hdbQBreadcsibiling']").val(bcsibilibing);
    jQuery('div.' + id).show().find("input:radio").attr("checked",false);
    
    
    //alert(bcsibilibing);
    //alert(bc);
}


function AddToBreadCrumbProfile(id, sibiling) {

    var bcsibilibing = jQuery("input:hidden[id$='hdbQBreadcsibiling']").val(); //sibling
    var bc = jQuery("input:hidden[id$='hdbQBreadcrumb']").val(); //id

    if (bcsibilibing.length > 0 && id.length > 0 && sibiling.length > 0) {
        var arr = bcsibilibing.split(',');
        var arBc = bc.split(',');

        var i = 0;

        for (i = 0; i < arr.length; i++) {
            if (arr[i] == id) {
                arr[i] = arBc[i];
                arBc[i] = id;
                break;
            }
        }

        var arr2 = '';
        for (var j = 0; j < arr.length; j++) {
            if (j <= i) {
                arr2 = arr2 + arr[j] + ",";
            }
            else {
                if (arr[j].length > 0) {
                    jQuery('div.' + arr[j]).hide().find("input:radio").each(function() {
                        this.checked = false;
                    });
                }
            }
        }

        bcsibilibing = arr2.toString();

        var arBc2 = '';
        for (var j = 0; j < arBc.length; j++) {
            if (j <= i) {
                arBc2 = arBc2 + arBc[j] + ",";
            }
            else {
                if (arBc[j].length > 0) {
                    jQuery('div.' + arBc[j]).hide().find("input:radio").each(function() {
                        this.checked = false;
                    });
                }
            }
        }
        bc = arBc2.toString();
    }

    if (id.length > 0 && sibiling.length > 0) {
        if (bc.search(id + ',') == -1) {
            bc = bc + id + ',';
        }
        if (bcsibilibing.search(sibiling + ',') == -1) {
            bcsibilibing = bcsibilibing + sibiling + ',';
        }
    }
    
    jQuery("input:hidden[id$='hdbQBreadcrumb']").val(bc);
    jQuery("input:hidden[id$='hdbQBreadcsibiling']").val(bcsibilibing);
    jQuery('div.' + id).show().find("input:radio").attr("checked",false);
    
    //alert(bcsibilibing);
    //alert(bc);
}


function checkdate(source, args) 
{
    var SelectedDate =jQuery(".selected-date").find("input").val();
    var validformat = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/; //Basic check for format validity
    var returnval = false;
    if(jQuery.trim(SelectedDate).length>0)
    {
        if (!validformat.test(SelectedDate)) {
            returnval = false;
        }
        else {
            //Detailed check for valid date ranges
            var monthfield = SelectedDate.split("/")[1];
            var dayfield = SelectedDate.split("/")[0];
            var yearfield = SelectedDate.split("/")[2];
            
            returnval=true;
            if(monthfield==2)
            {
                if(dayfield <=29 && checkYear(yearfield)==1)
                {
                    returnval=true;
                }
                else if(dayfield <=28)
                {
                    returnval=true;
                }
                else
                {
                    returnval=false;
                }
            }
        }
    }
    else
    {
        returnval=true;
    }
   args.IsValid=returnval;
   return args.IsValid;
}

// Leap Year
function checkYear(year) {
    return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}

function RefreshDeliveryDate(frmid,urlprefix,stateid,suburbid,postcodeid)
{
    var state =  document.getElementById(stateid).value;
    var statename = document.getElementById(stateid).options[document.getElementById(stateid).selectedIndex].text;
    var suburb = document.getElementById(suburbid).value;
    var postcode = document.getElementById(postcodeid).value;
    if(state != "0" && suburb != "0" && postcode != "0" )
    {
        var url = urlprefix+"?ShippingState="+statename+"&ShippingSuburb="+document.getElementById(suburbid).value+"&ShippingZip="+document.getElementById(postcodeid).value;
        document.getElementById(frmid).src=url;
    }
}

function ValidateCustomerAddress()
{
    var fname = jQuery("#Form2").find("input:text[id$='txtFName']").val();
    var initialfname = jQuery("#Form2").find("input:text[id$='txtFName']").attr("defaultValue");
    
    var lname = jQuery("#Form2").find("input:text[id$='txtLName']").val();
    var initiallname = jQuery("#Form2").find("input:text[id$='txtLName']").attr("defaultValue");
    
    var HomePhone = jQuery("#Form2").find("input:text[id$='txtHomePhone']").val();
    var initialHomePhone = jQuery("#Form2").find("input:text[id$='txtHomePhone']").attr("defaultValue");
    
    
    var WorkPhone = jQuery("#Form2").find("input:text[id$='txtWorkPhone']").val();
    var initialWorkPhone = jQuery("#Form2").find("input:text[id$='txtWorkPhone']").attr("defaultValue");
    
    var Mobile = jQuery("#Form2").find("input:text[id$='txtMobile']").val();
    var initialMobile = jQuery("#Form2").find("input:text[id$='txtMobile']").attr("defaultValue");

    var Address = jQuery("#Form2").find("input:text[id$='txtAddress']").val();
    var initialAddress = jQuery("#Form2").find("input:text[id$='txtAddress']").attr("defaultValue");

    var Address2 = jQuery("#Form2").find("input:text[id$='txtAddress2']").val();
    var initialAddress2 = jQuery("#Form2").find("input:text[id$='txtAddress2']").attr("defaultValue");

    var State = document.getElementById("ddlState").options[document.getElementById("ddlState").selectedIndex].text;
    
    //Coupon
//    var CouponCode = jQuery("#Form2").find("input:text[id$='txtCoupon']").val();
//    var initialCouponCode = jQuery("#Form2").find("input:text[id$='txtCoupon']").attr("defaultValue");


    var NewStateValue = jQuery("#Form2").find("select[id$='ddlState']").find('option').filter(':selected').text();
    jQuery("#Form2").find("select[id$='ddlState']").find('option').each(function(){
       if(this.defaultSelected)
        initialState = this.text;
    });
    
    var Suburb = document.getElementById("ddlSuburb").options[document.getElementById("ddlSuburb").selectedIndex].text;
    var NewSuburbValue = jQuery("#Form2").find("select[id$='ddlSuburb']").val();

    jQuery("#Form2").find("select[id$='ddlSuburb']").find('option').each(function(){
      if(this.defaultSelected)
        initialSuburb = this.text;
    });


    var Postcode = document.getElementById("ddlPostcode").options[document.getElementById("ddlPostcode").selectedIndex].text;
    var NewPostcodeValue = jQuery("#Form2").find("select[id$='ddlPostcode']").val();
    jQuery("#Form2").find("select[id$='ddlPostcode']").find('option').each(function(){
      if(this.defaultSelected)
        initialPostcode = this.text;
    });

    var DeliveryDate = jQuery("#Form2").find("input:hidden[id$='hdfselectdate']").val();
    var DeliveryInstruction = jQuery("#Form2").find("textarea[id$='txtDeliveryInstructions']").val();
    
    
    var blnFormChanged = false;
    
    if(jQuery.trim(fname) != jQuery.trim(initialfname))
    {
         blnFormChanged = true;
    }
    else if(jQuery.trim(lname) != jQuery.trim(initiallname))    
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(HomePhone) != jQuery.trim(initialHomePhone))
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(Mobile) != jQuery.trim(initialMobile))    
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(WorkPhone) != jQuery.trim(initialWorkPhone))    
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(Address) != jQuery.trim(initialAddress))    
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(Address2) != jQuery.trim(initialAddress2))    
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(NewStateValue) != jQuery.trim(initialState))   
    { 
        blnFormChanged = true;
    }
    else if(jQuery.trim(NewSuburbValue) != jQuery.trim(initialSuburb))  
    {
        blnFormChanged = true;
    }
    else if(jQuery.trim(NewPostcodeValue) != jQuery.trim(initialPostcode))    
    {
        blnFormChanged = true;
    }


    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnFormChanged']").val(blnFormChanged.toString());
    
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnFirstName']").val(fname);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnLastName']").val(lname);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnHomePhone']").val(HomePhone);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnWorkPhone']").val(WorkPhone);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnMobile']").val(Mobile);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnAddress']").val(Address);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnAddress2']").val(Address2);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnState']").val(State);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnSuburb']").val(Suburb);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnPostcode']").val(Postcode);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnDeliveryDate']").val(DeliveryDate);
    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnDeliveryInstruction']").val(DeliveryInstruction);
    
    //For Coupon
//    jQuery("#frmCustomerAddress").find("input:hidden[id$='hdnCoupon']").val(CouponCode);
//    
    return (jQuery.trim(DeliveryDate).length > 0 && jQuery.trim(fname).length > 0 && jQuery.trim(lname).length > 0 && jQuery.trim(Address).length > 0 && jQuery.trim(State)!="Select" && jQuery.trim(Suburb)!= "Select" && jQuery.trim(Postcode)!="Select");

}


function GetCenterByState(rqurl,stateid,targetid)
{
    if (stateid != "0") {
        if (http) {
            try {
            
                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                var parameters = "{'stateid':'" + stateid + "'}";

                http.send(parameters);

                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        $('#' + targetid).html(a.d);
        document.getElementById(targetid).disabled = false;

    }
    else {

        $('#' + targetid).html("<option value=\"0\">Select</option>");
        document.getElementById(targetid).disabled = true;
    }

}




function GetPostcodeBySuburb(rqurl,suburb,targetid)
{
    document.getElementById(targetid).value = "0";
    document.getElementById(targetid).disabled = true;
    
    if (suburb != "0") {
        if (http) {
            try {
                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                var parameters = "{'suburb':'" + suburb + "'}";

                http.send(parameters);

                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        $('#' + targetid).html(a.d);
        document.getElementById(targetid).disabled = false;

    }
    else {

        $('#' + targetid).html("<option value=\"0\">Postcode</option>");
        document.getElementById(targetid).disabled = true;
    }
}


jQuery(document).ready(function() {
    
    var rdHealthConditionYesId = jQuery("input:radio[id$='rdHealthConditionYes']").attr("id");
    if(rdHealthConditionYesId !=null)
    {
        if(document.getElementById(rdHealthConditionYesId).checked == true)
        {
            jQuery("div[id='divHealthInfoComment']").show();
        }
        else
        {
            jQuery("div[id='divHealthInfoComment']").hide();
        }
    }
    
});


function HealthConditionCheck(obj)
{   
    var txtHealthInfoCommentId = jQuery("textarea[id$='txtHealthInfoComment']");
    if(obj.value==1)
    {
        jQuery("div[id='divHealthInfoComment']").show();
        
    }
    else
    {
        jQuery("div[id='divHealthInfoComment']").hide();
        jQuery(txtHealthInfoCommentId).val("");
    }
  
}

function ValidateHealthInformation(sender, args) {
    var rdHealthConditionYesId = jQuery("input:radio[id$='rdHealthConditionYes']").attr("id");
    var rdHealthConditionNoId = jQuery("input:radio[id$='rdHealthConditionNo']").attr("id");
    var txtHealthInfoCommentId = jQuery("textarea[id$='txtHealthInfoComment']");
    
    var val=jQuery(txtHealthInfoCommentId).val();
    val=jQuery.trim(val);
    
    var isCheck =document.getElementById(rdHealthConditionYesId).checked;
    
    if(isCheck==true)
    {
        if(val.length>0)
        {
         args.IsValid=true;
        }
        else{
        args.IsValid=false;
        }
    }
    else
    {
        args.IsValid=true;
    }
    return args.IsValid;
}


function ValidateHealthCondition(sender, args) {
    var rdHealthConditionYesId = jQuery("input:radio[id$='rdHealthConditionYes']").attr("id");
    var rdHealthConditionNoId = jQuery("input:radio[id$='rdHealthConditionNo']").attr("id");
   var IsValid = !(document.getElementById(rdHealthConditionYesId).checked == false && document.getElementById(rdHealthConditionNoId).checked == false)
   args.IsValid=IsValid;
    return args.IsValid;
}

function SevenDaySupplementWarning(id)
{
    var result =  window.confirm("Are you sure you want to delete 7 day supplement");
    if(result)
    {
        jQuery("#"+id).val(0);
    }
    return result;
}


jQuery(document).ready(function() {
    
    var pnl=jQuery("div[id$='pnlCartSummary']");
    var select = jQuery("div[id$='pnlCartSummary']").find("select");
    if(pnl.length>0)
    {
        var M_Price=jQuery(pnl).find("input[id$='hdnM_Price']").val();
        var M_ShoppingCartRecordID=jQuery(pnl).find("input[id$='hdnM_ShoppingCartRecordID']").val();
        var M_Supp_ExtensionData=jQuery(pnl).find("input[id$='hdnM_Supp_ExtensionData']").val();
        
        select=jQuery(select).attr("id");
        LoadPrice(select,M_Price,M_ShoppingCartRecordID,true,M_Supp_ExtensionData);
        //UpdatePrice(select,M_Price,M_ShoppingCartRecordID,true);
    }
});

function LoadPrice(obj,unitPrice,scRecordID,CallonReady,Supp_ExtensionData)
{
    var quantity=0;
    if(CallonReady==true)
    {
      quantity = jQuery("#"+obj).val();
    }
    else
    {
   quantity = jQuery("#"+obj.id).val();   
  }
  
  /*if(quantity == 0)
  {
    var result =  window.confirm("We highly recommend that you purchase the Jenny Craig Multi-Vitamin and Mineral Supplement each week. The 7 Day Supplement is designed to ensure balanced nutrition throughout your Program.");
    if(result == false)
    {
        jQuery("#"+obj.id).val(jQuery("#hdnQtty_"+scRecordID).val());
    }
  }
  else
  {*/
    jQuery("#hdnQtty_"+scRecordID).val(quantity);
  /*}*/
  
  if(obj ==null)
  {
   quantity=0;
   unitPrice=0;
  }
 
  var Sup_Price = quantity * unitPrice;
  Sup_Price = FormatTo2Dec(Sup_Price.toString());
  
  //var Sup_Price_GST=Sup_Price *.1;
  var Sup_Price_GST=quantity * Supp_ExtensionData;
  //alert(Sup_Price_GST);
  if(jQuery("#hfCartSubTotal").length >0)
  {
  var subtotal = jQuery("#hfCartSubTotal").val();
  subtotal = subtotal.replace("$","");
    
  var GST = jQuery("#hfGST").val();
  GST = GST.replace("$","");
 
  var shipping=jQuery("span[id$='lblSubrubPrice']").text();
  shipping = shipping.replace("$","");
 
 var GST_exl_supp = GST-Sup_Price_GST;
  jQuery("input[id$='hfGSTExSup']").val(GST_exl_supp);
  
  var subtotal_exl_supp = (subtotal-Sup_Price);
  jQuery("input[id$='hfSubTotalExSup']").val(subtotal_exl_supp);
  
 //var nettotal_exl_supp = subtotal_exl_supp + (GST-Sup_Price_GST)+shipping;
  //jQuery("input[id$='hfTotalExSup']").val(nettotal_exl_supp);
  
  //alert(GST_exl_supp + ' ' + subtotal_exl_supp);
  }
}

function UpdatePrice(obj,unitPrice,scRecordID,CallonReady,sup_extensiondata)
{
    var quantity=0;
    if(CallonReady==true)
    {
      quantity = jQuery("#"+obj).val();
    }
    else
    {
   quantity = jQuery("#"+obj.id).val();   
  }
  
  if(quantity == 0)
  {
    var result =  window.confirm("We highly recommend that you purchase the Jenny Craig Multi-Vitamin and Mineral Supplement each week. The 7 Day Supplement is designed to ensure balanced nutrition throughout your Program.");
    if(result == false)
    {
        jQuery("#"+obj.id).val(jQuery("#hdnQtty_"+scRecordID).val());
    }
  }
  else
  {
    jQuery("#hdnQtty_"+scRecordID).val(quantity);
  }
  
  /* logic to replace*/
  var supQty=0;
  if(quantity >0)
  {
  supQty=parseFloat(quantity*unitPrice);
  }
  else
  {
  supQty=0;
  }
  
  if(jQuery("#hfGSTExSup").length >0)
  {
    var GST = jQuery("#hfGSTExSup").val();
    GST = GST.replace("$",""); 
    //GST = parseFloat(GST) + (supQty*.1);
    GST = parseFloat(GST) + (quantity*sup_extensiondata);
  
    var subTotal = jQuery("#hfSubTotalExSup").val();
    subTotal= subTotal.replace("$","");

var subtot=FormatTo2Dec(parseFloat(subTotal).toString());
var supprice= FormatTo2Dec(parseFloat(supQty).toString());
subTotal=roundNumber(parseFloat(subtot)+ parseFloat(supprice),2)
    //subTotal= parseFloat(subTotal) + supQty;
  


  
    var shipping=jQuery("span[id$='lblSubrubPrice']").text();
    shipping = parseFloat(shipping.replace("$",""));
  
    var netTotal = subTotal+GST+shipping;
  
  //alert(GST + ' * ' + subTotal + ' * ' + shipping + ' * ' + netTotal);
  
   if(CallonReady==true)
   {
      jQuery("#"+obj).parent().next("td").text("$"+FormatTo2Dec(supQty.toString()));
   }
   else
   {
       jQuery("#"+obj.id).parent().next("td").text("$"+FormatTo2Dec(supQty.toString()));
   }
 
  jQuery("#lblGST").text("$"+FormatTo2Dec(GST.toString()));
  jQuery("#CartSubTotal").text("$"+FormatTo2Dec(subTotal.toString()));
  jQuery("#lblTotal").text("$"+FormatTo2Dec(netTotal.toString()));
  }
  /* end*/

//  //var GST = jQuery("#lblGST").text();
//  //GST = GST.replace("$","");
//  
//  var GST = jQuery("#hfGST").val();
//  GST = GST.replace("$","");
//  
//  
//  //var SupplementProduct = jQuery("#"+obj.id).parent().next("td").text();
//  
//  if(CallonReady==true)
//    {
//      SupplementProduct = jQuery("#"+obj).parent().next("td").text();
//    }
//    else
//    {
//   SupplementProduct = jQuery("#"+obj.id).parent().next("td").text();
//  }
//  
//  SupplementProduct = SupplementProduct.replace("$","");   

//    
//  //var subtotal = jQuery("#CartSubTotal").text();
//  var subtotal = jQuery("#hfCartSubTotal").val();
//  
//  
//  
//  subtotal = subtotal.replace("$","");
//  
//  var tempGst = SupplementProduct*10/100;
//alert(tempGst);
//  GST = GST - tempGst;  


//  //var quantity = jQuery("#"+obj.id).val();
//  var totalPrice = quantity * unitPrice;
//  totalPrice = FormatTo2Dec(totalPrice.toString());
//  
//  //var prevProdTotal = jQuery("#"+obj.id).parent().next("td").text();
//  if(CallonReady==true)
//    {
//      prevProdTotal = jQuery("#"+obj).parent().next("td").text();
//    }
//    else
//    {
//   prevProdTotal = jQuery("#"+obj.id).parent().next("td").text();   
//  }
//  
//  prevProdTotal = prevProdTotal.replace("$","");
// 

//  
//  var tempSubTotal = parseFloat(subtotal)-parseFloat(prevProdTotal);
//  
//  GST = GST + totalPrice*10/100;
// 
//  
//  GST =roundNumber(GST,2);
//  //alert(GST );
//  
//  if(CallonReady==true)
//    {
//      jQuery("#"+obj).parent().next("td").text("$"+FormatTo2Dec(totalPrice.toString()));
//    }
//    else
//    {
//   jQuery("#"+obj.id).parent().next("td").text("$"+FormatTo2Dec(totalPrice.toString()));
//  }
//  
//  
//  
//  jQuery("#lblGST").text("$"+FormatTo2Dec(GST.toString()));
//  jQuery("#hfGST").val("$"+FormatTo2Dec(GST.toString()));
//  
//  var netTotal = parseFloat(tempSubTotal) + parseFloat(totalPrice);
//  
//  netTotal=roundNumber(netTotal,2);
//  //alert(tempSubTotal + '+' + totalPrice +'=' + netTotal);
//  
//  jQuery("#CartSubTotal").text("$"+FormatTo2Dec(netTotal.toString()));

//  
//  var total = jQuery("#lblTotal").text();
//  total = total.replace("$","");
//  
//  var tempTotal = parseFloat(total)-parseFloat(prevProdTotal);
//  
//  //alert(total + '-' + prevProdTotal +'='+tempTotal);
//  
//  //var lblSubrubPrice=jQuery("span[id$='lblSubrubPrice']").text();
//  //lblSubrubPrice = lblSubrubPrice.replace("$","");
//  //alert(subtotal + '+'+GST + '+' + lblSubrubPrice);
//  
//  var netTotal = parseFloat(tempTotal) + parseFloat(totalPrice);
//  
//  jQuery("#lblTotal").text("$"+FormatTo2Dec(netTotal.toString()));
//  
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
     
function RoundToDigits(n, d)
{
    var dVal = 10 * d;
    
    if (dVal > 0)
    {
        return (Math.round(n * dVal) / dVal);
    }
    else
    {
        Math.round(n);
    }    
}

function TwoDecimalValue(n)
{
    var decPos = n.indexOf('.');
    return n.substring(0,decPos+3);
}

function FormatTo2Dec(strValue)
{
    var decPos = strValue.indexOf('.');
    
    if (decPos > 0)
    {
        if (strValue.substring(decPos).length < 3)
        {
            strValue = strValue + "0";
        }
        else if (strValue.substring(decPos).length > 3)
        {
//            strValue = RoundToDigits(strValue,2);
            strValue = TwoDecimalValue(strValue);
        }

    }
    else if (decPos == 0)
    {
        strValue = "0" + strValue;
        if (strValue.length < 4)
        {
            strValue = "0" + strValue + "0";
        }        
    }
    else
    {
        strValue = strValue + ".00";
    }
    
    
    return strValue;
}



jQuery(document).ready(function() {
    
    var span = jQuery(".signup").find(".validation-color").find("span");
    if(span.length>0)
    {
    jQuery(span).css("color","yellow");
    }
    
    
    span = jQuery(".profile-weight").find("span");
    if(span.length>0)
    {
        jQuery(span).css("color","yellow");
        jQuery(".spnkg").css("color","#ffffff");
    }
});

function ShowReceipt(url)
{
   window.open(url); 
}

function formChanged() {
  
  var form = document.forms[0];
  var blnIsChanged = false; 
  for (var i = 0; i < form.elements.length; i++) {
        if(form.elements[i].tagName == "INPUT" && (form.elements[i].type == "checkbox" || form.elements[i].type == "radio")){
            if(form.elements[i].checked != form.elements[i].defaultChecked) 
                blnIsChanged = true;
           }
        if(form.elements[i].tagName == "SELECT"){
                var elm = form.elements[i];
                for(var j=0; j< elm.options.length; ++j)
                { 
                    if(elm.options[j].defaultSelected == elm.options[j].selected)
                        blnIsChanged = true;
                }
           }
        else if(form.elements[i].value != null && form.elements[i].defaultValue != null) {
            if(form.elements[i].id != "hdnFormChanged"){
                if(form.elements[i].value != form.elements[i].defaultValue) 
                    blnIsChanged = true;
               }     
        }       
                
  }
  document.getElementById("hdnFormChanged").value = blnIsChanged; 
}

function ShowBMIWarning(ctrlWeightID,height,rqurl){
   if (http) {
    try{
        http.open("POST", rqurl, false);
        http.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        var parameters = "{'strHeight':'" + height + "','strWeight':'" + jQuery('#'+ctrlWeightID).val() + "'}";

        http.send(parameters);

        if (http.readyState == 4) {
            a = eval("(" + http.responseText + ")");
        }
    }
    catch (e) {
        alert(e);
    }
   }
   
   var result = parseFloat(a.d); 
   var url = "Jc_WelcomeUser.aspx?Weight="+jQuery('#'+ctrlWeightID).val();
   if(result <= 20){
        jQuery.modal(jQuery('#divBMI'));

//        jQuery('#btnOK').click(function() {
//                         window.location.href = url;
//                    });
        jQuery('#simplemodal-container').width(305);
        jQuery('#simplemodal-container').height(290);
        
        return false;
   }
   return true;
}

function ValidatePurchaseMenu()
{
   jQuery(document).ready(function() {
    jQuery.modal(jQuery('#divError'));
    jQuery('#simplemodal-container').width(305);
    jQuery('#simplemodal-container').height(290);
   });
}

function RequireMembershipPuchase()
{
   jQuery(document).ready(function() {
    jQuery.modal(jQuery('#divError'));
    jQuery('#simplemodal-container').width(305);
    jQuery('#simplemodal-container').height(290);
   });
}

function GetDayByMonthYear(yearid,monthid,dayid,rqurl)
{
    var year = jQuery("#"+yearid).val();
    var month = jQuery("#"+monthid).val();
    document.getElementById(dayid).disabled = true;
    document.getElementById(dayid).value = "0";
    
    if(year !="0" && month !="0"){
    
        if (http) {
            try {

                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");

                var parameters = "{'year':'" + year + "','month':'" + month + "'}";

                http.send(parameters);

                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        $('#' + dayid).html(a.d);

        document.getElementById(dayid).disabled = false;
    }
    

}

function ValidateDOB(sender, args)
{
  var year = jQuery("select[id$='ddlYear']").val();
  var month = jQuery("select[id$='ddlMonth']").val();   
  var day = jQuery("select[id$='ddlDay']").val();
  
  args.IsValid = (year!= "0" && month!="0" && day!="0");
  return args.IsValid;       

}


function ValidateOtherHealthCondition(sender,args){
  var checkboxid = jQuery("input:checkbox[id$='chkOther']").attr("id");
  var oCheckbox = document.getElementById(checkboxid);
  
  var txtboxid = jQuery("input:text[id$='txtOtherHealthCondition']").attr("id");
  var oTextBox = document.getElementById(txtboxid);
  
  if(oCheckbox.checked)
  {
     args.IsValid =  jQuery.trim(args.Value).length > 0;
  }

  return args.IsValid;
}

function EnableOtherComment(oCheckbox)
{
  var txtboxid = jQuery("input:text[id$='txtOtherHealthCondition']").attr("id");
  var oTextBox = document.getElementById(txtboxid);
  
  if(oCheckbox.checked)
  {
     oTextBox.disabled = false;
  }
  else
  {
     oTextBox.disabled = true;
     oTextBox.value = "";
  }
}


/*
   Made Parent child realtion-ship
*/
jQuery(document).ready(function() {

  jQuery('div.divHealthInfoComment > table.table-health').find("td.td-subhealth").parent().hide().find("input").attr("disabled","true");
  jQuery('div.divHealthInfoComment > table.table-health').find("td.td-health").each(function(){
  
    jQuery(this).find("input").click(function(){
    
        var $Next = $(this).parent().parent().parent().next().find("td");
        
        if(this.checked)
        {
            while($Next.hasClass('td-subhealth'))
            {
               $Next.parent().show().find("input:checkbox").removeAttr("disabled");
               $Next = $Next.parent().next().find("td");         
            }  
        }
        else
        {
            while($Next.hasClass('td-subhealth'))
            {
               $Next.parent().hide().find("input:checkbox").attr("disabled","true").removeAttr("checked");
               $Next = $Next.parent().next().find("td");         
            }  
        }
    });
  });
});

jQuery(document).ready(function() {
    jQuery(".payment-display").removeClass("payment-display");
});

function ValidateUpdatedDetails()
{   
     if(!Page_ClientValidate("myProfile") || !Page_ClientValidate("vgInitial"))
     {
        return false;
     }
    var objMyProfile=jQuery("form[id$='MyProfileForm']");
    
    var chkCancer = document.getElementById(objMyProfile.find("input:checkbox[id$='chkCancer']").attr("id")).checked;
    var chkCeliacDisease = document.getElementById(objMyProfile.find("input:checkbox[id$='chkCeliacDisease']").attr("id")).checked;
    var chkGallBladderStone = document.getElementById(objMyProfile.find("input:checkbox[id$='chkGallBladderStone']").attr("id")).checked;
    var chkGallBladderRemoved = document.getElementById(objMyProfile.find("input:checkbox[id$='chkGallBladderRemoved']").attr("id")).checked;
    var chkGastrointestinalDisease = document.getElementById(objMyProfile.find("input:checkbox[id$='chkGastrointestinalDisease']").attr("id")).checked;
    var chkCrohnDisease = document.getElementById(objMyProfile.find("input:checkbox[id$='chkCrohnDisease']").attr("id")).checked;
    var chkDiverticulitis = document.getElementById(objMyProfile.find("input:checkbox[id$='chkDiverticulitis']").attr("id")).checked;
    var chkUlcerativeColitis = document.getElementById(objMyProfile.find("input:checkbox[id$='chkUlcerativeColitis']").attr("id")).checked;
    // 20110916 LN - added (ref bugsy #3915)
    var chkHeartburnReflux = document.getElementById(objMyProfile.find("input:checkbox[id$='chkHeartburnReflux']").attr("id")).checked;
    var chkGout = document.getElementById(objMyProfile.find("input:checkbox[id$='chkGout']").attr("id")).checked;
    var chkHeartDiseas = document.getElementById(objMyProfile.find("input:checkbox[id$='chkHeartDiseas']").attr("id")).checked;
    var chkHypoglycemia = document.getElementById(objMyProfile.find("input:checkbox[id$='chkHypoglycemia']").attr("id")).checked;
    var chkKidneyStones = document.getElementById(objMyProfile.find("input:checkbox[id$='chkKidneyStones']").attr("id")).checked;
    var chkTakingLithium = document.getElementById(objMyProfile.find("input:checkbox[id$='chkTakingLithium']").attr("id")).checked;
    var chkPostpartum = document.getElementById(objMyProfile.find("input:checkbox[id$='chkPostpartum']").attr("id")).checked;
    var chkStomachStapling = document.getElementById(objMyProfile.find("input:checkbox[id$='chkStomachStapling']").attr("id")).checked;
    var chkSurgery = document.getElementById(objMyProfile.find("input:checkbox[id$='chkSurgery']").attr("id")).checked;
    
    var chkThyroid = document.getElementById(objMyProfile.find("input:checkbox[id$='chkThyroid']").attr("id")).checked;
    var chkAnorexia = document.getElementById(objMyProfile.find("input:checkbox[id$='chkAnorexia']").attr("id")).checked;      
    var chkBreastfeedingYounger = document.getElementById(objMyProfile.find("input:checkbox[id$='chkBreastfeedingYounger']").attr("id")).checked;
    var chkBreastfeedingOlder = document.getElementById(objMyProfile.find("input:checkbox[id$='chkBreastfeedingOlder']").attr("id")).checked;
    var chkCardiacArrhythmia = document.getElementById(objMyProfile.find("input:checkbox[id$='chkCardiacArrhythmia']").attr("id")).checked;
    var chkKidneyDisease = document.getElementById(objMyProfile.find("input:checkbox[id$='chkKidneyDisease']").attr("id")).checked;
    var chkChronicRenal = document.getElementById(objMyProfile.find("input:checkbox[id$='chkChronicRenal']").attr("id")).checked;
    var chkKidneyTransplant = document.getElementById(objMyProfile.find("input:checkbox[id$='chkKidneyTransplant']").attr("id")).checked;
    // 20110916 LN - Missing?? :
    // Liver Deisese, Stroke, Depression, Diabetes Melitus (sub: Diet Controlled, Oral Medication), Hyperlipidemia,High Blood Pressure (sub: on medication, not on medication), athritis (sub:  Steroid Medication or Methotrexate) 
    var ChkMAOIMedications = document.getElementById(objMyProfile.find("input:checkbox[id$='ChkMAOIMedications']").attr("id")).checked;
    var chkCurrentPregnancy = document.getElementById(objMyProfile.find("input:checkbox[id$='chkCurrentPregnancy']").attr("id")).checked;
    // 20110916 LN - Removed (ref bugsy #3915)
    //var chkPrimaryPulmonary = document.getElementById(objMyProfile.find("input:checkbox[id$='chkPrimaryPulmonary']").attr("id")).checked;
    var chkSeizures = document.getElementById(objMyProfile.find("input:checkbox[id$='chkSeizures']").attr("id")).checked;
    var chkLithiumMAOImedications = document.getElementById(objMyProfile.find("input:checkbox[id$='chkLithiumMAOImedications']").attr("id")).checked;
    var chkInsulinDependent = document.getElementById(objMyProfile.find("input:checkbox[id$='chkInsulinDependent']").attr("id")).checked;
    var chkOther = document.getElementById(objMyProfile.find("input:checkbox[id$='chkOther']").attr("id")).checked;
    
    var chkNoMedicalCondition = !document.getElementById(objMyProfile.find("input:checkbox[id$='chkNoMedicalCondition']").attr("id")).checked;
    
    // 20110916 LN - Registration refresh (bugsy #3915)
    var check =chkNoMedicalCondition+","+chkCancer +","+ chkCeliacDisease+","+chkGallBladderStone+","+chkGallBladderRemoved+","+chkGastrointestinalDisease+","+chkCrohnDisease+","+
                chkDiverticulitis+","+chkUlcerativeColitis+","+chkHeartburnReflux+","+chkGout+","+chkHeartDiseas+","+chkHypoglycemia+","+chkKidneyStones+","+
                chkTakingLithium+","+chkTakingLithium+","+chkPostpartum+","+chkStomachStapling+","+chkSurgery+","+chkThyroid+","+chkAnorexia+","+
                chkBreastfeedingYounger+","+chkBreastfeedingOlder+","+chkCardiacArrhythmia+","+chkKidneyDisease+","+chkChronicRenal+","+
                chkKidneyTransplant+","+ChkMAOIMedications+","+chkCurrentPregnancy+","+chkPrimaryPulmonary+","+chkSeizures+","+
                chkLithiumMAOImedications+","+chkOther;
    
    var dob =objMyProfile.find("input:text[id$='dtDOB']").val();
    
    var txtheight = objMyProfile.find("input:text[id$='txtHeight']").val();
    var txtweight = objMyProfile.find("input:text[id$='txtWeight']").val();
    var txtGoalWeight = objMyProfile.find("input:text[id$='txtGoalWeight']").val();
    
    var phyactivity =0;
    if(document.getElementById(objMyProfile.find("input:radio[id$='rdoLight']").attr("id")).checked)
    {
         phyactivity = 1;
    }
    else if(document.getElementById(objMyProfile.find("input:radio[id$='rdoModerate']").attr("id")).checked)
    {
         phyactivity = 2;
    }
    else if(document.getElementById(objMyProfile.find("input:radio[id$='rdoHeavy']").attr("id")).checked)
    {
          phyactivity = 3;
    }
   
    var phyLim= document.getElementById(objMyProfile.find("input:radio[id$='rdoPhLimitationYes']").attr("id")).checked;
    var foodConstrarint= document.getElementById(objMyProfile.find("input:radio[id$='rdoFoodConstrarintYes']").attr("id")).checked;
    var rdoLiyes=objMyProfile.find("input:radio[id$='rdoLiyes']").attr("id");
    var lactoseInt;
    if(rdoLiyes !=null)
    {
     lactoseInt = document.getElementById(objMyProfile.find("input:radio[id$='rdoLiyes']").attr("id")).checked;
    }
    else
    {
        lactoseInt = document.getElementById(objMyProfile.find("input:radio[id$='rdoliNo']").attr("id")).checked;
    }
    
    var Milkcup;
    var rdoMilkcupYes=objMyProfile.find("input:radio[id$='rdoLiyes']").attr("id");   
    if(rdoMilkcupYes !=null)
    {
       Milkcup= document.getElementById(objMyProfile.find("input:radio[id$='rdoMilkcupYes']").attr("id")).checked;
    }
    else
    {
       Milkcup= document.getElementById(objMyProfile.find("input:radio[id$='rdomilkcupNo']").attr("id")).checked;
    }
    
    var DietRequire;
    var rdoDietrequireYes=objMyProfile.find("input:radio[id$='rdoDietrequireYes']").attr("id");
    if(rdoDietrequireYes !=null)
    {  
         DietRequire= document.getElementById(objMyProfile.find("input:radio[id$='rdoDietrequireYes']").attr("id")).checked;
    }
    else
    {
        DietRequire= document.getElementById(objMyProfile.find("input:radio[id$='rdodietrequireNo']").attr("id")).checked;
    }
    
    var AnimalDerv= document.getElementById(objMyProfile.find("input:radio[id$='rdoanimalingrYes']").attr("id")).checked;
    
    var Vegan= document.getElementById(objMyProfile.find("input:radio[id$='rdoVeganYes']").attr("id")).checked;
    var Vegetarain= document.getElementById(objMyProfile.find("input:radio[id$='rdoVegetarianYes']").attr("id")).checked;

    var rFemale= document.getElementById(objMyProfile.find("input:radio[id$='rbFemale']").attr("id")).checked;
    var rMale= document.getElementById(objMyProfile.find("input:radio[id$='rbMale']").attr("id")).checked;
    
    jQuery.post("./ajax.aspx", { action: "validateprofiledetails",DOB:dob,chkhealth:check,height:txtheight,weight:txtweight,goal:txtGoalWeight,
               PhyActivity:phyactivity,Limitation:phyLim,Constrarint:foodConstrarint,lactoseInt:lactoseInt,Milkcup:Milkcup,DietRequire:DietRequire,AnimalDerv:AnimalDerv,
               Veg:Vegan,vegt:Vegetarain,
               Female:rFemale,Male:rMale},
      function(data) {
        if(data=="true")
        {  
            ShowForgotPassord('modelAlert','http://my.jennycraig.com.au/',1);
        }
        else
        { 
            __doPostBack('btnsaveChange','');
        }
      });
       return false;
 }
 
 function profileSave()
 {
    jQuery("input:hidden[id$='hfIsLogOut']").val('1');
    __doPostBack('btnsaveChange','');
 }
  
 function GetPostcodeSuburbJoinToday(rqurl, val, id,stateid, clientid) {
    var arId = clientid.split('#');
    
    for (var i = 0; i < arId.length; ++i) {
        document.getElementById(arId[i]).value = "0";
        document.getElementById(arId[i]).disabled = true;
    }
    
    if (val != "0") {
        if (http) {
            try {
                http.open("POST", rqurl, false);
                http.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                var parameters = "{'value':'" + val + "','id':'" + id + "','stateid':'" + stateid + "'}";

                http.send(parameters);
                if (http.readyState == 4) {
                    a = eval("(" + http.responseText + ")");
                }
            }
            catch (e) {
                alert(e);
            }
        }

        for (var i = 0; i < arId.length; ++i) {
            if (i == 0) {
                $('#' + arId[i]).html(a.d);
                document.getElementById(arId[i]).disabled = false;
            }
            if (i > 0) {
                if(arId[i].search(/Postcode/i)>0)
                {
                    $('#' + arId[i]).html("<option value=\"0\">Postcode</option>");
                }
                else if(arId[i].search(/Suburb/i)>0)
                {
                    $('#' + arId[i]).html("<option value=\"0\">Suburb</option>");
                } 
                document.getElementById(arId[i]).disabled = true;
            }
        }
    }
    else {

        for (var i = 0; i < arId.length; ++i) {
            $('#' + arId[i]).empty();
            
            if(arId[i].search(/Postcode/i)>0)
            {
                $('#' + arId[i]).html("<option value=\"0\">Postcode</option>");
            }
            else if(arId[i].search(/Suburb/i)>0)
            {
                $('#' + arId[i]).html("<option value=\"0\">Suburb</option>");
            }    
            document.getElementById(arId[i]).disabled = true;
        }
    }
}
 
 ///////////////about jenny cuisine /////////////
 
 jQuery(document).ready(function() {

  $("a.planned").click(function() {
     jQuery("div[id$='imgPlannedMenu']").removeClass("hide");    
     jQuery("div[id$='imgPersonalizedMenu']").addClass("hide");  
     jQuery("div[id$='imgVegMenu']").addClass("hide");     
     return false; 
        });
    
  $("a.personalized").click(function() {
     jQuery("div[id$='imgPersonalizedMenu']").removeClass("hide");    
     jQuery("div[id$='imgPlannedMenu']").addClass("hide");  
     jQuery("div[id$='imgVegMenu']").addClass("hide");  
     return false;     
        });
        
  $("a.Veg").click(function() {
    jQuery("div[id$='imgVegMenu']").removeClass("hide");    
    jQuery("div[id$='imgPlannedMenu']").addClass("hide");  
    jQuery("div[id$='imgPersonalizedMenu']").addClass("hide"); 
    return false;
       });  
 }); 
 
 /*GetStarted*/
 jQuery(document).ready(function() {
 
    var hdnSign = jQuery("input[id$='hdnIsLogin']").val();
      if(hdnSign !=null)
      {
            if(hdnSign=="true")
            {
                //jQuery("div[id$='getStarted']").hide(); 
                jQuery(".afterLogin").hide(); 
                jQuery("div[id$='ContactJoinNow']").hide(); 
                //jQuery("div[id$='headerSignup-btn']").hide(); 
            }
            else
            {
                 jQuery(".afterLogin").show();
            }
       }
 }); 

 

 /*Header*/
 jQuery(document).ready(function() {
 
    var hdnSign = jQuery("input[id$='hdnIsLogin']").val();
      if(hdnSign !=null)
      {
            if(hdnSign=="true")
            {
                jQuery("div[id$='headerTop']").addClass("header-bg-inner") ;
            }
            else
            {
                jQuery("div[id$='headerTop']").addClass("header-bg") ;
            }
       }
 }); 
 

  
var mainImageOuter = ".mainImageOuter"
var pagination = ".pagination"
jQuery(document).ready(function() {

    //call image rotation
    var mainOuter = jQuery(mainImageOuter);
    if (mainOuter != null) {
        bindDefaultEvents();
        //setActiveImage();
        
        var objImg = jQuery(".pagination").find('#page1').find("img");
        SrcImageSetHover(objImg);
        
        //initilize timer
        if (jQuery(mainImageOuter).length > 0) {
            jQuery(mainImageOuter).cycle({
                fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                startingSlide: 0
            });
        }
    }
})

function setActiveImage() {
    //mousehover and out event on command
    jQuery(pagination).find("img").each(function() {
        jQuery(this).mouseover(function() {
            jQuery(mainImageOuter).cycle('pause');
        });
        jQuery(this).mouseout(function() {
            var currentCmdId = jQuery(this).parent().parent().find(".active").attr("id");
            jQuery(mainImageOuter).cycle('resume', false);
        });
    });
}


function bindDefaultEvents() {
    jQuery(pagination).find("img").each(function() {
        //mouseover
        jQuery(this).mouseover(function(e) {
            activeTab = jQuery(this).parent().removeClass("inactive").addClass("active").attr("id");
            var objImg = jQuery('#'+activeTab).find("img");
            SrcImageSetHover(objImg)
            jQuery(pagination).find("img").each(function() {
                var tabId = jQuery(this).parent().attr("id");
                
                if (activeTab != tabId) {
                    jQuery(this).parent().removeClass("active").addClass("inactive");
                    
                      var objImg = jQuery('#'+tabId).find("img");
                        SrcImageResetHover(objImg)
                }
            });

            //get active image index
            var index = activeTab.replace('page', '');
            setActiveImage();

            //initilize timer with current selected slide
            jQuery(mainImageOuter).cycle({
                fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                startingSlide: index - 1
            });
            //pause timer
            jQuery(mainImageOuter).cycle('pause');
        });
    });
}

function setActivePagination(index, totalCount) {
    totalCount = totalCount + 1;
    index = index + 2;
    if (index == totalCount) {
        index = 1;
    }
    var $activeCommand = jQuery(pagination).find("div[id$='page" + index + "']");

    if ($activeCommand != null) {
        var activeTab = $activeCommand.removeClass("inactive").addClass("active").attr("id");
        var objImg = jQuery('#'+activeTab).find("img");
        SrcImageSetHover(objImg)
        jQuery(pagination).find("img").each(function() {
            var tabId = jQuery(this).parent().attr("id");
            if (activeTab != tabId) {
                jQuery(this).parent().removeClass("active").addClass("inactive");
                 var objImg = jQuery('#'+tabId).find("img");
                 SrcImageResetHover(objImg)
            }
        });
        setActiveImage();
    }
}

  
 function SrcImageSetHover(obj) {

    var src = obj.attr("src");
    var newSrc = "";
    if(src !=null)
    {
    if (src.indexOf("-hover") > 0) {
        newSrc = src.replace("-hover", "");
    }
    else {
        newSrc = newSrc + src.replace(/(.+)(\.[a-z]+)$/, "$1-hover$2");
    }

        obj.attr("src", newSrc);
    }
}
function SrcImageResetHover(obj) {


    var src = obj.attr("src");
    var newSrc = "";
    if(src !=null)
    {
    if (src.indexOf("-hover") > 0) {
        newSrc = src.replace("-hover", "");
    }
    else
    {
        newSrc=src;
    }
    
    obj.attr("src", newSrc);
    }
}

//content bg adjust using js
jQuery(document).ready(function() {
    if (navigator.appName == "Microsoft Internet Explorer" && jQuery(".mainImageOuter").length >0) {
        jQuery(".content-area").css("margin-left", "3px");
        jQuery(".footer-bg").css("margin-left", "3px");
        
    }
    else {
        //jQuery(".content-area").css("margin-left", "3px");
        //jQuery(".footer-bg").css("margin-left", "3px");
    }
    
//    if(jQuery("form[id#='PurchaseMembershipForm']").length>0)
//    {
//        jQuery("form[id#='PurchaseMembershipForm']").find(".content-area").css("background-position","left");
//    }

if (jQuery(".mainImageOuter").length > 0) {
        jQuery(".mainImageOuter").show();
    }
    

    
});

//$.ajaxSetup({   
//      beforeSend:function(){   
//         $("#divResult").show();   
//      },   
//      complete:function(){   
//         $("#divResult").hide();   
//     },
//     success:function(){   
//         $("#divResult").hide();   
//     }
//   }); 


 







