
function toggle_section(section) {
	var s = document.getElementById("section_"+section);
	var i = document.getElementById("toggle_"+section);
	if(s.className=="shown") {
		s.className = "hidden";		
		i.src = "/WHVIntl/CDA/Images/common/icon_plus.gif";
	} else {
		s.className = "shown";		
		i.src = "/WHVIntl/CDA/Images/common/icon_minus.gif";
	};
	return false;
};


function setScrolls() {
	var ie = navigator.appName.toLowerCase().indexOf("netscape")==-1;
	if(ie) {
		var divs = document.getElementsByTagName("div");
		for(var i=0; i<divs.length; i++) if(divs[i].id=="scroll") divs[i].className = "scroll";
	};
};

// WHV Template

var delay, timer, curr, elem, table, pos, cpos, el, str, product, srchengine, news, release, normobj, ovrobj, isIE, offsetNN, iframe, isMacIE, sizeNo; //basic variables used throughout
var bp, pt, mk, pr, mt, com, hlp; //variables for image rollovers

delay						= 100; //timeout for menu
isIE						= (navigator.userAgent.indexOf("MSIE") > -1); //is this IE?
isMacIE						= ((navigator.userAgent.indexOf("MSIE") > -1) && (navigator.userAgent.indexOf("Mac") > -1));
sizeNo						= (isMacIE) ? 
	"5" :
	"3";
offsetNN					= (isIE) ?
	0 :
	1;
product					= "productleft"; // newly decleared tab var for product info page
srchengine					= "prdsrch"; //products / graphics search options - represents ths ID of the active (selected) <a> tag 

news						= "newsleft"; //news / my inbox / notices swap - see srchengine
release						= "relleft"; //releases section - see srchengine

//color values for over and normal states
normobj						= new Object();
ovrobj						= new Object();

normobj["bcol"]				= "#003366";
normobj["tcol"]				= "#FFFFFF";
normobj["state"]			= "norm";
ovrobj["bcol"]				= "#83bcd9";
ovrobj["tcol"]				= "#003366";
ovrobj["state"]				= "over";

//Display / hide menus
/*
	Sets a positioning for the drop downs adjusted to the left. Can eb centered by dividing image width by 2
	
	@params:
		e					= [object] reference to calling element
*/
var showmenu				= function(e){
	if(timer){
		if(elem) setcol(elem, normobj);
		setsubmenu(curr.id);
	}
	/*
		Mac IE5 Offset strangeness band-aid.
		Forces the last menu item to flush its drop-down menu with the right side border of the WHV window
		
		If Help is no longer the last option, be sure to replace this value with the id of the last object.
	*/
	
	var MacIEOffset;
	iframe					= document.getElementById("myiframe");
	clearTimeout(timer);
	setcol(e.id, ovrobj);
	curr					= e;
	
	table					= document.getElementById("m"+e.id); 
	pos						= getPos(document.getElementById("td"+e.id));//gets the Table Cell <td> object containing the <a> tag
	
	if(isMacIE) //this statement allows for errors in Mac IE5 and adjusts menu items which would overlap the safe area back inside of it.
	{
		var num				= Math.ceil(((document.body.offsetWidth - 740) / 2)-2);
		var finalX			= document.body.offsetWidth - num;// determine the distance of the container from the right edge of the screen
		var currX			= pos.x+175;
		if(currX>finalX)
		{
			MacIEOffset		= currX-finalX;
		}
		else
		{
			MacIEOffset		= 1;
		}
	}
	else
	{
		MacIEOffset			= 0;
	}
	table.style.left		= pos.x-offsetNN-MacIEOffset+"px";
	table.style.top			= pos.y+34+"px"; //34 is the height of the Cell object (32) + 2 px for borders
	table.style.display		= "block";
	if(isIE)
	{
		iframe.style.left		= pos.x-offsetNN+"px";
		iframe.style.top		= table.style.top;
		table.style.zIndex		= 100;
		iframe.style.zIndex		= 99;
		iframe.style.height		= table.offsetHeight;
		iframe.style.display	= "block";
		iframe.style.width		= table.offsetWidth;
	}
};

/*
	ActiveOver() is a function used for elements that have drop down menus displayed while the user is in the section
	represented by the main button. I have set an example of this on the template page (Marketing).
	
	I'm using images with the _sel name to indicate selected images. The only difference between these and the other
	buttons is that I have included a 1 pixel black border on the selected images for spacing between them and their
	neighbors.
*/
var activeover				= function(e){
	if(timer){
		if(image) setcol(elem, normobj);
		setsubmenu(curr.id);
	}
	/*
		Hook for the <select> disable feature
	*/
	/*if(e.id == clrselone || e.id == clearseltwo || e.id == clearselfour){
		setselvis("hidden", "qksrchsel");
		setselvis("visible", "favsrch");
	} else if(e.id == clearselthree){
		setselvis("visible", "qksrchsel");
		setselvis("hidden", "favsrch");
	} else {
		setselvis("visible", "favsrch,qksrchsel");
	}*/
	clearTimeout(timer);
	el						= document.getElementById(e.id);
	curr					= e;
	
	table					= document.getElementById("m"+e.id);
	pos						= getPos(document.getElementById("td"+e.id)); //gets the Table Cell <td> object containing the <a> tag
	table.style.left		= pos.x-offsetNN+"px";
	table.style.top			= pos.y + el.style.height+2+"px";
	table.style.display		= "block";
	{
		iframe.style.left		= pos.x-offsetNN+"px";
		iframe.style.top		= table.style.top;
		table.style.zIndex		= 100;
		iframe.style.zIndex		= 99;
		iframe.style.height		= table.offsetHeight;
		iframe.style.display	= "block";
		iframe.style.width		= table.offsetWidth;
	}
	
};

