function createAjax()
{
	var objAjax = false;
	
    if (window.XMLHttpRequest)
    {
    	objAjax = new XMLHttpRequest ();
    } 
    else 
    {
    	if (window.ActiveXObject)
	    {
    		try 
	        {
	        	objAjax = new ActiveXObject ("Msxml2.XMLHTTP");
	        }
	        catch (e)
	        {
	            try
	            {
	            	objAjax = new ActiveXObject ("Microsoft.XMLHTTP");
	            }
	            catch (e)
	            {
	            }
	        }
	    } 
    	else
    	{
    		objAjax = false;
    	}
    }
    return objAjax;
}

function georeferenceByPhone_ajax()
{
    if (document.getElementById("dato_teledir").value == "")
    {
        alert("Para poder iniciar la busqueda por telefono en el mapa primero debe ingresar el n�mero telef�nico que desea buscar!");
    }
    else
    {
        var params  =   "telefono="+document.getElementById("dato_teledir").value+"&ciudad="+document.getElementById("ciudad_teledir").value;
        enlace += "?opmapa=telefono&pais=CO&ciudad="+document.getElementById("ciudad_teledir").value+"&telefono="+document.getElementById("dato_teledir").value;
        callAjax("controller/georeference/start.php",params,0,"","","");
    }
}

function infocomercio_ajax()
{
    
    var geographyValues;
    try
    {
        geographyValues =   armaStringCombo(document.getElementById("geography_area_values"),true);

    }catch(e){geographyValues =   "";}
    
    var category_list   =   armaStringCombo(document.getElementById("categoria"),false);
    
    var params  =   "strCityCode="+document.getElementById("ciudad_2009").value+"&geographyArea="+document.getElementById("geography_area").value;
    params      +=  "&geographyValues="+geographyValues+"&intCombo=4&category_list="+category_list;

    showHideLayers("div_loading_conteo_2009","div_form_2009");
    callAjax("controller/info_2009/options.php",params,2,"div_conteo_2009","div_loading_conteo_2009");
    
}

function loadOptions_ajax(intCombo)
{
    var params;

    var strCityCode =   document.getElementById("ciudad_2009").value;
    var divToDraw;
    var divToLoad;


    switch(intCombo)
    {
        case 1:
            params="intCombo="+intCombo+"&strCityCode="+strCityCode;
            if (strCityCode <= 3)
            {
                divToDraw   =   "div_ciudades";
                divToLoad   =   "div_loading_ciudades";

                document.getElementById("div_area_geografica").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true'></select>";
                document.getElementById("div_valores_area_geografica").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true'></select>";
                document.getElementById("div_categoria").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true' id='categoria'></select>";

            }
            else
            {
                divToDraw   =   "div_area_geografica";
                divToLoad   =   "div_loading_area_geografica";

                document.getElementById("div_valores_area_geografica").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true'></select>";
                document.getElementById("div_categoria").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true' id='categoria'></select>";
            }
            break;
        case 2:
            if (document.getElementById("geography_area").value != -1)
            {
                params="intCombo="+intCombo+"&strCityCode="+strCityCode+"&geographyArea="+document.getElementById("geography_area").value;

                if (document.getElementById("geography_area").value == 0)
                {
                    divToDraw   =   "div_categoria";
                    divToLoad   =   "div_loading_categoria";
                    params      +=  "&intTable=1";
                }
                else
                {
                    divToDraw   =   "div_valores_area_geografica";
                    divToLoad   =   "div_loading_geography_area_values";
                }
                

                document.getElementById("div_valores_area_geografica").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true'></select>";
                document.getElementById("div_categoria").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true' id='categoria'></select>";
            }
            break;
        case 3:
            if (document.getElementById("categoria").value == 3 || document.getElementById("categoria").value == 2 || document.getElementById("categoria").value == 1)
            {
                divToDraw   =   "div_categoria";
                params      =   "intCombo=3&category="+document.getElementById("categoria").value;
                params      +=  "&intTable="+(parseInt(document.getElementById("geography_area").value)+1);
                try
                {
                    params      +=  "&value="+document.getElementById("geography_area_values").value;
                }catch(e){params      +=  "&value=''";}
                
                params      +=  "&strCityCode="+strCityCode;
                divToLoad   =   "div_loading_categoria";
            }
            break;
       case 4:
            if (document.getElementById("geography_area_values").value != "-1")
            {
                var category;
                if (document.getElementById("categoria").value != "" && document.getElementById("categoria").value != -1)
                {
                    category = document.getElementById("categoria").value;
                }
                else
                {
                    category = 1;
                }

                divToDraw   =   "div_categoria";
                params      =   "intCombo=3&category="+category+"&strCityCode="+strCityCode;
                params      +=  "&intTable="+(parseInt(document.getElementById("geography_area").value)+1);
                params      +=  "&value="+document.getElementById("geography_area_values").value;
                divToLoad   =   "div_loading_categoria";
            }

            document.getElementById("div_categoria").innerHTML = "<select class='cmbSitios' style='width:80%' disabled='true' id='categoria'></select>";

            break;

    }
    callAjax("controller/info_2009/options.php",params,1,divToDraw,divToLoad);
}

function callAjax(url,params,response,divToDraw,divToLoad)
{
    var ajax = createAjax();
    ajax.open("POST", url,true);

    ajax.onreadystatechange=function()
    {
        if (ajax.readyState == 4)
        {
            try
            {
                showHideLayers(divToDraw,divToLoad);
            }catch(e){}
            
            switch (response)
            {
                case 0: 
                    eval(ajax.responseText);
                    break;
                case 1: 
                    try{
                    document.getElementById(divToDraw).innerHTML = ajax.responseText;
                    }catch(e){}
                    break;
                case 2:
                    var scripts =   ajax.responseText.split("[js]");
                    document.getElementById(divToDraw).innerHTML = scripts[1];
                    eval(scripts[0]);
                    break;
            } 
        }
        else
        {

            try
            {
                showHideLayers(divToLoad,divToDraw);
            }catch(e){}
        }
    }

    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(params);
}
