function objeto_request() {
	
	var objeto_request = false;
	
     try {
		objeto_request = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e) {
         try { 
			objeto_request = new ActiveXObject("Microsoft.XMLHTTP");
         }catch (E) {
            objeto_request = false; 
        } 
    }
    
    if (!objeto_request && typeof XMLHttpRequest != 'undefined') {
		objeto_request = new XMLHttpRequest();
    }
    
    if(!objeto_request){
		alert("El navegador no soporta el objeto de conexión XMLHttpRequest. Actualícese.");
	}
    
	return objeto_request;
}

var conexion = objeto_request();

function conexion_gestionar_datos_combo_generico(id_control, sp, nombre, script, funcion, con, opc){

	if(! con){
	    var con = objeto_request();
	}else{
		con.abort();
    }	

    if(! opc){
        opc = "";
    }
        
	var tamanio = document.getElementById(nombre).style.width;
    
	if(parseInt(id_control, 10) != -1){

	    if(tamanio){
		    document.getElementById(nombre).parentNode.style.width = tamanio;
		    document.getElementById(nombre).style.overflow = "hidden";
		}else{
    
		    //document.getElementById(nombre).parentNode.style.width = "50%";
		}
		
		document.getElementById(nombre).parentNode.innerHTML = "<img id='" + nombre + "' src='/web/images/cargando_16x16.gif' align='center' style='width:16px;height:16px'/><span class='cargando'>&nbsp;cargando ...</span>";

		con.open("GET", "/intranet/combo_generico.asp" +
									"?sp=" + sp + 
									"&opc=" + opc + 
									"&nombre=" + nombre + 
									"&tamanio=" + parseInt(tamanio, 10) + 
									"&script=" + script, true);

		con.onreadystatechange = 
			function(){
				if(con.readyState == 4){
					if(con.status == 200 || con.status == 0){
                      
					   document.getElementById(nombre).parentNode.innerHTML = con.responseText; 
						
						if(funcion){
							if(funcion.ejecuta){
							    funcion.ejecuta();
							}else{
							    funcion();
							}
						 }
					}else{
						document.getElementById(nombre).parentNode.innerHTML = "<select id='" + nombre + "' name='" + nombre + "'><option></option></select>";
														
						alert("Error " + con.status + ' ' + con.statusText);
					}
					
					con = null;

				}
				
			}

		con.send(null);
	}else{
		document.getElementById(nombre).parentNode.innerHTML = "<select id='" + nombre + "' name='" + nombre + "' style='width:" + tamanio + "'><option></option></select>";
	}
}

function conexion_gestionar_datos_combo_grupos_generico(id_control, sp, nombre, script, funcion, sincronizacion){

	var con	= objeto_request();
	
	var tamanio = document.getElementById(nombre).style.width;

	//con.abort();

	if(parseInt(id_control, 10) != -1){
	    if(tamanio){
		    document.getElementById(nombre).parentNode.style.width = tamanio;
		}else{
		    document.getElementById(nombre).parentNode.style.width = "100%";
		}
		
		document.getElementById(nombre).parentNode.innerHTML = "<img id='" + nombre + "' src='/web/images/cargando_16x16.gif' align='center' style='width:16px;height:16px'/><span class='cargando'>&nbsp;cargando ...</span>";
		
		con.open("GET", "/intranet/combo_grupos_generico.asp" +
									"?sp=" + sp + 
									"&nombre=" + nombre + 
									"&tamanio=" + parseInt(tamanio, 10) + 
									"&script=" + script, sincronizacion);
		
		con.onreadystatechange = 
			function(){
				if(con.readyState == 4){
					if(con.status == 200 || con.status == 0){

					   document.getElementById(nombre).parentNode.innerHTML = con.responseText; 
						
						if(funcion){
							if(funcion.ejecuta){
							    funcion.ejecuta();
							}else{
							    funcion();
							}
						 }
					}else{
						document.getElementById(nombre).parentNode.innerHTML = "<select id='" + nombre + "' name='" + nombre + "' style='width:" + tamanio + "'></select>";
														
						alert("Error " + con.status + ' ' + con.statusText);
					}
					
					con = null;

				}
				
			}

		con.send(null);
	}else{
		document.getElementById(nombre).parentNode.innerHTML = "<select id='" + nombre + "' name='" + nombre + "' style='width:" + tamanio + "'></select>";
	}
}

// ------------------------------------------------------------------------

