/*
 
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("Please input username");
 		return false;
 	}
 	//is s contain whitespace
   	if ( isWhitespace(s) )
	{
		alert("username can not contain space！");	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar)
    	if (errorChar != "" )
	{
		alert("the username " + s+" is invalid,\n\ndo not input invalid character " + errorChar + " !\n\nTry again!" );
		return false;
	} 	
	
	return true;
}

function isEmail (s)
{


	if(!isEmpty(s))
	{
    if (isWhitespace(s))
	{
		strReport=strReport+"No valid \n";	
		return false;
	}

   var i = 1;
   var len = s.length;

	if (len > 50)
	{
		strReport=strReport+"email length should not be more than 50 characters!\n";
		return false;
	}
	
	pos1 = s.indexOf("@");
	pos2 = s.indexOf(".");
	pos3 = s.lastIndexOf("@");
	pos4 = s.lastIndexOf(".");
	//alert ("pos4="+pos4);
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1)||(pos3>len-5)||(pos4>len-3))  
	{ 
		strReport=strReport+"You input a wrong E-mail!\n";
		return false;
	}
	else
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 )  //. should behind the '@'
		  || ( pos4 ==pos2+1 ) ) //find continious dot  		
		{
			strReport=strReport+"You input a wrong E-mail!\n";
			return false;
		}


	if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
	{
		strReport=strReport+"email should only include ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" ;
		return false;
	}
	}
	
	return true;
}

function isTelNumber(s)
{
	//is s contain invalid characters
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&`QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm"; 
	var len = s.length;
   //Validate the user name
    if ( isCharsInBag( s, badChar))
	{
		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==18)||(s.length==15)||(s.length==9)||(s.length==10)))
  {
     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 = "><,[]{}?/+=|\\'\":;~!#$%()`1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; 
 	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请重新输入您的真实姓名！" );
		return false;
	} 	
	if (s.length>=20){
		alert("您输入的名字太长，请重新输入！");
		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)
{
  if (isEmpty(s))
  {
	alert("Password can not be blank!");
	return false;
  }
//is s contain whitespace
  if ( isWhitespace(s) )
  {
	alert("Password can not contain space!");	
	return false;
  }

  if (s.length<6)
  {
 	alert("password must be six characters!");
	return false;
  }
  if (s.length>50)
  {
 	alert("password must be less than 50 characters");
	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(".")+1);
  if (parseInt(opart) != 0)
  {
	alert(item+"的最小单位是1元！");
	return false;
  }

  return true;
}

function ckcontact(ee,dt) {
	bstr = new Array;
	bstr[1] = "@";
	bstr[2] = "icq";
	//bstr[3] = "yahoo";
	//bstr[4] = "mail";
	//bstr[5] = "msn";
	//bstr[6] = "aol";
	//bstr[7] = "tel";
	
	
	
	
	 for(i = 0; i < bstr.length; i++)
        {
	s=ee.value.toLowerCase().indexOf(bstr[i]);
	if (s!=-1){
		alert('请勿在 ' + dt +' 中加入电话、呼机、EMAIL等联系方法，\n\n共同维护网上竞标的良好气氛！');
		return false;
		
		}
		
	}
	   
	  
	  exp=new RegExp("[0-9]{6,15}"); //tel
	  ss=ee.value.toLowerCase().match(exp);
	  if (ss!=null){
	  	alert('请勿在 ' + dt + ' 中加入电话、呼机、EMAIL等联系方法，\n\n共同维护网上竞标的良好气氛！');
	  	return false;
	  
	  }
	 return true;
	// alert("ok");
	 
}