//XMLHttpRequest
var xmlHttp;
if (parseInt(navigator.appVersion.charAt(0))>=4){ 
var isNN=(navigator.appName=='Netscape')?1:0; 
var isIE=(navigator.appName.indexOf('Microsoft')!=-1)?1:0; 
} 
if (isNN) 
{
     function CalculatePrice(obj)
    {
      toFormant(obj);
      var text = obj.value;  
	  var ServerName=document.getElementById("ServerNameID").value;
	  var currencyRe=document.getElementById("currencyRID").value;
      text = text.replace(',','');
	  var url="FreeAmount.asp?ServerName=" + ServerName + "&CurrencyR=" + currencyRe + "&FreeAmount=" + text;
      retCode=openUrl(url);
      
      retCode = retCode.substring(retCode.indexOf('^'),retCode.Length-retCode.indexOf('^'));
      
       document.getElementById("CalculateResultID").value = retCode;
          
    }
}

if (isIE) 
{
 
    function CalculatePrice(obj)
    {
      toFormant(obj);
      var text = obj.value; 
	  var ServerName=document.getElementById("ServerNameID").value;
	  var currencyRe=document.getElementById("CurrencyRID").value;
	  text = text.replace(',','');
      
      var url="FreeAmount.asp?ServerName=" + ServerName + "&CurrencyR=" + currencyRe + "&FreeAmount=" + text;
	  retCode=openUrl(url);
      retCode = retCode.substring(retCode.indexOf('^'),retCode.Length-retCode.indexOf('^'));
      document.getElementById("CalculateResultID").value = retCode;               
    }
}






function   openUrl(url)
   {  
        if   (window.XMLHttpRequest)  
        {   
                objxml   =   new   XMLHttpRequest();
        }  
         else   if   (window.ActiveXObject)  
        {   
                objxml   =   new   ActiveXObject("Msxml2.XMLHTTP");
        }   
        
        objxml.open("GET",url,false);
        
        objxml.send(""); 
        retInfo=objxml.responseText;
        if   (objxml.status== "200 ")
        { 
		   return   retInfo;
		   
        }  
        else
        { 
		   return   "";
		   
        }  
    }  
    
    
 function toFormant(obj)
    {
        
        var numstr = obj.value;
            
        var num =numstr.replace(/,| /g,"");
        if(num.length>1)
        {
            num = num.replace(/\b[0*]/g,"");
        }
		if(!num.match(/[^0-9]/g))
        {
            var a = new Array();
            if(num.length>3)
            {
                for(i=num.length;i>0;i=i-3)
                {
                    a.push(num.substring(i-3,i));
                }
                //obj.value=a.reverse().join(",");
            }
            else
            {
                obj.value = num.replace(/,/g,"");
            }
        }
        else
        {
          alert("Please enter integer");
	      obj.value="";
        }
    }
    
    function CheckFreeNull()
    { 
        var t = document.getElementById("FreeOptionAmountID");
        var p = document.getElementById("CalculateResultID");
		var n = document.getElementById("charFreename");
      
        if(t.value=='')
        {
            alert('Please Fill in Quantity');
            return false;
        }
        if(t.value < 5)
        {
            alert('The Minimum is 5M');
			t.value = "";
			p.value = "";
            return false;
        }
		if(p.value.length==0)
        {
            alert('Please Retype Amount');
            return false;
        }
		if(n.value.length==0)
        {
            alert('Please fill in the name in game');
            return false;
        }
    }
    function CheckNameNull()
    { 
		var n = document.getElementById("charename");

		if(n.value.length==0)
        {
            alert('Please fill in the name in game');
            return false;
        }
    }