cookiecookiedebugOnOn=false;
	
if(cookiecookiedebugOnOn){
	alert("cookie.js");
}


/* ###################################################################################################### */


/*		Created by: SCOTT KAISER
			Created date: Feb 10, 2002

			Modified by:
			Modified date:
			Modification details:

			This function is used to set cookies 
			It must be passed:
			- COOKIE NAME
			- COOKIE VALUE
			
			It can also be passed the following:
			- CEXPIRES
			- CPATH
			- CDOMAIN
			- CSECURE 
			
			Note: If no expiration date is sent the cookie will only last as long as the current browser
			session is open. Once the browser is closed the cookie is gone */
		
function makeCookie(cName,cVal,cExpires,cPath,cDomain,cSecure){

		/* If a expiration date is passed in create the setDate string that will be appended on the function
		to create the cookie */
		((cExpires==null) ? setDate = "" : expDate = "; expires = "+cExpires.toGMTString());

		/* If a path is passed in create the setPath string that will be appended on the function
		to create the cookie */
		((cPath==null) ? setPath = "" : setPath = "; path = "+cPath);

		/* If a domain is passed in create the setDomain string that will be appended on the function
		to create the cookie */
		((cDomain==null) ? setDomain = "" : setDomain="; domain = "+cDomain);

		document.cookie = cName + "=" + escape(cVal) + setDate + setPath + setDomain;
}


/* ###################################################################################################### */


/*		Created by: SCOTT KAISER
			Created date: Feb 10, 2002

			Modified by:
			Modified date:
			Modification details:

			This function is used to delete cookies 
			It must be passed:
			- COOKIE NAME
			
			It can also be passed the following:
			- CPATH
			- CDOMAIN */
		
function delCookie(cName,cPath,cDomain){
		/* If a path is passed in create the setPath string that will be appended on the function
		to delete the cookie */
		((cPath==null) ? setPath = "" : setPath = "; path = "+cPath);

		/* If a domain is passed in create the setDomain string that will be appended on the function
		to delete the cookie */
		((cDomain==null) ? setDomain = "" : setDomain="; domain = "+cDomain);

		/* Set the expiration date of the cookie to some time in the past so that it will be
		deleted by the browser*/
		document.cookie = cName + "=" + setPath + setDomain +"; expires=Wed, 01-Jan-80 00:00:01 GMT;"
}


/* ###################################################################################################### */


/*		Created by: SCOTT KAISER
			Created date: Feb 10, 2002

			Modified by:
			Modified date:
			Modification details:

			This function is used to retrieve cookie value
			It will search through the semi-colin delimited pairs of values stored in the cookie and 
			return the value we are looking for
			It must be passed:
			- COOKIE NAME */

function retCookie(cName){

	/* Since cookie values are store in semi-colin delimited pairs of name=value
	well will create the string to search for by appending = on to the end of the 
	cookie name passed in */
  var strSrh = cName + "=";

	/* Set up the varaible the will eventually be returned */
  var rtnStr = "";

	/* Check to see if the cookie has a lenght greater that 0
	If it does nothing further will happen and an empty string will be returned */
  if (document.cookie.length > 0) {

		/* Find the start point of the search string created above */
    strFnd = document.cookie.indexOf(strSrh);

    /* If the string does not exisit nothing further will happen and an empty string will be returned */
    if (strFnd != -1) { 

			/* Because the cookie values are store in semi-colin delimited pairs of name=value the actual value
			we want is stored at the end of the search string so we set a variable which is the postition
			where the search string was found plus the length of the search string */
      strtStr = strFnd+strSrh.length;

			/* Now find the end position of our string by finding the postition of the semi-colin that would be
			separating this value from the next cookie value in the semi-colin delimited pairs
			Start the search at the postition where seach string starts above strtStr */
      endStr = document.cookie.indexOf(";", strtStr);

      /* If there is semi-colin then this is the last pair in the cookie so we must set the end position
			to the lenght of the cookie string */
      if (endStr == -1) endStr = document.cookie.length;
							rtnStr=unescape(document.cookie.substring(strtStr, endStr))
      }
   }
  return rtnStr;
}


/* ###################################################################################################### */


/*		Created by: SCOTT KAISER
			Created date: Feb 10, 2002

			Modified by:
			Modified date:
			Modification details:

			This function is used to test if the browser is set to allow cookies.
			It used the makeCookie and retCookie functions above */

function tstCookie(cName,Cval){

	/* Set the test variable isCookieOK to true.
	if any testing fails the var will be set to false and false will be returned */
	isCookieOK = true;

	if(cookiedebugOn){
		alert("write cookie");
	}

	/* Create a cookie using the makeCookie function, the name and value passed */
	makeCookie(cName,Cval);

	/* Test if the cookie is there. If not set isCookieOK to false */
	if(document.cookie){
		if(cookiedebugOn){
			alert("detected cookies");
		}

		/* If the cookie is there test to see if the value set in the cookie is the same as
		what was passed. Do this using the retCookie function and the cookie name passed. */
		valueTst = retCookie(cName);

		if(cookiedebugOn){
			alert(valueTst);
		}

		/* If the value is not the same set the isCookieOK to false */
		if(valueTst!=Cval){
			isCookieOK = false;
		}
	}
	else{
		isCookieOK = false;
	}
	if(cookiedebugOn){
		alert(isCookieOK);
	}

	/* Finally evaluate the isCookieOK var. If it is true then return true. If it is 
	false then return false */
	if(!isCookieOK){
		return false;
	}
	else{
		return true;
	}
}

function delAllCookies(){

	if(debugOn){
		alert("cookie: "+document.cookie);
	}
	
	/* Set a variable equal to the cookie string so it can be manipulated */
	strCookie = document.cookie
	
	/* Make and array out of the semi-colin delimited string */
	arrCookie = strCookie.split(";");
	
	if(cookiedebugOn){
		alert("delete all cookies");
	}
	for(i=0; i<arrCookie.length; i++){
		if(cookiedebugOn){
			alert(arrCookie[i]);
		}
	
		/* find where the name of the cookie ends - this would be where the equal sign is */
		endPos = arrCookie[i].indexOf("=");
		if(cookiedebugOn){
			alert(endPos);
		}
	
		/* Create a substring from the begining of the string to the postion of the equal sign
		This is the cookie name. */
		cookieName = ""+arrCookie[i].substring(0,endPos);
	
		/* Delete the cookie using the delCookie function and the cookie name found above */
		delCookie(cookieName);
	}
}