var currentSlide = "wa"; // the default starting slide


function showSlide(theSlide) {
	
	var soref = "fpseelct_t_" + currentSlide;
	var snref = "fpseelct_t_" + theSlide;
	var boref = "fpselect_b_" + currentSlide;
	var bnref = "fpselect_b_" + theSlide;
	var loref = "fpselect_a_" + currentSlide;
	var lnref = "fpselect_a_" + theSlide;
	var obg = "#B0C3C8";
	var newbg = "#FCEDDB";
	var obrd = "1px #fff solid";
	var nbrd = "0px";
	currentSlide = theSlide;
	
	
	if(document.getElementById(soref))
	{
		if (document.getElementById(soref)){
			(document.getElementById(soref)).style.display = 'none';
		}
		if (document.getElementById(snref)){
			(document.getElementById(snref)).style.display = 'inline';
		}
		if (document.getElementById(boref)){
			(document.getElementById(boref)).style.background = obg;
			(document.getElementById(boref)).style.border = obrd;
		}
		if (document.getElementById(bnref)){
			(document.getElementById(bnref)).style.background = newbg;
			(document.getElementById(bnref)).style.border = nbrd;
		}
		if (document.getElementById(loref)){
			(document.getElementById(loref)).style.fontWeight = "normal";
		}
		if (document.getElementById(lnref)){
			(document.getElementById(lnref)).style.fontWeight = "bold";
		}
	}
	else if (document.all) {
		if (document.all[soref]){
			document.all[soref].style.display = 'none';
		}
		if (document.all[snref]){
			document.all[snref].style.display = 'inline';
		}
		
		if (document.all[boref]){
			document.all[boref].style.background = obg;
			document.all[boref].style.border = obrd;
		}
		if (document.all[bnref]){
			document.all[bnref].style.background = newbg;
			document.all[bnref].style.border = nbrd;
		}
		
		if (document.all[loref]){
			document.all[loref].style.fontWeight = "normal";
		}
		if (document.all[lnref]){
			document.all[lnref].style.fontWeight = "bold";
		}
	}
	else if (document.layers) 
	{
		if (document.layers[soref]){		
			document.layers[soref].display = "none";
		}
		
		if (document.layers[snref]){
				document.layers[snref].display = "inline";
		}
		
		if (document.layers[snref])
			document.layers[boref].style.background = obg;
		if (document.layers[bnref])	
			document.layers[bnref].style.background = newbg;
	}

}

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)
{
	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 = currencyToStr(myPrice);
		}
		else
			this.document.products[tbRef].value = currencyToStr(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 = currencyToStr(baseTotal);
	this.document.products.AUDTotal.value = currencyToStr(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("");
	
	if(amount.indexOf(".") > 0)
	{
		items = amount.split(".");
		var cents = parseInt(items[1]);
		
		if(cents >= 0 && cents < 10)
			amount = items[0] +".0" + items[1];
		else
			amount = items[0] + "." + items[1];
	}
	else
		amount = amount + ".00";
	
	amount = parseFloat(amount);
	amount = Math.round(amount*100)/100;
	return amount;
}

function currencyToStr(amount)
{
	var items = new Array();
	amount = amount.toString();
	var cents = 0;
	
	if(amount.indexOf(".") > 0)
	{
		items = amount.split(".");
		if(items[1])
			cents = parseInt(items[1]);
		
		if(cents < 10)
			amount = '$' + items[0] +".0"+ cents;
		else
			amount = '$' + items[0] + "." + cents;
	}
	else
		amount = '$' + amount + ".00";
	
	
	return amount;
}


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');

}