trimString = function (str)
{
	var i,j;

	if(str == "") return "";

	for(i=0;i<str.length;i++)
	if(str.charAt(i) != ' ') break;
	if(i >= str.length) return "";

	for(j=str.length-1;j>=0;j--)
	if(str.charAt(j) != ' ') break;

	return str.substring(i,j+1);
}

//no use yet, use with addError
clearErrorMessages = function (form)
{
	return;
}

//no use yet, use with addError
clearErrorLabels = function (form)
{
	return;
}

//public functions
processError = function (field, errMsg)
{
	alert(errMsg);
	field.focus();
	//field.select()
	return false;
}

//private functions
//to add the errors for the form-validate
addError = function (e, errorText) 
{
	try
	{
		var o = getErrorShowDiv();
		o.innerHTML = '错误提示: ' + errorText;
		e.focus();
	}
	catch (e)
	{
		alert(e);
	}
	return false;
}

Checker = function()
{
	this.checkRequired=function(fieldValue)
	{
		fieldValue = trimString(fieldValue);
		return ('' != fieldValue);
	}
	
	this.checkRequiredstring=function(fieldValue)
	{
		fieldValue = trimString(fieldValue);
		return ( ('' != fieldValue) && (0 < fieldValue.length) );
	}
	
	this.checkEmail=function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return ( this.checkRequiredstring(fieldValue) && (this.checkRegex(fieldValue, /^\S+@\S+\.(com|net|org|info|edu|mil|gov|biz|ws|us|tv|cc|aero|arpa|coop|int|jobs|museum|name|pro|travel|nato|.{2,2})$/gi)) );
	}
	
	this.checkUrl=function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return ( this.checkRequiredstring(fieldValue) && (this.checkRegex(fieldValue, /^((file:\/\/\S+)|(ftp|http|https):\/\/\S+\.(com|net|org|info|edu|mil|gov|biz|ws|us|tv|cc|aero|arpa|coop|int|jobs|museum|name|pro|travel|nato|.{2,2}))$/gi)) );
	}
	
	this.checkInt=function(fieldValue, min, max, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return ( this.checkRequiredstring(fieldValue) && (parseInt(fieldValue) >= min && parseInt(fieldValue) <= max) );
	}
	
	this.checkStringlength=function(fieldValue, min, max, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkRequiredstring(fieldValue) && (fieldValue.length >= min && fieldValue.length <= max) );
	}
	
	this.checkRegex = function (fieldValue, reg)
	{
		fieldValue = trimString(fieldValue);
		return (null != fieldValue.match(reg));
	}
	
	this.checkDouble = function (fieldValue, minInclusive, maxInclusive, minExclusive, maxExclusive)
	{
		fieldValue = trimString(fieldValue);
		return ( (false == minInclusive) && (false == maxInclusive) && (false == minExclusive) && (false == maxExclusive) );
	}
	
	this.checkPhone = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkRequiredstring(fieldValue) && this.checkRegex(fieldValue, '^[0-9]{3,5}-[0-9\(\)\-\s]{6,20}$'));
	}
	
	this.checkUserName = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkStringlength(fieldValue, 1, 30) );
	}
	this.checkTrivalWriting = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkStringlength(fieldValue, 2000, 40000) );
	}
	this.checkRealName = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkStringlength(fieldValue, 2, 6) );
	}
	
	this.checkPassword = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return this.checkStringlength(fieldValue, 1, 20);
	}
	
	this.checkPostcode = function(fieldValue, onlyIfAvailable)
	{
		fieldValue = trimString(fieldValue);
		if (onlyIfAvailable && ('' == fieldValue))
		{
			return true;
		}
		return (this.checkRequiredstring(fieldValue) && this.checkRegex(fieldValue, '^[0-9]{6}$'));
	}

   this.checkStr = function (fieldValue){  
		var re1 = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$");
		if (!re1.test(fieldValue)){
			return false;
		}
		return true;
   }

}

