var nItemsCnt=Number(0);
var ShoppingCart=new Object;

function CShoppingCart(name,description,price,sku,cartnb)
{	// constructor for a CShoppingCart object
	this.ItemName=name;
	this.Description=description;
	this.Price=price;
	this.Sku=sku; // SKU = Stock Keeping Unit
	this.CartNb=cartnb;

	this.display=showItem; //method
	return this;
}

function getCartId()
{
	var nCart = new Number();
	var sCart = new String();
	var sCartId = new String();
	sCartId = '';
	var dtNow = new Date();
	var nSeed = dtNow.getTime(); 
	var luvCookies = new String();
	myCookies = document.cookie.split('; ');
	if (myCookies.length <= 0)
	{
		return sCartId;
	}
	for (i=0; i < myCookies.length;i++)
	{
		if ('cart_id' == myCookies[i].split('=')[0])
		{
			sCartId = myCookies[i].split('=')[1];
			break;
		}
	}
	if (sCartId.length > 0)
	{
		document.myForm.cart_id.value = sCartId;
		return sCartId;
	}
	// no cart_id cookie: create one...
	nCart = Math.random(nSeed) * 100000000000;
	var sCart = nCart.toString();
	var sCart1 = sCart.substr(0,7);
	var sCart2 = sCart.substr(sCart.length - 4,4);
	var sCartId = sCart1 + "." + sCart2;
	var dtThen = new Date(dtNow.getTime() + (1000 * 120));
	document.cookie = "cart_id=" + sCartId 
					+ "; expires=" + dtThen;
//////////////		+ " domain="  + "www.fifiluv.com";
	document.myForm.cart_id.value = sCartId;
	return sCartId;
}


function writeCartIdToForm()
{
	var myCartId = new String();
	myCartId = getCartId();
	if (myCartId.length > 0)
	{
		document.myForm.cart_id.value = myCartId;
		return true;
	}
	document.myForm.cart_id.value = '';
	return true;
}

function addToCart(name,description,price,sku,cartnb)
{	// put a new cart item into the cart array.
	ShoppingCart[nItemsCnt]=new CShoppingCart(name,description,price,sku,cartnb);
	nItemsCnt++;
	alert(name + '(' + sku + ')' + '\n has been added to your shopping cart' + '\n items=' + nItemsCnt.toString());
	return;
}

function ImageWindow(ImgFileName)
{
	var imgWindowProperties = new String();
	imgWindowProperties = "resizeable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes";
	window.open(ImgFileName,"ImgLarge", imgWindowProperties);
				
}

