var strReport=new String();

function checkUserid(userName) {
var str = userName;        
var re = /^[A-Za-z0-9]{1,8}$/;
	if (re.test(str)) {
		return true;
	}
return false;
}


function checkPassword(pwdObj) {
var str = pwdObj.value;        
var re = /^[A-Za-z0-9]{6,8}$/;
	if (re.test(str)) {
		return true;
	}
return false;
}

function checkEmail(emailObj) {
var str = emailObj.value;
var re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var re2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
if (!re1.test(str) && re2.test(str)) {
		return true;
	}
return false;
}



function isEnglish(s)
{
	if(isEmpty(s))
	{
		strReport=strReport+"用户名不能为空！\n";
		return false;
	}
	for(i=0;i<s.length;i++)
	{
		var c=s.charAt(i);
		if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||c=='_')
		{   
			continue;
		}
		else
		{
			strReport=strReport+"用户名必须为英文、下划线或数字！\n";	
			return false;
		}	
	}		
	return true;
}

function isEmpty(s)
{  
	return ((s == null) || (s.length == 0));
}

function isWhitespace (s)
{  
  var whitespace = " \t\n\r";
  var i;
  for (i = 0; i < s.length; i++)
   {   
       var c = s.charAt(i);
       if (whitespace.indexOf(c) >= 0) 
	   {
		  return true;
	   }
   }

     return false;
}

function isCharsInBagEx (s, bag)
{  
  var i,c;
  for (i = 0; i < s.length; i++)
  {   
        c = s.charAt(i);
	if (bag.indexOf(c) > -1) 
        return c;
  }
  return "";
}

function BadCharsInBag(s,bag)
{
 var i,c;
  for (i = 0; i < s.length; i++)
  {   
        c = s.charAt(i);
	if (bag.indexOf(c) > -1) 
        return false;
  }
  return true;
}

function isCharsInBag (s, bag)
{  
  var i;

  for (i = 0; i < s.length; i++)
  {   
     
      var c = s.charAt(i);
      if (bag.indexOf(c) == -1) return false;
  }
  return true;
}



function isUserName(s)
{
	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!#$%()`"; 
	if (isEmpty(s))
	{
		strReport=strReport+"Please input username!\n";
		return false;
	}
	//is s contain whitespace
	
	
  	if ( isWhitespace(s) )
	{
		strReport=strReport+"username can not contain space.\n";	
		return false;
	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar);
   	if (errorChar != "" )
	{
		strReport=strReport+"the username " + s+" is invalid,do not input invalid character "+ errorChar + " !Try again!\n";
		return false;
	} 	
	
	return true;
}
 
function isPassword(s)
{
  if (isEmpty(s))
  {
	strReport=strReport+"Password can not be blank!\n";
	return false;
  }
//is s contain whitespace
  if ( isWhitespace(s) )
  {
	strReport=strReport+"Password can not contain space!\n";	
	return false;
  }

  if ((s.length>50)||(s.length<6))
  {
 	strReport=strReport+"Must be six characters and less than 50\n";
	return false;
  }
  return true;
}

function isTitle(s)
{
  if (isEmpty(s))
  {
	strReport=strReport+"标题不能为空，请输入！\n";
	return false;
  }
  return true;
}

function isInt(s, item)
{
  if (isEmpty(s))
  {
	strReport=strReport+item + "不能为空，请输入！\n";
	return false;
  }
      	
  var validChar = "0123456789";
  if (!isCharsInBag(s, validChar))
  {
	strReport=strReport+"您输入的 " + item + s +"是无效的 " + item + "，请输入合法的 " + item + "！\n";
	//strReport=strReport +"您输入的 "+ item+ s;
	return false;
  }

  return true;
}

function isIntEx(s, item, len, bCompare)
{
  if (isEmpty(s))
  {
	strReport=strReport+item + "不能为空，请输入！\n";
	return false;
  }
      	
  var validChar = "0123456789"; 
  if (!isCharsInBag(s, validChar))
  {
	strReport=strReport+"您输入的 " + item + s +"是无效的 " + item + "，请输入合法的 " + item + "！\n";
	return false;
  }
  
  if (bCompare == "=") 
  {
    if (s.length != len)
    {
	strReport=strReport+"您输入的 " + item + s +"是无效的 " + item + "，必须等于" + len + "位！\n";
	return false;
    }
  }
  else if (bCompare == "<")
  {
    if (s.length >= len) 
    {
	strReport=strReport+"您输入的 " + item + s +"是无效的 " + item + "，必须小于" + len + "位！\n";
	return false;
    }
  }
  
  return true;
}


function isValidString(s, des)
{
 	var errorChar;
	var badChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`"; 
 	if (isEmpty(s))
 	{
 		strReport=strReport+"请输入"+ des +"！\n";
 		return false;
 	}
	//is s contain invalid characters
	//Validate the user name
	errorChar = isCharsInBagEx( s, badChar);
    	if (errorChar != "" )
	{
		strReport=strReport+"您输入的 " + des +"是无效的 "+des +",请不要在"+des+"中输入字符串 " + errorChar + "!请重新输入合法的 "+des+"！\n";
		return false;
	} 	
	
	return true;
 }
 

function JudgePassword(s1,s2)
{
	if (s1==s2)
		return true;
		
	else{
			strReport=strReport+"密码输入不一致！请重新输入！\n";
		 return false;
		 }
}



function LTrim(s)
{
	for(var i=0;i<s.length;i++)
		if(s.charAt(i)!=' ')
		 return s.substring(i,s.length);
	 return "";
}
	
function RTrim(s)
{
	for(var i=s.length-1;i>=0;i--)
		if(s.charAt(i)!=' ')
			return s.substring(0,i+1);
		return "";
}
	
function Trim(s)
{
	return RTrim(LTrim(s));
}
	

