jQuery(document).ready(function(){
	jQuery('#google_maps').change(function(){
		var checked=jQuery("#google_maps").attr('checked');
		if (checked) {
			jQuery('#google_map_details').show();
			jQuery('#service_googlemaps').show();
		}
		else {
			jQuery('#google_map_details').hide();
			jQuery('#service_googlemaps').hide();
		}
	})

	jQuery('#breadcrumb').change(function(){
		var checked=jQuery("#breadcrumb").attr('checked');
		if (checked) {
			jQuery('#breadcrumb_details').show();
		}
		else {
			jQuery('#breadcrumb_details').hide();
		}
	})
	

	
	// delete a service organisation
    jQuery('.delete-service').live("click", function() {
		var nonce = jQuery("#n_wp").attr("value");
		var org_id=this.id;
        var status=this.title;
		var answer = confirm ("Do you really want to permanently " + status.toLowerCase() + "?\n  \'Cancel\' to stop, \'OK\' to delete.")
		if (!answer) return;
		jQuery.ajax({
			type: "post",url: "admin-ajax.php",data: {
            action: 'deleteservice',
            id: escape( this.id), _ajax_nonce: nonce   },
			success: function(html){
				jQuery("#service-"+org_id).remove();
			}
		});
	})	
	
	

	jQuery('#submission').submit(function() {

		var nonce = jQuery("#n_wp").attr("value");
		var url_loc = jQuery("#url").attr("value")+"/wp-admin/admin-ajax.php";
		var status;
		jQuery.ajax({
			type: "post",url: url_loc,data: {
				action: 'addservice',
				_ajax_nonce: nonce,
				org_name:jQuery("#org_name").attr("value"),
				address1:jQuery("#address1").attr("value"),
				address2:jQuery("#address2").attr("value"),
				address3:jQuery("#address3").attr("value"),			
				postcode:jQuery("#postcode").attr("value"),
				phone:jQuery("#phone").attr("value"),
				email:jQuery("#email").attr("value"),
				website:jQuery("#website").attr("value"),
				twitter:jQuery("#twitter").attr("value"),
				facebook:jQuery("#facebook").attr("value"),
				description:jQuery("#description").attr("value"),
				directions:jQuery("#directions").attr("value"),
				maps_lat:jQuery("#maps_lat").attr("value"),				
				maps_lng:jQuery("#maps_lng").attr("value")		
			},
			success: function(status){
				if (status.search("error")==-1) {
					jQuery("#submission").remove();
				}	
				jQuery("#status").html(status);
			}
		});
	
		return false;
	})
	
	
	
	// delete a service category
    jQuery('.delete-service-category').live("click", function() {
		var nonce = jQuery("#n_wp").attr("value");
		var cat_id=this.id;
        var status=this.title;
		var answer = confirm ("Do you really want to permanently " + status.toLowerCase() + "?\n  \'Cancel\' to stop, \'OK\' to delete.")
		if (!answer) return;
		jQuery.ajax({
			type: "post",url: "admin-ajax.php",data: {
            action: 'deleteservicecategory',
            id: escape( this.id), _ajax_nonce: nonce   },
			success: function(html){
				jQuery("#cat-"+cat_id).remove();
			}
		});
	})

});









