﻿

function EnableDisableCart(bEnabled)

{
//    var hypUrl;
//    if (bEnabled)
//    {
//        hypUrl = 'http://10.92.9.202:8021/ViewCart.aspx';
//    }
//    else
//    {
//        hypUrl = '';
//    }
//    setAnchorURL('Cart',hypUrl);
//    setAnchorURL('ctl00_LeftNav1_Catalog2_lbtCheckout',hypUrl);
////    setAnchorURL('Cart',hypUrl);

//    if (document.forms[0] != null)
//    {
//        for (var i=0; i < document.forms[0].elements.length; i++) 
//        {
//           var e = document.forms[0].elements[i];
//           if (e.type == 'submit' && e.value == 'Checkout')
//           {
//            e.disabled = 'disabled';
//           }
//           
//        }
//    }
//    
////    for (i=0; i<document.links.length; i++) 
////    {
////        if(document.links[i].text) 
////        {
////            if(((document.links[i].text).indexOf("cart")) == -1) 
////            {
////                setAnchorURL(document.links[i].id,hypUrl);
////            }
////        }
////    }
}

function setPrice(txtQuantity, txtPrice, lblPriceHdn)
{
    if (IsNumeric(txtQuantity.value))
    {
        if (txtQuantity.value != '' && txtQuantity.value != '0')
        {
            if (txtQuantity.value > '0')
            {
                txtQuantity.value = Math.round(txtQuantity.value);
            }
            else
            {
                txtQuantity.value = '0';
            }
        }
    }
    else
    {
            txtQuantity.value = '0';
    }
    txtPrice.value = formatCurrency(txtQuantity.value * lblPriceHdn.value);
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
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);
//return num;
}

function setAnchorURL(hypName,hypUrl) 
{
	if (document.all) 
	{
		var hyp = document.links(hypName);
	}
	else
	{
		var hyp = document.getElementById(hypName);
	}

	if (hyp != null)
	{
		hyp.href = hypUrl;
		hyp.disabled = (hypUrl == '' || hypUrl == null);
	}			
}

//function setCartLinks()
//{
//    setAnchorURL('hypCheckout','/storefront/shoppingcart.aspx')
//    setAnchorURL('hypShoppingCart','/storefront/shoppingcart.aspx')
//}