﻿/// <reference path="jquery-1.2.6-intellisense.js" />




function doPostBackAsync(eventName, eventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    
    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }
    

    __doPostBack(eventName, eventArgs);

}

function SetUniqueRadioButton(nameregex, current, idOfDataItem,clientid) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }

    current.checked = true;

    $('.listing_view').find("*[ID$='hfClickedRadio']").val(idOfDataItem);
    var btn = document.getElementById(clientid);
    if (btn) {
        btn.click();
    }
    ShowHideButtons();
}

/******************************************
* General validation functions
******************************************/

function CheckBoxMustBeChecked_SetHiddenField() {
    var checkbox = $("[id$=btnTermsAndConditions]");
    if (checkbox.attr('checked')) {
        $("[id$=txtTermsAndConditionsChecked]").val('true');
    }
    else {
        $("[id$=txtTermsAndConditionsChecked]").val('false');
    }
}

function CheckBoxValidator_MustBeChecked(source, args) {
    args.IsValid = ($("[id$=txtTermsAndConditionsChecked]").val() == 'true');
}

/******************************************
*      checks if an addressID is mapped
******************************************/
//function ConfirmMappedAddress(source, args) {
//    var selectedAddress = args.Value;

//    if (selectedAddress.search(/mapped/) > -1) {
//        args.IsValid = true;
//    }

//    args.IsValid = false;
//}


function ShowHideButtons()
{
    $('.listing_view').find("*[ID$='btnSaveCard']").css("display", "block");
    $('.listing_view').find("*[ID$='btnAddCard']").css("display", "none");
}


function fnSwitchProductDetailsTabs(index) {
    var details = $("#pnlDetails");
    var about = $("#pnlAbout");
    var ingredients = $("#pnlIngredients");
    var nutrition = $("#pnlNutrition");
    var disclaimer = $("#pd_disclaimer");
    removeActiveClass();


    var detailsTab = $('.details_tabs');
    
    switch (index) {
        case 1:
            detailsTab.find("*[ID$='details_tab']").find('a').attr("class", "active");
            details.show();
            about.hide();
            ingredients.hide();
            nutrition.hide();
            disclaimer.hide();
            break;
        case 2:
            detailsTab.find("*[ID$='about_tab']").find('a').attr("class", "active");
            details.hide();
            about.show();
            ingredients.hide();
            nutrition.hide();
            disclaimer.show();
            break;
        case 3:
            detailsTab.find("*[ID$='ingredients_tab']").find('a').attr("class", "active");
            details.hide();
            about.hide();
            ingredients.show();
            nutrition.hide();
            disclaimer.show();
            break;
        case 4:
            detailsTab.find("*[ID$='nutrition_tab']").find('a').attr("class", "active");
            details.hide();
            about.hide();
            ingredients.hide();
            nutrition.show();
            disclaimer.show();
            break;
    }
}


function removeActiveClass() {
    var detailsTab = $('.details_tabs');
    detailsTab.find("*[ID$='details_tab']").find("a").removeAttr("class", "active");
    detailsTab.find("*[ID$='about_tab']").find("a").removeAttr("class", "active");
    detailsTab.find("*[ID$='ingredients_tab']").find("a").removeAttr("class", "active");
    detailsTab.find("*[ID$='nutrition_tab']").find("a").removeAttr("class", "active");
}

// -----------------------------------------------------------------------------
// ----------------------  weight and quantity incrementer/decrementer functions
// -----------------------------------------------------------------------------

function fnFormatNum(expr, decplaces) {
    var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces))
    while (str.length <= decplaces)
    { str = "0" + str; }
    var decpoint = str.length - decplaces
    return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
}

function fnSetListingQuantity(id, qty) {
    var qtyCtrl = document.getElementById(id);
    if (qtyCtrl != null) {
        qtyCtrl.value = qty;
    }
};

function fnGetListingQuantity(id) {
    var qtyCtrl = document.getElementById(id);
    return qtyCtrl.value;
};

function fnListingPlusWithUpdate(id, updatePriceControl, basePrice) {
    // decrement the Quantity
    fnListingPlus(id);
    // get price
    var price = parseFloat(basePrice);
    if (price > 0) {
        // calculate total
        var total = fnFormatNum(($get(id).value) * price, 2);
        if (total != null) {
            // set the price
            fnDetailSetTotalPrice(updatePriceControl, total);
        }
    }
}

