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);
}
var sso = readCookie('ssCartInfo');
var tso = readCookie('tsCartInfo');
var sah = readCookie('shCartInfo');
var personal = readCookie('SPS_UD');



if ( sso ) {
	sso = sso.split('|')[0];
	sso = sso.substring(0,sso.length-1);
}
if ( tso ) {
	tso = tso.split('|')[0];
	tso = tso.substring(0,tso.length-1);
}
if ( sah ) {
	sah = sah.split('|')[0];
	sah = sah.substring(0,sah.length-1);
}
if ( personal )
{
	var temp = personal.split('|');
	personal = (temp[2] + ' ' + temp[3]).toLowerCase();
}

function displayTopLinks() {
	document.write('<ul class="right">');
	if ( personal ) {
		document.write('<li class="first"><img src="/cool_images/nav3.o/arrow_white.gif" alt="" width="4" height="9" border="0" /> <a href="https://my.scholastic.com/sps_my_account/accmgmt/GenericSignin.jsp?finalSuccessURL=http://www.scholastic.com">Sign Out</a></li>');
		document.write('<li>&nbsp;</li>');
		document.write('<li class="ma"><a href="https://my.scholastic.com/sps_my_account/accmgmt/MyAccount.jsp">My Account</a></li>');
	}
	else {
		document.write('<li class="first"><img src="/cool_images/nav3.o/arrow_white.gif" alt="" width="4" height="9" border="0" /> <a href="https://my.scholastic.com/sps_my_account/accmgmt/GenericSignin.jsp?finalSuccessURL=http://www.scholastic.com">Sign In / Register</a></li>');
		document.write('<li>&nbsp;</li>');
		document.write('<li class="ma"><a href="https://my.scholastic.com/sps_my_account/accmgmt/MyAccount.jsp">My Account</a></li>');
	}
	document.write('</ul>');
}

function personalize() {
	obj = document.getElementById("personalized");
	if ( !obj ) return;
	
	if ( personal ) {
	obj.innerHTML = '<strong>Welcome Back <span class="schlName">' + personal + '</span></strong> <a href="https://my.scholastic.com/sps_my_account/accmgmt/GenericSignin.jsp">Not <span class="schlName">' + personal +'?</span></a>';
	}
}

function displayNumOfCartItems(store) {
	if ( store == "sahCart") {
		if ( sah ) {
			document.write('<br /><a href="http://homeclubs.scholastic.com"><img src="/cool_images/nav3.o/iconCart.gif" alt="" width="12" height="12" border="0" /></a> <a href="http://homeclubs.scholastic.com" class="small">' + sah + '</a>');
		}
	}
	else if ( store == "ssoCart" ) {
		if ( sso ) {
		document.write('<br /><a href="http://www.scholastic.com/scholasticstore"><img src="/cool_images/nav3.o/iconCart.gif" alt="" width="12" height="12" border="0" /></a> <a href="http://www.scholastic.com/scholasticstore" class="small">' + sso + '</a>');
		}
	}
	else if ( store == "tsoCart" ) {
		if ( tso ) {
		document.write('<br /><a href="http://www.scholastic.com/teacherstore"><img src="/cool_images/nav3.o/iconCart.gif" alt="" width="12" height="12" border="0" /></a> <a href="http://www.scholastic.com/teacherstore" class="small">' + tso + '</a>');
		}
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}