function validate(f){
  if (!checkName(f.name.value)) {
    return false;
  }
  if(!checkEmail(f.email.value)){
	  return false;
  }
  if(!checkDate(f.day1.value+f.monyear1.value,f.day2.value+f.monyear2.value)){
	  return false;
  }
  return true;
}

function checkName(string){
 if (string == "") {
    alert("Please enter your name");
    return false;
 }
return true;	
}

function checkEmail(string){
 var pattern = /^.+@.+\..{2,3}$/;
 if (string == "") {
     	alert("Please enter your email address");
	return false;
 }
 if (!(pattern.test(string))){
	alert("Please enter a valid email address");
 	return false;
 }
 return true;
}

function checkDate(startdate,enddate){
	var sday = startdate.substr(0,2);
	var eday = enddate.substr(0,2);
	var smonth = startdate.substr(2,2);
	var emonth = enddate.substr(2,2);
	var syear = startdate.substr(4,4);
	var eyear = enddate.substr(4,4);
	var today = new Date();
	var startDate = new Date(syear,smonth-1,sday);
	var endDate = new Date(eyear,emonth-1,eday);

	//check months with 30 days
	if(smonth == "04" || smonth == "06" || smonth == "09" || smonth == "11") {
		if(sday == "31"){
			alert("Check the Start Date entered. There are only 30 days in this month!");
			return false;
		}
	}
	if(emonth == "04" || emonth == "06" || emonth == "09" || emonth == "11") {
		if(eday == "31"){
			alert("Check the End Date entered. There are only 30 days in this month!");
			return false;
		}
	}
	//Check Feb 2004
	if(smonth == "02"){
		if(sday > 29){
			alert("Check the Start Date. There are only 29 day in Feb 2004");
			return false;
		}
	}
	if(emonth == "02"){
		if(eday > 29){
			alert("Check the End Date. There are only 29 day in Feb 2004");
			return false;
		}
	}
	//check startdate is after today
	if((startDate-today)<1){
		alert("The Start Date you selected has already passed. Please select another date.");
		return false;
	}
	//check enddate is after startdate
	if((endDate-startDate)<1){
		alert("You're return date must be later than your departure date!. Please check your dates.");
		return false;
	}
	return true;
}
function swapPhoto(photoSRC,text) {


	document.images.imgPhoto.src = "images/" + photoSRC;
    	document.images.imgPhoto.alt = text;
	
    	if(document.images.imgPhoto.alt == "Sunrise from the Bedroom Balcony"){



		document.images.swap1.src = "images/beachsm.jpg";
		document.images.swap1.alt = "The Beach";
		document.images.swap1.name = "beach";
	}
	if(document.images.imgPhoto.alt == "The Beach"){
		document.images.swap1.src = "images/sunrisesmall.jpg";
		document.images.swap1.alt = "Sunrise from the Bedroom Balcony";
		document.images.swap1.name = "sunrise";
	}
    	if(document.images.imgPhoto.alt == "Sunny Bedroom"){
		document.images.swap2.src = "images/backbedroomsmall.jpg";
		document.images.swap2.alt = "Second Bedroom";
		document.images.swap2.name = "backbed";
	}
    	if(document.images.imgPhoto.alt == "Second Bedroom"){
		document.images.swap2.src = "images/mainbedroomsmall.jpg";
		document.images.swap2.alt = "Sunny Bedroom";
		document.images.swap2.name = "mainbed";
	}


	if(document.images.imgPhoto.alt == "Kitchen"){
		document.images.swap1.src = "images/swimmingpoolsm.jpg";
		document.images.swap1.alt = "Swimming Pool";
		document.images.swap1.name = "swimmingpool";
	}







/*	if(document.images.imgPhoto.alt == "Swimming Pool"){
		document.images.swap1.src = "images/kitchensm.jpg";
		document.images.swap1.alt = "Kitchen";
		document.images.swap1.name = "kitchen";
	}
    	if(document.images.imgPhoto.alt == "Kitchen"){
		document.images.swap1.src = "images/swimmingpoolsm.jpg";
		document.images.swap1.alt = "Swimming Pool";
		document.images.swap1.name = "swimmingpool";
	}
    	if(document.images.imgPhoto.alt == "Spacious Lounge"){
		document.images.swap2.src = "images/frontsm.jpg";
		document.images.swap2.alt = "Front facing the Sea";
		document.images.swap2.name = "front";
	}
    	if(document.images.imgPhoto.alt == "Front facing the Sea"){
		document.images.swap2.src = "images/loungesm.jpg";
		document.images.swap2.alt = "Spacious Lounge";
		document.images.swap2.name = "lounge";
	}
*/

}		


