/* $Revision: 1 $
 * $Author: Errol $
 * $Date: 11/07/05 3:11p $
 * $Logfile: /Development/Property Phase1/Web/Postings/16696/scripts/pe_cookies.js $
 * $NoKeywords: $
 */

//========================================================================================================//
function fnSetCookie(cookieName, cookieVal, blnExpiry, intExpiryLen){
	if (blnExpiry == true && intExpiryLen != "") {
		expireDate = new Date(); expireDate.setDate(expireDate.getDate()+intExpiryLen);
		document.cookie = cookieName+"="+cookieVal+"; expires=" + expireDate.toGMTString();
	} else {
		document.cookie = cookieName+"="+cookieVal+"; ";
	}
}
//========================================================================================================//
function fnReadCookie(which){
	var thisCookie="", theVal=0, theVisits=0;
	if(document.cookie.indexOf("; ", 0) != -1){
		thisCookie = document.cookie.split("; "); 
		for(var i=0;i<thisCookie.length;i++){
			/*Basic purpose of this cookie 'visits' is to count how many times user has been to page.
			Cookie value is then passed into flash movie via QS and read into dynamic textfield (var visits) 
			They will only hear the mooooo and baaaaa twice in one day*/
			if( thisCookie[i].split("=")[0]=="visits" ){
				theVisits=parseInt(thisCookie[i].split("=")[1]);
				theVisits++; fnSetCookie(which, theVisits, true, 1);
			}
		}//end for
	} else {
		 theVisits++; fnSetCookie(which, theVisits, true, 1);
	}
	return (theVisits);
}
//========================================================================================================//
function cookiesEnabled(which){
	var theVisits = null;
	if(navigator.cookieEnabled){theVisits = fnReadCookie(which);}
	return theVisits;
}
