//trim the left and right space去掉字串两边的空格 
function trim(str) 
{ 
return lTrim(rTrim(str)); 
} 

function checkgb() {

//check user name
	var ulen;
 if(document.formtblGuestBookadd.x_GuestName.value.replace(/\s/g,"")=="")

 {
 alert("请输入您的姓名.\n\n-------- www.tjyxh.com ----------");
 document.formtblGuestBookadd.x_GuestName.focus();
 return false;
 }
 
 ulen = document.formtblGuestBookadd.x_GuestName.value.length;
	if (ulen < 2){
	document.formtblGuestBookadd.x_GuestName.focus();
	alert("请输入您的姓名.\n\n-------- www.tjyxh.com ----------");
	return false
	   }

// Check user email
	if (document.formtblGuestBookadd.x_GuestEmail.value=="") {
	document.formtblGuestBookadd.x_GuestEmail.focus();
	alert("请输入您的电子邮件地址.\n\n-------- www.tjyxh.com ----------");
	return false
	}
	// check for @
	i = document.formtblGuestBookadd.x_GuestEmail.value.indexOf("@");
	if (i == -1) {
	document.formtblGuestBookadd.x_GuestEmail.focus();
	alert("对不起，您输入的电子邮件地址无效.\n\n-------- www.tjyxh.com ----------");
	return false
	}

	// separate the user name and domain
	var username = document.formtblGuestBookadd.x_GuestEmail.value.substring(0, i);
	var domain = document.formtblGuestBookadd.x_GuestEmail.value.substring(i + 1, document.formtblGuestBookadd.x_GuestEmail.value.length);

	// look for spaces at the beginning of the username
	i = 0;
	while ((username.substring(i, i + 1) == " ") && 
	(i < username.length)) {
	i++;
	}
	// remove any found
	if (i > 0) {
	username = username.substring(i, username.length);
	}

	// look for spaces at the end of the domain
	i = domain.length - 1;
	while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
	i--;
	}

	// remove any found
	if (i < (domain.length - 1)) {
	domain = domain.substring(0, i + 1);
	}

	i = domain.length - 1;
	if (domain.substring(i, i + 1) == ".") {
	document.formtblGuestBookadd.x_GuestEmail.focus();
	alert("对不起，您输入的电子邮件地址无效.\n\n-------- www.tjyxh.com ----------");
	return false
	}

	i = domain.indexOf(".");
	if (i == -1) {
	document.formtblGuestBookadd.x_GuestEmail.focus();
	alert("对不起，您输入的电子邮件地址无效.\n\n-------- www.tjyxh.com ----------");
	return false
	}


	// check for bad characters in the username
	var ch;
	for (i = 0; i < username.length; i++) {
	ch = (username.substring(i, i + 1)).toLowerCase();
	if (!(((ch >= "a") && (ch <= "z")) || 
        ((ch >= "0") && (ch <= "9")) ||
        (ch == "_") || (ch == "-") || (ch == "."))) {
	document.formtblGuestBookadd.x_GuestEmail.focus();
	alert("对不起，您输入的电子邮件地址无效.\n\n-------- www.tjyxh.com ----------");
	return false
	    }
	}

	// check for bad characters in the domain
	for (i = 0; i < domain.length; i++) {
	    ch = (domain.substring(i, i + 1)).toLowerCase();
	    if (!(((ch >= "a") && (ch <= "z")) || 
        ((ch >= "0") && (ch <= "9")) ||
        (ch == "_") || (ch == "-") || (ch == ".") || (ch == "+"))) {
	document.formtblGuestBookadd.x_GuestEmail.focus();
            alert("对不起，您输入的电子邮件地址无效.\n\n-------- www.tjyxh.com ----------");return false
	     }
	}
//check user Description
	var delen;
	 if(document.formtblGuestBookadd.x_GuestComments.value.replace(/\s/g,"")=="")

 {
 alert("请输入备注信息，长度必须大于五个字.\n\n-------- www.tjyxh.com ----------");
 document.formtblGuestBookadd.x_GuestComments.focus();
 return false;
 }

	
	delen = document.formtblGuestBookadd.x_GuestComments.value.length;
	if (delen < 5){
	document.formtblGuestBookadd.x_GuestComments.focus();
	alert("请输入备注信息，长度必须大于五个字.\n\n-------- www.tjyxh.com ----------");
	return false
	   }
	if (delen > 2000){
	document.formtblGuestBookadd.x_GuestComments.focus();
	alert("请输入备注信息，长度不能超过2000个字.\n\n-------- www.tjyxh.com ----------");
	return false
	   }

return true;
}
