<!-- ----------------------------------------------------------------------------------
//
// Name: Cart.js 
//
// Author: GoldRam Systems. All rights reserved 2007.
//
// Description:	Shopping cart.
//		  
// Maintenance:
//
// Date			Developer			Modification
// --------   	------------------	----------------------------------------------
// 01/05/07		Dan Carlson			Initial version created.
//
//--------------------------------------------------------------------------------- -->

//-------------------------------------------------------------------------------------
// Attach events.
//-------------------------------------------------------------------------------------
window.onload = InitPage;

//-------------------------------------------------------------------------------------
// Module level variables.
//-------------------------------------------------------------------------------------

var mbTesting = true; //Use test site?

//var moMain = top.frames;
var moMain = window.parent.moMain;
var moThisDialog = parent.document.all.CartPopup;	

var msDiscount  = " 0.00";
var msTax	    = " 0.00";
var msShipState = "";
var miColoradoTaxRate = new Number(.029);

var msMode = "";
var mbCartChanged = false;
var mbSavePending = false;

var maCartItems = new Array();

var miOrderID = 0;

//Cart Item object.
function CartItem(sCode, sDesc, iQty, iCost, sUnit) {

	this.Code	= sCode;
	this.Desc	= sDesc;
	this.Qty	= iQty;
	this.Cost	= iCost;
	this.Unit	= sUnit;
	this.Total	= "$0.00";
}

//Checkout object.
function CartCheckoutObject() {

    this.Main = moMain;
    this.Cart = moMain.top.frames("CartPopup");
    this.CartSummary = document.all.CartSummary;
    this.Testing = mbTesting;
}

//-------------------------------------------------------------------------------------
// Calculate cart item total cost. 
//-------------------------------------------------------------------------------------
function CalcItemTotalCost(p) {

	var iCost = maCartItems[p].Cost;	
	var iQty = maCartItems[p].Qty;
	
	if (iCost.indexOf("$") == 0) iCost = iCost.substr(1);
	var iTotal = new Number(parseInt(iCost) * parseInt(iQty));
	
	return parent.FormatCurrency(iTotal);
}

//-------------------------------------------------------------------------------------
// Clear the error message box as long as there are no unfixed errors. 
//-------------------------------------------------------------------------------------
function CartClearErrorBox() {
	
	//Spin thru the line items and see if any are tagged with an error.
	for (var i=0; i<maCartItems.length; i++) {
		var oErrorTag = document.getElementById("ItemError" + i);
		if (oErrorTag.style.visibility == "visible") return;
	}
	
	//If we got this far, there are no other errors, so hide the error message box.
	CartError.style.visibility = "hidden";
	CartErrorText.innerText = "";
}	

