
	// Cookies must be written and updated both on client and server: write PHP Cookies because JS cookies can't be changed by PHP:

function phpCookie(cookieNames, cookieValues, cookieCallback, cookieDur, passVals) {	// Write, read, or delete a cookie via php

										// Multiple names and values can be passed via strings separated by commas	
										// cookieDur:      the duration of the cookie in ms. Use '-1' to delete

										// cookieCallback: optional name of a javascript function to run after reading a cookie
										//	...callback is constructed by passing the fetched value along with passVals
	if (!cookieValues) {
		cookieValues = '';
	}

	if (!cookieDur) {
		cookieDur = '';
	}

	if (!cookieCallback) {
		cookieCallback = '';
	}

	if(!passVals) {
		passVals = '';
	}

	var url          = "index-phpCookie.php";
	var targetID     = '';
	var callbackFunc = '';
	var oData        = {
		cookieNames: cookieNames,
		cookieValues: cookieValues,
		cookieCallback: cookieCallback,
		cookieExpire: cookieDur, 
		cookiePassVals: passVals
	};
	var syncReqFlag  = '';
	sendData(url, targetID, callbackFunc, oData, syncReqFlag);
}

function makeCookie(parameterName, sValue) {
	
			// When should this data expire?
		
	dur = pageDuration;			// Current Page memory expires in 2 hours

	top.phpCookie(parameterName, sValue, '', dur);
}


function readCookie(parameterName) {

	var start = document.cookie.indexOf( parameterName + "=" );

	var len = start + parameterName.length + 1;
	if ( ( !start ) && 	( parameterName != document.cookie.substring( 0, parameterName.length ) ) ) {		// Doesn't exist
		return null;
	}
	if ( start == -1 ) {
		return null;													// Contains no data
	}
	
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) {
		end = document.cookie.length;
	}

		// Cookies replace " " with "+"; fix that...

	var outputString = unescape( document.cookie.substring( len, end ) );

	outputString = outputString.replace(/\+/, " ");
	return outputString;
}

function delCookie(parameterName) {

	// document.cookie = parameterName + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;";
	var cookieValues   = '';
	var cookieCallback = '';
	var cookieDur      = -9000000;
	var passVals       = '';
	phpCookie(parameterName, cookieValues, cookieCallback, cookieDur, passVals);
}


function destroyIfExists() {			// Empty specified DOM object(s) when cookie expires

	var idList = destroyIfExists.arguments;

	var lastID = idList.length;
	var objRef;

	for(i=0; i < lastID; i++) {
		objRef = getObjectByID( idList[i] );

		if ( objRef != null ) {
			objRef.innerHTML="";
		}
	}
}


