
//检测参数设置
function ValidateNum(item,type,str)

{

	var returnVal = 0;

	//var maxVal    = 0xFFFFFFFF;

  var intVal;   

  var strVal = new String(item.val());

  var ch;

  var i;

  var j;

		  			
	if(type == "IP_ADDR")

	{

		ipaddr = strVal.split(".");

		if(ipaddr.length != 4)

		{

			alert("Please input valid "+str+" address!");

			item.focus();

			return false;

		}

		

		for(j = 0; j < 4; j++)

		{

			strVal = ipaddr[j];

			for ( i = 0 ; i < strVal.length ; i++ )

			{      

				ch = strVal.charAt(i);

				if(ch < '0' || ch > '9')

				{

					alert("Please input valid  "+str+"  address!");

					item.focus();

					return false;

				}

			}

			if(strVal=="")

			{

				alert("Please input valid  "+str+"  address!");

				item.focus();

				return false; 

			}

			intVal= parseInt(strVal, 10);

			if(intVal > 255)

			{

				alert("Please input valid  "+str+"  address!");

				item.focus();

				return false; 

			}

		}

	

	}
	else if(type == "GBEMAC")
	{
		
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9'&& ch < 'A' || ch > 'F' && ch < 'a' || ch > 'f')
			{
				alert("Please enter a legal hexadecimal number");
				item.focus();
	      return false; 
			}
		}
	}
	else if(type == "PID")
	{
          if(strVal=="")
		   {

			alert("Please input"+str);

			item.focus();

			return false; 

		   }

		for ( i = 0 ; i < strVal.length ; i++ )

		{      

			ch = strVal.charAt(i);

 			if(ch < '0' || ch > '9'&& ch < 'A' || ch > 'F' && ch < 'a' || ch > 'f')

			{

				alert(str+"Please input valid hexadecimal number!");

				item.focus();

	                          return false;

			}

		}

		intVal = 0;

		for ( i = 0 ; i < strVal.length ; i++ )

		{      

			ch = strVal.charAt(i);

			if ((ch >= '0') && (ch <= '9'))

			{		

				intVal *= 16;

				intVal += (ch - '0');

			}

			else if ((ch >= 'a') && (ch <= 'f'))

			{

				intVal *= 16;

				if(ch=='a')

				intVal += 10;

				if(ch=='b')

				intVal += 11;

				if(ch=='c')

				intVal += 12;

				if(ch=='d')

				intVal += 13;

				if(ch=='e')

				intVal += 14;

				if(ch=='f')

				intVal += 15;

			}

			else

			{

				intVal *= 16;

				if(ch=='A')

				intVal += 10;

				if(ch=='B')

				intVal += 11;

				if(ch=='C')

				intVal += 12;

				if(ch=='D')

				intVal += 13;

				if(ch=='E')

				intVal += 14;

				if(ch=='F')

				intVal += 15;

			}

		}

		if(intVal > 8191)

		{

				alert(str+"must be between 0 and 0x1FFF!");

				item.focus();

				return false; 

		}

         

	}
	else if(type == "TTL")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 255)
			{
				alert("TTL Value must be between 0 ~ 255");
				item.focus();
				return false; 
			}
		
	}
	else if(type == "GOPSIZE")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legitimate integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 30 || intVal <4)
			{
				alert("GOP length must be between 4 ~ 30");
				item.focus();
				return false; 
			}
		
	}
	else if(type == "FREQ")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		
	}
	else if(type == "PORT")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal < 1234)
			{
				alert("Port Value must be higher Than 1233");
				item.focus();
				return false; 
			}
		
	}
	else if(type == "ENCDELAY")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 1000 || intVal <0)
			{
				alert("AC3 encoding delay time must be between 0 ~ 1000");
				item.focus();
				return false; 
			}
		
	}
	else if(type == "VIDEOVAL")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 255 || intVal <0)
			{
				alert("Video parameter must be between 0 ~ 255");
				item.focus();
				return false; 
			}
		
	}
	else if(type == "PROGRAMNO")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9'&& ch < 'A' || ch > 'F' && ch < 'a' || ch > 'f')
			{
				alert("Please enter a legal hexadecimal number");
				item.focus();
	      return false; 
			}
		}
		intVal = 0;
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
			if ((ch >= '0') && (ch <= '9'))
			{		
				intVal *= 16;
				intVal += (ch - '0');
			}
			else if ((ch >= 'a') && (ch <= 'f'))
			{
				intVal *= 16;
				if(ch=='a')
				intVal += 10;
				if(ch=='b')
				intVal += 11;
				if(ch=='c')
				intVal += 12;
				if(ch=='d')
				intVal += 13;
				if(ch=='e')
				intVal += 14;
				if(ch=='f')
				intVal += 15;
			}
			else
			{
				intVal *= 16;
				if(ch=='A')
				intVal += 10;
				if(ch=='B')
				intVal += 11;
				if(ch=='C')
				intVal += 12;
				if(ch=='D')
				intVal += 13;
				if(ch=='E')
				intVal += 14;
				if(ch=='F')
				intVal += 15;
			}
		}
		if(intVal > 8191 || intVal < 0)
		{
				alert("No. programs must be between 0 ~ 8191");
				item.focus();
				return false; 
		}
	}
	else if(type == "RFRATE")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 200000000)
			{
				alert("RFrate Value Must Be Lower Than 200000000bps");
				item.focus();
				return false; 
			}
		
		
	}
	else if(type == "BITRATE")
	{
        if(strVal=="")
		   {
			alert("Please input"+str);
			item.focus();
			return false; 
		   }
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert(str+"Please input valid decimal number!");
				item.focus();
	       		return false;
			}
		}
		intVal= parseInt(item.val(),10);
		if((intVal < 0)||(intVal > 213000000))
			{
				alert(str+" must be between 0 and 213000000bps!");
				item.focus();
				return false;
			}	
	}
	else if(type == "PIDBITRATE")
	{
        if(strVal=="")
		   {
			alert("Please input"+str);
			item.focus();
			return false; 
		   }
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert(str+"Please input valid decimal number!");
				item.focus();
	       		return false;
			}
		}
		intVal= parseInt(item.val(),10);
		if((intVal < 0)||(intVal > 200000000))
			{
				alert(str+" must be between 0 and 200000000bps!");
				item.focus();
				return false;
			}	
	}
	else if(type == "BACKUPTIME")
	{
		if(strVal=="")
		   {
			alert("Please input"+str);
			item.focus();
			return false; 
		   }
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert(str+"Please input valid decimal number!");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.val(),10);
		if((intVal < 0)||(intVal > 65))
			{
				alert(str+" must be between 0 and 65!");
				item.focus();
				return false;
			}	
	}
	else if(type == "CHPID")
	{
		for ( i = 0 ; i < strVal.length ; i++ )
		{      
			ch = strVal.charAt(i);
 			if(ch < '0' || ch > '9')
			{
				alert("Please enter a legal integer");
				item.focus();
	       		return false; 
			}
		}
		intVal= parseInt(item.value,10);
		if(intVal > 8191)
			{
				alert("PID must be between 0 ~ 8191");
				item.focus();
				return false; 
			}
		
	}

	return true;
}