//-------------------------------------------------------------------------------------
// Display cart items.
//-------------------------------------------------------------------------------------
function CartDisplayItems() {

	//Clear item list object.
	CartItems.innerHTML = "";
	
	//Build the list.
	var iTop = 0;
	var iItemCnt = 0;
	for (var p=0; p<maCartItems.length; p++) {
		//Insert container for a single cart item.
		var oItemBox = document.createElement("SPAN");	
		oItemBox.id = "ProdName" + p;
		oItemBox.className = "CartItemBox";
		oItemBox.style.left = "0px";
		oItemBox.style.top = iTop;
		oItemBox.style.width = CartItemsHdr.offsetWidth;
		oItemBox.style.height = "25px";
		CartItems.insertAdjacentElement("beforeEnd",oItemBox);
		
		//Insert Item Code.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemCode" + p;
		oItem.className = "CartItem";
		oItem.innerText = maCartItems[p].Code;
		oItem.style.left = ItemCodeHdr.offsetLeft;
		oItem.style.width = ItemCodeHdr.offsetWidth;
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item Description.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemDesc" + p;
		oItem.className = "CartItem";
		oItem.innerText = maCartItems[p].Desc;
		oItem.style.left = ItemDescHdr.offsetLeft;
		oItem.style.width = ItemDescHdr.offsetWidth;
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item remove action.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemRemove" + p;
		oItem.className = "CartItemAction";
		oItem.innerText = "remove";
		oItem.style.left = ItemQtyHdr.offsetLeft - 36;
		oItem.style.width = "26";
		oItem.setAttribute("Index", p);
		oItem.setAttribute("Code", maCartItems[p].Code);
		oItem.attachEvent("onmouseover",SetItemActionHilite);
		oItem.attachEvent("onmouseout",SetItemActionHilite);
		oItem.attachEvent("onclick",CartItemRemove);
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item Qty.
		var oItem = document.createElement("INPUT");	
		oItem.id = "ItemQty" + p;
		oItem.type = "text";
		oItem.maxLength = 4;
		oItem.className = "CartItemInput";
		oItem.value = maCartItems[p].Qty;
		oItem.style.left = ItemQtyHdr.offsetLeft + 8;
		oItem.style.width = "35px";
		oItem.setAttribute("Index", p);
		oItem.setAttribute("Code", maCartItems[p].Code);
		oItem.attachEvent("onkeyup",CartItemUpdateQty);
		//oItem.attachEvent("onblur",OnBlur_CartItemQty);
		oItem.attachEvent("onblur",CartItemValidateQty);
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item error indicator.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemError" + p;
		oItem.className = "CartItemError";
		oItem.innerText = "Error";
		oItem.style.left = ItemQtyHdr.offsetLeft + ItemQtyHdr.offsetWidth - 20;
		oItem.style.width = "26";
		oItem.setAttribute("Index", p);
		oItem.setAttribute("Code", maCartItems[p].Code);
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item Cost.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemCost" + p;
		oItem.className = "CartItemRight";
		var sUnit = (maCartItems[p].Unit == "Each") ? "ea" : maCartItems[p].Unit;
		oItem.innerText = maCartItems[p].Cost + " " + sUnit;
		oItem.style.left = ItemCostHdr.offsetLeft;
		oItem.style.width = ItemCostHdr.offsetWidth;
		oItem.setAttribute("Index", p);
		oItem.setAttribute("Code", maCartItems[p].Code);
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Insert Item Total Cost.
		var oItem = document.createElement("LABEL");	
		oItem.id = "ItemTotal" + p;
		oItem.className = "CartItemRight";
		//var iCost = maCartItems[p].Cost;
		//if (iCost.indexOf("$") == 0) iCost = iCost.substr(1);
		//var iTotal = new Number(parseInt(iCost) * parseInt(maCartItems[p].Qty));
		oItem.innerText = maCartItems[p].Total;
		oItem.style.left = ItemTotalHdr.offsetLeft;
		oItem.style.width = ItemTotalHdr.offsetWidth;
		oItem.setAttribute("Index", p);
		oItem.setAttribute("Code", maCartItems[p].Code);
		oItemBox.insertAdjacentElement("beforeEnd",oItem);
		
		//Adjust the width of the item's container.
		oItemBox.style.width = oItem.offsetLeft + oItem.offsetWidth + 1;
		
		//Increment item count.
		iItemCnt += parseInt(maCartItems[p].Qty);
				
		//Set top of next item.
		iTop += 24;
	} 
	
	//Update cart summary items.
	CartSummaryUpdate();
	
	//Update main window.
	if (msMode != "Checkout") moMain.MenuCartItems.innerText = iItemCnt + " items";
}

//-------------------------------------------------------------------------------------
// Creates a pipe delimited string of field-value pairings for all content in the cart.
// This string is then passed to the database server.
//-------------------------------------------------------------------------------------
function CartBuildContentString() {

	var sVal;
	var sFieldDelimiter = "|";
	var sRecordDelimiter = "::";
	
	var iCount = CartItems.children.length;
	
	var sItems = "";
	for(var i=0; i<maCartItems.length; i++) {
		sItems += "%ItemCode="	+ maCartItems[i].Code	+ sFieldDelimiter; 
		sItems += "%ItemDesc="	+ maCartItems[i].Desc	+ sFieldDelimiter; 
		sItems += "%ItemQty="	+ maCartItems[i].Qty	+ sFieldDelimiter; 
		sItems += "%ItemCost="	+ maCartItems[i].Cost	+ sFieldDelimiter; 
		sItems += "%ItemUnit="	+ maCartItems[i].Unit	+ sFieldDelimiter; 
		sItems += "%ItemTotal="	+ maCartItems[i].Total	+ sFieldDelimiter;
		sItems += sRecordDelimiter;
	}
		
	//Add cart summary values.
	sItems += "%Subtot=" + Subtot.innerText	+ sFieldDelimiter;
	sItems += "%Disc="	+ Disc.innerText	+ sFieldDelimiter;
	sItems += "%Ship="	+ Ship.innerText	+ sFieldDelimiter;
	sItems += "%Tax="	+ Tax.innerText		+ sFieldDelimiter;
	sItems += "%Total="	+ Total.innerText	+ sFieldDelimiter;
	
	//Return string.
	return sItems;
}

