﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

jQuery(document).ready(function () {
    LoadImage(); 
    BindDateFieldEvents();

});
var ServerDte, baseUrl;
/*    Start : Getting Started    */
jQuery('.FP').live('click', function () {
    var blnValid = true;
    var errMsg = "";

    if (!(jQuery("[id$='chkIsMedicare']").is(':checked'))) {
        jQuery(this).attr('class', 'hidden'); errMsg += '<p>If you`re not entitled to full Australian Medicare, you may qualify for our <a href="javascript:RedirectToOSVCover();">Overseas Visitors Health Cover</a></p>';
        if (blnValid) {
            blnValid = false;
        }
    }

    if (!(jQuery("[id$='chkIsMember']").is(':checked'))) {

        jQuery(this).attr('class', 'hidden'); errMsg += '<p>Existing HCF members are unable to complete the online application form at this time. Please call 13 13 34 to discuss your options.</p>';
        blnValid = false;
    }

    if (errMsg != "") {
        jQuery("#errorMsg").html(errMsg);
    }
    return blnValid;
});
 
function RedirectToOSVCover() {
    window.close();
    window.opener.location = ResolveUrl("~/healthinsurance/overseas-visitors-health-cover/");
    return false;
}

jQuery("[id$='chkIsMember']").live('click', function () { if (jQuery(this).is(':checked')) { jQuery("#errorMsg").html(''); jQuery("[id$='lknGSNext']").attr('class', 'button next FP'); } });
jQuery("[id$='chkIsMedicare']").live('click', function () { if (jQuery(this).is(':checked')) { jQuery("#errorMsg").html(''); jQuery("[id$='lknGSNext']").attr('class', 'button next FP'); } });

/*    End : Getting Started    --------------------------------------------------------------------------------------------------------------------*/

/*    Start : Personal Details  page    */

jQuery("[id$='lknNext']").live('click', function () { IsThisPageValid(); });

function PersonalPageOnLoad() {
    if (!(jQuery("[id$='SameAddress']").is(':checked'))) {
        jQuery("[id$='SameAddress']").parent().next().show("fast");
        PostalAddressEnableValidators(true);
    } else { PostalAddressEnableValidators(false); }

    if ((jQuery("[id$='chkRebate']").is(':checked'))) {
        jQuery("[id$='chkRebate']").parent().next().attr('class', '');
        MedicareEnableValidators(true);
    } else { MedicareEnableValidators(false); }

    jQuery('#PersonalDetails .edit').each(function (i) {//Hide the edit Button in Personal Details page
        jQuery('#' + jQuery(this).attr('id')).attr('class', 'hidden');
    });
}

function PostalAddressEnableValidators(blnVal) {
    var ID = jQuery("[id$='PostalA']").attr('id') + ' .Validate';
    EnableValidators(ID, blnVal); ;
}

function MedicareEnableValidators(blnVal) { EnableValidators('divRebate .Validate', blnVal); }

function dep() {
    //if hdnMaxDepCount exist then the application will have dependent and this variable will hold maximum value count of the dependant
    var MaxDepCount;
    if (jQuery.find("[name$='hdnMaxDepCount']") != "") {
        MaxDepCount = jQuery("[name$='hdnMaxDepCount']").val();
        //        alert(MaxDepCount);
        for (J = 1; J <= MaxDepCount; J++) {
            var id = jQuery("[id$='dep_" + J + "']").attr('id') + ' .Validate';
            jQuery('.col.right', "[id$='dep_" + J + "']").append('<div id="' + J + '" class="removePersonButton">Remove this person</div>');
            EnableValidators(id, false);
        }
    }
    var controlKey = jQuery.find("[name$='hdnpersonaldetails']");
    if (controlKey != "") {
        var controlKeyValue = jQuery("[name$='hdnpersonaldetails']").val();
        if (controlKeyValue != '') {
            if (controlKeyValue != MaxDepCount)
                jQuery("input[name$='hdndepcount']").val(parseInt(controlKeyValue) + 1); //Assign the server value to depcount and update the running number for the depeaby adding + 1
            else
                jQuery("input[name$='hdndepcount']").val(controlKeyValue); //Assign the server value to depcount - if its the max value do add the running number
        }
        for (J = 1; J <= controlKeyValue; J++) {
            jQuery("[id$='dep_" + J + "']").attr('class', 'depPerson').fadeIn();
            var id = jQuery("[id$='dep_" + J + "']").attr('id') + ' .Validate';
            EnableValidators(id, true);
            DisableSchoolContorlValidators(id);
            //countt();
        }
    }
}

function DisableSchoolContorlValidators(Selector) {
    var ctrl = '#' + Selector;
    var lctrl = Selector.split('_');
    var no = lctrl[3].split('.');
    var s = new String(no[0]);
    s = s.trim();
    var id = s + "_ddlRelationship";
    var Relationship = jQuery("select[id$='" + id + "']").val(); //change to running id
    jQuery(document).ready(function () {
        jQuery(ctrl).each(function (i) {
            var ctrl = jQuery(this).attr('id').split('_');
            var Ctrid = ctrl[2] + '_' + ctrl[3];
            EnabledivDepSchool(Relationship, Ctrid)//show right year dropdown list based on relation ship
            if (jQuery(this).attr('id').indexOf('rfvSchool') >= 0) {
                if (Relationship == "Dependant Child") { ValidatorEnable(this, false); }
            }
        });
    });
}

var RelationshipID = "";
jQuery("[id$=ddlRelationship]").live('click', function () {
    RelationshipID = jQuery(this).attr('id'); //get the id of the control and save it in RelationshipID which will be used on selection on the ddl via <li> tag
});

jQuery("[id$=ddlRelationship] li").live('click', function () {
    var dllValue = jQuery(this).data('value');
    //Target Id =ctl00_cphMainContent_dep_1_divDepSchool lenght is 5 to get the control block id dep_i below split and join below 2 line code
    var ctrl = RelationshipID.split('_');
    var Ctrid = ctrl[2] + '_' + ctrl[3];
    EnabledivDepSchool(dllValue, Ctrid);
});

function EnabledivDepSchool(ddlValue1, Ctrid1) {
    var Ctrid = Ctrid1;
    var ddlValue = ddlValue1;
    if (ddlValue1 == "Student Dependant") {
        jQuery("[id$=" + Ctrid + "_ddldepYear]").removeClass('hidden'); //show dep year ddl
        jQuery("[id$=" + Ctrid + "_ddlYear]").addClass('hidden'); //hide default year ddl
        jQuery("[id$=" + Ctrid + "_divDepSchool]").removeClass('hidden');
        var ID = jQuery("[id$=" + Ctrid + "_divDepSchool]").attr('id') + ' .Validate';
        EnableValidators(ID, true);
    }
    else {
        jQuery("[id$=" + Ctrid + "_ddlYear]").removeClass('hidden'); //show default year ddl
        jQuery("[id$=" + Ctrid + "_ddldepYear]").addClass('hidden'); //hide dep year ddl
        jQuery("[id$=" + Ctrid + "_divDepSchool]").addClass('hidden');
        var ID = jQuery("[id$=" + Ctrid + "_divDepSchool]").attr('id') + ' .Validate';
        EnableValidators(ID, false);
    }
}

/*    Join Form: 'Add another person'    */

jQuery('.addPersonButton').live('click', function () {
    if (CheckDepValues()) {
        var removedItem;
        var MaxDepCount = parseInt(jQuery("[name$='hdnMaxDepCount']").val(), 10);
        var DepCount = parseInt(jQuery("[name$='hdndepcount']").val(), 10); //Get the value of dep #
        jQuery('.removed').each(function (i) { //Check if there any removed dep item
            //ctl00_cphMainContent_divdep_1 //28 is length of the id name with out the running number
            removedItem = jQuery(this).attr("id").substring(28);
            return false;
        });
        if (removedItem != null) {
            jQuery("[id$='dep_" + removedItem + "']").attr('class', 'depPerson').fadeIn();
            jQuery("#" + jQuery("[id$='dep_" + removedItem + "']").attr('id') + " :input[type='text']:first").focus(); //Focus the first tet box elelmer
            jQuery('.col.right', "[id$='dep_" + removedItem + "']").append('<div id="' + removedItem + '" class="removePersonButton">Remove this person</div>');
            DependantEnableValidators(jQuery("[id$='dep_" + removedItem + "']").attr('id') + " .Validate", true);
        }
        else {
            jQuery("[id$='dep_" + DepCount + "']").attr('class', 'depPerson').fadeIn();
            jQuery("#" + jQuery("[id$='dep_" + DepCount + "']").attr('id') + " :input[type='text']:first").focus(); //Focus the first tet box elelmer
            if (jQuery('#' + DepCount).length == 0)//check if remove person div is already avaliable! if yes do n0t add the removeperson div tag again.
                jQuery('.col.right', "[id$='dep_" + DepCount + "']").append('<div id="' + DepCount + '" class="removePersonButton">Remove this person</div>');
            DependantEnableValidators(jQuery("[id$='dep_" + DepCount + "']").attr('id') + " .Validate", true);
        }
        DepCount = parseInt(jQuery("[name$='hdndepcount']").val(), 10);
        if (DepCount < MaxDepCount) {
            jQuery("input[name$='hdndepcount']").val(DepCount + 1); //move to the next dependant and store in the hidden variable
        }
        if (DepCount == MaxDepCount) {
            jQuery("[id$='divAddPerson']").attr('class', 'hidden addPersonButton');
            jQuery("#divDepMsg").attr('class', 'DeperrorMsg');
            jQuery("#divDepMsg").text('You are limited to adding 10 dependants. If you need to add more than this, please call HCF on 13 13 34.');
        }
        else
            jQuery("#divDepMsg").attr('class', 'DeperrorMsg hidden');
        personTitleUpdate();
        return false;
    }
    else {
        jQuery("#divDepMsg").attr('class', 'DeperrorMsg');
        jQuery("#divDepMsg").text('Please enter the dependant information above first before adding another dependant');
    }
});