function ChgMenu(tablemenu,Num) 
{ 
		hiddenform=top.frames[0].document.hiddenform;
	if (tablemenu.style.display == "none") 
	{
		tablemenu.style.display = ""; 
		if(Num == 0)
			hiddenform.TableStyle0.value = "1";
		else if(Num == 1)
			hiddenform.TableStyle1.value = "1";
	}
	else 
	{
		tablemenu.style.display = "none"; 
		if(Num == 0)
			hiddenform.TableStyle0.value = "0";
		else if(Num == 1)
			hiddenform.TableStyle1.value = "0";
		//if(hiddenform.TableStyle6.value >= 2*Num && hiddenform.TableStyle6.value <= 2*Num-1)
		  //SysSet.color= #CA00CA;
	}
}



function confirm_reset()
{
	 var iWidth=500; //窗口宽度
     var iHeight=400;//窗口高度
     var iTop=(window.screen.height-iHeight)/2;
     var iLeft=(window.screen.width-iWidth)/2;
	var ret=confirm("确定要重启系统吗？");
	if(ret==true){
		window.open("reset.asp","消息","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
		document.form2.submit();
	}
}

function confirm_resetEN()
{
	 var iWidth=500; //窗口宽度
     var iHeight=400;//窗口高度
     var iTop=(window.screen.height-iHeight)/2;
     var iLeft=(window.screen.width-iWidth)/2;
	var ret=confirm("Confirm that you want to reboot the system?");
	if(ret==true){
		window.open("reset.asp","message","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
		document.form2.submit();
	}
}

function confirm_defalt()
{
	 var iWidth=500; //窗口宽度
     var iHeight=400;//窗口高度
     var iTop=(window.screen.height-iHeight)/2;
     var iLeft=(window.screen.width-iWidth)/2;
	var ret=confirm("确定要恢复默认参数吗？");
	if(ret==true){
		window.open("defalt.asp","消息","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
		document.form3.submit();
	}
}

function confirm_defaltEN()
{
	 var iWidth=500; //窗口宽度
     var iHeight=400;//窗口高度
     var iTop=(window.screen.height-iHeight)/2;
     var iLeft=(window.screen.width-iWidth)/2;
	var ret=confirm("Confirm that you want to restore the factory parameter?");
	if(ret==true){
		window.open("defalt.asp","message","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
		document.form3.submit();
	}
}

function sysalarm(slot)
{
    var iWidth=500; //窗口宽度
    var iHeight=400;//窗口高度
    var iTop=(window.screen.height-iHeight)/2;
    var iLeft=(window.screen.width-iWidth)/2;
    window.open("alarmSlot.asp?slotno="+slot,"_blank","Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
      
}