//-------------------------------------------------------------------------------------
// Initiate checkout process. 
//-------------------------------------------------------------------------------------
function CartInitCheckout() {

	var oSrc = event.srcElement;

	if (maCartItems.length == 0) {
		alert("There are no items in your cart");
		return;
	}

	//Display status message.
	CartStatus.style.visibility = "visible";
	CartStatusText.innerText = "Proceeding to checkout...";
	CartStatus.style.left = oSrc.offsetLeft - 240;
	CartStatus.style.top  = oSrc.parentElement.offsetTop - 40;
	
	//Save cart contents to database and when done, open checkout window. If no changes
	//to the cart, then go directly to the Checkout dialog.
	if (mbSavePending) {
		CartSaveToDB(true);
	}
	else {
		ShowCheckoutDialog();
	}
}

//-------------------------------------------------------------------------------------
// Add item to cart. 
//-------------------------------------------------------------------------------------
function CartItemAdd(sCode, sDesc, iQty, iCost, sUnit) {
	
	//See if item is already in the cart. If so, increment the quantity, update the 
	//total, and then get outta here.
	var iItemCnt = 0;
	var bFound = false;
	for (var i=0; i<maCartItems.length; i++) {
		if (maCartItems[i].Code == sCode) {
			maCartItems[i].Qty += iQty;
			maCartItems[i].Total = CalcItemTotalCost(i);
			bFound = true;
		}
		iItemCnt += parseInt(maCartItems[i].Qty);
	}
	
	//Add item to cart;
	if (!bFound) {
		maCartItems.push(new CartItem(sCode, sDesc, iQty, iCost, sUnit));
		var p = maCartItems.length-1;
		maCartItems[p].Total = CalcItemTotalCost(p);
		iItemCnt += parseInt(iQty);
	}
	
	//Update main window.
	if (msMode != "Checkout") moMain.MenuCartItems.innerText = iItemCnt + " items";
	
	//Set flag to indicate a SAVE action is pending.
	mbSavePending = true;
}

//-------------------------------------------------------------------------------------
// Remove item from cart. 
//-------------------------------------------------------------------------------------
function CartItemRemove() {

	var sCode = event.srcElement.getAttribute("Code");
	
	//Find the item in the array and remove it.
	for (var i=0; i<maCartItems.length; i++) {
		if (maCartItems[i].Code == sCode) {
			if (i == 0) {
				maCartItems = maCartItems.slice(1);
			}
			else if (i == (maCartItems.length -1)) {
				maCartItems = maCartItems.slice(0, i);
			}
			else {
				var aSlice1 = new Array();
				var aSlice2 = new Array();
				aSlice1 = maCartItems.slice(0, i);
				aSlice2 = maCartItems.slice(i+1);
				maCartItems.length = 0;
				maCartItems = maCartItems.concat(aSlice1, aSlice2);
			}
		}
	}
			
	//Rebuild list of cart items.	
	CartDisplayItems();
			
	//Make sure previous error message is not displayed.	
	CartClearErrorBox();
	
	//Set flag to indicate a SAVE action is pending.
	mbSavePending = true;
}

