﻿//var xhr;
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");};
function qtyKeyPress(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /\d/;
	return reg.test(keychar);
}

/*
function qtyKeyUp(e, control)
{
	xhr = createXhr();
	xhr.onreadystatechange = processQtyResponse;
	var cartid = document.getElementById("__cartid").value;
	var _pos = control.id.lastIndexOf("_");
	var sortorderStr = control.id.substr(_pos + 1, control.id.length - _pos);
	var sortorder = (+sortorderStr + 1).toString();
	xhr.open("GET", "cartUpdate.aspx?action=update&clientid=1001001&cartid=" + cartid + "&sortorder=" + sortorder + "&field=quantity&value=" + control.value);
	xhr.send(null);
}
*/

function descTextChanged()
{
	var xhr = createXhr();
	xhr.open("GET", "cartUpdate.aspx?action=update&clientid=1001001&cartDescription=" + document.getElementById("txtCartDesc").value + "&dts=" + (new Date()).toString());
	xhr.send(null);
	xhr.close;
}

function qtyTextChanged(control, sortorder)
{
	var qty = control.value.toString();
	if (qty === "0")
	{
		removeCartItem(sortorder);
		return;
	}

	var xhr = createXhr();
	xhr.onreadystatechange = processQtyTextChangeResponse;
	xhr.open("GET", "cartUpdate.aspx?action=update&clientid=1001001&sortorder=" + sortorder + "&field=quantity&value=" + control.value + "&dts=" + (new Date()).toString(), true);
	xhr.send(null);

	function processQtyTextChangeResponse()
	{
		var sortorder = 0;
		var appliedprice = 1;
		var applieddiscount = 2;
		var qty = 3;
		var linetotal = 4;
		var total = 0;
		var itemsQty = 0;
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText;
			xhr.close;
			var rows = data.split("~~~");
			for (var i = 0; i < rows.length - 2; i++)
			{
				var fields = rows[i].split("(;|;)");
				var ordinal = (fields[sortorder] - 1).toString();
				var priceCell = document.getElementById("price" + ordinal);
				priceCell.innerHTML = fields[appliedprice];
				var qtyBox = document.getElementById("txtQty_" + ordinal);
				qtyBox.value = fields[qty];
				var lnTotalCell = document.getElementById("lineTotal" + ordinal);
				lnTotalCell.innerHTML = fields[linetotal] + "&nbsp;&nbsp;";
			}

			document.getElementById("grandTotal").innerHTML = "$" + rows[rows.length - 2] + "&nbsp;&nbsp;";
			document.getElementById("linksBarTotal").innerHTML = "Total: $" + rows[rows.length - 2];
			document.getElementById("linksBarCount").innerHTML = "Items: " + rows[rows.length - 1]
		}
	}
}

function createXhr()
{
//	var xhr;
//	try
//	{
//		xhr = new ActiveXObject("Microsoft.XMLHTTP");
//	}
//	catch (e1)
//	{
//		xhr = false;
//	}
//	if (!xhr && typeof XMLHttpRequest != "undefined")
//	{
//		xhr = new XMLHttpRequest()
//	}
//	return xhr;

	var xhr = null;
	try
	{
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e1)
	{
		try
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e2)
		{
			xhr = false;
		}
	}
	if (!xhr && typeof XMLHttpRequest != "undefined")
	{
		xhr = new XMLHttpRequest()
	}
	return xhr;
}

function createXMLHttpRequest(){
    var xmlHttp = null;
    if(typeof XMLHttpRequest != "undefined"){
        xmlHttp = new XMLHttpRequest();
    }
    else if(typeof window.ActiveXObject != "undefined"){
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
        }
        catch(e){
            try {
                xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
            }
            catch(e){
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e){
                    xmlHttp = null;
                }
            }
        }
    }
    return xmlHttp;
}

