﻿
function GetConID(ConID)
{
	var theCon ;
	
 	theCon = GetSubConID ( document.body.getElementsByTagName("input") ,ConID ) ;
	if ( theCon != null ) return theCon ;
	
	theCon = GetSubConID ( document.body.getElementsByTagName("select") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("table") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("tbody") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("tr") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("td") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("div") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("a") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("font") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("span") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("strong") ,ConID ) ;
	if ( theCon != null ) return theCon ;

	theCon = GetSubConID ( document.body.getElementsByTagName("label") ,ConID ) ;
	if ( theCon != null ) return theCon ;
	
	theCon = GetSubConID ( document.body.getElementsByTagName("*") ,ConID ) ;
	if ( theCon != null ) return theCon ;
	
	return document.getElementById( ConID ) ;
}

function GetTagConID(TagName ,ConID)
{
	return GetSubConID ( document.body.getElementsByTagName( TagName ) ,ConID ) ;
}

function GetSubConID( ControlArray , ConID )
{
 	for ( var i = 0 ;i< ControlArray.length ;i++)
	{
		var con = ControlArray[i] ;
		if ( con.nodeType == 1 && con.getAttribute("ConID") == ConID )
		{
			 return con ;
		}
	}
	return null; 
}        
        
        function chk(chkboxs,chkbox)
        {
            for(var i=0;i<chkboxs.length;i++)
            {
              chkboxs[i].checked = false;
            }
            
            chkbox.checked = true;
            buytypeChange(chkboxs);
        }
    
    function selectServer(gid,boxObj)
    {
     var sel=GetConID(boxObj);
      selectBoxClear(sel);
       
       for(var i=0;i<gameserver.length;i++)
       {
         if(gameserver[i][1]==gid)
         {
 
            selectBoxAdd(sel,gameserver[i][0],gameserver[i][2]);
            
         }
       }
       sel.options[0].selected=true;
    }  

