function addEforumWinOpts(className)
{
	if (typeof document.getElementsByClassName != 'function') { return -1; }
	if(screen.width) { w = screen.width - 40; }
	else { w = 600; }
	
	if(screen.height) { h = screen.height - 100; }
	else { h = 500; }
	
	//set default parameter values
	var className = (className == null)	? "eform" : className;
	var defaultWinOptions = "resizable=yes,toolbar=no,scrollbars=1,width=" + w + ",height=" + h + ",screenX=20,screenY=20";

	var position = 0;
	popUpsLinks = document.getElementsByClassName(className);
	
	for(position in popUpsLinks)
	{
		popUpsLinks[position].popWinOpts = defaultWinOptions;
	}
}

function addJsPopus(className, winOptions)
{
	 if (typeof document.getElementsByClassName != 'function') { return -1; }
	
	//set default parameter values
	var className = (className == null)	? "popup" : className;
	var defaultWinOptions = "resizable=yes,toolbar=no,scrollbars=1,width=600,height=500,screenX=100,screenY=100";
	var winOptions = (winOptions == null) ? defaultWinOptions : winOptions;

	var position = 0;
	popUpsLinks = document.getElementsByClassName(className);
	
	for(position in popUpsLinks)
	{
		if(popUpsLinks[position].popWinOpts)
		{
			convertLinkToPopup( popUpsLinks[position],popUpsLinks[position].popWinOpts);
		}
		else
		{
			convertLinkToPopup( popUpsLinks[position],defaultWinOptions);
		}
	}
}

function clearInput(target, msg)
{
	if(target.value == msg)
	{
		target.value = "";
		return true;
	}
	return false;
}

function setInput(target, msg)
{
	if(target.value == "")
	{
		target.value = msg;
		return true;
	}
	return false;
}

function convertLinkToPopup(targetItem, winOptions)
{
	if(!targetItem) { return; }

	targetItem.onclick=function()
	{
		
		window.open(this.getAttribute("href"),"cmwf",winOptions);
		return false;
	}
	return true;
}

function init()
{
	var searchMsg = "Enter keywords";
	var focusedClass = " focused";
	var navPrimaryTags = new Array("LI");
	
	addHover("navPrimary", navPrimaryTags);
	
	if(document.getElementById("searchSite"))
	{
		var srchInput = document.getElementById("searchSite");
		
		srchInput.onfocus = function()
		{
			clearInput(srchInput, searchMsg);
			this.className+=focusedClass; 
		};
		
		srchInput.onblur = function()
		{
			setInput(srchInput, searchMsg);
			this.className=this.className.replace(focusedClass, "");
		};
		
		setInput(srchInput, searchMsg);
	}
	
	
	
	if(document.getElementById("searchSiteWithin"))
	{
		var withinSelectBox = document.getElementById("searchSiteWithin");
		withinSelectBox.className+= " jse"; 
		
		var wsbul = withinSelectBox.getElementsByTagName("UL");
		wsbul = wsbul[0];
		
		var wsbli = wsbul.getElementsByTagName("LI");
		var firstWsbli = wsbli[0];

		var fLi		= document.createElement("li");
		var linkText	= document.createTextNode("Entire Site");
		fLi.setAttribute("class", "first");
		
		// check to see if any are select, if so use that text
		var searchSubCollection = withinSelectBox.getElementsByTagName("INPUT");
		
		for(var count = 1; count < searchSubCollection.length; count++)
		{
			if(searchSubCollection[count].getAttribute("checked"))
			{
				linkText.nodeValue = searchSubCollection[count].nextSibling.nodeValue;
			}
			
		}
		
		
		fLi.appendChild(linkText);
		wsbul.insertBefore(fLi,firstWsbli);
		
		
		wsbli[0].onclick = function()
		{
			if(withinSelectBox.className.indexOf("focused") != -1)
			{
				withinSelectBox.className = "group jse";
			}
			else
			{
				withinSelectBox.className = "group jse focused";
			}
		};

		for(var i = 1; i < wsbli.length; i++)
		{
			wsbli[i].onclick=function()
			{
				var t = this.firstChild.childNodes;
				wsbli[0].firstChild.nodeValue = t[1].nodeValue;
				withinSelectBox.className = "group jse";
				selectScope(wsbli[0].firstChild.nodeValue);
  			}
			
			wsbli[i].onmouseover=function()
			{
				this.className+=" over";
  			}
				
 			wsbli[i].onmouseout=function()
			{
 				this.className=this.className.replace("over", "");
  			}
		}
			
	}
	
function selectScope(scopeValue){
	switch(scopeValue){
		case 'Publications':
		document.getElementById('scopePubs').checked = true;
		break;
		case 'Grants':
		document.getElementById('scopeGrants').checked = true;
		break;
		case 'Newsletters':
		document.getElementById('scopeNewsletters').checked = true;
		break;
		case 'Authors & Bios':
		document.getElementById('scopeProfile').checked = true;
		break;
		default:
		document.getElementById('scopeAll').checked = true;
	}
}
	
	
}

addLoadEvent(init);
addLoadEvent(addEforumWinOpts);
addLoadEvent(addJsPopus);

