<!--
	// ============================================================================================
	// ============================================================================================
	// 
	// 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 = 200;
	var cookieExpiration = 365; //specified in days
	document.cookie = "cookiestatus=enabled; domain=.hypnosisdownloads.com; path=/;";
	// Valid characters that the URL should start with to set the cookie
	var ValidChars = "0123456789";
	
	//==========begin custom for hypnosisdownloads
	var cookiebegin = document.cookie.indexOf('refurl=');
	if(cookiebegin < 0) 
	{
		var rurl = document.referrer;
		cookieExpiration = 1; //this cookie only lasts a day.
		WriteCookie('refurl',rurl);
		cookieExpiration = 365;
	}
	//==========end custom for hypnosisdownloads

	
	
	function GetAffnumCookie()
	{
		var cookiecontent;
		if(document.cookie.length > 0) 
		{
   			var cookiename = 'affnum=';
   			var cookiebegin = document.cookie.indexOf(cookiename);
   			var cookieend = 0;
   			if(cookiebegin > -1) 
   			{
      				cookiebegin += 7;
      				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
		}
		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 + '; domain=.hypnosisdownloads.com; path=/' + exp;
	}


	function PrintAffiliateCode(prefix) 
	{
		var anum = inhouseNumber; //default
		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'; }
		}
		else
		{
			args = location.hash;
			if (args.charAt(0) == '#')
			{
				u_anum = args.substring(1);
				//alert('u_anum=' + u_anum);
				if (u_anum == inhouseNumber) { u_anum = 'none'; }
			}
		}
		
		if (ValidChars.indexOf(u_anum.charAt(0)) != -1) {
			// URL-passed affiliate number takes precedence over cookie
			// affiliate number (except in cases where cookie affnum is inhouse affnum
			// or in any other case when it starts with a non-digit)
			anum = u_anum;
		} 
		else if (c_anum != 'none') {
			anum = c_anum;
		}

		if (anum != inhouseNumber) {
			WriteCookie('affnum',anum);
		}
		//document.write(prefix + anum);
		prefix = prefix.replace(/_AFFNUM_/g, 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>
//-->
