/**
 * @author MansonPlus && Pelvis
 */
var panel_estado
var datos_estados

var tips = function(){
	//alert(datos_estados.length)
	for (i = 0; i < datos_estados.length; i++) {
        new YAHOO.widget.Tooltip("tt" + i, {
            context: datos_estados[i].ide_estado,
            autodismissdelay: 999999999,
            text: "<div class='tool1' ><div class='tool2' align='center'>" + unescape(datos_estados[i].estado) + "</div><div style='' align='center'>" + datos_estados[i].total + " Bienes</div></div>"
        });
    }
	document.getElementById("prueba2").style.background = "url(assets/mapa/tiendas_intromap_mex_over.png) no-repeat"
}
var marcar = function(estado_marcar, opcion){
    var estado = document.getElementById("estados");
    if (opcion == "1") {
        if (panel_estado == "SimpleDialog panel_estado") {
            panel_estado.hide();
            panel_estado.destroy();
            panel_estado = "";
        }
        estado.style.backgroundImage = "url(assets/mapa/" + estado_marcar + ".gif)";
        estado.style.backgroundPosition = "" + estados_mapa[estado_marcar].x + "px " + estados_mapa[estado_marcar].y + "px";
        //ver_dialog(estado_marcar);
    }
    else {
        estado.style.backgroundImage = "url(assets/mapa/blanco.gif)";
    }
}

var quitar_cuadro = function(){
    if (panel_estado == "SimpleDialog panel_estado") {
        panel_estado.hide();
        panel_estado.destroy();
    }
}
var estados_mapa = {
    "4": {
        "x": "42",
        "y": "129"
    },
    "2": {
        "x": "295",
        "y": "275"
    },
    "3": {
        "x": "10",
        "y": "10"
    },
    "27": {
        "x": "54",
        "y": "18"
    },
    "9": {
        "x": "165",
        "y": "44"
    },
    "6": {
        "x": "271",
        "y": "89"
    },
    "20": {
        "x": "328",
        "y": "140"
    },
    "29": {
        "x": "350",
        "y": "141"
    },
    "26": {
        "x": "155",
        "y": "160"
    },
    "11": {
        "x": "205",
        "y": "164"
    },
    "33": {
        "x": "264",
        "y": "209"
    },
    "19": {
        "x": "232",
        "y": "258"
    },
    "25": {
        "x": "305",
        "y": "225"
    },
    "15": {
        "x": "230",
        "y": "268"
    },
    "12": {
        "x": "310",
        "y": "288"
    },
    "23": {
        "x": "342",
        "y": "290"
    },
    "14": {
        "x": "357",
        "y": "298"
    },
    "17": {
        "x": "274",
        "y": "325"
    },
    "16": {
        "x": "345",
        "y": "330"
    },
    "30": {
        "x": "380",
        "y": "335"
    },
    "10": {
        "x": "370",
        "y": "340"
    },
    "18": {
        "x": "368",
        "y": "355"
    },
    "13": {
        "x": "310",
        "y": "362"
    },
    "22": {
        "x": "379",
        "y": "310"
    },
    "21": {
        "x": "390",
        "y": "360"
    },
    "8": {
        "x": "487",
        "y": "370"
    },
    "28": {
        "x": "482",
        "y": "350"
    },
    "5": {
        "x": "519",
        "y": "300"
    },
    "32": {
        "x": "560",
        "y": "270"
    },
    "24": {
        "x": "592",
        "y": "270"
    },
    "31": {
        "x": "382",
        "y": "270"
    },
    "7": {
        "x": "260",
        "y": "345"
    }
};



var datos = function(){
    var callback = {
        success: function(o){
            listaDatos = YAHOO.lang.JSON.parse(o.responseText);
            datos_estados = listaDatos["datos"];
			//alert(datos_estados.length)
            tips();
            /*var cuadro = "<table width='100%' class='tabla_destacados'><tr>", columna = 0
            for (i = 0; i < listaDatos["destacados"].length; i++) {
                if (columna == 0) {
                    cuadro += "<tr><td><span>•</span> <a href='anuncio.html?ide=" + listaDatos["destacados"][i].ide + "'>" + listaDatos["destacados"][i].texto + "</a></td>";
                    columna++;
                }
                else {
                    if (columna == 2) {
                        cuadro += "<td><span>•</span> <a href='anuncio.html?ide=" + listaDatos["destacados"][i].ide + "'>" + listaDatos["destacados"][i].texto + "</a></td></tr>";
                        columna = 0;
                    }
                    else {
                        cuadro += "<td><span>•</span> <a href='anuncio.html?ide=" + listaDatos["destacados"][i].ide + "'>" + listaDatos["destacados"][i].texto + "</a></td>";
                        columna++;
                    }
                    
                }
                
            }
            cuadro += "</tr></table>";
            document.getElementById("destacados").innerHTML = cuadro;
            llenarListaCatalogo(listaDatos["estados"], "lista_estado1", "", "Sel. Estado")
            llenarListaCatalogo(listaDatos["estados"], "lista_estado2", "", "Sel. Estado")
            llenarListaCatalogo(listaDatos["propiedades"], "lista_propiedades", "", "Sel. Propiedad")*/
        },
        failure: function(){
        
        }
    };
    var sUrl = "WebServices/lista_datos.php";
    var params = 'param1=val1&param2=val2';
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params);
}

