


function cargar_op_hash(nselect,hvector){
    // recarga las opciones de un select
    //alert('entro en cargar_op');
    $("#"+nselect).children().remove();
    $.create('option', {'value': 0}, '').appendTo('#'+nselect);
     for (var i in hvector.items) {
	//alert('key is: ' + i + ', value is: ' + myHash.items[i]);
        $.create('option', {'value': i}, hvector.items[i]).appendTo('#'+nselect);


        }
}

function cargando_op(nselect){
    // muestra cargando
    $("#"+nselect).children().remove();
    $.create('option', {'value': 0}, 'Cargando..').appendTo('#'+nselect);
     
}

function cargar_op_json(nselect,hvector){
    // recarga las opciones de un select
    // el vector debe ser de la forma v[codigo_barrio]=nombre_barrio
//    $("#"+nselect).children().remove();
    $("#"+nselect).empty();
    $("#"+nselect).options.length=0; // esto no esta funcionando deja espacios libres

    $.create('option', {'value': 0}, '').appendTo('#'+nselect);
     for (var i in hvector) {
	//alert('key is: ' + i + ', value is: ' + hvector[i]);
        $.create('option', {'value': i}, hvector[i]).appendTo('#'+nselect);


        }
}

function cargar_op_json_breve(nselect,vcuales,vtodos){
    // recarga las opciones de un select usando un vector precargado con todos los posibles
    // el vector cuales debe ser del tipo cuales[]=codigo_barrio y vtodos es jbarrios

    $("#"+nselect).empty();
    if(vcuales[0]!==0){
        $.create('option', {'value': 0}, '').appendTo('#'+nselect);
    }
     for (var i in vcuales) {
	//alert('key is: ' + i + ', value is: ' + hvector[i]);
        $.create('option', {'value': vcuales[i]}, vtodos[vcuales[i]]).appendTo('#'+nselect);
        }
}

function oper_cambio_inc(){
//    if($("#frm_buscador_inc select[name=oper]").val()==0){
//        // resetear
//    }else{
        cargando_op('tipo');
        var params=$("#frm_buscador_inc").serialize();
        $.getJSON("aj_tipo.php?"+params+"&format=json&modo=1&jsoncallback=?",
                function(data){
                    cargar_op_json_breve('tipo',data,jTipos);
                });
//    }

}
function tipo_cambio_inc(){
    var params=$("#frm_buscador_inc").serialize();
    cargando_op('ubicacion');
$.getJSON("aj_ubic.php?"+params+"&format=json&modo=1&jsoncallback=?",
            function(data){
                cargar_op_json_breve('ubicacion',data,jUbicaciones);
            });


}

function ubic_cambio_inc(){
    var params=$("#frm_buscador_inc").serialize();
cargando_op('barrio');
$.getJSON("aj_zona.php?"+params+"&format=json&jsoncallback=?",function(data){cargar_op_json_breve('barrio',data,jBarrios);});


}


function mostrar_foto(foto_id,foto_url,foto_txt){
            $("#"+foto_id).attr('src',foto_url);
            //alert("#foto_"+prop_id);
         }


         
function mostrar_resultados(){
            $("#frm_buscador_inc").action='index.php';
            $("#frm_buscador_inc").submit();
         }


function mostrar_lista(av,pag){
            // en general av es 1
            document.location.href="principal.php?mostrar=listar&av="+av+"&pag="+pag;
         }



function verfoto(foto) {
	$('#fotos').cycle('pause');
      eval("document.mostrar_foto.src = '" + foto + "'");
      document.getElementById('marco_foto').style.display='';
      var ancho=document.getElementById('marco_foto').clientWidth;
      var ventana=document.body.clientWidth;

      var medio=parseInt((ventana-ancho)/2);

      document.getElementById('marco_foto').style.left=medio+'px';
      $('#marco_foto').maxZIndex();
      return
}

function cerrar_foto(){
	document.getElementById('marco_foto').style.display='none';
	$('#fotos').cycle('resume');
}

$.maxZIndex = $.fn.maxZIndex = function(opt) {
    /// <summary>
    /// Returns the max zOrder in the document (no parameter)
    /// Sets max zOrder by passing a non-zero number
    /// which gets added to the highest zOrder.
    /// </summary>    
    /// <param name="opt" type="object">
    /// inc: increment value, 
    /// group: selector for zIndex elements to find max for
    /// </param>
    /// <returns type="jQuery" />
    var def = { inc: 10, group: "*" };
    $.extend(def, opt);    
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
    });
}


