// Common JavaScript Code
// USDA Procurement Divisions
// Last Modified: Nov 2005

var newWindow;

window.onload = init;

function init() {
//Assists with the separation of document behavior from XHTML structure. Assigns
//	mouse events to various tags and preloads images.
//Requires: Rollover image tags must have an id attribute.
//	The rollover image filename must be identical to the original 
//	image file and end with the additional characters "_over", e.g., 
//  home.gif and home_over.gif. 
//Caller: onload event
//Usage: Register rollover image tags by including their ids in idArray.
//	To display the "over" image by default on a specific page, set the img src 
//	appropriately and remove the id AND name (IE Bug) attributes from the tag.
//	Note: XHTML deprecates the name attribute and is not needed for img tags with an id.

var idArray = new Array('home','fb4p','faqs','about','help','test','contact','advsrch','tips','altfuel','facilities','greenpurchasing','policy','recycling');
var imageArray = new Array();
for (var i=0;i<idArray.length;i++)
	{
		var imageTag = document.getElementById(idArray[i]);
		if (imageTag){
			//Register the relevant image tags
			imageTag.onmouseover = imageOver;
			imageTag.onmouseout = imageOut;
			imageArray[i] = new Image();
			//Preload
			imageArray[i].src = imageTag.src.substring(0,imageTag.src.lastIndexOf('.')) + '_over' + imageTag.src.substring(imageTag.src.lastIndexOf('.'));	
		}
	}
	//Register the jump menu  Note: removal of the trigger from the template markup disables DWs ability to update the links in the jump menu.
	var widget = document.getElementById('audienceJumpMenu');
	if (widget) {
		widget.onchange = jumpToLink;
	}
}


function imageOver(){
	this.src = this.src.substring(0,this.src.lastIndexOf('.')) + '_over' + this.src.substring(this.src.lastIndexOf('.'));
}

function imageOut(){
	this.src = this.src.substring(0,this.src.lastIndexOf('_')) + this.src.substring(this.src.lastIndexOf('.'));
}

function jumpToLink(){
	MM_jumpMenu('parent',this,1)
}	

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openExternalWindow(url)
{
	newWindow=window.open(url,'extWindow');
	if (window.focus){newWindow.focus()}
}



