﻿$(function(){ 

	var game_select    =  $('#fr_game');
	var server_select  =  $('#fr_server');
	var product_select =  $('#fr_product');
	var money_choose   =  $('input[name=moneytype]');
	var fastorderbt    =  $('#fastorderbt');
	var price		   =  $('#price');
	var selccode	   =  $('#selccode');
	$.get('/inc/ajax.fastorder.asp?action=GetGameList', function(data) {
		if(data!=''){ 
			game_select.append($(data));
			game_select.removeAttr('disabled');
		}
	})
	
	game_select.change(function(){
		server_select.children('option:gt(0)').remove();
		product_select.children('option:gt(0)').remove();
		product_select.attr('disabled','disabled');
		setPrice();
		$.get('/inc/ajax.fastorder.asp?action=GetServerList&GameID='+$(this).val(), function(data) {
			if(data!=''){ 
				server_select.append($(data));
				server_select.removeAttr('disabled');
			}	
		})	
	})
	server_select.change(function(){
		product_select.children('option:gt(0)').remove();
		$(price).val(0);
		$.get('/inc/ajax.fastorder.asp?action=GetProductList&ServerID='+$(this).val(), function(data) {
			if(data!=''){ 
				product_select.append($(data));
				product_select.removeAttr('disabled');
			}
		})	
	})
	
	function setPrice(){ 
		$(price).val('0');
		$(selccode).html('');
		
		if ( !(game_select.val()>0) ) return false;
		if ( !(server_select.val()>0) ) return false;
		if ( !(product_select.val()>0) ) return false;

		var queryString = 	'action=GetPrice&ProductID='+product_select.val()
							+ '&ServerID='+server_select.val()
							+ '&GameID='+game_select.val()
							+ '&CurrencyID='+$(':input[name=moneytype]:checked').val();
							
		$.get('/inc/ajax.fastorder.asp?'+queryString, function(data) {
			if (data!=''){ 
				var arr = data.split(' ');
				$(price).val(arr[0]);
				$(selccode).html(arr[1]);	
			}
		})	
	}
	
	product_select.change(function(){ 
		setPrice();
	})
	
	money_choose.click(function(){
		setCookie("currencyID",1+Number($(this).val()));
		setPrice();
	})
	
	fastorderbt.click(function(){
		if ( ($('#fr_product').val()>0) )
			location.href = '/shoppingcart.asp?pid='+product_select.val();
	})



})
