// Validate the form fields
function validateForm(obj){
	with(obj){
		if(custname.value == ""){
			alert('Please enter your name');	
			return false;
		}
		
		if(custemail.value == ""){
			alert('Please enter your email');	
			return false;
		}else{
			if(!checkEmail(custemail))
				return false;
		}
		
	}
	document.getElementById('return_uri').value = window.location.href;
	var url = obj.action;
	var postdata ={custname:obj.custname.value, custemail:obj.custemail.value, custtel:obj.custtel.value, comments:obj.comments.value,return_uri:window.location.href };
	$('address').append('<div align="center" id="jresponse"><img src="images/ajax-loader.gif"></div>');
	var alertDiv = '#jresponse';
	submitForm2(obj.action,postdata,alertDiv);
	
	return false;
}

function validateReserveForm(obj){
	with(obj){
		if(first_name.value == ""){
			alert('Please enter your first name');	
			return false;
		}
		
		if(email.value == ""){
			alert('Please enter your email');	
			return false;
		}else{
			if(!checkEmail(email))
				return false;
		}
	}
	
	var url = obj.action;
	var postdata ={	first_name:obj.first_name.value, 
					last_name:obj.last_name.value, 
					email:obj.email.value, 
					daytime_phone:obj.daytime_phone.value,
					evening_phone:obj.evening_phone.value, 
					address:obj.address.value, 
					city:obj.city.value,
					state:obj.state.value, 
					zip:obj.zip.value, 
					describe:obj.describe.value };	
	var alertDiv = '#responsdata';
	$(alertDiv).show();
	window.location = 'reserve-thank-you.htm';
	//submitForm(obj.action,postdata,alertDiv);
	
	return false;
}

function checkEmail(emailAddr) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr.value)){
		return true;
    }
     alert("Invalid E-mail Address! Please re-enter.")
     return false
}

function submitForm(url,postdata,alertDiv){
	$.ajax({
	  type: 'POST',
	  url: url,
	  data: postdata,
	  success: function(rdata){
		$(alertDiv).html('<font  class="success"> Form submitted successfully.</font>');	  
		
	  },
	  dataType: "html"
	});	
}

function submitForm2(url,postdata,alertDiv){
	$.ajax({
	  type: 'POST',
	  url: url,
	  data: postdata,
	  success: function(rdata){
		//$(alertDiv).html('<font  class="success"> Form submitted successfully.</font>');	  
		window.location = 'thank-you.htm';
	  },
	  dataType: "html"
	});	
}
