/*Cookie Generation*/
// Global variables 
var cv;						// Value of my cookie
var myCookie;		//Name of my cookie
var allCookies;		// Gets all cookies 

function expireDate(nDays) {
	 // nDays														// No. of days in future to expire 
	 var one_second = 1000;						// 1 sec = 1000 milliseconds
	 var one_hour = 3600 * one_second;
	 var one_day = 24 * one_hour;
	 var expire = new Date((new Date()).getTime() + nDays*one_day);
	 return expire.toGMTString();					// Time to expire cookie
}

// Extracts 1st substring in 'myString' bounded by 'delim1' and 'delim2'
// It is OK if the 'delim2' is missing
function extractSubstring(myString, delim1, delim2) {
	var substr1 = myString.split(delim1)
	if (substr1 == myString){
		return -1												// delim1 not found
	}
	var substr2 = substr1[1].split(delim2)
	var len1 = substr1[0].length + delim1.length
	var len2 = substr2[0].length
	return myString.substring(len1, len1+len2)
} 

function storeCookie(t) {
	var cookie = myCookie + '=' + cv + '; expires=' + expireDate(t);
	document.cookie = cookie;
	report.document.write(' cookie => ' + cookie + '<BR>');
} 

function initialize(f) {
	allCookies = document.cookie;
	//report = window.open('','r','width=500,height=200,resizable');
	myCookie = "CitiJapanToppage";
	if (extractSubstring( allCookies, myCookie+'=', ';' ) != "-1"){
		oldcv = extractSubstring( allCookies, myCookie+'=', ';' );
		if (oldcv.indexOf(f) < "0"){
			cv =  f +  "," + oldcv;
		}
		else{
			cv = oldcv;
		}
	}
	else{
		cv = f;
	}
	storeCookie(90);
} 
/**/