//-------------------------------------------------------------------------------------
// Update line item's quantity and then update the line item's total cost. 
//-------------------------------------------------------------------------------------
function CartItemUpdateQty() {

	var oSrc = event.srcElement;
	var sCode = oSrc.getAttribute("Code");
	
	//Find the item in the array and update it.
	for (var i=0; i<maCartItems.length; i++) {
		if (maCartItems[i].Code == sCode) {
			var iQty = parseInt(oSrc.value);
			
			//If not numeric, get outta here.
			if (isNaN(iQty)) return;
			
			//Make sure error tag and related message text is not displayed.
			document.getElementById("ItemError" + i).style.visibility = "hidden";
			CartClearErrorBox();
			
			//Update total cost for line item.
			maCartItems[i].Qty = iQty;
			var iCost = maCartItems[i].Cost;
			if (iCost.indexOf("$") == 0) iCost = iCost.substr(1);
			var iTotal = new Number(parseInt(iCost) * parseInt(iQty));
			maCartItems[i].Total = parent.FormatCurrency(iTotal);
			document.getElementById("ItemTotal" + i).innerText = maCartItems[i].Total;
		}
	}
	
	//Update cart summary.
	CartSummaryUpdate();
	
	//Set flag to indicate a SAVE action is pending.
	mbSavePending = true;

}

//-------------------------------------------------------------------------------------
// Validate line item Quantity entered by user. 
//-------------------------------------------------------------------------------------
function CartItemValidateQty() {

	var oSrc = event.srcElement;
	var sCode = oSrc.getAttribute("Code");
	
	var bValid = true;
	
	var iQty = parseInt(oSrc.value);
	if (isNaN(iQty)) {
		bValid = false;
		var sIndex = oSrc.getAttribute("Index");
		DisplayCartQtyError(sIndex);
	}
			
	//Return result.	
	return bValid;
}

//-------------------------------------------------------------------------------------
// Submits SQL statement to retrieve cart contents from the database.
//-------------------------------------------------------------------------------------
function CartLoadFromDB() {

	var fa = dbCart.document.all;

	//Display status message.
	CartStatus.style.visibility = "visible";
	CartStatusText.innerText = "Retrieving cart...";
	CartStatus.style.left = 80;
	CartStatus.style.top  = 60;
    		
	//Start building SQL statement.
	var oSQL = new parent.SQL();
	oSQL.stmt = "qryCartLoad";
	parent.BuildSQL(oSQL, "@OrderID", miOrderID, true);

	//Trim the last comma from the SQL code string.
	oSQL.stmt = oSQL.stmt.substr(0,oSQL.stmt.length - 2); 
		
	//Submit SQL statement to the server.
	fa.UseCustomCOM.value = "N";
	fa.Database.value = "";
	fa.ReturnData.value = "Y";
	fa.Callback.value = "window.parent.OnCartLoaded()";
	fa.SQL.value = oSQL.stmt;
	fa.ErrorMsg.value = "Unable to retrieve shopping cart.";
	fa.frmDB.submit();
}

//-------------------------------------------------------------------------------------
// Submits SQL statement to save cart contents to the database.
//-------------------------------------------------------------------------------------
function CartSaveToDB(bDoCheckout) {

	var fa = dbCart.document.all;

	//Display status message. Only do this if not proceeding to Checkout afterwards.
	if (!bDoCheckout) {
		CartStatus.style.visibility = "visible";
		CartStatusText.innerText = "Saving cart...";
		CartStatus.style.left = 80;
		CartStatus.style.top  = 60;
	}
			
	//Get current date and time.
	var dt = new Date();
	var sDateTime = (dt.getMonth()+ 1) + "/" + dt.getDate()+ "/" +  dt.getFullYear();
	sDateTime += " " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
    		
    //Get the cart contents in the form of a field-value paired string.
    var sCartContents = CartBuildContentString();
    		
	//Start building SQL statement.
	var oSQL = new parent.SQL();
	oSQL.stmt = "qryCartSave";
	parent.BuildSQL(oSQL, "@CustomerID", 1, true);
	parent.BuildSQL(oSQL, "@OrderID", miOrderID, true);
	parent.BuildSQL(oSQL, "@Date", sDateTime);
	parent.BuildSQL(oSQL, "@CartContents", sCartContents);

	//Trim the last comma from the SQL code string.
	oSQL.stmt = oSQL.stmt.substr(0,oSQL.stmt.length - 2); 
		
	//Submit SQL statement to the server.
	fa.UseCustomCOM.value = "N";
	fa.Database.value = "";
	fa.ReturnData.value = "Y";
	fa.Callback.value = (bDoCheckout) ? "window.parent.OnCartSaved(true)" : "window.parent.OnCartSaved(false)" ;
	fa.SQL.value = oSQL.stmt;
	fa.ErrorMsg.value = "Unable to save shopping cart.";
	fa.frmDB.submit();
}

