/*********************************************
	JavaScript for Intranet
	1/8/2003
	Chad Martin
**********************************************/

// function for drop-down box finding <a name> tags (quick search)
function MovePageDown(frmname,object)
{ 	var tmpsearchterm = document[frmname].elements[object].value;
	if (tmpsearchterm != "")
		{	window.location.hash = tmpsearchterm;	}
	return false;}

// pass in form name and form element to give focus to
function givefocus(formname,forminputname)
{		document[formname].elements[forminputname].focus();	}

// Java script opens a new window
function openwindow(windowname,windocument,height,width)
{	var winleft = 1;
	var wintop = 1;
	var winheight = height;
	var winwidth = width;
	var winopenstring = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,replace=true,top=" + wintop +",width=" + winwidth + ",height=" + winheight + ",left=" + winleft;
	var tmppage = windocument;
	newwindow = window.open(tmppage,windowname,winopenstring);
	newwindow.focus(); 
}


/*(2/18/2003) this function would be much handier if I knew some list functions
that could split up a list into an array (so more than 2 objects could be passed in
without me adding to the function parameters every time I needed a new requirement) */

// Form field validation
function validate(frmname,object0,object1)
{	
	// initialize list variable
	var list = "";
	// set up form name
	var formname = frmname;
	// create new array
	required = new Array();
	
	// set up array elements
	required[0] = document[frmname].elements[object0];
	// if the variable isdefined, continue
	if (typeof(object1) != "undefined")
	{	required[1] = document[frmname].elements[object1];	}

	// loop through the array elements
	for(i=0; i < required.length; i++)
	{	// the name of the element
		var name = required[i].name;
		// the value of the element
		var value = required[i].value;
		// the type of the element
		var type = required[i].type;

		// if there is no value for this element
		if(value == "")
		{	// append the element to the list
			list = list + name + "\n";	
		}
	}
	
	// if list is blank, submit the form
	if(list != "")
		{	// alert the user of the required fields
			alert("The following are required fields: \n\n" + list);
		}
	// if the list is not blank
	else
		{	document[formname].submit();	}
		
}



// function to change drop down box
function changeselect(formname,input,dropdown)
{	
	function object(textbox,dropdownbox) 
	{   this.textbox = textbox;
	    this.dropdownbox  = dropdownbox;
	}
	
	var obj = new object (document[formname].elements[input],document[formname].elements[dropdown]);
	
	// loop through the dropdown box
	for (i=0; i <= obj.dropdownbox.length; i++)
	{	
		/* alert(obj.dropdownbox.value);
		alert(obj.textbox.value);
		alert(document[formname].elements[obj.dropdownbox.name].selectedIndex);
		alert(i);
		break; */
		
		// if the input text equals drop down box value
		if(obj.dropdownbox.value == obj.textbox.value)
		// set dropdownbox selected index equal to i
		{	document[formname].elements[obj.dropdownbox.name].selectedIndex = i;	}
	}
}

