$(function() {

	get_location_info($('input#postal_code').val());

	$('input#postal_code').live('keyup', function() {
		get_location_info($(this).val());
	});
	
	$('input#postal_code').live('change', function() {
		get_location_info($(this).val());
	});
	
	$('form#apply_for_job').live('submit', function() {
		var res_val = $('input[name="userfile"]').val();
		
		if(res_val == "")
		{
			alert("A resume file is required to apply for this job!");
			return false;
		}
		
	});

});

function get_location_info(myval)
{		
	if(myval.length == 5)
	{
		var target = "/jobs/location/"+myval;
		
		$.getJSON(target, function(data) {
		
			if(data.AdministrativeAreaName !== undefined)
			{
				$('input[name="municipality"]').val(data.Locality.LocalityName);
				$('input[name="region"]').val(data.AdministrativeAreaName);
				$('span.show_location_info').empty().append("(" + data.Locality.LocalityName + ", " + data.AdministrativeAreaName + ")");
			}
			else
			{
				$('input[name="municipality"]').val('');
				$('input[name="region"]').val('');
				$('span.show_location_info').empty();
			}
		});
	
	}
}
