function openWindow( URL, WindowName, Width, Height, Scroll, Top, Left, Resizable ) {
   newWindow = window.open( URL, WindowName, 'width=' + Width + ',height=' + Height + ', scrollbars=' + Scroll + ',top=' + Top + ',Left=' + Left + ',resizable=' + Resizable );
}

function addToLink( key, val )
{
	for ( n=0;n<document.links.length;n++ )
	{
		
		var anchor = getAnchor(document.links[n].href);
		
		var ref = new String( document.links[n].href );
		
		if ( ref.indexOf("#") > -1 )
		{
			ref = ref.substring(0,ref.indexOf("#"));
		}
		
	
		ref = ref.replace( "?" + key + "=" + querystring( key), "" );
		

		if ( ref.indexOf("?") == -1 )
		{
			document.links[n].href =  ref + "?" + key + "=" + val + anchor;
		}
		else
		{
			document.links[n].href =  ref + "&" + key + "=" + val + anchor;
		}
		
		
	}
	
	
}
function querystring(name)
{
   var tmp = ( location.search.substring(1) );
   var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
   var ret = "";
   
   if ( i >= 0 )
   {
      tmp = tmp.substring( name.length+i+1 );
      i = tmp.indexOf("&");
      
      ret = new String( unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length )));
      
      
   }

   return(ret);
}

function getAnchor(tmp)
{

   var i   = tmp.indexOf("#");
   
   var ret = "";
   
   if ( i >= 0 )
   {
      ret = tmp.substring(i,tmp.length);
      
   }

   return(ret);
}

function updateLinks()
{
	if ( querystring("ref_code") != "" )
	{
		addToLink("ref_code", querystring("ref_code") );
	}
}

window.onload = updateLinks;
