function ReadCookie(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));
        }
   }
   return(cookieVal);
}



function WriteCookie(name,value,expires)
{
 
   var CookieVal, CookError;
   var today = new Date();
   today.setTime( today.getTime() );
   CookieVal=CookError="";
   if (name)
   {
   	CookieVal=CookieVal+escape(name)+"=";

   }
   if (value)
   {
    	CookieVal=CookieVal+escape(value);
   }
   if (expires)
   {
      expires = expires * 1000 * 60 * 60 * 24;
   }
   var expires_date = new Date(today.getTime() + (expires) );

   CookieVal=CookieVal+"; expires="+expires_date.toGMTString();
   document.cookie=CookieVal;  // sets the cookie

   CookieVal=CookieVal+"; path=/casa/";
   document.cookie=CookieVal;  // sets the cookie
}



function DeleteCookie (name,domain,path)
{
  if ( ReadCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function GetLogonCookies()
{
   var username;
   username = ReadCookie('username')
   if (username != null)
   {
       document.logonForm.username.value = username;
   }
   password = ReadCookie('password')
   if (password != null)
   {
       document.logonForm.password.value = password;
   }

   RotateImage();
}

function SetLogonCookies()
{
   var today = new Date();
   var expires = new Date(today.getTime() + (56 * 86400000));

   WriteCookie('username',document.logonForm.username.value,10);
   WriteCookie('password',document.logonForm.password.value,10);
}

function GetLogonCookies()
{
   var username;
   var password;
   username = ReadCookie('username')
   if (username != null)
   {
       document.logonForm.username.value = username;
   }
   password = ReadCookie('password')
   if (password != null) {
       document.logonForm.password.value = password;
   }
}
