////////////////////////////////
// Code for in browser popups
// contact footer popup code
var IB_PopupCloseDelay = 500; // in milliseconds
var IB_PopupFade = 500; // in milliseconds
var IB_PopupCloseTimer;
var IB_LastOpenedDivName = '';
var IB_PopupXOffsetDefault = 18;

/*
<div id="ibp_container" style="z-index:98"><a class="ibp_link" href="#" onClick="return false" onMouseOver="IB_Open('ibp_9A', 18)" onMouseOut="IB_Close('ibp_9A')"><div id="ibp_9A" class="ibp_popup" style="z-index:198"><div class="ipb_shadow"><div class="ipb_border1"><div class="ipb_border2"><div class="ipb_content">

<strong>9A:</strong> Availability of Interactive Website

</div></div></div></div></div><span class="underline">9A</span></a></div>

IB_Build uses the format above
*/
var IB_ParentZIndex = 100; // goes down from here, so increase if more than 90 popups on page
var IB_PopupZIndex = 200; // goes down from here, so increase if more than IB_PopupZIndex - IB_ParentZIndex popups on page
var IB_PopupIndex = 1;


function IB_Popup(_LinkText, _PopupText, _PopupXOffset, _PopupWidth)
{
	IB_PopupNoTitle(_LinkText, '<strong>'+_LinkText+':</strong> '+_PopupText, _PopupXOffset, _PopupWidth);
}

function IB_PopupNoTitle(_LinkText, _PopupText, _PopupXOffset, _PopupWidth)
{
	if (_PopupXOffset == undefined)
		_PopupXOffset = IB_PopupXOffsetDefault;
	
	document.write(IB_BuildPopup(_LinkText, _PopupXOffset, _PopupText, _PopupWidth));
}

function IB_BuildPopup(_LinkText, _PopupXOffset, _PopupText, _PopupWidth)
{	
	var PopupID = 'ibp_id'+IB_PopupIndex++;
	var PopupExtraStyle = '';
	if (_PopupWidth != undefined)
		PopupExtraStyle = ';width:'+_PopupWidth+'px;';
//alert(		_PopupWidth+' '+PopupExtra);
		
	var Html = '<div id="ibp_container" style="z-index:'+(IB_ParentZIndex--)+'"><a class="ibp_link" href="#" onClick="return false" onMouseOver="IB_Open(\''+PopupID+'\', '+_PopupXOffset+')" onMouseOut="IB_Close(\''+PopupID+'\')"><div id="'+PopupID+'" class="ibp_popup" style="z-index:'+(IB_PopupZIndex--)+PopupExtraStyle+'"><div class="ipb_shadow"><div class="ipb_border1"><div class="ipb_border2"><div class="ipb_content">'+_PopupText+'</div></div></div></div></div><span class="underline">'+_LinkText+'</span></a></div>';
	
	if (IB_ParentZIndex < 0)
		alert('Update IB_ParentZIndex to be a larger number since too many browser popups on this page');

	return Html;
}

var IB_CurrentlOpenedPopupDivName = '';
function IB_Open(_PopupDivName, _LeftOffset)
{
	if (IB_CurrentlOpenedPopupDivName == _PopupDivName)
	{
		clearTimeout(IB_PopupCloseTimer);
		return; // this popup is already opened
	}
	
	IB_ClearTimers();

	if (IB_LastOpenedDivName != _PopupDivName && IB_LastOpenedDivName != '')
		IB_PerformClose(IB_LastOpenedDivName, true);

Debug("IB_OPen - current "+IB_CurrentlOpenedPopupDivName+", new "+_PopupDivName);

	IB_LastOpenedDivName = _PopupDivName;
	IB_CurrentlOpenedPopupDivName = _PopupDivName;

	var PopupDiv = document.getElementById(_PopupDivName);
	PopupDiv.style.left = _LeftOffset + "px";
	PopupDiv.style.display = "inline";

	FadeIn(_PopupDivName);
}
function IB_Close(_PopupDivName)
{
Debug("	>>IB_CLose("+_PopupDivName);

	IB_PopupCloseTimer = setTimeout("IB_PerformClose('"+_PopupDivName+"')", IB_PopupCloseDelay );
}

function IB_PerformClose(_PopupDivName, _InstantClose)
{
	IB_CurrentlOpenedPopupDivName = '';
	
Debug("	IB_PerformClose("+_PopupDivName+", "+_InstantClose);

	IB_ClearTimers();	

	if (_InstantClose)
	{
		var PopupDiv = document.getElementById(_PopupDivName);
		PopupDiv.style.display = "none";		
	}
	else // fade out otherwise
		FadeOut(_PopupDivName);
}

function IB_ClearTimers()
{
	clearTimeout(IB_PopupCloseTimer);	
	clearTimeout(IB_FadeDiv_Timer);
}