function showProductPage(urlImage,name,description,price,sku,cartnb,keywords,itemString)
{
	var wndProperties = new String();
	wndProperties = "resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,dependent=yes,width=1000,height=650,innerWidth=1000,innerHeight=650,outerWidth=1200,outerHeight=700";
	var ProductPage = window.open('','ProductPage', wndProperties);
	if (keywords < ' ')
	{
		keywords="lingerie";
	}
	with (ProductPage.document)
	{
		writeln("<HTML><HEAD>"
				+ "<SCRIPT language='JavaScript' src='http://www.fifiluv.com/ShoppingCart.js'></script>"
				+ "</HEAD>"
				+ "<BODY width='900' bgcolor='white'>"
				);
		writeln("<DIV id='itemForm'>");
		writeln("<STYLE>");
		writeln("P {font-size: 8pt; font-family: Tahoma, sans-serif; font-weight: bold} ");
		writeln("h3 {font-size: 10pt; font-family: Tahoma, sans-serif} ");
		writeln("td {font-size: 8pt; font-family: Tahoma, sans-serif; font-weight: bold} ");
		writeln("</STYLE>");
		writeln("<FORM action='http://www.fifiluv.com/cgi/store/commerce.cgi' method='post' name='OrderForm' align='center'>");

		writeln("<TABLE COLS='2' WIDTH='900' align='center' BGCOLOR='white' BORDER='0' CELLPADDING='0' CELLSPACING='4'>");
		writeln("<TR>");
		writeln("<TD WIDTH='475' ALIGN='LEFT' VALIGN='TOP'>");

		writeln("<IMG WIDTH='450' HEIGHT='563' SRC='" + urlImage + "'>" 
				+ "</TD>"
				);

		writeln("<TD WIDTH='400' ALIGN='CENTER'>"
				+ "<IMG SRC='http://www.fifiluv.com/images/fifiluvLogo.gif' WIDTH='230' HEIGHT='130' >"
				);

		writeln("<h3>" + name + "</h3>");
		writeln("<font color='blue'>Price: " + price + "</font>");
		writeln("&nbsp&nbsp&nbsp&nbsp&nbsp SKU #: " + sku + "<BR>");
		writeln("<P ALIGN='LEFT'>" + description + "</P>");
		// table within the cell:
		writeln("<TABLE COLS='3' WIDTH='50%' align='left' BGCOLOR='white' BORDER='0' CELLPADDING='2' CELLSPACING='10'>");
		writeln("<TR>"
				+ "<TD COLSPAN='3'><INPUT TYPE='TEXT' NAME='" + itemString + " ' VALUE='1' MAXLENGTH='3' SIZE='3'>(Quantity)"
				+ "</TD>");
		writeln("</TR>");
		writeln("<TR></TR>");
		writeln("<TR><TD COLSPAN='3'>"); listSizes(ProductPage.document); writeln("</TD></TR>");
		writeln("<TR></TR>");
		writeln("<TR><TD COLSPAN='3'>"); listColors(ProductPage.document); writeln("</TD></TR>");
		writeln("<TR></TR>");
		writeln("<TR>");
		writeln("<TD><INPUT TYPE='IMAGE' NAME='add_to_cart_button' VALUE='Add To Cart' SRC='http://www.fifiluv.com/images/add_to_cart.gif' BORDER='0'> " 
//				+ "onClick=\"addToCart(" + "'" + name + "'," + "'" + description + "'," + "'" + price + "'," + "'" + sku + "'," + "'" + cartnb + "'" + ")\">"
				+ "</TD>"
				);
		writeln("</TR>");
		writeln("<TR></TR>");
		writeln("<TR>");
		writeln("<TD>");
		writeln("<A HREF='http://www.fifiluv.com/cgi/store/commerce.cgi?add_to_cart_button.x=yes"
				+ "&product=" + sku
				+ "&cart_id=" + cartnb 
				+ "&keywords=" + keywords
				+ "&viewOrder=yes'>"
				+ "<FONT FACE='TAHOMA,VERDANA,HELVETICA,ARIAL' SIZE='1'>"
				+ "<b>View Cart</b></FONT>"
				+ "</A>"
				);
		writeln("</TD>");
		writeln("</TR>");
		writeln("<TR></TR>");

		writeln("<TR>");
		writeln("<TD colspan='3'>");
		writeln("<P>Cart#: " + cartnb + "</P>");
		writeln("<br><INPUT TYPE='hidden' NAME='cart_id' VALUE='" + cartnb + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='product' VALUE='" + sku + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='keywords' VALUE='" + keywords + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='viewOrder' VALUE='yes'>");
		writeln("</TD>");
		writeln("</TR>");

		writeln("</TABLE>"); 
		// end of cell table
		writeln("</TD>"); //end of cell

		writeln("</TR>");
		writeln("</TABLE></FORM>");
		writeln("</DIV>");
		writeln("</BODY></HTML>");
	}
}