function DependantEnableValidators(Selector, blnVal) {
    EnableValidators(Selector, blnVal); //Enable all the validators for dependants
    var DepSelector = "#" + Selector;
    jQuery(DepSelector).each(function (i) { //Search through all the validators inside this dependant
        if (jQuery(this).attr('id').indexOf('School') >= 0) {//Disable validators for School/Uni text box
            ValidatorEnable(this, false);
        }
    });
}

jQuery('.removePersonButton').live('click', function (i) {
    var MaxDepCount = jQuery("[name$='hdnMaxDepCount']").val();
    var DepNo = jQuery(this).attr("id"); //get the id of the clicked id
    jQuery('#' + DepNo).remove(); //remove the div of remove this person button else next time add aperson will add 2 button
    jQuery("[id$='dep_" + DepNo + "']").attr('class', 'hidden removed'); //Hide the dependant elements
    ClearcontrolsValues(jQuery("[id$='dep_" + DepNo + "']").attr('id'));
    EnableValidators(jQuery("[id$='dep_" + DepNo + "']").attr('id') + " .Validate", false);
    var DepCount = jQuery("[name$='hdndepcount']").val(); //get the count of the dependant and reduce one.
    if (DepCount != "1") //default number
        jQuery("input[name$='hdndepcount']").val(parseInt(DepCount) - 1);
    if (DepCount <= MaxDepCount) {
        jQuery("[id$='divAddPerson']").attr('class', 'addPersonButton');
        jQuery("#divDepMsg").attr('class', 'hidden');
    }
    jQuery("#divDepMsg").attr('class', 'hidden'); //Check for the check dep values
    personTitleUpdate();
    return false;
});


function CheckDepValues() {
    var blnVal = true;
    var varRelationShip = '';
    var txtSchool = '';
    jQuery(".depPerson").each(function (i) {
        jQuery("#" + jQuery(this).attr('id') + " :input").each(function (i) {
            if (jQuery(this).attr('id').indexOf('ddlRelationship') != -1) {
                varRelationShip = jQuery("#" + jQuery(this).attr('id') + " :selected").val();
            }
            if (jQuery(this).attr('id').indexOf('txtSchool') != -1) {
                txtSchool = this.value;
            }
        });
        jQuery("#" + jQuery(this).attr('id') + " :input").each(function (i) {
            var type = this.type;
            var tag = this.tagName.toLowerCase();
            if (jQuery(this).attr('id').indexOf('txtSchool') == -1) {
                if (type == 'text' || type == 'password' || tag == 'textarea') {
                    if (this.value == "")
                        blnVal = false;
                    else
                        blnVal = true;
                }
            }
            //            else if (type == 'checkbox' || type == 'radio')
            //                this.checked = false;
            //            // select elements need to have their 'selectedIndex' property set to -1
            //            // (this works for both single and multiple select elements) in our project this select index will not work because of the design
            //            else if (tag == 'select') {
            //                //this.selectedIndex = 1;//                var id = jQuery(this).attr('id');//                alert(jQuery("#" + id + " :selected").index());//                jQuery("#" + id + " :selected").get(0).selectedIndex = 0//                alert(jQuery("#" + id + " :selected").index());
            //            }
            //            alert('varRelationShip: ' + varRelationShip + 'txtSchool:   ' + txtSchool);
            //            if (varRelationShip == "Dependant Child" && txtSchool == "") {
            //                alert('inside');
            //                blnVal = true;
            //            }
            //            alert(blnVal);
        });

        if ((varRelationShip == "Dependant Child" && txtSchool == "" && blnVal == true) || (varRelationShip == "Student Dependant" && txtSchool != "" && blnVal == true)) blnVal = true; //dep child and txt school is null or student dep and school not null-- true
        else blnVal = false;
    });
    return blnVal;
}

function ClearcontrolsValues(id) {
    jQuery("#" + id + " :input").each(function (i) {
        var type = this.type;
        var tag = this.tagName.toLowerCase();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = "";
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        // select elements need to have their 'selectedIndex' property set to -1
        // (this works for both single and multiple select elements) in our project this select index will not work because of the design
        else if (tag == 'select') {
            //this.selectedIndex = 1;//                var id = jQuery(this).attr('id');//                alert(jQuery("#" + id + " :selected").index());//                jQuery("#" + id + " :selected").get(0).selectedIndex = 0//                alert(jQuery("#" + id + " :selected").index());
        }
    });
}

//for each 'depPerson' set title - eg "Dependant #1", "Dependant #2", "Dependant #3" etc
function personTitleUpdate() {
    jQuery('.depPerson').each(function (i) {
        var iPlusOne = i + 1;
        jQuery('h2', this).text('Dependant #' + iPlusOne);
    });
} //end personTitleUpdate()

jQuery("[id$='SameAddress']").live('click', function () {

    var next = jQuery(this).parent().next();
    if (jQuery(this).is(':checked')) {
        next.hide('fast');
        PostalAddressEnableValidators(false);
    }
    else {
        next.show('fast');
        PostalAddressEnableValidators(true);
    }
});

//Medicare Controls Eligible
jQuery("[id$='chkRebate']").live('click', function () {
    var next = jQuery(this).parent().next();
    if (jQuery(this).is(':checked')) {
        next.show('fast');
        MedicareEnableValidators(true);
    }
    else {
        MedicareEnableValidators(false);
        next.hide('fast');
    }
});

/* --------------------------------------------    End : Personal Details page      --------------------------------------------*/

/* --------------------------------------------    Start   :   Confirmation page    --------------------------------------------*/

//Items Edit

jQuery(".Confirm").live("click", function () {
    if (EditStatus != "Closed") {
        alert("Please close the edit mode");
        return false;
    }
});

var EditStatus = "Closed";
jQuery('.edit').live('click', function () {
    //Hide and display Edit and Update button respectivly
    if (EditStatus != "Closed") {
        alert("Edit mode is already enabled for another panel.");
    }
    else
        ShowHide(jQuery(this).attr('id'));
});

function ShowHide(ctrlId) {
    //alert(ctrlId);
    ctrlId
    ctrlId.replace('Edit', 'Update');
    jQuery("#" + ctrlId).attr('class', 'hidden');
    jQuery("#" + jQuery("[id$=" + ctrlId + "]").attr('id').replace('Edit', 'Update')).attr('Class', 'button grey Update');
    ShowControl("#" + ctrlId, true);
    EditStatus = "Open";
    return false;
}

jQuery('.Update').live('click', function () {
    if (IsThisPageValid()) {
        ShowControl("#" + jQuery(this).attr('id'), false);
        jQuery('#' + jQuery(this).attr('id')).attr('class', 'hidden');
        jQuery('#' + jQuery(this).attr('id').replace('Update', 'Edit')).attr('Class', 'button grey edit');
        EditStatus = "Closed";
    }
    return false;
});

function ShowControl(ctrl, blnVal) {
    var ControlDisplay, labelDisplay;
    if (ctrl.indexOf("ContactDetails") != -1) {
        ControlDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_ContactDetails', '_divContactControls');
        labelDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_ContactDetails', '_divConfirmation');
        AssignContactDetailsControlValuesToLabels(ControlDisplay);
    }
    else if (ctrl.indexOf("Address") != -1) {
        ControlDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_Address', '_divAddressControls');
        labelDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_Address', '_divConfirmation');
        AssignAddressDetailsControlValuesToLabels(ControlDisplay);
    }
    else if (ctrl.indexOf("PersonalDetails") != -1) {
        ControlDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_PersonalDetails', '_divPersonalDetailsControls');
        labelDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_PersonalDetails', '_divConfirmation');
        AssignPersonalDetailsControlsValuesToLables(ControlDisplay);
    }
    else if (ctrl.indexOf("Rebate") != -1) {
        ControlDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_Rebate', '_divRebateControls');
        labelDisplay = jQuery(jQuery(ctrl).parent().get(0)).attr('id').replace('_Rebate', '_divConfirmation');
        AssignRebateDetailsControlsValuesToLables(ControlDisplay);
    }
    if (blnVal) {
        jQuery('#' + ControlDisplay).attr('class', '');
        EnableValidators(ControlDisplay + " .Validate", blnVal);
        if (ctrl.indexOf("PersonalDetails") != -1) { DisableSchoolContorlValidators(ControlDisplay); }
        jQuery('#' + labelDisplay).attr('class', 'hidden');
    }
    else {
        jQuery('#' + ControlDisplay).attr('class', 'hidden');
        EnableValidators(ControlDisplay + " .Validate", blnVal);
        jQuery('#' + labelDisplay).attr('class', '');
    }
}

