// pagefunctions.js
//
//These are some javascript functions that are used by:
//FindByCategory.jsp
//FindByName.jsp
//FindWithinDistance.jsp

/** quick browser tests */
var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

/** show function makes some of the objects in jsp visible to user
  * such as help text. 
  *
  * parameters: sw - is a boolean variable. true for visible, false for hidden
  *             obj - is the obj that should be visible or hidden
  */ 
function show(sw,obj) {
	if (sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'visible';
	if (!sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'hidden';
	if (sw && ns4) document.layers[obj].visibility = 'visible';
	if (!sw && ns4) document.layers[obj].visibility = 'hidden';
	if (sw && ns6) document.getElementById(obj).style.visibility = 'visible';
	if (!sw && ns6) document.getElementById(obj).style.visibility = 'hidden';
}

/** toggle function toggles the visibility for help items
  * 
  * parameters: obj - is the obj that is toggled
  *
  */
function toggle(obj) {
	if (ie4 || ie5) {
		if (document.all[obj].style.visibility=='visible') {
			document.all[obj].style.visibility='hidden';
		}
		else {
			document.all[obj].style.visibility='visible';
		}
	}
	else if (ns4) {
		if (document.layers[obj].visibility=='visible') {
			document.layers[obj].visibility='hidden';
		}
		else {
			document.layers[obj].visibility='visible';
		}
	}
	else if (ns6)
	{
		if (document.getElementById(obj).style.visibility=='visible') {
			document.getElementById(obj).style.visibility='hidden';
		}
		else {
			document.getElementById(obj).style.visibility='visible';
		}
	}
}
/** makeEnable function enables object so that it is functional and clickable
  * 
  * parameters: element - is the object that is made enabled
  *
  */
function makeEnable(element)
{
	element.disabled=false;
}
/** makeDisable function disables object so that it is not functional and clickable
  * 
  * parameters: element - is the object that is disabled
  *
  */
function makeDisable(element)
{
	element.disabled=true;
}

/** transferOption function transfers an option from one dropdown list to another 
  * 
  * parameters: dropdownlistA - is the source of the option
  *             dropdownlistB - is the destination of the option
  */
function transferOption(dropdownlistA, dropdownlistB) {
    var index = dropdownlistA.selectedIndex;
    if (index > -1) {
        var newoption = new Option(dropdownlistA.options[index].text, dropdownlistA.options[index].value, false, false);
        dropdownlistB.options[dropdownlistB.length] = newoption;
        if (!document.getElementById) history.go(0);
        dropdownlistA.options[index] = null;
    }
}

/**function PageForward(folder, page) - this function forwards the window to the
  * 			page passed in the page argument the page should be in the folder
  *				passed in the folder argument
  */
function PageForward(page){
	var CurrentUrl=new String(window.location);
	var i=CurrentUrl.indexOf("VTQuest");
	if(i > -1){
		var URL= CurrentUrl.substring(0,i+7);
		CurrentUrl=URL.concat('/').concat(page);
	}
	window.location=CurrentUrl;
} 	

/** Redirect(argument,value) - This function adds arguments onto the url and reloads
  * 
  * parameters: argument - this is either 'name' or 'category' depending on the  
  *				value - the value of the argument (this is an integer key value)
  */
function Redirect(argument,value)
{
	var CurrentUrl=new String(window.location);
	var pastlocation=CurrentUrl.indexOf("location=");
	var pastcategory=CurrentUrl.indexOf("category=");

	//note: setting the window.location variable reloads the page
	
	//hopefully these tests will be generalized/simplified in the future
	if(pastcategory==-1 && argument=="category")
	{	
		window.location=CurrentUrl.concat("?").concat(argument).concat("=").concat(value);
	}
	else if(pastcategory!=-1 && argument=="category")
	{
		window.location=CurrentUrl.substring(0,pastcategory-1).concat("?").concat(argument).concat("=").concat(value);
	}
	else if(pastcategory==-1 && argument=="location")
	{
		window.location=CurrentUrl.concat("?category=-1&").concat(argument).concat("=").concat(value);
	}
	else if(pastcategory!=-1 && pastlocation==-1 && argument=="location")
	{
		window.location=CurrentUrl.concat("&").concat(argument).concat("=").concat(value);
	}
	else if(pastlocation!=-1 && argument=="location")
	{
		window.location=CurrentUrl.substring(0,pastlocation-1).concat("&").concat(argument).concat("=").concat(value);
	}
}

/*this function is used to refresh the getdirections page
*/
/** Refresh(argument1, argument2,value1,value2,page) - This function adds arguments onto the url and reloads
  * 
  * parameters: arguments - these will be parameter names put in the url  
  *				value - these are the respective parameter values
  				page  - This is the page to be redirected to with the 
  						parameter name,value pairs
  */
function Refresh(catagory1,list1, catagory2,list2, cat1Value,list1Value,cat2Value,list2Value,page)
{
	var CurrentUrl=new String(window.location);
	var i=CurrentUrl.lastIndexOf("VTQuest/");
	if(i > -1){
		var URL= CurrentUrl.substring(0,i+8);
		CurrentUrl=URL.concat(page);
	}
	//note: setting the window.location variable reloads the page
	
	//hopefully these tests will be generalized/simplified in the future
	window.location=CurrentUrl.concat("?").concat(catagory1).concat("=").concat(cat1Value).concat("&").concat(list1).concat("=").concat(list1Value).concat(catagory2).concat("=").concat(cat2Value).concat("&").concat(list2).concat("=").concat(list2Value);

}

function SelectAll(SelectBox)
{
	for(index=0;index<SelectBox.options.length;index++) {
		SelectBox.options[index].selected=true;
	}
}
