function createRequestObject()
{
        var request_o;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer")
        {
                request_o = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
                request_o = new XMLHttpRequest();
        }
        return request_o; //return the object
}
var http = createRequestObject();

function MenuCombo(accion,elemento,contenedor,seccion,sector,subsector,pais,provincia,comunidad,pagina) {
        var cadena;
        /*  alert(elemento);
        alert(contenedor);
        alert(document.form_combos.elements[elemento].selectedIndex);*/

        var indice = document.form_combos.elements[elemento].selectedIndex;
        if (contenedor != "div_resultados") {
        var valorcombo = document.form_combos.elements[elemento].options[indice].value;
        }
        //alert(seccion);
        switch (seccion) {
            case "680":
            case "681":
            case "682":
                 http.open('get', 'internal_request_680_681_682.php?action=MenuCombo&id_seccion=' + seccion + '&id_sector=' + sector + '&id_subsector=' + subsector + '&id_pais=' + pais + '&id_provincia=' + provincia + '&id_comunidad=' + comunidad + '&pagina=' + pagina + '&elemento=' + elemento + '&accion=' + accion + '&id=' + valorcombo );
            break;
            case "683":
                 http.open('get', 'internal_request_683.php?action=MenuCombo&id_seccion=' + seccion + '&id_sector=' + sector + '&id_subsector=' + subsector + '&id_pais=' + pais + '&id_provincia=' + provincia + '&id_comunidad=' + comunidad + '&pagina=' + pagina + '&elemento=' + elemento + '&accion=' + accion + '&id=' + valorcombo );
            break;
            case "684":
                 http.open('get', 'internal_request_684.php?action=MenuCombo&id_seccion=' + seccion + '&id_sector=' + sector + '&id_subsector=' + subsector + '&id_pais=' + pais + '&id_provincia=' + provincia + '&id_comunidad=' + comunidad + '&pagina=' + pagina + '&elemento=' + elemento + '&accion=' + accion + '&id=' + valorcombo );
            break;

        }
        switch (contenedor) {
                case "div_sector":
                        http.onreadystatechange = handleProducts_sector;
                break;
                case "div_subsector":
                        http.onreadystatechange = handleProducts_subsector;
                break;
                case "div_provincia":
                        http.onreadystatechange = handleProducts_provincia;
                break;
                case "div_submit":
                        http.onreadystatechange = handleProducts_submit;
                break;
                case "div_resultados":
                        http.onreadystatechange = handleProducts_resultados;
                break;
                case "div_pais":
                        http.onreadystatechange = handleProducts_pais;
                break;
                case "div_comunidad":
                        http.onreadystatechange = handleProducts_comunidad;
                break;
        }
        http.send(null);
}
function handleProducts_comunidad(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_comunidad').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_directorio').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_provincia').innerHTML = "";
                document.getElementById('div_submit').innerHTML = "";
                document.getElementById('div_resultados').innerHTML = "";
                document.getElementById('div_comunidad').innerHTML = response;
        }
}
function handleProducts_pais(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_pais').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_pais').innerHTML = response;
                document.getElementById('div_directorio').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_provincia').innerHTML = "";
                document.getElementById('div_comunidad').innerHTML = "";
                document.getElementById('div_submit').innerHTML = "";
                document.getElementById('div_resultados').innerHTML = "";
        }
}

function handleProducts_sector(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_sector').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_directorio').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_provincia').innerHTML = "";
                document.getElementById('div_submit').innerHTML = "";
                document.getElementById('div_resultados').innerHTML = "";
                document.getElementById('calendario').innerHTML = "";
                document.getElementById('div_sector').innerHTML = response;
        }
}
function handleProducts_subsector(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_subsector').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_directorio').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_pais').innerHTML = "";
                document.getElementById('div_submit').innerHTML = "";
                document.getElementById('div_provincia').innerHTML = "";
                document.getElementById('div_resultados').innerHTML = "";
                document.getElementById('div_subsector').innerHTML = response;
        }
}
function handleProducts_provincia(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_provincia').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
              document.getElementById('div_directorio').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_submit').innerHTML = "";
                document.getElementById('div_resultados').innerHTML = "";
                document.getElementById('div_provincia').innerHTML = response;
        }
}
function handleProducts_submit(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_submit').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_resultados').innerHTML = "";
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_submit').innerHTML = response;
        }
}
function handleProducts_resultados(){
        if ( http.readyState == (1||2||3) ){
                document.getElementById('div_resultados').innerHTML = "<br>Cargando Datos...";
        }
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById('div_secciones_oculta').style.visibility="visible";
                document.getElementById('div_resultados').innerHTML = response;
        }
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
        /* Make sure that the transaction has finished. The XMLHttpRequest object
                has a property called readyState with several states:
                0: Uninitialized
                1: Loading
                2: Loaded
                3: Interactive
                4: Finished */
        if(http.readyState == 4){ //Finished loading the response
                /* We have got the response from the server-side script,
                        let's see just what it was. using the responseText property of
                        the XMLHttpRequest object. */
                var response = http.responseText;
                /* And now we want to change the product_categories <div> content.
                        we do this using an ability to get/change the content of a page element
                        that we can find: innerHTML. */
                document.getElementById('product_cage').innerHTML = response;
        }
}
