/*******************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Variables and functions used throughout website.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// VARIABLES BEGIN
//------------------------------------------------------------------------------

seekHelp = 0; //Seeking Help dialog
segmentType = 0; //Segment dialog
gliderInitialized = false;

//------------------------------------------------------------------------------
// VARIABLES END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- creates a new 3/4 browser window for links to other websites throughout site
function openExternalWin(argURL) {
 externalWin = window.open(argURL, null, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500');
 if(externalWin != null) externalWin.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a popup window for pdfs
function newPDFWin(argURL) {
 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(argURL,"",popupWinFeatures);
 }
 else window.location.href = argURL; //mac fix for OS X
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a popup browser window
function openDisclaimerWin(argURL) {
 disclaimerWin = window.open(argURL, "disclaimer", 'directories=1,location=1,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1');
 if(disclaimerWin != null) disclaimerWin.focus();
}

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// CSS FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- sets CSS class
function setCssClass(argID, argClass) {
 document.getElementById(argID).className = argClass;
}

//------------------------------------------------------------------------------
// CSS FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- preload images
function preloadImage(argVirtualName, argFilePath, argFileName) {
 eval(argVirtualName +' = new Image()'); //create a new image object
 eval(argVirtualName +'.src = "' + argFilePath + argFileName + '"');
}

//------------------------------------------------------------------------------

//FUNCTION-- dynamically swaps one image
function swapImageSingle(argImageName, argImageState) {
 document.images[argImageName].src = eval(argImageName + argImageState + ".src");
}

//------------------------------------------------------------------------------

//FUNCTION-- sets rollover highlight
function setRollover(argID, argFilePath, argFileName) {
 preloadImage(argID +"_off", argFilePath, argFileName);
 preloadImage(argID +"_on", argFilePath, argFileName);
 swapImageSingle(argID, '_on');
}

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- sets a cookie - jsv 1.0
function setCookie(cookieName, cookieValue, expireDate) { 
 if(expireDate != null)
 {
  //set expiration date for cookie
	var expires = new Date( );                                   
	expires.setTime(expires.getTime( ) + (1000 * 60 * 60 * 24 * expireDate)); //days ahead
 }
 document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/" + ((expireDate == null) ? ";" : "; expires=" + expires.toGMTString());
}

//FUNCTION-- retrieves a cookie - jsv 1.0
function getCookie(cookieName) {
 var cookieNameStr = cookieName + "=";               
 var dc = document.cookie;
	            
 if(dc.length > 0)
 {              
  var beginStr = dc.indexOf(cookieNameStr);       
  if(beginStr != -1) 
  {           
   beginStr += cookieNameStr.length;       
   var endStr = dc.indexOf(";", beginStr);
   if(endStr == -1) {endStr = dc.length;}
   return unescape(dc.substring(beginStr, endStr));
  } 
 }
 return null;
}

//FUNCTION-- deletes a cookie - jsv 1.0
function deleteCookie(cookieName) {
 document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns screen height
function getScreenHeight() {
 return parseInt(screen.height);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns screen width
function getScreenWidth() {
 return parseInt(screen.width);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns height of working area of system's screen, excluding windows taskbar
function getScreenAvailHeight() {
 return parseInt(screen.availHeight);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of working area of system's screen, excluding windows taskbar
function getScreenAvailWidth() {
 return parseInt(screen.availWidth);
}

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of browser window
function getBrowserWindowHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientHeight;
	else return document.body.clientHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasHorizontalScrollbar()) return window.innerHeight-getScrollbarOffSet();
	else return window.innerHeight;
 }
 else return window.innerHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of browser window
function getBrowserWindowWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientWidth;
	else return document.body.clientWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasVerticalScrollbar()) return window.innerWidth-getScrollbarOffSet();
	else return window.innerWidth;
 }
 else if(gBrowser.safari && hasVerticalScrollbar()) //safari
 {
	return window.innerWidth - getScrollbarOffSet();
 }
 else return window.innerWidth;
}

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of body
function getBodyHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollHeight;
	else return document.body.scrollHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasHorizontalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasVerticalScrollbar())	return (window.innerHeight+window.scrollMaxY)-scrollOffSet;
  else return window.innerHeight-scrollOffSet;
 }
 else return document.body.scrollHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of body
function getBodyWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollWidth;
	else return document.body.scrollWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasVerticalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasHorizontalScrollbar())	return (window.innerWidth+window.scrollMaxX)-scrollOffSet;
  else return window.innerWidth-scrollOffSet;
 }
 else return document.body.scrollWidth;
}

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- determines horizontal scrollbar existence
function hasHorizontalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxX > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- determines vertical scrollbar existence
function hasVerticalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxY > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else if(gBrowser.safari || gBrowser.chrome) //safari or chrome
 {
	if(window.innerWidth == getBodyWidth()) return false;
	else return true;
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- checks if scrollMaxY and scrollMaxX properties are supported
function isScrollMax() {
 if(window.scrollMaxY >= 0 && window.scrollMaxX >= 0) return true;
 else return false;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns vertical scroll position
function getVerticalScrollPosition() {
 if(window.pageYOffset) {return window.pageYOffset;}
 else if(document.documentElement && document.documentElement.scrollTop) {return document.documentElement.scrollTop;}
 else if(document.body) {return document.body.scrollTop;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns horizontal scroll position
function getHorizontalScrollPosition() {
 if(window.pageXOffset) {return window.pageXOffset;}
 else if(document.documentElement && document.documentElement.scrollLeft) {return document.documentElement.scrollLeft;}
 else if(document.body) {return document.body.scrollLeft;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns offset value equal to scrollbar width
function getScrollbarOffSet() {
 if(gBrowser.firefox)
 {
  if(gBrowser.isWin) return 17;
	else if(gBrowser.isMac) return 15;
 }
 else if(gBrowser.safari) {return 15;}
}

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- checks document mode for IE
function checkMode() {
 if(document.all) {return (document.compatMode && document.compatMode != "BackCompat");}
 else {alert("Mode not detected");}
}

//------------------------------------------------------------------------------

//FUNCTION-- sets document mode for IE (documentElement or body based on DOCTYPE used)
function setMode() {
 if(document.all)
 {
	if(checkMode()) {DOCUMENTMODE = document.documentElement;}
	else {DOCUMENTMODE = document.body;}
 }
 else {alert("Unable to set mode");}
}

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns left coordinates for object centering
function getObjectPositionLeft(argScreenWidth, argObjWidth) {
 if(argObjWidth < argScreenWidth)
 {
  var halfScreenWidth = parseInt(argScreenWidth/2);
  var halfObjWidth = parseInt(argObjWidth/2); 
  return ((halfScreenWidth-halfObjWidth)+getHorizontalScrollPosition());
 }
 else return 0;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns top coordinates for object centering
function getObjectPositionTop(argScreenHeight, argObjHeight) {
 if(argObjHeight < argScreenHeight)
 {	
  var halfScreenHeight = parseInt(argScreenHeight/2);
  var halfObjHeight = parseInt(argObjHeight/2); 
  return ((halfScreenHeight-halfObjHeight)+getVerticalScrollPosition());
 }
 else return getVerticalScrollPosition();
}	

//------------------------------------------------------------------------------

//FUNCTION-- validate top position
function isValidatePositionTop(argTopPosition, argObjectHeight, argBrowserWindowHeight) {
 if(argTopPosition <= 0 || (argTopPosition+argObjectHeight) > argBrowserWindowHeight) return false;
 else return true;
}

//------------------------------------------------------------------------------

//FUNCTION-- validate left position
function isValidatePositionLeft(argLeftPosition, argObjectWidth, argBrowserWindowWidth) {
 if(argLeftPosition <= 0 || (argLeftPosition+argObjectWidth) > argBrowserWindowWidth) return false;
 else return true;
}

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// MENU BEGIN
//------------------------------------------------------------------------------

menus = new Array(); 

//CLASS CONSTRUCTOR-- creates menu object with foundation properties
function menu(argID, argPage, argParentMenu, argSubMenu, argMenuOnClass) {
 this.id = argID;
 this.page = argPage;
 this.parentMenu = argParentMenu;   
 this.subMenu = argSubMenu; 
 this.menuOnClass = argMenuOnClass;

 menus.push(this);
}

//------------------------------------------------------------------------------

function setMenu() {
 var pageId = document.getElementById("leftColumnDiv").className; //set target class

 for(var j=0;j<menus.length;j++)
 {
  if(pageId == menus[j].page)
  {
   setCssClass(menus[j].id, menus[j].menuOnClass); //set selected state of menu for page

   //if menu has a subMenu then expand it
   if(menus[j].subMenu)
   {
    document.getElementById(menus[j].subMenu).style.display = "inline";
   }

   var parentMenu = menus[j].parentMenu;

   while(parentMenu)
   {
	  document.getElementById(parentMenu.subMenu).style.display = "inline"; //expand parent menu
	  setCssClass(parentMenu.id, parentMenu.menuOnClass); //set selected state of parent menu
	  parentMenu = parentMenu.parentMenu; //set flag for next parentMenu check
   }
   break;
  }
 } 
}

//------------------------------------------------------------------------------
// MENU END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG BEGIN
//------------------------------------------------------------------------------

pdfDialog = new Spawn_Object("pdfMessageDiv");
leavingDialog = new Spawn_Object("leavingSiteDiv");
t2hBridge1Dialog = new Spawn_Object("t2hBridge1Div");
t2hBridge2Dialog = new Spawn_Object("t2hBridge2Div");
seekHelpDialog = new Spawn_Object("seekHelpDiv");
segmentDialog = new Spawn_Object("segmentDialogDiv");

//FUNCTION-- init dailogs
function initDialogs() {
 var grayMask = initMask("mask01", "/images/grayAlpha.png"); //initialize mask

 pdfDialog.m_initDialogProperties(grayMask, "pdf"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 leavingDialog.m_initDialogProperties(grayMask, "siteExit"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 t2hBridge1Dialog.m_initDialogProperties(grayMask, "t2h1Exit"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 t2hBridge2Dialog.m_initDialogProperties(grayMask, "t2h2Exit"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 seekHelpDialog.m_initDialogProperties(grayMask, "seekHelp"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 segmentDialog.m_initDialogProperties(grayMask, "segment"); //init common dialog properties [mask=mask object or null | dialogType=integer]

 activeDialog = null;
 window.onresize = doOnResize;

/* if(document.getElementsByTagName("body")[0].className == "page-home")
 {
  if(!optinDone)
  {
   optinUpdatesDialog = new Spawn_Object("optinUpdatesDiv");
   optinUpdatesDialog.m_initDialogProperties(grayMask, "optinHome"); //init common dialog properties [mask=mask object or null | dialogType=integer]
   optinUpdatesDialog.m_setResource("null");
   document.getElementById("optinUpdatesIframe").src = "/home/optin.aspx"; //load the iframe
  }
 }*/
}

