// All code (besides a few open source functions) are copyright 2009 EoSTudios.com
// If you would like to use this code, please contact orders@eostudios.com and pay a one time $100 fee.
// That would help to pay for the many hours it took to create.
//

// auto clearing of fields on click
function ResetField(FieldObj, DefaultText) {
  if (FieldObj.value=="") 
    FieldObj.value=DefaultText;
}
function ClearSearchField(FieldObj, DefaultText) {

	if (FieldObj.value==DefaultText)
    FieldObj.value='';	
}


function showDiv(_id)
{
	var Div = document.getElementById(_id);
	if (Div == undefined)
		return;
	Div.style.display = "block";
	return false;
}
function hideDiv(_id)
{
	var Div = document.getElementById(_id);
	if (Div == undefined)
		return;
	Div.style.display = "none";
	return false;
}
function toggleDiv(_id)
{
	var Div = document.getElementById(_id);
	if (Div == undefined)
		return;

	Div.style.display = (Div.style.display == "block") ? "none" : "block"; 
	return false;
}



////////////////////////////////
// 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 = 2;

/*
<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)
{
	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);

	PopupPlacementDiv = PopupID+"_pl";

	PopupID
		
	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 id="'+PopupPlacementDiv+'" 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 = '';
var IB_MaxLeftOffset = 123;

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);

	PopupPlacementDivName = _PopupDivName+"_pl";
	PopupPlacementDiv = document.getElementById(PopupPlacementDivName);

	IB_LastOpenedDivName = _PopupDivName;
	IB_CurrentlOpenedPopupDivName = _PopupDivName;

	var PopupDiv = document.getElementById(_PopupDivName);
	
	_LeftOffset += PopupPlacementDiv.offsetWidth;
	
	if (_LeftOffset > IB_MaxLeftOffset)
	{
		PopupDiv.style.top = "17px";
		_LeftOffset = IB_MaxLeftOffset;
	}
	
	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;
	_Msg = ": "+ _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 winwidth = 672;
	var IsScrolling = 0;
	var HeightOffset = 50;
	if ((winheight+HeightOffset) > window.screen.height)
	{
		IsScrolling = 1;
		winheight = window.screen.height-HeightOffset;
		winwidth += 24; // make room for scrollbar		
	}

	var centerWidth = (window.screen.width - winwidth) / 2;
  var centerHeight = ((window.screen.height-HeightOffset) - winheight) / 3;
	if (IsScrolling)
		centerHeight = 0;
		
	if (centerWidth < 0)
		centerWidth = 0;
	if (centerHeight < 0)
		centerHeight = 0;
		
	newwindow = window.open(url,'name','height='+winheight+',width='+winwidth+',resize=1,scrollbars='+IsScrolling+',menubar=0,toolbar=0,status=0,left='+centerWidth+ 
        ',top='+centerHeight);
	
	if (window.focus)
		newwindow.focus();
	
	return false; 
}

////////////////////////////////////////
// Form Field accessors
////////////////////////////////////////

////////////////////////////////////////
function disableInput(_Obj)
{
	_Obj.disabled = true;
}

////////////////////////////////////////
function enableInput(_Obj)
{
	_Obj.disabled = false;
}

////////////////////////////////////////
function setSelectListToValue(value, selectId)
{
	var i, si, v, args=setSelectListToValue.arguments;
	if ((obj=document.getElementById(args[1])) != null)
	{
		v = args[0];
		
		for(i=0; i<obj.length; i++){
			if(obj.options[i].value == v){
				si = i;
			}
		}

		obj.selectedIndex = si;
	}
}

////////////////////////////////////////
function getSelectValue(_Obj)
{
	return _Obj.options[_Obj.selectedIndex].value;
}

////////////////////////////////////////
function getRadioValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

////////////////////////////////////////
function setRadioValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;

	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		//Debug(radioObj[i].value);
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
