﻿//fastOrder
var thispath="../";
function setthispath(Mthispath)
	{
		thispath=Mthispath;
	}
	




function trim(s)
{
	return s.replace(/\s+$|^\s+/g,"");
} 
function isEmail(s)
{
	s = trim(s); 
	var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i; 
	return p.test(s);
}
function Check()
{
	if(document.theform.GameNameListID.options[document.theform.GameNameListID.selectedIndex].value==0)
	{
		alert("Please select the game!");
		return false;
	}
	else if(document.theform.ServerNameListID.options[document.theform.ServerNameListID.selectedIndex].value==0)
	{
		alert("Please select the server!");
		return false;
	}
	else if(document.theform.ProductNameListID.options[document.theform.ProductNameListID.selectedIndex].value==0)
	{
		alert("Please select the product!");
		return false;
	}
	//else if(trim(document.getElementById("FullName").value) == ""){
//		alert("Please enter your Full name!");
//		return false;
//	}
//	else if(trim(document.getElementById("CharacterName").value) == ""){
//		alert("Please enter your Character name!");
//		return false;
//	}
//	else if(trim(document.getElementById("Email").value) == ""){
//		alert("Please enter your Email!");
//		return false;	
//	}
	//else if(isEmail(document.getElementById("Email").value)){
//		alert("Please valid your Email!")
//		return false;
//	}	
	//else if(trim(document.getElementById("Phone").value) == ""){
//		alert("Please enter your phone number!")
//		return false;
//	}
//	else{
//		//index fastorder track
//		jq.ajax({
//			url: '/ajax/fastOrderStat.cfm',
//			async: false
//		});
//	}
}
function send_request(url,obj) 
{
	http_request = false;
	
	if(window.XMLHttpRequest) 
	{ 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) 
	{ 
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{}
		}
	}
	if (!http_request) 
	{ 
		return false;
	}
		http_request.onreadystatechange = obj;
		
		
		http_request.open("GET", url, true);
		http_request.send(null);
}
function getGamelist()
{
	send_request(thispath+"ajax/geFastordertGameList.cfm",BoandGamelist);
}

function BoandGamelist()
{
	/*var str=ReAjax.prototype.LoadUrl2(thispath+"ajax/getGameList.cfm");*/
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{ 
			var str=http_request.responseText;
			while(document.theform.GameNameListID.options.length>0)
			{
				document.theform.GameNameListID.remove(0)
			}
			document.theform.GameNameListID.selectedIndex=-1;
			var rightstr=str.split("$$$");
			var arrayStr=rightstr[0].split("|");
			var i;
			var opt=document.createElement("OPTION");
			opt.text="---Please select the game---";
			opt.value="0";
			document.theform.GameNameListID.options.add(opt);
			opt.selected=true;
			if(arrayStr.length-1>0)
			{
				for(i=0;i<arrayStr.length-1;i++)
				{
					var arrayName=new Array(1);
					arrayName=arrayStr[i].split("@");
					var opt=document.createElement("OPTION");
					opt.text=arrayName[1];
					opt.value=arrayName[0];
					opt.title=arrayName[1];
					document.theform.GameNameListID.options.add(opt);
				}
			}
		}
	}
		
}
var tempGid=0;
function getServerList(gameid)
{
	//if(gameid==1||gameid==15)
//	{
//	   document.getElementById("ServerNameListID").length=1;
//	   document.getElementById("ProductNameListID").length=1;
//	   document.getElementById("AZs").style.display="";
//	   document.getElementById("ServerNameListID").style.width="202px";
//	   tempGid = gameid;
//	   getServerListByAZ(document.getElementById("AZs").value);
//	}
//	else{
	tempGid=0;	
//document.getElementById("AZs").style.display="none";
//document.getElementById("ServerNameListID").style.width="250px";
	send_request(thispath+"ajax/getFastorderServerList.cfm?gameid="+gameid,BoandServerList);
	//}
}
function getServerListByAZ(indexA){
	if(tempGid==1||tempGid==15){
    send_request(thispath+"ajax/getFastorderServerList.cfm?gameid="+tempGid+"&indexA="+indexA,BoandServerList);	
	}
}
function getServerListByAZ2(indexA){
    send_request(thispath+"ajax/getFastorderServerList.cfm?gameid="+document.getElementById('GameNameListID').value+"&indexA="+indexA,BoandServerList);	
}
function BoandServerList()
{
	while(document.theform.ServerNameListID.options.length>0)
	{
		document.theform.ServerNameListID.remove(0)
	}
	document.theform.ServerNameListID.selectedIndex=-1;
	var opt=document.createElement("OPTION");
	opt.text="---Loading...---";
	opt.value="0";
	document.theform.ServerNameListID.options.add(opt);
	opt.selected=true;
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{ 
			var str=http_request.responseText;
			while(document.theform.ServerNameListID.options.length>0)
			{
				document.theform.ServerNameListID.remove(0)
			}
			document.theform.ServerNameListID.selectedIndex=-1;
			var rightstr=str.split("$$$");
			var arrayStr=rightstr[0].split("|");
			var i;
			var opt=document.createElement("OPTION");
			opt.text="---Please select the server---";
			opt.value="0";
			document.theform.ServerNameListID.options.add(opt);
			opt.selected=true;
			if(arrayStr.length-1>0)
			{
				for(i=0;i<arrayStr.length-1;i++)
				{
					var arrayName=new Array(1);
					arrayName=arrayStr[i].split("@");
					var opt=document.createElement("OPTION");
					opt.text=arrayName[1];
					opt.value=arrayName[0];
					opt.title=arrayName[1];
					document.theform.ServerNameListID.options.add(opt);
				}
			}
		}
	}
}

