/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var dialog1
var menuOpciones = function(op,columnas){
    if (op==1){
        titulo = "Seleccione un Tema";
        variable = "tema";
    }else{
        if (op==2){
            titulo = "Seleccione un Grupo";
            variable = "grupo";
        }else{
            if (op==3){
                titulo = "Seleccion una Especie";
                variable = "especie";
            }else{
                titulo = "Seleccion un Genero";
                variable = "genero";
            }
        }
    }
    var handleSubmit = function() { 
        this.submit();
    };
    var handleCancel = function() {
        dialog1.cancel();
    };
    dialog1= new YAHOO.widget.Dialog("dialog1",
    {
        width : "750px",
        height: "300px",
        fixedcenter : true,
        constraintoviewport : true,
        modal : true,
        buttons : [ {
            text:"Submit",
            handler:handleSubmit,
            isDefault:true
        },

        {
            text:"Cancel",
            handler:handleCancel
        } ]
    } );
    dialog1.setHeader(titulo);
    dialog1.setBody("<div align='center' id='opciones'><img src='assets/gif_cargando.gif'></div>")
    dialog1.render(document.body);
    dialog1.show();

    var AjaxObject = {
        handleSuccess: function(o){
            menus2 = YAHOO.lang.JSON.parse(o.responseText)
            var codigo_menu = "<table width='100%'>";
            var col = 0;
            for (i=0;i<menus2["menu"].length;i++){
                //codigo_menu = codigo_menu + menus["menu"][i].nombre;
                if (col==0){
                    codigo_menu = codigo_menu + "<tr><td width='33%' class='menuOpcion'><a href='busquedas.html?"+variable+"="+menus2["menu"][i].ide+"' target='frame1' onclick='dialog1.cancel();'>"+unescape(menus2["menu"][i].nombre)+"</a></td>";
                    col= col + 1;
                }else{
                    if (col==2){
                        codigo_menu = codigo_menu + "<td width='33%' class='menuOpcion'><a href='busquedas.html?"+variable+"="+menus2["menu"][i].ide+"' target='frame1' onclick='dialog1.cancel();'>"+unescape(menus2["menu"][i].nombre)+"</a></td></tr>";
                        col = 0;
                    }else{
                        codigo_menu = codigo_menu + "<td width='33%' class='menuOpcion'><a href='busquedas.html?"+variable+"="+menus2["menu"][i].ide+"' target='frame1' onclick='dialog1.cancel();'>"+unescape(menus2["menu"][i].nombre)+"</a></td>";
                        col = col + 1;
                    }
                }
            }
            codigo_menu = codigo_menu + "</table>";
            document.getElementById("opciones").innerHTML = codigo_menu;
            //alert(menus["menu1"][0].ide + " " + unescape(menus["menu1"][0].nombre))
            this.processResult(o);
        },
        handleFailure: function(o){
        // Failure handler
        },
        processResult: function(o){
        // This member is called by handleSuccess
        },
        startRequest: function(){
            YAHOO.util.Connect.asyncRequest('GET', 'ServiciosWeb/lista_opciones.php?tipo='+op, callback);
        }
    };
    var callback = {
        success: AjaxObject.handleSuccess,
        failure: AjaxObject.handleFailure,
        scope: AjaxObject
    };
    AjaxObject.startRequest();
}