function confirmRemove(item)
{
	item--;
	var itemId = "txtQty_" + item.toString();
	var qty = document.getElementById(itemId).value;
	var itemTitle = "title_" + item.toString();
	var title = document.getElementById(itemTitle).innerText;
	var msg = "";
	if (qty == "1" || qty == "0")
		msg = "Remove the item titled '" + title + "' from the shopping cart?";
	else if (qty == "2")
		msg = "Remove both items titled '" + title + "' from the shopping cart?";
	else
		msg = "Remove all " + qty + " items titled '" + title + "' from the shopping cart?";
	return confirm(msg);
}

function noteTextChanged(control, sortorder)
{
	var xhr = createXhr();
	xhr.open("GET", "cartUpdate.aspx?action=update&clientid=1001001&sortorder=" + sortorder + "&field=itemnote&value=" + control.value + "&dts=" + (new Date()).toString());
	xhr.send(null);
	xhr.close;
}

function removeCartItem(sortorder)
{
	if (!confirmRemove(sortorder))
		return;
	//window.location = "cartUpdate.aspx?action=remove&clientid=1001001&sortorder=" + sortorder;
		
	itemToBeRemoved = sortorder;
	while(tblCart.rows.length)
		tblCart.deleteRow(tblCart.rows.length - 1)
	var xhr = createXhr();
	xhr.onreadystatechange = processRemoveResponse;
	xhr.open("GET", "cartUpdate.aspx?action=remove&clientid=1001001&sortorder=" + sortorder + "&dts=" + (new Date()).toString());
	xhr.send(null);

	function processRemoveResponse()
	{
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText;
			xhr.close;
			document.mainForm.submit();
		}
	}
}

function dupeCartItem(sortorder)
{
	//window.location = "cartUpdate.aspx?action=duplicate&clientid=1001001&sortorder=" + sortorder;
	itemToBeDuped = sortorder;
	while(tblCart.rows.length)
		tblCart.deleteRow(tblCart.rows.length - 1)
	var xhr = createXhr();
	xhr.onreadystatechange = processDupeResponse;
	xhr.open("GET", "cartUpdate.aspx?action=duplicate&clientid=1001001&sortorder=" + sortorder + "&dts=" + (new Date()).toString());
	xhr.send(null);

	function processDupeResponse()
	{
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText;
			xhr.close;
			//var xhr = "";
			document.mainForm.submit();
		}
	}
}

/*
function getCartItemsByPmfid(pmfid)
{
	var xhr = createXhr();
	xhr.onreadystatechange = processQtyResponse;
	var cartid = document.getElementById("__cartid").value;
	var _pos = control.id.lastIndexOf("_");
	var sortorderStr = control.id.substr(_pos + 1, control.id.length - _pos);
	var sortorder = (+sortorderStr + 1).toString();
}
*/

function addToCart(pmfid, evt) {
	var clickX;
	var clickY;
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		clickX = window.event.clientX + document.documentElement.scrollLeft;
		clickY = window.event.clientY + document.documentElement.scrollTop;
	}
	else
	{
		clickX = evt.pageX;
		clickY = evt.pageY;
	}
	//var xhr = createXhr();
	if (xhr) xhr.abort();
	var nowDate = new Date();
	var xhr = createXMLHttpRequest();
	xhr.open("GET", "cartUpdate.aspx?action=add&clientid=1001001&pmfid=" + pmfid + "&dts=" + nowDate.toString());
	xhr.onreadystatechange = function() { processCartItemQueryResponse(clickX, clickY, pmfid); };
	xhr.send(null);
	
	function processCartItemQueryResponse(x, y, pmfid)
	{
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText;
			xhr.close;
			if (data.length !== null || data.trim() !== "")
			{
				var separator = ";";
				if (data.indexOf("~~~") > -1)
					separator = "~~~";
				var rows = data.split(separator);
				var title = rows[1];
				var cartid = rows.length > 2 ? rows[2] : "";
				var cookie = rows.length > 3 ? rows[3] : "";
				if (cookie.length > 0)
				{
					var now = new Date();
					var oneMinute = 60 * 1000  // milliseconds in a minute
					var oneHour = oneMinute * 60
					var oneDay = oneHour * 24
					var oneWeek = oneDay * 7
					var today = new Date()
					var dateInMS = today.getTime() + oneWeek * 27
					var targetDate = new Date(dateInMS)
					setCookie("tepcart", cookie, targetDate, "", "", false)
				}
				if (rows[0] == "added")
				{
					//addToCartById(pmfid);
					document.getElementById("linksBarTotal").innerHTML = "Total: $" + rows[rows.length - 2];
					document.getElementById("linksBarCount").innerHTML = "Items: " + rows[rows.length - 1]
					goToPage('cart.aspx');
					//alert('"' + title + '" was added to the shopping cart successfully.');
				}
				else
					returnItemChoice(data, x, y);
			}
			else
			{
				//addToCartById(pmfid);
				alert("This item could not be added at the present time");
			}
		}
	}
}

