
function G_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.G_p) d.G_p=new Array();
    var i,j=d.G_p.length,a=G_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.G_p[j]=new Image; d.G_p[j++].src=a[i];}}
}

function G_swapImage() { //v3.0
  var i,j=0,x,a=G_swapImage.arguments; document.G_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=G_findObj(a[i]))!=null){document.G_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function G_swapImgRestore() { //v3.0
  var i,x,a=document.G_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function G_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=G_findObj(n,d.layers[i].document); return x;
}

function G_pop(path,name,features) {
	popWindow = window.open(path,name,features);
	popWindow.focus();
}

//schl nav search
function formSubmit(){
	document.SearchForm.QueryText.value = document.SearchForm.query.value;
	document.SearchForm.submit();
}

function validateNavSearch(){
	if(document.SearchForm.query.value == "Enter Search Term" || document.SearchForm.query.value == "") {
		//document.SearchForm.query.value = "Type your search term here";
		return false;
	}
	else {
		return true;	
	}
}

function validateSearch(){
	if(document.searchForm.query.value == "") {
		//document.SearchForm.query.value = "Type your search term here";
		return false;
	}
	else {
		return true;	
	}
}
function hook2NewSearch() {
	if (!document.searchForm) return;
	document.searchForm.onsubmit = function() {
		if (document.searchForm.query.value == "")
		{
			return false;
		}	
		else {
			return true;
		}
	};
}


function cls(field){
	if (field.value == "Enter Search Term") field.value = "";
}

function cls9 ( field, term ) {
	if ( field.value == term ) field.value = "";	
}

function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) return pair[1];    
  }   
}

function setAdvert(){}

var axel = Math.random() + "";
var ord = axel * 1000000000000000000;



function positionAds() {
	curobj = document.getElementById('ScholasticLogo');
	obj = document.getElementById('schlSkyscraper');

	if(curobj && obj) {
		x = curobj.offsetWidth;
		y = getposOffset(curobj, "top");
		x2 = getposOffset(curobj, "left");
		x2 += x + 195;
		y -= 10;
		
		obj.style.display = "block";
		obj.style.left = x2 + "px";
		obj.style.top = y + "px";
	}
}


if ( (typeof newWrapper == "undefined") || !newWrapper ) window.onresize = positionAds;

function openMediaPlayer(url) {
window.open(url,'media','width=400,height=400,scrollbars=no,resizable=no,menubar=no,toolbar=no,location=no');
}

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="/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><a href="https://my.scholastic.com/sps_my_account/accmgmt/GenericSignin.jsp?finalSuccessURL=http://www.scholastic.com">Why Register?</a></li>');
		//document.write('<li>|</li>');
		document.write('<li class="first"><img src="/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="/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="/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="/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();
		}
	}
}

var schlLeadBtm = {
	display : false,
	url : null
};

var dctile = 0;

addLoadEvent(hook2NewSearch);