function createCookie(name,value,minutes) {
	var expires = "";
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
	// alert("Created Cookie: " + name+"="+value+expires+"; path=/");
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var sRet = "";
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			sRet = c.substring(nameEQ.length,c.length)
		}
	}
	return sRet;
}

function sGetThisScrollObj() {

	oColRight = document.getElementById('column_right');
	oColSingle = document.getElementById('single_column');
	oPopup = document.getElementById('faux_popup_content');
	
	if (oColRight != null) {
		return "column_right";
	} else if (oColSingle != null) {
		return "single_column";
	} else if (oPopup != null) {
		return "faux_popup_content";
	}
	
	return "";
	
}

function sGetThisId(sXY) {
	var sLoc = location.href;
	sLoc = sLoc.replace(/\//g,"-");
	sLoc = sLoc.replace(/:/g,"-");
	return sGetThisScrollObj() + "-" + sLoc + "-" + sXY;
}

function sGetReferrer() {
	var sReferrer = "";
	if (document.referrer != "" && document.referrer != null) {
		sReferrer = document.referrer;
	}
	return sReferrer;
}

function loadStuff() {

	// alert("Loading");
	
	// alert("ReadX: " + readCookie(sGetThisId("x")) + " ReadY: " + readCookie(sGetThisId("y")));
	
	// alert("Referrer: " + sGetReferrer() + " Saved Refer: " + readCookie(sGetThisId("h")));
	
	
	// if (sGetReferrer() == readCookie(sGetThisId("h"))) {
	
		obj = document.getElementById(sGetThisScrollObj());
		obj.scrollTop=readCookie(sGetThisId("y"));
		obj.srollLeft=readCookie(sGetThisId("x"));
	
	// }

	if (document.login) {
		document.login.userName.focus();
	}


}

function unloadStuff() {
	
	// save the scroll vals into a cookie
	sHid = sGetThisId("h");
	sXid = sGetThisId("x");
	sYid = sGetThisId("y");

	// createCookie(sHid,"test",15);
	// alert("Y=" + document.getElementById(sGetThisScrollObj()).scrollTop + " ID: " + sYid);
	createCookie(sYid,document.getElementById(sGetThisScrollObj()).scrollTop,15);
	createCookie(sXid,document.getElementById(sGetThisScrollObj()).scrollLeft,15);

}