function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateNoblank(theForm.guestname);
  reason += validateNoblank(theForm.guestemail);
  reason += validateNum(theForm.secureno);
      
  if (reason != "") {
    alert("以下部份項目必須輸入:\n\n" + reason);
    return false;
  }

	theForm.Submit.value = '儲存中!';
	theForm.Submit.disabled = true;
  return true;
}

function validateNoblank(fld) {
    var error = "";
	
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow';
		if (fld.name == 'guestname') {
        	error = "您的名字.\n"
		} else if (fld.name == 'guestemail') {
        	error = "您的電郵.\n"
		} else if (fld.name == 'secureno') {
        	error = "驗證碼.\n"
		}
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateNum(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "驗證碼不正確.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "驗證碼不正確.\n";
        fld.style.background = 'Yellow';
    } 
    return error;
}


