
	function replace(string, text, by) {
	  var strLength = string.length, txtLength = text.length;
	  if ((strLength == 0) || (txtLength == 0)) return string;

	  var i = string.indexOf(text);
	  if ((!i) && (text != string.substring(0,txtLength))) return string;
	  if (i == -1) return string;

	  var newstr = string.substring(0,i) + by;

	  if (i+txtLength < strLength)
	      newstr += replace(string.substring(i+txtLength,strLength),text,by);

	  return newstr;
	}
	

	// Rounds the number to the nearest cents
	function formatnumber(num){
		var	fnum=""+Math.floor(num);
		var i0=7-fnum.length;
		while (i0--){
		  fnum=" "+fnum;
		}
		var raps=Math.round(+num*100-Math.floor(+num)*100);
		//alert(raps);
		if (raps>=10) fnum+="."+raps;
		else fnum+=".0"+raps;
		return (fnum);
	}


	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 currencyformat(num) {
		return formatCurrency(num)
	}

	//submits the form
	function sbmt(action, ItemID) {
	    document.ShopCart.action = "cart.asp?action=" + action + "&ItemID=" + ItemID;
	    document.ShopCart.submit();
	}
		
	function updateQty(ItemID) {
		var formobj = document.forms["ShopCart"];
		var index = 0;
		while (formobj.elements[index]) {	
			if (formobj.elements[index].name == "q" + ItemID)	{
				var qty = formobj.elements[index].value;
				if (qty <= 0 || !isNum(qty))  {
					alert("Invalid Quantity, Please check and proceed again");
					return;
				}
			}
			index++;
		}
		sbmt("update", ItemID);
	}

	function isNum(str) {
		var digits="0123456789";
		var temp;
		var teststr = StripWhitespace(str);
		for (var i=0; i < teststr.length; i++) {
			temp = teststr.substring(i,i+1);
			if (digits.indexOf(temp)==-1) {
				return false;
			}
		}
		return true;
	}

	function StripWhitespace(str) {
		var temp;
		var newstring = "";
		for (var i=0; i < str.length; i++) {
		    temp = str.charAt(i);
			if (temp != " ") {
				newstring = newstring + temp;
			}
		}
		return newstring;
	}