function GetControlsId(BaseId, idName) {
    return BaseId + "_" + idName;
}

function GetBaseControlId(id) {
    var ctrl = id.split('_');

    return ctrl[id.split('_').length - 2];
}

function AssignPersonalDetailsControlsValuesToLables(Valctrl) {
    var plcHol = GetBaseControlId(Valctrl);
    var idDay = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlDay") + "']").attr('id') + ' .selected';
    var idMonth = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlMonth") + "']").attr('id') + ' .selected';
    var idYear = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlYear") + "']").attr('id') + ' .selected';
    var idDepYear = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddldepYear") + "']").attr('id') + ' .selected';
    var idDepRelation = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlRelationship") + "']").attr('id') + ' .selected';
    jQuery("[id$='" + GetControlsId(plcHol, "lblFirstName") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtFirstName") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblSurname") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtSurname") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblTitle") + "']").text(jQuery("#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlTitle") + "']").attr('id') + ' .selected').text());
    jQuery("[id$='" + GetControlsId(plcHol, "lblGender") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "rbtnGender") + "'] :radio:checked").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblRelationship") + "']").text(jQuery(idDepRelation).text());
    if (plcHol.indexOf("Client") >= 0 || plcHol.indexOf("Spouse") >= 0) {
        jQuery("[id$='" + GetControlsId(plcHol, "lblDOB") + "']").text(jQuery(idDay).text() + ' ' + jQuery(idMonth).text() + ' ' + jQuery(idYear).text());
    }
    else {
        if (jQuery(idDepRelation).text() == 'Student Dependant') {
            jQuery("[id$='" + GetControlsId(plcHol, "divRelationshipLabel") + "']").removeClass('hidden');
            jQuery("[id$='" + GetControlsId(plcHol, "trSchoolLabel") + "']").removeClass('hidden');
            jQuery("[id$='" + GetControlsId(plcHol, "lblSchool") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtSchool") + "']").val());
            jQuery("[id$='" + GetControlsId(plcHol, "lblDOB") + "']").text(jQuery(idDay).text() + ' ' + jQuery(idMonth).text() + ' ' + jQuery(idDepYear).text());
        }
        else {
            jQuery("[id$='" + GetControlsId(plcHol, "divRelationshipLabel") + "']").removeClass('hidden');
            jQuery("[id$='" + GetControlsId(plcHol, "trSchoolLabel") + "']").addClass('hidden');
            jQuery("[id$='" + GetControlsId(plcHol, "lblDOB") + "']").text(jQuery(idDay).text() + ' ' + jQuery(idMonth).text() + ' ' + jQuery(idYear).text());
        }
    }
}

function AssignAddressDetailsControlValuesToLabels(Valctrl) {
    var plcHol = GetBaseControlId(Valctrl);
    var idState = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlState") + "']").attr('id') + ' .selected';
    var idPostcode = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlPostCode") + "']").attr('id') + ' .selected';
    jQuery("[id$='" + GetControlsId(plcHol, "lblAddress") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtAddr1") + "']").val() + ' ' + jQuery("[id$='" + GetControlsId(plcHol, "txtAddr2") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblSuburb") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtSuburb") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblState") + "']").text(jQuery(idState).text());
    jQuery("[id$='" + GetControlsId(plcHol, "lblPostCode") + "']").text(jQuery(idPostcode).text());
}

function AssignContactDetailsControlValuesToLabels(Valctrl) {
    var plcHol = GetBaseControlId(Valctrl);
    jQuery("[id$='" + GetControlsId(plcHol, "lblEmail") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtEmail") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMobile") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtMobile") + "']").val() == '' ? '-' : jQuery("[id$='" + GetControlsId(plcHol, "txtMobile") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblWorkPhone") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtWorkPhone") + "']").val() == '' ? '-' : jQuery("[id$='" + GetControlsId(plcHol, "txtWorkPhone") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblHomePhone") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtHomePhone") + "']").val() == '' ? '-' : jQuery("[id$='" + GetControlsId(plcHol, "txtHomePhone") + "']").val());
}

function AssignRebateDetailsControlsValuesToLables(Valctrl) {
    var plcHol = GetBaseControlId(Valctrl);
    var idDay = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlDay") + "']").attr('id') + ' .selected';
    var idMonth = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlMonth") + "']").attr('id') + ' .selected';
    var idYear = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlYear") + "']").attr('id') + ' .selected';
    var idValidMonth = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlMCExpMonth") + "']").attr('id') + ' .selected';
    var idValidYear = "#" + jQuery("[id$='" + GetControlsId(plcHol, "ddlMCExpYear") + "']").attr('id') + ' .selected';

    jQuery("[id$='" + GetControlsId(plcHol, "lblMCFirstname") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtMCFirstname") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMCMiddlename") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtMCMiddleInitial") + "']").val() == '' ? '-' : jQuery("[id$='" + GetControlsId(plcHol, "txtMCMiddleInitial") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMCsurname") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtMCLastname") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMCCardNumber") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "txtMCCardNumber") + "']").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMCDOB") + "']").text(jQuery(idDay).text() + ' ' + jQuery(idMonth).text() + ' ' + jQuery(idYear).text());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMCGender") + "']").text(jQuery("[id$='" + GetControlsId(plcHol, "rbtnGender") + "'] :radio:checked").val());
    jQuery("[id$='" + GetControlsId(plcHol, "lblMedicareExpDate") + "']").text(jQuery(idValidMonth).text() + '/' + jQuery(idValidYear).text());
}


/*     End   :   Confirmation page    */

//--------------------------------------------------------------------------------------------------------------------

/*     Start   :   Declare page    */

function DeclarePageOnLoad() {
    //Disable all the hidden control validators
    if (jQuery("table[id$=rbtnAilment] :radio:checked'").val() == 'Y') {
        var next = jQuery('#divAlimentBox').show('fast');
        AlimentEnableValidators(true);
    }
    else
        AlimentEnableValidators(false);
    if (jQuery("table[id$=rbtnswitchFunds] :radio:checked'").val() == 'Y') {
        jQuery('#divSwitchingFundsBox').show('fast');
        SwitchingFundsEnableValidators(true);
    }
    else
        SwitchingFundsEnableValidators(false);
    if (jQuery("table[id$=rbtnPartnerswitchFunds] :radio:checked'").val() == 'Y') {
        jQuery('#divSwitchingPartnerFundsBox').show('fast');
        jQuery('#divfineprintFormHolder').html(jQuery('#divfineprint').clone(true));
    }
    else
        PartnerSwitchingFundsEnableValidators(false)
}

function AlimentEnableValidators(blnVal) { EnableValidators('divAlimentBox .Validate', blnVal); }
function SwitchingFundsEnableValidators(blnVal) { EnableValidators('divSwitchingFundsBox .Validate', blnVal); }
function PartnerSwitchingFundsEnableValidators(blnVal) { EnableValidators('divSwitchingPartnerFundsBox .Validate', blnVal); }

//Join form: Existing Ailments?

jQuery("table[id$=rbtnAilment] :radio").live('click', function () {
    var next = jQuery('#divAlimentBox');
    if (jQuery(this).val() == 'Y') {
        next.show('fast');
        AlimentEnableValidators(true);
    }
    else {
        next.hide('fast');
        AlimentEnableValidators(false);
    }
}).change(); //check this change ???

//Load controls based on the switching fund selection
jQuery("table[id$= rbtnswitchFunds] :radio").live('click', function () {
    var next = jQuery('#divSwitchingFundsBox');
    if (jQuery(this).val() == 'Y') {
        next.show('fast');
        SwitchingFundsEnableValidators(true);
    }
    else {
        next.hide('fast');
        SwitchingFundsEnableValidators(false);
    }
});

//Load controls based on the switching fund selection - Partner
jQuery("table[id$= rbtnPartnerswitchFunds] :radio").live('click', function () {
    var next = jQuery('#divSwitchingPartnerFundsBox');
    var fineprintForm = jQuery('#divfineprintFormHolder');
    if (jQuery(this).val() == 'Y') {
        next.show('fast');
        PartnerSwitchingFundsEnableValidators(true);
        fineprintForm.html(jQuery('#divfineprint').clone(true));
    }
    else {
        next.hide('fast');
        PartnerSwitchingFundsEnableValidators(false);
    }
});

jQuery("[id$='chkIsConfirmOnlineRebate']").live('click', function () {//inside jqModelwindow
    if (jQuery(this).is(':checked')) {
        jQuery("#triggeredonlineRebate").trigger('click');

    }
});

