<!--
	// ============================================================================================
	// ============================================================================================
	// 
	// This Javascript Code is part of the Synergyx (http://www.synergyx.com) affiliate tracking 
	// system, and is used for tracking affiliates across multiple domains.
	//
	// This code is Copyright 2002, Paul Galloway. All Rights Reserved
	//
	// Use of this code in part or in full is expressly forbidden except by 
	// written permission from Paul Galloway, paulg@palis.com
	//
	// ============================================================================================
	// ============================================================================================
	
	var inhouseNumber = 10000;
	var sgx_anum = inhouseNumber; //default
	var cookieExpiration = 365; //specified in days
	
	function GetAffnumCookie()
	{
		var cookiecontent;
		if(document.cookie.length > 0) 
		{
   			var cookiename = 'pgjvp=';
   			var cookiebegin = document.cookie.indexOf(cookiename);
   			var cookieend = 0;
   			if(cookiebegin > -1) 
   			{
      				cookiebegin += 6;
      				cookieend = document.cookie.indexOf(";",cookiebegin);
      				if(cookieend < cookiebegin) 
      				{ 
      					cookieend = document.cookie.length; 
				}
				cookiecontent = document.cookie.substring(cookiebegin,cookieend);
			}
			else { cookiecontent = 'none'; }
		}
		else { cookiecontent = 'none'; }
		
		if (cookiecontent == inhouseNumber) 
		{ 
			cookiecontent = 'none'; //want to ignore in-house affiliate number in favor of REAL affiliate number
		}
		
		cookiecontent = cookiecontent.replace(/\%(25)*21/, "!");
		return cookiecontent;
	}
	
	
	function WriteCookie(name,value) 
	{
		var exp = '';
		var today = new Date();
		var expdate = today.getTime() + (cookieExpiration * 24 * 60 * 60 * 1000);
		today.setTime(expdate);
		exp = '; expires=' + today.toGMTString();
		document.cookie = name + "=" + value + '; path=/' + exp;
		//document.cookie = name + "=" + value + '; path=/; domain=.surefiremarketing.com' + exp;
	}


	function PrintAffiliateCode(prefix) 
	{
		var u_anum = 'none'; //Affnum in URL
		var c_anum = GetAffnumCookie(); // Affnum in Cookie -- is set to 'none' if cookie affnum is inhouseNumber

		var args = location.search;
		if (args.charAt(0) == '?')
		{
			u_anum = args.substring(1);
			//alert('u_anum=' + u_anum);
			if (u_anum == inhouseNumber) { u_anum = 'none'; }
		}

		u_anum = u_anum.replace(/\%(25)*21/, "!");
		c_anum = c_anum.replace(/\%(25)*21/, "!");
		
		if (u_anum != 'none') { sgx_anum = u_anum; } //URL-passed affiliate number takes precedence over cookie affiliate number (except in cases where cookie affnum is inhouse affnum)
		else if (c_anum != 'none') { sgx_anum = c_anum; }

		if (sgx_anum != inhouseNumber) { WriteCookie('affnum',sgx_anum); }
		//document.write(prefix + sgx_anum);
		prefix = prefix.replace(/_AFFNUM_/g, sgx_anum);
		document.write(prefix);
	}
	// Insert this anywhere in your page where you want the affiliate number to show up
	//  <SCRIPT Language="Javascript" type=text/javascript>PrintAffiliateCode('Affnum is _AFFNUM_');</SCRIPT>
//-->
