var followed_link;

function updateZones(selectZone)
{
	var country_id = $('#country_id').val();
	
	if(country_id == 'none')
	{
		$('#zone_id').html("").attr('disabled', 'disabled');;
		return false;
	}
	
    $.ajax({
    	url: zonesStoreUrl,
    	dataType: 'json',
    	type: 'GET',
    	data: {country_id: country_id},
    	beforeSend: function()
    	{
    		$('#zone_id').html('<option>' + loadingLabel + '</option>');
    	},
    	success: function(data, textStatus)
    	{
    		if(data.items.length > 0)
    		{
    			
    			$('#zone_id').html('');
    			
    			// Adding empty option (default)
    			option = $('<option value="0"></option>');
    			$('#zone_id').append(option);
    			
    			for(var i = 0; i < data.items.length; i++)
    			{
    				var item = data.items[i],
    					option = $('<option value="' + item.zone_id + '">' + item.name + '</option>');
    				
    				$('#zone_id').append(option);
    			}
    			$('#zone_id').attr('disabled', '');
    			
    			if(selectZone)
    			{
    				$('#zone_id').val(selectZone);
    			}
    		}
    		else
    		{
    			$('#zone_id').attr('disabled', 'disabled');
    		}
    	}
    });
}

function updateOption()
{
    var artistClassified_iType = $('#artistClassified_iType').val(),
    	artistClassifiedOption_id_label = $('#artistClassifiedOption_id-label label');
    
    
    if(artistClassified_iType.length > 0)
    {
    	$('#artistClassifiedOption_id-label').show();
    	$('#artistClassifiedOption_id-element').show();
    }
    else
    {
    	$('#artistClassifiedOption_id-label').hide();
    	$('#artistClassifiedOption_id-element').hide();
    }
    
    
    if(artistClassified_iType == 1)
    {
    	artistClassifiedOption_id_label.text(label_type_artist);
    }
    else if(artistClassified_iType == 2)
    {
    	artistClassifiedOption_id_label.text(label_type_lessons_take);
    }
    else if(artistClassified_iType == 3)
    {
    	artistClassifiedOption_id_label.text(label_type_lessons_give);
    }
    else if(artistClassified_iType == 4)
    {
    	artistClassifiedOption_id_label.text(label_type_job_find);
    }
    else if(artistClassified_iType == 5)
    {
    	artistClassifiedOption_id_label.text(label_type_job_give);
    }
    else if(artistClassified_iType == 6)
    {
    	artistClassifiedOption_id_label.text(label_type_group);
    }
    
    $.ajax({
    	url: optionStoreUrl,
    	type: 'GET',
    	dataType: 'json',
    	data: {artistClassified_iType: artistClassified_iType},
    	beforeSend: function()
    	{
    		$('#artistClassifiedOption_id').html('<option>' + loadingText + '</option>');
    	},
    	success: function(data, textStatus)
    	{
    		var count = data.items.length;
    		
    		if(count > 0)
    		{
    			var select = $('#artistClassifiedOption_id');
    			
    			select.html('').attr('disabled', '');
    			
    			
    			for(var i = 0; i < count; i++)
    			{
    				var item = data.items[i],
    					option = $('<option></option>');
    				
    				option.text(item.name).val(item.artistClassifiedOption_id);
    				select.append(option);
    			}
    		}
    		
    		return data;
    	}
    });
}

function showContent(id)
{
	$("#" + id).slideToggle("slow");
    return false;
}

$(document).ready(function()
{
	
	$('.classified-rows a').each(function(){
		$(this).click(function(){
			followed_link=1;
	        window.location = this.href;
			return true;
		});
	});
	
	$('.classified-rows').each(function(){
		var tr = $(this),
			id = tr.attr('id');
		
		tr.click(function(){
			if (followed_link == 1)
			{
				followed_link=0;
			    return false;
			}
			
			$('#artistClassifiedContent-' + id).slideToggle("slow");
			return false;
		});
	});
});