function getNoCookieVar() {return "zzNoCookie";}
// function getDomain() {return "albanyflorist.com";}
function getSeparator() {return '`';}

function setCookie(var_name, var_value, expDate)
{
	  var the_date = new Date(expDate);
        var sExpDate="";
        var the_cookie = var_name + "_info=" + var_name + "^" + escape(var_value);
        var the_cookie_date = the_date.toGMTString();
        if (expDate != 0)
           the_cookie = the_cookie + ";expires=" + the_cookie_date;
//        var the_domain = getDomain();
//        if (the_domain != "")
           the_cookie = the_cookie + ";path=/"; //;domain=" + the_domain;
        document.cookie = the_cookie;
}

function expireCookie(cookieName)
{
	var expDate = new Date("January 10, 1990");
	setCookie(cookieName, getNoCookieVar(), expDate);
}

function readCookie(cookieName)
{
  var noCookie = getNoCookieVar();
  var cookie_value = noCookie;
  var the_cookie = WM_readCookie(cookieName + "_info");
  if (the_cookie != noCookie)
    {
	var broken_cookie = the_cookie.split("^");
	var the_name_part = broken_cookie[1];
	var broken_name = the_name_part.split(";");
	cookie_value = broken_name[0];
    }
  if (cookie_value.length > 0)
      return cookie_value;
     else return noCookie;
}

function readMultiCookie(cookieName,pos)
{     //assumes all parts of the cookie will contain data - programmer must gaurantee this at time of setting
	var separator = getSeparator();
      var the_cookie = readCookie(cookieName);
	var noCookie = getNoCookieVar();
	if (the_cookie == noCookie) return noCookie;
	var count=0;
	var myValues = the_cookie.split(separator);
	if (pos < 0) return myValues;
		else if (myValues[pos]) return myValues[pos];
			else return noCookie;
}
function isThere(stringName)
{
	if (!stringName) return getNoCookieVar();
		else return stringName;
}
function isValid(cookie)
{
	if (cookie=='' || cookie==getNoCookieVar() || cookie==null)
		return false;
		else return true;
}

function invalidChars(cookie)
{
	var loop;
	var separator = getSeparator();
	for (loop=0; loop < cookie.length; loop++)
	     if (cookie[loop] == separator) return true;
	return false;
}

// if there's no cookie, return false else get the value and return it
function WM_readCookie(name)
{
  if(document.cookie == '') return getNoCookieVar();
     else return unescape(WM_getCookieValue(name));
}



function WM_getCookieValue(name)
{
  var firstChar, lastChar;

  // Get the entire cookie string. (This may have other name=value pairs in it.)
  var theBigCookie = document.cookie;

  // Grab just this cookie from theBigCookie string.
  // Find the start of 'name'.
  firstChar = theBigCookie.indexOf(name);

  // If you found it,
  if(firstChar != -1) {
	// skip 'name' and '='.
	firstChar += name.length + 1;

	// Find the end of the value string (i.e. the next ';').
	lastChar = theBigCookie.indexOf(';', firstChar);

	if(lastChar == -1) lastChar = theBigCookie.length;

	// Return the value.
	return theBigCookie.substring(firstChar, lastChar);

   } else {
    	// If there was no cookie, return "zzNoCookie".
    	return getNoCookieVar();
  }
}

function isLeapYear(Year)
{
  if ((Year % 4)==0)
	return true;
	else return false;
}


function calcExpirationDate(AddDays)
{
  TDate = new Date();
  TMonth = new Array('January', 'February', 'March', 'April', 'May','June', 'July', 'August', 'September', 'October', 'November', 'December');
  MonthDays = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

  var days;  // temp value for days in currentMonth
  var CurYear  = TDate.getYear();
  var CurMonth = TDate.getMonth();
  var CurDay = TDate.getDate();


  if (CurMonth == 1 && isLeapYear(CurYear+1900)) days=29;
     else days = MonthDays[CurMonth]; 
  CurDay += AddDays;
  while (CurDay > days) 
  {
    if (CurMonth == 11) {
        CurMonth = 0;
        CurYear += 1;
       } else CurMonth += 1;
    CurDay -= days;
    if (CurMonth == 1 && isLeapYear(CurYear+1900)) days=29;
       else days = MonthDays[CurMonth]; 
  }
  CurYear += 1900;

  var TheDate = TMonth[CurMonth] + ' ';
  TheDate += CurDay + ', ';
  TheDate += CurYear;
  return TheDate;
}

//////////////////////////////////////////////////////////////////////
// begin AlbanyFlorist Specific Stuff
//////////////////////////////////////////////////////////////////////

function addToCart(item,alertNotice)
{
  var the_cart = readCookie("dfdcart");
//  var temp=the_cart;
  var the_items = the_cart.split("`");

  var numItems=0;
  if (the_cart != getNoCookieVar())
     for (numItems=0; the_items[numItems]; numItems++);
    else the_cart = "";

  if (numItems>=5)
  {
     alert("Your Shopping Cart is full");
     return;
  }
  if (numItems > 0)
     the_cart += "`" + item;
    else the_cart = item;

  setCookie("dfdcart", the_cart, 0);
  alert(unescape(alertNotice) + " has been added to your cart");
}

function removeItem(ItemNum)
{
   var the_cart = readCookie("dfdcart");
   var the_items = the_cart.split("`");
   var the_new_items = "";

   var numItems=0;
   if (the_cart != getNoCookieVar())
      for (numItems=0; the_items[numItems]; numItems++);

   for (pos=0; pos<=numItems-1; pos++)
   {
      if (pos != ItemNum)
      {
         if (the_new_items.length == 0)
            { the_new_items = the_items[pos]; }
           else { the_new_items += "`" + the_items[pos]; }
      }
   }

   setCookie("dfdcart", the_new_items, 0);
   location.href = location.href;
}

function toDollars(inFloat)
{
  var dollarString = " " + inFloat;
  dollarString = dollarString.substring(1,dollarString.length);
  var dollarArray = dollarString.split(".");
  var returnDollar = dollarArray[0] + ".";
  if (dollarArray[1])
     dollarArray[1] += "00";
   else dollarArray[1] = "00";
  returnDollar += dollarArray[1].substring(0,2);
  return returnDollar;
}
