/***********************************************************************************************************
	bowser.js - this contains routines to support click-through tracking by cookies
	
	Author:		Charles Alexander
	
	Created:	10/1/2001

***********************************************************************************************************/

/***********************************************************************
	GetCookie - extracts a single key-value combination from the 
				cookie string
	
	PARAMETERS:
	
		name - the key name to search for
		
	RETURNS:
	
		either the key value or nothing
		
************************************************************************/

function GetCookie(name) {
	var cookieString = document.cookie;			// get the cookie string
	var newArray = cookieString.split(/;\s/);	// break it down by key-values
	var itemCount = newArray.length;			// how many do we have?
	
	for (var i = 0; i < newArray.length; i++) {	
		var nameString = newArray[i];			// examine each key-value combination
		var nameArray = nameString.split("=");	// separate the key from the value

		if (nameArray[0] == name)				// if this is the key we are looking for...
			return nameArray[1];				// ...return its value
	}
	return "";									// otherwise, return nothing
}

/***********************************************************************
	SetCookie - creates or resets a given cookie

	PARAMETERS:
	
		name    - the key name to create or reset
		
		value   - the value to put there
		
		expires	- how long it will last
		
		path	- where it will have an effect
		
		domain	- how many servers are involved

************************************************************************/
function SetCookie(name, value, expires, path, domain) {
	
	document.cookie = name + "=" + escape(value) +
  		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "");
}

/***********************************************************************
	setGUID - creates a unique identifier for the cookie value.  It
			  uses a combination of the current time and a large random
			  number.
	
	RETURNS:
	
		the unique identifier
	
************************************************************************/

function setGUID() {
	var today = new Date();
	var GUID;
	
	GUID = (today.getTime() * 10000) + (Math.round(Math.random() * 9999) + 1);
	return GUID;
}

/***********************************************************************
	TodayPlusAYear - calculates a date one full year in the future
	
	RETURNS:
	
		a Date object with the future date
	
************************************************************************/

function TodayPlusAYear() {
	var today = new Date();
	var targetDate = new Date();

	targetDate.setTime(today.getTime() + (1000 * 60 * 60 * 24 * 365));
	return targetDate;
}

/***********************************************************************
	Dog - this is our watchdog routine.  It either creates or resets
		  a cookie named POL.
		  
************************************************************************/

function Dog() {
	var cookieVal = GetCookie("POL");
	var GUID;
	
	if (cookieVal == "") 
		GUID = setGUID();
	else
		GUID = cookieVal;
		
	SetCookie ("POL", GUID, TodayPlusAYear(), "/", ".panasonic.com");
}