function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
					((expires) ? "; expires=" + expires.toUTCString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function addToCartById(pmfid)
{
	var xhr = createXhr();
	xhr.onreadystatechange = processAddToCartByIdResponse;
	xhr.open("GET", "cartUpdate.aspx?action=add&clientid=1001001&pmfid=" + pmfid + "&dts=" + (new Date()).toString());
	xhr.send(null);

	function processAddToCartByIdResponse()
	{
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText.split(";");
			xhr.close;
			var state = data[0];
			var title = data[1];
			
			document.getElementById("linksBarTotal").innerHTML = "Total: $" + data[data.length - 2];
			document.getElementById("linksBarCount").innerHTML = "Items: " + data[data.length - 1]
			
			if (state == "added")
				alert('"' + title + '" was added to the shopping cart successfully.');
			else
				alert('Failed to add "' + title + '" to the shopping cart at time.  Please try later.');
		}
	}
}

function returnItemChoice(data, x, y)
{
	var records = data.split("~~~");
	var popupDiv;
	if (document.getElementById("popupDiv") !== null)
		document.getElementById("popupDiv").parentNode.removeChild(document.getElementById("popupDiv"));
	popupDiv = document.createElement("div");
	popupDiv.setAttribute("id", "popupDiv");
	document.getElementById("mainForm").appendChild(popupDiv);
	popupDiv.style.position = "absolute";
	popupDiv.style.height = "120px";
	popupDiv.style.width = "451px";
	popupDiv.style.backgroundColor = "White";
	popupDiv.style.border = "solid 5px #5588DD";
	popupDiv.style.textAlign = "center";
	popupDiv.style.verticalAlign = "middle";
	popupDiv.style.fontSize = "9pt";
	popupDiv.setAttribute("onmousemove", "this.style.display='';");
	popupDiv.setAttribute("onmouseout", "this.style.display='none';");
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		popupDiv.attachEvent("onmousemove", function(){document.getElementById("popupDiv").style.display = "";});
		popupDiv.attachEvent("onmouseout", function(){document.getElementById("popupDiv").style.display = "none";});
	}
	var spanText = document.createElement("span");
	popupDiv.appendChild(spanText);
	spanText.style.position = "relative";
	spanText.style.top = "3px";
	spanText.style.cursor = "default";
	spanText.innerHTML = "<p style=\"position:relative; top:5px;\">Select into which line item do you want to add this title:</p>";
	popupDiv.style.display = "";
	var values;
	var lstSelect = document.createElement("select");
	lstSelect.id = "lstSelect";
	popupDiv.appendChild(lstSelect);
	lstSelect.style.width = "440px";
	var z = 0;
	for (var i = 0; i < records.length; i++)
	{
		values = records[i].split("(;|;)");
		var cnode = document.createElement("option");
		lstSelect.appendChild(cnode);
		cnode.value = values[0];
		cnode.style.fontFamily = "Monospace";
		cnode.style.fontSize = "9pt";
		values[1] = (values[1] == null || values[1] == "" ? "[No Description]" : values[1].substr(0, 50));
		values[1] += "                                                  ";
		values[1] = values[1].substring(0, 50);
		cnode.innerHTML = "Item: " + values[0] + " \"" + values[1] + "\" Qty: " + values[2] + " Line total: " + values[3];
		if (i == 0) cnode.setAttribute("selected", "");
		z++;
	}
	if (z > 3) z = 3;
	lstSelect.size = z;
	var useragent = navigator.userAgent.toLowerCase();
	if (navigator.userAgent.toLowerCase().indexOf("webkit") > -1)
		lstSelect.style.height = (z * 20) + "px";
	
	var divButtons = document.createElement("div");
	popupDiv.appendChild(divButtons);
	divButtons.style.position = "relative";
	divButtons.style.top = "10px";
	divButtons.style.TextAlign = "right";
	var btnOK = document.createElement("input");
	btnOK.id = "btnOK";
	btnOK.type = "button";
	btnOK.value = "OK";
	btnOK.style.width = "60px";
	divButtons.appendChild(btnOK);
	var btnCancel = document.createElement("input");
	btnCancel.id = "btnCancel";
	btnCancel.type = "button";
	btnCancel.value = "Cancel";
	if (navigator.userAgent.toLowerCase().indexOf("webkit") < 0)
	{
		btnOK.style.position = "relative";
		btnOK.style.left = "-20px";
	
		btnCancel.style.position = "relative";
		btnCancel.style.left = "-10px";
	}
	divButtons.appendChild(btnCancel);
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		btnOK.attachEvent("onclick", function(){dlgProcess(lstSelect.value);});
		btnCancel.attachEvent("onclick", function(){popupDiv.style.display = "none";});
	}
	else
	{
		btnOK.onclick = function (){dlgProcess(lstSelect.value);};
		btnCancel.onclick = function (){popupDiv.style.display='none';};
	}
	
	y -= 5;
	x -= 5;
	var divWidth = +popupDiv.style.width.replace("px", "");
	var divHeight = +popupDiv.style.height.replace("px", "");
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		x = ((x + divWidth) > document.body.offsetWidth ? document.body.offsetWidth - divWidth - 50 : x - 50);
		y = ((y + divHeight) > document.body.offsetHeight ? document.body.offsetHeight - divHeight - 50 : y - 50);
	}	
	else
	{
		x = ((x + divWidth) > window.innerWidth ? window.innerWidth - divWidth - 50 : x - 50);
		y = ((y + divHeight) > window.innerHeight ? window.innerHeight - divHeight - 50 : y - 50);
	}
	popupDiv.style.top = y + "px";
	popupDiv.style.left = x + "px";
}

