n4 = (document.layers)? true:false
ie = (document.all)? true:false
n6 = (document.getElementById)? true:false

function addOption( etiqueta, valor, combo ) {

	var oOption = new Option(etiqueta, valor);
	combo.options[combo.options.length]=oOption;

    return(true);
}

function eraseAllOptions (combo){
    for( j=combo.options.length; j >= 0; j--) {
        combo.options[j] = null;
    }
}

function getElementById(id)
{
    if (ie)
		return document.all[id];
	else if (n6)
		return document.getElementById(id);
}

function getSelectedOptionValue(selectId){
    return getElementById(selectId).options[getElementById(selectId).selectedIndex].value;
}


// Dado dos campos select, mueve los elementos seleccionados de uno al otro
function moveSelectedItems( origen, destino ) {
    var l_index;
    var l_valor;
    var l_texto;
    var j;

    for( j=0; j < origen.options.length; j++) {
        if( origen.options[j].selected ) {
            l_valor = origen.options[j].value;
            l_texto = origen.options[j].text;
            var oOption = new Option(l_texto, l_valor, false,false);
            destino.options[destino.options.length]=oOption;
            origen.options[j] = null;
            j = j -1;          
        }
    }
    return(true);
}

// Dado un combo, agrega el item seleccionado al select destino
function addItem( origen, destino ) {
    var l_index;
    var l_valor;
    var l_texto;

    l_valor = origen.options[origen.selectedIndex].value;
    l_texto = origen.options[origen.selectedIndex].text;
    var oOption = new Option(l_texto, l_valor, false,false);
    destino.options[destino.options.length]=oOption;

    return(true);
}

// Dado un combo, quita el item seleccionado del select destino
function removeItem( origen, destino ) {
    var l_valor;

    l_valor = origen.options[origen.selectedIndex].value;

    for( j=0; j < destino.options.length; j++) {
        if( destino.options[j].value == l_valor) {
            destino.options[j] = null;
            j = destino.options.length;
        }
    }

    return(true);
}
 
// Selecciona todos los elementos de un select                                                                                                                                              
function selectAll ( campo ){
    var i;
    for (i=0; i<campo.length; i++){
        campo.options[i].selected = true;
    }
}

// AGENDA           
function checkTimeFormat(value){
    var res = false;
    if(value != ''){
        if(checkNumber(value)){
            idx = value.indexOf(':');
            if(idx!=-1){
                res = parseInt(value.substring(0,idx-1)) < 24;
                res = parseInt(value.substring(idx+1)) < 60;
            }
        }
    }
    return res;
}

function checkNumber(value){
    var res = true;
    for(i=0;i<value.length;i++){
        ch = value.charAt(i);
        res = res && ((ch>='0' && ch<='9') || (ch == ':'));
    }
    return res;
}