// JavaScript Document
function submit_search(the_form)
{
	var theForm = document.getElementById(the_form);
	theForm.action = "/search.php?page=-1";
	theForm.submit();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// javascript drop-down menu for searching
// Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	MM_swapImgRestore();
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

function clear_all_items()
{
	var myitems = new Array("all",
        					"pathway",
        					"pev","ppl","ppe","per","psc","pmi","por","pre",
							"community",
        					"cev","cpl","cpe","cer","csc","cmi","cor","cre",
							"user");
	for (i=0; i < 20; i++) {
		mi = document.getElementById(myitems[i]);
		//alert(myitems[i]);
		mi.style.background="#f2f2f2";
		if ((i != 0) && (i != 1) && (i != 10) && (i != 19)) {
			mi.style.color = "#000000";
		} else {
			mi.style.color = "#01209D";
		}
	}
}

function onsearchclick(fid)
{
	clear_all_items();
	href_item = document.getElementById(fid);
	href_item.style.background = "#49A3FF";
	href_item.style.color = "#ffffff";

	filter_input = document.getElementById('filter');
	filter_input.value=fid;
	MM_swapImgRestore();
	
}

function checkEnterKey(form_name, e, type)
{
	//the purpose of this function is to allow the enter key to 
	//point to the correct button to click.
	var key;

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		key = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		key = e.keyCode //character code is contained in IE's keyCode property
	}

	if (key == 13)
	{
		//Get the button the user wants to have clicked
		//alert (xform);
		//var btn = document.getElementById(btnName);
		var theForm = document.getElementById(form_name);
		if (theForm != null)
		{ //If we find the button click it
			//alert ("3:" + xform.action.value);
			//btn.click();
			//xform.submit();
			if (type == 0) {
				theForm.submit();
			} else if (type == 1) {
				submit_search(form_name);	
			}
			event.keyCode = 0
		}
	}
}

//------------------------------------------------**************--------------------------------------------------------
					// validation for post
//------------------------------------------------**************--------------------------------------------------------

/* Function to remove the leading and trailing spaces*/
function trim_text(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//End of Function

