// Scholastic Teacher Store
// main javascript functions
// (c) 2001 j.blecher / digital pulp

// BEGIN ###############################################################
// code to adjust nav links via DOM

var dom = (document.getElementById) ? true : false;
var mOverClass = "mainNavCellBg1";
var mOutClass = "mainNavCellBg0";
var mOverLinksContainer = "mainNavCell";


function highlight(td) {
  if (dom) {
//    var theDiv = a.parentNode;
//    var theTd = theDiv.parentNode;
//  alert(td.className);
    td.className = mOverClass;
    }
  }

function unhighlight(td) {
  if (dom) {
//    var theDiv = a.parentNode;
//    var theTd = theDiv.parentNode;
    td.className = mOutClass;
    }
  }


function init() {
  var allLinks = document.getElementsByTagName("A");

  for (var i=0; i<allLinks.length; i++) {
    var par = allLinks[i].parentNode;
    var grandPar = par.parentNode;
    if (grandPar.className.indexOf(mOverLinksContainer) != -1) {
      grandPar.setAttribute("onmouseover", "highlight(this)");
      grandPar.setAttribute("onmouseout", "unhighlight(this)");
//      alert(allLinks[i].getAttribute("href"));
      grandPar.setAttribute("onclick", "window.location.href='" + allLinks[i].getAttribute("href") + "'");
      allLinks[i].removeAttribute("href");
      }
    }
  }

// if (dom) window.onload = init;
// END -----------------------------------------------------------------

window.onload = loadEvents;

function loadEvents()
{
	try
	{
		var digitalDownloadLink = document.getElementById("DigitalDeliveryLink");
		digitalDownloadLink.onclick = function(event)
		{
			openHelp('11','DigitalDownload'); 
			return false;
		}
	}
	catch(e){}

}

// BEGIN ###############################################################
// code to open help window

var helpWin;
function openHelp(section, poundDown) {
  var helpPages = new Array();
  var page = "http://" + window.location.host + "/content/stores/teacherstore/custserv/help/index.html";
  
  helpPages[0] = "search_browse.html";
  helpPages[1] = "ordering.html";
  helpPages[2] = "registration.html";
  helpPages[3] = "privacy_security.html";
  helpPages[4] = "using_my_acct.html";
  helpPages[5] = "order_status_ship.html";
  helpPages[6] = "faq.html";
  helpPages[7] = "http://" + window.location.host + "/webapp/wcs/stores/servlet/TSContactUsView?langId=-1&storeId=10001&catalogId=10002";
  helpPages[8] = "bonus-points.html";
  helpPages[9] = "returning_order.html";
  helpPages[10] = "po.html";
  helpPages[11] = "DigitalProducts.html";
  
	  // pass the help section and poundDown if we receive it from caller
	  if(section != 7)
	  {
			poundDown = (poundDown == null) ? "" : "#" + poundDown;
			page += (section == null) ? "" : "?" + helpPages[section] + poundDown;
			helpWin = window.open(page, "helpWindow", "width=550,height=400,toolbar=no");
	  }
	  else
	  {
	  	popContactUsForm(helpPages[section]);
	  	return false;
	  }  
  }


// END -----------------------------------------------------------------

// BEGIN ###############################################################
// code to open Need help window

var helpWin;
function openNeedHelp(section, poundDown, serverName) {
  
  var helpPages = new Array();
  // alert("serverName" +serverName);
  var page = "http://" + window.location.host + "/content/stores/teacherstore/custserv/help/index.html";
  

  helpPages[0] = "search_browse.html";
  helpPages[1] = "ordering.html";
  helpPages[2] = "registration.html";
  helpPages[3] = "privacy_security.html";
  helpPages[4] = "using_my_acct.html";
  helpPages[5] = "order_status_ship.html";
  helpPages[6] = "faq.html";
  helpPages[7] = "http://" + window.location.host + "/webapp/wcs/stores/servlet/TSContactUsView?langId=-1&storeId=10001&catalogId=10002";
  helpPages[8] = "bonus-points.html";
  helpPages[9] = "returning_order.html";
  helpPages[10] = "po.html";
  helpPages[11] = "DigitalProducts.html";  

	  // pass the help section and poundDown if we receive it from caller
	  if(section != 7)
	  {
			poundDown = (poundDown == null) ? "" : "#" + poundDown;
			page += (section == null) ? "" : "?" + helpPages[section] + poundDown;
			helpWin = window.open(page, "helpWindow", "width=550,height=400,toolbar=no");
	  }
	  else
	  {
	  	popContactUsForm(helpPages[section]);
	  	return false;
	  }  

  }


// END -----------------------------------------------------------------



// BEGIN ###############################################################
// code to pop enlarged prod window

var prodWin;

function enlargeProd(url) {
  var height = 390;
  var width = 620;
  prodWin = window.open(url, "enlargedProdWin", "width=" + width+ ",height=" + height + ",toolbars=no");
  }

// END -----------------------------------------------------------------

// BEGIN ###############################################################
// LexileGRLevels

var levelsWin;

function showLevel() {
  var height = 309;
  var width = 401;
  var urlImg  = "/content/stores/teacherstore/promo/level_popup.htm";
  levelsWin = window.open(urlImg,"levelsWin","width=" + width+ ",height=" + height + ",scrollbars=yes,toolbars=no");
  }

// END -----------------------------------------------------------------

// BEGIN ###############################################################
// code for help window

function closeAndGoto(page) {
//  alert(top.window.opener.location.href);
  top.window.opener.location.href = page;
  top.close();
  }

// END -----------------------------------------------------------------

// BEGIN ###############################################################
// code to make sure a user only presses a button once

var i=0;
function checkFirst() {
    if (i==0) {
      i++;
      return true;
    }
    else {
      return false;
    }
  }

// END -----------------------------------------------------------------

/**
 * function is used to pop up "Email a link" form for user to email recommended URL to friends
 * the link to be sent is embedded in the form as hidden value with name=target
 */
var newWin;
function popEmailForm(form) {


  var target = form.target.value;
	target = escape(target);
  // the email link form for user to fill out name, email address, and message
  var url = form.emailform.value;
  url += "?target=" + target;

  url = unescape(url);
  
  newWin = window.open(url,"MyWindow","toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600,left=20,top=20");
  return false;
}

/**
 * function is used to pop up "Email a link" form for user to email recommended URL to friends
 * the link to be sent is embedded in the form as hidden value with name=target
 */
 var contactWin;
function popContactUsForm(url) {

  var page = url;
  contactWin = window.open(page,"ContactUsWindow","toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600,left=20,top=20");
}

// BEGIN ###############################################################
// code to open collateral pop up window

var collatWin;
function popProductCollateral(url) {
  
  var page = url;
  collatWin = window.open(page, "productCollateral", "titlebar=no,toolbars=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500");
  }

// END -----------------------------------------------------------------

function correctPrevURL(form)
{
   form.prevURL.value = window.location;
}

function showDisplay(divId)
{
	var theStyle;
	if(document.all)
	{
		theStyle = eval("document.all."+divId+".style");	
	}
	else
	{
		theStyle = document.getElementById(divId).style;	
	}
	theStyle.display = "block";

}
function hideDisplay(divId)
{
	var theStyle;
	if(document.all)
	{
		theStyle = eval("document.all."+divId+".style");	
	}
	else
	{
		theStyle = document.getElementById(divId).style;	
	}
	theStyle.display = "none";
}

function openEprocHelp(url)
{
	var popWin = window.open(url, "eProcWin", "titlebar=no,toolbars=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600");
	popWin.focus();
}