function sendOwnersRequest() {
	
	var form = document.getElementById("rental-request-form");
	
	// Check form data
	if (form.name.value=='') {
		alert("Please enter your name (first & last).");
		form.name.focus();
		return(false);
	}
	
	if (form.phone.value=='') {
		alert("Please enter your phone number.");
		form.phone.focus();
		return(false);
	}
	
	if (form.email.value=='') {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}
	
	if (form.rental_name.value=='') {
		alert("Please enter a rental name.");
		form.rental_name.focus();
		return(false);
	}
	
	if (form.rental_address.value=='') {
		alert("Please enter the rental address.");
		form.rental_address.focus();
		return(false);
	}
	
	$("#content-request-form").fadeOut('fast', function() {
		$("#content-request-processing").fadeIn('fast', function() {
			$.post("/owners/request/", 
				{
					name: form.name.value, 
					phone: form.phone.value, fax: form.fax.value, 
					email: form.email.value, rental_name: form.rental_name.value, 
					rental_address: form.rental_address.value, 
					bedrooms: form.bedrooms.options[form.bedrooms.selectedIndex].value, 
					sleeps: form.sleeps.options[form.sleeps.selectedIndex].value, 
					features: form.features.value, comments: form.comments.value
				}, function() {
				$("#content-request-processing").fadeOut('fast', function() {
					$("#content-request-sent").fadeIn('fast');
				});
			});
		});
	});
}

function sendRentalRequest() {
	
	var form = document.getElementById("vacation-request-form");
	
	// Check form data
	if (form.first_name.value=="") {
		alert("Please enter your first name.");
		form.first_name.focus();
		return(false);
	}
	
	if (form.last_name.value=="") {
		alert("Please enter your last name.");
		form.last_name.focus();
		return(false);
	}
	
	if (form.email.value=="") {
		alert("Please enter your email address.");
		form.email.focus();
		return(false);
	}
	
	if (form.day_phone.value=="") {
		alert("Please enter your daytime phone number.");
		form.day_phone.focus();
		return(false);
	}
	
	if (form.zipcode.value=="") {
		alert("Please enter your zip code.");
		form.zipcode.focus();
		return(false);
	}
	
	$("#content-request-form").fadeOut('fast', function() {
		$("#content-request-processing").fadeIn('fast', function() {
			$.post("/request/send/", 
				{
					first_name: form.first_name.value, 
					last_name: form.last_name.value, 
					address: form.address.value, 
					city: form.city.value, 
					state: form.state.value, 
					zipcode: form.zipcode.value, 
					country: form.country.value, 
					day_phone: form.day_phone.value, 
					night_phone: form.night_phone.value, 
					fax: form.fax.value, 
					email: form.email.value, 
					date_month: form.date_month.options[form.date_month.selectedIndex].value,
					date_day: form.date_day.options[form.date_day.selectedIndex].value,
					date_year: form.date_year.options[form.date_year.selectedIndex].value,
					date_month_to: form.date_month_to.options[form.date_month_to.selectedIndex].value,
					date_day_to: form.date_day_to.options[form.date_day_to.selectedIndex].value,
					date_year_to: form.date_year_to.options[form.date_year_to.selectedIndex].value,
					location: form.location.options[form.location.selectedIndex].value, 
					price_range: form.price_range.options[form.price_range.selectedIndex].value, 
					rooms: form.rooms.options[form.rooms.selectedIndex].value,
					guests: form.guests.options[form.guests.selectedIndex].value, 
					adults: form.adults.options[form.adults.selectedIndex].value,
					children: form.children.options[form.children.selectedIndex].value,
					extra_services: form.extra_services.value, 
					activities: form.activities.value, 
					special_needs: form.special_needs.value, 
					comments: form.comments.value 
				}, 
				function() {
				$("#content-request-processing").fadeOut('fast', function() {
					$("#content-request-sent").fadeIn('fast');
				});
			});
		});
	});
}

function changePhoto(id) {
	$("#main-photo").attr("src", $("#photo-"+id).attr("src"));
}

function sendInquiry() {
	
	var form = document.getElementById("inquire-form-data");
	
	$("#inquire-form").fadeOut('fast', function() {
		$("#inquire-form-submit").fadeIn('fast', function() {
			$.post("/rentals/inquire/", {
				firstname: form.firstname.value, 
				lastname: form.lastname.value, 
				emailaddress: form.emailaddress.value, 
				phonenumber: form.phonenumber.value, 
				fromdate: form.fromdate.value, 
				todate: form.fromdate.value, 
				comments: form.comments.value, 
				rentalid: form.rentalid.value 
			}, function() {
				$("#inquire-form-submit").fadeOut('fast', function() {
					$("#inquire-form-success").fadeIn('fast');
				});
			});
		});
	});
}

function searchOptions() {
	$("#hidden-search-items").slideToggle('normal', function() {
		var text = $("#search-options-link").html();
		if (text=="Show More Options") {
			$("#search-options-link").html("Hide Options");
		} else {
			$("#search-options-link").html("Show More Options");
		}
	});
}

function subscribe() {
	var email_val = $("#subscribe_email").val();
	
	if (email_val!="" && checkEmail(email_val)) { 
		$("#subscribe-image").fadeIn('fast', function() {
			$.post("/request/subscribe/", { email: $("#subscribe_email").val() }, function() {
				$("#subscribe-image").fadeOut('fast', function() {
					$("#subscribe-success").fadeIn('fast');
				});
			});
		});
	}
}

function checkName() {
	var control = document.getElementById("rentalid");
	
	if (control.options[control.selectedIndex].value=="") {
		return(false);
	}
	
	return(true);
}

function checkEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    return false
	 }

		 return true					
}