jQuery("[id$='chkIsOnlineRebate']").live('click', function () {
    if (jQuery(this).is(':checked')) {
        jQuery("[id$='chkIsConfirmOnlineRebate']").attr('checked', false); //untick the check box
        var Date = jQuery("#" + jQuery("[id$=ddlstartDay]").attr('id') + " :selected").val() + "/" + jQuery("#" + jQuery("[id$=ddlstartMonth]").attr('id') + " :selected").val() + "/" + jQuery("#" + jQuery("[id$=ddlstartYear]").attr('id') + " :selected").val();
        jQuery("#" + jQuery("[id$='SpnCommencementDate']").attr('id')).append(Date);
        jQuery("#popUpTriggerOnlineRebate").trigger('click'); //show the JQ modelwindow
    }
});


/*     End   :   Declare page    */

//--------------------------------------------------------------------------------------------------------------------

/*     Start:   Payment page:      */

//Page On Load
function PayPageOnLoad() {
    if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'CreditCard') {
        PageLoadCCControls();
        CCRegularPaymentCVV(false); //Do not display the CVV for regualr payments on loading
    }
    else if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'Ezipay') {
        PageLoadEziPayControls()
    } else
        jQuery("table[id$= rbtPaymentType] :radio").eq(0).click(); // default
}

//Controls Validators
function CreditCardFormEnableValidators(blnVal) { EnableValidators('CreditCardForm .Validate', blnVal); }
function EzyPayFormEnableValidators(blnVal) { EnableValidators('EzyPayForm .Validate', blnVal); }
function SimpleEzyPayFormEnableValidators(blnVal) { EnableValidators('SimpleEzyPayForm .Validate', blnVal); }
function CardFormPayTodayEnableValidators(blnVal) { EnableValidators('CardFormPayToday .Validate', blnVal); }

//Payment Method Selection - How do you wish to make regular payments?
jQuery("table[id$= rbtPaymentType] :radio").live('click', function () {
    switch (jQuery(this).val()) {
        case 'CreditCard':
            CCControls();
            CCRegularPaymentCVV(false); //Do not display the CVV for regualr payments on loading
            DisplayErrorNotificationArea(true); //Remove the error message
            break;
        case 'Ezipay':
            EziPayControls();
            DisplayErrorNotificationArea(true); //Remove the error message
            break;
    }
});

function CCControls() {
    jQuery('#EzyPayForm').hide('fast');
    EzyPayFormEnableValidators(false);
    jQuery('#CreditCardForm').show('fast');
    UnCheckrbtPayToday(); // uncheck the one off payment Disable one of CC validators
    jQuery("#divTextForDirectCreditQuestion").html("Would you like to nominate a bank account to have your claims paid into?");
    UnCheckrbtpayIntoBankAccount(); // uncheck the direct credit Disable direct cliams validator
    CreditCardFormEnableValidators(true);
}

function EziPayControls() {
    jQuery('#CreditCardForm').hide('fast');
    CreditCardFormEnableValidators(false);
    jQuery('#EzyPayForm').show('fast');
    EzyPayFormEnableValidators(true);
    UnCheckrbtPayToday(); // uncheck the one off payment Disable one of CC validators
    jQuery("#divTextForDirectCreditQuestion").html("Would you like your claims paid directly into the above account?");
    UnCheckrbtpayIntoBankAccount(); // uncheck the direct credit Disable direct cliams validator
}

function PageLoadCCControls() {
    jQuery('#EzyPayForm').hide('fast');
    EzyPayFormEnableValidators(false);
    jQuery('#CreditCardForm').show('fast');
    var varPayToday = jQuery("table[id$= rbtPayToday] :radio:checked").val();
    if (varPayToday != 'undefined' && varPayToday == "Y") {
        if (jQuery("[id$='chkSameAsCardAbove']").is(':checked')) { //if same as the above card
            CardFormPayToday(false); //Hide and disable controls and validators
            EnableValidatorsdivCCVArea(true); //Enable CVV validators in regular payment credit card section 
        }
        else {
            CardFormPayToday(true); //Display and enable controls and validators
            EnableValidatorsdivCCVArea(false); //Disable CVV validators in regular payment credit card section 
        }

        jQuery('#SameAsCardAbove').removeClass("hidden"); //display the question 
    }
    jQuery("#divTextForDirectCreditQuestion").html("Would you like to nominate a bank account to have your claims paid into?");
    var varpayIntoBankAccount = jQuery("table[id$= rbtpayIntoBankAccount] :radio:checked").val();
    if (varpayIntoBankAccount != 'undefined' && varpayIntoBankAccount == "Y") {
        SimpleEzyPayForm(true);
    }
    CreditCardFormEnableValidators(true);

}

function PageLoadEziPayControls() {
    jQuery('#CreditCardForm').hide('fast');
    CreditCardFormEnableValidators(false);
    jQuery('#EzyPayForm').show('fast');
    EzyPayFormEnableValidators(true);
    var varPayToday = jQuery("table[id$= rbtPayToday] :radio:checked").val();
    if (varPayToday != 'undefined' && varPayToday == "Y") {
        SameAsCardAbove(false);  //Hide SameAsCardAbove check box
        CardFormPayToday(true); //Show controls and disable validators
    }
    jQuery("#divTextForDirectCreditQuestion").html("Would you like your claims paid directly into the above account?");
    var varpayIntoBankAccount = jQuery("table[id$= rbtpayIntoBankAccount] :radio:checked").val();
    if (varpayIntoBankAccount != 'undefined' && varpayIntoBankAccount == "N") {
        SimpleEzyPayForm(true);
    }
}

//Would you like to make a credit card payment today for your first month's premium?
jQuery("table[id$= rbtPayToday] :radio").live('click', function () {
    if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'CreditCard') {
        if (jQuery(this).val() == 'Y') {
            SameAsCardAbove(true); //show SameAsCardAbove check box
            CCRegularPaymentCVV(true);
        }
        else {
            SameAsCardAbove(false); //Hide SameAsCardAbove check box
            CardFormPayToday(false);
            CCRegularPaymentCVV(false);
        }
    }
    else {
        SameAsCardAbove(false) //Hide SameAsCardAbove check box
        //Ezi pay Would you like to make a credit card payment today for your first month's premium?
        if (jQuery(this).val() == 'Y')
            CardFormPayToday(true);
        else
            CardFormPayToday(false);
    }
});

//Same as card above
jQuery("[id$='chkSameAsCardAbove']").live('change', function () {
    if (!jQuery(this).is(':checked')) { //if not same as the above card
        CardFormPayToday(true); //Display and enable controls and validators
        EnableValidatorsdivCCVArea(false); //Disable CVV validators in regular payment credit card section 
    }
    else {
        CardFormPayToday(false); //Hide and disable controls and validators
        EnableValidatorsdivCCVArea(true); //Enable CVV validators in regular payment credit card section 
    }
});

function EnableValidatorsdivCCVArea(blnVal) {
    EnableValidators('divCCVArea .Validate', blnVal);
}

//Would you like to nominate a bank account to have your claims paid into?  Direct Credit
jQuery("table[id$= rbtpayIntoBankAccount] :radio").live('change', function () {
    if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'CreditCard') {
        if (jQuery(this).val() == 'Y') SimpleEzyPayForm(true);
        else SimpleEzyPayForm(false);
    }
    else if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'Ezipay') {
        if (jQuery(this).val() == 'N') {
            SimpleEzyPayForm(true);
            jQuery("#SimpleEzyPayFormFinePrint").removeClass("hidden");
        }
        else {
            SimpleEzyPayForm(false);
            jQuery("#SimpleEzyPayFormFinePrint").addClass("hidden");
        }
    }
});

function UnCheckrbtPayToday() {
    jQuery("table[id$= rbtPayToday] :radio").attr('checked', false);
    SameAsCardAbove(false);  //Hide SameAsCardAbove check box
    CardFormPayToday(false); //Hide controls and disable validators
}

function UnCheckrbtpayIntoBankAccount() {
    jQuery("table[id$= rbtpayIntoBankAccount] :radio").attr('checked', false);

    SimpleEzyPayForm(false); //Hide controls and disable validators
}

//One Off Credit Card
function CardFormPayToday(blnVal) {
    if (blnVal) {
        jQuery("#CardFormPayToday").removeClass("hidden");
        jQuery("#divCCVArea").addClass('hidden');
    }
    else {
        jQuery("#CardFormPayToday").addClass("hidden");
        jQuery("#divCCVArea").removeClass('hidden');
    }
    CardFormPayTodayEnableValidators(blnVal);
}

function ShowCVV() {
    jQuery("#divCCVArea").addClass('hidden');
}

function CCRegularPaymentCVV(blnVal) {
    if (blnVal) {
        jQuery("#divCCVArea").removeClass('hidden');
        EnableValidatorsdivCCVArea(blnVal);
    }
    else {
        jQuery("#divCCVArea").addClass('hidden');
        EnableValidatorsdivCCVArea(blnVal);
    }
}
function SameAsCardAbove(blnVal) {
    if (blnVal) {
        jQuery('#SameAsCardAbove').removeClass("hidden");
        jQuery("[id$='chkSameAsCardAbove']").attr('checked', true);     //by default Check the Same as above card control
    }
    else
        jQuery('#SameAsCardAbove').addClass("hidden");
}

