// JavaScript Document

function addMapOption(targetselectbox,value)
{
	//firstly check that the item does not already exist in the target droplist
	if(checkOption(targetselectbox, value)){
		targetselectbox.options[targetselectbox.length] = new Option(value, value);
	}
	targetselectbox.focus();
}

function addOption(selectbox,targetselectbox)
{
	//interate through each of the selected items form the selectbox droplist
	var i;
	for(i=selectbox.options.length-1;i>=0;i--){
		if(selectbox.options[i].selected){
			//firstly check that the item does not already exist in the target droplist
			if(checkOption(targetselectbox, selectbox.options[i].value)){
				//add the selected value to the target droplist
				//this is the cross browser method for adding options via javascript
				targetselectbox.options[targetselectbox.length] = new Option(selectbox.options[i].text, selectbox.options[i].value);
			}
		}
	}
}

function checkOption(selectbox, value){
	//alert(selectbox.length);
	if(selectbox.length > 0){
		for (var i=0; i < selectbox.length;++i){
			if(value == selectbox.options[i].value){//if the value submitted is already in the target droplist return false
				alert("You've already added "+selectbox.options[i].value+" to this list");
				return false;
			}
		}
	}
	return true;
}

function removeOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--){
		if(selectbox.options[i].selected){
			selectbox.remove(i);
		}
	}
}

function allSelect() 
{
	//use the function arguments array to pass limitless arguments to the function
   var items = allSelect.arguments //assign arguments to variable
   var itemssize = allSelect.arguments.length// assign number of arguments to variable

   for (i = 0;i < itemssize;i++)
   {
		List = items[i];
		for (j=0;j<List.length;j++)
		{
			//debug alert(List.options[j].value);
			List.options[j].selected = true;
		}
   }
   return true;
} 

function allSelectSubmit()
{
	
	List1 = document.searchform.area_receiver;
	for (i=0;i<List1.length;i++)
	{
		List1.options[i].selected = true;
	}
	List2 = document.searchform.cat_receiver;
	for (i=0;i<List2.length;i++)
	{
		List2.options[i].selected = true;
	}
}
