function ReadCookie(aName){
  var allCookie, cookieVal, length, start, end;
  cookieVal="";
  name=aName+"=";
  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));
    }
  }
  len=cookieVal.length;

  return(cookieVal);
}


function WriteCookie(name,value,domain,path,expires,secure){ 
	var CookieVal, CookError;
	CookieVal=CookError="";
      expires = new Date("December 31, 2023");
	if (name){
		CookieVal=CookieVal+escape(name)+"=";
	}
	if (value){
            if (name='RedirectURL') CookieVal=CookieVal+value
            else 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+"Write failure";
	}
	document.cookie=CookieVal;  // sets the cookie
}