function fnListingMinusWithUpdate(id, updatePriceControl, basePrice) {
    // decrement the Quantity
    fnListingMinus(id);
    // get price
    var price = parseFloat(basePrice);
    if (price > 0) {
        // calculate total
        var total = fnFormatNum(($get(id).value) * price, 2);
        if (total != null) {
            // set the price
            fnDetailSetTotalPrice(updatePriceControl, total);
        }
    }
}

function fnDetailSetTotalPrice(id, total) {
    $('#pnlDetails').find("*[ID$='" + id + "']").text("€" + total);
}

// Decrement the Quantity
function fnListingPlus(id) {
    var quant = parseInt($get(id).value);
    if (parseInt(quant) >= 999) {
        fnSetListingQuantity(id, 999);
    }
    else {
        fnSetListingQuantity(id, quant + 1);
    }
};
// Increment the Quantity
function fnListingMinus(id) {
    var element = $get(id);
    var quant = parseInt(element.value);
    if (parseInt(quant) > 1) {
        fnSetListingQuantity(id, parseInt(quant) - 1);
    }
};
function fnListingMinusChoice(id) {
    var element = $get(id);
    var quant = parseInt(element.value);
    if (parseInt(quant) > 1) {
        fnSetListingQuantity(id, parseInt(quant) - 1);
    }
    else {
        fnSetListingQuantity(id, 0);
    }
};
//
function fnListingChangeQuantity(id) {
    fnValidateQuantityRange(id);
};
//
function fnValidateQuantityBlur(id) {
    if (parseInt(fnGetListingQuantity(id)) == 0) {
        fnSetListingQuantity(id, "1");
    } else {
        if (fnGetListingQuantity(id) == "") {
            fnSetListingQuantity(id, "1");
        }
    }
};
//
function fnValidateQuantityRange(id) {
    if (isNaN(fnGetListingQuantity(id))) {
        fnSetListingQuantity(id, "1");
    } else {
        if (parseInt(fnGetListingQuantity(id)) > 999) {
            fnSetListingQuantity(id, "999");
        } else {
            if (parseInt(fnGetListingQuantity(id)) < 0) {
                fnSetListingQuantity(id, "0");
            }
        }
    }
};

function fnWeightPlusWithUpdate(id, increment, updatePriceControl, basePrice) {
    fnWeightPlus(id, increment);
    var price = fnFormatNum(parseFloat($get(id).value) * parseFloat(basePrice), 2);
    var element = $get(updatePriceControl);
    element.innerHTML = "€" + price;
}

function fnWeightMinusWithUpdate(id, increment, updatePriceControl, basePrice) {
    fnWeightMinus(id, increment);
    var price = fnFormatNum(($get(id).value) * parseFloat(basePrice), 2);
    var element = $get(updatePriceControl);
    element.innerHTML = "€" + price;
}

function fnWeightPlus(id, increment) {
    var element = $get(id);
    var qty = parseFloat(element.value) + parseFloat(increment);
    fnSetPopupWeight(id, qty);
    //fnPopupValidateWeightRange(id);
    fnPopupValidateWeightBlur(id);
};
function fnWeightMinus(id, decrement) {
    var element = $get(id);
    var qty = parseFloat(element.value) - parseFloat(decrement);
    fnSetPopupWeight(id, qty);
    //fnPopupValidateWeightRange(id);
    fnPopupValidateWeightBlur(id);
};
function fnPopupValidateWeightRange(id) {
    if (isNaN(fnGetPopupWeight(id))) {
        fnSetPopupWeight(id, "1.00");
    } else {
        if (parseFloat(fnGetPopupWeight(id)) > 999) {
            fnSetPopupWeight(id, "999.00");
        } else {
            if (parseFloat(fnGetPopupWeight(id)) < 0) {
                fnSetPopupWeight(id, "0.00");
            }
        }
    }
};
function fnPopupValidateWeightBlur(id) {
    if (parseFloat(fnGetPopupWeight(id)) == 0) {
        fnSetPopupWeight(id, "1.00");
    } else {
        if (fnGetPopupWeight(id) == "") {
            fnSetPopupWeight(id, "1.00");
        }
    } 
};
function fnPopupWeightChange(id, labelToUpdate) {
    fnPopupValidateWeightRange(id);
    updateWeightDisplay(id, labelToUpdate);
};

