

function ReadAffiliateID() {
	var expDays = 30; // number of days the cookie should last
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 
	var path = '/';
	var domain = 'www.reitools.com';
	var id = GetCookie('AffiliateID');
	//alert('ID = ' + id);
	if (id == null || id == "None") {
		if (location.search.length > 1) {
				//alert('Setting ID from location');
				id = location.search.substring(1, location.search.length);
			}
		else {
				//alert('Setting ID to None');
				id = "None";
			}
		if (id != GetCookie('AffiliateID')){ 				
				//alert('Setting Cookie using variables: ' + id + ', ' + expDate + ', ' + path + ', ' + domain);
				SetCookie('AffiliateID', id, expDate, path, domain);
			}
		}

	// You can change the FORM location below
	// where the referral ID is stored on your page
	// You then access this element to get the ID
		
	//alert('AffiliateID: ' + id + '\nReferrer: ' + document.referrer);
	
	//Set the merchant ID and refer to it later
	//document.idform.id.value = id;

	}
function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
	}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
		if (document.cookie.substring(i,j) == arg)      
			return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) 
			break;   
	}  
	return null;
	}
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

