var loadding = "<div class='loadding'>load...</div>";

function getServer(areaid) {
	$("#serverdiv").html(loadding);
	$("#quantitydiv").html(loadding);
	$("#price").html(loadding);
	$("#showallprice").html(loadding);	
	
	$.ajax({
		type:"POST",
		url:"ajax_server.php",
		data:"sendtype=server&areaid=" + areaid,
		success:function(server) {
			$("#serverdiv").empty().html(server);
			$("#serverdiv select").change(function() {
				var areaid = $(this).val();
				getQuantity(areaid);
			});
			$("#serverdiv select").trigger("change");
		}
	});
}

function getQuantity(serverid) {
	$("#quantitydiv").html(loadding);
	$("#price").html(loadding);
	$("#showallprice").html(loadding);
	
	$.ajax({
		type:"POST",
		url:"ajax_server.php",
		data:"sendtype=quantity&serverid=" + serverid,
		success:function(quantity) {
			$("#quantitydiv").empty().html(quantity);
			$("#quantitydiv select").change(function() {
				var productsid = $(this).val();
				getPrice(productsid);
			});
			$("#quantitydiv select").trigger("change");
		}
	});
}

function getPrice(productsid) {
	$("#price").html(loadding);
	$("#showallprice").html(loadding);
	
	$.ajax({
		type:"POST",
		url:"ajax_server.php",
		data:"sendtype=price&productsid=" + productsid,
		success:function(price) {
			$("#price").html(price);
			getAllPrice();
		}
	});
}

function getCurr(currency,productsid) {
	$("#price").html(loadding);
	$("#showallprice").html(loadding);

	$.ajax({
		type:"POST",
		url:"ajax_server.php",
		data:"sendtype=price&currency=" + currency + "&productsid=" + productsid,
		success:function(price) {
			$("#price").html(price);
			getAllPrice();
		}
	});
}

function getAllPrice() {

	$.ajax({
		type:"POST",
		url:"ajax_server.php",
		data:"sendtype=allprice",
		success:function(allprice) {
			$("#showallprice").html(allprice);
		}
	});
}

$(function() {
	$("input[type='radio'][name='serverarea']").click(function() {
		var serverArea = $(this).val();
		getServer(serverArea);
	});
	
	//$("input[type='radio'][name='serverarea']").eq(0).trigger("click");
});