var subover					= function(e){
	clearTimeout(timer);
	setBGColor(e.id, "#e6f4f7");
};

var subout					= function(e){
	settimer();
	setBGColor(e.id, "#83bcd9");
};

var settimer				= function(){
	timer					= setTimeout("hidemenu()", delay);
};

var hidemenu				= function(){
	if(elem){
		setcol(elem, normobj);
	} 
	table					= document.getElementById("m"+curr.id);
	table.style.display		= "none";
	if(isIE) iframe.style.display	= "none";
	setselvis("visible", "favsrch,qksrchsel");
	setselvis("visible", "favsrch");
	setselvis("visible", "qksrchsel");
};

var setselvis				= function(vis, id){
	if(id.indexOf(",") > -1)
	{
		var arr				= id.split(",");
		for(var i = 0; i < arr.length; i++)
		{
			if(document.getElementById(arr[i])!=null){	
				document.getElementById(arr[i]).style.visibility = vis;
		 	}	
		}
	}
	else
	{
		if(document.getElementById(id)!=null){
			document.getElementById(id).style.visibility = vis;
		}	
	}
	/*if(loc == "top"){
		document.getElementById("qksrchsel").style.visibility = vis;
	} else if(loc == "srch") {
		document.getElementById("assettype").style.visibility = vis;
	} else {
		document.getElementById("qksrchsel").style.visibility = vis;
		document.getElementById("assettype").style.visibility = vis;
	}*/
};

var setsearchselvis			= function(vis){
	
};

var setsubmenu				= function(id){
	table					= document.getElementById("m"+id);
	table.style.display		= "none";

};
//End menu display

//color swap
/*
	Swaps colors (text and BG) - simple version
	
	@params:
		id					= unique ID of the <a> tag containing the image. 
		obj					= Object with properties representing the state of the active request
*/
var setcol					= function(id, obj){
	var arrow				= document.getElementById("i"+id);
	el						= document.getElementById(id);
	el.style.color			= obj.tcol;
	setBGColor("td"+id, obj.bcol);
	
	//set items based on state
	arrow.src				= (obj.state == "norm") ?
		document.getElementById("image_path").value+"arrow.gif" :
		document.getElementById("image_path").value+"arrow_over.gif";
	elem					= (obj.state == "norm") ?
		null :
		id;
};
//end color swap

//potitioning
/*
	Positions elements to the left hand side of the calling image
	
	@params:
		img					= [object] reference to the iage object
*/
var getPos					= function(img){
	return {x: getPosX(img), y: getPosY(img)};
};

var getPosX					= function(ele) {
	var curr				= 0;
	if(ele.offsetParent){
		while(ele.offsetParent){
			curr			+= ele.offsetLeft;
			ele				= ele.offsetParent;
		};
		return curr;
	} else if(ele.x) {
		curr				+= ele.x;
		return curr;
	}
};

var getPosY					= function(ele) {
	var curr				= 0;
	if(ele.offsetParent){
		while(ele.offsetParent){
			curr			+= ele.offsetTop;
			ele				= ele.offsetParent;
		};
		return curr;
	} else if(ele.y){
		curr				+= ele.y;
		return curr;
	}
};
//end positioning

//text field background color settings
/*
	@params:
		id					= element id
		c					= html hex color # as a string (Ex. '#FFFFFF')
*/
var setBGColor				= function(id, c){
	document.getElementById(id).style.backgroundColor	= c;
};

//set misc options - search, news, releases
/*
	@params:
		id					= <a> tag id of the caller
		sec					= designates the page section affected (differs based on variables)
		cls					= class to swap for active / inactive
*/
var setopts					= function(id, sec){
var cls					= document.getElementById(id).className;
	switch(sec)
	{
		
		case "products":
			setproductsoptions(id, cls);
			break;
		case "search":
			setsrchoptions(id, cls);
			break;
		case "releases":
			setreloptions(id, cls);
			break;
		default: //news, inbox, etc
			setnewsoptions(id, cls);
			break;
	}
};

var setproductsoptions			= function(id, cls){
	//alert("are we here222");
	if(id == product){
		return;
	} else {
		swapopts(id, cls, product);
		product			= id;
	}
};

var setsrchoptions			= function(id, cls){
	if(id == srchengine){
		return;
	} else {
		swapopts(id, cls, srchengine);
		srchengine			= id;
	}
};

var setreloptions			= function(id, cls){
	if(id == release){
		return;
	} else {
		swapopts(id, cls, release);
		release				= id;
	}
};

var setnewsoptions			= function(id, cls){
	if(id == news){
		return;
	} else {
		swapopts(id, cls, news);
		news				= id;
	}
};

var swapopts				= function(id, cls, currid){
	var altcls				= (cls == "srchinactivebtn") ?
		"srchactivebtn" :
		"dkbluebtns";
	
	var activetab			= document.getElementById(currid+"opts");
	var inactivetab			= document.getElementById(id+"opts");
	var activebtn			= document.getElementById(currid);
	var inactivebtn			= document.getElementById(id);
	var activetd			= document.getElementById("td"+currid);
	var inactivetd			= document.getElementById("td"+id);
	
	activetab.style.display = "none";	
	inactivetab.style.display = "block";

	activetd.className 		= cls;
	inactivetd.className	= altcls;
	activebtn.className 	= cls;
	inactivebtn.className 	= altcls;
};
