
// This function allows s section of an expanded ecomp menu to be hidden
//  when the user clicks it without a postback to server.
// Parameters:
//  divLevel2 is the Html div element that was clicked.
function LibraryMenuHideLevel3List(divLevel2) {
   if   ((typeof(divLevel2.className)=="string") && 
         (divLevel2.className.indexOf("mnuRow3Selected")>=0 || 
          divLevel2.className.indexOf("mnuRow4Selected")>=0)) {
      var nodeNextSibling = divLevel2.nextSibling;
      
      while (nodeNextSibling && (nodeNextSibling.nodeType==3)) {
         nodeNextSibling=nodeNextSibling.nextSibling; // skip Text nodes
      };
      
      if (nodeNextSibling && (nodeNextSibling.nodeType==1) && 
            (nodeNextSibling.className.indexOf("mnuSubMenu")>=0)) {
         nodeNextSibling.className="mnuSubMnuHidden";
         return false;
      };
   };
}


// Catches the enter key in a field triggers a search
function FireDefaultButton(event, target, minLength) {
   var EventTarget;
   if (event.target) {
      EventTarget=event.target;
   } else if (event.srcElement) {
      EventTarget=event.srcElement;
   };
   
   if (event.keyCode == 13 && !(EventTarget && (EventTarget.tagName.toLowerCase() == "textarea"))) {
      var defaultButton;
      
      if (document.getElementById) {
         defaultButton = document.getElementById(target);
      } else {
         defaultButton = document.all[target];
      };
      if (defaultButton && typeof(defaultButton.click) != "undefined") {
         if (minLength==0 || !EventTarget.value || EventTarget.value.length>=minLength) {
            defaultButton.click();
         };
         event.cancelBubble = true;
         if (event.stopPropagation) event.stopPropagation();
         return false;
      };
  };
  return true;
}


// Changes the border of a text box when it has the focus
// Parameters:
//  event is the html dom onfocus event that triggered this code
// Remarks:
//  This is only needed because IE (through IE7) does not support the "focus" css pseudo-class
function txtboxOnFocus(event) {
   if ( window && window.event ) {
      obj = window.event.srcElement;
      obj.className = "textBoxFocused";
   };
}


// Changes the border of a text box back to normal when it looses the focus
// Parameters:
//  event is the html dom onblur event that triggered this code
// Remarks:
//  This is only needed because IE (through IE7) does not support the "focus" css pseudo-class
function txtboxOnBlur(event) {
   if ( window && window.event ) {
      obj = window.event.srcElement;
      obj.className = "textBox";
   };
}


// Only allows a text box to accept numerics.
// Parameters:
//  event is the html dom keypress event that triggered this code
function txtboxValidateNumeric(event) {
   if ( window && window.event ) {
      if (( typeof( window.event.keyCode ) == "number" ) && 
         ( window.event.keyCode < 48 || window.event.keyCode > 57 )) {
         window.event.returnValue = false;
      };
   } else if ( event && event.which ) {
      var keyChar = String.fromCharCode( event.which );
      
      if ((( keyChar < '0' ) || ( keyChar > '9' )) && 
         ( event.which != 8 )) {
         return false;
      };
   };
   return true;
}


// Horizontally scrolls the page to the right to hide the menu on the left
//   when the screen is narrow.
function fcnScroll() {
   if (document.body && document.body.parentElement && document.body.parentElement.clientWidth) {
      // IE
      if (document.body.parentElement.clientWidth<800 && document.getElementById) {
         if (window && window.scrollTo) window.scrollTo(200,0);
      };
   } else if (window.innerWidth) {
      // Mozilla
      if (window.innerWidth<800 && document.getElementById) {
         if (window && window.scrollTo) window.scrollTo(200,0);
      };
   };
};


// Sets up the all pages to do load events when the page finished loading.
// Invoked as part of the standard page template.
function fcnGlobalInit() {
   if (window && window.addEventListener) {
      //Mozilla
      window.addEventListener("load",fcnScroll,false);
   } else if (window.attachEvent) { 
      //MS IE
      window.attachEvent("onload",fcnScroll);
   };
}


// Redirects the user to a page discussing cookies when she does
//  not accept non-persistant cookies.
function AcceptsCookies() {  
   document.cookie = "TestCookie=True";

   if ( document.cookie.indexOf( "TestCookie" ) == -1 ) {
      window.location = "EnablingCookies.aspx";
   };
}


// Puts up an alert box when the user wishes to cancel an order or subscription
// Parameters:
//  OrderNum is a string with the number of the order or subscription
//  CartType is a 'N' for a one-time order, else it is a subscription
function ConfirmCancel(OrderNum, CartType) {
   var msg = "Click 'OK' if you are sure that you want to cancel this ";
   
   if ( CartType == "N" ) {
      msg += "one-time order.\n\n\tOne-Time";
   }  else {
      msg += "subscription order.\n\n\tSubscription";
   };
   msg += " Order Number: " + OrderNum;
   
   return confirm( msg );
}


// Puts up an alert box when the user wishes to defer paying for an order
// Parameters:
//  CartType is a 'N' for a one-time order, else it is a subscription
//  RetUrl is the relative URL the user should be taken to if they confirm they want to defer payment
function ConfirmPayLater(CartType, RetUrl) {
   var msg = "Click 'OK' if you are sure that you want to pay for this ";
   
   if ( CartType == 'N' ) {
      msg += "one-time order ";
   } else if ( CartType == 'Y' ) {
      msg += "subscription order ";
   } else if ( CartType == 'R' ) {
      msg += "subscription renewal order ";
   } else if ( CartType == 'rg' ) {
      msg = "Click 'OK' if you are sure that you want to pay this balance ";
   } else {
      msg += "order ";
   };
   msg += "at a later time.";
 
   if ( confirm( msg )) {
      top.location.target = "_top"
      top.location.href = RetUrl;
   };
}


// Determines whether the __EVENTVALIDATION hidden field exists on a form.
// Used to prevent users from clicking a button before the whole form is painted.
// Returns true if it is unable to determine
function EVExists() {
   if (!document.getElementById) return true;
   return (document.getElementById("ihLast"));
}