// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function addLoad(fn){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload=fn;
	}else{
		window.onload=function(){
			oldload();
			fn();
		}
	}
	
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


	function checkCookie(){
		var obj =document.getElementById("welcomeinfo");;
		var val = readCookie("username");
		//alert(val);
		if (val ==null || typeof val == "undefined" || val.length == 0){
			obj.innerHTML = "Welcome Click here to <a class='under' href='/login.jhtml'>sign in </a> OR <a class='under' href='/register.jhtml'>register</a>";
		}else{
			 document.getElementById("tipHere").innerHTML = "Hello, " + val + ". <a href='login.jhtml' class='1'>Login</a> <a href='account.jhtml' class='1'>My Preterence</a> (Not " + val + "?<a href='login.jhtml' class='l'>Click Here</a>)";
		}
	}
//addLoad(checkCookie);

