// JS script used to check for Ad Tracker params in the URL.
// If found stored in a cookie to be used later.
// Originally developed for C21T by CR on 5/19/09.
//



//////////////////////////
// Configs

var c_domain = 'century21thomas.com';		// Client's Domain without subdomain
var c_expires = 30;						// Days till cookie will expire

// NO NEED TO EDIT BELOW
/////////////////////////




var adCode = getUrlVars();
//alert("Ad Code: "+adCode);

if(adCode != 0){
	// Set Cookie
	setCookie("adCode",adCode,c_expires,c_domain);
}

// Read Cookie
//var c_adCode = getCookie("adCode");
//alert("Cookie AdCode: "+c_adCode);

function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		if(hash[0] == 'ref'){
			if(hash[1] != ''){
				return hash[1];
			}
			//vars.push(hash[0]);
			//vars[hash[0]] = hash[1];
		}
	}

	return 0;

}

function setCookie(c_name,value,expiredays,domain){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+"; path=/"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+((domain==null) ? "" : "; domain=" + escape ( domain ));
}


function getCookie(c_name){
	if (document.cookie.length>0) {
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1){
		    c_start=c_start + c_name.length+1;
    		c_end=document.cookie.indexOf(";",c_start);
    		if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	}
  	}
	return "";
}