	$(function() {
		//AJAX setup and overLay 		
	    $.ajaxSetup({
	        async: true,
	        global: true,
	        type: "POST",	        
	        dataType: "json",
	        error: function (XMLHttpRequest, textStatus, errorThrown) {},        
	        cache: false
	    });		
		
	    function overTransform(obj) {
	        $.ajax({
	            beforeSend: function(XMLHttpRequest){
	                var dim = $(obj.target).offset({
	                    border:true
	                });
	                $('<div id="over1"><img src="/images/ajax_loader.gif" alt="img"/></div>').appendTo(document.body)
	                .css({
	                    position:'absolute',
	                    top:dim.top,
	                    left:dim.left,
	                    backgroundColor:'#000',
	                    width:$(obj.target).outerWidth(),
	                    height:$(obj.target).outerHeight()
	                });
	            },
	            url: "ajax.php",
	            data: JSON.stringify(obj.sendData),
	            success: function (data, textStatus) {
	                obj.transform(data, JSON.parse(this.data), obj.target);
	            },
	            complete: function (XMLHttpRequest, textStatus) {
	                $('#over1').remove();
	            }
	        });
	    }	
	    //--------
	    
	    //SWH		
	    $('#pet_type_id').change(function(e) {	        
	    	var pet_id = $(e.target).val();
	
            overTransform({
	                target: $('#location_id').get(0),
	                sendData: {	                    
	                    target:'getSWHpetsLocations',
	                    indata:{'pet_id':pet_id, 'type':'swh'}
	                },
	                transform: function(response, request, element) {	                	
	                    element.options.length = 0;
	                    element.options[element.options.length] = new Option('All Counties', '', false, false);
	                    try {
		                    element.options[element.options.length] = new Option(response[0]['location'], response[0]['location_id'], false, false);
		                    
		                    for(var i=1; i<response.length; i++) {
		                        element.options[element.options.length] = new Option(response[i]['location'], response[i]['location_id'], false, false);
		                    }
		                }catch(e){}    
	                }
	       });	        
	    });
	    
	    //LF
	    $('#switcher-lost, #switcher-found').click(function(e) {	        
	    	var type = $(e.target).val();
	    		
            overTransform({
	                target:   $('#location_id_lf_form').get(0),
	                sendData: {	                    
	                    target: 'getLFpetsLocations',
	                    indata: type
	                },
	                transform: function(response, request, element) {	                	
	                    element.options.length = 0;
	                    element.options[element.options.length] = new Option('All Counties', '', false, false);
	                    try {
		                    element.options[element.options.length] = new Option(response[0]['location'], response[0]['location_id'], false, false);
		                    
		                    for(var i=1; i<response.length; i++) {
		                        element.options[element.options.length] = new Option(response[i]['location'], response[i]['location_id'], false, false);
		                    }
	                    }catch(e){}
	                }
	       });	             
	    });
	    
	});
