//去掉字符串的前后空格
function AllTrim(strSource1)
{
	strSource = new String( strSource1 );

	var ReturnString="";
	var i=0 , j=0;

	//1: clear previous blank space char
	while ( (i < strSource.length) && (strSource.charAt(i) ==" ") )
		i++;
	//2: clear backword blank space char
	j = strSource.length-1;
	if ( i < strSource.length )
	{
		while ((j>=0 ) && (strSource.charAt(j) ==" ") )
			j = j-1;
	}

	//3: make a new string
	while ( i <= j )
	{
		ReturnString += strSource.charAt(i);
		i++; 
	}
	return(ReturnString);
}

//验证给定的字符串是否时间是时间格式
function isDate(sdate)
{
	sdate = AllTrim(sdate);
	
	if (sdate == "") 
	   return false;

	
	i = Date.parse(sdate);

	if (isNaN(i) )
	{
		return false;
	}
	else
		return true;
}

//验证给定的字符串是否时间是Email格式
function IsValidEmail( strEmail )
{
	
	//1:不能为空
	strEmail = AllTrim( strEmail );
	if (strEmail == "")  
		return false;

	//2:只有一个'@'
	if ((i=strEmail.indexOf ('@')) == -1)
		return false;
	else //only one '@'
	{
		j=strEmail.indexOf ('@',i+1);
		if ( j != -1 )
			return false;
	}
	
	//3:'@'后有一个'.'，但'.'不能是最后一个字符
	if ((i=strEmail.indexOf ('.')) == -1)
       return false;
	else
	{
		//'.'在最后
		if ( i == (strEmail.length-1) )
			return false;
	}

	//4:@前的字符必须是0-9， a-b, A-B之间才对
	i=strEmail.indexOf ('@');
	i--;
	if ((i<0) || !( (strEmail.charAt(i)>='0' && strEmail.charAt(i)<='9')
		|| (strEmail.charAt(i)>='a' && strEmail.charAt(i)<='z')
		|| (strEmail.charAt(i)>='A' && strEmail.charAt(i)<='B') ))
		return false;

	return true;
}
/*
{
	ie4 = (document.all) ? true : false; 
	ns4 = (document.layers) ? true : false; 
	function keyDown(e)
	{ 
		if (ns4)
		{ 
			var nKey=e.which; 
			document.keyform.keytext.value="键值是"+nKey; 
		} 
		if (ie4)
		{ 
			var ieKey=event.keyCode; 
			document.keyform.keytext.value="键值是"+ieKey; 
		} 
	} 
	document.onkeydown=keyDown; 
	if (ns4) 
		document.captureEvents(Event.KEYDOWN); } 
}
*/

