var files = 'select.aspx?time=' + Ajax.getDatetime() + '&';
var files4 = '/admin/getgame_new.asp?time=' + Ajax.getDatetime() + '&';

var filepost = 'Append.asp?time=' + Ajax.getDatetime() + '&';
var sResult = "";

function fucCheckNUM(NUM)
{
	var i,j,strTemp;
	strTemp="0123456789.";
	if ( NUM.length== 0)
		return 0
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1)
		{
			return 0;
		}
	}
	return 1;
	
}
var Areas =
{
	 getgame : function()
   {
	   Areas.appendOption("server", "");
	   Areas.appendOption("gettype1", "");
	   Areas.appendOption("get3", "");
	   Areas.appendOption("get4", "");
	   Areas.appendOption("getchar", "");
      $("rgame").value = "";
      var strurl = files4 + "s=1";
      new Ajax.Request(strurl,
			  {
				 method : 'get',
				 onSuccess : function(sResult)
				 {
					if(Areas.appendOption("game", sResult.responseText))
					{
						// alert($("gameID").value); // null  && typeof($("gameID") != "undefined"//alert($("game").options.length);	
						if ($("gameID") != null )		 
						{
 							var gameID= $("gameID").value;
 							for(var i=0;i<$("game").options.length;i++) {
								
								 if(parseInt($("game").options[i].value)==parseInt(gameID))     //firefox需要 [i]
								 {   
									  $("game").selectedIndex = i ;
									 
								 } 
								 
							}
						
							$("rgame").value =gameID;
						//$("rserver").value = $("server").options[$("server").selectedIndex].value;  document.getElementById("gameID").value
					 //   $("rget3").value = $("get3").options[$("get3").selectedIndex].value; 
					    //$("rget4").value = $("get4").options[$("get4").selectedIndex].value; 
							
						} 	
					   Areas.getserver();
					   Areas.gettype1();
					  Areas.getchar();
					   Areas.get3();
					   //alert($("rget4").value);
					   //game cancel > server cancel ;   get3 cancel > get4 cancel					  
					}
					sResult = null;
				 }
			  }
      );
	  //$("rget4").value = "";
	  // $("rget3").value = "";
   }
   ,
   getserver : function()
   {
	$("rgame").value = $("game").options[$("game").selectedIndex].value;
      var o = $("game").options[$("game").selectedIndex].value;
	
      if(o == "")  //Game Select
      {
			Areas.appendOption("server", "");//显示没有项目的表头
			Areas.appendOption("get3", "");
			Areas.appendOption("get4", "");
		 $("rget4").value = "";		//消除hidden 的值
		 $("rget3").value = "";
      }
      else
      {
         var strurl = files4 + "s=4&o=" + escape(o);
         new Ajax.Request(strurl,
				 {
						method : 'get',
						onSuccess : function(sResult)
						{
							if(Areas.appendOption("server", sResult.responseText)){
								if ($("serverID") != null)
								{ 
									var serverID= $("serverID").value;
									for(var i=0;i<$("server").options.length;i++) {
										 if($("server").options[i].value==serverID)   
										 {   
											  $("server").selectedIndex = i ; 
										 } 
									}
									$("rserver").value =serverID;
									//alert(serverID);
								}
								//Areas.getnext();
							}
							
							sResult = null;
						}
				 }
         );
      } 
	    $("rserver").value = $("server").options[$("server").selectedIndex].value;
		
   }
     ,
   gettype1 : function()
   {
		$("rgame").value = $("game").options[$("game").selectedIndex].value;
      var o = $("game").options[$("game").selectedIndex].value;
      if(o == "Game Select")
      {
		Areas.appendOption("type1", "");
      }
      else
      {
         var strurl = files4 + "s=20&o=" + escape(o);
         new Ajax.Request(strurl,
				 {
						method : 'get',
						onSuccess : function(sResult)
						{
							if(Areas.appendOption("type1", sResult.responseText)){
								if ($("type1ID") != null)
								{ 
									var type1ID= $("type1ID").value;
									for(var i=0;i<$("type1").options.length;i++) {
										 if($("type1").options[i].value==type1ID)   
										 {   
											  $("type1").selectedIndex = i ; 
										 } 
									}
									$("rtype1").value =type1ID;
								}
							}
							sResult = null;
						}
				 }
         );
      } 
   }
    ,
   gettype1next : function()
   {
	$("rtype1").value = $("type1").options[$("type1").selectedIndex].value;
   }
     ,
   getchar : function()
   {
		$("rgame").value = $("game").options[$("game").selectedIndex].value;
      var o = $("game").options[$("game").selectedIndex].value;
      if(o == "Game Select")
      {
		Areas.appendOption("char", "");
      }
      else
      {
         var strurl = files4 + "s=19&o=" + escape(o);
         new Ajax.Request(strurl,
				 {
						method : 'get',
						onSuccess : function(sResult)
						{
							if(Areas.appendOption("char", sResult.responseText)){
								if ($("charID") != null)
								{ 
									var charID= $("charID").value;
									for(var i=0;i<$("char").options.length;i++) {
										 if($("char").options[i].value==charID)   
										 {   
											  $("char").selectedIndex = i ; 
										 } 
									}
									$("rchar").value =charID;
								}
							}
							sResult = null;
						}
				 }
         );
      } 
   }
    ,
   getcharnext : function()
   {
	$("rchar").value = $("char").options[$("char").selectedIndex].value;
   }
    ,
   get3 : function()
   {
	 $("rgame").value = $("game").options[$("game").selectedIndex].value;
      var o = $("game").options[$("game").selectedIndex].value;
	   // $("rget4").value = $("get4").options[$("get4").selectedIndex].value;
      if(o == "")  //Game Select
      {
         Areas.appendOption("get3", "");
		 // $("rget4").value = "";
      }
      else
      {
         var strurl = files4 + "s=8&o=" + escape(o);
         new Ajax.Request(strurl,
         {
            method : 'get',
            onSuccess : function(sResult)
            {
				if(Areas.appendOption("get3", sResult.responseText)){
					if ($("get3ID") != null)
					{ 
						var get3ID= $("get3ID").value;
						for(var i=0;i<$("get3").options.length;i++) {
							 if($("get3").options[i].value==get3ID)   
							 {   
								  $("get3").selectedIndex = i ; 
							 } 
						}
						$("rget3").value =get3ID;
					}
					Areas.get4();
				}
               sResult = null;
            }
         }
         );
      } 
	 
   }
    ,
   get4 : function()
   {
	$("rget3").value = $("get3").options[$("get3").selectedIndex].value;
      var o = $("get3").options[$("get3").selectedIndex].value;
      if(o == "")//All Select
      {
         Areas.appendOption("get4", "");
		 
      }
      else
      {
         var strurl = files4 + "s=9&o=" + escape(o);
         new Ajax.Request(strurl,
         {
            method : 'get',
            onSuccess : function(sResult)
            {
				if(Areas.appendOption("get4", sResult.responseText)){
					if ($("get4ID") != null)
					{ 
						var get4ID= $("get4ID").value;
						for(var i=0;i<$("get4").options.length;i++) {
							 if($("get4").options[i].value==get4ID)   
							 {   
								  $("get4").selectedIndex = i ; 
							 } 
						}
						$("rget4").value =get4ID;   
					}
					Areas.getnext4();//消除hidden 的值************
				}
               sResult = null;
            }
         }
         );
      } 
   }
    ,
   getnext4 : function()
   {
	$("rget4").value = $("get4").options[$("get4").selectedIndex].value;
   }
   ,
   getnext : function()
   {
	$("rserver").value = $("server").options[$("server").selectedIndex].value;
   }
   ,
   appendOption : function(sId, Value)
   {
      try
      {
         var temps = "";
         $(sId).options.length = 0
         switch(sId)
         {
            case "game" :
            temps = "Game Select";
            break;
            case "server" :
            temps = "Server Select";
			break;
			case "get3" :
            temps = "All Select";
			break;
			case "get4" :
            temps = "All Select";
            break;
			case "type1" :
			 temps = "Rarity Select";
            break;
			case "char" :
			 temps = "Character Select";
            break;
         }
		 // $(sId).options.add(new Option("dd", ""));
         $(sId).options.add(new Option(temps, ""));
		 
         if(sId == "server")
         {
            var o = $("game").options[$("game").selectedIndex].value;
         }
		 itemp = 0;
		 var   t   =   Value.indexOf("|");   
		if (t!= -1)
		{	var sValues = Value.split('|');
			//var rgame = document.getElementById("rgame").value;
			for(var i = itemp+1; i < sValues.length ; i ++ )
			 {
				 $(sId).options.add(new Option(sValues[i].split(',')[1], sValues[i].split(',')[0]));
			 }
		}
      }
      catch(e)
      {
         return false;
         // alert(e.description);
      }
      return true;
   }
}
;
