﻿// JScript File
var ie4 = false; 
        if(document.all) 
        { 
	        ie4 = true; 
        }
        function getObject(id) 
        { 
            if (ie4) 
            
            { 
                return document.all[id]; 
            } 
            else 
            {   
                return document.getElementById(id); 
            } 
        }   
        function toggle(link, divId) 
        { 
            var lText = link.innerHTML; 
            var d = getObject(divId);
            if (lText != 'collapse') 
            {  
                d.style.display = 'block'; 
            }
            else 
            { 
                d.style.display = 'none'; 
            } 
        }
        function toggleTable(sender, tableId)
        {
            var tbl = document.getElementById(tableId);
            var div = document.getElementById(tableId + "_div");
            if(tbl.style.display == 'none')
            {
                tbl.style.display = 'block';
                div.style.display = 'block';
                sender.className = 'cm_collapse';
            }
            else
            {
                tbl.style.display = 'none';
                div.style.display = 'none';
                sender.className = 'cm_expand';
            }
              
        }
        function yellowOut(id)
        {
            whiteOut();
            document.getElementById(id).style.backgroundColor="#ffffcc";
        
        }
        function whiteOut()
        {
            var divs,i;
            divs = document.getElementsByTagName('div');
            for(i=0; i<divs.length; i++)
            {
              if(divs[i].style.backgroundColor == "#ffffcc")
              {
                divs[i].style.backgroundColor="white";
              }            
            }          
        }
        function NewWindow(page)
        {
		    if( page != "javascript:void(0);" )
		    {
			    window.open( page, "", "");
		    }
	    }

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


    function DivShow(showCat){
        var theDiv   = (document.getElementById(showCat));
        if(theDiv){

            theDiv.style.display="block";
        }
    }
    
    function DivHide(hideCat){
        var theDiv   = (document.getElementById(hideCat));
        if(theDiv){

            theDiv.style.display="none";
        }
    }
    
    function ShowHideDiv(divId){
        var theDiv = document.getElementById(divId);
        
        if(theDiv){
            if(theDiv.style.display == "none"){
                theDiv.style.display="block";
            }else{
                theDiv.style.display="none";
            }
        }
    }
    
    
    // Cart Ajax
    function GetShipOptions(){

        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        var postalCode = document.getElementById('txtPostalCode') ? document.getElementById('txtPostalCode').value : null;
        if (postalCode == null)
            postalCode = "";
        
        if(basketGuid != "" && userGuid != ""){
            // Show Loading
            DivShow('loadingImg');
            DisableButton("ctl00_MainContent_NextButton", "/Images/Checkout/ContinueProcessing_Loading.gif");
            
            var pl = new SOAPClientParameters();
            pl.add("basketGuid", basketGuid);
            pl.add("userGuid", userGuid);
            pl.add("postalCode", postalCode);
            SOAPClient.invoke("/SiteHelper.asmx", "GetShippersForBasket", pl, true, GetShipOptions_callBack);
        }
    }
    function GetShipOptions_callBack(Items)
    {
        var mask = document.getElementById('ShipEst');
        var shipTable;
        
        if(Items != null){
            shipTable = "<table cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"product_list_header\" style=\"padding-left:5px\">Shipping Type</td><td class=\"product_list_header\">Est. Delivery Date</td><td class=\"product_list_header\">Shipping Cost</td></tr>";
            
            if(Items.name == "Error")
            {
                shipTable += "<tr><td colspan=\"3\" style=\"color:red; padding:10px\">Error Retrieving Shipping Information, Please Try Again.</td></tr>";
            }else{
                for (var i in Items)
                {
                    if (typeof (Items[i]) != "function") {

                        if(Items[i].HasError == "True"){
                            shipTable += "<tr><td><label><input id=opt_\""+ Items[i].Guid +"\" type=\"radio\" value=\""+ Items[i].Guid + "\" name=\"ShipOption\" disabled=\"disabled\" /><span style=\"color:#666\">"+ Items[i].Name+ "</span></label></td><td style=\"color:#666\">"+ Items[i].Message+ "</td><td id=\"price_"+ Items[i].Guid +"\" class=\"list_price\">NA</td></tr>";
                        }
                        else
                        {
                            var price = (Items[i].Cost > 0) ? formatCurrency(Items[i].Cost) : 'Free';
                            var checked = (Items[i].Selected == 'True') ? 'checked="checked"' : '';
                            var ShowLocations = (Items[i].ShowLocations == "True" && document.getElementById('StoreLocations')) ? true : false;
                            var ShowAddressPicker = (Items[i].ShowLocations == "True") ? "" : "DisplayPickupInStore(false, null, null);";
                            shipTable += "<tr><td><label style=\"cursor:pointer; color:#003366\"><input id=opt_\"" + Items[i].Guid + "\" onclick=\"SetShipOptionsAsync(this.value, " + ShowLocations + ");" + ShowAddressPicker + "\" type=\"radio\" value=\"" + Items[i].Guid + "\" name=\"ShipOption\" " + checked + " /><b>" + Items[i].Name + "</b></label></td><td>" + Items[i].Message + "</td><td id=\"price_" + Items[i].Guid + "\" class=\"list_price\">" + price + "</td></tr>";
                            if(Items[i].Selected == 'True' && document.getElementById('ShipPrice')) document.getElementById('ShipPrice').innerHTML = price;
                            if(Items[i].Selected == 'True' && ShowLocations) SetShipOptions(Items[i].Guid, true);
                        }
                    }
                }
                DisplayOutOfStock();
            }
            shipTable += "</table>";
        }
        else
        {
            shipTable = "Sorry, there are no shipping options for that Postal Code";
        }
        
        mask.innerHTML = shipTable;
        
        // Show the Shipping
        DivShow('ShipEst');
        
        // Hide Loading
        DivHide('loadingImg');
        EnableButton("ctl00_MainContent_NextButton", "/Images/Checkout/ContinueProcessing_L.gif");
    }



    function SetShipOptionsAsync(Id, GetStores) {
        DisableButton("ctl00_MainContent_NextButton", "/Images/Checkout/ContinueProcessing_Loading.gif");
        setTimeout('SetShipOptions("' + Id + '",' + GetStores + ')', 0);
    }


    function SetShipOptions(Id, GetStores) {

        var price = document.getElementById('ShipPrice');
        var setPrice = document.getElementById('price_'+Id);
        if(price && setPrice) price.innerHTML = setPrice.innerHTML;
        
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;


        if(basketGuid != "" && userGuid != ""){
            var pl = new SOAPClientParameters();
            pl.add("basketGuid", basketGuid);
            pl.add("userGuid", userGuid);
            pl.add("shipGuid", Id);
            
            var setShip = SOAPClient.invoke("/SiteHelper.asmx", "SetShipperForBasketByGuid", pl, false, null);
            
            if(setShip){
                GetBasketTotals();
                DisplayOutOfStock();
                if(GetStores){
                    SOAPClient.invoke("/SiteHelper.asmx", "GetStoreLocationsForBasket", pl, true, GetStoreLocations_callBack);
                    DivShow('PaymentMethodDisabledDiv');
                    DivHide('PaymentMethodListDiv');
                }else{
                    DivHide('StoreLocations');
                    DivHide('PaymentMethodDisabledDiv');
                    DivShow('PaymentMethodListDiv');
                }
            }
        }

        EnableButton("ctl00_MainContent_NextButton", "/Images/Checkout/ContinueProcessing_L.gif");
    }


    function GetStoreLocations_callBack(Items){
        var mask = document.getElementById('StoreLocations');
        var locationsTable;
        
        if(Items != null){
            locationsTable = "<img style=\"float:left; padding-right:3px\" src=\"/Images/Checkout/expanded.gif\"><div style=\"margin-left:28px; width:400px; padding:5px; background-color:#FFFFCC; border:solid 1px #FF9966\"><b style=\"color:#666666; font-size:13px\">Select Your Pickup Location:</b><br />";
            for (var i in Items)
            {
                if(typeof(Items[i]) != "function"){
                    var checked = (Items[i].Selected == 'True') ? 'checked="checked"' : '';
                    locationsTable += "<label style=\"cursor:pointer; color:#003366\"><input id=opt_\"" + Items[i].ID + "\" onclick=\"SetPickupStoreId(this.value);DisplayPickupInStore(true, '" + Items[i].Name + "', '" + Items[i].Address + "');\" type=\"radio\" value=\"" + Items[i].ID + "\" name=\"LocationOption\" " + checked + " /><b>" + Items[i].Name + "</b> - <span class=\"grey_med\">" + Items[i].Address + "</span> <span style=\"color:Black; font-size:10px\"><b>(" + Items[i].Distance + "km From You)</b></span></label><br />";
                    
                    // Display Store as Shipping Address
                    if(Items[i].Selected == 'True')
                    {
                        DisplayPickupInStore(true, Items[i].Name, Items[i].Address);
                    }
                }
            }
            locationsTable += "<br><label><b>Sales Associate:</b> <input type=\"text\" name=\"frm_SalesRep\" id=\"frm_SalesRep\" class=\"textfield\" style=\"width:150px\" /></label> <span class=\"grey_med\"><em>(Optional)</em></span><div Class=\"grey_sm\" style=\"font-style:italic\">Use the Sales Associate field if you prefer dealing with a particular representative.</div></div>";
        }
        else
        {
            locationsTable = "<img style=\"float:left; padding-right:3px\" src=\"/Images/Checkout/expanded.gif\"><div style=\"margin-left:28px; width:400px; padding:5px; background-color:#FFFFCC; border:solid 1px #FF9966\"><b style=\"color:#666666; font-size:13px\">Select Your Pickup Location:</b><br /><div style=\"padding:5px; color:Red\">Sorry, there was a problem retrieving store locations</div></div>";
        }
        
        mask.innerHTML = locationsTable;
        
        // Show the Shipping
        DivShow('StoreLocations');
    }
    
    function DisplayPickupInStore(Show, Name, Address)
    {
        if(Show)
        {
            var pickupAddress = document.getElementById('div_PickupAddress');
            pickupAddress.innerHTML = "<div style=\"font-size:15px; padding-bottom:5px; padding-top:3px\">Pickup In Store:</div><b>" + Name + "</b> - " + Address;

            DivShow('div_PickupAddress');
            DivShow('differentPickup');
            DivHide('div_ShippingAddress');
            DivHide('div_DifferentShipTo');
        }
        else
        {
            DivHide('div_PickupAddress');
            DivHide('differentPickup');
            DivShow('div_ShippingAddress');
            isDifferentShipTo();
        }
    }
    
    function SetPickupStoreId(Id){
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;

        if(basketGuid != "" && userGuid != ""){
            var pl = new SOAPClientParameters();
            pl.add("basketGuid", basketGuid);
            pl.add("userGuid", userGuid);
            pl.add("storeId", Id);

            SOAPClient.invoke("/SiteHelper.asmx", "SetPickupStoreId", pl, false, null);
            DisplayOutOfStock();
        }
    }
    
    function GetBasketTotals(){
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        
        if(basketGuid != "" && userGuid != ""){
            var pl = new SOAPClientParameters();
            pl.add("basketGuid", basketGuid);
            pl.add("userGuid", userGuid);
            
            var Totals = SOAPClient.invoke("/SiteHelper.asmx", "GetBasketTotals", pl, false, null);
            if(Totals != null){
                for (var t in Totals){
                    var Items = Totals[t];
                    
                    if(Items.attributes['Name'] == 'Totals' || Items.attributes['Name'] == 'Services'){
                        for (var i in Items){
                            if(Items[i] != Items.attributes){
                                Item = Items[i];
                                var update = document.getElementById('total_'+ Item['Name']);
                                if(update) update.innerHTML = formatCurrency(Item['Cost']);
                            }
                        }
                    }
                    
                    if(Items.attributes['Name'] == 'Taxes'){
                        var update = document.getElementById('total_Taxes');
                        var table = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
                        
                        for (var i in Items){
                            if(Items[i] != Items.attributes){
                                Item = Items[i];
                                
                                table += "<tr><td class=\"cm_border_bot\" style=\"text-align: right; padding-right: 3px\"><span class=\"large_grey_txt\" style=\"font-weight: normal\">"+Item['Name']+"</span></td><td class=\"cm_right_bot\" style=\"width:72px\"><span class=\"list_price\">" +formatCurrency(Item['Cost'])+ "</span></td></tr>";
                            }
                        }
                         table += "</table>";
                         if(update) update.innerHTML = table;
                    }
                }
            }
        }
    }
    
    
    
    function BillingAddressChange(id, sender)
    {
        var SelectBox = document.getElementById(id + "_MemxDrop");
        var SelectValue = document.getElementById(id + "_Value");
        document.getElementById('hdn_BillingAddressId').value = SelectValue.value;
        
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        
        var div_Billing = document.getElementById('div_BillingAddressDisplay');
        
        if(basketGuid != "" && userGuid != ""){
            var spl = new SOAPClientParameters();
            spl.add("basketGuid", basketGuid);
            spl.add("addressId", SelectValue.value);
            
            SOAPClient.invoke("/SiteHelper.asmx", "SetBillingAddress", spl, false, null);
            
            
            var gpl = new SOAPClientParameters();
            gpl.add("basketGuid", basketGuid);
            
            var Billing = SOAPClient.invoke("/SiteHelper.asmx", "GetBillingAddress", gpl, false, null);
            if(Billing != null)
            {
                div_Billing.innerHTML = Billing.FirstName + " " + Billing.LastName + "<br/>" + (Billing.CompanyName != null ? Billing.CompanyName + "<br/>" : "") + Billing.Line1 + "<br/>" + (Billing.Line2 != null ? Billing.Line2 + "<br/>" : "") + Billing.City + ", " + Billing.Region + ", "+ Billing.Country + "<br/>" + Billing.PostalCode;
                GetShipOptions();
                isDifferentShipTo();
            } else {
                //Fix for login timeout
                refresh();
            }
        }
    }
    
    
    function ShippingAddressChange(id, sender)
    {
        var SelectBox = document.getElementById(id + "_MemxDrop");
        var SelectValue = document.getElementById(id + "_Value");
        document.getElementById('hdn_ShippingAddressId').value = SelectValue.value;
        
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        
        var div_Shipping = document.getElementById('div_ShippingAddressDisplay');
        
        DivHide('ShipEst');
        DivHide('StoreLocations');
        
        if(basketGuid != "" && userGuid != ""){
            var spl = new SOAPClientParameters();
            spl.add("basketGuid", basketGuid);
            spl.add("addressId", SelectValue.value);
            
            SOAPClient.invoke("/SiteHelper.asmx", "SetShippingAddress", spl, false, null);
            
            
            var gpl = new SOAPClientParameters();
            gpl.add("basketGuid", basketGuid);
            
            var Shipping = SOAPClient.invoke("/SiteHelper.asmx", "GetShippingAddress", gpl, false, null);
            if (Shipping != null) {
                div_Shipping.innerHTML = Shipping.FirstName + " " + Shipping.LastName + "<br/>" + (Shipping.CompanyName != null ? Shipping.CompanyName + "<br/>" : "") + Shipping.Line1 + "<br/>" + (Shipping.Line2 != null ? Shipping.Line2 + "<br/>" : "") + Shipping.City + ", " + Shipping.Region + ", " + Shipping.Country + "<br/>" + Shipping.PostalCode;
                GetShipOptions();
                UpdateShipping();
                isDifferentShipTo();
            } else {
                //Fix for login timeout
                refresh();
            }
        }
    }

    function refresh() 
    {
        // Refresh The Page
        window.location.href = unescape(window.location.pathname);
    }
    
    function isDifferentShipTo()
    {
        var div_Billing = document.getElementById('hdn_BillingAddressId');
        var div_Shipping = document.getElementById('hdn_ShippingAddressId');

        if ((div_Billing != null && div_Shipping != null) && (div_Billing.value != div_Shipping.value) && !isVisible('div_PickupAddress'))
        {
            DivShow('div_DifferentShipTo');
        }
        else
        {
            DivHide('div_DifferentShipTo');
        }
    }
    
    
    function UpdateShipping()
    {
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        var postalCode = document.getElementById('txtPostalCode') ? document.getElementById('txtPostalCode').value : null;
        if (postalCode == null)
            postalCode = "";
        
        if(basketGuid != "" && userGuid != ""){
            // Show Loading
            DivShow('loadingImg');
            DisableButton("ctl00_MainContent_NextButton", "/Images/Checkout/ContinueProcessing_Loading.gif");
            
            var pl = new SOAPClientParameters();
            pl.add("basketGuid", basketGuid);
            pl.add("userGuid", userGuid);
            pl.add("postalCode", postalCode);
            SOAPClient.invoke("/SiteHelper.asmx", "GetShippersForBasket", pl, true, UpdateShipping_callBack);
        }
    }
    
    
    function UpdateShipping_callBack(Items)
    {
        var basketGuid = document.getElementById('basketGuid').value;
        var userGuid = document.getElementById('userGuid').value;
        
        if(Items.name != "Error")
        {
            for (var i in Items)
            {
                if(Items[i].Selected == 'True'){
                    
                    var spl = new SOAPClientParameters();
                    spl.add("basketGuid", basketGuid);
                    spl.add("userGuid", userGuid);
                    spl.add("shipGuid", Items[i].Guid);
        
                    var setShip = SOAPClient.invoke("/SiteHelper.asmx", "SetShipperForBasketByGuid", spl, false, null);
                }
            }
        }
    }


    function DisplayOutOfStock()
    {
        var basketGuid = document.getElementById('basketGuid').value;
        var OutOfStockDiv = document.getElementById('OutOfStockItems');

        if (basketGuid != "" && OutOfStockDiv != null) {
            var spl = new SOAPClientParameters();
            spl.add("basketGuid", basketGuid);

            var ItemsOut = SOAPClient.invoke("/SiteHelper.asmx", "GetOutOfStockItemsInBasket", spl, false, null);

            var html = "";

            if (ItemsOut != null) {
                for (var i in ItemsOut) {
                    if (ItemsOut[i] != ItemsOut.attributes) {
                        html += "<div style=\"margin:8px; padding:5px; background-color:#fff; border:solid 1px #ccc;\">";
                        html += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                        html += "<tr>";
                        html += "    <td width=\"45\"><img src=\"/Images/Products/ShowImage.axd?ImgType=Product&ImgID=" + ItemsOut[i].ProductId + "-0&ImgSize=Small\" width=\"40\" height=\"40\" border=\"0\" style=\"padding-right:5px\" /></td>";
                        html += "    <td><b>" + ItemsOut[i].Manufacturer + "</b> " + ItemsOut[i].DisplayName + "<br/><a href=\"#NA\" onclick=\"UpdateItemQuantity('" + ItemsOut[i].LineItemId + "', '0', '" + ItemsOut[i].Url + "');\">Find a Replacement</a></td>";
                        html += "    <td width=\"30\"><b style=\"color:#cc0000\">" + ItemsOut[i].FullfilledQty + "</b></td>";
                        html += "    <td width=\"30\"><input name=\"qty_" + ItemsOut[i].LineItemId + "\" type=\"text\" class=\"inputCSS\" id=\"qty_" + ItemsOut[i].LineItemId + "\" value=\"" + ItemsOut[i].Quantity + "\" style=\"width:20px\" maxlength=\"3\" /></td>";
                        html += "    <td width=\"75\"><a href=\"#NA\" onclick=\"UpdateItemQuantity('" + ItemsOut[i].LineItemId + "', getvalue('qty_" + ItemsOut[i].LineItemId + "'), null);\"><img border=\"0\" src=\"/Images/Checkout/update.gif\"/></a></td>";
                        html += "</tr>";
                        html += "</table>";
                        html += "</div>";  
                    }
                }
            }
            
            // Dispaly Out Of Stock Message
            if (html != "") {
                DivShow("OutOfStockMsg");
            } else {
                DivHide("OutOfStockMsg");
            }
            OutOfStockDiv.innerHTML = html;
        }
    }


    function UpdateItemQuantity(id, qty, url) {
        var basketGuid = document.getElementById('basketGuid').value;

        if (basketGuid != "" && id != null && qty != null) {
            var spl = new SOAPClientParameters();
            spl.add("basketGuid", basketGuid);
            spl.add("itemId", id);
            spl.add("quantity", qty);

            var Items = SOAPClient.invoke("/SiteHelper.asmx", "UpdateLineItemQuantity", spl, false, null);
            if (url == null || url == "") {
                DisplayOutOfStock();
            } else {
                window.location = url;
            }
        }
    }

    function getvalue(id) {
        return document.getElementById(id).value;
    }

    function isVisible(id) {
        var target = document.getElementById(id);
        if (target != null && target.style.display != "none") {
            return true;
        } else {
            return false;
        }
    }
    
    
    // Site Navigation Functions
    
    function GetNavSub(id, lvl, startPath, hash){
        // Set Loading Img
        // document.getElementById('mask_'+id).innerHTML = "<div style=\"text-align:center\"><img src=\"/Images/Common/loading.gif\" width=\"130\" height=\"60\" alt=\"Loading...\" /></div>";
        
        if(document.getElementById('sub_'+hash).innerHTML == ""){
        
            var pl = new SOAPClientParameters();
            pl.add("id", id);
            pl.add("lvl", lvl);
            pl.add("startPath", startPath);
            SOAPClient.invoke("/SiteHelper.asmx", "GetNavSubCategories", pl, false, GetNavSub_callBack);
        }
    }
    
    function GetNavSub_callBack(Items)
    {
        for (var i in Items)
        {
            if(typeof(Items[i]) != "function"){
                var mask = document.getElementById('sub_'+Items[i].ParentHash);
                var subProds = Items[i].ChildProducts > 0 ? " <span style=\"font-size:9px;color:#000\">("+Items[i].ChildProducts+")</span>" : "";
                var subCatsImg = Items[i].ChildCategories > 0 ? "P.gif" : "L.gif";
                var rootCatObj = Items[i].Path.split("/");
                var rootCat = rootCatObj[2].replace("(ME)", "");
                var onClick = Items[i].ChildCategories > 0 ? "onclick=\"GetNavSub('" + Items[i].ID + "', '" + Items[i].LVL + "', '" + Items[i].Path + "', '"+ Items[i].PathHash+ "');ShowHideNav('"+ Items[i].PathHash+ "');VNID_"+rootCat+".show();\"" : "";
                var catDiv = "<div id=\"nav_"+ Items[i].PathHash+ "\"><img id=\"blt_"+ Items[i].PathHash+ "\" src=\"/Images/"+subCatsImg+"\" class=\"nav_blt\" "+onClick+" /><div><a href=\""+ Items[i].Path + "/Default.aspx\"><span class=\"nav_link_"+ Items[i].LVL+ "\">"+ Items[i].Name + subProds + "</span></a><br clear=\"all\" /></div></div><div id=\"sub_"+ Items[i].PathHash + "\" class=\"nav_sub\" style=\"display:none;\" ></div>";
                
                var newCatDiv = document.createElement('div');
                newCatDiv.innerHTML = catDiv;
                mask.appendChild(newCatDiv);
            }
        }
    }
    
    function DisplayNav(Cat){
        var theDiv = document.getElementById(Cat);
        
        if(NavId && theDiv){
            for (var i = 0;i<NavId.length;i++){
                if(NavId[i] == Cat){ 
                    var hideDiv = document.getElementById(NavId[i]);
                    hideDiv.style.display="";
                    eval('V'+NavId[i]+'.slideIn()');
                    
                }else{
                    eval('V'+NavId[i]+'.slideOut()');
                }
            }
        }
    }
    
    function ShowHideNav(showCat){
        var theCat = (document.getElementById('sub_'+showCat));
        var theBlt = (document.getElementById('blt_'+showCat));
        
        if(theCat && theBlt){
            if(theCat && theCat.style.display == "none"){
                theCat.style.display="";
                theBlt.src="/Images/M.gif";
            }else{
                theCat.style.display="none";
                theBlt.src="/Images/P.gif";
            }
        }
    }


    function scrollto(toId) {
        var to = document.getElementById(toId);
        if (to != null) {
            to.scrollIntoView(true);
        }
    }
    
    //////////
    
    
    // MemxDropDown
    var DropActive;

    function MemxDropDown_click(active)
    {
        DropActive = active;
        document.onclick=MemxDropCheck;
    }
    
    document.onclick=MemxDropCheck;
    function MemxDropCheck(e){
        var target = (e && e.target) || (event && event.srcElement);
        
        var MemxDrop = document.getElementById(DropActive + '_MemxDrop');
        var DropShow = document.getElementById(DropActive + '_DropShow');
        
        if(target==MemxDrop || target==DropShow)
        {
            ShowHideDiv(DropActive + '_DropDiv') 
        }
        else
        {
            DivHide(DropActive + '_DropDiv');
            DropActive = null;
        }
    }
    
    function MemxDropDown_select(id, text, itemVal, sender, selected)
    {
        var SelectBox = document.getElementById(id + "_MemxDrop");
        SelectBox.value = text;
        
        
        var SelectValue = document.getElementById(id + "_Value");
        SelectValue.value = itemVal;
        
        //Set Selected ID and BackgroundColor
        var SelectItemID = document.getElementById(id + "_SelectItem");
        
        // Change Old Item Background to White
        if(SelectItemID.value != "NA")
        {
            document.getElementById(id +'_'+ SelectItemID.value).style.backgroundColor = '';
        }
        
        // Set Selected Item Background to #f0f2f4 and update the hidden field for SelectID
        document.getElementById(id +'_'+ selected).style.backgroundColor = '#f0f2f4';
        SelectItemID.value = selected;
    }
    
    //
    
    
    function containsDOM (container, containee) {
        var isParent = false;
        do {
            if ((isParent = container == containee))
                break;

            containee = containee.parentNode;
        }
        while (containee != null);
        return isParent;
    }
    
    function checkMouseEnter (element, evt) {
      if (element.contains && evt.fromElement) {
        return !element.contains(evt.fromElement);
      }
      else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
      }
    }

    function checkMouseLeave (element, evt) {
      if (element.nodeName == 'A') return;
      if (element.contains && evt.toElement) {
        return !element.contains(evt.toElement);
      }
      else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
      }
    }


    function ChangeCheckBoxState(id, checkState)
    {
      var cb = document.getElementById(id);
      if (cb != null)
         cb.checked = checkState;
    }
             
   function ChangeAllCheckBoxStates(checkstate)
   {
      //alert(checkstate);
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      if (CheckBoxIDs != null)
      {
         for (var i = 0; i < CheckBoxIDs.length; i++)
            ChangeCheckBoxState(CheckBoxIDs[i], checkstate);
      }
   }


    function popChat(url,boxname,w,h) 
    { 
      window.open(url , boxname , 'width='+w+',height='+h+',left=0,top=0,menubar=0,toolbar=0,status=0,resizable=0'); 
    }

