// JavaScript Document
function isblank(s) 
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function sendqueries() 
{
    var msg;
    var empty_fields = "";
    var errors = "";

	if(isblank(form1.name.value))
		errors += "- 请填写姓名 Name required\n";
	if(isblank(form1.content.value))
		errors += "- 请填写查询内容 Enquiry required\n";
	if(isblank(form1.phone.value))
		errors += "- 请填写联系电话 Telephone required\n";
	else if(isNaN(form1.phone.value))
			errors += "- 电话必须为数字 Telephone field must be a number \n";
	if(isblank(form1.email.value))
		errors += "- 请填写电子邮件 Email required\n";
	else if(!isEmail(form1.email.value))
			errors += "- 电子邮件格式不正确 Invalid Email Format\n";
	

	if(errors=="")
	{
		form1.action="oopsprocess.php";
		form1.submit();
	}
	else
	{
		alert(errors);
	}

}

function sendqueries2() 
{
    var msg;
    var empty_fields = "";
    var errors = "";

	if(isblank(form1.name.value))
		errors += "- 请填写姓名 Name required\n";
	if(isblank(form1.age.value))
		errors += "- 请填写年龄 Age required\n";
	else if(isNaN(form1.age.value))
			errors += "- 年龄必须为数字 Age field must be a number \n";
	if(isblank(form1.number.value))
		errors += "- 请填写人数 Number of tourists required\n";
	else if(isNaN(form1.number.value))
			errors += "- 人数必须为数字 Number of tourists field must be a number \n";
	if(isblank(form1.phone.value))
		errors += "- 请填写联系电话 Telephone required\n";
	else if(isNaN(form1.phone.value))
			errors += "- 联系电话必须为数字 Telephone field must be a number \n";
	if(isblank(form1.email.value))
		errors += "- 请填写电子邮件 Email required\n";
	else if(!isEmail(form1.email.value))
			errors += "- 电子邮件格式不正确 Invalid Email Format\n";
	if(isblank(form1.address.value))
			errors += "- 请填写联系地址 Contact address required\n";
	if(document.form1.checkbox.checked==false)
			errors += "- 请勾选我同意条款 Please tick I agree box\n";
	

	if(errors=="")
	{
		form1.action="oopsprocess.php";
		form1.submit();
	}
	else
	{
		alert(errors);
	}

}

var checkobj
function agreesubmit(el){
  checkobj=el
  if (document.all||document.getElementById){
  for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
  var tempobj=checkobj.form.elements[i]
  if(tempobj.type.toLowerCase()=="submit")
  tempobj.disabled=!checkobj.checked
  }
  }
  }
function defaultagree(el){
  if (!document.all&&!document.getElementById){
  if (window.checkobj&&checkobj.checked)
  return true
  else{
  alert("Please read/accept terms to submit form")
  return false
  }
  }
  }

