﻿function GotoCheckout() {
      window.location.href = "checkout1.aspx?checkout=true";
 }
function ValidatePwdSpace(ID) {
    var txt = document.getElementById(ID).value;
    var iChars = " ";
    var str = txt;
    var j = 0;
    for (var i = 0; i < txt.length; i++) {
        if (iChars.indexOf(txt.charAt(i)) != -1) {
            j = 1;
            var rep = txt.charAt(i);
            str = str.replace(rep, "");
        }
    }
    if (j == 1) {
        window.setTimeout('document.getElementById("' + ID + '").focus();', 100);
        alert("White-Space characters are not allowed. Characters Removed.\n");
        document.getElementById(ID).value = str;
        return false;
    }
    return true;
}
function ValidateTxt(ID) {
    var txt = document.getElementById(ID).value;
    var iChars = "!$%^&*()+=[]\\\;/{}|\":<>?";
    var str = txt;
    var j = 0;
    for (var i = 0; i < txt.length; i++) {
        if (iChars.indexOf(txt.charAt(i)) != -1) {
            j = 1;
            var rep = txt.charAt(i);
            str = str.replace(rep, "");
        }
    }
    if (j == 1) {
        window.setTimeout('document.getElementById("' + ID + '").focus();', 100);
        alert("Special characters are not allowed. Characters Removed.\n");
        document.getElementById(ID).value = str;
        return false;
    }
    return true;
}

function endRequestHandler(sender, args) {

}

function ValidatePwdSpace(ID) {
    var txt = document.getElementById(ID).value;
    var iChars = " ";
    var str = txt;
    var j = 0;
    for (var i = 0; i < txt.length; i++) {
        if (iChars.indexOf(txt.charAt(i)) != -1) {
            j = 1;
            var rep = txt.charAt(i);
            str = str.replace(rep, "");
        }
    }
    if (j == 1) {
        window.setTimeout('document.getElementById("' + ID + '").focus();', 100);
        alert("White-Space characters are not allowed. Characters Removed.\n");
        document.getElementById(ID).value = str;
        return false;
    }
    return true;
}
function signclubfrmCat_Click() {
    if (document.getElementById("newsletter").value == '' || document.getElementById("newsletter").value == 'Email Address') {
        alert("Please enter your email address.");
        return (false);
    }
    else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("newsletter").value)) {
    __doPostBack('ClubSubmit', document.getElementById("newsletter").value);
    }
    else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("newsletter").value) == false) {
        alert("Invalid e-mail address! please re-enter.");
        return (false);
    }

    return (true);

    //document.location.href = "club.aspx?email=" + document.getElementById("newsletter").value;
}
function signclub_Click() {
    if (document.getElementById("newsletter").value == '' || document.getElementById("newsletter").value == 'Email Address') {
        alert("Please enter your email address.");
        return (false);
    }
    else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("newsletter").value)) {
        return (true);
    }
    else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("newsletter").value) == false) {
        alert("Invalid e-mail address! please re-enter.");
        return (false);
    }

    return (true);

    //document.location.href = "club.aspx?email=" + document.getElementById("newsletter").value;
}

function resetbox() {
    document.getElementById("newsletter").style.color = '';
    document.getElementById("newsletter").value = '';
}

function emailblur() {
    if (document.getElementById("newsletter").value == '') {
        document.getElementById("newsletter").value = 'Email Address';
        document.getElementById("newsletter").style.color = 'Gray';
    }
}


