var currentProduct = ""; // the default starting product


function showSKUList(pccode,theImage) {
	var posx, posy, offsetx, offsety, boxH, boxW, theItem, theItemStyle, menuHeight, screenHeight, screenBottomOffset, maxScreenWidth;
	
	screenBottomOffset = 50;
	maxScreenWidth = 778;
	offsetx = -200;
	offsety = -115;

	posx = findPosX(theImage) + offsetx;
	posy = findPosY(theImage) + offsety;
	
	
	// TODO put in browser check here
	var f = document.getElementById("footer");
	var fPos = findPosY(f);
	

	// hide any visible sku list
	hideSKUList();
	var pcref = "pp_" + pccode;
	currentProduct = pcref;
	
	
	if(document.getElementById(pcref))
	{
		theItem = document.getElementById(pcref);
		theItemStyle = theItem.style;
	}
	else if (document.all) {
		if (document.all[pcref]){
			theItem = document.all[pcref];
			theItemStyle = theItem.style;
		}
	}
	else if (document.layers) 
	{
		if (document.layers[pcref]){		
			theItem = document.layers[pcref];
			theItemStyle = theItem;
		}
	}
	
	if (theItem)
	{
		menuHeight = 0;
		if(theItem.offsetHeight){ 
			menuHeight = theItem.offsetHeight;
		}
		else if(theItem.pixelHeight){ 
			menuHeight = theItem.pixelHeight;
		}
		
		
		theItemStyle.position = "absolute";
		
		if(posy + menuHeight > fPos + offsety - 20)
		{
			posy = posy - menuHeight - 16;
		}
		
		theItemStyle.top = posy;
		
		var menuWidth = parseInt(theItemStyle.width);
		
		if(posx + menuWidth > maxScreenWidth + offsetx)
		{
			posx = posx - menuWidth + 60;
		}
		
		theItemStyle.left = posx;
		
		theItemStyle.visibility = "visible";
	}

}

function hideSKUList(){
	if(document.getElementById(currentProduct))
	{
		(document.getElementById(currentProduct)).style.visibility = "hidden";
	}
	else if (document.all) {
		if (document.all[currentProduct]){
			document.all[currentProduct].style.visibility = "hidden";
		}
	}
	else if (document.layers) 
	{
		if (document.layers[currentProduct]){		
			document.layers[currentProduct].visibility = "hidden";
		}
	}
}


function OpenReferThis(sbj, page) 
{

	var url = '/recommendthis/index.php?sbj=' + sbj + "&page=" + page;
	newwin = open (url, 'popup', 'width=450,height=450,scrollbars=1'); 
	newwin.focus();

}

/* Show Pop Up Help Menu*/
function showHelp(field)
{
	newwin	= open ('/help/Manual.php?HelpID='+field+'', 'popup', 'width=450,height=400,scrollbars=1'); 
	newwin.focus();
}



function calcForm(pcCode,basePrice, fcPrice, isChecked,qty)
{
	alert("ff");
	return 0;
	var baseTotal;
	var fcTotal;
	var tbRef = "items_" + pcCode; 
	var qtyRef = "items[" + pcCode +"]"; 
	var cbxRef = "items_cbx_" + pcCode; 
	
	baseTotal = this.document.products.Total.value;
	fcTotal = this.document.products.AUDTotal.value;
	basePrice = currencyToNum(basePrice);
	fcPrice = currencyToNum(fcPrice);
	baseTotal = currencyToNum(baseTotal);
	fcTotal = currencyToNum(fcTotal);
	
	
	/*
	if(basePrice.indexOf('$')>=0)
		basePrice = basePrice.substring(basePrice.indexOf('$')+1);
		
	if(fcPrice.indexOf('$')>=0)
		fcPrice = fcPrice.substring(fcPrice.indexOf('$')+1);
		
	if(baseTotal.indexOf('$')>=0)
	{
		baseTotal = baseTotal.substring(baseTotal.indexOf('$')+1);
	}
	
	if(fcTotal.indexOf('$')>=0)
		fcTotal = fcTotal.substring(fcTotal.indexOf('$')+1);
	*/

	var myPrice = parseFloat(basePrice) * qty;
	var myFCPrice = parseFloat(fcPrice) * qty;
	//baseTotal = parseFloat(baseTotal);
	//fcTotal = parseFloat(fcTotal);
	fcTotal = Math.round(fcTotal*100)/100;
	
	myFCPrice = Math.round(myFCPrice*100)/100;
	
	if(isChecked == true)
	{
		if(this.document.products[qtyRef].value == 0 || qty > 1)
			this.document.products[qtyRef].value = qty;
			
		if(qty > 1)
		{
			
			this.document.products[tbRef].value = '$' + myPrice;
		}
		else
			this.document.products[tbRef].value = '$' + basePrice;

		
		baseTotal = baseTotal + myPrice;
		fcTotal = fcTotal + myFCPrice;
	}
	else
	{
		this.document.products[tbRef].value = '$0.00';
		this.document.products[qtyRef].value = 0;
		if(baseTotal > 0)
		{
			baseTotal = baseTotal - myPrice;
			if(baseTotal > 0)
			{
				fcTotal = fcTotal - myFCPrice;
				fcTotal = currencyToNum(fcTotal);
			}
			else
			{
				fcTotal = '0.00';
				baseTotal = '0.00';
			}
		}
		
	}
	
	if(qty > 0 && isChecked != false)
		this.document.products[cbxRef].checked = true;
	else
		this.document.products[cbxRef].checked = false;
	
	// add the totals
	
	this.document.products.Total.value = '$' + baseTotal;
	this.document.products.AUDTotal.value = '$' + fcTotal;
	
	if(baseTotal >0)
		this.document.products.Next.disabled = false;
	else
		this.document.products.Next.disabled = true;
		
}

function currencyToNum(amount)
{
	var items = new Array();
	amount = amount.toString();
	if(amount.indexOf('$')>=0)
		amount = amount.substring(amount.indexOf('$')+1);
	
	items = amount.split(",");
	amount = items.join("");

	amount = parseFloat(amount);
	amount = Math.round(amount*100)/100;
	
	if(amount.indexOf(".") > 0)
	{
		items = amount.split(".");
		var cents = parseInt(items[1]);
		
		if(cents >= 0 && cents < 10)
			amount = items[0] + "." + items[1] + "0";
		else
			amount = items[0] + "." + items[1];
	}
	else
		amount = amount + ".00";
	

	return amount;
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj && obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj && obj.y)
		curtop += obj.y;
	return curtop;
}

function clickHandler(){
	
	hideSKUList();
}

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function TestCookie(){

	SetCookie("accepttest",1,0);
	if(ReadCookie("accepttest")) {
		return 1;
	}else{
		return 0;
	}
}

function calculateshipping(){
	
	window.open('/calc_shipping.php','calcshipping','width=200,height=200');

}

function showProductDetailImage(theImage)
{
	if(document.plimg)
		document.plimg.src = "/productimages/" + theImage;
	
}

function resetProductDetailImage(){
	
}