﻿var strInfo="";
function submitVenueBookingForm()
{
    strInfo=""
    if(checkInfo())
    {
      ajaxonReadySubmitVenueBooking(strInfo);
    }
}

function checkInfo()
{
  if (!chkLocation())
  {
   	return false;
  }
   
   
   
   var objName=document.getElementById("username");
   if(objName.value=="")
  {
    document.getElementById("nameLabel").innerHTML="Please input your name to complete register.";
    objName.style.borderColor = '#FF0000';
    return false;    
  }
  else
  {
     strInfo+="name="+objName.value;
  }
  
  
  var objEmail=document.getElementById("email");
   if(objEmail.value=="")
  {
    document.getElementById("emailLabel").innerHTML="Please input your email to complete register.";
    objEmail.style.borderColor = '#FF0000';
    return false; 
    
  }
  else
  {
     var t = /^[A-Za-z0-9._%-]+@([\-_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;	 		
	 if(t.test(objEmail.value)!=true)
	 {
	    document.getElementById("emailLabel").innerHTML="Please input validate email to complete register.";
        objEmail.style.borderColor = '#FF0000';
        return false; 
	 }
	 else
	 {
	   strInfo+="&email="+objEmail.value;
	 }
  }
   var objPhone=document.getElementById("phone");
   if(objPhone.value=="")
  {
    document.getElementById("phoneLabel").innerHTML="Please input phone number to complete register.";
    objPhone.style.borderColor = '#FF0000';
    return false;
  }
  else
  {
     var t = /^[0-9]*$/;	
	 if(t.test(objPhone.value)!=true)
	 {
	    document.getElementById("phoneLabel").innerHTML="Wrong input, please try again.";
        objPhone.style.borderColor = '#FF0000';
        return false; 
	 }
	 else
	 {
	   strInfo+="&phone="+objPhone.value;
	 }
  }
  
  var codeObj=document.getElementById("checkcode");
  if(codeObj.value=="")
  {
    document.getElementById("codeLabel").innerHTML="Please input validate code to complete register.";
    codeObj.style.borderColor = '#FF0000';
    return false; 
  }
  else
  {
      if(!ajaxGetCheckCode("checkcode="+codeObj.value))
      {
         document.getElementById("codeLabel").innerHTML="Wrong validate code, please try again.";
         document.getElementById("checkcode").style.borderColor = '#FF0000';
         return false; 
      }
      
  }
 
  strInfo+="&location="+getLocation();
   
  strInfo+="&purpose="+document.getElementById("purpose").value;
  strInfo+="&company="+document.getElementById("company").value;
  strInfo+="&message="+document.getElementById("message").value;
   
   return true;
}

function getLocation() {
  var location = "the_orange";
  if(document.getElementById("location2").checked==true)
    location="the_piazza";
  else if (document.getElementById("location_others").checked==true)
  	location=document.getElementById("location_others_txt").value;
  return location;
}

function clickLocation()
{
	if (document.getElementById("location_others").checked==true)
	{
		$("#location_others_txt").show();
		$("#location_others_txt").focus();
	}
	else
  {
		$("#location_others_txt").hide();
		clearLocation();
  }
	
}


function chkLocation()
{
   if (document.getElementById("location_others").checked==true)
   {
   	 var obj=document.getElementById("location_others_txt");
   	 
   	 if (obj.value=="")
   	 {
       document.getElementById("locationLabel").innerHTML="Please select or input location information.";
       obj.style.borderColor = '#FF0000';
       return false;
     }
   }
   
   return true;
}

function clearLocation()
{
 document.getElementById("locationLabel").innerHTML="";
 document.getElementById("location_others_txt").style.borderColor =""; 
}




var xmlHttpRequestSubmitVenueBooking;
function ajaxonReadySubmitVenueBooking(strInfo) {
  
    xmlHttpRequestSubmitVenueBooking = getXMLHttpRequest();
    xmlHttpRequestSubmitVenueBooking.open("POST", "/_layouts/TheVillage/eng/app/forms/VenueBookingSubmitAPI.aspx", false);
    xmlHttpRequestSubmitVenueBooking.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    xmlHttpRequestSubmitVenueBooking.send(strInfo);
    onReadySubmitVenueBooking();
}
function onReadySubmitVenueBooking() {
    if (xmlHttpRequestSubmitVenueBooking.readyState == 4) {
      
        if (xmlHttpRequestSubmitVenueBooking.status == 200) {
            
            if (xmlHttpRequestSubmitVenueBooking.responseText=="1")
            {
              
              //alert("提交成功，转页---");
              contactUs_form_success();

            }
            else
            {
              alert(xmlHttpRequestSubmitVenueBooking.responseText);
            }
        } else
            alert("处理忙，请稍候再试！");
    }
}
