var selectedList;
var availableList;

function createListObjects(){
    availableList = document.getElementById("kwbase");
    selectedList = document.getElementById("kw");
}

function delAttribute(){
   var selIndex = selectedList.selectedIndex;
   if(selIndex < 0)
      return;
   var len = availableList.childNodes.length;
   var text = selectedList.options.item(selIndex).text;
   var done = false;
   for(i=0; i<len; i++){
	  if(availableList.childNodes[i].text > text) {
	  	 availableList.insertBefore(selectedList.options.item(selIndex), availableList.childNodes[i]);
	  	 done = true;
      }
   }
   if (!done) availableList.appendChild(selectedList.options.item(selIndex));
   selectNone(selectedList,availableList);
   setSize(availableList,selectedList);
}
function addAttribute(){
   var addIndex = availableList.selectedIndex;
   if(addIndex < 0)
      return;
   selectNone(selectedList,availableList);
   selectedList.appendChild(availableList.options.item(addIndex));
   setSize(selectedList,availableList);
}
function setTop(top){
	document.getElementById('someLayer').style.top = top;
}
function setLayerTop(lyr,top){
	lyr.style.top = top;
}
function setSize(list1,list2){
	return;
    list1.size = getSize(list1);
    list2.size = getSize(list2);
}

function selectNone(list1,list2){
    list1.selectedIndex = -1;
    list2.selectedIndex = -1;
    addIndex = -1;
    selIndex = -1;
}
function getSize(list){
    /* Mozilla ignores whitespace, 
       IE doesn't - count the elements 
       in the list */
    var len = list.childNodes.length;
    var nsLen = 0;
    //nodeType returns 1 for elements
    for(i=0; i<len; i++){
        if(list.childNodes.item(i).nodeType==1)
            nsLen++;
    }
    if(nsLen<2)
        return 2;
    else
        return nsLen;
}

function delAll(){
    var len = selectedList.length -1;
    for(i=len; i>=0; i--){
        availableList.appendChild(selectedList.item(i));
    }
    selectNone(selectedList,availableList);
    setSize(selectedList,availableList);   
}

function addAll(){
    var len = availableList.length -1;
    for(i=len; i>=0; i--){
        selectedList.appendChild(availableList.item(i));
    }
    selectNone(selectedList,availableList);
    setSize(selectedList,availableList);
    
}
function showSelected(form) {
    var optionList = 
       document.getElementById("selectedOptions").options;
    var data = '';
    var len = optionList.length;
    for(i=0; i<len; i++){
        if (i>0) data += ',';
        data += optionList.item(i).value;
    }
    if (data != '') {
    	form.fieldListResult.value = data;
    	return true;
    } else {
    	alert("La lista e' vuota!");
    	return false;
    }
}
function nothing() { }
function selectAll() {
	//selectedList.selectedIndex = 0;
    var len = selectedList.options.length;
    for(i=0; i<len; i++) {
    	selectedList.options[i].selected = true;
    }
}