function getProductDetailForm(name,description,price,sku,cartnb,keywords)
{
	var htmlForm = new String();
	htmlForm = 
	"<FORM METHOD='post' ACTION='" + "http://www.fifiluv.com/cgi/store/commerce.cgi" + "' NAME='OrderForm'>"
	+ "\n<TABLE WIDTH='800' align='center' BGCOLOR='white' BORDER='0' CELLPADDING='0' CELLSPACING='9'>"
	+ "\n<TR WIDTH='100%'><TD COLSPAN = '3'><HR></TD></TR>"
	+ "\n<TR WIDTH='100%' CELLSPACING='2' CELLPADDING='2'>" 
	+ "\n<TD WIDTH='10%' ALIGN='LEFT' VALIGN='MIDDLE'>"
	+ "\n	<FONT FACE='TAHOMA,VERDANA,HELVETICA,ARIAL' SIZE='2'>"
	+ "\n	<INPUT TYPE='hidden' NAME='cart_id' VALUE='" + cartnb + "'>"
	+ "\n	<INPUT TYPE='hidden' NAME='product' VALUE='" + sku + "'>"
	+ "\n	<INPUT TYPE='hidden' NAME='keywords' VALUE='" + keywords + "'>"
	+ "\n</TD>"
	+ "\n<TD WIDTH='90%' ALIGN='LEFT' VALIGN='top'>"
	+ "\n	<FONT FACE='TAHOMA,VERDANA,HELVETICA,ARIAL' SIZE='2'>"
	+ "\n	<table align='left' cols='3'>"
	+ "\n	<tr><td width='50%'><b>" + name + "</b></td>"
	+ "\n		<td width='25%'><font color='blue'>[ " + price + " ] </font></td>"
	+ "\n		<td width='25%' align='left' valign='top'>Quantity Available:"
	+ "\n		<INPUT TYPE='TEXT' NAME='quantity'" + "' SIZE='3' MAXLENGTH='3' VALUE='1' READONLY></td>"
	+ "\n	</tr>"
	+ "\n	<tr><td colspan='3' align='left' valign='top'>"
	+ "\n<P>" + description + "</td>"
	+ "\n	</tr>"
	+ "\n	</table>"
	+ "\n	</FONT>	"
	+ "\n</TD><!--END SELECT QUANTITY BUTTON-->"
	+ "\n</TR>"
	+ "\n<!-- bottom row for cart functions -->"
	+ "\n<TR> "
	+ "\n<TD WIDTH='10%' ALIGN='CENTER' VALIGN='TOP'>"
	+ "\n	<INPUT TYPE='IMAGE' NAME='add_to_cart_button' VALUE='Add To Cart' SRC='images/add_to_cart.gif' BORDER='0'>"
	+ "\n</TD>"
	+ "\n<TD WIDTH='10%' align='left'>"
	+ "\n	<A HREF='http://www.fifiluv.com/cgi/store/commerce.cgi?add_to_cart_button.x=yes"
	+ "&product=" + sku
	+ "&cart_id=" + cartnb 
	+ "&keywords=" + keywords
	+ "&viewOrder=yes'>"
	+ "\n	<FONT FACE='TAHOMA,VERDANA,HELVETICA,ARIAL' SIZE='2'>"
	+ "\n	<b>View Cart</b></FONT>"
	+ "\n	</A>"
	+ "\n</TD>"
	+ "\n</TR>"
	+ "\n</FORM>";
	return htmlForm;

}


function listSizes(ProductDoc)
{
	var sizes = new String();
	with (ProductDoc)
	{
		sizes = "<SELECT NAME='size'>"
			+ "<OPTION VALUE='null'>Size"
			+ "<OPTION VALUE='small'>Small"
			+ "<OPTION VALUE='medium'>Medium"
			+ "<OPTION VALUE='large'>Large"
			+ "</SELECT>";
		writeln(sizes);
	}
	return;
}

function listColors(ProductDoc)
{
	var colors = new String();
	with (ProductDoc)
	{
		colors = "<SELECT NAME='color'>"
			+ "<OPTION VALUE='null'>Color"
			+ "<OPTION VALUE='red'>Red"
			+ "<OPTION VALUE='white'>White"
			+ "<OPTION VALUE='black'>Black"
			+ "</SELECT>";
		writeln(colors);
	}
	return;
}

function showItem(deleteFlag,TargetDocument)
{
	with(TargetDocument)
	{
		write('<TR><TD>' + this.Description + '</TD>');
		write('<TD ALIGN=RIGHT>$' + this.Price + '</TD>');
		if (deleteFlag == true)
			write("<TD><A HREF='JavaScript:top.HIDDEN.deleteItem(" + this.Sku + ")'>Remove from Cart</A></TD>");
		write('</TR>');				
	}
}

