
var json_data = null;

function update() {
	if(json_data != null) {
		$('.load, .load_image').show();
		
		$.get("translate.php", { web: true, message: escape(json_data.from.language + ' ' + json_data.to.language + ' ' + $("#sample").val()) }, function(data){
			$(".sample_data_result").html(data); 
			$(".sample_data").html($("#sample").val()); 	
			
			$('.load, .load_image').hide();
			
		});
	}
}

/**
 * document ready function
 */
$(document).ready(function() {
	
	//get dealer autocomplete
	
	$("#from, #to").change(function(e) {
		if($("#from").val() != '' && $("#to").val() != '') {
			
			$("#result .default").hide();
			$("#result .selected").show();			
			$('.load, .load_image').show();
			
			$.get("country.php", { from: $("#from").val(), to: $("#to").val()}, function(json){
				
				var text = 'You send an SMS, that reads<br/> <b>"';
				text = text + '<span class="highlight">' + json.to.keyword + ' ' + json.from.language + ' ' + json.to.language + '</span> <span class="sample_data">' + json.from.hello;
				text = text + '</span>"</b><br/> to ' + json.to.number + ' in ' + json.to.name + ' (' +  json.to.price + ') ';
				text = text + '<br/> and we send you back the translation:<br/>';
				
				$('.sample').show();
				
				$("#sample").val(json.from.hello);
				
				$("#result .selected").html(text);
			  	$('.load, .load_image').hide();
			  	
			  	json_data = json;
			  	$.get("translate.php", { web: true, message: escape(json.from.language + ' ' + json.to.language + ' ' + json.from.hello) }, function(data){
					$("#result .selected").append('<b class="sample_data_result">' + data + '</b>');  	
				});
			  	
			}, "json");
		} else {
			$("#result .default").show();
			$("#result .selected, .sample").hide();
		}
	});
	
	$('#sample').keypress(function(e) {
		if(e.keyCode == 13) {
			update();
			return false;
		}
	});
	
	$('#test').click(function(e) {
		update();
		return false;
	});
	
	$('a.point').click(function(e) {
		$('.point_text').toggle("slow");
		return false;
	});
	
});



