/*
 
s: string value
bag: char array

isEmpty(s) : null
isWhitespace (s) : " \t\n\r"
isUserName(s) 
isName(s)
isEmail (s)
isTelNumber(s)
isCardNumber(s) 
isAddress(s)
isCharsInBag (s, bag)
isKeyword(s)
isItemNum(s)
isPassword(s)
isInt(s, item)
isIntEx(s, item, len， bCompare)

isCharsInBagEx (s, bag) : return a bad char

isUserNameOld(s) 
*/

function isEmpty(s)
{  
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{  
  var whitespace = " \t\n\r";
  var i;
  // Is s empty?
  //if (isEmpty(s)) return true;

   // Search through string's characters one by one
   // until we find a non-whitespace character.
   // When we do, return false; if we don't, return true.
   for (i = 0; i < s.length; i++)
   {   
       // Check that current character isn't whitespace.
       var c = s.charAt(i);
       if (whitespace.indexOf(c) >= 0) 
	   {
		  return true;
	   }
   }

   // All characters are whitespace.
   return false;
}

function isCharsInBagEx (s, bag)
{  
  var i,c;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.
  for (i = 0; i < s.length; i++)
  {   
        c = s.charAt(i);
	if (bag.indexOf(c) > -1) 
        return c;
  }
  return "";
}

function isCharsInBag (s, bag)
{  
  var i;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.

  for (i = 0; i < s.length; i++)
  {   
      // Check that current character isn't whitespace.
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

function isRegisterUserName(s)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入用户名！");
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的用户名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名！" );
		return false;
	} 	
	
	return true;
}

function isEmail (s)
{
   	// is s Empty?
 /*   if (isEmpty(s))
	{
		alert("输入的E-mail地址不能为空，请输入！");	
		return false;
	}
*/
	//is s contain whitespace
    if (isWhitespace(s))
	{
		alert("输入的E-mail地址中不能包含空格符，请重新输入！");	
		return false;
	}

   // there must be >= 1 character before @, so we
   // start looking at character position 1
   // (i.e. second character)
   var i = 1;
   var len = s.length;

	if (len > 30)
	{
		alert("email地址长度不能超过30位!");
		return false;
	}
	
	pos1 = s.indexOf("@");
	pos2 = s.indexOf(".");
	pos3 = s.lastIndexOf("@");
	pos4 = s.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))  
	{
		alert("请输入有效的E-mail地址！");
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 2) || (pos1 == pos2 + 2) 
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'  		
		{
			alert("请输入有效的E-mail地址！");
			return false;
		}
	}

	if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
	{
		alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
		return false;
	}
	//is s contain invalid characters
	/*
	var badChar = "><,[]{}?/+=|\\'\":;!#$%^&()`"; 
	if ( isCharsInBag( s, badChar))
	{
		alert("请不要在email地址中输入字符 " + badChar + "\n" );
		alert("请重新输入" );
		return false;
	}
	*/
	return true;
}
function isTelNumber(s)
{
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`"; 
	var len = s.length;
   //Validate the user name
    if ( isCharsInBag( s, badChar))
	{
		alert("请输入正确的号码");
		return false;
	}
	//check user length 
	if ((len>18)||(len<6))
	{
		alert("请输入电话不能超过18位也不能少于6位！");
		return false;
	}
	return true;
}

function isAddress(s)
{
   	// is s Empty?
   	if ( isEmpty(s) )
	{
		alert("联系地址不能为空，请重新输入！");	
		return false;
	}
	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的联系地址中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`"; 
	var len = s.length;
   //Validate the user name
    if ( isCharsInBag( s, badChar))
	{
		alert("联系地址中不能含有字符 "+badChar + " !");
		return false;
	}
	//check user length 
	if ((len>100)||(len<5))
	{
		alert("联系地址不能超过50个汉字也不能少于五个汉字！");
		return false;
	}
	return true;
}

