// JavaScript Document
/*parameter description:item:current param; type:param type;language:current page language*/
function ValidateParam(item,type,startvalue,endvalue,str,language)
{
	var returnVal = 0;
	var intVal;
	var strVal = new String(item.val());
	var ch;
	var i;
	var j;
	switch(type) {
		/*  valid integer */
		case "VALI_INTEGER":
			if(strVal=="")
			{
				if(language == 1)
				{
					alert("请输入"+str);
				}
				else
				{
					alert("Please input"+str);
				}
				item.focus();
				return false; 
			}
			for ( i = 0 ; i < strVal.length ; i++ )
			{      
				ch = strVal.charAt(i);
				if(ch < '0' || ch > '9')
				{
					if(language == 1)
					{
						alert(str+"请输入合法的十进制数!");
					}
					else
					{
						alert(str+"Please input valid decimal integer!");
					}
					item.focus();
					return false;
				}
			}
			intVal= parseInt(item.val(),10);
			if((intVal < startvalue)||(intVal > endvalue))
			{
				if(language == 1)
				{
					alert(str+"必须在"+ startvalue + "和" + endvalue +"之间!");
				}
				else
				{
					alert(str+"must be between "+ startvalue + " and " + endvalue +"!");
				}
				item.focus();
				return false;
			}
			break;
		/* compatible data  ..apply to PID or ProgramNo */
		case "VALI_COM_DATA":
			if(strVal=="")//cann't be empty
			{
				if(language == 1)
				{
					alert("请输入"+str);
				}
				else
				{
					alert("Please input"+str);
				}
				item.focus();
				return false; 
			}
			if(strVal.length == 1)//only one number
			{
				ch0 = strVal.charAt(0);
				if(ch0 < '0' || ch0 > '9')
				{
					if(language == 1)
					{
						alert(str+"请输入合法的数字!");
					}
					else
					{
						alert(str+"Please input valid number!");
					}
					item.focus();
					return false;
				}
			}
			else//长度大于1的情况 
			{	
				ch0 = strVal.charAt(0);
				ch1 = strVal.charAt(1);
				if(((ch0 == '0')&&(ch1 == 'x'))||((ch0 == '0')&&(ch1 == 'X')))//如果是0x开头，默认为输入十六进制数据
				{
					if(strVal.length == 2)
					{
						if(language == 1)
						{
							alert(str+"请输入合法的数值!");
						}
						else
						{
							alert(str+"Please input valid number!");
						}
						item.focus();
						return false;
					}
					for ( i = 0 ; i < strVal.length-2; i++ )
					{      
						ch = strVal.charAt(i+2);
						if(ch < '0' || ch > '9'&& ch < 'A' || ch > 'F' && ch < 'a' || ch > 'f')
						{
							if(language == 1)
							{
								alert(str+"请输入合法的数值!");
							}
							else
							{
								alert(str+"Please input valid number!");
							}
							item.focus();
							return false;
						}
					}
				}
				else if(ch0 == '0')//否则的话不能以0作为开头
				{
					if(language == 1)
					{
						alert(str+"请输入合法的数值!");
					}
					else
					{
						alert(str+"Please input valid number!");
					}
					item.focus();
					return false;
				}
				else//认为输入十进制数
				{
					for ( i = 0 ; i < strVal.length ; i++ )
					{      
						ch = strVal.charAt(i);
						if(ch < '0' || ch > '9')
						{
							if(language == 1)
							{
								alert(str+"请输入合法的数值!");
							}
							else
							{
								alert(str+"Please input valid number!");
							}
							item.focus();
							return false;
						}
					}			
				}
			}
			intVal= parseInt(item.val());
			if((intVal < startvalue)||(intVal > endvalue))
			{
				if(language == 1)
				{
					alert(str+"必须在 "+ startvalue + " 和 " + endvalue +" 之间!");
				}
				else
				{
					alert(str+"must be between "+ startvalue + " and " + endvalue +"!");
				}
				item.focus();
				return false;
			}
			break;
		case "VAL_HEX1"://不能为空
			if(strVal=="")
			{
				if(language == 1)
				{
					alert("请输入"+str);
				}
				else
				{
					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')
				{
					if(language == 1)
					{
						alert(str+"请输入合法的16进制数!");
					}
					else
					{
						alert(str+"Please input valid hexadecimal number");
					}				
					item.focus();
					return false;
				}
			}
			intVal= parseInt(item.val());
			if(startvalue != endvalue)
			{
				if((intVal < startvalue)||(intVal > endvalue))
				{
					if(language == 1)
					{
						alert(str+"必须在 "+ startvalue + " 和 " + endvalue +" 之间!");
					}
					else
					{
						alert(str+"must be between "+ startvalue + " and " + endvalue +"!");
					}
					item.focus();
					return false;
				}
			}
			break;
		case "VAL_HEX0"://可以为空
			for ( i = 0 ; i < strVal.length ; i++ )
			{      
				ch = strVal.charAt(i);
				if(ch < '0' || ch > '9'&& ch < 'A' || ch > 'F' && ch < 'a' || ch > 'f')
				{
					if(language == 1)
					{
						alert(str+"请输入合法的16进制数!");
					}
					else
					{
						alert(str+"Please input valid hexadecimal number");
					}				
					item.focus();
					return false;
				}
			}
			intVal= parseInt(item.val());
			if(startvalue != endvalue)
			{
				if((intVal < startvalue)||(intVal > endvalue))
				{
					if(language == 1)
					{
						alert(str+"必须在 "+ startvalue + " 和 " + endvalue +" 之间!");
					}
					else
					{
						alert(str+"must be between "+ startvalue + " and " + endvalue +"!");
					}
					item.focus();
					return false;
				}
			}
			break;
		case "LENGTH":
			if(startvalue == endvalue)//Length is fixed
			{
				if(strVal.length != startvalue)
				{
					if(language == 1)
					{
						alert(str+"长度只能为 "+startvalue+"!");
					}
					else
					{
						alert(str+"The length must be "+startvalue+"!");
					}
					item.focus();
					return false;
				}
			}
			else
			{
				if((strVal.length < startvalue)||(strVal.length > endvalue))
				{
					if(language == 1)
					{
						alert(str+"长度必须在 "+ startvalue + " 和 " + endvalue +" 之间!");
					}
					else
					{
						alert(str+"The length must be between "+ startvalue + " and " + endvalue +"!");
					}			
					item.focus();
					return false;
				}
			} 
			break;
		case "DECIMALS":
		 	var patten  =/^[+-]?\d+(\.\d+)?$/;
			if(patten.test(strVal) == false)
			{
				if(language == 1)
				{
					alert(str+"请输入合法的数字!");
				}
				else
				{
					alert(str+"Please input valid number!");
				}
				return patten.test(strVal);
			}
			intVal= parseFloat(item.val());
			if((intVal < startvalue)||(intVal > endvalue))
			{
				if(language == 1)
				{
					alert(str+"必须在 "+ startvalue + " 和 " + endvalue +" 之间!");
				}
				else
				{
					alert(str+"must be between "+ startvalue + " and " + endvalue +"!");
				}
				item.focus();
				return false;
			}
			break;
		default:
			break;
	}
	return true; 
}