﻿product01 = "Mississippi Jet Blue Frog";
product01_price = 251.99;
product02 = "California Miniature Frog";
product02_price = 135.54;
product03 = "South American Green Frog";
product03_price = 467.23;
grandtotal = 0;

function getTodaydate()
{
	//document.write(Date() + "&nbsp;");
	today = new Date();
	dd = today.getDate();
	day = today.getDay();
	mm = today.getMonth();
	yyyy = today.getFullYear();
	
	darray = new Array();
	darray[0] = "Sunday";
	darray[1] = "Monday";
	darray[2] = "Tuesday";
	darray[3] = "Wednesday";
	darray[4] = "Thursday";
	darray[5] = "Friday";
	darray[6] = "Saturday";
	
	marray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	document.write(darray[day] + ", " + marray[mm] + " " + dd + ", " + yyyy); 
	//document.write("Tuesday, December 16, 2008");
}

function menuRollover(imageObject, imageName)
{
	imageObject.src = "images/" + imageName + ".jpg";
}

function buildTable()
{
  //alert ("entering buildtable()");
  document.write("<table id=shoppingcart>");
  document.write("<tr><td>&nbsp;</td></tr><tr><td align=center colspan=4><b>SHOPPING CART</b></td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>");
  document.write("<tr><th>ITEM</th><th>QTY</th><th>UNIT PRICE</th><th>TOTAL PRICE</th></tr>");
  
  //Read QueryString to Retrieve Arguments and Values
  querystring = location.search.substring(1);
  //alert ("querystring = " + querystring);
  pairs = querystring.split("&");
  //alert ("pairs = " + pairs);
  for (i = 0; i < pairs.length; i++)
  {
    //alert("for statement");
    productname = "";
    productprice = 0;
    pos = pairs[i].indexOf('=');
    //alert("pos = " + pos);
    argname = pairs[i].substring(0,pos);
    //alert ("argname = " + argname);
    
    switch (argname)
    {
     case "QTY01":
       //alert("case QTY01")
       productname = product01;
       productprice = product01_price;
       break;
     case "QTY02":
       productname = product02;
       productprice = product02_price;
       break;
     case "QTY03":
       productname = product03;
       productprice = product03_price;
       break;
    }
 
    value = pairs[i].substring(pos+1);
    //alert("value = " + value);
 
    if (value > 0)
    {
      subtotal = (value * productprice);
      document.write("<tr><td>" + productname + "</td><td>" + value + "</td><td>" + productprice + "</td><td class=tdboldcenter>$" + subtotal.toFixed(2) + "</td></tr>");
      //alert ("right before error");
      grandtotal += subtotal;
      //alert ("grandtotal = " + grandtotal);
    }
  }
  document.write("<tr><td>&nbsp;</td></tr><tr><td colspan=2></td><td><b>GRAND TOTAL</b></td><td>$" + grandtotal + "</td></tr>");
  document.write("<tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr></table>");
  setCookie('grandtotal',grandtotal,365); 
  //alert ("exiting buildtable()");
} 

function setCookie(c_name,value,expiredays)
{
  var exdate=new Date()
  exdate.setDate(exdate.getDate()+expiredays)
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
  if (document.cookie.length>0)
  { 
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
     } 
   }
   return ""
}

function saveMessage()
{
	//alert ("Entering saveMessage()");
	frmCheckOut.message.value = frmCheckOut.name.value;
	frmCheckOut.message.value += "/" + frmCheckOut.email.value;
	frmCheckOut.message.value += "/" + frmCheckOut.phone.value;
	//alert ("Exiting saveMessage()");
}

function popGrandTotal()
{
	frmCheckOut.message.value = getCookie("grandtotal");
	frmCheckOut.grandtotal.value = getCookie("grandtotal");
}