function fnGetPopupWeight(id) {
    var element = $get(id);

    element = element.value;
    
    if (element.substring(element.length - 1, element.length) == ".") {
        element += "0";
    }
    
    return element;
};
function fnSetPopupWeight(id, qty) {
    var element = $get(id);
    element.value = fnFormatNum(qty, 2);
};

//
function IncrementWeightUpdate(id, increment, updatePriceControl) {
    fnWeightPlus(id, increment);
    updateWeightDisplay(id, updatePriceControl);
}

//
function DecrementWeightUpdate(id, increment, updatePriceControl) {
    fnWeightMinus(id, increment);
    updateWeightDisplay(id, updatePriceControl); 
}


function IncrementPriceAddNote(id, labelToUpdate) {

    var popup = $find("modalPopupAddNoteBehavior")

    fnListingPlus(id);
    var q = $get(id).value;

    var price = $("#" + popup._PopupControlID).find("*[ID$='hfPopupPrice']").val();

    price = fnFormatNum(parseFloat(q) * parseFloat(price), 2);

    $("#" + popup._PopupControlID).find("#" + labelToUpdate).text("€" + price);
}


function DecrementPriceAddNote(id, labelToUpdate) {
    var popup = $find("modalPopupAddNoteBehavior")

    fnListingMinus(id);

    var q = $get(id).value;

    var price = $("#" + popup._PopupControlID).find("*[ID$='hfPopupPrice']").val();
    price = fnFormatNum(parseFloat(q) * parseFloat(price), 2);
    $("#" + popup._PopupControlID).find("#" + labelToUpdate).text("€" + price);
}


function updateWeightDisplay(valueControlID, updatePriceControl) {
    var popup = $find("modalPopupChooseWeightNoteBehavior");

    var q = $get(valueControlID).value;
    if (q < 1) {
        $("#" + popup._PopupControlID).find("#weightInGrammes").show().text((q * 1000) + "g");
        $("#" + popup._PopupControlID).find("*[ID$='lblcurrentSelectedWeight']").hide();
    }
    else {
        $("#" + popup._PopupControlID).find("#weightInGrammes").hide();
        $("#" + popup._PopupControlID).find("*[ID$='lblcurrentSelectedWeight']").show();
    }

    var price = $("#" + popup._PopupControlID).find("*[ID$='hfPopupPrice']").val();
    price = fnFormatNum(parseFloat(q) * parseFloat(price), 2);
    $("#" + popup._PopupControlID).find("#" + updatePriceControl).text(price);

}






// ------------------------------------------------------------------
// ----------------------  tool tip functions  ----------------------
// ------------------------------------------------------------------

function ShowTip(text) {

    var toolTipText;
    var textArr = text.split('#');

    if (textArr.length == 1) {
        toolTipText = "<p>" + textArr[0] + "</p>";
    }
    else {
        toolTipText = "<h2>" + textArr[0] + "</h2>";

        for (var i = 1; i < textArr.length; i++) {
            toolTipText += "<p>" + textArr[i] + "</p>";
        } 
    }

    Tip('<div class="tooltip">' + toolTipText + '</div>', DELAY, 10, PADDING, 9);
}


// Displays the header message control; if the page does not pass through validation 
// it then displays the error messages in this control.
function CheckPageValidation(errorHeading) {
    
    //"HeaderMsg" is the name of the validation group to check
    var inputValid = Page_ClientValidate('HeaderMsg');

    if (!inputValid) {
        //find the header message panel
        var pnl = $("*[ID$='pnlHeaderMessage']");
        pnl.removeAttr("style");
        pnl.attr("style", "display:block;");
        pnl.addClass("header alert");

        var vsErrors = $("DIV[ID$='vsErrors']");

        //get the errors and prefix it with our error heading
        var divInnerHTML = vsErrors.html();
        vsErrors.html(errorHeading + divInnerHTML);
    }

    return inputValid;
}

function ShowAlert(message) {
    
    //find the header message panel
    var pnl = $("*[ID$='pnlHeaderMessage']");
    pnl.removeAttr("style");
    pnl.attr("style", "display:block;");
    pnl.addClass("header alert");

    var label = $("SPAN[ID$='lblMessageToDisplay']");

    label.text(message);
}