function signclub_validate() {
    return signclub_Click();
}
function SetPageSize(pageno, baseurl, size, order, direction) {
    if (size.toString() == "All") {
        pageno = 1;
    }
    var loc = baseurl + '?page=' + pageno + '&reccount=' + size + '&sortby=' + order + '&sortorder=' + direction;
    window.location.href = loc;

}
  function OnSelectURCondChange(txtID,lstID) {
        var radio = document.getElementsByName(lstID);
        var value;
        for (var ii = 0; ii < radio.length; ii++) {
            if (radio[ii].checked)
            value = radio[ii].value;
             
        }
        if (value == 'Other') {
            document.getElementById(txtID).style.display = 'block';
            document.getElementById(txtID).focus();
             document.getElementById("ctl00_PageContent_hfother").value = value;
           
           
        }
        else {
            document.getElementById(txtID).value = '';
            document.getElementById(txtID).style.display = 'none';
        }
        
    }
    function OnWhoRUChange(objDdl,objText,objSpace,objTr) {
        var value = document.getElementById(objDdl).value;
        if (value == 'Other') {
            document.getElementById(objText).style.display = 'block';
            document.getElementById(objSpace).style.display = 'block';
            document.getElementById(objText).focus();
            document.getElementById(objTr).style.height = '52px';
        }
        else {
            document.getElementById(objText).value = '';
            document.getElementById(objText).style.display = 'none';
            document.getElementById(objSpace).style.display = 'none';
            document.getElementById(objTr).style.height = '25px';
        }
    }
function ShowModaledImage() {
    document.getElementById('modalPicture').style.display = 'block';
    $(function() {
        $("#modalPicture").dialog({
            modal: true,
            height: 550,
            width: 500,
            position: 'center',
            buttons: {}
        });
    });
}
function ShowAROPopup(AroID,height, width) {
    document.getElementById(AroID).style.display = 'block';
    $(function() {
    $("#" + AroID).dialog({
            modal: true,
            height: height,
            width: width,
            title: 'Are you sure?',
            position: 'center',
            buttons: {}
        });
    });
    return false
}
function ShowProcessShipping() {
    document.getElementById('modalProcessShipping').style.display = 'block';
    $(function() {
        $("#modalProcessShipping").dialog({
            modal: true,
            height: 150,
            width: 475,
            position: 'center',
            title: 'Please wait',
            closeOnEscape: false,
            open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
            buttons: {}
        });
    });
}
function HideProcessShipping() {
    $(function() {
        $("#modalProcessShipping").dialog('close');
    });
    document.getElementById('modalProcessShipping').style.display = 'none';

}
function ShowAddressPopup(height, width, disableClose) {
    document.getElementById('modalAddress').style.display = 'block';
    if (disableClose) {
        $(function() {
            $("#modalAddress").dialog({
                modal: true,
                height: height,
                width: width,
                position: 'center',
                title: 'Please wait',
                closeOnEscape: false,
                open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
                buttons: {}
            });
        });
    }
    else {
        $(function() {
            $("#modalAddress").dialog({
                modal: true,
                height: height,
                width: width,
                position: 'center',
                closeOnEscape: true,
                buttons: {}
            });
        });
    }
    return false
}

function ShowPopup(height, width, disableClose) {
    document.getElementById('modalPopUp').style.display = 'block';
    if (disableClose) {
        $(function() {
            $("#modalPopUp").dialog({
                modal: true,
                height: height,
                width: width,
                position: 'center',
                title: 'Please wait',
                closeOnEscape: false,
                open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
                buttons: {}
            });
        });
    }
    else {
        $(function() {
            $("#modalPopUp").dialog({
                modal: true,
                height: height,
                width: width,
                position: 'center',
                closeOnEscape: true,
                buttons: {}
            });
        });
    }
    return false
}
function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}
function ShowProgress(objup,objtxt)
    {
   if(document.getElementById("ctl00_PageContent_ctl00_ctrlLogin_UserName").value != "")
   {
        document.getElementById(objup).style.display = 'inline';
        document.getElementById(objtxt).focus();
        document.getElementById("ctl00_PageContent_ctl00_hfcontrol").value="TRUE"
       return true;
        }
        else{
        //alert(document.getElementById("ctl00_PageContent_ctl00_ctrlLogin_UserName").value);
        document.getElementById(objtxt).focus();   
        document.getElementById("ctl00_PageContent_ctl00_hfcontrol").value="TRUE"     
      return false;
        }
       
    }
