/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
        // function click #pest_buscador_avanzado
        $('#pest_buscador_avanzado').click(function() {
                loadHtml('/include/busqueda_avanzada.inc.php','opcion_list=list_avanzada_index','loading','centerbox');
                return false;
        });
});
function validar_news(num) {
	
        var options = {
	   success:       showResponse  // post-submit callback
        };
	function showResponse(responseText, statusText)  {
		alert(responseText);
		window.location='/admin.php?op=news';
	}
        $('#insertNews').ajaxSubmit(options);
        return false;
}

function load_confirm(url,datos,divloading,div,op) {
	var ret = true;
	if(op == "del") {
		ret = confirm("Esta seguro de que desea eliminar este registro?");
	}
	if (ret == true) {
		loadHtml(url,datos,divloading,div);
	}
	return false;
	
}

function load(url,datos,divloading,div){
    
            $('#ingreso').remove();
            
       $.ajax({
            beforeSend: function(){

              $("#"+divloading).show();

            },
            type: "POST",
            url:url,
            data: datos,
            async: true,
            cache:false,
            success: function(mensaje){
              msg2=mensaje.split("-");
              msg=msg2[0]; 
              $("#"+divloading).hide();
             
             
             
   if(div==''){
              
              if(msg==103)
              {
                  alert("Usuario Eliminado Correctamente");
                  loadHtml('opcionesUsuario.php','opcion=admin','arbol','cont1');
              }          
              
              else if(msg==203)
              {
                  alert("Banco Eliminado Correctamente");
                  loadHtml('opcionesBanco.php','opcion=admin','arbol','cont1');
              }          
            
              else if(msg==303)
              {
                  alert("Departamento Eliminado Correctamente");
                  loadHtml('opcionesDepartamento.php','opcion=administrar','arbol','cont1');
              }          
              
              else if(msg==304)
              {
                  
                  if(!confirm("Hay fotos asociadas a este departamento, esta seguro?"))return false;
                  else
                  load('opcionesDepartamento.php','opcion=eliminarConFotos&id_departamento='+msg2[1], 'arbol','');
                  
              }
              
              else if(msg==503)
              {
                  alert("Corredora Eliminada Correctamente");
                  loadHtml('opcionesCorredora.php','opcion=admin','arbol','cont1');
              } 
              
              else if(msg==603)
              {
                  alert("Inmobiliaria Eliminada Correctamente");
                  loadHtml('opcionesInmobiliaria.php','opcion=admin','arbol','cont1');
              }
              
              else if(msg==703)
              {
                  alert("Encuesta Eliminada Correctamente");
                  loadHtml('opcionesEncuesta.php','opcion=admin','arbol','cont1');
              }
              
              else if(msg==803)
              {
                  alert("Favorito Eliminado Correctamente");
                  loadHtml('opcionesFavoritos.php','opcion=admin','arbol','cont1');
              }
              
              else if(msg==903)
              {
                  alert("Cambio Realizado");
                  loadHtml('opcionesCorredora.php','opcion=admin','arbol','cont1');
              }
            
              else 
              {
                  alert(msg);
                  
              }
                  
                        
                        
              
   }
              
          else{
            $("#"+div).html(msg);
            $("#"+divloading).hide();}
                


            }
        });
    }
    
    function loadHtml(url,datos,divloading,div){
    
       $.ajax({
            beforeSend: function(){

              $("#"+divloading).show();

            },
            type: "POST",
            url:url,
            data: datos,
            async: true,
            cache:false,
            success: function(msg){
            	$("#"+div).html(msg);
            	$("#"+divloading).hide();

              }
        });
    }

