var w_privacypolicy;
var w_productinfo;
var w_login;
var w_popup;
var w_producttour;

/**
 * popup - open general popup window.
 * - url (string) - URL to open
 * - width (int) - width in pixels
 * - height (int) - height in pixels
 * - scrollbars (string) - if "1", show scrollbars
 * - toolbar (string) - if "1", show toolbar
 * - x (int) - x position in pixels
 * - y (int) - y position in pixels
 * - win (var) - window object to use
 * - winname (string) - window name to use
 */
function popup(url, width, height, scrollbars, toolbar, x, y, win, winname) {

   if (win == null) win = w_popup;
   if (winname == null) winname = "popup_window";
   // check for existing popup
   if (! win || win.closed) {
      // set defaults
      if (width == null) width = 570;
      if (height == null) height = 510;
      if (scrollbars == null) scrollbars = 1;
      if (toolbar == null) toolbar = 0;
      if (x == null) x = 50;
      if (y == null) y = 20;
      win = open(url, winname, "directories=0,location=0,menubar=0,resizable=yes,scrollbars=" + scrollbars + ",status=0,toolbar=" + toolbar + ",width=" + width + ",height=" + height + ",left=" + x + ",top=" + y);
      if (! win.opener)
         win.opener = self;
      if (win)
         win.focus();
   } else {
      win.focus();
      win.location = url;
   }
}

/**
 * privacypolicy - open privacy policy window.
 * - url (string) - URL to open
 */
function privacypolicy(url) {
   popup(url, 550, 500, 1, 0, w_privacypolicy, "privacypolicy_window");
}

/**
 * productinfo - open product information request window.
 * - url (string) - URL to open
 */
function productinfo(url) {
   popup(url, 550, 500, 1, 0, w_productinfo, "productinfo_window");
}

/**
 * producttour - open product tour window.
 * - url (string) - URL to open
 */
function producttour(url) {
   popup(url, 580, 450, 1, 0, w_producttour, "producttour_window");
}

/**
 * login - open login window.
 * - url (string) - URL to open
 */
function login(url) {
   popup(url, 550, 500, 1, 0, w_login, "login_window");
}

/**
 * cult3d - open cult3d popup window.
 * - url (string) - URL to open
 */
function cult3d(url) {
   self.name = "parent";
   popup(url, 592, 450, 1, 0, null, "popup_cult3d");
}

/**
 * loadpage - open URL given at dropdown jump menu.
 */
function loadpage() {
   windows.location = document.jump.menu.options[document.jump.menu.selectedIndex].value;
}

/**
 * toggleDiv - toggles given div areas to be visible or not based on a boolean
 * input value.
 * - controlValue (boolean)
 * - divOnName (string) - name of the div to turn on
 * - divOffName (string) - name of the div to turn off
 */
function toggleDiv(controlValue, divOnName, divOffName) {

   // get div objects
   var oDivOn =
      (document.getElementById ? document.getElementById(divOnName) :
         (document.all ? eval('document.all.' + divOnName) : null));
   var oDivOff =
      (document.getElementById ? document.getElementById(divOffName) :
         (document.all ? eval('document.all.' + divOffName) : null));

   if (controlValue) {
      if (oDivOn && oDivOn.style)
         oDivOn.style.display = '';
      if (oDivOff && oDivOff.style)
         oDivOff.style.display = 'none';
   } else {
      if (oDivOn && oDivOn.style)
         oDivOn.style.display = 'none';
      if (oDivOff && oDivOff.style)
         oDivOff.style.display = '';
   }
}

function showHideDiv(divName) {

   var oDiv =
      (document.getElementById ? document.getElementById(divName) :
         (document.all ? eval('document.all.' + divName) : null));
   if (oDiv) {
      if (oDiv.style.display == '')
         toggleDiv(true, null, divName);
      else
         toggleDiv(true, divName, null);
   }
}

/**
 * searchFocus - called when the search box receives focus.
 * - searchBox (HTML text box) - search text box
 * - watermarkText (String) - watermark text
 */
function searchFocus(searchBox, watermarkText) {
   if (searchBox.value == watermarkText)
      searchBox.value = "";
   searchBox.style.color = "#000000";
   searchBox.style.backgroundColor = "#FFFFFF";
}

/**
 * searchBlur - called when the search box loses focus.
 * - searchBox (HTML text box) - search text box
 * - watermarkText (String) - watermark text
 */
function searchBlur(searchBox, watermarkText) {
   if (searchBox.value == "")
      searchBox.value = watermarkText;
   searchBox.style.color = "#FFFFFF";
   searchBox.style.backgroundColor = "#000000";
}

/**
 * resizeContentArea - resize content window based on browser window size.
 * - scrollArea (string) - div name of scrollable area
 * - remainHeight (int) - remaining window height not used by scroll area
 */
function resizeContentArea(scrollArea, remainHeight) {

   // get scroll area
   var oContent = (document.getElementById ? document.getElementById(scrollArea) :
      (document.all ? eval("document.all." + scrollArea) : null));
   var contentHeight = (window.innerHeight ? window.innerHeight :
      document.body.clientHeight) - remainHeight;
   oContent.style.height = contentHeight + "px";
}
