	// JavaScript Document
<!--


function purchase() // OPENS WINDOW THAT CONFIRMS PURCHASE AND SAYS THANKS
{

var porder="";
// add order array and item array
var cart = Item;
alert("CART Length: " + cart.contents.length);
if (cart.contents.length == 0) alert("can't add for zero reasons");

for (i=0; i<cart.contents.length; i++)
{
//document.write("<li>" + cart.contents[i].name + "<br>Price: " + toCurrency(cart.contents[i].price) + "<br>Quantity: " + cart.contents[i].ship + "<br><br>");

// Here is the cookie setter functions
var porder = porder + cart.contents[i].name + "||" + cart.contents[i].price + "||" + cart.contents[i].ship;
if (i<cart.contents.length-1) porder = porder + "&&";
}
alert("PORDER: " + porder);

//var old_order = "";
//for (i=0; i<order.length; i++)
//{

//old_order = old_order + order[i] + "&&";
//alert("entering old");

//}
//alert("old_order: " + old_order);
//porder = old_order + porder;

//alert(order);
//var porder = porder + cart.contents[i].name + "||" + cart.contents[i].price + "||" + cart.contents[i].ship;
//Set_Cookie( 'test', porder, '', '/', '', '' );


// Here is the cookie getter functions
//var order = cart.iname.value + "||" + cart.iprice.value + "||" + cart.iship.value + "||" + cart.total.value + "&&";
//if ( Get_Cookie( 'test' ) ) alert( Get_Cookie('test'));
  // and these are the parameters for Delete_Cookie:
  // name, path, domain
  // make sure you use the same parameters in Set and Delete Cookie.
//Delete_Cookie('test', '/', '');
//( Get_Cookie( 'test' ) ) ? alert( Get_Cookie('test')) : 
//alert( 'it is gone');


// End cookie



purchaseWin = window.open("cartthankyou.html","","width=350,height=350,scrollbars=1,resizable=1,menubar=0,status=0,directories=0,location=0,toolbar=1");
//cartWin = window.open("","cartWin","width=100,height=100,scrollbars=0,resizable=0,menubar=0,status=0,directories=0,location=0,toolbar=0,");

//cartWin.close();
}

function getdisplay()
{
 if (dropform.s.selectedIndex == 1)
  {
	longsleeve.display();
  }
  if (dropform.s.selectedIndex == 2)
  {
	shortsleeve.display();
  }
  if (dropform.s.selectedIndex == 3)
  {
 	youthmed.display();
  }
  if (dropform.s.selectedIndex == 4)
  {
	youthlarge.display();
  }
  if (dropform.s.selectedIndex == 5)
  {
	bluelarge.display();
  }
  if (dropform.s.selectedIndex == 6)
  {
	bluexlarge.display();
  }
  cart.iship.focus();
}  

function Item(name,price,ship) // THE ITEM OBJECT CONSTRUCTOR FUNCTION
{
this.name = name;
this.price = price;
this.ship = ship;
this.selected = false; // VARIABLE THAT IS TURNED ON WHEN ITEM IS SELECTED
}

function toCurrency(x) // SWICHES NUMERIC VALUES TO CURRENCY STRINGS
{
if (x == 0) return "$0.00";
x = x.toString();
var pre = x.substring(0,(x.length - 2));
var post = x.substring((x.length - 2),(x.length));
return "$" + pre + "." + post;
}

// INITIALIZE CLASS VARIABLES
Item.total = 0; // TOTAL PRICE
Item.contents = new Array(); // STORE CONTENTS OF CART
Item.counter = 0; // DESIGNATE A UNIQUE INTIGER FOR INITIALIZATION OF AN ELEMENT OF ITEM.CONTENTS


Item.prototype.display = function() // METHOD TO SET OBJECT VALUES IN DISPLAY FIELDS 
{
longsleeve.selected = false;
shortsleeve.selected = false;
youthmed.selected = false;
youthlarge.selected = false;
bluelarge.selected = false;
bluexlarge.selected = false;
document.cart.iname.value = this.name;
document.cart.iprice.value = toCurrency(this.price);
//document.cart.iship.value = this.ship;
document.cart.iship.value = 0;
this.selected = true; // TURN ON THIS VARIABLE TO SELECT IT FOR INCLUSION IN THE CART
}

Item.prototype.add = function() // METHOD TO ADD AN ITEM OBJECT TO THE CART
{
Item.total = Item.total + (this.price * cart.iship.value); // ADD TO THE TOTAL PRICE
Item.contents[Item.counter] = this; // PLACE AN ITEM INTO A NEW ARRAY ELEMENT
Item.contents[Item.counter].ship = Math.round(parseInt(cart.iship.value));
document.cart.total.value = toCurrency(Item.total); // PURELY FOR DISPLAY
document.cart.iname.value = ""; // UPDATE DISPLAY FIELDS
document.cart.iprice.value = ""; // UPDATE DISPLAY FIELDS
document.cart.iship.value = ""; // UPDATE DISPLAY FIELDS
document.dropform.s.value = "selecta";
Item.counter++ // INCREMENT COUNTER FOR NEXT ARRAY ELEMENT
}