function getProductList(gameid,serverid)
{
	send_request(thispath+"ajax/getFastorderProductList.cfm?gameid="+gameid+"&serverid="+serverid,BoandProductList);
}
function BoandProductList()
{
	while(document.theform.ProductNameListID.options.length>0)
	{
		document.theform.ProductNameListID.remove(0)
	}
	document.theform.ProductNameListID.selectedIndex=-1;
	var opt=document.createElement("OPTION");
	opt.text="---Loading...---";
	opt.value="0";
	document.theform.ProductNameListID.options.add(opt);
	opt.selected=true;
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{ 
			var str=http_request.responseText;
			while(document.theform.ProductNameListID.options.length>0)
			{
				document.theform.ProductNameListID.remove(0)
			}
			document.theform.ProductNameListID.selectedIndex=-1;
			var rightstr=str.split("$$$");
			var arrayStr=rightstr[0].split("|");
			var i;
			var opt=document.createElement("OPTION");
			opt.text="---Please select the product---";
			opt.value="0";
			document.theform.ProductNameListID.options.add(opt);
			opt.selected=true;
			if(arrayStr.length-1>0)
			{
				for(i=0;i<arrayStr.length-1;i++)
				{
					var arrayName=new Array(1);
					arrayName=arrayStr[i].split("@");
					var opt=document.createElement("OPTION");
					opt.text=arrayName[1];
					opt.value=arrayName[0];
					opt.title=arrayName[1];
					document.theform.ProductNameListID.options.add(opt);
				}
			}
		}
	}
	
}

function getTestTime(TestTime)
{
	
	var str = ReLoadAjax.prototype.LoadUrl2("/ajax/getTestTime.cfm?Time="+TestTime);
}

function cleartext(obj,mmark)
{
	if(obj.value==mmark)
	{
		obj.value='';
	}
}



var ReLoadAjax = function()
{}
ReLoadAjax.prototype.GetHttpRequest = function()
{
	var reObj="";
	if ( window.XMLHttpRequest ){
		reObj= new XMLHttpRequest() ;
	}
	else if ( window.ActiveXObject ){	
		try{
			reObj=new ActiveXObject("MsXml2.XmlHttp") ;
		}
		catch(e){
			reObj=new 	ActiveXObject("microsoft.XmlHttp")
		}
	}
	return reObj;
}