function dlgProcess(sortorder)
{
	addToCartBySortOrder(sortorder);
	popupDiv.style.display = "none";
}

function addToCartBySortOrder(sortorder)
{
	var xhr = createXhr();
	xhr.onreadystatechange = processAddToCartBySortorderResponse;
	xhr.open("GET", "cartUpdate.aspx?action=add&clientid=1001001&sortorder=" + sortorder + "&dts=" + (new Date()).toString());
	xhr.send(null);

	function processAddToCartBySortorderResponse()
	{
		if (xhr.readyState == 4)
		{
			var data = xhr.responseText.split(";");
			xhr.close;
			var state = data[0];
			var title = data[1];
			if (state == "added")
			{
				document.getElementById("linksBarTotal").innerHTML = "Total: $" + data[data.length - 2];
				document.getElementById("linksBarCount").innerHTML = "Items: " + data[data.length - 1]
				goToPage('cart.aspx');
//				alert('"' + title + '" was added to the shopping cart successfully.');
			}
			else
				alert('Could not add "' + title + '" to the shopping cart at time.  Please try again later.');
		}
	}
}

function validateCheckoutInfo(evt)
{
	if (validateAccountInfo(evt, false))
		if (validatePurchaseInfo(evt))
			document.getElementById("mainForm").submit();
}

function checkout(evt)
{
	if (validatePurchaseInfo(evt))
		document.getElementById("mainForm").submit();
}