function frmCheck(isbool)
{
        isbool=false;
       
		with(document.formAffirm)
		{
		
			if (GetConID('txtAccount').value=="")
			{
				 var obj=GetConID('lbAccount'); 
			     obj.innerText="Login ID is required.";
			     obj.style.display="inline";		    
				 GetConID('txtAccount').focus();
				 return isbool=false;
			}
			else
			{
			     var obj=GetConID('lbAccount'); 
			      obj.style.display="none";	
			      			
			}	
			
			if(GetConID('txtAccount').value.length<1)
			{
			    var obj=GetConID('lbAccount'); 
			     obj.innerText="Login ID must longer than 1 characters.";
			     obj.style.display="inline";		    
				 GetConID('txtAccount').focus();
				 return  isbool=false;
			}	
			else
			{
			   var obj=GetConID('lbAccount'); 
			      obj.style.display="none";	 
			    
			}
			
		    if (GetConID('txtAccount').value!=GetConID('txtReAccount').value)
			{
				 var obj=GetConID('lbAccount'); 
			     obj.innerText="Login ID is not consistent.";
			     obj.style.display="inline";	
				GetConID('txtReAccount').focus();
				return isbool=false;
			}
 			else
			{
			     var obj=GetConID('lbAccount'); 
			      obj.style.display="none";	 
			      			
			}	
			
			if (strim(GetConID('ServerList').value)=="")
			{
				 var obj=GetConID('lbselect'); 
			     obj.innerText="Please select server.";
			     obj.style.display="inline";							
				GetConID('ServerList').focus();
				return isbool=false;
			}
 			else
			{
			     var obj=GetConID('lbselect'); 
			      obj.style.display="none";	
			     
			}
			if (strim(txtPws.value)=="")
			{
			     var obj=GetConID('lbPws'); 
			     obj.innerText="Please enter your password.";
			     obj.style.display="inline";
				txtPws.focus();
				return isbool=false;
			}
			else
			{
			     var obj=GetConID('lbPws'); 
			      obj.style.display="none";
			    
			}	
			 if(txtPws.value.length<6){ var obj=GetConID('lbPws'); obj.innerText='Password must longer than 6 characters.';obj.style.display='inline';txtPws.focus();}; 
		    if (strim(GetConID('GameList').value)=="")
		    {
			     var obj=GetConID('lbselect'); 
		         obj.innerText="Please select game.";
		         obj.style.display="inline";								
			    GetConID('GameList').focus();
			    return isbool=false;
		    }
		    else
		    {
		         var obj=GetConID('lbselect'); 
		          obj.style.display="none";
			    		
		    }
		   
			
		     var mytype="" ; 
		   
			if(GetConID('txtAccount').value.length>=1)	
			{
			    // mytype=getAjaxHTML3("/shop/ShopCheckUser.aspx?act=chkName&account="+GetConID('txtAccount').value);
			
			    var ajax1 = GetO();
	            ajax1.open("GET", "/shop/ShopCheckUser.aspx?act=chkName&account="+GetConID('txtAccount').value, false); 
                ajax1.setRequestHeader("Content-Type","text/xml");
	            ajax1.setRequestHeader("Content-Type","utf-8");
	            ajax1.setRequestHeader("pragma","no-cache");
	            ajax1.setRequestHeader("Cache-Control","no-cache, must-revalidate");
	            ajax1.setRequestHeader("If-Modified-Since","0");
	            // Setup a function for the server to run when it's done
	            //ajax1.onreadystatechange = CallBackUrl;

	            // Send the request
	            ajax1.send(null);
	            
                mytype= ajax1.responseText; 
                    
                 if(mytype.length>0)
                 {
                    var obj=GetConID('lbAccount'); 
                    obj.innerText=mytype;
                    obj.style.display="inline";		    
                     GetConID('txtAccount').focus();
                    return isbool=false;
                 }	
                 else
                 {
                       var obj=GetConID('lbAccount'); 
                       obj.style.display="none";
                       
    	           
                 }														   																		           			               
             }
             
             ////////////

             if(txtPws.value.length>=6)
			 {
			    var ajax2 = GetO();
		
	            ajax2.open("GET", "/shop/ShopCheckUser.aspx?act=chkPwd&account="+GetConID('txtPws').value, false); 
                mytype="" ; 
                ajax2.setRequestHeader("Content-Type","text/xml");
	            ajax2.setRequestHeader("Content-Type","utf-8");
	            ajax2.setRequestHeader("pragma","no-cache");
	            ajax2.setRequestHeader("Cache-Control","no-cache, must-revalidate");
	            ajax2.setRequestHeader("If-Modified-Since","0");
	          
                ajax2.send(null);
              
                mytype=ajax2.responseText; 
               
                if(mytype=="0")
                 {  
                     var obj=GetConID('lbPws');  
	                 obj.innerText="Password is not correct.";
	                 obj.style.display="inline";		    
		             return   isbool=false;				     // GetConId("chkPwdName").value="0";
		            
 	             }	
 	             else
 	             {
 	                // window.setTimeout("return true;",1000);
 	              
 	             }
			 }
			 ////////////////////////////
		     var ajax3 = GetO();
             ajax3.open("GET", "/shop/ShopCheckUser.aspx?act=chkCount&account="+GetConID('txtAccount').value, false); 
             mytype="" ; 
             ajax3.setRequestHeader("Content-Type","text/xml");
	         ajax3.setRequestHeader("Content-Type","utf-8");
	         ajax3.setRequestHeader("pragma","no-cache");
	         ajax3.setRequestHeader("Cache-Control","no-cache, must-revalidate");
	         ajax3.setRequestHeader("If-Modified-Since","0");
	          
             ajax3.send(null);
              
             mytype=ajax3.responseText; 
             if(mytype.length>0)
             {  
                 var obj=GetConID('lbAccount');  
                 obj.innerText=ajax3.responseText; 
                 obj.style.display="inline";		    
	             //txtPws.focus();
	            return isbool=false;				     // GetConId("chkPwdName").value="0";
             }	
             else
             {
              //  window.setTimeout("return true;",1000);
             }
     	        
             
		   	////////////////////////////////	
            return true;
			 
	    }
}