function deleteItem(Sku)
{	// remove cart item into the cart array.
	delete ShoppingCart[Sku];
	viewCart();
}
/*==================================================================
function viewCart()
{
	var cartTotal=0;
	with (top.MAIN.document)
	{
		write();
		close();
		write('<html><title>Shopping Cart</title>');
		write('<body bgcolor=#ffffff>');
		write('<table align=center border=0><tr>');
		write('<td><img src=""></td>');
		write('<td align=center valign=bottom>');
		write('<h2>FiFi Luv Shopping Cart</h2></td>');
		write('<td align=center valign=bottom>');
		write('<h2>FiFi Luv Shopping Cart</h2></td>');
		write('<td><img src=""></td>');
		write('</tr>');
		write('</table><br><hr><br>');
		write('');
		write('<table align=center border=1 width=500 bgcolor=blue cellspacing=1 cellpadding=3>');
		write('');
		for (i in ShoppingCart)
		{
			cartTotal += ShoppingCart[i].Price;
			if (ShoppingCart[i].Sku != null)
			{
				ShoppingCart[i].display(true,top.MAIN.document);
			}
		}

		write('<tr><td>Total:</td><td align=right>$' + cartTotal + '</td>');
		write('<td>&nbsp;</td></tr></table><br>');
		write('<a href="JavaScript:top.HIDDEN.goBack();">Return to OrderPage</a><br><br>');
		write('<a href="JavaScript:top.HIDDEN.showOrder();">Show printable order form</a><br><br>');
		write('<br></body></html>');
	}
}
function goBack()
{
	top.MAIN.history.go(-2);
}

function showOrder()
{
	var CartTotal=0;
	var Name = "";
	var CustomerId = "";
	var PhoneNumber = "";
	Name=prompt("Enter your name:","");
	CustomerId=prompt("Enter your customer id:","");
	PhoneNumber=prompt("Enter your phone number:","");

	alert("To print: On menu bar click File, Print.");
	order = window.open("","orderWindow","toolbar=no,width=550,height=400,status=no,menubar=yes,resize=yes");
	with (order.document)
	{
		write();
		close();
		write("<html><title>Order Form</title><body bgcolor=white>");
		write("<table border=0><tr><td><img src=''></td><td align=center valign=bottom> ");
		write("<table border=0><tr><td><img src=''></td><td align=center valign=bottom> ");
		write("<h2>FiFi Luv Order Form</h2></td>");
		write("<td><img src=''></td></tr></table>");
		write("fax form to FiFi Luv<br>");
		write("<center><table width=350 border=1>");
		for (i in ShoppingCart)
		{
			CartTotal += ShoppingCart[i].Price;
			if (ShoppingCart[i].Sku != null)
			{
				ShoppingCart[i].display(false,order.document);
			}
			
		}
		write("<tr><td></td><td align=right>$" + CartTotal + "</td></tr>");
		write("</table></center></body></html>");
		close();
	}
}

function setBrowser()
{
	var isNS = false;
	var isNS4 = false;
	var isNS6 = false;
	var isNSx = false;
	var isIE = false;
	var isIE4 = false;
	var isIE5 = false;
	var isIEx = false;
	var isMac = false;
	isNS = (navigator.appName == 'Netscape') ? 1:0;
	isIE = (navigator.appName == 'Microsoft Internet Explorer') ? 1:0;
	var nVer= parseInt(navigator.appVersion,10);

	if( isNS)
	{
		switch(nVer)
		{
		case 4:
			isNS4 = true;
			break;
		case 6:
			isNS6 = true;
			break;
		default:
			 isNSx = true;
		}
		docs = "document";
		styles = " ";
		html = ".document";
		xposition = "e.pageX";
		yposition = "e.pageY";
	}
	if (isIE)
	{
		switch(nVer)
		{
		case 4:
			isIE4 = true;
			break;
		case 5:
			isIE6 = true;
			break;
		default:
			isIEx = true;
			break;
		}

		docs = "document.all";
		styles = ".style";
		html = " ";
		xposition = "event.x";
		yposition = "event.y";
	}
	var isDynamic = ((isNS || isIE) &&  
					!(isIE4 && navigator.appVersion.indexOf("Mac") >= 0)
					) 
		? 1 : 0;
	if ((isNS || isIE) && ! isDynamic)
	{
		alert("You should upgrade your browser to view this website.\n" +
				"Download the free upgrade from the browser website.\n"
			);
	}
}
======================================================= */

