var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
var data = getData();
var ref = getRef();
var id = getID();
var count = getCount();
document.cookie ="date="+(data)+"; path=/; expires="+expiry.toGMTString(); // first visit time
document.cookie ="ref="+(ref)+"; path=/; expires="+expiry.toGMTString(); // ref
document.cookie ="id="+(id)+"; path=/; expires="+expiry.toGMTString(); // user id
document.cookie ="count="+(count)+"; path=/; expires="+expiry.toGMTString(); // page visited

function getData()
{
	var data = GetCookie('date');
	if(data == null)
	{
		var day = today.getDate()+"/";
		var month = today.getMonth()+1+"";
		data = day+month;
	}
	return data;
}

function getRef()
{
	var ref = GetCookie('ref');
	if(ref == null)
	{
		ref = document.referrer;
	}
	return ref;
}

function getID()
{
	var id = GetCookie('id');
	if(id == null)
	{
		id = today.getTime();
	}
	return parseInt(id);
}

function getCount()
{
	var count = GetCookie('count');
	if(count == null)
	{
		return 1;
	}
	else
	{
		var newcount = parseInt(count) + 1;
		return newcount;
	}
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen)
	{
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0)
			break;   
	}  
	return null;
}
function GetRegnowLink(pid,cur)
{
	pid = pid + "";
	var id = GetCookie('id');
	if(id == null)
	{
		var url = "https://www.regnow.com/softsell/nph-softsell.cgi?styleid=5201-8&item=" + pid + "&linkid=null&ordertype=Business";
	}
	else
	{
		var ref = GetCookie('ref');
		if(ref == null)
		{
			var ref2 = "directRequest";
		}
		else
		{
			var ref2 = escape (ref);
		}
		var date = GetCookie('date');
		var count = GetCookie('count');
		var todaydate = getToday();
		var url = "https://www.regnow.com/softsell/nph-softsell.cgi?styleid=5201-8&ordertype=Business&item=" + pid + "&currency="+ cur + "&linkid=" + (todaydate) + "&linkid=" + (date) +  "&linkid=" + (ref2) + "&linkid=" + (count) + "&linkid=" + (id);
	}
	var target = "_self";
	window.open(url,target);
}


function GetRegnowLink1(pid,cur)
{
	pid = pid + "";
	var id = GetCookie('id');
	if(id == null)
	{
		var url = "https://www.regnow.com/softsell/nph-softsell.cgi?styleid=5201-8&item=" + pid + "&linkid=null&ordertype=Personal";
	}
	else
	{
		var ref = GetCookie('ref');
		if(ref == null)
		{
			var ref2 = "directRequest";
		}
		else
		{
			var ref2 = escape (ref);
		}
		var date = GetCookie('date');
		var count = GetCookie('count');
		var todaydate = getToday();
		var url = "https://www.regnow.com/softsell/nph-softsell.cgi?styleid=5201-8&ordertype=Personal&item=" + pid + "&currency="+ cur + "&linkid=" + (todaydate) + "&linkid=" + (date) +  "&linkid=" + (ref2) + "&linkid=" + (count) + "&linkid=" + (id);
	}
	var target = "_self";
	window.open(url,target);
}

function GetShareItLink(pid,cur)
{
	pid = pid + "";
	var id = GetCookie('id');
	if(id == null)
	{
		var url = "https://secure.element5.com/shareit/cart.html?afproducts=1&PRODUCT[" + pid + "]=1&stylefrom=" + pid + "&currencies=" + cur;
	}
	else
	{
		var ref = GetCookie('ref');
		if(ref == null)
		{
			var ref2 = "directRequest";
		}
		else
		{
			var ref2 = escape (ref);
		}
		var date = GetCookie('date');
		var count = GetCookie('count');
		var todaydate = getToday();
		var url = "https://secure.element5.com/shareit/cart.html?afproducts=1&PRODUCT[" + pid + "]=1&stylefrom=" + pid + "&currencies=" + cur +"&HADDITIONAL2[" + pid + "]=" + (todaydate) + "," + (date) +  "," + (ref2) + "," + (count) + "," + (id);
	}
	var target = "_self";
	window.open(url,target);
}

function getToday()
{
	var today = new Date();
	var day = today.getDate()+"/";
	var month = today.getMonth()+1+"";
	data = day+month;
	return data;
}
