
function trim(theString){
	while(theString.substr(0,1)==" ")
		theString=theString.substr(1);

	while(theString.substr(theString.length-1,1)==" ")
		theString=theString.substr(0,theString.length-1);

	return theString;
}

function isValidEMail(theEMail) {
	var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return regexp.test(theEMail);
}



function chkAll(theForm){

	var msg="";
	var j=0;
	var intregexp=/\d+/;


	var sn=theForm.VisitorName.value=trim(theForm.VisitorName.value);
	var phone=theForm.VisitorPhone.value=trim(theForm.VisitorPhone.value);
	var eml=theForm.VisitorEmail.value=trim(theForm.VisitorEmail.value);
	var cont=trim(theForm.Message.value);
	theForm.Message.value=cont==theForm.Message.defaultValue?"":cont;
	var teltest = intregexp.test(phone) && (phone.length == 10) 

	msg+=sn==""?(++j)+". 請輸入您的大名\n":"";
	msg+=eml==""?(++j)+". 請輸入E-Mail\n":isValidEMail(eml)?"":(++j)+". 請輸入正確的E-Mail\n";
	msg+=phone==""?(++j)+". 請輸入電話\n":teltest?"":(++j)+". 電話請輸入十個數字\n";
	msg+=cont==""?(++j)+". 請輸入反應問題\n":cont.length>500?(++j)+". 反應問題請輸入 500 個字元以內\n":"";

	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
		return false;
	}
}