ReLoadAjax.prototype.LoadUrl = function( urlToCall,altDiv,valInput)
{	
	var oReAjax = this ;
	var oAjaxHttp = this.GetHttpRequest() ;
	oAjaxHttp.open( "GET", urlToCall, true) ;
	oAjaxHttp.onreadystatechange=function()
	{
		if(oAjaxHttp.readyState==4)
		{
			document.getElementById(altDiv).innerHTML=oAjaxHttp.responseText;
		}
	}
	oAjaxHttp.send( null ) ;
}
ReLoadAjax.prototype.LoadUrl2 = function(urlToCall)
{	
	var oReAjax = this ;
	var oAjaxHttp = this.GetHttpRequest() ;
	oAjaxHttp.open( "GET", urlToCall, false) ;
	oAjaxHttp.send( null );
	var result=oAjaxHttp.responseText;
	return result;
}
//选产品后的价格
function getTotalPrice(obj){	
	var PriceText = obj.options[obj.selectedIndex].text;
	var start = PriceText.indexOf("(")+1;
	var end = PriceText.indexOf(")");
	var PriceVal = PriceText.substring(start,end);
	var curc = document.getElementById("SelectCurrency").value;		
	document.getElementById("totalprice2").value = PriceVal;//最原始的美元价格
	getRatePrice(curc);
	
	var gid = document.getElementById("GameNameListID").value;
	var sid = document.getElementById("ServerNameListID").value;
	var pid = obj.value;	
	getTagPrice(gid,sid,pid,curc);
	
}
//根据选择货币计算价格
function getRatePrice(curc){	
	var PriceMoney = document.getElementById("totalprice2").value.substring(1,document.getElementById("totalprice2").value.length);
	if(PriceMoney != "" || PriceMoney > 0){
		var RateString = ReLoadAjax.prototype.LoadUrl2("/ajax/getRate.cfm?curc="+curc+"&money="+encodeURIComponent(PriceMoney));//取得货币单位和汇率
		var gid = document.getElementById("GameNameListID").value;
		var sid = document.getElementById("ServerNameListID").value;
		var pid = document.getElementById("ProductNameListID").value;	
		var curc = document.getElementById("SelectCurrency").value;	
		getTagPrice(gid,sid,pid,curc);
	//var RateArray = RateString.split("|");
//	var Rate = RateArray[0];
//	var Symbol = RateArray[1];		
//	var RateResult = parseFloat(Rate) * parseFloat(PriceMoney);
//	document.getElementById("totalprice").value = " "+Symbol+""+formatFloat(RateResult,2);
		document.getElementById("totalprice").value = RateString;
	}else{
		document.getElementById("totalprice").value = "";
	}
}
/*保留n位小数位*/
function formatFloat(src,pos){
	return Math.round(src*Math.pow(10,pos))/Math.pow(10,pos);	
}
//删除前导空白和尾部空白
function removeLeadingAndTrailingWhitespace(inputString) 
{
  if (typeof inputString == "string")
  {
    var firstNonWhite = inputString.search(/\S/);

    if (firstNonWhite != -1)
    {
      for (var i=inputString.length-1; i >= 0; i--)
      {
        if (inputString.charAt(i).search(/\S/) != -1)
        {
          inputString = inputString.substring(firstNonWhite, i+1);
          break;
        }
      }
    }
  }

  return inputString;
}

<!---支付方式控制--->
function getTagPrice(var1,var2,var3,var4){	
	var str=ReAjax.prototype.LoadUrl2("../ajax/getFastorderProductPrice.cfm?gameid="+var1+"&serverid="+var2+"&pid="+var3+"&curc="+var4);	
	if(str != "" || str !="undefined"){
		var arrayPrice = str.split(",");
		for(var i=0 ;i<arrayPrice.length;i++){
			var array2 =  arrayPrice[i].split("@");			
			if(array2[0] == "false"){					
				var id="Pay"+removeLeadingAndTrailingWhitespace(array2[1]);								
				document.getElementById(id).disabled = "disabled";
			}	
			else{
				var id="Pay"+removeLeadingAndTrailingWhitespace(array2[1]);					
				document.getElementById(id).disabled = "";	
				document.getElementById(id).checked = "checked";				
			}	
		}
		var arryB = document.getElementsByName("PayMode");		
		for(var j = 0;j<arryB.length;j++){
			if(arryB[j].disabled == false){
				arryB[j].checked = "checked";
				break;
			}
		}
 		
	}
}	



//end
