$.ajaxSetup( {
type : 'POST',	   
 url  : 'http://www.srogold.com/ajax.php'
} ); 

function getserver(){
alert("1111");
	if($.trim($('#quick_game_select').val())==''){
		$('#serverlist').html('<select  disabled="disabled" class="textinput"><option value="">Choose server</option></select>');
		$('#numlist').html('<select id="numlist" disabled="disabled" class="textinput"><option value="">Choose Amount</option></select>');
		$("#currey_quickgold").attr('disabled','disabled');
		return;	
		}
  $("#currey_quickgold").attr('disabled','disabled');

  $("#server1").attr('disabled','disabled');

  $("#num").attr('disabled','disabled');
  $("#load_ajax_quickgoldgamelist").attr('style','display:block');
  $("#goldPriceList").attr('style','display:none');				
  var gameidArray = ($('#quick_game_select').val()).split('|');
  var gameId = gameidArray[0];
  if(gameId=='1'){
  $("#load_game_no_rs").attr('style','display:');
  $("#load_game_no_rs2").attr('style','display:');
  $("#load_game_rs").attr('style','display:none');
  }else{
  $("#load_game_no_rs").attr('style','display:none');
  $("#load_game_no_rs2").attr('style','display:none');
  $("#load_game_rs").attr('style','display:');
  }
  
  //document.getElementById("load_ajax_quickgoldgamelist").style.display = 'block';
  //alert($("#load_ajax_quickgoldgamelist").attr('style'));
  if(gameId=='1'){
  $.ajax({
  alert("2222");
 data : 'game_id='+gameId+'&type=server',
 //dataType : 'script',
 success : function(data){
 alert("3333");
            eval('var serverArray='+data);
			 
			  var str_serverList='<select id="server1" name="server1" onchange="getreserver();">';
		           str_serverList+='<option value="">Choose server</option>';
		      
			for(var key in serverArray){
				 if(key=='add'){continue;}
				str_serverList+='<option value="'+serverArray[key][0]+'|'+serverArray[key][2]+'" >'+serverArray[key][1]+'</option>';
			   }
		   str_serverList+='</select>';
		 $('#serverlist').html(str_serverList);
		 $("#load_ajax_quickgoldgamelist").attr('style','display:none');		
				}
	   	 })		
  }else{
  $.ajax({
  alert("4444");
 data : 'game_id='+gameId+'&type=server',
 //dataType : 'script',
 success : function(data){
            eval('var serverArray='+data);
			 
			  var str_serverList='<select id="server1" name="server1" onchange="getproducts();">';
		           str_serverList+='<option value="">Choose server</option>';
		      
			for(var key in serverArray){
				 if(key=='add'){continue;}
				str_serverList+='<option value="'+serverArray[key][0]+'|'+serverArray[key][2]+'" >'+serverArray[key][1]+'</option>';
			   }
		   str_serverList+='</select>';
		 $('#serverlist').html(str_serverList);
		 $("#load_ajax_quickgoldgamelist").attr('style','display:none');	
		 $("#load_server_rs").attr('style','display:none');

				}
	   	 })		
  }
}

function getreserver(){
var serveridArray = ($('#server1').val()).split('|');
var serverId = serveridArray[0];
$.ajax({
		 data : 'server_id='+serverId+'&type=products',
 	 success : function(data){
		if(data=="[]"){
		  $("#load_server_rs").attr('style','display:');
		  $("#serverlist3").attr('style','display:block');
		}else{
		  $("#load_server_rs").attr('style','display:none');
		  $("#serverlist3").attr('style','display:none');
			    getproducts();
		}
	 }
 })
  
  $("#currey_quickgold").attr('disabled','disabled');

  $("#num").attr('disabled','disabled');

  $("#load_ajax_quickgoldgamelist").attr('style','display:block');
  
	  $.ajax({
	 data : 'game_id='+serverId+'&type=server',
	 //dataType : 'script',
	 success : function(data){
				eval('var serverArray='+data);
				 
				  var str_serverList='<select id="server2" name="server2" onchange="getproducts();">';
					   str_serverList+='<option value="">Choose server</option>';
				  
				for(var key in serverArray){
					 if(key=='add'){continue;}
					str_serverList+='<option value="'+serverArray[key][0]+'" >'+serverArray[key][1]+'</option>';
				   }
			   str_serverList+='</select>';
			 $('#serverlist2').html(str_serverList);
			 $('#serverlist3').html(str_serverList);
			 $("#load_ajax_quickgoldgamelist").attr('style','display:none');		
					}
			 })	
}