//Direct Credit
function SimpleEzyPayForm(blnVal) {
    if (blnVal) {
        jQuery("#SimpleEzyPayForm").removeClass("hidden");
        jQuery("[id$='txtClaimsPaidBSB']").blur(function () {
            var id = jQuery(this).attr("id");
            getBankAndBranch(id);
        });

    } else {
        jQuery("#SimpleEzyPayForm").addClass("hidden");
    }
    SimpleEzyPayFormEnableValidators(blnVal);
}

jQuery("[id$='lknPayNext']").live('click', function () {
    if (jQuery("table[id$= rbtPaymentType] :radio:checked'").val() == 'Ezipay')
        if ((jQuery("table[id$= rbtpayIntoBankAccount] :radio:checked'").val() != 'undefined') && (jQuery("table[id$= rbtpayIntoBankAccount] :radio:checked'").val() == 'N')) {
            var blnVal = false;
            jQuery("#SimpleEzyPayForm").each(function (i) {
                jQuery("#" + jQuery(this).attr('id') + " :input").each(function (i) {
                    var type = this.type;
                    var tag = this.tagName.toLowerCase();
                    if (type == 'text' || type == 'password' || tag == 'textarea') {
                        if (this.value != "") {
                            blnVal = true;
                        }
                    }
                });
            });
            SimpleEzyPayFormEnableValidators(blnVal);
        }
IsThisPageValid();
});

/*    End : Payment Details     */


//--------------------------------------------------------------------------------------------------------------------


//Enable Validators 
//Start ---------------------------------------------------------
function EnableValidators(Selector, blnVal) {
    var ctrl = '#' + Selector;
    jQuery(document).ready(function () {
        jQuery(ctrl).each(function (i) {
            ValidatorEnable(this, blnVal);
        });
    });
}

//---------------------------------------------------------End

//Check Validators 
//Start ---------------------------------------------------------

function IsThisPageValid() {
    if (Page_ClientValidate() == true) { DisplayErrorNotificationArea(true); return true; }
    else { DisplayWarningImg(); DisplayErrorNotificationArea(false); return false; }
}

//---------------------------------------------------------End

function DisplayErrorNotificationArea(blnVal) {
    if (blnVal) {
        jQuery("#" + jQuery("[id$=ValidationSummary]").attr('id')).html(""); //clear the message from the list
        jQuery('#NotificationArea').attr('class', 'hidden');
    }
    else
        jQuery('#NotificationArea').attr('class', '');

}

function DisplayWarningImg() {
    var n = Page_Validators.length;
    for (i = 0; i < n; i++) {
        val = Page_Validators[i];
        var id;
        var idval;
        if (val.enabled != false) {
            if (val.evaluationfunction(val) == false) {
                jQuery(jQuery(jQuery("#" + jQuery(val).attr('id')).parent().get()).children().get()).addClass('warning');
            }
            else {
                if (jQuery(val).attr('id').indexOf('_rev') < 0) {
                    jQuery(jQuery(jQuery("#" + jQuery(val).attr('id')).parent().get()).children().get()).removeClass('warning');
                }
            }
        }
    }
    return false;
}

//Utility - get the enbaled validators and the values
function GetPageValidatorsInfo() {

    var n = Page_Validators.length;

    for (i = 0; i < n; i++) {

        val = Page_Validators[i];
        var id;
        var idval;
        if (val.enabled != false) {
            //                alert('val Enable : ' + val.enabled + '      Validator' + val.id);
            id = id + '\n\r' + 'val Enable : ' + val.enabled + '      Validator' + val.id;
            if (val.evaluationfunction(val) == false) {
                alert(Page_Validators[i].errormessage);
            }
        }
    }
    return false;
}


//Commom check for checkbox checked
function ValidateTandCs(source, args) {
    var blnVal;
    if (jQuery(source).attr('id').indexOf('Medicare') >= 0) { blnVal = jQuery("[id$='chkIsMedicare']").attr('checked'); } //valIsMedicare
    else if (jQuery(source).attr('id').indexOf('Member') >= 0) { blnVal = jQuery("[id$='chkIsMember']").attr('checked'); } //valIsMember
    else if (jQuery(source).attr('id').indexOf('Understand') >= 0) { blnVal = jQuery("[id$='chkIsUnderstand']").attr('checked'); } //CvalIsUnderstand
    else if (jQuery(source).attr('id').indexOf('Confirm') >= 0) { blnVal = jQuery("[id$='chkIsConfirm']").attr('checked'); } //chkIsConfirm
    else if (jQuery(source).attr('id').indexOf('EmailAlerts') >= 0) { blnVal = jQuery("[id$='chkIsEmailAlerts']").attr('checked'); } //chkIsEmailAlerts
    else if (jQuery(source).attr('id').indexOf('OnlineRebate') >= 0) { blnVal = jQuery("[id$='chkIsOnlineRebate']").attr('checked'); } //Online Rebate
    args.IsValid = blnVal;
}


function LoadImage() {
    if (!jQuery('form').attr('action').indexOf('GettingStarted.aspx') >= 0)
        if (jQuery("#securedByVeriSign") != null)
            jQuery("#securedByVeriSign").attr('class', 'hidden');
}

function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}
var url = ResolveUrl("~/AutoComplete.asmx");

function setContextKey(id) {
    var contextKey;
    var cmbExtender;
    var ctrid = id.replace('txtSuburb', '');
    var servicePath = url;
    if ((jQuery("#" + id).val().length) >= 1) {
        cmbExtender = $find(ctrid + "AutoCompleteSuburb");
        contextKey = jQuery("#SS" + id.replace('txtSuburb', 'ddlState') + " :selected").text();
        cmbExtender.set_contextKey(contextKey);
        cmbExtender.set_servicePath(servicePath);
    }
}

// Generic version to set key pressed context
// in used with AjaxToolkit
function setContextParamsKey(id, suburb, state, autoCompleteId) {
    var contextKey;
    var cmbExtender;
    var ctrid = id.replace(suburb, '');
    var servicePath = url;
    if ((jQuery("#" + id).val().length) >= 1) {
        cmbExtender = $find(ctrid + autoCompleteId);
        contextKey = jQuery("#SS" + id.replace(suburb, state) + " :selected").text();
        cmbExtender.set_contextKey(contextKey);
        cmbExtender.set_servicePath(servicePath);
    }
}





var regexMaleTitle = "(Mr)|(Fr)|(Brother)";
var regexFemaleTitle = "(Mrs)|(Miss)|(Ms)|(Sister)";
var regexCommon = "(Dr)|(Professor)";
var TitleID = "";

jQuery("[id$=ddlTitle]").live('click', function () {
    TitleID = jQuery(this).attr('id'); //get the id of the control and save it in RelationshipID which will be used on selection on the ddl via <li> tag
});

jQuery("[id$=ddlTitle] li").live('click', function () {
    var dllValue = jQuery(this).data('value');
    var ctrl = TitleID.split('_');
    var Ctrid = "";
    if (ctrl.length == 5)
        Ctrid = ctrl[2] + '_' + ctrl[3];
    else
        Ctrid = ctrl[2];

    Ctrid = TitleID.substring(TitleID.lastIndexOf("cphMainContent"), TitleID.lastIndexOf("_"));

    if (dllValue.match(regexMaleTitle) != null && dllValue != "Mrs") {
        jQuery("[id$=" + Ctrid + "_rbtnGender_0]").attr('checked', 'checked');
    }
    else if (dllValue.match(regexFemaleTitle) != null) {
        jQuery("[id$=" + Ctrid + "_rbtnGender_1]").attr('checked', 'checked');
    }
});

function GetIdFromCustomValidators(source) { var ctrl = jQuery(source).attr('id').split('_'); var id = jQuery(source).attr('id').replace(ctrl[parseInt(ctrl.length) - 1], ''); return id; }
function MsgFor(id) {
    var msgFor = '', count = '', Type = "";
    Type = jQuery(id).attr('Type');
    if (typeof (Type) != "undefined") {
        if (Type == "Client") msgFor = "Your";
        else if (Type == "Partner") msgFor = "Partner's";
        else if (Type == "Spouse") msgFor = "spouse";
        else if (Type == "Rebate") msgFor = "Medicare";
        else if (Type == "Dependant") {
            count = jQuery(id).attr('count');
            msgFor = "dependant #" + count;
        }
    }
    return msgFor;
}

function PhoneNumberRequired(source, args) {
    var blnVal;
    var id = GetIdFromCustomValidators(source);
    if (jQuery("#" + id + "txtMobile").val() == "" && jQuery("#" + id + "txtWorkPhone").val() == "" && jQuery("#" + id + "txtHomePhone").val() == "")
        blnVal = false;
    else
        blnVal = true;
    args.IsValid = blnVal;
}

