cats_js = new Array();
catsNom_js = new Array();

function addOption (tipus, id, nom) {
    if (!cats_js[tipus]) {
        cats_js[tipus] = new Array();
    }
    cats_js[tipus][cats_js[tipus].length] = new Option (nom, id);
}

function addNomOption (tipus, id, nom) {
    if (!catsNom_js[tipus]) {
        catsNom_js[tipus] = new Array();
    }
    catsNom_js[tipus][catsNom_js[tipus].length] = new Option (nom, id);
}


//borrar capsa select
function borra_select(nom_form,nom_camp){
	//inicialitzam el select de seleccionats
	var obj_sele = document.getElementById(nom_form).elements[nom_camp];
	var num=obj_sele.length;
	for(i=0;i<num;i++){
        obj_sele.options[0]=null;
	}
    return true;
}
                
function update_select(n_form,n_camp,arr_llista,selectedValue){
    
    borra_select(n_form,n_camp);
    var obj = document.getElementById(n_form).elements[n_camp];
    
    //inicialitzem el primer element en blanc
    obj.options[0]= new Option(textos['qualse'],'');        
    
    if (typeof(arr_llista)=='undefined'){
        return false;
    }
    if (typeof(selectedValue)=='undefined'){
        selectedValue = null;
    }
    
    for (i=0;i<arr_llista.length;i++){
        obj.options[i+1]=arr_llista[i];
       /* if (arr_llista[i].value == selectedValue) {
            obj.options[i+1].selected = true;
        }*/
    }
    
    // marcamos el primer elemento.
    obj.selectedIndex = 0;
} 

