function IsOptChecked(theObj,theObjType,theReturnType){
	var blnChecked=false;
	var isSelect=false;
	var objType=theObjType==null?"":theObjType;
	var checkedValue="";
	if(theObj){
		isSelect=theObjType.toLowerCase()=="select";
		if(theObj.length>1){
			for(var i=0;i<theObj.length;i++){
				blnChecked=isSelect?theObj[i].selected:theObj[i].checked;
				if(blnChecked){
					checkedValue=theObj[i].value;
					break;
				}
			}
		}
		else{
			blnChecked=isSelect?theObj.selected:theObj.checked;
			checkedValue=theObj.value
		}
	}
	return theReturnType=="bool"?blnChecked:checkedValue;
}

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 blnEPaperChecked=true;
	var today=new Date();
	var dateformat=today.getFullYear()+"/"+(today.getMonth()+1)+"/"+today.getDay();

	var eml=trim(theForm.Email.value);
	var nl=theForm.newsLetter;
	
	var memnumregexp=/^[a-zA-Z]{1}\d{9}$/;
	var alpharegexp=/[a-zA-Z]+/;
	var intregexp=/\d+/;
	var today=new Date();
	var dateformat=today.getFullYear()+"/"+(today.getMonth()+1)+"/"+today.getDay();
	if(nl) blnEPaperChecked=IsOptChecked(nl,"radio","");

	msg+=blnEPaperChecked?"":(++j)+". 請選擇訂閱 / 取消訂閱Matsusei 松青超市網路電子報\n";
	msg+=eml==""?(++j)+". 請輸入E-Mail\n":isValidEMail(eml)?"":(++j)+". 請輸入正確的E-Mail\n";

	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
		return false;
	}

}

function chkEpaper(theForm){

	var msg="";
	var j=0;

	var eml=trim(theForm.Email.value);

	msg+=eml==""?(++j)+". 請輸入E-Mail\n":isValidEMail(eml)?"":(++j)+". 請輸入正確的E-Mail\n";

	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
		return false;
	}

}