function isCardNumber(s) 
{
//身份证号码验证
  if (s == "")
  {
     alert("身份证号码不能为空！请填写！");
	return false;
  }
  
  if ((s.length<15)||(s.length>18)||(s.length==16)||(s.length==17))
  {
     alert("请检查一下您输入的身份证号码位数是否正确！");
	return false;
  }
  
  //if(!isCharsInBag (s, "0123456789"))
  //{
  //  alert("请检查一下您输入的身份证号是否为数字！");
  //  return false;
  //}
  return true;
}

 function isKeyword(s)
 {
 	var a, errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
	// is s Empty?
   	if ( isEmpty(s) )
	{
		a = confirm("如果您不输入任何查询关键字，您可能会得到太多的查询结果。\n\n您确定要进行查询吗？");	
		if (a == false)
			return false;
	}
	else
	{
		//is s contain invalid characters
		//Validate the user name
		errorChar = isCharsInBagEx( s, badChar)
	    	if (errorChar != "" )
		{
			alert("请不要在查询关键字中输入字符" + errorChar + "\n\n请重新输入！" );
			return false;
		} 	
	}
	return true;
 }
 
 function isItemNum(s)
 {
 	if (isEmpty(s))
	{
		alert("请输入物品编号进行查询！");
 		return false;
	}
	var validChar = "0123456789"; 
	if (!isCharsInBag(s, validChar))
	{
		alert("您输入的物品编号" + s +"是无效的物品编号，\n\n请输入合法的物品编号！");
 		return false;
	}
	return true;		
 }
 
 function isUserName(s)
 {
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入用户名！");
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的用户名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的用户名" + s+"是无效的用户名,\n\n请不要在用户名中输入字符" + errorChar + "!\n\n请重新输入合法的用户名！" );
		return false;
	} 	
	
	return true;
 }
 
 function isName(s)
 {
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入姓名！");
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("输入的姓名中不能包含空格符，请重新输入！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的姓名" + s+"是无效的姓名,\n\n请不要在姓名中输入字符" + errorChar + "!\n\n请重新输入合法的姓名！" );
		return false;
	} 	
	
	return true;
 }
 
function isSource(s)
{
   if (s=='选择')
   {
      alert("信息不能为空，请你选择");
      return false;
   }
   return true;
}

function isSex(s)
{
   if (s=='选')
   {
      alert("性别信息不能为空，请你选择");
      return false;
   }
   return true;
}



function isCity(s)
{
   if (s=='选择')
   {
      alert("城市信息不能为空，请你选择");
      return false;
   }
   return true;
}



function isPassword (s)
{ var errorChar
  var badChar = "<>'?/\\"; 
  if (isEmpty(s))
  {
	alert("密码不能为空，请输入！");
	return false;
  }
//is s contain whitespace
  if ( isWhitespace(s) )
  {
	alert("密码中不能包含空格符，请重新输入！");	
	return false;
  }

   errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的密码是无效的用户名,\n\n请不要在密码中输入字符 " + errorChar + "!\n\n请重新输入合法的密码！" );
		return false;
	} 	
  if ((s.length>16)||(s.length<4))
  {
 	alert("口令不能超过16位也不能少于4位！");
	return false;
  }

  return true;
}

function isInt(s, item)
{
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }

  return true;
}

function isInt2(s, item)
{
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }

  return true;
}

function isIntEx(s, item, len, bCompare)
{
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
      	
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
  
  if (bCompare == "=") 
  {
    if (s.length != len)
    {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n必须等于" + len + "位！");
	return false;
    }
  }
  else if (bCompare == "<")
  {
    if (s.length >= len) 
    {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n必须小于" + len + "位！");
	return false;
    }
  }
  
  return true;
}

function isValidString(s, des)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		alert("请输入"+ des +"！");
 		return false;
 	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("您输入的" + des +"是无效的"+des +",\n\n请不要在"+des+"中输入字符" + errorChar + "!\n\n请重新输入合法的"+des+"！" );
		return false;
	} 	
	
	return true;
 }
 
function isPrice(s, item)
{
 
  if (isEmpty(s))
  {
	alert(item + "不能为空，请输入！");
	return false;
  }
   
  var validChar = "0123456789."; 
  if (!isCharsInBag(s, validChar))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
  if (s.indexOf(".") == -1)
  	return true;
  	
  if (s.indexOf(".") != s.lastIndexOf("."))
  {
	alert("您输入的" + item + s +"是无效的" + item + "，\n\n请输入合法的" + item + "！");
	return false;
  }
 /*
  var opart = s.substr(s.indexOf(".")+3)
  if (parseInt(opart) != 0)
  {
	alert(item+"的最小单位是1元！");
	return false;
  }
*/
  return true;
}

//设置按钮颜色
function mOvr(src,clrOver) { 
	if (!src.contains(event.fromElement)){
		src.style.cursor = 'hand'; 
		src.bgColor = clrOver;
	}
}
		
function mOut(src,clrIn){
	if (!src.contains(event.toElement)) { 
		src.style.cursor = 'default'; 
		src.bgColor = clrIn; 
	}
} 

function mClk(src) { 
	if(event.srcElement.tagName=='TD'){
		src.children.tags('A')[0].click();
	}
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function isEnglish(s)
{

if ( !isCharsInBag( s, "ABC DEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@><,[]{}?/+=|\\'\":;~!#$%()`"))
	{
		alert(" 请确认输入字符为 英文字符 " + "请重新输入" );
		return false;
	}

 return true;


}


function disp_tr()
 {
 	if(tr_car2.style.display!="")
		tr_car2.style.display="";
	else
		tr_car2.style.display="none";

}

function disp_tr2()
 {
 	if(tr_car3.style.display!="")
		tr_car3.style.display="";
	else
		tr_car3.style.display="none";

}