Item.show = function() // DISPLAY WINDOW TO REVEAL CART CONTENTS
{
cartWin = window.open("showcart.html","cartWin","width=300,height=400,scrollbars=1,resizable=0,menubar=0,status=0,directories=0,location=0,toolbar=0,left=320,top=20");
cartWin.focus();
}

Item.removalOf = function(x) // REMOVE AN ITEM FROM THE CART, WHEW!
{
Item.total = Item.total - (Item.contents[x].price * Item.contents[x].ship); // REDUCE TOTAL
Item.contents[x] = ""; // VOID OUT THE ARRAY ELEMENT
document.cart.total.value = toCurrency(Item.total); // UPDATE DISPLAY
Item.contents.sort(function (a,b) // RESORT OUR ARRAY
   {
   if (a == "") a = 1; else a = 0;
   if (b == "") b = 1; else b = 0;
   return a - b;
   });
var holdPoint = Item.contents.length;
for (i=0; i<Item.contents.length; i++) // DESIGNATE WHERE EMPTY ELEMENTS BEGIN
   {
   if (Item.contents[i] == "") { holdPoint = i; break; }
   }
Item.contents = Item.contents.slice(0,holdPoint); // DISCARD EMPTY ELEMENTS
Item.counter--; // DECREMENT COUNTER TO MATCH BACK UP TO ARRAY
}

Item.addToCart = function(ship) // FIGURE OUT WHICH ITEM IS SELECTED
{

// Check for int or NaN
zerot = parseInt(ship);
//zerot = parseInt(cart.iship.value);
zerot = Math.round(zerot);

NotNum = isNaN(zerot);

if (zerot == "0" || NotNum) 
{
  alert("User must enter a numeric quantity to add item to cart");
  return true;
}  


//if (longsleeve.selected) { longsleeve.add(cart.iship.value); longsleeve.selected = false; }
//if (shortsleeve.selected) { shortsleeve.add(cart.iship.value); shortsleeve.selected = false; }
//if (youthmed.selected) { youthmed.add(cart.iship.value); youthmed.selected = false; }
//if (youthlarge.selected) { youthlarge.add(cart.iship.value); youthlarge.selected = false; }
//if (bluelarge.selected) { bluelarge.add(cart.iship.value); bluelarge.selected = false; }
//if (bluexlarge.selected) { bluexlarge.add(cart.iship.value); bluexlarge.selected = false; }

// Get cookie nze

if (longsleeve.selected) { longsleeve.add(zerot); longsleeve.selected = false; }
if (shortsleeve.selected) { shortsleeve.add(zerot); shortsleeve.selected = false; }
if (youthmed.selected) { youthmed.add(zerot); youthmed.selected = false; }
if (youthlarge.selected) { youthlarge.add(zerot); youthlarge.selected = false; }
if (bluelarge.selected) { bluelarge.add(zerot); bluelarge.selected = false; }
if (bluexlarge.selected) { bluexlarge.add(zerot); bluexlarge.selected = false; }

// Set cookie + new order nze
var cart = Item;
var porder = "";
//for (i=0; i<cart.contents.length; i++)
//{
//document.write("<li>" + cart.contents[i].name + "<br>Price: " + toCurrency(cart.contents[i].price) + "<br>Quantity: " + cart.contents[i].ship + "<br><br>");

// Here is the cookie setter functions NZE
var name = "test";
var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	cookie_stuff = unescape( document.cookie.substring( len, end ) );
	alert("CCOOKIE " + cookie_stuff);
	order = cookie_stuff.split("&&");
	for (i=0; i<order.length; i++)
    {
	  alert("Order: "+order [i]);
	}

/////////////////////////
//porder = porder + cart.contents[].name + "||" + cart.contents[i].price + "||" + cart.contents[i].ship;
if (i<cart.contents.length-1) porder = porder + "&&";
//}
Set_Cookie( 'test', porder, '', '/', '', '' );
alert("PORDER Me: " + porder);

}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	cookie_stuff = unescape( document.cookie.substring( len, end ) );
	order = cookie_stuff.split("&&");
	for (i=0; i<order.length; i++)
    {
	  alert("Order: "+order [i]);
	}  
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
function proc_cookie()
{ 
  var prorder = cart.iname.value + "&&" + cart.iprice.value + "&&" + cart.iship.value + "&&" + cart.total.value;
  Set_Cookie( 'test', prorder, '', '/', '', '' );
  if ( Get_Cookie( 'test' ) ) alert( Get_Cookie('test'));
  // and these are the parameters for Delete_Cookie:
  // name, path, domain
  // make sure you use the same parameters in Set and Delete Cookie.
  /////nze/Delete_Cookie('test', '/', '');
   ( Get_Cookie( 'test' ) ) ? alert( Get_Cookie('test')) : 
  alert( 'it is gone');
}







// INITIALIZE ITEM INSTANCES
//var milk = new Item("Milk",289);
//var eggs = new Item("Eggs",175);
//var detergent = new Item("Detergent",595);
//var spinach = new Item("Spinach",350);
//var catfood = new Item("Cat Food",1238);

//-->