

function download(ElementName)
{
	var sURL;
	
    if(getCookie("serial"))
	{
		sURL = 'http://www.888.com/CasinoInstaller?sr=' + getCookie("serial");
		document.getElementById(ElementName).setAttribute("href",sURL);
	}
	else
	{
	}
}

function getCookie(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));
}


/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function PageQuery(q) 
{
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else 
		this.q = null;
		
	this.keyValuePairs = new Array();
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() 
		{ 
			return this.keyValuePairs; 
		}
	this.getValue = function(s) 
		{
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				if(this.keyValuePairs[j].split("=")[0].toLowerCase() == s.toLowerCase())
				{
					return this.keyValuePairs[j].split("=")[1];
				}
			}
			return false;
		}
	this.getParameters = function() 
		{
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
	this.getLength = function() 
		{ 
			return this.keyValuePairs.length; 
		}	
}

function queryString(key)
{
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}


/***** set cookie *******/

if (queryString("sr") != 'false')
{
	//get serial from querystring
	setCookie("serial", queryString("sr"),null,"/")	
}
else
{ 	

	//if (getCookie("serial") == null)
	//{		 
	//	//get serial from referrer if any, else use default serial.
	//	setCookie("serial", GetSerialByReferrer(),null,"/")	
	//} 	
}

/***************************/