var IB_FadeIncrement = 10;
var IB_FadeTime = 400; // in milliseconds, undershoot the number as fade takes time
var IB_FadeIncrementTime = IB_FadeTime / IB_FadeIncrement;
var IB_FadeDiv_Timer;
function FadeIn(_DivName, _Amount)
{
Debug("	FadeIn("+_DivName+", "+_Amount);
	
	if (_Amount == undefined)
		_Amount = 0;
		
	_Amount += IB_FadeIncrement;		
	if (_Amount >= 100)
		_Amount = 100;
	
	FadeDiv(_DivName, _Amount);
	
	if (_Amount < 100)
		IB_FadeDiv_Timer = setTimeout("FadeIn('"+_DivName+"', "+_Amount+")", IB_FadeIncrementTime);
}
function FadeOut(_DivName, _Amount)
{
Debug("	FadeOut("+_DivName+", "+_Amount);
	if (_Amount == undefined)
		_Amount = 100;
		
	_Amount -= IB_FadeIncrement;		
	if (_Amount <= 0)
		_Amount = 0;

	FadeDiv(_DivName, _Amount);
	
	if (_Amount > 0)
		IB_FadeDiv_Timer = setTimeout("FadeOut('"+_DivName+"', "+_Amount+")", IB_FadeIncrementTime);	
}
function FadeDiv(_DivName, _Percentage) // where percentage is given out of 100
{
	//Debug("fading "+_DivName+" to "+_Percentage);	
	var Div = document.getElementById(_DivName);

	if (_Percentage > 0)
		Div.style.display = "inline";
	else 
	{
		Div.style.display = "none";
		return;
	}
	
	///clearTimeout(IB_FadeDiv_Timer);
	Div.style.opacity = _Percentage / 100;
  Div.style.filter = 'alpha(opacity = '+_Percentage+')';	
}
// Debugging functions
function Debug(_Msg)
{	
return;
	var Debug = document.getElementById('debug_console');
	if (Debug == undefined)
		AddDebugConsole();

	var Debug = document.getElementById('debug_console');

	Time = new Date();
	_Msg = Time.getMinutes()+Time.getSeconds()+": "+ _Msg;

	Debug.innerHTML = _Msg+"<br>"+Debug.innerHTML;
}
function AddDebugConsole()
{
	// add debug div
	var DebugConsole = document.createElement('div');
	DebugConsole.id = "debug_console";
	DebugConsole.style.position = "absolute";
	DebugConsole.style.top = 0;
	DebugConsole.style.left = 0;
	DebugConsole.style.width = "300px";
	DebugConsole.style.height = "600px";

	// add debug window to top left of browser
	document.body.insertBefore(DebugConsole, document.body.firstChild);
}


////////////////////////////////
// Code used to pop up new browser
var newwindow;
function popitup(url, winheight) 
{
	if (newwindow)
		newwindow.close();
	
	var UserAgent = navigator.userAgent;//.toLowerCase();
	var isIE = /*@cc_on!@*/false;
	var isSafari = (navigator.userAgent.indexOf("KHTML")!=-1); // or chrome, konquerer, etc

	var HeightOffset = 0;
	if (isSafari)
		HeightOffset = 40;

	// see if popup is larger than display area
	var IsScrolling = 0;
	if (winheight > (window.screen.availHeight - HeightOffset))
	{
		IsScrolling = 1;
		winheight = window.screen.availHeight - HeightOffset;			
	}
	
	var winwidth = 672;

	// add space for scrollbar
	if (IsScrolling || isIE)
		winwidth += 24; 

	var centerWidth = (window.screen.availWidth - winwidth) / 2;
  var centerHeight = (window.screen.availHeight - winheight) / 3;
	if (IsScrolling)
		centerHeight = 0;
		
	if (centerWidth < 0)
		centerWidth = 0;
	if (centerHeight < 0)
		centerHeight = 0;
		
	// give each popup a different name, so we'll never load into a popup opened on another page but not yet closed
	// because the names are the same.  For popups in the same page, the newwindow reference will work
	var PopupName = "popup_"+Math.floor(Math.random()*10001);

	newwindow = window.open(url,PopupName,'height='+winheight+',width='+winwidth+',resizable=1,scrollbars=1,location=0,menubar=0,toolbar=0,status=0,left='+centerWidth+ 
        ',top='+centerHeight);
	
	if (window.focus)
		newwindow.focus();
	
	return false; 
}


// auto clearing of fields on click
function ResetField(FieldObj, DefaultText) {
  if (FieldObj.value=="") 
    FieldObj.value=DefaultText;
}
function ClearSearchField(FieldObj, DefaultText) {
	// strip off first char since dif browsers treat &nbsp; differently
	FieldValue = FieldObj.value;
	//FieldValue = FieldValue.substring(1);

	if (FieldValue==DefaultText)
    FieldObj.value='';	
}