var apiPath = "/feiying-service/";

$.createUUID = function() {
	return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4()
			+ S4() + S4());
};

var S4 = function() {
	return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};

$(function() {

	$("#submit").bind('click', function() {
		var actionType = $('#actionType option:selected').val();
		if (actionType == "") {
			alert("Please select the action type!");
			return false;
		}
		var url = $("#json").val();

		$.ajax({
			url : apiPath + encodeURI(url),
			type : "GET",
			async : false,
			success : function(json) {
				console.debug(json);
				console.debug(JSON.stringify(json));
				console.debug(JSON.parse(JSON.stringify(json)));
				console.debug(JSON.parse(JSON.stringify(json)) == json);
				console.debug(FormatJSON(json));
				$("#response").val(FormatJSON(json));
			}
		});
		
	
	});
	$("#clear").bind('click', function() {

		$("#actionType option").filter(function() {
			return $.trim($(this).text()) == "----";
		}).attr('selected', true);

		$("#json").val("");
		$("#response").val("");
	});

});

function change(o) {
	var type = $(o).val();
	if (type != "") {
		$("#json").val($("#" + type + "SampleData").val());
		/*$("#json").val($("#" + type + "SampleData").html());*/
		$("#tips").val($("#" + type + "Tips").html());
	}
}