jQuery(document).ready(function(){
  
  jQuery(".Row .Palabra #buscar_funebres_popup, .ContField .F_Col4 #buscar_funebres").click(function(c){
    updateLocationFunebres(c);
  });
  
  jQuery('.Editor').keyup(function(e) {
	if(e.keyCode == 13) {
	  updateLocationFunebres();
	}
  });  
  
  updateLocationFunebres = function(c){
   	if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
   		var buscar = jQuery('#buscar').val();
   	} else {
   		var buscar = jQuery('#clave').val();
   	}

    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var fecha = jQuery('#fecha_funebres_1').val();
    } else {
    	var fecha = jQuery('#fecha_funebres_2').val();
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_todos = (jQuery('#funebresTodos').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_todos = (jQuery('#Todos').attr('checked')==true)?'1':'0';
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_oficios = (jQuery('#funebresOficios').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_oficios = (jQuery('#Oficios').attr('checked')==true)?'1':'0';
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_sepelios = (jQuery('#funebresSepelios').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_sepelios = (jQuery('#Sepelios').attr('checked')==true)?'1':'0';
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_invitaciones = (jQuery('#funebresInvitaciones').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_invitaciones = (jQuery('#Invitaciones').attr('checked')==true)?'1':'0';
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_participaciones = (jQuery('#funebresParticipantes').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_participaciones = (jQuery('#Participaciones').attr('checked')==true)?'1':'0';
    }
	if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_recordatorios = (jQuery('#funebresRecordatorios').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_recordatorios = (jQuery('#Recordatorios').attr('checked')==true)?'1':'0';
    }
    if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_agradecimientos = (jQuery('#funebresAgradecimientos').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_agradecimientos = (jQuery('#Agradecimientos').attr('checked')==true)?'1':'0';
    }
	if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_traslados = (jQuery('#funebresTraslados').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_traslados = (jQuery('#Traslados').attr('checked')==true)?'1':'0';
    }
	if (jQuery(c.target).attr('id')=='buscar_funebres_popup') {
    	var opcion_funerales = (jQuery('#funebresFuneralesMisas').attr('checked')==true)?'1':'0';
    } else {
    	var opcion_funerales = (jQuery('#Funerales').attr('checked')==true)?'1':'0';
    }	
    
    if (buscar=='' && fecha=='' && opcion_todos==0 && opcion_oficios==0 && opcion_sepelios==0 && opcion_invitaciones==0 && opcion_participaciones==0 && opcion_recordatorios==0 && opcion_agradecimientos==0 && opcion_traslados==0 && opcion_funerales) {
    	var fecha = jQuery('#fecha_hidden').val();
    	opcion_todos = 1;
    }
    
    window.location='/?q=avisos_funebres&buscar='+buscar+'&fecha='+fecha+'&opcion_todos='+opcion_todos+'&opcion_oficios='+opcion_oficios+'&opcion_sepelios='+opcion_sepelios+'&opcion_invitaciones='+opcion_invitaciones+'&opcion_participaciones='+opcion_participaciones+'&opcion_recordatorios='+opcion_recordatorios+'&opcion_agradecimientos='+opcion_agradecimientos+'&opcion_traslados='+opcion_traslados+'&opcion_funerales='+opcion_funerales;           
  };
  jQuery('#fecha_funebres_1').datePicker();
  jQuery('#fecha_funebres_2').datePicker();

});
