/*******************************************************************************
FILE NAME    :global.js
DEPENDENCIES :browser.js
********************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Functions used throughout website.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//-- global variables and functionality begin ----------------------------------
pageLoaded = false; //set page loaded flag
homePage = false;
if(top.location.href != self.location.href) top.location.href = self.location.href; //prevent unauthorized framing
theURL = window.document.location.href;

//used for dialog functionality
maskInitialized = false;
leavingSiteInitialized = false;
H2HBridgeMessageInitialized = false;
T2HBridgeMessageInitialized = false;
windowResizeSet = false;
currentDialog = null; //used for dynamic dialog tracking
dialogEnabled = false;
dailogType = 0;
doLinkURL = "";
doLinkWindowType = 0;
//-- global variables and functionality end ------------------------------------

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- preload images
function preloadImage(virtualName, filePath, fileName) {
 eval(virtualName +' = new Image()'); //create a new image object
 eval(virtualName +'.src = "' + filePath + fileName + '"');
}

//FUNCTION-- dynamically swaps one image (also used for rollovers in layers for Netscape 4)
function swapImageSingle(imageName, imageState, imageLayer) {
 if(gBrowser.ns4 && imageLayer!=null) eval('document.' + imageLayer + '.document.images["'+ imageName +'"].src =' + imageName + imageState + ".src"); //path to nested layer for Netscape 4
 else document.images[imageName].src = eval(imageName + imageState + ".src");
}

//FUNCTION-- sets rollover highlight
function setRollover(imageId, imageFilePath, imageFileName) {
 preloadImage(imageId+"_off", imageFilePath, imageFileName);
 preloadImage(imageId+"_on", imageFilePath, imageFileName);
 swapImageSingle(imageId, '_on', null);
}

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- creates a new 3/4 browser window for links to other websites throughout site
function openExternalWin(argURL) {
 if(argURL != null || argURL != "")
 {
  a411_externalWin = window.open(argURL, null, 'directories=1,location=1,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1');
  if(a411_externalWin != null) a411_externalWin.focus();
 }
 else alert("Error: Missing URL parameter");
}

//FUNCTION-- creates a mini popup browser window
function openEmailWin(argURL) {
 if(argURL != null || argURL != "")
 {
  var showToolBar = 0;
  if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar = 1; //if IE7 show tool bar
  a411_openEmailWin1 = window.open(argURL, "a411_email", 'directories=0,location=0,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar='+showToolBar);
  if(a411_openEmailWin1 != null) a411_openEmailWin1.focus();
 }
 else alert("Error: Missing URL parameter");
}

//FUNCTION-- creates a popup browser window
function openDisclaimerWin(argURL) {
 if(argURL != null || argURL != "")
 {
  a411_disclaimerWin = window.open(argURL, "disclaimer", 'directories=1,location=1,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1');
  if(a411_disclaimerWin != null) a411_disclaimerWin.focus();
 }
 else alert("Error: Missing URL parameter");
}

//FUNCTION-- creates a popup window for pdfs
function openPDFWin(url) {
 if(!gBrowser.isMac) //if its not a Mac
 {
	popupWinFeatures = "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no";
  window.open(url,"",popupWinFeatures);
 }
 else window.location.href = url; //mac fix for OS X
}

//FUNCTION-- determines the target for loading a new href
function doLink() {
 switch(doLinkWindowType)
 {
  case 1:
   doLinkWindowType = 0;
   window.location.href = doLinkURL; //load into same window
   break;
  default:
   doLinkWindowType = 0;
   openExternalWin(doLinkURL); //load into popup window
 }
}

//FUNCTION-- creates a popup browser window
function sampleResults(argURL) {
 if(argURL != null || argURL != "")
 {
  var showToolBar = 0;
  if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar = 1; //if IE7 show tool bar
  a411_sampleResultsWin = window.open(argURL, "sampleresults", 'directories=0,location=0,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar='+showToolBar);
  if(a411_sampleResultsWin != null) a411_sampleResultsWin.focus();
 }
 else alert("Error: Missing URL parameter");
}

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG AND MASKING BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- moves dialog off screen
function moveOffScreen() {
 if(currentDialog) currentDialog.m_moveTo(0, -1000);
}

//FUNCTION-- sets dialog
function setDialog() {
 if(dialogEnabled) 
 {
  if(dailogType == 2)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   leavingSite.m_updateHeight();
   leavingSite.m_positionObj(false);
  }
  else if(dailogType == 3)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   H2HBridgeMessage.m_updateHeight();
   H2HBridgeMessage.m_positionObj(false);
  }
  else if(dailogType == 4)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   T2HBridgeMessage.m_updateHeight();
   T2HBridgeMessage.m_positionObj(false);
  }
  else {alert("Error: dailogType undefined");}
 }
}

//FUNCTION-- clears dialog and Mask
function clearDialogMask() {
 dialogEnabled = false;
 moveOffScreen();
 if(dailogType == 0) {}
 else if(dailogType == 2) {mask01.m_setDisplay(2);}
 else if(dailogType == 3) {mask01.m_setDisplay(2);}
 else if(dailogType == 4) {mask01.m_setDisplay(2);}
 else {alert("Error: dailogType undefined");}
}

//FUNCTION-- clears dialog only and retains mask (used when swapping mutliple dialogs when mask is visible)
function clearDialog() {
 dialogEnabled = false;
 moveOffScreen();
}

//------------------------------------------------------------------------------
// DIALOG AND MASKING END
//------------------------------------------------------------------------------

//---END