function runSelected()
{
addOption(form1.MakeModel, form1.Model);
update();
}

function runSelected2()
{
removeOption(form1.MakeModel);
update();
}

function setValueSelected(field, targetField, vPrfx)
	{
		
		if(field.selectedIndex != -1)
		{
			data = field.options[field.selectedIndex].value;
			replaceValuesWithArray(targetField, eval(vPrfx + 'Tx_' + data), eval(vPrfx + 'ID_'+ data));
			targetField.selectedIndex=-1;
		}
	}


function setNewOptions2(field, targetField)
	{
		if(field.selectedIndex != -1)
		{
			data = field.selectedIndex;
			replaceValuesWithArray(targetField, eval('Ata_'+data), eval('Ava_'+data));
			targetField.selectedIndex=-1;
		}
	}


function setNewOptions3(field, targetField, txtPrefix, valPrefix)
	{
		if(field.selectedIndex != -1)
		{
			data = field.selectedIndex;
			replaceValuesWithArray(targetField, eval(txtPrefix+data), eval(valPrefix+data));
			targetField.selectedIndex=-1;
		}
	}

function addToSearch(addTo, addFrom)
	{
		if(addFrom.selectedIndex >= 0)
		{
			txt = addFrom.options[addFrom.selectedIndex].text;
			val = addFrom.options[addFrom.selectedIndex].value;
			addFrom.options[addFrom.selectedIndex].selected = false;
			if((val != '') && !optionExists(val, addTo))
			{
				// trim because apartmentareas are indented
				newOption = new Option(trim(txt), val, false, false);
				if (addTo.length == 1 && (addTo.options[0].value == '')) {
					 addTo.options[0] = newOption;
				} else {
				  addTo.options[addTo.length] = newOption;
				}
				newOption.selected = false;
			}
		}
	}

function addToSearchText(addTo, addFrom)
	{
		if(addFrom.selectedIndex >= 0)
		{
			txt = addFrom.options[addFrom.selectedIndex].text;
			addFrom.options[addFrom.selectedIndex].selected = false;
			if((txt != '') && !optionExists(txt, addTo))
			{
				// trim because apartmentareas are indented
				newOption = new Option(trim(txt), txt, false, false);
				if (addTo.length == 1 && (addTo.options[0].value == '')) {
					 addTo.options[0] = newOption;
				} else {
				  addTo.options[addTo.length] = newOption;
				}
				newOption.selected = false;
			}
		}
	}

function addToSearchWithOneLine(addTo, addFrom)
	{
		if(addFrom.selectedIndex >= 0)
		{
			txt = addFrom.options[addFrom.selectedIndex].text;
			val = addFrom.options[addFrom.selectedIndex].value;
			addFrom.options[addFrom.selectedIndex].selected = false;
			if((val != '') && !optionExists(val, addTo))
			{
				// trim because apartmentareas are indented
				newOption = new Option(trim(txt), val, false, false);
				//if (addTo.length == 1 && (addTo.options[0].value == '')) {
					 addTo.options[0] = newOption;
				//} //else {
				  //addTo.options[addTo.length] = newOption;
				//}
				newOption.selected = false;
			}
		}
	}
	
function removeFromSearch(field) {
	if(field.options[field.selectedIndex].value != '') {
		if (field.length == 1) {
			field.options[0].selected = false;
			newOption = new Option(' ','',false,false);
			field.options[0] = newOption;
		} else {
			field.options[field.selectedIndex] = null;
		}
	} else {
            field.options[field.selectedIndex].selected = false;
        }
}

function replaceValuesWithArray(field, txtArray, valArray){
	clearValues(field);
	if(txtArray.length > valArray.length){
		}
		else
		{
			for(var i = 0; i < txtArray.length; i++){
			txt = txtArray[i];
			val = valArray[i];
			uusi = new Option(txt, val, false, false);
			field.options[field.length] = uusi;
			}
		}
 }
 
 function clearValues(field){
	while(field.length != 0){
		field.options[field.length - 1] = null;
	}
}


function optionExists(val, field)
	{
		for(var i = 0;i < field.length;i++)
		{
			if(field.options[i].value==val)
				return true;
		}
			return false;
	}

//removes spaces from the beginning and end of a string
function trim(strText) {
// this will get rid of leading spaces
	while (strText.substring(0,1) == ' ')
	strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	return strText;
}

function selectValues(control){
    //window.alert("selectValues");
    if(control == null) return true;
    if (control.type == "hidden") return true;
    
		for(i = 0;i < (control.length);i++){
			//window.alert(control.options[i].text);
	    control.options[i].selected = true;
	}
	return true;
}

function submitSearchForm(){ 
	//selectValues(document.Form1.MakeModel)
	
	selectValues(document.Form1.cvsToimialat)
	selectValues(document.Form1.selectedProfessions)
	selectValues(document.Form1.locSelectedAreas)
	document.Form1.submit() 
	
}

function submitHakijanTiedot(){
	//tutkinnot
	selectValues(document.Form1.selTutkinnot)
	selectValues(document.Form1.selSijainnit)	
	document.Form1.submit() 
	

}