// JavaScript Document
function M(Obj)
{
	return document.getElementById(Obj);
}

function check()
{
var wowserver=document.getElementById("interfaceServer").value;
	if(wowserver=="")
	{
	alert("Please select Your WOW-server!");
	return  false;
	}
var quantitys=document.getElementById("interfaceProduct").value;
	if(quantitys=="")
	{
	alert("Your Product Is not empty!");
	return  false;
	}
/*var wowprice=document.getElementById("prices").value;
	if(wowprice=="")
	{
	alert("price Is not empty!");
	return false;
	}*/

var fullname=document.getElementById("tboxFullName").value;
if(fullname=="")
{
alert("Full Name Is not Empty!");
return false;
}
var charname=document.getElementById("tboxCharacterName").value;
if(charname=="")
{
alert("Character Name Is not Empty!");
return false;
}
var  wowemail=document.getElementById("tboxEmail").value;
var zzEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if(wowemail=="")
{
alert("E-mail Is not empty!");
return false;
}
if(!zzEmail.test(wowemail))
{
alert(" Your E-mail is not cerrect!");
return false;
}
var phone1=document.getElementById("phone1").value;
var phone2=document.getElementById("phone2").value;
var phone3=document.getElementById("phone3").value;
var phone4=document.getElementById("tboxCoupon").value;
var pl1=phone1.length;
var pl2=phone2.length;
var pl3=phone3.length;
var pl4=phone4.length;
if(phone4=="" &&(pl1 !=3 || pl2!=3 || pl3!=4))
{
alert("please Type Your phone number! Forexample:***-***-****!");
return false;
}
	if(pl1=="")
	{
		  if(pl1==0 && pl2==0 && pl3==0 && (pl4<5 ||pl4>16))
		   {
			 alert("please Type Your phone number! Forexample:Forexample: ***-*******!");
			 return false;
			}
	}
	var wowcoupon=document.getElementById("coupon").value;
	if(wowcoupon=="")
	{
	alert("coupon Is  not empty!~");
	return false;
	}
}
/*var WSA="http://"+document.location.host+"belrion/belrion/en/wow/wow-inc/wow-server.php";*/

var type;
var xmlHttp=false;
function createXMLHttpRequest()
{//AJAX
	if(window.XMLHttpRequest)
	{
		xmlHttp=new XMLHttpRequest();
	}
	else
	{
		if(window.ActiveXObject)
		{
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Micrsost.XMLHTTP");
				}
				catch(ee)
				{
					xmlHttp=false;
				}
			}
		}
	}
}
//
function LoadOne()
{
    createXMLHttpRequest();
    type="GameList";
    var urlP='../wow-inc/ffxi.php?Action=GameList&n='+Math.random();
	//window.open(urlP);
    xmlHttp.open("GET",urlP,true);
    xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.send(null);
}
function showOne()
{
    var returnxml=xmlHttp.responseText;
	var xmlarray=new Array();
	xmlarray=returnxml.split("BNK(|c");
	var objA=M("interfaceServer");
	objA.options[objA.selectedIndex]=null;
	for(i=0;i<xmlarray.length-1;i++)
	{
		xmlarrayA=xmlarray[i].split("NBJ|=Xdf");
		objA.options[i]=new Option(xmlarrayA[1],xmlarrayA[0]);	
	}saveUserInfo();
}
function saveUserInfo()
{
 var wowid=null;
 var wowid=document.getElementById('interfaceServer');
 wowid=document.form1.interfaceServer.options[document.form1.interfaceServer.selectedIndex].value;
 var urlP='../wow-inc/ffxi.php?Action=GetProduct&id='+wowid;
 //window.open(urlP);
    xmlHttp.open("GET",urlP,true);
    xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.send(null);
	Showprduct();
}

function Showprduct()
{   type="GetProduct";
	var returnxml=xmlHttp.responseText;
	var xmlarray=new Array();
	xmlarray=returnxml.split("HaRT)");
	var objB=M("interfaceProduct");
	objB.options[objB.selectedIndex]=null;
	for(i=0;i<xmlarray.length-1;i++)
	{
		xmlarrayB=xmlarray[i].split("e(Rk=hh");
		objB.options[i]=new Option(xmlarrayB[1],xmlarrayB[0]);	
	}
	GetpriceA();
}
function GetpriceA()
{
 var serverid=null;
 var wowprice=document.getElementById('interfaceProduct');
 //alert(wowprice);
 wowprice=document.form1.interfaceProduct.options[document.form1.interfaceProduct.selectedIndex].value;
 var urlP='../wow-inc/ffxi.php?Action=Getprice&id='+document.getElementById("interfaceServer").value+'&wowqty='+wowprice;
	//window.open(urlP);
    xmlHttp.open("GET",urlP,true);
    xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.send(null);	
	Showsellprice();
}
function Showsellprice()
{
	type="Getprice";
	var returnxmlC=xmlHttp.responseText;
	var xmlarrayC=new Array();
	xmlarrayC=returnxmlC.split("|");
	var objC=M("prices");
	objC.innerHTML=xmlarrayC[0];	
	var d=new Date();
	var getyear=d.getYear();
	var gettime=new Date().getTime();
	var OrderId="2009"+gettime;
   document.getElementById("OrderId").value=OrderId;	 
}

function handleStateChange()
{
	 if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			if(type=="GameList")
			{
             	showOne();				
            }
			else
			{
				if(type=="GetProduct")
				{
					Showprduct();	
				}
				else
				{
					if(type=="Getprice")	
					{
						Showsellprice();
					}
				}
				
			}
		}
	}
}