function ValidateGender(source, args) {
    var blnVal = false;
    var id = GetIdFromCustomValidators(source);
    var msgFor = MsgFor(source);
    var rbtnGenderValue = jQuery("[id$=" + id + "rbtnGender] :radio:checked").val();
    var SelectedTitle = jQuery("#" + id + "ddlTitle :selected").val();
    if (rbtnGenderValue != null) {
        blnVal = MatchGenderTitle(SelectedTitle, rbtnGenderValue);
        source.errormessage = msgFor.charAt(0).toUpperCase() + msgFor.substring(1) + "'s title does not match with " + msgFor.toLowerCase() + "'s gender";
    }
    else {
        source.errormessage = "Please select your " + msgFor.toLowerCase() + " gender";
        blnVal = false;
    }
    args.IsValid = blnVal;
}

function MatchGenderTitle(Title, Gender) {
    var Valid = "";
    if (Title == "Dr" || Title == "Professor") {
        Valid = true;
    }
    else if (Gender != "") {
        switch (Gender) {
            case "M":
                if (Title.match(regexMaleTitle) && Title != "Mrs")
                    Valid = true;
                break;
            case "F":
                if (Title.match(regexFemaleTitle))
                    Valid = true;
                break;
            default:
                Valid = false;
                break;
        }
    }
    else {
        Valid = false;
    }

    return Valid;
}

function CheckWithTodayDate(DAY, MONTH, YEAR, ServerDte) {
    var dateStr = MONTH + "/" + DAY + "/" + YEAR;
    var DOB = new Date(dateStr);
    var currentDate = new Date(ServerDte);
    if (DOB.getTime() > currentDate.getTime())
        return true;
    else
        return false;
}

function ValidateDate(source, args) {
    var blnVal = false;
    var id = GetIdFromCustomValidators(source);
    var msgFor = MsgFor(source);
    var DepNo, CtrlType, Day, Month, Year;
    var varRelationShip = "";
    CtrlType = jQuery(source).attr('Type');
    Day = jQuery("#" + id + "ddlDay").get(0).selectedIndex;
    Month = jQuery("#" + id + "ddlMonth").get(0).selectedIndex;
    Year = jQuery("#" + id + "ddlYear :selected").val();
    if ((typeof (CtrlType) != "undefined")) {
        if (CtrlType == "Spouse") { // Health Assessment Partner control
            Day = jQuery("#" + id + "ddlSpouseDay").get(0).selectedIndex;
            Month = jQuery("#" + id + "ddlSpouseMonth").get(0).selectedIndex;
            Year = jQuery("#" + id + "ddlSpouseYear :selected").val();
        }
        else if (CtrlType == "Dependant") {//is validator for dep?  then check for relation ddl value and select year ddl value
            varRelationShip = jQuery("#" + id + "ddlRelationship :selected").val();
            if (varRelationShip == "Student Dependant")
                Year = jQuery("#" + id + "ddldepYear :selected").val();
            else
                Year = jQuery("#" + id + "ddlYear :selected").val();
        }
    }
    if (IsDateMandatory(parseInt(Day), parseInt(Month), parseInt(Year))) {
        if (dateChk(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte)) {
            if (IsValidDate(parseInt(Day), parseInt(Month), parseInt(Year), source)) {
                blnVal = true;

                if ((typeof (CtrlType) != "undefined") && (CtrlType == "Client")) {
                    if (getAge(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte) < 16) {
                        source.errormessage = "Applicant's age should be at least 16 years old";
                        blnVal = false;
                    }
                }
                else if ((typeof (CtrlType) != "undefined") && (CtrlType == "Partner")) {
                    if (getAge(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte) < 17.0100) {
                        source.errormessage = "Partner's age should be greater than 17 years and 1 month";
                        blnVal = false;
                    }
                }
                else if ((typeof (CtrlType) != "undefined") && (CtrlType == "Dependant")) {
                    if ((varRelationShip == "Student Dependant") && (getAge(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte) < 22 || getAge(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte) >= 25)) {
                        source.errormessage = "Age of " + msgFor + " should be between 22 to 24 years old";
                        blnVal = false;
                    }
                    else if ((varRelationShip == "Dependant Child") && getAge(parseInt(Day), parseInt(Month), parseInt(Year), ServerDte) >= 22) {
                        source.errormessage = "Age of " + msgFor + " should be between 0 to 21 years old";
                        blnVal = false;
                    }
                    else if (typeof (CommencementDte) != 'undefined' && CommencementDte != '') {
                        if ((varRelationShip == "Student Dependant") && (getAge(parseInt(Day), parseInt(Month), parseInt(Year), CommencementDte) < 22 || getAge(parseInt(Day), parseInt(Month), parseInt(Year), CommencementDte) >= 25)) {
                            source.errormessage = "Age of " + msgFor + " should be between 22 to 24 years old from commencement date";                            
                            blnVal = false;
                        }
                        else if ((varRelationShip == "Dependant Child") && getAge(parseInt(Day), parseInt(Month), parseInt(Year), CommencementDte) >= 22) {
                            source.errormessage = "Age of " + msgFor + " should be between 0 to 21 years old from commencement date";
                            blnVal = false;
                        }
                    }
                }
            }
            else {
                var msg = source.errormessage;
                if (CtrlType == "Client") source.errormessage = "Please select your valid date of birth";
                else if (CtrlType == "Partner") source.errormessage = "Please select your partner’s valid date of birth";
                else if (CtrlType == "Dependant") source.errormessage = "Please select a valid date of birth for " + msgFor;
                else if (msgFor.indexOf("Medicare") != -1) source.errormessage = "Please select your valid Medicare date of birth";

            }
        }
        else {

            if (CtrlType == "Dependant") {
                source.errormessage = "Date of birth cannot be greater than the current date for " + msgFor;
            }
            else {
                source.errormessage = msgFor + " date of birth cannot be greater than the current date";
            }
            blnVal = false;
        }

    } else {
        if (CtrlType == "Dependant") {
            msgFor += "'s";
        }

        if (msgFor.indexOf("Your") < 0) {
            msgFor = "your " + msgFor;
        }

        if (msgFor.indexOf("Medicare") < 0) {
            msgFor = msgFor.toLowerCase();
        }
        source.errormessage = "Please select " + msgFor + " date of birth"; //"Please select the date of birth for " + msgFor ;
        blnVal = false;
    }
    args.IsValid = blnVal;
}

function dateChk(DAY, MONTH, YEAR, CurrentDateVal) {
    var dateStr = MONTH + "/" + DAY + "/" + YEAR;
    var DOB = new Date(dateStr);
    var currentDate = new Date(CurrentDateVal);
    if (DOB.getTime() > currentDate.getTime()) return false;
    else return true;
}

function ChkExpiryDate(MONTH, YEAR, CurrentDateVal) {
    //The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.
    //Note: January is 0, February is 1, and so on. In Application we start the month from 1-12 so getMonth is addded with 1
    var GetFullDate = new Date(YEAR, MONTH, 0); //Get last date of the month
    var dateStr = MONTH + "/" + GetFullDate.getDate() + "/" + YEAR;
    var ExpiryDate = new Date(dateStr);
    var currentDate = new Date(CurrentDateVal);
    if (ExpiryDate >= currentDate) return true; else return false;
}


function getAge(DAY, MONTH, YEAR, CurrentDateVal) {
    var dateStr = MONTH + "/" + DAY + "/" + YEAR;
    var now = new Date();
    var DOB = new Date(dateStr);
    var currentDate = new Date(CurrentDateVal);
    if (DOB.getTime() > currentDate.getTime())
        return 0;
    return datediff(currentDate, DOB);
}

function datediff(date1, date2) {
    var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(), y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate();
    if (d1 < d2) {
        m1--;
        d1 += DaysInMonth(y2, m2);
    }
    if (m1 < m2) {
        y1--;
        m1 += 12;
    }
    var YEAR = y1 - y2;
    var MONTH = "" + (m1 - m2) + "";
    var DAY = "" + (d1 - d2) + "";
    if (MONTH.length < 2)
        MONTH = "0" + MONTH;

    if (DAY.length < 2)
        DAY = "0" + DAY;
    return YEAR + "." + MONTH + "" + DAY;
}

function DaysInMonth(Y, M) {
    with (new Date(Y, M, 1, 12)) {
        setDate(0);
        return getDate();
    }
}

