
function createCookie(CookieName,CookieValue,days)
{	
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		document.cookie = CookieName+"="+CookieValue+expires+"; path=/";
	}
}

function get_random(seed)
{
    var randNum= Math.floor(Math.random()*seed);
    return randNum;
}


// getting the gipid cookie

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookieValueGipId(name)
{
	var theDate = new Date();
	var gipid = "";
	var txtRandSeed1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var txtRandSeed2 = "¬!£$%^&*()_+=-[]{}#~:./?><\|";
	var txtRandSeed3 = "abcdefghijklmnopqrstuvwxyz";
	var txtRandSeed4 = "0123456789";

	gipid += txtRandSeed1.charAt(get_random(26));
	gipid += txtRandSeed2.charAt(get_random(26));
	gipid += txtRandSeed3.charAt(get_random(26));
	gipid += txtRandSeed4.charAt(get_random(10));
	gipid += theDate.getTime();
	gipid += gipid.charAt(get_random(10));
	gipid += txtRandSeed1.charAt(get_random(26));
	gipid += txtRandSeed2.charAt(get_random(26));
	gipid += txtRandSeed3.charAt(get_random(26));
	gipid += txtRandSeed4.charAt(get_random(10));
	gipid += theDate.getTime();
	gipid += gipid.charAt(get_random(15));

	return gipid;

}


function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

var gip= getCookieValueGipId('gipid');
var x = getCookieValue('webAnalyticsCookie');

//cookie creation
if (x==false)
{ 
	var theDate = new Date();
	var x = theDate.getYear();
	var y = x % 100;
	//year epoch funda
	y += (y > 69) ? 1900 : 2000;
	//month
	var month =theDate.getMonth();
	var date =theDate.getDate();
	var day =theDate.getDay();
	var hours= theDate.getHours();
	var minutes=theDate.getMinutes();
	var seconds =theDate.getSeconds();
	// String to be concatenated with the gipid
	var timeStamp=y+"|"+month+"|"+date+"|"+day+"|"+hours+"|"+minutes+"|"+seconds+"@";
	var ckValue=timeStamp+gip;
	createCookie("webAnalyticsCookie",ckValue,"730");
}