function validatePurchaseInfo(evt)
{
	var poExists = validateSchoolPO();
	var ccExists = creditCardExists();
	var errmsg = "";
	if (ccExists)
	{
		if (!isValidCCType())
			errmsg += "Invalid \"Credit Card Type\"<br/>";
		if (!isValidCCNumber())
			errmsg += "Invalid \"Credit Card Number\"<br/>";
		if (!isValidCCName())
			errmsg += "Invalid \"Name on Card\"<br/>";
		if (!isValidCCCVV())
			errmsg += "Invalid \"CVV\" number<br/>";
	}
	else
	{
		var ortype = document.getElementById("lstOrgType").value;
		if (ortype === "Individual")
		{
			errmsg += "This type of purchase requires a credit card";
		}
		else if (ortype === "Public School" || ortype === "School District")
		{
			if (!poExists)
			{
				errmsg += "This type of transaction requires<br/>";
				errmsg += "a purchase order and/or a credit card";
			}
		}
	}
	
	if (errmsg.length > 0)
	{
		var clickX;
		var clickY;
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			clickX = window.event.clientX + document.documentElement.scrollLeft;
			clickY = window.event.clientY + document.documentElement.scrollTop;
		}
		else
		{
			clickX = evt.pageX;
			clickY = evt.pageY;
		}
		cartmsgBox(errmsg, clickX, clickY);
		return false;
	}
	return true;
}

function validateSchoolPO(value)
{
	var poValue = document.getElementById("txtSchoolPO").value;
	if (poValue.trim() !== "")
	{
		return true;
	}
	return false;
}

function creditCardExists()
{
	var ccValue = document.getElementById("txtCardNumber").value;
	if (ccValue.trim() !== "")
	{
		return true;
	}
	return false;
}

function getCCType()
{
	if (document.getElementById("radVisa").checked)
		return "visa";
	if (document.getElementById("radMasterCard").checked)
		return "mc";
	if (document.getElementById("radAmex").checked)
		return "amex";
	else
		return "";
}

function isValidCCType()
{
	var ccType = getCCType();
	if (ccType.trim() !== "")
		return true;
	else
		return false;
}

function isValidCCNumber()
{
	var ccNumber = document.getElementById("txtCardNumber").value;
	if (isValidCC(getCCType(), ccNumber))
		return true;
	else
		return false;
}

function isValidCC(type, ccnum)
{
	// Remove all dashes and spaces for the checksum checks to eliminate negative numbers
	ccnum = ccnum.split("-").join("");
	ccnum = ccnum.split(" ").join("");
	if (type == "visa")
	{
		// Visa: length 16, prefix 4, dashes optional.
		var re = /^4\d{15}$/;
	}
	else if (type == "mc")
	{
		// Mastercard: length 16, prefix 51-55, dashes optional.
		var re = /^5[1-5]\d{14}$/;
	}
	else if (type == "amex")
	{
		// American Express: length 15, prefix 34 or 37.
		var re = /^3[4,7]\d{13}$/;
	}
	if (!re.test(ccnum))
		return false;
	// Checksum ("Mod 10")
	// Add even digits in even length strings or odd digits in odd length strings.
	var checksum = 0;
	for (var i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2)
	{
		checksum += parseInt(ccnum.charAt(i - 1));
	}
	// Analyze odd digits in even length strings or even digits in odd length strings.
	for (var i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2)
	{
		var digit = parseInt(ccnum.charAt(i - 1)) * 2;
		if (digit < 10)
		{
			checksum += digit;
		}
		else
		{
			checksum += (digit - 9);
		}
	}
	if ((checksum % 10) == 0)
		return true;
	else
		return false;
}

function isValidCCName()
{
	var re = /^[a-zA-Z]{1,}[ ][a-zA-Z ]{1,}/;
	if (re.test(document.getElementById("txtNameOnCard").value))
		return true;
	else
		return false;
}

function isValidCCCVV()
{
	var re = /\d{3,4}/;
	if (re.test(document.getElementById("txtCVV").value))
		return true;
	else
		return false;
}

