if (!Get_Source_Cookie('source')) {

	var text = window.location.search.substring(1);
	var expdate = new Date ();
	expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // 365 days from now 

	// Referrer is superseded by a source field
	if (document.referrer) {
		var myreferrer = document.referrer;

		var position = myreferrer.indexOf('http://');
		if (position >= 0) {
			var textreferrer = myreferrer.substring(position+7);
		}

	

		position = textreferrer.indexOf('/');
		if (position >= 0) {
			textreferrer = textreferrer.substring(0,position);
		}
	


		position = textreferrer.indexOf('www.');
		if (position >= 0) {
			textreferrer = textreferrer.substring(position+4);
		}

	

		if (textreferrer) {
			Set_Source_Cookie('source',textreferrer,expdate,'/');
		}

	}
	
	var source = text.indexOf('source=');
	if (source >= 0) {
		var sourcecode = text.substring(source+7);
		Set_Source_Cookie('source',sourcecode,expdate,'/');
	}
	
	var nma = text.indexOf('nma=');
	if (nma >= 0) {
		var nmacode = text.substring(nma+4);
		Set_Source_Cookie('source',nmacode,expdate,'/');
	}
} 


function Get_Source_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Source_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}
