function ReadCookie(name)
{//alert("in ReadCookie - name: " + name);
   var allCookie, cookieVal, length, start, end;
   cookieVal="";
   name=name+"="; 
   allCookie=document.cookie; 
   length=allCookie.length; 
   if (length>0)
   {  start=allCookie.indexOf(name, 0);
      if (start!=-1)
      {   start+=name.length; 
          end=allCookie.indexOf(";",start);
          if (end==-1) {end=length;}
          cookieVal=unescape(allCookie.substring(start,end));
      }
   }
//alert("in ReadCookie - returning: " + cookieVal);
   return(cookieVal);
}

function WriteCookie(name,value,domain,path,expires,secure)
{//alert("in WriteCookie - name:" + name + "\nvalue:" + value);
   var CookieVal, CookError;
   CookieVal=CookError="";
   if (name)
   {  CookieVal=CookieVal+escape(name)+"=";
      if (value)
      {  CookieVal=CookieVal+escape(value); 
         if (domain)
         {   CookieVal=CookieVal+"; domain="+domain; 
         }
         if (path)
         {   CookieVal=CookieVal+"; path="+path; 
         }
         if (expires)
         {   CookieVal=CookieVal+"; expires="+expires.toGMTString(); 
         }
         if (secure)
         {   CookieVal=CookieVal+"; secure="+secure;
         }
      }
      else
      {   CookError=CookError+"Value failure";
      }
   }
   else
   {   CookError=CookError+"Name failure";
   }

   if (!CookError)
   {  document.cookie=CookieVal;  // sets the cookie
      if (value != ReadCookie(name))
      {   CookError="Write failure";
      }
   }
//alert("in Write, returning: " + CookError);
   return CookError;
}

function DeleteCookie (name,domain,path)
{
   var expireDate=new Date(1);
   if (ReadCookie(name))
   {
      WriteCookie(name, " ", domain, path, expireDate);
   }
}

function DateDiff(dt1, dt2)
{//alert("DateDiff dt1: " + dt1 + "\ndt2: " + dt2);
	var diff = Math.abs( dt1.getTime() - dt2.getTime() );
	diff = Math.floor( diff / (1000 * 60 * 60 * 24) );
//alert("DateDiff rtn: " + diff);
	return diff;
}

function TestCookie()
{	var t = WriteCookie("test","test");
	if ( t == "" )
	{	return true;	}
	else
	{	return false;	}
}
