/* cookielib.js - javascript library for manipulating cookies */

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookieValue(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  var expire = new Date();
  expire.setTime(expire.getTime() - 1000*60*60*24*5); //expired 5 days ago
  if (getCookieValue(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=" + expire.toGMTString();
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function VAX_getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search) 
		if (offset != -1) { // if cookie exists 
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length;
			if ((Name == "Colors")||(Name == "MyColors")) {
				var l_str = unescape(document.cookie.substring(offset, end));
				l_pipe = 0;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				tText = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				tBackG = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				dText = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				if (l_pipe2 == -1)
					l_pipe2 = l_str.length;
				dBackG = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				if (l_pipe2 == -1)
					l_pipe2 = l_str.length;
				lColor = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				if (l_pipe2 == -1)
					l_pipe2 = l_str.length;
				bulkColor = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				if (l_pipe2 == -1)
					l_pipe2 = l_str.length;
				pubColor = l_str.substring(l_pipe, l_pipe2);
				l_pipe = l_pipe2 + 1;
				l_pipe2 = l_str.indexOf("|", l_pipe);
				if (l_pipe2 == -1)
					l_pipe2 = l_str.length;
				dollarColor = l_str.substring(l_pipe, l_pipe2);
				return "";
			}
			else
			{
			   if (Name == "VendOrd")
			   {
				VendorList = unescape(document.cookie.substring(offset, end));
				return "";
			   }
			   else
			   {
			     if (Name == "NoVend")
			     {
				NoVendor = unescape(document.cookie.substring(offset, end));
				return "";
			     }
			     else
			     {
				if (Name == "Cities")
				{
				  CityList = unescape(document.cookie.substring(offset, end));
				  return "";
				}
				else
				{
				  return unescape(document.cookie.substring(offset, end))
				}
			     }
			   }
			}
		}
		else
		{
			if ((Name == "Colors")||(Name == "MyColors")){
				tText = "navy";
				tBackG = "E9EABB";
				dText = "navy";
				dBackG = "wheat";
				lColor = "910053";
				bulkColor = "green";
				pubColor = "navy";
				dollarColor = "goldenrod";
				return "";
			}
			else
			{
			  if (Name == "VendOrd")
			  {
			    VendorList = "";
			  }
			  else
			  {
			    if (Name == "NoVend")
			    {
			      NoVendor = "";
			    }
			    else
			    {
				if (Name == "Cities")
				{
				  CityList = "******00";
				}
			    }
			  }
			}
		}
	}
	else
	{
		if ((Name == "Colors")||(Name == "MyColors")){
			tBackG = "E9EABB";
			tText = "navy";
			dText = "navy";
			dBackG = "wheat";
			lColor = "910053";
			bulkColor = "green";
			pubColor = "navy";
			dollarColor = "goldenrod";
			return "";
		}
		else
		{
		  if (Name == "VendOrd")
		  {
		    VendorList = "";
		  }
		  else
		  {
		    if (Name == "NoVend")
		    {
		      NoVendor = "";
		    }
		    else
		    {
			if (Name == "Cities")
			{
			  CityList = "******00";
			}
		    }
		  }
		}
	}
}
//alert("Version 2.0 CookieLib.js loaded.");