//-------------------------------------------------------------------------------------
// Update cart's summary items. 
//-------------------------------------------------------------------------------------
function CartSummaryUpdate() {

	var iItemTotal = new Number(0);
	var iSubtotal = new Number(0);
	
	//Get the subtotal.
	for (var i=0; i<maCartItems.length; i++) {
		var iQty  = parseInt(maCartItems[i].Qty);
		var iCost = maCartItems[i].Cost;
		
		//Remove $-sign from cost.
		if (iCost.indexOf("$") == 0) iCost = iCost.substr(1);
				
		//If Qty not numeric, display error and get outta here.
		if (isNaN(iQty)) {
			DisplayCartQtyError(i);
			return;
		}
		
		iSubtotal += parseInt(iCost) * iQty;
	}
	
	//Display subtotal.
	Subtot.innerText = parent.FormatCurrency(iSubtotal);
	
	//Display discount.
	var iDiscount = new Number(parseInt(msDiscount));
	Disc.innerText = parent.FormatCurrency(iDiscount);
	
	//Display shipping charge, based on Subtotal less any discount.
	var iSubtotWithDisc = iSubtotal - iDiscount;
	if ((iSubtotWithDisc > 0) && (iSubtotWithDisc < 50)) {
		var iShipping = new Number(8);
	}
	else if ((iSubtotWithDisc >= 50) && (iSubtotWithDisc <= 100)) {
		var iShipping = new Number(25);
	}
	else if ((iSubtotWithDisc >= 101) && (iSubtotWithDisc <= 500)) {
		var iShipping = new Number(75);
	}
	else if ((iSubtotWithDisc >= 501) && (iSubtotWithDisc <= 1000)) {
		var iShipping = new Number(100);
	}
	else { 
		var iShipping = new Number(0);
	}
	ShipHdr.innerText = (iShipping == 0) ? "FREE Shipping:" : "Shipping:";
	Ship.innerText = parent.FormatCurrency(iShipping);
	
	//Display tax.
	if (msShipState == "CO") {
		var iTax = new Number(miColoradoTaxRate * (iSubtotWithDisc));
	}
	else {
		var iTax = new Number(0);
	}
	Tax.innerText = parent.FormatCurrency(iTax);
	
	//Display Total.
	var iTotal = new Number(iSubtotal - iDiscount) + iShipping + iTax;
	Total.innerText = parent.FormatCurrency(iTotal);
		
	//If this cart is "owned" by the Checkout dialog, update the summary items displayed in 
	//the Checkout window.
	if (msMode == "Checkout") parent.ShowCartSummary();
	//	window.parent.Subtot.innerText = Subtot.innerText;
	//	window.parent.Disc.innerText = Disc.innerText;
	//	window.parent.Ship.innerText = Ship.innerText;
	//	window.parent.Tax.innerText = Tax.innerText;
	//	window.parent.Total.innerText = Total.innerText;
	//}
	
}

//-------------------------------------------------------------------------------------
// Close the dialog. 
//-------------------------------------------------------------------------------------
function Close(oOtherDialog) {
	
	//If in Checkout mode and changes have been made to the cart contents, save cart 
	//contents to database.
	if ((mbSavePending) && (msMode == "Checkout")) CartSaveToDB(false);
	
	//Hide this dialog.
	Hide();
	
	//If requested, close related dialog.
	if (oOtherDialog) oOtherDialog.Close();
}

//-------------------------------------------------------------------------------------
// Display error related to line item Quantity value entered by user. 
//-------------------------------------------------------------------------------------
function DisplayCartQtyError(sIndex) {

	var oErrorTag = document.getElementById("ItemError" + sIndex);
	oErrorTag.style.visibility = "visible";
	CartErrorText.innerText = "Quantity must be numeric. Please correct this before proceeding with checkout."
	CartError.style.visibility = "visible";
}

//-------------------------------------------------------------------------------------
// Hide the dialog (inline frame). Make sure any events attached to the parent
// are detached. 
//-------------------------------------------------------------------------------------
function Hide() {

	//Hide status.
	CartStatus.style.visibility = "hidden";

    //Hide the inline frame.
	moThisDialog.style.visibility = "hidden";
	
	//If changes have been made, save cart to the database.
	
	
	//if (msMode == "Checkout") parent.SyncCarts();
	
	//***TO DO*** Hide Cloaking object.
}