function getPromiseDate(value) {
    if (document.getElementById('H_PromiseTxt' + value)) {
        var promisetxt = document.getElementById('H_PromiseTxt' + value).value;
        var msg = '<ul class="messages"><li class="note-msg"><ul><li >' + promisetxt + '</li></ul><a class="btn-remove" href="#dismiss">Dismiss</a></li></ul>';
        document.getElementById("ctl00_PageContent_PromiseDate").style.display = "Block";
        document.getElementById("ctl00_PageContent_PromiseDate").innerHTML = msg;
    }
    else {
        document.getElementById("ctl00_PageContent_PromiseDate").style.display = "none";
        document.getElementById("ctl00_PageContent_PromiseDate").innerHTML = '';
    }
}
function setPromiseDateOnLoad() {
    var txt = '';
    if (document.aspnetForm.ctl00$PageContent$ctrlShippingMethods$ctrlShippingMethods) {
        for (var i = 0; i < document.aspnetForm.ctl00$PageContent$ctrlShippingMethods$ctrlShippingMethods.length; i++) {
            if (document.aspnetForm.ctl00$PageContent$ctrlShippingMethods$ctrlShippingMethods[i].checked) {
                txt = document.aspnetForm.ctl00$PageContent$ctrlShippingMethods$ctrlShippingMethods[i].value;
            }
        }
    }
    if (txt != '') {
        getPromiseDate(txt)
    }
    else {
        document.getElementById("ctl00_PageContent_PromiseDate").style.display = "none";
        document.getElementById("ctl00_PageContent_PromiseDate").innerHTML = '';
    }
}

