$.ajaxSetup({
type : 'POST',
contentType : 'application/x-www-form-urlencoded;charset=iso-8859-1',
url  : 'http://www.questmonk.com/ajax.php'
});

function getgame()
{
	$('#QuickGame').html('<select name="QuickGameList" id="QuickGameList" onchange="getserver()" disabled="disabled" style="width:180px"><option value="">please choose your game</option></select>');
	$('#QuickServer').html('<select name="QuickServerList" id="QuickServerList" onchange="getproduct()" disabled="disabled" style="width:180px"><option value="">please choose your server</option></select>');
	$('#QuickProduct').html('<select name="QuickProductList" id="QuickProductList" disabled="disabled" style="width:180px"><option value="">please choose the product</option></select>');
	$("#QuickCurrency").attr('disabled',false);
	$("#Ajax_Load_Quick").attr('style','display:block');
	$.ajax( {
		data : 'qt=' +$.trim($('#QuickType').val())+ '&type=game',
		success : function(data)
			{
				eval('var gameArray=' +data);
				var str_gameList = '<select name="QuickGameList" id="QuickGameList" onchange="getserver()" style="width:180px"><option value="">please choose your game</option>';
				for(var key in gameArray)
				{
					str_gameList += '<option value="' +gameArray[key][0]+ '" >' +gameArray[key][1]+ '</option>';
				}
				str_gameList += '</select>';
				$('#QuickGame').html(str_gameList);
				$("#Ajax_Load_Quick").attr('style','display:none');
				$("#QuickCurrency").attr('disabled',true);
			}
	} );
}

function getserver()
{	
	$('#QuickServer').html('<select name="QuickServerList" id="QuickServerList" onchange="getproduct()" disabled="disabled" style="width:180px"><option value="">please choose your server</option></select>');
	$('#QuickProduct').html('<select name="QuickProductList" id="QuickProductList" disabled="disabled" style="width:180px"><option value="">please choose the product</option></select>');
	$("#QuickCurrency").attr('disabled',true);
	if($.trim($('#QuickGameList').val())==''){return false;}
	$("#Ajax_Load_Quick").attr('style','display:block');	
	$.ajax( {
		data : 'qt=' +$.trim($('#QuickType').val())+ '&gameid=' +$.trim($('#QuickGameList').val())+ '&type=server',
		success : function(data)
			{
				eval('var serverArray=' +data);
				var str_serverList = '<select name="QuickServerList" id="QuickServerList" onchange="getproduct()" style="width:180px"><option value="">please choose your server</option>';
				for(var key in serverArray)
				{
					str_serverList += '<option value="' +serverArray[key][0]+ '" >' +serverArray[key][1]+ '</option>';
				}
				str_serverList += '</select>';
				$('#QuickServer').html(str_serverList);
				$("#Ajax_Load_Quick").attr('style','display:none');
				$("#QuickCurrency").attr('disabled',false);
			}
	} );
}

function getproduct()
{
	var ccode = $.trim($('#QuickCurrency').val());
	if(ccode=='')
	{ccode="USD";}
	$('#QuickProduct').html('<select name="QuickProductList" id="QuickProductList" disabled="disabled" style="width:180px"><option value="">please choose the the product</option></select>');
	$("#QuickProductList").attr('disabled',true);
	$("#Ajax_Load_Quick").attr('style','display:block');
	switch(ccode)
	{
		case 'USD':
			csign = '$';
			break;
		case 'EUR':
			csign = '&euro;';
			break;
		case 'GBP':
			csign = '&pound;';
			break;
		default :
			csign = '$';
			break;
	}
	$.ajax( {
		data : 'qt=' +$.trim($('#QuickType').val())+ '&serverid=' +$.trim($('#QuickServerList').val())+ '&ccode='+ccode+'&type=products',
		success : function(data)
			{
				eval('var productArray=' +data);
				var str_productList = '<select name="QuickProductList" id="QuickProductList" style="width:180px"><option value="">please choose the product</option>';
				for(var key in productArray)
				{
					productarray = productArray[key][1].split('-');
					productnumunit = checknum(productarray[productarray.length-1]);
					str_productList += '<option value="'+productArray[key][0]+'-'+productArray[key][2]+' " >'+productnumunit+' - ' + csign + productArray[key][2]+'</option>';
				}
				str_productList += '</select>';
				$('#QuickProduct').html(str_productList);
				$("#Ajax_Load_Quick").attr('style','display:none');
			}
	} );
}

function getproducts()
{
	var ccode = document.getElementsByName('Currency');
	for(var i=0;i<ccode.length;i++){
		if(ccode[i].checked){
			ccode=ccode[i].value;
			break;
		}
	}
	if(typeof(ccode)=="object")
	{ccode="USD";}
	$('#Product').html('<select name="ProductList" id="ProductList" disabled="disabled" style="width:180px"><option value="">please choose the the product</option></select>');
	$("#ProductList").attr('disabled',true);
	$("#Ajax_Load").attr('style','display:block');
	switch(ccode)
	{
		case 'USD':
			csign = '$';
			break;
		case 'EUR':
			csign = '&euro;';
			break;
		case 'GBP':
			csign = '&pound;';
			break;
		default :
			csign = '$';
			break;
	}
	$.ajax( {
		data : 'qt=&serverid=' +$.trim($('#ServerList').val())+ '&ccode='+ccode+'&type=products',
		success : function(data)
			{
				eval('var productArray=' +data);
				var str_productList = '<select name="ProductList" id="ProductList" style="width:180px"><option value="">please choose the product</option>';
				for(var key in productArray)
				{
					productarray = productArray[key][1].split('-');
					productnumunit = checknum(productarray[productarray.length-1]);
					str_productList += '<option value="'+productArray[key][0]+'-'+productArray[key][2]+' " >'+productnumunit+' - ' + csign + productArray[key][2]+'</option>';
				}
				str_productList += '</select>';
				$('#Product').html(str_productList);
				$("#Ajax_Load").attr('style','display:none');
			}
	} );
}


function checknum(str)
{
	var start; 
	for(i=0;i<str.length;i++)  
	{
		if("0123456789".indexOf(str.substr(i,1))>-1) 
		{
			start = i;
			break;
		}
	}  
	return  str.substr(start);
}

function check_quick()
{
	if($.trim($('#QuickType').val()) == '')
	{
		alert('please choose the type');
		return false;
	}
	if($.trim($('#QuickGameList').val()) == '')
	{
		alert('please choose your game');
		return false;
	}
	if($.trim($('#QuickServerList').val()) == '')
	{
		alert('please choose your server');
		return false;
	}
	if($.trim($('#QuickProductList').val()) == '')
	{
		alert('please choose the the product');
		return false;
	}

	numberPrice = $.trim($('#QuickProductList').val())+'|'+ $('#QuickProductList').find('option:selected').text()
	$("#TypeName").val($('#QuickType').find('option:selected').text());
	$("#QuickGameName").val($('#QuickGameList').find('option:selected').text());
	$("#QuickServerName").val($('#QuickServerList').find('option:selected').text());
	$("#QuickNumberPrice").val(numberPrice);
	$("#quickform").submit();
}