﻿$(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();
		$.get('/inc/ajax.fastorder.asp?action=GetServerList&GameID='+$(this).val(), function(data) {
			if(data!=''){ 
				server_select.append($(data));
				server_select.removeAttr('disabled');
				product_select.attr('disabled','disabled');
				price.val('0');
				selccode.html('');
				money_choose.first().attr('checked',true);
			}	
		})	
	})
	server_select.change(function(){
		product_select.children('option:gt(0)').remove();
		$(price).val(0);
		$.get('/inc/ajax.fastorder.asp?action=GetProductList&ServerID='+$(this).val()+'&GameID='+$('#fr_game').val()+'&CurrencyID='+$('input[name=moneytype]:checked').val(), function(data) {
			if(data!=''){ 
				product_select.append($(data));
				product_select.removeAttr('disabled');
			}
		})	
	})
	product_select.change(function(){ 
		setPrice();
	})
	money_choose.click(function(){
		if ( !($('#fr_game').val()>0) ){return true;}
		if ( !($('#fr_product').val()>0) ){return true;}
		var value = product_select.val();
		setCookie("currencyID",1+Number($(this).val()));
		product_select.children('option:gt(0)').remove();
		$.get('/inc/ajax.fastorder.asp?action=GetProductList&ServerID='+server_select.val()+'&GameID='+$('#fr_game').val()+'&CurrencyID='+$(this).val(), function(data) {
			if(data!=''){ 
				product_select.append($(data));
				product_select.children('option[value='+value+']').attr('selected',true);
				setPrice();
			}
		})	

	})
	fastorderbt.click(function(){
		if($('#fr_product').children('').length>1)					   
			location.href = '/shoppingcart.asp?pid='+product_select.val();
	})

	function setPrice(){ 
		var oprice = product_select.children('option:selected').attr('oprice');
		$(price).val( oprice );
		var currencyCode = product_select.children('option:selected').attr('ocurr');
		$(selccode).html( currencyCode );
	}

})