function showProductDetail(inForm,x_nRowNb,x_picWidth,x_picHeight)
{
	alert("show" + inForm.length);

	var sItemRow = new String();
	sku			= inForm.product.value;
	keywords	= inForm.keywords.value;
	urlImage	= inForm.imgFile.value;
	urlImageAlt	= inForm.imgFileAlt.value;
	name		= inForm.ProductName.value;
	description = inForm.ProductText.value;
	price		= inForm.Price.value;
	cartnb		= inForm.cart_id.value;

	var wndProperties = new String();
	wndProperties = "resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,dependent=yes,width=1000,height=650,innerWidth=1000,innerHeight=650,outerWidth=1200,outerHeight=700";
	var ProductPage = window.open('','ProductPage', wndProperties);
	if (keywords < ' ')
	{
		keywords="lingerie";
	}

	with (ProductPage.document)
	{
		writeln("<HTML><HEAD>"
				+ "<link rel='stylesheet' type='text/css' href='luvStyle.css'>"
				+ "<SCRIPT language='JavaScript' src='http://www.fifiluv.com/ShoppingCart.js'></script>"
				+ "</HEAD>"
				+ "<BODY width='900' bgcolor='white'>"
				);
		writeln("<DIV id='itemForm'>");
		writeln("<FORM action='http://www.fifiluv.com/cgi/store/commerce.cgi' method='post' name='OrderForm' align='center'>");

		writeln("<TABLE COLS='2' WIDTH='900' align='center' BGCOLOR='white' BORDER='0' CELLPADDING='0' CELLSPACING='4'>");
		writeln("<TR>");
		writeln("<TD WIDTH='" + x_picWidth + "' ALIGN='LEFT' VALIGN='TOP'>");

		writeln("<IMG WIDTH='" + x_picWidth + "' HEIGHT='" + x_picHeight + "' SRC='" + urlImage + "'>" 
				+ "</TD>"
				);

		writeln("<TD WIDTH='400' ALIGN='CENTER' VALIGN='TOP'>"
				+ "<IMG SRC='http://www.fifiluv.com/images/fifiluvLogo.gif' WIDTH='230' HEIGHT='130' >"
				);

		writeln("<h3>" + name + "</h3>");
		writeln("<font color='blue'>Price: " + price + "</font>");
		writeln("&nbsp&nbsp&nbsp&nbsp&nbsp SKU #: " + sku + "<BR>");
		writeln("<P ALIGN='LEFT'>" + description  + "</P>");
		// table within the cell:
		writeln("<TABLE COLS='3' WIDTH='50%' align='left' BGCOLOR='white' BORDER='0' CELLPADDING='2' CELLSPACING='10'>");
		writeln("<TR>");
		writeln("<TD COLSPAN='1'>Quantity:&nbsp&nbsp<INPUT TYPE='TEXT' NAME='" + sItemRow + " ' VALUE='1' MAXLENGTH='3' SIZE='3'></TD>");
		writeln("<TD COLSPAN='1'>");
				listSizes(ProductPage.document);
		writeln("</TD>");
		writeln("<TD COLSPAN='1'>");
				listColors(ProductPage.document);
		writeln("</TD>");
		writeln("</TR>");
		writeln("<TR>");
		writeln("<TD COLSPAN='3'><INPUT TYPE='IMAGE' NAME='add_to_cart_button' VALUE='Add To Cart' SRC='http://www.fifiluv.com/images/add_to_cart.gif' BORDER='0'> " 
//				+ "onClick=\"addToCart(" + "'" + name + "'," + "'" + description + "'," + "'" + price + "'," + "'" + sku + "'," + "'" + cartnb + "'" + ")\">"
				+ "</TD>"
				);
		writeln("</TR>");
		writeln("<TR></TR>");
		writeln("<TR>");
		writeln("<TD COLSPAN='3'>");
		writeln("<A HREF='http://www.fifiluv.com/cgi/store/commerce.cgi?add_to_cart_button.x=yes"
				+ "&product='"	+ sku + "'"
				+ "&cart_id='"	+ cartnb  + "'"
				+ "&keywords='" + keywords + "'"
				+ "&viewOrder='yes'>"
				+ "<FONT FACE='TAHOMA,VERDANA,HELVETICA,ARIAL' SIZE='1'>"
				+ "<b>View Cart</b></FONT>"
				+ "</A>"
				);
		writeln("</TD>");
		writeln("</TR>");
		writeln("<TR></TR>");

		writeln("<TR>");
		writeln("<TD colspan='3'>");
		writeln("<P>Cart#: " + cartnb + "</P>");
		writeln("<br><INPUT TYPE='hidden' NAME='cart_id' VALUE='" + cartnb + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='product' VALUE='" + sku + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='keywords' VALUE='" + keywords + "'>");
		writeln("<br><INPUT TYPE='hidden' NAME='viewOrder' VALUE='yes'>");
		writeln("</TD>");
		writeln("</TR>");

		writeln("</TABLE>"); 
		// end of cell table
		writeln("</TD>"); //end of cell

		writeln("</TR>");
		writeln("</TABLE></FORM>");
		writeln("</DIV>");
		writeln("</BODY></HTML>");
	}
}
