
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=/";
	}
}

// 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 dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


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");
}