//-------------------------------------------------------------------------------------
// Initializes the page, fires immediately after the browser loads page. 
//-------------------------------------------------------------------------------------
function InitPage() {

	//See if running from the Checkout dialog. If so, get OrderID/CartID from parent
	//and load the cart from the database.
	try {
		miOrderID = parent.OrderID.innerText;
		msMode = "Checkout";
		CartLoadFromDB();
	}
	catch(e) {
		//do nothing
	}
}

//-------------------------------------------------------------------------------------
// Perform actions after the cart item quantity field loses focus. 
//-------------------------------------------------------------------------------------
function OnBlur_CartItemQty() {

	CartItemValidateQty(event.srcElement);
}	

//-------------------------------------------------------------------------------------
// Called when cart data has been retrieved from the database.
//-------------------------------------------------------------------------------------
function OnCartLoaded() {

	//Check for error.
	if (dbCart.Error()) {
		CartStatus.style.visibility = "hidden";
		return;
	}
	
	//Hide status message.
	CartStatus.style.visibility = "hidden";

	//Get reference to XMLDOMNodeList.
	var oResults = dbCart.DataNodeList();
    
    //If no data, get outta here.
	if (oResults.length == 0) return;

	//Build array to display cart items.
	var iItemCnt = 0;
	for (var i=0; i<oResults.length; i++) {
		var sCode = oResults.item(i).getAttribute("ItemCode");
		var sDesc = oResults.item(i).getAttribute("ItemDesc");
		var sQty  = oResults.item(i).getAttribute("ItemQty");
		var sCost = oResults.item(i).getAttribute("ItemCost");
		var sUnit = oResults.item(i).getAttribute("ItemUnit");
		var sTotal = oResults.item(i).getAttribute("ItemTotal");
		maCartItems.push(new CartItem(sCode, sDesc, sQty, sCost, sUnit));
		maCartItems[i].Total = CalcItemTotalCost(i);
		iItemCnt += parseInt(sQty);
	}
	
	//Update main window Checkout status.
	if (msMode != "Checkout") moMain.MenuCartItems.innerText = iItemCnt + " items";

	//Update cart summary.
	CartSummaryUpdate();
}

//-------------------------------------------------------------------------------------
// Called when data has been returned.
//-------------------------------------------------------------------------------------
function OnCartSaved(bDoCheckout) {

	//Check for error.
	if (dbCart.Error()) {
		CartStatus.style.visibility = "hidden";
		return;
	}
	
	//Hide status message.
	CartStatus.style.visibility = "hidden";

	//Get reference to XMLDOMNodeList.
	var oResults = dbCart.DataNodeList();
    
    //If no data, get outta here.
	if (oResults.length == 0) return;
	
	//Get Order ID.
	miOrderID = oResults.item(0).getAttribute("OrderID");
	
	mbSavePending = false;
	mbCartChanged = true;
	
	if (bDoCheckout) ShowCheckoutDialog();
}

//-------------------------------------------------------------------------------------
// Hilites a footer action link.
//-------------------------------------------------------------------------------------
function SetFooterActionHilite() {

	with (event.srcElement) {
		if (event.type == "mouseover") {
		    style.color = "yellow";
		}    
		else {
		    style.color = 'rgb(227,222,238)';
		    style.color = "white";
		}    
    }		    
}

//-------------------------------------------------------------------------------------
// Hilites an item action link.
//-------------------------------------------------------------------------------------
function SetItemActionHilite() {

	with (event.srcElement) {
		if (event.type == "mouseover") {
		    style.color = "orange";
		}    
		else {
		    style.color = "blue";
		}    
    }		    
}

