function checkcookie()
{
	if(GetCookie("vmdiscount") != null)
	{
		repid = GetCookie('vmdiscount');
		url = "http://www.visual-mind.com/ordervm.htm?" + repid;
		window.open(url, "_self");
	}
}

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 SetCookie (name, value)
{ 
	var setvalue = false;
	if(value == null)
		setvalue = true;
	else if(value == "")
		setvalue = true;
	else if(GetCookie(name) == null)
		setvalue = true;
		
	if(setvalue == true)
	{
		var expires = new Date();
		expires.setYear(2010);
		full = name + "=" + escape (value) + "; expires=" + expires.toGMTString() + "; path=/;domain=www.visual-mind.com";
		document.cookie = full;
	}
}

function ExtractRepIDFromURL()
{
	var RepID = window.location.search;
	var len = RepID.length;
	if(len > 4)
		len = 4;
	RepID = RepID . substring (1, len+1);
	return RepID;
}

function addpidtoaddress()
{
	repid = GetCookie('pid');	
	if(GetCookie("pid") == null)
	{
		SetCookie("pid", 0);
	}
	
	var full = window.location.search;
	var full2 = full. substring (1, full.length);
	if(full2 == "")
	{
		if(GetCookie("pid") != null)
		{
			repid = GetCookie('pid');
			url = window.location + "?" + repid;
			window.open(url, "_self");
		}
	}
}

function addpidtoaddresstest()
{
	alert("Checking pid");
	repid = GetCookie('pid');	
	alert("pid = " + repid);
	if(GetCookie("pid") == null)
	{
		alert("Setting pid to 0");
		SetCookie("pid", 0);
	}
	
	var full = window.location.search;
	var full2 = full. substring (1, full.length);
	alert("full2 = " + full2);
	if(full2 == "")
	{
		alert("Checking pid again");
		repid = GetCookie('pid');	
		alert("pid = " + repid);
		if(GetCookie("pid") != null)
		{
			repid = GetCookie('pid');
			url = window.location + "?" + repid;
			alert("redirecting to " + url);
			window.open(url, "_self");
		}
	}
}

function AddURLAddOnItem(currentstring, cookiename, cookieprefix)
{
	cookievalue = GetCookie(cookiename);
	if(GetCookie(cookiename) == null)
	{
		sReturn = currentstring;		
	}
	else
	{
		if(currentstring == "")
			toadd = cookieprefix + cookievalue;
		else
			toadd = "_" + cookieprefix + cookievalue;
		sReturn = currentstring + toadd;
	}
	return sReturn;
}

function GetURLAddons()
{
	addon = '';
	addon = AddURLAddOnItem(addon, "pid", "0");
	addon = AddURLAddOnItem(addon, "homepagevariant", "1");
	return addon;
}

function GetRedirectURL(page)
{
	addons = GetURLAddons();
	return page + "?" + addons;
}

function RedirectWithAddOn(page)
{
	url = GetRedirectURL(page);
	window.open(url, "_self");
	//document.write(url);
}

function GenerateLinkWithAddOn(page, text)
{
	url = GetRedirectURL(page);
	code = '<a href="' + url + '"' +' >' + text + '</a>';
	//alert(code);
	document.write(code);
}

