var str = window.location.search.substring(1);

function printUrl(address)
{
	var rExp, newstr;
	
	rExp = /\[id\]/gi;
	if (str =="")
	{	
		str="xxxxxx";
		newstr2 = address.replace(rExp, str);
		str="";
	}
	else
	{
		newstr2 = address.replace(rExp, str);
	}
	document.write(newstr2);
}

function getUrl(address)
{
	var rExp, newstr;
	
	rExp = /\[id\]/gi;
	if (str =="")
	{	
		str="xxxxxx";
		newstr2 = address.replace(rExp, str);
		str="";
	}
	else
	{
		newstr2 = address.replace(rExp, str);
	}
	return newstr2;
}

function printLink(address)
{
	var rExp, newstr;
	
	rExp = /\[id\]/gi;
	if (str =="")
	{	
		str="xxxxxx";
		newstr2 = address.replace(rExp, str);
		str="";
	}
	else
	{
		newstr2 = address.replace(rExp, str);
	}
	document.write('<a href="'+newstr2+'" target=_blank>'+newstr2+'</a>');
}
function goUrl(address)
{
	var rExp, newstr;
	rExp = /\[id\]/gi;
	if (str =="")
	{	
		document.location.href=	address	
	}
	else
	{
		newstr=address +"?"+str;
		document.location.href=	newstr;
	}
	return false;
}

function subform (theform)
{
	var aff=theform.affid.value;
	var aff="?"+aff;
	document.location.href=aff;
	return false;
}

function printform()
{
	if (str=="")
	{
		document.write("Insert your ClickBank \"nickname\" in the FORM below, click submit, and your links will be customized automatically:<br>");
		document.write('<form onsubmit="return subform(this)">');
		document.write('<input type=text name=affid><input type=submit value=Submit>');
		document.write('</form>');
	}
	else
	{
		document.write('We show your affiliate ID as: <font color=red><b>'+str+'</b></font><br>If this ID is incorrect, <a href="#" onclick="return changeId()">Click Here</a><br>');
	}
	
}
function printUrl2(address)
{
	//It only prints the url if there is an affiliate ID
	var rExp, newstr;
	
	rExp = /\[id\]/gi;
	if (str =="")
	{	
		str="xxxxxx";
		newstr2 = address.replace(rExp, str);
		str="";
	}
	else
	{
		newstr2 = address.replace(rExp, str);
	}
	if (str !="")
	{
		document.write('Your Affiliate link: <font color=red size=+1><b>'+newstr2+"</b></font>");
	}
}

function printText(txt,txt2)
{
	if (str =='')
	{
	document.write(txt);
	}
	else
	{
	document.write(txt2);
	}
}
function changeId()
{
	str="";
	goUrl("?");
	return false;
}
	