// Created by Ben Turski
// 
// Add an Item to the shopping cart
function AddtoCart(addID){
	var ScreenWidth=window.screen.width;
	var ScreenHeight=window.screen.height;
	var movefromedge=0;
	
	placementx=movefromedge;
	placementy=movefromedge;
	var PopUpUrl='../data/addtocart.asp?Item='+addID;	

	// open the add to cart background window
	var WinPop = window.open(PopUpUrl,"","width=1,height=1,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");

	// set the opener handle
	if (!WinPop.opener) WinPop.opener = self;

	WinPop.window.blur();
	window.focus();
}

// Clear contents of shopCart Array
function ClearCart() {
	for(i=0;i<=shopCart.length-1;i++) shopCart[i] = {ProductCode: 'No', ProductID: '0', Quantity: '0', Price: '0.00'};
}

// Update the shopCart Array
function UpdateCart(ProdCode, Quantity, Price) {
	shopCart[shopCart.length] = {ProductCode: "'" + ProdCode + "'", Quantity: Quantity, Price: Price};
}

// Build the shopping cart - display items and total
function DisplayCart() {
	var sItems = document.getElementById("ShopItems");
	var sTotal = document.getElementById("SubTotal");
	var sInfo = document.getElementById("info");
	var cartItem;
	if(shopCart[0].ProductCode=='No') { 
		sItems.innerHTML = "&nbsp;";
		sTotal.innerHTML = "&nbsp;";
		sInfo.innerHTML = "No Products in Cart";
	} else {
		cartItem = "";
		for(i=0;i<=shopCart.length-1;i++) {
			cartItem = cartItem + shopCart[i].Quantity + "&nbsp;&nbsp;&nbsp;&nbsp; <a href='/products/details.asp?id=" + shopCart[i].ProductID + "'>#" + shopCart[i].ProductCode + "</a><br>";
		}
		sItems.innerHTML = cartItem + "<br>";
		sInfo.innerHTML = "";
		if(cartSubTotal=='' || cartSubTotal==0 || cartSubTotal=='0') cartSubTotal='0.00';
		sTotal.innerHTML = "Sub Total: $" + cartSubTotal;
	}
}


// Row highlighting for each product
function rowOvr(src,clrOver){ 
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'hand'; 
		src.bgColor = clrOver; 
	} 
} 

function rowOut(src,clrIn){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.bgColor = clrIn; 
	} 
} 

function mClk(src){ 
	if(event.srcElement.tagName=='TD')
		src.children.tags('A')[0].click();
}

function hideCart() {
	ShopCart1.style.visibility = 'hidden';
	ShopCart2.style.visibility = 'visible';
}

function showCart() {
	ShopCart2.style.visibility = 'hidden';
	ShopCart1.style.visibility = 'visible';
}

function showAddMessage() {
	alert('Item was successfully added to your shopping cart.');
}