// 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 -----------------------------------------------------------------




// BEGIN ###############################################################
// code to open help window

var helpWin;
function openHelp(section, poundDown) {
  var helpPages = new Array();
  var page = "http://" + window.location.host + "/content/stores/quickshop/custserv/help/index.html";

  helpPages[0] = "registration_signin.html";
  helpPages[1] = "select_order.html";
  helpPages[2] = "item_inventory.html";
  helpPages[3] = "review_cart.html";
  helpPages[4] = "select_school.html";
  helpPages[5] = "ship_info.html";
  helpPages[6] = "po.html";
  helpPages[7] = "cc.html";
  helpPages[8] = "promotions.html";
  helpPages[9] = "bonus_points.html";
  helpPages[10] = "after_order.html";
  helpPages[11] = "contact_us.html";
  helpPages[12] = "/webapp/wcs/stores/servlet/ContactUsView?langId=-1&storeId=21552&catalogId=10001";

	  // pass the help section and poundDown if we receive it from caller
	  if(section != 12)
	  {
			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/quickshop/custserv/help/index.html";
  
  helpPages[0] = "registration_signin.html";
  helpPages[1] = "select_order.html";
  helpPages[2] = "item_inventory.html";
  helpPages[3] = "review_cart.html";
  helpPages[4] = "select_school.html";
  helpPages[5] = "ship_info.html";
  helpPages[6] = "po.html";
  helpPages[7] = "cc.html";
  helpPages[8] = "promotions.html";
  helpPages[9] = "bonus_points.html";
  helpPages[10] = "after_order.html";
  helpPages[11] = "contact_us.html";
  helpPages[12] = "http://" + window.location.host + "/webapp/wcs/stores/servlet/ContactUsView?langId=-1&storeId=21552&catalogId=10001";

	  // pass the help section and poundDown if we receive it from caller
	  if(section != 12)
	  {
			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;
}