// Prepares the placing of an order by first validating the page.  If the page is 
// valid, we disable the click on the button to prevent user placing order twice
// and related errors.
function PreparePlaceOrder() {

    var placeOrderBtn = $("*[ID$='btnPlaceOrder']");
    var inputValid = ValidatePage();

    if (inputValid) {
        placeOrderBtn.unbind();
        placeOrderBtn.bind("click", function() {
            return false; 
        });
    }

    return inputValid;
}





// Change the save changes button in the basket to be a loading icon when the user hits save changes.
function UnBindBasketSaveChanges() {

        var hdnUrlPath = $("*[ID$='hfSiteUrlWithTheme']").val();
    
        var btnSaveChangesTop = $("*[ID$='btnUpdateBasketTop']");
        var imgSaveChangesTop = $("#imgUpdateBasketTop");

        var btnSaveChangesBottom = $("*[ID$='btnUpdateBasketBottom']");
        var imgSaveChangesBottom = $("#imgUpdateBasketBottom");







        imgSaveChangesTop.attr("src", hdnUrlPath + "/images/anim_processing_white.gif");
     
        imgSaveChangesTop.mouseover(function() {
        $(this).attr("src", hdnUrlPath + "/Images/anim_processing_white.gif");
        });

        imgSaveChangesTop.mouseout(function() {
        $(this).attr("src", hdnUrlPath + "/Images/anim_processing_white.gif");
        });

        btnSaveChangesTop.removeAttr("onclick");

        btnSaveChangesTop.unbind();
        btnSaveChangesTop.bind("click", function() {
            return false;
        });





        imgSaveChangesBottom.attr("src", hdnUrlPath + "/images/anim_processing_white.gif");
               
        imgSaveChangesBottom.mouseover(function() {
        $(this).attr("src", hdnUrlPath + "/Images/anim_processing_white.gif");
        });

        imgSaveChangesBottom.mouseout(function() {
        $(this).attr("src", hdnUrlPath + "/Images/anim_processing_white.gif");
        });

        btnSaveChangesBottom.removeAttr("onclick");

        btnSaveChangesBottom.unbind();
        btnSaveChangesBottom.bind("click", function() {
            return false;
        });
        
        
       
    
}


function ValidatePage() {

    //check if the page is valid
    //var inputValid = Page_IsValid;

    var inputValid = Page_ClientValidate('HeaderMsg');

    // set the hidden field so that we know to cause a post back on the dropdownlist
    $("*[ID$='hfCauseValidation']").val(!inputValid);

    // find the header message panel (must use _pnlHeaderMessage as there is also
    // upnlHeaderMessage that should not be changed)
    var pnl = $("*[ID$='_pnlHeaderMessage']");

    if (!inputValid) 
    {
        pnl.removeAttr("style");
        pnl.attr("style", "display:block;");
        pnl.removeAttr("class");
        pnl.addClass("header alert");
    }
    else 
    {
        pnl.removeAttr("style");
        pnl.removeAttr("class");
        pnl.attr("style", "display:none;");        
    }
    //IE6, the alert image needs to be fixed
    if (typeof(pngfix) == 'function')
        pngfix();

    return inputValid;
   
}


//Pass validation group to validate
function ValidatePageGroup(vGroup) {

    //check if the page is valid
    //var inputValid = Page_IsValid;

    var inputValid = Page_ClientValidate(vGroup);

    //set the hidden field so that we know to cause a post back on the dropdownlist
    $("*[ID$='hfCauseValidation']").val(!inputValid);

    if (!inputValid) {

        //find the header message panel
        var pnl = $("*[ID$='pnlHeaderMessage']");
        pnl.removeAttr("style");
        pnl.attr("style", "display:block;");
        pnl.addClass("header alert");

    }

    return inputValid;

}

function CheckSavedAddress_ClientValidate(sender, args) 
{

    var ddl = $("SELECT[ID$='ddlSavedAddress']");
    
    //if the dropdownlist is disabled then we do not want to validate it, just return true
    if(ddl.attr('disabled') == true) {
        args.IsValid = true;
    }
    else {
        //ddl.val() (holds the values of the selectedvalue)
           
        //if the first item in the list is chossen then do not proceed
        if (ddl.attr("selectedIndex") <= 0) {
            args.IsValid = false;
        }
        else {
            args.IsValid = true; 
        }
    }
   
}

