var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var ShowCount = 0;
var AlternateColor = 0;
var SelectedItem = "";
var DataOrderList = "name,address,city,state,zip,phone,submit_by,comments,bdaynotes";
var itemsprinted = false;
var referringpage = "";

function refresh() {
window.location.href = window.location;
}

function ListWishItems(referringpage) {
var NumWishItems = GetCookie('PT_NumWishList');
var i;
var WishItem;
if (NumWishItems == null) {NumWishItems = 0;}
ShowCount = 0; AlternateColor = 0;
if (referringpage == "contactus.html") {document.write("<br /><strong>I Would Like To Order These Items:</strong><br />");}
for (i=1; i <= NumWishItems; i++) {
	WishItem = GetCookie('PT_WishItem'+i);
	if (WishItem != null) {PrintItem(WishItem, i);}
}
if (itemsprinted == false) {
   if (referringpage == "contactus.html") {document.write("<table cellpadding='2' cellspacing='0' border='1' align='center'><tr><td colspan='3' align='center' width='450'>(No Wish List Items Currently Selected - Click Buttons Above to Shop)</td></tr></table>");}
   }
else {
   if (referringpage == "order_thanks.html") { 
   	  document.write("<tr><td colspan='3' align='center' style='font-family:Arial,Helvetica,Geneva,Swiss,SunSans-Regular; font-size:13px; font-weight:bold;'><a href='javascript:DeleteAllItems()'>Delete ALL Items from this Wish List Now</a></td></tr></table>");
	  }
   else if (referringpage == "contactus.html") {
   	  document.write("<tr><td colspan='3' align='center' style='font-family:Arial,Helvetica,Geneva,Swiss,SunSans-Regular; font-size:13px; font-weight:bold;'><a href='javascript:DeleteAllItems()'>Delete ALL Items from this Wish List Now</a></td></tr></table>");
	  document.write("<input type='hidden' name='form_id' value='ORDER Contact Form Submission'><input type='hidden' name='data_order' value='" + DataOrderList + "'><input type='hidden' name='ok_url' value='../../order_thanks.html'>");
	  }
   else {
   	  document.write("<tr><td colspan='3' align='center' style='font-family:Arial,Helvetica,Geneva,Swiss,SunSans-Regular; font-size:13px; font-weight:bold;'><a href='contactus.html'>Place Your Order Now</a></td></tr></table>");
	  }
   }
}

function DeleteItem(Count) {
DeleteCookie('PT_WishItem'+Count);
refresh();
}

function DeleteAllItems() {
var NumWishItems = GetCookie('PT_NumWishList');
var i = 0;
if (NumWishItems != null) {
   for (i=1; i <= NumWishItems; i++) {
	   DeleteCookie('PT_WishItem'+i);
	   }
   DeleteCookie('PT_NumWishList');
   refresh();
   }
}

function PrintItem (WishItem, Count) {
if (itemsprinted == false) {document.write("<table cellpadding='2' cellspacing='0' border='1' align='center'><tr><td colspan='3' align='center'><img src='images/wishlist1.gif' alt='WISH LIST' width='150' height='20' border='0'></td></tr>");}
itemsprinted = true;
var color = "bgcolor='#ffffff'";
AlternateColor = 1 - AlternateColor;
if (AlternateColor==1) {color = "bgcolor='#d6edff'";}
ShowCount++;
document.write("<tr " + color + ">");
document.write("<td width='15' align='center' valign='top'><small><b>"+ShowCount+"</b></small></td>");
document.write("<td width='373' align='left'><small>"+WishItem+"</small></td>");
document.write("<td width='50' align='center'><small>"+"<a href='javascript:DeleteItem(" + Count + ")'>Delete</a>"+"</small></td></tr>");
document.write("<input type='hidden' name='itemnumber" + ShowCount + "' value='" + WishItem + "'>");
DataOrderList = DataOrderList + ",itemnumber" + ShowCount;
}

function AddItem(SelectedItem) {
var NumWishItems = GetCookie('PT_NumWishList');
var WishItem;
if (NumWishItems == null) {NumWishItems = 0;}
WishItem = SelectedItem;
if ((WishItem != null) && (WishItem != "undefined" )) {
NumWishItems++;
SetCookie('PT_WishItem'+NumWishItems, WishItem, exp);
SetCookie('PT_NumWishList',NumWishItems, exp);
refresh();
   }
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1000000);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
