$(document).ready(function()
{

    $(".jumpmenu").change(function(e) {
        window.location.href = this.options[this.selectedIndex].value;
    });


    $("select#county").change(function(){
       if($(this).val() == 18){
           $("#london").slideDown();
       };
    });

    $("select#category").change(function()
    	    {
    	        $.ajax({
    	            type: "GET",
    	            dataType: 'json',
    	            url: '/suggest/get_subcategories/'+$(this).val(),
    	            global: false,
    	            success: function(j){
    	                var options = '';
    	                for (var i = 0; i < j.length; i++) {
    						if (i == 0)
    						{
    							$("#uniform-subcategories > span").text(j[i].name);
    						};
    						options += '<option value="' + j[i].id + '">' + j[i].name + '</option>';
    	                }
    	                $("#subcategories").html('<option value=""> - Please Choose Sub Category - </option>'+options);
    	            },
    	            error: function(XMLHttpRequest, textStatus, errorThrown){
    	                alert('An error occured - ' + errorThrown + ' ' +  textStatus);
    	            }
    	        });
    	    });

    if($('#request_site_update').length > 0)
    {
        $('#request_site_update').click(function(event)
        {
            event.preventDefault();

            $.ajax({
                type: "GET",
                dataType: 'jsonp',
	            jsonp: false,
	            jsonpCallback: "update_site",
                url: $(this).attr('href'),
                global: false,
                success: function(message)
                {
                    if(message.colour && message.text)
                    {
                        $("#request_site_update_status").html(message.text+'<br />').attr("style", "color:"+message.colour);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    alert('An error occured - ' + errorThrown + ' ' +  textStatus);
                }
            });
        });
    }

	$(".set_subcat_order").change(function(){
		var selected = $(this).find('option:selected');
		var theurl = selected.data('theurl');
		var redirect_url = selected.data('redirecturl');

        $.ajax({
            type: "GET",
            dataType: 'jsonp',
	        jsonp: false,
	        jsonpCallback: "set_subcat_order",
            url: theurl,
            global: false,
            success: function()
            {
                window.location = redirect_url;
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                alert('An error occured - ' + errorThrown + ' ' +  textStatus);
            }
        });
	});

});