function fnDropDownRequired(source, arguments)
{
    var dropdown = document.getElementById(source.controltovalidate);
    if (dropdown.selectedindex == 0)
    {
        argument.IsValid = false;
    }   
    else {
        arguments.IsValid = true;
    }
}

// Ajax Loading
function ShowLoading(){
    DivShow("LoadingDiv");
    
    contTd = eval(document.getElementById("ConfigWindow"));
    if(contTd) {
        contTd.style.display = "none";
    }
}

function HideLoading(){
    DivHide("LoadingDiv");
    
    contTd = eval(document.getElementById("ConfigWindow"));
    if(contTd) {
        contTd.style.display = "block";
    }
}

function DisableButton(id, bg) {
    btn = document.getElementById(id);
    if (btn) {
        if (bg) btn.style.backgroundImage = "url(" + bg + ")";
        btn.disabled = true;
    }
}

function EnableButton(id, bg) {
    btn = document.getElementById(id);
    if (btn) {
        if (bg) btn.style.backgroundImage = "url(" + bg + ")";
        btn.disabled = false;
    }
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function addFormElement(name, value) {
    if (!document.getElementById && document.createElement) { return; }
    var inhere = document.getElementById("aspnetForm");
    var formfield = document.createElement("input");
    formfield.name = name;
    formfield.type = "hidden";
    formfield.value = value;
    inhere.appendChild(formfield);
    return true;
}