function ValidateCommencementDate(source, args) {
    var blnVal = false;
    var id = GetIdFromCustomValidators(source);
    var Day = jQuery("#" + id + "ddlstartDay").get(0).selectedIndex;
    var Month = jQuery("#" + id + "ddlstartMonth").get(0).selectedIndex;
    var Year = jQuery("#" + id + "ddlstartYear :selected").val();
    var dateStr = Month + "/" + Day + "/" + Year;
    var OrderDate = new Date(dateStr);
    var ValidCommencementDate = new Date(ServerDte);
    var currentDate = new Date(ServerDte);
    var curDate;

    curDate = (currentDate.getMonth() + 1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear();
    curDate = new Date(curDate);

    ValidCommencementDate.setDate(ValidCommencementDate.getDate() + parseInt(90));
    if (IsDateMandatory(parseInt(Day), parseInt(Month), parseInt(Year))) {
        if (IsValidDate(Day, Month, Year, source)) {
            blnVal = true;
            if (OrderDate <= ValidCommencementDate && OrderDate >= curDate) {
                blnVal = true;
            }
            else {
                source.errormessage = "Commencement date must be either the current date or a date in the future no more than 90 days from the current date";
                blnVal = false;
            }
        }
        else {
            source.errormessage = "Please enter your valid membership commencement date";
            blnVal = false;
        }
    }
    else {
        source.errormessage = "Please select your membership commencement date";
        blnVal = false;
    }
    args.IsValid = blnVal;
}

function IsDateMandatory(DAY, MONTH, YEAR) {

    if (MONTH == 0 || DAY == 0 || YEAR == 0) {
        return false;
    }
    else return true;
}

function IsValidDate(DAY, MONTH, YEAR, source) {
    var ValidDate;
    if (MONTH == 0 || DAY == 0 || YEAR == 0) {
        return false;
    }
    if (MONTH == 2 && DAY > 29) {
        ValidDate = false;
    }
    else if (MONTH == 2 && DAY == 29 && (((YEAR % 4 == 0) && ((!(YEAR % 100 == 0)) || (YEAR % 400 == 0))) ? false : true)) {
        ValidDate = false;
    }
    else if ((MONTH == 4 || MONTH == 6 || MONTH == 9 || MONTH == 11) && DAY == 31) {
        ValidDate = false;
    }
    else {
        ValidDate = true;
    }
    if (ValidDate)
        return ValidDate;
    else {
        source.errormessage = "Please enter a valid date";
        return ValidDate;
    }

}

//function RequiredFieldValidatorforDDL(source, args) { //ClientScriptRegisterExpandoAttribute method does not works on partial postback so for the ddl which has autopostback and required field validator, created custom validator.
//    var blnVal = true;
//    var SelectedValue = jQuery("#" + jQuery("[id$=ddlEzipayFrequency]").attr('id') + " :selected").val();
//    if (SelectedValue == "00") blnVal = false;
//    args.IsValid = blnVal;
//}

function RequiredFieldValidatorforDDL(source, args) {
    var blnVal = true;
    if (document.getElementById(source.ddl) != null) {
        if (jQuery("#" + jQuery(document.getElementById(source.ddl)).attr('id')).get(0).selectedIndex == 0)
            blnVal = false;
    }
    args.IsValid = blnVal;
}

function RequiredFieldEzipayAuthorise(source, args) {
    var blnVal = true;
    if (jQuery("[id$='chkEziPayAuthorise']").length > 0) {
        blnVal = jQuery("[id$='chkEziPayAuthorise']").is(':checked');
    }
    args.IsValid = blnVal;
}

function ValidateCreditCardNumber(source, args) {
    var blnVal;
    var SelectedCard, CCVNumber;
    var id = GetIdFromCustomValidators(source);
    var sourceID = jQuery(source).attr('id');
    var msgFor;
    if (sourceID.indexOf("CvalValidateCreditCard") != -1) {
        SelectedCard = jQuery("#" + id + "ddlTypeOfCard :selected").val();
        CCVNumber = jQuery("[id$=txtCardNumber]").val();
        msgFor = " for your regular payment";
    }
    else if (sourceID.indexOf("CvalValidateOneOffCreditCard") != -1) {
        SelectedCard = jQuery("#" + id + "ddlOneOffCardType :selected").val();
        CCVNumber = jQuery("[id$=txtOneOffCardNumber]").val();
        msgFor = " for your first month’s premium  payment";
    }
    if (CCVNumber != "") {
        if (SelectedCard != "00") {
            switch (SelectedCard) {
                case "VC":
                    if (CCVNumber.match("^[0-9]{16}$")) {
                        if (CCVNumber.substring(0, 1) == "4") blnVal = true;
                        else blnVal = false;
                    }
                    else blnVal = false;
                    break;
                case "MC":
                    if (CCVNumber.match("^[0-9]{16}$")) {
                        if (CCVNumber.substring(0, 1) == "5") blnVal = true;
                        else blnVal = false;
                    }
                    else blnVal = false;
                    break;
                case "AE":
                    if (CCVNumber.match("^[0-9]{15}$")) {
                        if (CCVNumber.substring(0, 1) == "3") blnVal = true;
                        else blnVal = false;
                    }
                    else blnVal = false;
                    break;
                default:
                    blnVal = false;
                    break;
            }
            if (blnVal == false)
            { source.errormessage = "Please enter a valid credit card number" + msgFor; }
        }
        else { blnVal = true; }
    }
    else {
        source.errormessage = "Please enter the credit card number" + msgFor;
        blnVal = false;
    }
    args.IsValid = blnVal;
}

function ValidateDependant(source, args) {
    var blnVal = false;
    var depCount = jQuery("[name$=hdndepcount]").val();
    if (CvalScale != null) {
        if (CvalScale == "P" || CvalScale == "F") {
            if (depCount == 1)
                blnVal = false;
            else
                blnVal = true;
        }
        else if (CvalScale == "S" || CvalScale == "C") {
            if (depCount == 1)
                blnVal = true;
        }
    }
    source.errormessage = "Please click on the ‘Add another person’ button to add a dependant";
    args.IsValid = blnVal;
}

function ValidateCVV(source, args) {
    var blnVal;
    var IsMandatory;
    var sourceID = jQuery(source).attr('id');
    var id = GetIdFromCustomValidators(source);
    var SelectedCard, CCVNumber;
    if (sourceID.indexOf("CvalValidateCVV") != -1) {
        SelectedCard = jQuery("#" + id + "ddlTypeOfCard :selected").val();
        CCVNumber = jQuery("[id$=txtCVV]").val();
    }
    else if (sourceID.indexOf("CvalValidateOneOffCVV") != -1) {
        SelectedCard = jQuery("#" + id + "ddlOneOffCardType :selected").val();
        CCVNumber = jQuery("[id$=txtOneOffCVV]").val();
    }
    if (CCVNumber != "") {
        if (SelectedCard != "00") {
            switch (SelectedCard) {
                case "VC":
                    if (CCVNumber.match("^[0-9]{3}$"))
                        blnVal = true;
                    else
                        blnVal = false;
                    break;
                case "MC":
                    if (CCVNumber.match("^[0-9]{3}$"))
                        blnVal = true;
                    else
                        blnVal = false;
                    break;
                case "AE":
                    if (CCVNumber.match("^[0-9]{4}$"))
                        blnVal = true;
                    else
                        blnVal = false;
                    break;
                default:
                    blnVal = false;
                    break;
            }
            if (sourceID.indexOf("CvalValidateCVV") != -1) {
                source.errormessage = "Please enter a valid CVV number";
            }
            else if (sourceID.indexOf("CvalValidateOneOffCVV") != -1) {
                source.errormessage = "Please enter a valid CVV number for your first month’s premium payment";
            }
        }
        else blnVal = true; //if card is not selected, make this validator to true 
    } else { blnVal = false; }
    args.IsValid = blnVal;
}

function ValidateExpiryDate(source, args) {
    var blnVal = false;
    var sourceID = jQuery(source).attr('id');
    var id = GetIdFromCustomValidators(source);
    var ExpMonth = "", ExpYear = "", msgFor = "", fieldName = "", prePos = "";
    var SelectedCard = jQuery("#" + id + "ddlTypeOfCard :selected").val();
    //Regular Pay Credit Card
    if (sourceID.indexOf("CvalCCExpiryDate") != -1) {//Regular payment Credit Card
        ExpMonth = jQuery("#" + id + "ddlCCExpMonth :selected").val();
        ExpYear = jQuery("#" + id + "ddlCCExpYear :selected").val();
        prePos = " the";
        fieldName = " credit card ";
        msgFor = " for your regular payment";
    } else if (sourceID.indexOf("CvalOneOffExpiryDate") != -1) { //One off Credit Card
        ExpMonth = jQuery("#" + id + "ddlOneOffExpiryMonth :selected").val();
        ExpYear = jQuery("#" + id + "ddlOneOffExpiryYear :selected").val();
        prePos = " the";
        fieldName = " credit card ";
        msgFor = " for your first month’s premium  payment";
    } else if (sourceID.indexOf("CvalMCExpiryDate") != -1) { //Medicare card expiry
        ExpMonth = jQuery("#" + id + "ddlMCExpMonth :selected").val();
        ExpYear = jQuery("#" + id + "ddlMCExpYear :selected").val();
        prePos = " your";
        fieldName = " Medicare card ";
    }
    if (ExpMonth != "00" && ExpYear != "00") {
        if (ChkExpiryDate(ExpMonth, ExpYear, ServerDte)) {
            blnVal = true;
        }
        else {
            source.errormessage = "Please enter your valid" + fieldName + "expiry date" + msgFor;
            blnVal = false;
        }

    }
    else {
        source.errormessage = "Please enter" + prePos + fieldName + "expiry date" + msgFor;
        blnVal = false;
    }
    args.IsValid = blnVal;
}

function ValidateSuburb(source, args) {
    var id = GetIdFromCustomValidators(source);
    var addressType = "";
    if (id.toLowerCase().indexOf("postal") >= 0) {
        addressType = "postal ";
    }
    var Suburb = jQuery("#" + id + "txtSuburb").val();
    var postcode = jQuery("#" + id + "ddlPostCode :selected").text();    
    if (Suburb == "") {
        source.errormessage = "Please enter your " + addressType + "suburb";
        args.IsValid = false;
    }
    else if (Suburb != "" && postcode == "") {
    source.errormessage = "Please enter your valid " + addressType + "suburb";
        args.IsValid = false;
    }
    else if (Suburb == "" || postcode == "") {
        source.errormessage = "Please enter your valid " + addressType + "suburb";
        args.IsValid = false;
    }
}

function ValidateMedicareInitial(source, args) {
    var blnVal = true;
    var id = GetIdFromCustomValidators(source);
    var MCInitial = jQuery("[id$=txtMCMiddleInitial]").val();
    if (MCInitial.length != 0) {
        if (MCInitial.match("^[a-zA-Z]{1}$"))
            blnVal = true;
        else
            blnVal = false;
    }
    args.IsValid = blnVal;
}

function ValidateMedicareNumber(source, args) {
    var blnVal = false;
    var id = GetIdFromCustomValidators(source);
    var MCCardNo = jQuery("[id$=txtMCCardNumber]").val();
    if (MCCardNo.length != 0) {
        if (MCCardNo.match("^[0-9]{10}$")) {
            var intMediNo = Number(MCCardNo);
            var arrMultiplier = new Array(1, 3, 7, 9);
            var intSum = 0;
            var intDigits = new Array(2);

            for (var intCount = 0; intCount < 10; intCount++) {
                if (intCount == 1 || intCount == 9) {
                    if (intCount == 1)
                        intDigits[1] = (Number(intMediNo) % 10);
                    else
                        intDigits[0] = (Number(intMediNo) % 10);
                }
                if (intCount > 1) {
                    intSum += (Number(intMediNo) % 10) * arrMultiplier[(3 - (intCount - 2) % 4)];
                }
                intMediNo = parseInt(Number(intMediNo) / 10);
            }
            if ((intSum % 10 == intDigits[1]) && (intDigits[0] >= 2 && intDigits[0] <= 6)) {
                blnVal = true;
            }
            else {
                blnVal = false;
            }
        }
        else {
            blnVal = false;
        }
        if (!blnVal) source.errormessage = "Please enter your valid Medicare card number";
    }
    else {

        source.errormessage = "Please enter your Medicare card number";
    }
    args.IsValid = blnVal;
}

function getBankAndBranch(srcid) {
    var ValBSB = jQuery("#" + srcid).val();
    var OnSucessCallBack = "OnSuccess(" + srcid + ")";
    // The following block prepends the BSB number with zeroes, if its length is not equal to 6
    if (ValBSB != "") {
        if (ValBSB.length != 6) {
            for (var i = 1; i <= 6 - ValBSB.length; i++) {
                jQuery("#" + srcid).val("0" + jQuery("#" + srcid).val());
            }
            ValBSB = jQuery("#" + srcid).val();
        }
        var keyvalue = "{'strBSBNumber':'" + ValBSB + "'}";
        jQuery.ajax( // JSON Ajax Call to get hte Bank name and Branch
                {type: "POST",
                url: url + "/GetBankAndBranch",
                data: keyvalue,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) { OnSuccess(response, srcid); }, error: OnError
            });
    }
}

