/**  cookies.js         written by Scott Honey

	A general library for writing cookies and reading cookies -- the highlight of which is the ability to read and write arrays as cookies (previously impossible).  Those arrays must be Netscape 3.0 arrays or higher, but the rest of the functions are useable with most any browser.  Currently, only the first two are used by the Singing Syllbary.



FUNCTIONS:

 	setCookie(STRING,VALUE,TIME)
		Creates a cookie with the STRING as the name, VALUE as the data, and TIME as the time it will expire.  If TIME is not included, then no expires tag is written for the cookie.  I got this function from some standard library somewhere, probably netscape's.

	getCookie(STRING)
		Retrieves the cookie by the name STRING and returns it to the caller.

	setArrayCookie(STRING,ARRAY)
		Creates a cookie that stores an array.  Expiration dates are not included.

	getArrayCookie(STRING)
		retrieves the cookied array STRING to the caller.

*/
/* setCookie(STRING,VALUE,TIME)
	Creates a cookie with the STRING as the name, VALUE as the data, and TIME as the time it will expire.  If TIME is not included, then no expires tag is written for the cookie.  I got this function from some standard library somewhere, probably netscape's.*/

function setCookie(name, value, expire) {
  document.cookie = name + "=" + escape(value)
    + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
    }	    

/* getCookie(STRING)
	Retrieves the cookie by the name STRING and returns it to the caller.*/
function 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
		return unescape(document.cookie.substring(offset, end))
	    } 
    }
}

/* setArrayCookie(STRING,ARRAY)
	Creates a cookie that stores an array.  Expiration dates are not included.*/
function setArrayCookie(name,theArray) {
  l=theArray.length;
  setCookie("length"+name,l);
  for (var i = 0; i<l;i++) {
    setCookie(name+i,theArray[i]);
  }//end for
}//end setArrayCookie

/* getArrayCookie(STRING)
	retrieves the cookied array STRING to the caller.*/
function getArrayCookie(name) {
  var l=getCookie("length"+name);
  var tempArray=new Array();
  for (var i=0;i < l; i++) {
    tempArray[i]=getCookie(name+i);
  }//end for
  return tempArray;
}//end getArrayCookie


