<!--
/*
Code generated by NSK & Associates for Carney Sandoe to monitor site usage
*/
var urlref="";

//Identifies whether or not the user has been to the site before, if not it records the referring site.
//This is ran automatically
//eg http://www.google.com or if the user
function createReferrer(){
	if (GetCookie("referreringSite")){
		urlref = GetCookie("referreringSite");
	} else {
		if (document.referrer != ''){
			urlref = document.referrer
			SetCookie("referreringSite", urlref)
		}
	}
}

//This function is for any link to the back end Carney Sandoe server, and works by concatenating the referring url onto the http link and then changes the current page to that page.
//eg. createLink("mypage.a4d") will redirect the page to
//mypage.a4d?ref=http%3A//www.google.com/?search=abc
function createLink(mydoc){
	if (mydoc.indexOf("?") != -1){
		location.href=mydoc + "&ref=" + escape(urlref)
	}else{
		location.href=mydoc + "?ref=" + escape(urlref)
	}
}

//This gets the referring urls link for your custom use
//NB this is not escaped and as such, if used will 
//eg http://www.google.com
function getLink(){
	return urlref;
}

//This gets the referring urls link for your custom use and does escape that string.
//eg ref=www.google.com
function getURLLink(){
	return "ref=" + escape(urlref)
}

//This resets the cookie, for testing
function resetCookie(){
	urlref = ""
	SetCookie("referreringSite", urlref)
}

//This saves the appropriate information to a cookie
function SetCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	var nDays;
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*300);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}


function refWindow(wUrl, wOptions){
            if (wUrl.indexOf("?") != -1){
                        wUrl=wUrl + "&ref=" + escape(urlref);
            }
            else{
                        wUrl=wUrl + "?ref=" + escape(urlref);
            }
            var mywindow = window.open(wUrl, null, wOptions);
            mywindow.focus();
}




//This gets the appropriate information from a cookie
function GetCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}else{
		if ( start != -1 ){
			var end = document.cookie.indexOf( ";", len );
			if ( end == -1 ){
				end = document.cookie.length;
			}
			return unescape( document.cookie.substring( len, end ) );
		}
	}
}
createReferrer()
//-->