$().ready(function() {
    
    $("#upload_image").show();
    $(".image_uploading").hide();
	$("#upload_image").click(function() {
	    $(".image_uploading").show();
        $("#upload_image").hide();
	});
    
    $('#change_user_id').change(function() {
    
        alert('Importing advertisers default contact details.');
        window.location = $(this).attr('title')+$(this).val();
        return false;
    });
    
	$(".thumbs, .clicks").click(function() {
		window.location=$(this).find("a").attr("href");return false;
	});
    
	$(".newsletter_form").click(function() {
		window.location=$(this).find("a").attr("href");return false;
	});
    
    $('#edit_user_id').change(function() {
        
    });
    
    $('#search, .per_line, .search_button').focus(function() {
      $(this).val('');
    });

    $(".change_password").hide();
	$(".show_password").click(function() {
	    $(".hide_password").hide();
		$(".change_password").show();
	});
    
	$(".password_cancel").click(function() {
	    $(".hide_password").show();
		$(".change_password").hide();
	});
    
	$.ajaxSetup ({  
		cache: false  
	});
    
    $('.action_delete').click(function(event) {
        var answer = confirm('Are you sure you want to complete this task?');
        
        if (answer){
                
            var hideID = $(this).attr('id');
            var loadUrl = $(this).attr('title');
        
    		$.get(
    			loadUrl,
    			{language: "php", version: 5},
    			function(responseText){
                    alert(responseText);
                    location.reload();
    			},
    			"html"
    		);
            
            
        }else{
            
        }
        
        return false;
    }) 
    
    $('.action_status').click(function(event) {
        var answer = confirm('Are you sure you want to change this status?');
        
        if (answer){
                
            var hideID = $(this).attr('id');
            var loadUrl = $(this).attr('title');
        
    		$.get(
    			loadUrl,
    			{language: "php", version: 5},
    			function(responseText){
                    alert(responseText);
                    location.reload();
    			},
    			"html"
    		);
            
            
        }else{
            
        }
        
        return false;
    })
    
    // Counties ----------------------------------
    
	$("#county").change(function(){
	   
       var id = $(this).val();
								  
		var loadUrl = '/ajax/searchTowns/' + id;
		var ajaxDiv = '#result_towns';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);

	});
    
    // Categories ----------------------------------
    
	$("#categories").change(function(){
	   
       var id = $(this).val();
								  
		var loadUrl = '/ajax/searchSubCategories/' + id;
		var ajaxDiv = '#result_cats';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);

	});
    
    
    // Alpha ----------------------------------
    
    $(".alpha_categories").hide();
    
    $("#alpha li").click(function(){			
			var id = $(this).attr("id");
            callAlphaCategories(id);
	        $(".alpha_categories").show();
	});
    
    $(".alpha_categories").mouseover(function(){
	        $(".alpha_categories").show();
	});

    $(".alpha_categories").mouseout(function(){
	        $(".alpha_categories").hide();
	});
        
    function callAlphaCategories(id){ 

        var loadUrl = '/ajax/searchAlphaCategories/' + id;
		var ajaxDiv = '.alpha_categories';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);
        
    }
    
    // Search ----------------------------------
    
    $(".sub_search").hide();
    
    $(".search").click(function(){			
	  $(".sub_search").show();
	});
  
    $(".sub_search").mouseover(function(){			
	  $(".sub_search").show();
	});

    $(".sub_search").mouseout(function(){			
	  $(".sub_search").hide();
	});
    
    // Models ----------------------------------
    
	$("#make").change(function(){
	   
       var id = $(this).val();
								  
		var loadUrl = '/ajax/searchModels/' + id;
		var ajaxDiv = '#result_models';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);

	});
    
    
    // Forms  ----------------------------------
    
	$("#county_id").change(function(){
       
        var id = $(this).val();			  
		var loadUrl = '/ajax/formTowns/' + id;
		var ajaxDiv = '#result_town_id';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);

	});
    
	$("#cat_id").change(function(){
       
        var id = $(this).val();			  
		var loadUrl = '/ajax/formCars/' + id;
		var ajaxDiv = '#result_cat_id';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);

	});
    	
});
