var GB_DONE = false, GB_HEIGHT = 707, GB_WIDTH = 400, GB_TOP = 132;
var maActiveTab, maDefaultStore, oc = (typeof oc != 'undefined') ? encodeURIComponent(oc) : '';
var rpType = (typeof srt != 'undefined') ? srt : '';

function GB_show(url, height, width) {    
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    jQuery(document.body).append("<div id='GB_overlay'></div><div id='ma_wrapper'></div>");
    GB_DONE = true;
  }
  hideSelectBoxes();
  maOverlay();
  jQuery("#GB_overlay").show();
  jQuery("#GB_frame").remove();
  jQuery("#ma_wrapper").append("<iframe id='GB_frame' name='GB_frame' frameborder='0' scrolling='no' allowtransparency='true' width='943' height='709' src='"+url+"'></iframe>");  
  GB_position();   
  jQuery("#ma_wrapper").show();
}

function MA_show() {
	if (document.domain.indexOf("scholastic") != -1) {
   		document.domain = "scholastic." + document.domain.split(".").pop();
    }
	var url = MYACCOUNT_HOST + '/com.scholastic.myaccount.MyAccount/MyAccount.html';
	if (typeof maDefaultStore != "undefined") {
		url += maDefaultStore;
	}	
	if (typeof rpType != "") {
		if (url.indexOf('?') != -1) { url += '&amp;t=' + rpType; }
		else { url += '?t=' + rpType; }		
	}
	if (typeof oc != "") {
		if (url.indexOf('?') != -1) { url += '&amp;oc=' + oc; }
		else { url += '?oc=' + oc; }		
	}
	if (typeof maActiveTab != "undefined") {
		url +=  maActiveTab;
	}
	GB_show(url,614,943);		

	return false;	
}
function MA_showLogin() {
	if (document.domain.indexOf("scholastic") != -1) {
   		document.domain = "scholastic." + document.domain.split(".").pop();
	}
	var url = MYACCOUNT_HOST + '/com.scholastic.myaccount.MyAccount/MyAccount.html?t=lo&amp;oc=' + oc;
	GB_show(url,614,943);	
	return false;	
}

function RP_show() {
	if (document.domain.indexOf("scholastic") != -1) {
   		document.domain = "scholastic." + document.domain.split(".").pop();
	}
	var url = (typeof rpType != 'undefined' && rpType != '') ? '/com.scholastic.registration.Registration/Registration.html?t=' + rpType + '&amp;oc=' + oc : '/com.scholastic.registration.Registration/Registration.html?oc=' + oc;		
	var uri = MYACCOUNT_HOST + url;
	GB_show(uri,614,943);	
	return false;	
}

function setActiveTab(tabName) { maActiveTab = "#" + tabName; }
function setDefaultStore(storeID) { maDefaultStore = "?" + storeID; }
function setRegistrationType(type) {
	rpType = type; /* possible types are: c - clubs, ts - teacher store, lo - login only */
}

var myAccoutCloseHook, onSignOutHook;
function setMyAccountCloseHook(hook){ myAccoutCloseHook = hook; }
function setOnSignOutHook(hook){ onSignOutHook = hook; }

function GB_hide() {
  jQuery("#ma_wrapper,#GB_overlay").hide();
  showSelectBoxes();
  jQuery("#GB_frame").remove();
  if (typeof nodisplay == "undefined") { chkLS(); }
  if (myAccoutCloseHook != null) { myAccoutCloseHook(); }
}

function RP_hide() { GB_hide(); }

function maOverlay() {  
  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  var h = arrayPageSize[1] + arrayPageScroll[1];
  if (h < (GB_HEIGHT + GB_TOP)) { h = GB_HEIGHT + GB_TOP + 10; }
  jQuery("#GB_overlay").css({height: h + 'px'});
}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  jQuery("#ma_wrapper").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: "22px",top: GB_TOP + "px"}); 
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	var arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var pageHeight, pageWidth, xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){ pageHeight = windowHeight; }
	else { pageHeight = yScroll; }

	if(xScroll < windowWidth){ pageWidth = windowWidth; }
	else { pageWidth = xScroll; }
	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "visible"; }
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden"; }
}
document.writeln('<style>#GB_overlay { background-image: url(' + imgRoot + 'overlay.png);position: absolute;margin: auto;top: 0;left: 0;z-index:  1000002;width:  100%;height: 100%;} * html #GB_overlay {background-color: #000;background-color: transparent;background-image: url(' + imgRoot + 'blank.gif);filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + imgRoot + 'overlay.png", sizingMethod="scale");} #ma_wrapper {top: 10px;left: 0px;position: absolute;overflow: hidden;z-index:  1000003;width: 943px;height: 614px;} #GB_frame {border: 0;margin: 0;overflow: hidden;width: 943px;height: 614px;}</style>');