// JavaScript Document

var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = function()
		{
			append_query_string();
		}
	} else {
		window.onload = function() {
		oldonload();
		append_query_string();
	}
}


function append_query_string()
{
	var apvalue=GetParam('ap');
	var aidvalue=GetParam('aid');
	var host = document.location.host;
	var cam_host = 'accounts.comodo.com/cfp/management/signup';
	if(apvalue != "")
	{
		a_href = document.getElementsByTagName("a");
		for(i=0;i<a_href.length;i++)
		{
			linkurl = a_href[i].href;
			if(linkurl.indexOf("://" + host)!= -1)
			{
				if(linkurl.indexOf("?") != -1)
				{
					a_href[i].href = a_href[i].href + "&ap=" + apvalue;
				}
				else
				{
					a_href[i].href = a_href[i].href + "?ap=" + apvalue;
				}
			}
			if(linkurl.indexOf("://" + cam_host)!= -1)
			{
				if(linkurl.indexOf("?") != -1)
				{
					a_href[i].href = a_href[i].href + "&ap=" + apvalue;
				}
				else
				{
					a_href[i].href = a_href[i].href + "?ap=" + apvalue;
				}	
			}
		}
	}
	
	
	if(aidvalue != "")
	{
		a_href = document.getElementsByTagName("a");
		for(i=0;i<a_href.length;i++)
		{
			linkurl = a_href[i].href;
			if(linkurl.indexOf("://" + host)!= -1)
			{
				if(linkurl.indexOf("?") != -1)
				{
					a_href[i].href = a_href[i].href + "&aid=" + aidvalue;
				}
				else
				{
					a_href[i].href = a_href[i].href + "?aid=" + aidvalue;
				}
			}
			if(linkurl.indexOf("://" + cam_host)!= -1)
			{
				if(linkurl.indexOf("?") != -1)
				{
					a_href[i].href = a_href[i].href + "&aid=" + aidvalue;
				}
				else
				{
					a_href[i].href = a_href[i].href + "?aid=" + aidvalue;
				}	
			}
		}
	}
	
}

function GetParam(name){ /*Returns values from location urls and assigns to reference variable*/
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
	if (start<0) return '';
	start += name.length+2;
	var end=location.search.indexOf("&",start)-1;
	if (end<0) end=location.search.length;
	var result=location.search.substring(start,end);
	var result='';
	for(var i=start;i<=end;i++) {
	var c=location.search.charAt(i);
	result=result+(c=='+'?' ':c);}
	return unescape(result);
}

