
function moveFormObject(fbox,tbox){

	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	
	for(i=0; i<tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length

	// If its an selectbox
	if(fbox.type!="text"){
			
		// Checking if the new value allreay existing in the list
		var dubbleValue = 0;
		for(i=0; i<tbox.options.length; i++) {
			if(fbox.value == tbox.options[i].value){
				dubbleValue = 1;
			}
		}
		
		if(!dubbleValue){
		for(i=0; i<fbox.options.length; i++) {
			arrLookup[fbox.options[i].text] = fbox.options[i].value;
			if(fbox.options[i].selected && fbox.options[i].value != "") {
				arrTbox[tLength] = fbox.options[i].text;
				tLength++;
			}else{
				arrFbox[fLength] = fbox.options[i].text;
				fLength++;
			}
		}
		}
		
	// If its a textfield
	}else{
	
		// Checking if the new value allreay existing in the list
		var dubbleValue = 0;
		for(i=0; i<tbox.options.length; i++) {
			if(fbox.value == tbox.options[i].text){
				dubbleValue = 1;
			}
		}
		
		// Adding the new value if its not empty and allready exists in the list
		if(fbox.value != "" && dubbleValue == 0) {
			arrTbox[tLength] = fbox.value;
			tLength++;
		}
		
	}

//	arrFbox.sort();
	arrTbox.sort();
//	fbox.length = 0;
	tbox.length = 0;
	var c;

//	for(c=0; c<arrFbox.length; c++) {
//		var no = new Option();
//		no.value = arrLookup[arrFbox[c]];
//		no.text = arrFbox[c];
//		fbox[c] = no;
//	}

	for(c=0; c<arrTbox.length; c++) {
		var no = new Option();
		// If its an selectbox, still use the value as value
		if(fbox.type!="text"){
			no.value = arrLookup[arrTbox[c]];
		// If its a textfield, set the text as value cos we got no value yet
		}else{
			no.value = arrTbox[c];
		}
		no.text = arrTbox[c];
		tbox[c] = no;
	}

}


function removeFormObject(fbox){

	var arrFbox = new Array();
	var arrLookup = new Array();
	var i;
	var fLength = 0;
	
	for(i=0; i<fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		//arrLookup[fbox.options[i].text] = fbox.options[i].text;
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			//do nothing
		}else{
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
		}
	}

	arrFbox.sort();
	fbox.length = 0;
	var c;

	for(c=0; c<arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}

}


function selectBeforeSubmitForm(fbox){
	for(i=0; i<fbox.length; i++) {
		fbox.options[i].selected = true;
	}
}

function setToUppercase(formObject){
	formObject.value = formObject.value.toUpperCase();
}

function walkList(formName,listStep,listOffset){
	formName.listOffset.value= listOffset+listStep;
	formName.submit();
}

function openWindow(winUrl,winName,winInfo){
	var newWindow = window.open(winUrl,winName,winInfo);
	newWindow.focus();
}

function insertTag(myArea, myValue){
  myField = eval("document." + myArea);
  if(document.selection){
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }else if(myField.selectionStart || myField.selectionStart == '0'){
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + myValue +     myField.value.substring(endPos, myField.value.length);
  }else{
    myField.value += myValue;
  }
  if(myValue.toLowerCase()!="å" && myValue.toLowerCase()!="ä" && myValue.toLowerCase()!="ö")
		myField.blur();
 }