function PrintReceipt() {
    var popupUrl = 'popup.aspx?topic=blank';
    var SkinId = 7;
    if (document.getElementById("ctl00_PageContent_CurSkinId") != null)
        SkinId = document.getElementById("ctl00_PageContent_CurSkinId").value;
    var windowName = 'OrderReceipt' + Math.floor(Math.random() * 1024 + 1);
    var popupOptions = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=600,left=0,top=0';
    //var winOrder = window.open('OrderReceipt',windowName,0,0,800,600);
    var winOrder = window.open(popupUrl, windowName, popupOptions);
    winOrder.document.writeln("<html>");
    winOrder.document.writeln("<head>");
    winOrder.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
    winOrder.document.writeln("<title>Order Receipt</title>");
    winOrder.document.writeln("<link rel='stylesheet' href='App_Themes/Skin_" + SkinId + "/styles.css' type='text/css'>");
    winOrder.document.writeln("</head>");
    winOrder.document.writeln("    <body style='margin: 0px;background-image: none;' class='body' bottommargin='0' leftmargin='0' marginheight='0' marginwidth='0' rightmargin='0' topmargin='0' bgcolor='#FFFFFF' onload='self.focus();self.print();'>");
    winOrder.document.writeln("        <table border='0' cellpadding='0' cellspacing='0' width='800px'>");
    winOrder.document.writeln("            <tr>");
    winOrder.document.writeln("                <td colspan='6' valign='top' height='10'>");
    winOrder.document.writeln("                    <table border='0' cellpadding='0' cellspacing='0' height='10'>");
    winOrder.document.writeln("                        <tr>");
    winOrder.document.writeln("                            <td height='10'>");
    winOrder.document.writeln("                                </td>");
    winOrder.document.writeln("                        </tr>");
    winOrder.document.writeln("                    </table>");
    winOrder.document.writeln("                </td>");
    winOrder.document.writeln("            </tr>");
    winOrder.document.writeln("            <tr>");
    winOrder.document.writeln("                <td colspan='6'>");
    winOrder.document.writeln("        <table border='0' cellpadding='0' cellspacing='0' width='100%'>");
    winOrder.document.writeln("            <tr>");
    winOrder.document.writeln("                <td valign='middle' width='638'>");
    winOrder.document.writeln("                    <table align='center' border='0' cellpadding='0' width='90%'>");
    winOrder.document.writeln("                        <tr>");
    winOrder.document.writeln("                            <td valign='middle'>");
    winOrder.document.writeln("                                <table align='center' border='0' cellpadding='0' cellspacing='0'style='background: transparent' width='100%'>");
    winOrder.document.writeln("                                    <tr>");
    winOrder.document.writeln("                                        <td valign='middle'>");
    winOrder.document.writeln("                                            <table align='center' border='0' cellpadding='0' cellspacing='0' style='background: transparent' width='100%'>");
    winOrder.document.writeln("                                                <tr>");
    winOrder.document.writeln("                                                    <td valign='middle'>");
    winOrder.document.writeln("                                                        <table align='center' border='0' cellpadding='0' cellspacing='0' width='100%'>");
    winOrder.document.writeln("                                                            <tr>");
    winOrder.document.writeln("                                                                <td valign='top'>");
    winOrder.document.writeln("                                                                    <div id='content' class='body'>");
    winOrder.document.writeln("                                                                        <!-- CONTENTS START -->");
    winOrder.document.writeln(document.getElementById("PrintPage").innerHTML);
    winOrder.document.writeln("                                                                        <!-- CONTENTS END -->");
    winOrder.document.writeln("                                                                    </div>");
    winOrder.document.writeln("                                                                    <p align='center'>");
    winOrder.document.writeln("                                                                </td>");
    winOrder.document.writeln("                                                            </tr>");
    winOrder.document.writeln("                                                        </table>");
    winOrder.document.writeln("                                                    </td>");
    winOrder.document.writeln("                                                </tr>");
    winOrder.document.writeln("                                            </table>");
    winOrder.document.writeln("                                        </td>");
    winOrder.document.writeln("                                    </tr>");
    winOrder.document.writeln("                                </table>");
    winOrder.document.writeln("                            </td>");
    winOrder.document.writeln("                        </tr>");
    winOrder.document.writeln("                    </table>");
    winOrder.document.writeln("                    <br />");
    winOrder.document.writeln("                </td>");
    winOrder.document.writeln("            </tr>");
    winOrder.document.writeln("        </table>");
    winOrder.document.writeln("                </td>");
    winOrder.document.writeln("            </tr>");
    winOrder.document.writeln("            <tr>");
    winOrder.document.writeln("                <td colspan='6' height='15'>");
    winOrder.document.writeln("                    <table border='0' cellpadding='0' cellspacing='0' height='15'>");
    winOrder.document.writeln("                        <tr>");
    winOrder.document.writeln("                            <td valign='top' height='15'>");
    winOrder.document.writeln("                                </td>");
    winOrder.document.writeln("                        </tr>");
    winOrder.document.writeln("");
    winOrder.document.writeln("                    </table>");
    winOrder.document.writeln("                </td>");
    winOrder.document.writeln("            </tr>");
    winOrder.document.writeln("        </table>");
    winOrder.document.writeln("</body>");
    winOrder.document.writeln("</html>");
    winOrder.document.close();
}
function ValidateState(reset) {
    var selState = document.getElementById('ctl00_PageContent_ctrlShippingAddress_State');
    var mySplitResult = document.getElementById('ctl00_PageContent_hfRestrictedStatesCSV').value.split(",");

    for (i = 0; i < mySplitResult.length; i++) {
        if (selState.value == mySplitResult[i]) {
            document.getElementById('modalShipping').style.display = 'block';
            $(function() {
            $("#modalShipping").dialog({
                    modal: true,
                    height: 175,
                    width: 500,
                    position: 'center',
                    closeOnEscape: true,
                    buttons: {}
                });
            });
            if (reset == true) {
                selState.selectedIndex = 0;
            }
            return false;
        }
    }
    return true;
}
     
      function doClick(buttonName,e) {
                //the purpose of this function is to allow the enter key to 
                //point to the correct button to click.
               
                var key;
                if (window.event)
                    key = window.event.keyCode;     //IE
                else
                    key = e.which;     //firefox

                if (key == 13) {

                    //Get the button the user wants to have clicked
                    var btn = document.getElementById(buttonName);
                    
                    if (btn != null) { //If we find the button click it
                    
                       btn.click();
                      
                        
                    }
                    
                }
            }
            
   function confirmChgReOrdAddTOPrimary(AddressId) {
       if (document.getElementById("ctl00_PageContent_HasRecurringOrder").value == 'TRUE') {
                    showMask();
                    showPopWin('Re-orderAddressChange.htm', 400, 75, null, false, false, false, false, true);
                    document.getElementById("ctl00_PageContent_H_CommandArgument").value = AddressId;
                    return false;

                }
                else {
                    document.getElementById("ctl00_PageContent_H_CommandArgument").value = AddressId;
                    document.getElementById('ctl00_PageContent_ChgReOrdAddTOPrimary').value = 'true';
                    document.getElementById('ctl00_PageContent_H_makeprimary').value = 'makeprimary';
                    document.forms['Address'].submit();
                }
                
            }   
            
 function EditMe() {
     document.getElementById('ctl00_PageContent_H_makeprimary').value = '';
    }
            
    function DeleteMe() {
        document.getElementById('ctl00_PageContent_H_makeprimary').value = '';
    }

    function ToggleRecurringOptions() {
        var lstRecurring = document.getElementById("ctl00_PageContent_lstRecurring");
        var chk = document.getElementById("ctl00_PageContent_chkRecurring");
        if (chk.checked) {
            if (document.getElementById("ctl00_PageContent_H_CartMatch").value == "true") {
                ShowAROPopup('ctl00_PageContent_modalARO', 200, 600);
            }
            if (document.getElementById("ctl00_PageContent_ckbSaveCC")) {
                if (document.getElementById("ctl00_PageContent_ckbSaveCC").checked == false) {
                    alert("For auto re-orders, it is required to save Credit Card details.\nPlease select 'Save My Credit Card Info'.");
                    chk.checked = false;
                    return;
                }
            }
            lstRecurring.disabled = "";
        } else {
            lstRecurring.disabled = "disabled";
        }
    }
    function ValidateForReorders() {
        var chk = document.getElementById("ctl00_PageContent_ckbSaveCC");
        var RecurringsAvailable = document.getElementById("ctl00_PageContent_hRecurringsAvailable").value;
        if (!chk.checked && (RecurringsAvailable == 'true')) {
            alert("You have some Auto Re-Orders set. It is required to save Credit Card details for Auto Re-Orders.");
            chk.checked = true;
            return;
        }
        if (!chk.checked && document.getElementById("ctl00_PageContent_chkRecurring").checked) {
            alert("You have selected to put this order on Auto Re-Order below.\nIt is required to save Credit Card details for Auto Re-Orders.");
            chk.checked = true;
            return;
        }
    }   
    function ValidateReorders() {
     var chk = document.getElementById("ctl00_PageContent_ckbSaveCC");
        var RecurringsAvailable = document.getElementById("ctl00_PageContent_hRecurringsAvailable").value;
        if(!chk.checked && (RecurringsAvailable == 'true')) {
            alert("You have some health subscription program set. It is required to save Credit Card details of health subscription program.");
            chk.checked = true;
        }
    }
    function enablevalsummary() {
            Page_ValidationActive = true;
            if (document.getElementById("ctl00_PageContent_errorpnl")) {
                document.getElementById("ctl00_PageContent_errorpnl").style.visibility = "visible";
            }


        }
    function NotSaveCC() {
            var agree = confirm("Are you sure! you do not want to save your Payment Information?");
            if (agree) {
                return true;
            }
            else {
                return false;
            }
        }    
        
                         
   function CheckEmptyField() {
    if (document.getElementById("ctl00_PageContent_hfOrderNumber").value == '') {
        alert("Please Select an order.");
        return (false);
    }
    }

    function SetSelectedOrder(selRadio) {                                                   
    for (i = 0; i < 100; i++) {
        //orderhistorylist__ctl1_rbOrder
        var element = "ctl00_PageContent_orderhistorylist__ctl0" + i + "_rbOrder";
        if (document.getElementById(element)) {
            if (selRadio == document.getElementById(element))
                document.getElementById("ctl00_PageContent_hfOrderNumber").value = document.getElementById(element).value;
            else
                document.getElementById(element).checked = false;
        }
    }
}