function PickUpLocation_ClientValidate(sender, args) {

    var ddl = $("SELECT[ID$='ddlPickupLocations']");

    //if the dropdownlist is disabled then we do not want to validate it, just return true
    if (ddl.attr('disabled') == true) {
        args.IsValid = true;
    }
    else {
        //ddl.val() (holds the values of the selectedvalue)

        //if the first item in the list is chossen then do not proceed
        if (ddl.attr("selectedIndex") <= 0) {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
        }
    }

}
  




//===============================================
//Slots


//when the slot view changes(next/previous 7 days) reset the slot that is currently choosen (if any)
//also reset the label that displays the slot time etc

//This is not being called anymore
function SlotViewChanged() {


   var SlotTimeDisplayControlID = $("*[ID$='hfSlotTimeDisplayControlID']").val(); 

    //when the user clicks next or previous 7 days then we want to reset the slot they have chossen
    $("*[ID$='hfCurrentSlotID']").val("");
    $("*[ID$='" + SlotTimeDisplayControlID + "']").text("");
}


//this is called when the user clicks on a slot
function SlotClicked(newSelectedSlotID, SlotTimeDisplayText)
{

    //get the name of the control that we display the slot date and time to
    var SlotTimeDisplayControlID = $("*[ID$='hfSlotTimeDisplayControlID']").val(); 

    //get the hyperlink of the new slot selected
    var hlNewSelectedSlot = $("*[ID$='SlotID_" + newSelectedSlotID + "']");
    
    //check to see if we can find the new slot selected
    if (hlNewSelectedSlot != null) {

        //get the slot id of the previous slot selected
        var previousSelectedSlotID = $("*[ID$='hfCurrentSlotID']").val();

        //remove the active css class against the previously selected slot
        var hlPreviousSelectedSlot = $("*[ID$='SlotID_" + previousSelectedSlotID + "']");
        if (hlPreviousSelectedSlot != null) {

            hlPreviousSelectedSlot.removeClass("active");
            hlPreviousSelectedSlot.addClass("slot_select");

            $("*[ID$='hfCurrentSlotID']").val(newSelectedSlotID)

            hlNewSelectedSlot.removeClass("slot_select");
            hlNewSelectedSlot.addClass("active");
           

            //update the label outside the user control to display the slot time text
            $("*[ID$='" + SlotTimeDisplayControlID + "']").text(SlotTimeDisplayText);

              
        }

    }

}

function CustomValidationForSlotSelected(source, args) {

    var selectedSlotID = $("*[ID$='hfCurrentSlotID']").val();

    //check to see if the hidden field is a number
    var fValue = parseFloat(selectedSlotID);
    
    
    if (isNaN(fValue)) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }    
     
}


//==================================================================================================

/*
function toggleSavedCardDDL(checkbox) {

    var ddl = $("SELECT[ID$='ddlSavedCard']");
    
    if (checkbox.checked) 
    {
        $('#divPaymentDetails :input').attr('disabled', true);
        ddl.attr("disabled", "");
    }
    else 
    {
        $('#divPaymentDetails :input').removeAttr('disabled');
        ddl.attr("disabled", "disabled");
    }
    
    checkbox.disabled = false;
}
*/

/*=================================================

    VALIDATION FUNCTIONS FOR PASSWORDS AND EMAIL

=================================================*/

function ValidateEmailChanges(source, args) {
    var value = args.Value;
    args.IsValid = ValidateEmail(value);    
}

function ValidateEmail(value) {
    // do length check.
    
    // do regex
    var exp = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    if (exp.test(value) == true) {
        return true;
    }
    else {
        return false;
    }
}

function ConfirmEmail(source, args) {

    // do length
    
    // do regex
    
    // Compare
}


function ValidatePasswordChanges(source, args) {
    var password = args.Value;
    args.IsValid = ValidatePassword(password);
}


function ValidatePassword(pass) {
    //^\w*(?=\w*\d)(?=\w*[A-Z])\w*$
    // if ((pass.length > 7) && (pass.length < 16)) {
    //   return false;
    //}

    //Minimum length 6 chars, max 20 chars.
    //At least 1 uppercase or 1 number or special char
    var exp = /^.*(?=.{6,20})(?=.*[A-Z0-9\W]).*$/;
    if (exp.test(pass) == true) {
        return true;
    }
    else {
        return false;
    }
}



