var WS="http://"+document.location.host+"/DCCreate/get.php";

//var WS="http://localhost/wowgold800/get.php"
var Cs=function(/* string */v){
  /* summary: Load xml to set servers options
   * init:an initializer order number,_lg:an initializer function to set servers.options.length=0;
   * description:load the server_id xml to set $server options;        
  */
  var addZero=function(n){if(n.length!=2&&((n-0)<10)){return '0'+n}else{return n}}
  var d=new Date();
  $("OrderId").value=""+d.getFullYear()+addZero(d.getMonth()+1)+addZero(d.getDate())+addZero(d.getHours())+addZero(d.getMinutes())+addZero(d.getSeconds())+addZero(d.getMilliseconds()); //e.g. 20089231222135994472
  // The _lg onRequest event headler of XHR for init the servers options
  var _lg=function(){
      /* summary: initialization function
       * init: Remove all options by setting the Options array's length to 0 and insert new Option('Loading') into servers
      */
      $('servers').options.length=0;
      $('servers').options.add(new Option('Loading Game Server'))
      }
      //set the selected option text in the games to be the value of input id attribute called 'gamename'  
	    $('gamename').value=$('games').options[$('games').selectedIndex].text;
      // The _lge onSuccess event headler of XHR  for set the serveres options
  var _lge=function(/* string*/ txt,/* XMLDocument */ xml){
      /* summary: 
       * init: remove Loading Game Server option;
       * description: set server options in select all element server in the XML document; 
      */
       $('servers').options.length=0; 
       var servers=xml.selectNodes('//server'); // set servers select all elements server in the XML document ;
       for(var i=0,ss=[];s=servers[i];i++){
       ss.push('<option value="'+s.getAttribute('code')+'">'+(s.lastChild.text||s.lastChild.textContent)+'</option>');
       }
       $('servers').parentNode.innerHTML='<select id="servers" onchange="Cq(value)" name="servercode" style="width:167px;">'+ss.join("")+'</select>';
       //Set the sv variable to be the value of the servers attribute     
       var sv=$("servers").value;
       $('server_id').value=sv.split(",").pop(); //returns the last element of split sv variable;  
       //call Cq(sv);   
       Cq(sv);
      }
      // create a new object instance of the XMLHttpRequest(XHR) object
      // register _lge callback function 
      var xhr=new XHR({method:'get',onRequest:_lg,onSuccess:_lge,ansyc:false})
      //do the send request
	  //alert(WS+"?action=server&code="+v);
	  //window.open(WS+"?action=server&code="+v);
      xhr.send(WS+"?action=server&code="+v);
}

var Cq=function(v){
  
  var _lg=function(){
     /* summary: initialization function
       * init: Remove all options by setting the Options array's length to 0 and insert new Option('Loading') into quantitys
      */
     $('quantitys').options.length=0;
     $('quantitys').options.add(new Option('Loading'))
   }
   //set the selected option text in the servers to be the value of the servername 
   $("servername").value=$('servers').options[$('servers').selectedIndex].text;
   //set the last split the value of servers to be the value of the server_id; 
   $('server_id').value=$("servers").value.split(",").pop();
  
  var _lge=function(/*string*/txt,/*XMLDocument*/xml){
     /* summary: 
       * init: remove Loading quantitys Server option;
       * description: set server options in select all element price in the XML document; 
       * list all products prices       
      */
     $('quantitys').options.length=0;
     var prices=xml.selectNodes('//price');
     var _tfoot,newRow,leftCell,rightCell,ops=[];
     var obj=$('objDiscount');
     for(var i=0;p=prices[i];i++){
        if(i==0)
        $("unit_price").value=p.getAttribute('unit_price');
        if(obj){
         if(i==0){
          obj.deleteTFoot();
          _tfoot =obj.createTFoot();        
         }
         newRow=_tfoot.insertRow(-1);
         leftCell=newRow.insertCell(-1);
         leftCell.innerHTML=p.getAttribute('num');
         rightCell=newRow.insertCell(-1);
         rightCell.innerHTML=(p.lastChild.text||p.lastChild.textContent);
        }
        ops.push('<option value="'+(p.lastChild.text||p.lastChild.textContent)+';'+p.getAttribute('guid')+'" discount="'+p.getAttribute('number')+'">'+p.getAttribute('qt')+'</option>');
     }
     $('quantitys').parentNode.innerHTML='<select id="quantitys" onchange="Cp(value)" name="quantitys" style="width:167px;">'+ops.join("")+'</select>'
     // call Cp() e.g. Cp(500.33) 
     Cp($('quantitys').value)
   }
  var xhr=new XHR({method:'get',onRequest:_lg,onSuccess:_lge,ansyc:false});
  //do send request
  xhr.send(WS+"?action=price&code="+v);
}