function OnSuccess(data, srcid) {
    var result = data.d;
    var txtEziFinancialInstitution = "";
    var txtEziBranch = "";
    if (srcid.indexOf("txtEziBSB") != -1) {
        txtEziFinancialInstitution = jQuery("[id$=txtEziFinancialInstitution]").attr('id');
        txtEziBranch = jQuery("[id$=txtEziBranch]").attr('id');
    }
    else if (srcid.indexOf("txtClaimsPaidBSB") != -1) {
        txtEziFinancialInstitution = "txtEziClaimsInstituteName";
        txtEziBranch = "txtEziClaimsBranchName";
    }    
    if (result[0] != "" || result[1] != "") {
        jQuery("#" + txtEziFinancialInstitution).val(result[0]);
        jQuery("#" + txtEziBranch).val(result[1]);
    }
    else {
        jQuery("#" + txtEziFinancialInstitution).val("");
        jQuery("#" + txtEziBranch).val("");
    }
}

function getPostcode(suburbid, stateid, postCodeid) {
    var suburb = jQuery("#" + jQuery('[id$=' + suburbid + ']').attr('id')).val();
    var state = jQuery("#" + stateid + " :selected").val();
    var count = 10;
    var keyvalue = "{'strSuburb':'" + escape(suburb) + "','strState':'" + state + "'}";

    jQuery.ajax( // JSON Ajax Call to get hte Bank name and Branch
                {type: "POST",
                url: url + "/PopulatePostCode",
                data: keyvalue,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) { PostCodeOnSuccess(response, postCodeid); }, error: OnError
            });
}

function PostCodeOnSuccess(data, postCodeid) {
    var result = data.d;

    var ctrl = jQuery('[id$=' + postCodeid + ']');
    var ParentCtrl = jQuery('[id$=' + postCodeid + ']'); //Parent control
    var ddlCtrl = jQuery("#" + jQuery(ctrl).attr('id')).children(); //ddlControl

    var arrPostcodes = new Array();
    arrPostcodes = result;
    if (arrPostcodes.length > 0) {
        $get(postCodeid).length = 0; //remove alll the items from the options
        jQuery($get(postCodeid)).next().remove(); // remove the next item of the dropdown list
        jQuery($get(postCodeid)).next().remove(); // remove the div ui list
        for (var count = 0; count < arrPostcodes.length; count++) {

            if (arrPostcodes[count] != null) {
                var varpostcodes = document.createElement("OPTION");
                varpostcodes.text = arrPostcodes[count];
                varpostcodes.value = arrPostcodes[count];
                $get(postCodeid).options.add(varpostcodes);
            }
        }
        ReRenderFancyDDL(postCodeid);
    }
    else {
        $get(postCodeid).length = 0; //remove alll the items from the options
        jQuery($get(postCodeid)).next().remove(); // remove the next item of the dropdown list
        jQuery($get(postCodeid)).next().remove(); // remove the div ui list
    }
}


function ReRenderFancyDDL(ddlID) {
    var ctrl = jQuery('[id$=' + ddlID + ']');
    var ParentCtrl = jQuery('[id$=' + ddlID + ']'); //Parent control
    var ddlCtrl = jQuery("#" + jQuery(ctrl).attr('id')).children(); //ddlControl

    ///Turns select html control into a fancy drop down control
    //use the first option as the label
    var myval = jQuery('#' + jQuery(ddlCtrl).attr('id') + ' option:selected').index();
    myval = jQuery('#' + jQuery(ddlCtrl).attr('id') + ' option').eq(myval).text();

    jQuery("#" + jQuery(ddlCtrl).attr('id')).after('<div class="selected">' + myval + '</div>');
    jQuery("#" + jQuery(ParentCtrl).attr('id')).append('<ul></ul>');

    //generate the list
    var list = jQuery('ul', ParentCtrl);
    jQuery('option', ParentCtrl).each(function () {
        var li = jQuery('<li>' + jQuery(this).text() + '</li>'); //create new list item
        li.data('value', jQuery(this).val()); //set the value to the value of this option
        list.append(li); //append to list
    });
}


//var ddlID = ""; detect state change at client side - in progress
//var ddlCurrentValue = "";
//jQuery("[id$=ddlState]").live('click', function () {
//    ddlID = jQuery(this).attr('id'); //get the id of the control and save it in RelationshipID which will be used on selection on the ddl via <li> tag
//    ddlCurrentValue = jQuery("#" + jQuery(this).attr('id') + " div.selected").html();
//});

//jQuery("[id$=ddlState] li").live('click', function () {
//    var dllChangedValue = jQuery(this).data('value');
//    //    alert("ddlCurrentValue: " + ddlCurrentValue + "   dllChangedValue:    " + dllChangedValue);
//    if (ddlCurrentValue != dllChangedValue) {

//     }
//});

function OnError(request, status, error) { }


function BindDateFieldEvents() {
    var PageURL = window.location.pathname;
    if (PageURL.toLowerCase().indexOf("personaldetails.aspx") >= 0) {

        jQuery("div[id$='ddlDay'] ul li").bind("click", function () {
            UpdateProductSummary(this);
        });

        jQuery("div[id$='ddlMonth'] ul li").bind("click", function () {
            UpdateProductSummary(this);
        });

        jQuery("div[id$='ddlYear'] ul li").bind("click", function () {
            UpdateProductSummary(this);
        });

    }
}

function UpdateProductSummary(object) {
    var selectObject = jQuery(object).parents("div.styleselect");
    if (selectObject.attr("id").toLowerCase().indexOf("client") >= 0 && jQuery("[id$='chkClientDateTrigger']").length > 0) {
        jQuery("[id$='chkClientDateTrigger']").click();
    }

    if (selectObject.attr("id").toLowerCase().indexOf("spouse") >= 0 && jQuery("[id$='chkSpouseDateTrigger']").length > 0) {
        jQuery("[id$='chkSpouseDateTrigger']").click();
    }
}