//FUNCTION-- multiple resize calls
function doOnResize() {
 adjustDialog();
 initDynamicGlider(); 
}

//------------------------------------------------------------------------------
// DIALOG END
//------------------------------------------------------------------------------

//FUNCTION-- fixes png transparency in unsupported browsers
function setPng(argId, argClearEl, argClearBg, argImagePath, argSizingMethod) {
 if(document.all)
 {
  var targetEl = document.getElementById(argId);
  if(argClearEl) targetEl.innerHTML = "";
  if(argClearBg) targetEl.style.backgroundImage = "none";
  targetEl.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+argImagePath+"', sizingMethod='"+argSizingMethod+"')";
 }
}

//------------------------------------------------------------------------------
// FORMS BEGIN
//------------------------------------------------------------------------------

function setEmptyZipCode(obj) {
 if(obj.value == "ZIP Code") obj.value = "";
}

//------------------------------------------------------------------------------
// FORMS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// GLIDER BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- return element if found
function hasFlash() {
 return document.getElementById("greeter_video");
}

//FUNCTION-- return pointer for greeter ID
function getFlashPointer() {
 return (gBrowser.ie) ? document.all.greeter_video:document.greeter_video;
}

//FUNCTION-- show privacy shade
function showShade() {
 if(gliderInitialized)
 {
  if(hasFlash()) //must be invoked before page is hidden (do not move)
  {
   var flashPointer = getFlashPointer();
   flashPointer.muteFlv(); //mute flash
  }
  if(activeDialog) activeDialog.m_hideDialog(); //hide active dialog if one is showing
	
  document.getElementById("hideShadeDiv").style.display = "none";
	document.getElementById("showShadeDiv").style.display = "block";
	
  //set html for page
	document.getElementById("windowShadeDiv").style.display = "block";
	document.getElementById("wrapper01Div").style.display = "none";
	document.body.style.backgroundColor = "#fff";

  if(document.getElementById("wrapper01Div").className == "page-privacy-popup")
  {
   document.body.style.margin = "0px";
	 document.body.style.backgroundImage = "none";
  }

	window.scrollTo(0,0);
 }
}

//FUNCTION-- hide privacy shade
function hideShade() {
 if(gliderInitialized)
 {
  document.getElementById("hideShadeDiv").style.display = "block";
	document.getElementById("showShadeDiv").style.display = "none";

  //set html for page
	document.getElementById("windowShadeDiv").style.display = "none";
	document.getElementById("wrapper01Div").style.display = "block";
	document.body.style.backgroundColor = "#94b9e2";

  if(document.getElementById("wrapper01Div").className == "page-privacy-popup")
  {
   document.body.style.margin = "25px 25px 25px 45px";
	 document.body.style.backgroundImage = "url(/images/background_popup.gif)";
   document.body.style.backgroundColor = "#fff";
  }

  if(hasFlash()) //must be invoked after page is reset to normal state (do not move)
  {
   var flashPointer = getFlashPointer();
   flashPointer.playFlv(); //play flash
  }
 }
}

//------------------------------------------------------------------------------
// GLIDER END
//------------------------------------------------------------------------------