var checar_busqueda = function(){
    propiedad = document.getElementById("lista_propiedades").value;
    //interes = document.getElementById("lista_interes").value;
    estado = document.getElementById("lista_estado2").value;
    ciudad = document.getElementById("lista_ciudades2").value;
    colonia = document.getElementById("lista_colonias").value;
    //cuartos1 = document.getElementById("txt_cuartos1").value;
    //cuartos2 = document.getElementById("txt_cuartos2").value;
    var cuartos1 = '';
    var cuartos2 = '';
    propiedad = document.getElementById("lista_propiedades").value;
    precio1 = document.getElementById("txt_precio1").value;
    precio2 = document.getElementById("txt_precio2").value;
    var opVenta = "", opRenta = "", opTraspaso = "";
    if (document.getElementById("chkVenta").checked) {
        opVenta = "1"
    }
    if (document.getElementById("chkRenta").checked) {
        opRenta = "1"
    }
    if (document.getElementById("chkTraspaso").checked) {
        opTraspaso = "1"
    }
    window.location.href = "busquedas.php?venta=" + opVenta + "&renta=" + opRenta + "&traspaso=" + opTraspaso + "&estado=" + estado + "&ciudad=" + ciudad + "&colonia=" + colonia + "&propiedad=" + propiedad + "&p1=" + precio1 + "&p2=" + precio2 + "&c1=" + cuartos1 + "&c2=" + cuartos2;
}

var ver_dialog = function(estado){

    var handleSubmit = function(){
        panel_estado.hide();
        panel_estado.destroy();
    };
    var handleCancel = function(){
        panel_estado.hide();
        panel_estado.destroy();
    };
    panel_estado = new YAHOO.widget.SimpleDialog("panel_estado", {
        width: "200px",
        visible: true,
        constraintoviewport: true,
        fixedcenter: false,
        modal: false,
        xy: [X, Y + 40],
        effect: {
            effect: YAHOO.widget.ContainerEffect.FADE,
            duration: 0.25
        },
        close: false
    });
    //panel_estado.setHeader(unescape(datos_estados[estado].estado))
    //alert(datos_estados.length)
    var nombre_estado, total = 0
    for (i = 0; i < datos_estados.length; i++) {
        if (estado == datos_estados[i].ide_estado) {
            nombre_estado = datos_estados[i].estado;
            total = datos_estados[i].total
        }
    }
    panel_estado.setBody("<div>" + unescape(nombre_estado) + "</div><a href=''><div align='center'>Propiedades: " + total + "</div></a>");
    panel_estado.setFooter('Gracias...');
    panel_estado.render(document.body);
    //panel_estado.render();
    //alert(YAHOO.util.Event.getPageX())
    //alert(X + " " + Y) 
}

//alert(typeof(datos_estados[estado].estado))

var cambiar_cuartos = function(){
	var cuarto1 = document.getElementById("txt_cuartos1").value;
	//alert(cuarto1)
	if (cuarto1){
		var campo = document.getElementById("txt_cuartos2");
	    campo.length = 0;
	    var cont = 0
	    cuarto1++;
	    for(var j=cuarto1;j<=10;j++){
			campo.options[cont] = new Option(j,j);
			cont++
		}
	}
}

var ver_banner = function(){
	var multi = 5;
	var i = Math.round(multi*Math.random());
	while (!i)
	{
		i = Math.round(multi*Math.random());
	}
	var result = new Array();
	result[1]="cuadrado001.jpg";
	result[2]="cuadrado002.jpg";
	result[3]="cuadrado003.jpg";
        result[4]="cuadrado004.jpg";
        result[5]="cuadrado005.jpg";
	
	var links = new Array();
	links[1]="http://www.stanzaresidencial.com/";
	links[2]="http://www.stanzaresidencial.com/";
	links[3]="http://fincamex.com.mx/";
        links[4]="http://www.genus.com.mx/";
        links[5]="";
	
	document.getElementById("banner1").innerHTML = "<a href='"+links[i]+"' target='_blank'><img src='assets/banners/"+result[i]+"' border='0'/></a>"
}