function ValidateRewardCardNumber_ClientValidate(source, args) {

    var msg = 1;
    
    var str
    var pos12
    var pos11
    var pos10
    var pos9
    var pos8
    var pos7
    var pos6
    var pos5
    var pos4
    var pos3
    var pos2
    var pos1
    var lastchar
    var bc
    var summed
    var gc

    

    //         str = document.forms[0].superclub.value

    str = args.Value;

    if (str.length == 0 || str == "") {
        args.IsValid = false;
        return false;
    }
    
    if (str.length != 9) {
        if (msg == 1) {
            args.IsValid = false;
            return false;
        }
        args.IsValid = false;
        return false;
    }

    lastchar = str.substr(8, 1)

    str = "2345" + str

    bc = str.substr(0, 1)

    pos12 = 1 * parseInt(bc)


    bc = str.substr(1, 1)
    pos11 = 3 * parseInt(bc)

    bc = str.substr(2, 1)
    pos10 = 1 * parseInt(bc)

    bc = str.substr(3, 1)
    pos9 = 3 * parseInt(bc)

    bc = str.substr(4, 1)
    pos8 = 1 * parseInt(bc)

    bc = str.substr(5, 1)
    pos7 = 3 * parseInt(bc)

    bc = str.substr(6, 1)
    pos6 = 1 * parseInt(bc)

    bc = str.substr(7, 1)
    pos5 = 3 * parseInt(bc)

    bc = str.substr(8, 1)
    pos4 = 1 * parseInt(bc)

    bc = str.substr(9, 1)
    pos3 = 3 * parseInt(bc)

    bc = str.substr(10, 1)
    pos2 = 1 * parseInt(bc)

    bc = str.substr(11, 1)
    pos1 = 3 * parseInt(bc)

    summed = pos12 + pos11 + pos10 + pos9 + pos8 + pos7 + pos6 + pos5 + pos4 + pos3 + pos2 + pos1


    gc = 0

    while (summed % 10 != 0) {
        gc = gc + 1
        summed = summed + 1
    }

    if (gc != parseInt(lastchar)) {
        if (msg == 1) {
            args.IsValid = false;
            return false;
        }
        args.IsValid = false;
        return false;
    }
    args.IsValid = true;
    return true;
}



//make sure that the reward points the user wants to cash in is a multiple of 500
function ValidateRewardPointsToUse_ClientValidate(source, args) {

    var pointsToUse = args.Value;

    if (TryParseInt(pointsToUse) == false) {
        args.IsValid = false;
        return false;
    }

    if ((pointsToUse % 500) == 0) {
        args.IsValid = true;
        return true
    }
    else {
        args.IsValid = false;
        return false;
    }

}


function TryParseInt(str) {
    var retValue = false;
    if (str != null) {
        if (str.length > 0) {
            if (!isNaN(str)) {
                retValue = parseInt(str);
            }
        }
    }
    return retValue;
}

function ParseBoolean(value)
{
    if (value == null || value == undefined)
        return false;

    if (value == false)
        return false;
    else if (value == true)
        return true;
    
    if (isNaN(value)) {
        if (value == "true")
            return true;
        else
            return false;
    }
    else {
        if (value == 0)
            return false;
        else
            return true;
    }
}





function ValidateCCSecurityCode_ClientValidate(source, args) {

     var ddl = $("SELECT[ID$='ddlCardType']");
     var cardTypeID = ddl.val();


    //if the card is VISA (1) or MasterCard(2) then make sure that something was entered in the security code textbox
     if ((cardTypeID == 1) || (cardTypeID == 2)) {
         var securityCode = args.Value;

         CheckNum = parseInt(securityCode)
         if (isNaN(CheckNum)) {
             args.IsValid = false;
             return false;
         }
         else
        {
             args.IsValid = true;
             return true;
         }

     }
     else {
         args.IsValid = true;
         return true;
     }


 }
//Used when loading a template from a file
 function LoadTemplateFromFile(template, data, location) {
     $.get(template, function(html) {
         $(location).append($.template(html), data);
     });

 }
//Used when passing raw html
 function LoadTemplate(template, data, location) {   
         $(location).append($.template(template), data);
     }






     function ResetScrollPosition() {
         setTimeout("window.scrollTo(0,0)", 0);
 }