/**
 *   consolidated.js
 *
 *   This file consolidates commonly used JavaScript functions
 *   found in these files previously: top.js, rollImg.js, 
 *   openwin.js, popupwin.js, and euiwindow.js
 */



/*
 *   Force the page to the top frame of the window.
 */

 self.name="topFrame";



/**
 *  Function:		rollImgSetup
 *
 *  Version History:	2001-04-02, Richard Coles, Initial Version
 *
 *  Description:	Use this function in a page body 'onLoad' event handler 
 *			to initialize variables rollover image processing via 'rollImg'.
 *			The document.images array is parsed.  Variables for image rollover
 *			are create for all images with names ending in '_on', '_off',
 *			'_at' and '_over' (Note: image name does not include the 
 *			file-type; e.g.: .gif, .jpg, etc).  Complementary images 
 *			(e.g.: an '_on' for each '_off') must exist in the same 
 *			source directory.
 *
 *  Syntax:		rollImgSetup()
 *
 *  Parameters:		none
 *
 *  Return:		none
 */

function rollImgSetup() {
  var boolArrayDefined;
  var i;
  var result;
  var strOnImgSrc;
  var strOffImgSrc;
  var strMsg = "";
  for (i = 0; (i < document.images.length); i++) {
    strOnImgSrc = "";
    strOffImgSrc = "";
    if (result = document.images[i].src.match(/(.+)_on\.(.+)$/i)) { // "on" image
      strOnImgSrc = document.images[i].src;
      strOffImgSrc = result[1] + "_on." + result[2];
    }
    else if (result = document.images[i].src.match(/(.+)_off\.(.+)$/i)) { // "off" image
      strOnImgSrc = result[1] + "_on." + result[2];
      strOffImgSrc = document.images[i].src;
    }
    if ((strOnImgSrc != "") && (strOffImgSrc != "")) {
      eval("((typeof " + document.images[i].name + "0) == \"object\") ? boolArrayDefined = 1 : boolArrayDefined = 0;");
      if (boolArrayDefined) continue;
      if ((document.images[i].height > 0) &&
	  (document.images[i].width > 0)) {
        eval(document.images[i].name + "0 = new Image(document.images[i].height,document.images[i].width);");
        eval(document.images[i].name + "1 = new Image(document.images[i].height,document.images[i].width);");
      }
      else {
	eval(document.images[i].name + "0 = new Image();");
	eval(document.images[i].name + "1 = new Image();");
      }
      eval(document.images[i].name + "0.src = strOffImgSrc;");
      eval(document.images[i].name + "1.src = strOnImgSrc;");
    }
  }
}



/**
 *  Function:		rollImg
 *
 *  Version History:	2001-04-02, Richard Coles, Initial Version
 *
 *  Description:	Use this function in an 'onMouseOver' or 'onMouseOut'
 *			event handler for rollover image processing.
 *
 *  Special Notes:	You must call 'imgRollSetup()' from the page body
 *			'onLoad' event for variable initialization.
 *
 *  Syntax:		rollImg(image-name, state)
 *
 *  Parameters:		image-name: (input) 'name' value from image tag
 *			state: (input) 1 for 'on'; 0 for 'off'
 *
 *  Returns:		void
 */

function rollImg(strImgName, intState) {
  var boolArrayDefined = 0;
  if (intState <= 0)
    intState = 0;
  else
    intState = 1;
  eval("((typeof " + strImgName + intState + ") == \"object\") ? boolArrayDefined = 1 : boolArrayDefined = 0;");
  if (!boolArrayDefined) return;
  eval("document.images." + strImgName + ".src = " + strImgName + intState + ".src;");
}



/**
 *  Function:		openWindow / popupWindow
 *
 *  Version History:	?
 *
 *  Description:	Use this function to open/popup a new window to display a link in.
 *
 *  Special Notes:	none
 *
 *  Syntax:		openWindow(url, w, h)
 *
 *  Parameters:		url: (input) target link
 *			w: (input) width of the popup window in pixels
 *			h: (input) height of the popup window in pixels
 *
 *  Returns:		void
 */

  function openWindow(url, w, h) {
    var options  = "width=" + w + ",height=" + h + ",";
        options += "resizable=yes,scrollbars=yes,status=yes,";
        options += "menubar=yes,toolbar=yes,location=yes,directories=no";
    var newWin = window.open(url, 'newWin', options);
    newWin.focus();
  }

  function popupWindow(url, w, h) {
    openWindow(url, w, h);
  }

  function videoWindow(url, w, h) {
    var options  = "width=" + w + ",height=" + h + ",";
        options += "resizable=no,scrollbars=no,status=no,";
        options += "menubar=no,toolbar=no,location=no,directories=no";
    var videoWin = window.open(url, 'videoWin', options);
    videoWin.focus();
  }



/**
 *  Function:		createHelpWindow
 *
 *  Version History:	?
 *
 *  Description:	Use this function to open/popup a new window to display a link in.
 *
 *  Special Notes:	none
 *
 *  Syntax:		openWindow(url, w, h)
 *
 *  Parameters:		newURL: (input) target link -- defaults to "/sc2000/blank.htm"
 *			newWin: (input) name of the window -- defaults to "EUIWin"
 *
 *  Returns:		false
 */

function createHelpWindow(newURL, newWin) {

  var maxWidth, winWidth;
  var maxHeight, winHeight;
  var positionString = "";

  screenWidth = 200;
  screenHeight = 300;

  winArgs = "width=520,height=460,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0";

  if (newURL == "") {
    newURL = "/sc2000/blank.htm";
  }

  if (newWin == "") {
    newWin = "EUIWin";
  }

  var catalogWin = window.open(newURL, newWin, winArgs);

  if (catalogWin != null) {
    catalogWin.focus();
  }

  return false;
}



/**
 *  Function:		createCatalogWindow
 *
 *  Version History:	?
 *
 *  Description:	Use this function to open/popup a new window, with
 *                      calcualted size and positioning, to display a link in.
 *
 *  Special Notes:	none
 *
 *  Syntax:		openWindow(url, w, h)
 *
 *  Parameters:		newURL: (input) target link
 *			newWin: (input) width of the popup window in pixels
 *
 *  Returns:		false
 */

function createCatalogWindow(newURL, newWin) {

  var maxWidth, winWidth;
  var maxHeight, winHeight;
  var positionString = "";

  screenWidth = screen.width - 15;
  screenHeight = screen.height - 25;

  if(navigator.userAgent.indexOf("MSIE") < 0) {
    newX = window.screenX + 45;
    newY = window.screenY + 45;
    positionString = ",SCREENX=" + newX;
    positionString += ",SCREENY=" + newY;
  }
  
  if(screenWidth > 700) {
    screenWidth = 700;
  }
  if(screenHeight > 520) {
    screenHeight = 520;
  }

  if (newURL == ""){
    newURL = "/sc2000/blank.htm";
  }

  if (newWin == "") {
    newWin = "EUIWin";
  }

  var catalogWin = window.open(newURL, newWin, "HEIGHT=" + screenHeight +",WIDTH=" + screenWidth + ",SCROLLBARS,TOOLBAR,STATUS" + positionString);
  if (catalogWin != null) {
    catalogWin.focus();
  }

  return false;
}