function getproducts(){
	if($.trim($('#server1').val())==''){
		$('#numlist').html('<select id="num" disabled="disabled" class="textinput" style="width:150px,_width:360px;"><option value="">Choose Amount</option></select>');
		$('#pricelist').html('');
		$("#currey_quickgold").attr('disabled','disabled');
		return;	
		}
  $("#num").attr('disabled','disabled');
  $("#currey_quickgold").attr('disabled','disabled');
  $("#load_ajax_quickgoldgamelist").attr('style','display:block');
  
  if($('#server2').val()!=""){
  $.ajax({
 data : 'server_id='+$('#server2').val()+'&type=products',
 //dataType : 'script',
 success : function(data){	
             eval('var productArray='+data);
			 var currcury = $("#currey_quickgold").val();
			 var currcury_type = document.getElementById("currey_quickgold").options[document.getElementById("currey_quickgold").selectedIndex].text;
			 switch(currcury_type){
				 
				  case 'USD':
				    currcury_code = '$';
				    break;
				  case 'EUR':
				    currcury_code = '&euro;';
				    break;
				  case 'GBP':
				    currcury_code = '&pound;';
				    break;
				 
			 }
			 var str_productList='<select class="textinput" id="num" style="width:150px,_width:360px;" onchange="getprice();">';
		     str_productList+='<option value=""  >Choose Amount</option>';
			 var str_list_price = '<tr><td width="">Gold</td><td width="">Price</td></tr>';
		      
			for(var key in productArray){
				 if(key=='add'){continue;}
				str_productList+='<option value="'+(parseFloat(productArray[key][0].replace("\t","")*currcury)).toFixed(2)+'|'+$.trim(productArray[key][3])+'|'+currcury_code+'|'+productArray[key][1]+'" >'+$.trim(productArray[key][1])+' '+$.trim(productArray[key][4])+'</option>';
				str_list_price+='<tr><td>'+$.trim(productArray[key][1])+' '+$.trim(productArray[key][4])+'</td><td>'+currcury_code+(parseFloat(productArray[key][0].replace("\t","")*currcury)).toFixed(2)+'</td></tr>';
			   }
		   str_productList+='</select>';
		 $('#numlist').html(str_productList);    
		 $("#currey_quickgold").attr('disabled','');
		 $('#goldPriceList').html(str_list_price);
		 $("#load_ajax_quickgoldgamelist").attr('style','display:none');				
				}
		 })	
  }else{
var serveridArray = ($('#server1').val()).split('|');
var serverId = serveridArray[0];
  $.ajax({
 data : 'server_id='+serverId+'&type=products',
 //dataType : 'script',
 success : function(data){	
             eval('var productArray='+data);
			 var currcury = $("#currey_quickgold").val();
			 var currcury_type = document.getElementById("currey_quickgold").options[document.getElementById("currey_quickgold").selectedIndex].text;
			 switch(currcury_type){
				 
				  case 'USD':
				    currcury_code = '$';
				    break;
				  case 'EUR':
				    currcury_code = '&euro;';
				    break;
				  case 'GBP':
				    currcury_code = '&pound;';
				    break;
				 
			 }
			 var str_productList='<select class="textinput" id="num" style="width:150px,_width:360px;" onchange="getprice();">';
			 var str_list_price = '<tr><td bgcolor="#FFFFFF">Gold</td><td bgcolor="#FFFFFF">Price</td></tr>';
		     str_productList+='<option value="">Choose Amount</option>';
		      
			for(var key in productArray){
				 if(key=='add'){continue;}
				str_productList+='<option value="'+(parseFloat(productArray[key][0].replace("\t","")*currcury)).toFixed(2)+'|'+$.trim(productArray[key][3])+'|'+currcury_code+'|'+productArray[key][1]+'" >'+$.trim(productArray[key][1])+' '+$.trim(productArray[key][4])+' </option>';
				str_list_price+='<tr><td bgcolor="#FFFFFF">'+$.trim(productArray[key][1])+' '+$.trim(productArray[key][4])+'</td><td bgcolor="#FFFFFF">'+currcury_code+(parseFloat(productArray[key][0].replace("\t","")*currcury)).toFixed(2)+'</td></tr>';
			   }
		   str_productList+='</select>';
		 $('#numlist').html(str_productList); 
		 $('#goldPriceList').html(str_list_price);
		 $("#goldPriceList").attr('style','display:');				
		 $("#currey_quickgold").attr('disabled','');
		 $("#load_ajax_quickgoldgamelist").attr('style','display:none');				
				}
		 })	
  }
}


function getprice(){

$("#load_ajax_quickgoldgamelist").attr('style','display:block');
var  productIdarr = ($("#num").val()).split("|");
var  productPrice = productIdarr[0];
var  productID = productIdarr[1];
var  productType = productIdarr[2];
	  if($("#num").val()==""){
			 var str_productList='<input type="text" readonly="readonly" id="priceType" name="priceType" value="0.00" />';
	  }else{
			 var str_productList='<input type="text" readonly="readonly" id="priceType" name="priceType" value="'+productType+productPrice+'" />';
	  }
		 $('#pricelist').html(str_productList);
		 $("#currey_quickgold").attr('disabled','');
		 $("#load_ajax_quickgoldgamelist").attr('style','display:none');				
}