function cartmsgBox(msg, x, y)
{
	var popupDiv;
	if (document.getElementById("popupDiv") !== null)
		document.getElementById("popupDiv").parentNode.removeChild(document.getElementById("popupDiv"));
	popupDiv = document.createElement("div");
	popupDiv.setAttribute("id", "popupDiv");
	document.getElementById("mainForm").appendChild(popupDiv);
	popupDiv.style.position = "absolute";
	var msgNoLineBreaks = msg;
	while (msgNoLineBreaks.indexOf("<br/>") > -1)
		msgNoLineBreaks = msgNoLineBreaks.replace("<br/>", "");
	popupDiv.style.height = (((((msg.length - msgNoLineBreaks.length) / 5) + 1) * 25) + 40) + "px";
	popupDiv.style.width = "351px";
	popupDiv.style.backgroundColor = "White";
	popupDiv.style.border = "solid 5px #5588DD";
	popupDiv.style.textAlign = "center";
	popupDiv.style.verticalAlign = "middle";
	popupDiv.style.fontSize = "9pt";
	popupDiv.setAttribute("onmousemove", "this.style.display='';");
	popupDiv.setAttribute("onmouseout", "this.style.display='none';");
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		popupDiv.attachEvent("onmousemove", function(){document.getElementById("popupDiv").style.display = "";});
		popupDiv.attachEvent("onmouseout", function(){document.getElementById("popupDiv").style.display = "none";});
	}
	var spanText = document.createElement("span");
	popupDiv.appendChild(spanText);
	spanText.style.position = "relative";
	spanText.style.top = "3px";
	spanText.style.cursor = "default";
	spanText.innerHTML = "<p style=\"position:relative; text-align:left; left:10px; top:5px;\">" + msg + "</p>";
	popupDiv.style.display = "";
	var divButtons = document.createElement("div");
	popupDiv.appendChild(divButtons);
	divButtons.style.position = "relative";
	divButtons.style.TextAlign = "right";
	divButtons.style.height = "20px";
	var btnOK = document.createElement("input");
	btnOK.id = "btnOK";
	btnOK.type = "button";
	btnOK.value = "OK";
	btnOK.style.width = "60px";
	divButtons.appendChild(btnOK);
	if (navigator.appName == "Microsoft Internet Explorer")
		btnOK.attachEvent("onclick", function(){popupDiv.style.display = 'none';});
	else
		btnOK.onclick = function(){popupDiv.style.display='none';};
	
	y -= 5;
	x -= 5;
	var divWidth = +popupDiv.style.width.replace("px", "");
	var divHeight = +popupDiv.style.height.replace("px", "");
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		x = ((x + divWidth) > document.body.offsetWidth ? document.body.offsetWidth - divWidth : x);
		y = ((y + divHeight) > document.body.offsetHeight ? document.body.offsetHeight - divHeight : y);
	}	
	else
	{
		x = ((x + divWidth + 20) > window.innerWidth ? window.innerWidth - divWidth - 20 : x);
		y = ((y + divHeight + 20) > window.innerHeight ? window.innerHeight - divHeight - 20 : y);
	}
	popupDiv.style.top = y + "px";
	popupDiv.style.left = x + "px";
}

function textboxSelectText(id)
{
	document.getElementById(id).select();
}

function shipMethodChanged(radButton)
{
	var cartTotal = +document.getElementById("hdnCartTotal").value
	if (radButton === document.getElementById("radGround"))
	{
		shipping = cartTotal * 0.08;
		if (shipping < 10)
			shipping = 10;
	}
	else if (radButton === document.getElementById("rad2Day"))
	{
		shipping = 30 + (cartTotal * 0.15);
	}
	else if (radButton === document.getElementById("radNextDay"))
	{
		shipping = 50 + (cartTotal * 0.25);
	}
	
	document.getElementById("spnShipping").innerHTML ="shipping: $" + CurrencyFormatted(shipping);
	document.getElementById("spnTotalCharge").innerHTML = "&nbsp;= $" + CurrencyFormatted(cartTotal + shipping);
	
	document.getElementById("spnShipping").style.color = "FFAA00";
	document.getElementById("spnTotalCharge").style.color = "FFAA00";
	
	setTimeout("setToBlack();", 2000);
}

function setToBlack()
{
	document.getElementById("spnShipping").style.color = "000000";
	document.getElementById("spnTotalCharge").style.color = "000000";
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

