// Global Variable Declarations
var isLoaded = false;

// Global Functions

/*
// This method is called when the site intro flash movie is completed
function siteIntroComplete()
{
	//alert(appRoot + 'Home.aspx');
	window.location = appRoot + "Home.aspx";
	return true;
}
*/


// Adds appropriate targets to anchor tags.
function processAnchorTargets()
{
	if (!document.getElementsByTagName) return;

	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup")
		{
			anchor.target = "_blank";
		}
	}
}

// Submits form[0]
function submitForm()
{
	document.forms[0].submit();
	return true;
}

// Submit Target Form
function submitTargetForm(in_formIndex)
{
	document.forms[in_formIndex].submit();
	return true;
}

// Print current page
function printPage()
{
	window.print();
}

// Image Swaps
function imageSwap(in_Name, in_State)
{
	if (!isLoaded)
	{
		return true;
	}
	document.images[in_Name].src = eval(in_Name + "_" + in_State + ".src");
}

  
// Window Openers
function popWindow(in_target, in_WindowParameters)
{
	//windowParameters are very browser dependent.  Be sure to test in all browswers when
	//changing window parameters.

	//For instance for Both IE and Netscape browsers to absolutely position a window properly 2 sets
	// of dimensions should be included example: screenX=0,screenY=0,left=0,top=0
	//To set the height and width of the windows example: width=625,height=400
	//A Good PopupWindow in all browsers with no toolbar, no scrollbar, and not resizable.
	//windowParameters = "scrollbars=no,width=625,height=400";
	
	if ( in_WindowParameters.length == 0 )
	{
		in_WindowParameters = "resizable,dependent,toolbar,scrollbars,location,status,menubar";
	}
	
	popupWin = window.open(in_target,'PopupWindow',in_WindowParameters);
}

function blurInputs()
{
	if (!document.getElementsByTagName) return;

	var inputs = document.getElementsByTagName("input");
	
	for (var i=0; i < inputs.length; i++)
	{
		var inp = inputs[i];
		inp.blur();
	}
	
}

// This is used by the flash scroll bars.
function scrollBarItemChanged(in_ObjectTypeId, in_ObjectIdentifier)
{
	//alert("here");
	//message = "New Scrollbar item: TypeId=" + in_ObjectTypeId + " Id=" + in_ObjectIdentifier;
	//alert(message);

	var myForm = document.aspnetForm;
	var typeId = myForm["SelectedScrollbarMainPromoBoxTypeID"].value;
	var objectId =  myForm["SelectedScrollbarMainPromoBoxObjectID"].value;
	var previouslySelectedElementId = "ScrollbarMainPromoBox_" + typeId + "_" + objectId;
	
	// Get a reference to the previously selected element
	var previouslySelectedElement = null;
	previouslySelectedElement = getElementFromId(previouslySelectedElementId);

	// Get the newly selected item and show it.
	var newSelectedElementId = "ScrollbarMainPromoBox_" + in_ObjectTypeId + "_" + in_ObjectIdentifier;
	var newSelectedElement = null;
	newSelectedElement = getElementFromId(newSelectedElementId);

	// Load the new image.
	var imgSrcFormName = newSelectedElementId + "_ImgSrc";
	var imgSrc = myForm[imgSrcFormName].value;
	var imgElementName = newSelectedElementId + "_Img";
	
	// Previous element will be hidden, and new element
	// will be shown upon image load. This statement
	// must come before the img.src property is set
	document.images[imgElementName].onload = 
		function () 
		{ 
			if (previouslySelectedElement != null)
			{
				hideElement(previouslySelectedElement);
			}
			if (newSelectedElement != null)
			{
				showElement(newSelectedElement); 
			}
		}

	document.images[imgElementName].src = imgSrc;

	// Save the currently selected item.
	myForm["SelectedScrollbarMainPromoBoxTypeID"].value = in_ObjectTypeId;
	myForm["SelectedScrollbarMainPromoBoxObjectID"].value = in_ObjectIdentifier;

	//message = "New Scrollbar item: TypeId=" + in_ObjectTypeId + " Id=" + in_ObjectIdentifier;
	//alert(message);
}

// Flash integration functions
function xxxscrollBarItemChanged(in_ObjectTypeId, in_ObjectIdentifier)
{
	message = "New Scrollbar item: TypeId=" + in_ObjectTypeId + " Id=" + in_ObjectIdentifier;
	alert(message);
}

// Functions for reading/writing session cookies
function readCookie(name)
{
	var tC = document.cookie.split('; ');
	for (var i = tC.length - 1; i >= 0; i--) {
		var x = tC[i].split('=');
		if (name == x[0]) return unescape(x[1]);
	}
	return null;
}

function writeCookie(name, value) 
{
	document.cookie = name + '='; // clear the current value
	document.cookie = name + '=' + escape(value);
}

// Global Initialization

function scrollbarGlobalInit()
{
	// Call globaInit();
	globalInit();
	
	defaultScrollbarElement = getElementFromId("ScrollbarMainPromoBox_0_Default");
	
	if (defaultScrollbarElement != null)
	{
		showElement(defaultScrollbarElement);
	}
	
	// Save the currently selected item.
	var myForm = document.aspnetForm;
	myForm["SelectedScrollbarMainPromoBoxTypeID"].value = "0";
	myForm["SelectedScrollbarMainPromoBoxObjectID"].value = "Default";

}

function globalInit()
{
    //window.onresize = function () {location.reload(); };
	processAnchorTargets();
	
	var languageCode = "";

	window.name = mainWindowName;
	
	isLoaded = true;
}