var Cp=function(/*currency*/v){
  /* summary: set prices,discount,trade_num,item value;
   */   
  var quantitys;
    var value =new Array();
  value = v.split(';');
  $('prices').value='$ '+(Math.round((value[0]*100)))/100;
  $('unit_price').value=(Math.round((value[0]*100)))/100; 
  quantitys=$('quantitys').options[$('quantitys').selectedIndex];
 

  $('discount').value=quantitys.getAttribute('discount');
  $('trade_num').value=quantitys.getAttribute('discount');
  $('item').value=quantitys.text;
  $('guid').value=value[1];
}


window.addEvent('domready', function(){
   $('country').value=navigator.browserLanguage||navigator.language;
   var _lg=function(){
    $('games').options.length=0;
    $('games').options.add(new Option('Loading Game...',''));
   }
   var _lge=function(txt,xml){
   $('games').options.length=0;
   var games=xml.selectNodes('//game');
   for(var i=0,gs=[];g=games[i];i++){
        gs.push('<option value="'+g.getAttribute('code')+'">'+(g.text||g.textContent)+'</option>');
   }
   $('games').parentNode.innerHTML='<select id="games" onchange="Cs(value)" name="game_id" style="width:167px;">'+gs.join("")+'</select>';
   $('gamename').value=$('games').options[$('games').selectedIndex].text;
   // Call Cs function ; e.g. Cs(100)
   Cs($('games').value);

   }
   var a=new XHR({method:'get',onRequest:_lg,onSuccess:_lge,ansyc:false})
   a.send(WS+"?action=game&code=013")
});


  function checkpost(f)
  {
   if(f.game_id.value==""){
	   alert('Please Select Game');
	   return false;
	  }
   if(f.servercode.value==""){
	  alert('Please Select Game Server');
	  return false;
  	}
   if(f.quantitys.value==""){
    alert('Please Select quantity');
	  return false;
   }
   if(f.amount.value==""||f.amount.value==0||f.amount.value=="undefined"){
	  alert('Please select Quantity');
	  return false;
	 }
	 if(f.customer_full_name.value=="")
	 {
		 alert('Please input Full Name');
		 f.customer_full_name.focus();
		 return false;
	 }
	 if(f.character_to.value=="")
	 {
		 alert("Please input character Name!");
		 f.character_to.focus();
	 	return false;
	 }
 	 if(f.character_to.value!=f.charname1.value){
	  alert('Please input confirm character name!');
	  f.charname1.focus();
	  return false;
	 }

	 if(f.customer_email.value==""){
	  alert('Please Type Email');
    f.customer_email.focus()
	  return false;
	 }

   var emailv=f.customer_email.value;
   var zzEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   if(!zzEmail.test(emailv))
   {
    alert("Please Type Email");
    f.customer_email.focus();
    return false;
    }
   if(f.customer_phone1.value=="")
   {
	  alert('Please input phone number');
   	  f.customer_phone1.focus();
	  return false;
	}
  }
  
  function getpowerlevel(){
  var s=document.getElementById('start_level').value;
  var e=document.getElementById('end_level').value;
  var g=document.getElementById('game_code').value;
  $('btn_level').disabled=true;
  var getContent=function(a,b)
   {
     /*
     eval(obj.responseText);
	 document.getElementById('level_price').value=((document.getElementById('level_price').value-0)*0.95).toFixed(2)
    */

    var result=a.replace(/<.*?>/i,'').match(/[\d\.]+/g);
   
	$('level_time').value=result[1]+'-'+result[2];
    $('needtime').value=result[2];

	$('level_price').value=((result[0]-0)*0.95).toFixed(2)

    var game=document.getElementById('game_code');
    var gamename=game.options[game.options.selectedIndex].text;

    $('itemname').value=gamename+' powerleveling '+s+'-'+e+'';
	 $('btn_level').disabled=false;

   }
 new Ajax('pl.php?action=calc&game='+g+'&s='+s+'&e='+e,{method:'get',onSuccess:getContent}).request();

}
/*************************************************************************************************/
  <!--
  // check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
   // prototying the XMLDocument
   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
   {
      if( !xNode ) { xNode = this; }
      var oNSResolver = this.createNSResolver(this.documentElement)
      var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
      var aResult = [];
      for( var i = 0; i < aItems.snapshotLength; i++)
      {
         aResult[i] =  aItems.snapshotItem(i);
      }
      return aResult;
   }

   // prototying the Element
   Element.prototype.selectNodes = function(cXPathString)
   {
      if(this.ownerDocument.selectNodes)
      {
         return this.ownerDocument.selectNodes(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }

   // prototying the XMLDocument
   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
   {
      if( !xNode ) { xNode = this; }
      var xItems = this.selectNodes(cXPathString, xNode);
      if( xItems.length > 0 )
      {
         return xItems[0];
      }
      else
      {
         return null;
      }
   }

   // prototying the Element
   Element.prototype.selectSingleNode = function(cXPathString)
   {
      if(this.ownerDocument.selectSingleNode)
      {
         return this.ownerDocument.selectSingleNode(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }

}


 var PL=new Class({
     initialize: function(options){
       this.setOptions(options);
     }
	 ,
     getpl:function(){
	 $('task').innerHTML='';
	 $('task').innerHTML='Please wait a bit';
	 var s=this.options.s.value,e=this.options.e.value,g=this.options.g.value;
      var getContent=function(a,b){

		var result=b.selectSingleNode("//level")
		var price=result.getAttribute("price");
		var time=result.getAttribute("time");
        var gamename=$('games1').options[$('games1').selectedIndex].text;
		$('level_time').value=time
		//$('need_time').value=time; 
		$('need_price').value=((price-0)).toFixed(2)
	    $('needprice').value=((price-0)).toFixed(2)
		$('task').innerHTML='';
		$('task').innerHTML=$('games1').options[$('games1').selectedIndex].text;
		$('itemname').value=gamename+' power leveling '+s+'-'+e+'';
     }

      new Ajax('/pl.php?game='+g+'&s='+s+'&e='+e,{method:'get',onSuccess:getContent}).request();
	 },

	 getlevel:function(){
	  $('task').innerHTML='';
	  $('task').innerHTML='Please wait a bit';
        var s=this.options.s,e=this.options.e,g=this.options.g;
		var me=this;
    var fun=function(a,b){;
	    var pl=b.selectSingleNode("//Level")
       if(pl!=null){
		var minPl=pl.getAttribute("Start")
        var startPl=pl.getAttribute("PLStart")
        var maxPl=pl.getAttribute("End")
		maxPl = parseInt(maxPl);
        s.options.length=0;
		for(var i=minPl;i<=maxPl;i++){
		  s.options.add(new Option(i,i))
		}
		e.options.length=0;
        for(var k=startPl;k<=maxPl;k++){
		  e.options.add(new Option(k,k))
		}
		 
		$('task').innerHTML='';
		$('task').innerHTML=$('games1').options[$('games1').selectedIndex].text;
        me.getpl();

		}else{
		alert('The mmo not offer power leveling');
		$('task').innerHTML='';
		$('task').innerHTML=$('games1').options[$('games1').selectedIndex].text;
		}
	   }
	  new Ajax('/pll.php?action=level&game='+g.value,{method:'get',onSuccess:fun}).request();
	 }
	 ,
	 postpl:function(){
	if($('need_price').value<0||$('need_time').value<1){
	 alert('Please Choose desired level')
	 return false;
	}else{
	  $('plform').submit();
	}
	}
}
 )
 PL.implement(new Options);
window.addEvent('domready',function(){ 
 if($('games1')){ 
 pl=new PL({s:$('currentlevel'),e:$('desiredlevel'),g:$('games1')});
 $('games1').addEvent('change',function(){pl.getlevel();})
 $('currentlevel').addEvent('change',function(){ pl.getpl();})
 $('desiredlevel').addEvent('change',function(){ pl.getpl();})
 $('desiredlevel').value=$('desiredlevel').options[$('desiredlevel').options.length-1].text;
 $('desiredlevel').fireEvent('change');
 $$('a.buyn').addEvent('click',function(event){var e=new Event(event);e.preventDefault();pl.postpl();})
 }

})
//-->