function ValidateNumber(txt) {
    var iChars = "0123456789";
    var str = txt;
    var j = 0;
    for (var i = 0; i < txt.length; i++) {
        if (iChars.indexOf(txt.charAt(i)) == -1) {
            return false
        }
    }
    return true;
    }

    function SelectedShipMeth(selRadio) {
        for (i = 0; i < 30; i++) {
            //orderhistorylist__ctl1_rbOrder
            var element = "ctl00_PageContent_ctrlShippingMethods_ctrlShippingMethods_" + i;
            if (document.getElementById(element)) {
                if (selRadio == document.getElementById(element).value) {
                    document.getElementById(element).checked = true;
                }
                else {
                    document.getElementById(element).checked = false;
                }
            }
        }
    }
    function SelectedShipMethAdmin(selRadio) {
        for (i = 0; i < 30; i++) {
            //orderhistorylist__ctl1_rbOrder
            var element = "ctl00_bodyContentPlaceholder_ctrlShippingMethods_ctrlShippingMethods_" + i;
            if (document.getElementById(element)) {
                if (selRadio == document.getElementById(element).value) {
                    document.getElementById(element).checked = true;
                }
                else {
                    document.getElementById(element).checked = false;
                }
            }
        }
    }


    function UpdateShippingMethodsAdmin() {
        document.getElementById('ctl00_bodyContentPlaceholder_h_selectedShipID').value = document.getElementById('ctl00_bodyContentPlaceholder_lstShipping').value;
        ShowProcessShipping();
        __doPostBack('ctl00$bodyContentPlaceholder$butUpdateShipping', '');
    }
    function endRequestHandlerAROAdmin(sender, args) {
        HideProcessShipping();
    }
    function endRequestHandlerARO(sender, args) {
        HideProcessShipping();
    }
    function HideProcessShipping() {
        $(function() {
            $("#modalProcessShipping").dialog('close');
        });
        document.getElementById('modalProcessShipping').style.display = 'none';

    }

    function Checkcart(items) {
        var QtyCart = items;
        if (QtyCart == 0)
            document.getElementById("ctl00_CartDiv").style.display = "none";
        else
            document.getElementById("ctl00_CartDiv").style.display = 'block';
    }
    function CheckCardType() {
        var type = document.getElementById("ctl00_PageContent_ctrlCreditCardPanel_ddlCCType").value;
        var number = document.getElementById("ctl00_PageContent_ctrlCreditCardPanel_txtCCNumber").value;
        if (document.getElementById("ctl00_PageContent_hfcardnumber").value != "") {
            if (type == document.getElementById("ctl00_PageContent_hfcardtype").value) {
                document.getElementById("ctl00_PageContent_ctrlCreditCardPanel_txtCCNumber").value = document.getElementById("ctl00_PageContent_hfcardnumber").value;
            }
            else {
                document.getElementById("ctl00_PageContent_ctrlCreditCardPanel_txtCCNumber").value = '';
                document.getElementById("ctl00_PageContent_ctrlCreditCardPanel_txtCCVerCd").value = '';
            }
        }
    }