//-------------------------------------------------------------------------------------
// Display popup. 
//-------------------------------------------------------------------------------------
function Show(sLeft, sTop, sWidth, sHeight) {
	
	//SetMovable(true);
	
	//Make sure previous error message is not displayed.
	CartError.style.visibility = "hidden";
	CartErrorText.innerText = "";
	
	//Display cart items.	
	CartDisplayItems();
		
	//If displaying cart during checkout, only display a "Close" button.
	if (msMode == "Checkout") {
		CartClose.innerText = "Close Cart";
		CartClose.style.left = "+680px";
		CartCheckout.style.visibility = "hidden";
	}
	
    //Set position and size.
    moThisDialog.style.left = sLeft;
    moThisDialog.style.top = sTop;

	//If requested, set overall dimensions of the content.
	//if (sWidth != null) TitleBar.style.width = sWidth;
	//if (sHeight != null) DetailBox.style.height = sHeight;
	
	//Adjust height to prevent display of scrollbar.
	//var iDiff = DetailBox.scrollHeight - DetailBox.offsetHeight;
	//if (iDiff > 0) DetailBox.style.height = DetailBox.offsetHeight + iDiff + 20;
	
	//Adjust frame object's dimensions to accommodate content.
    moThisDialog.style.height = Cart.offsetHeight - 2;
    moThisDialog.style.width = Cart.offsetWidth;

	//Show it.
	moThisDialog.style.visibility = "visible";
}

//-------------------------------------------------------------------------------------
// Displays dialog for processing order checkout.
//-------------------------------------------------------------------------------------
function ShowCheckoutDialog() {

	//Hide the cart.
	Hide();
    
    //var oArgs = new CartCheckoutObject();
   
    //Read cookie to determine the position of the dialog as it was last displayed. 
    //var sCookieName = "Checkout.dialogPos";
    //var sPos = moMain.ReadCookie(document.cookie, sCookieName, "");

	//Set dialog attributes.
    //var sOptions = "";
    //if (sPos.length) {
    //    var aPos = sPos.split("|");
    //    sOptions  = "dialogLeft:" + aPos[0] + "px;";
    //    sOptions += "dialogTop:" + aPos[1] + "px;";
    //    sOptions += "dialogHeight:" + aPos[2] + ";";
    //    sOptions += "dialogWidth:" + aPos[3] + ";";
    //    sOptions += "center:no;status:yes;help:no;scroll:yes;resizable:yes;";
    //}
    //else {
    	sOptions = "dialogHeight:732px;dialogWidth:982px;center:yes;status:yes;help:no;scroll:yes;resizable:yes;";
	//}

	//Display Checkout dialog.
	if (window.location.hostname.indexOf("www") >= 0) {
		if (window.location.pathname.indexOf("/test/") == 0) {
			sURL = "https" + "://www.grand-majestic-images.com/test/Checkout.asp"; //Test site
		}
		else {
			sURL = "https" + "://www.grand-majestic-images.com/Checkout.asp"; //Production site
		}
	}
	else {
		sURL = "Checkout.asp"; //Local development web server
	}
	//var sQueryString = "?URL=" + sURL;
	//sQueryString += "&OrderID=" + miOrderID;
	//***GoldRam Note*** Not sure this redirect is necessary. May have been needed at one point in time.
	//var iResult = window.showModalDialog("CheckoutRedirect.asp" + sQueryString,null,sOptions);
	
	sURL += "?OrderID=" + miOrderID;
	var iResult = window.showModalDialog(sURL,null,sOptions);
    
    //Read cookie to determine the position of the dialog as it was last displayed. The
    //name of the cookie is based on the task action.
    //NOTE: Using the value returned from showModalDialog will not work in a mixed protocol (HTTP and HTTPS)
    //due to changes in security in IE. So had to resort to using cookies which appears to work just fine.
    var sCookieName = "Checkout.Result";
    var sResult = moMain.ReadCookie(document.cookie, sCookieName, "");
    iResult = parseInt(sResult);
	
	//If cart contents changed, retrieve updated cart contents from database. If the order went
	//thru successfully, clear the cart contents.
	if (iResult > 0) {
		//Clear cart contents.
		maCartItems = new Array();;
			
		//Update main window.
		if (msMode != "Checkout") moMain.MenuCartItems.innerText = "0 items";
		
		//If the order was placed successfully, reset the Order ID;
		if (iResult == 2) miOrderID = 0;
		
		//If changes were made to the cart, but the order was not placed, reload the cart from
		//the database.
		if (iResult == 1) CartLoadFromDB();
	}
}
-->