function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function showphoto(img) {
	foto= new Image(400,300);
	foto.src=(img);
	w=window.open("","showphoto","width=400,height=300");
	w.document.open();
	w.document.write("<title>Rudy Garcia</title><body topmargin='0' leftmargin='0'>");
	w.document.write("<img src='"+img+"'></body>");
	w.focus();

}

function showphoto1(img) {
	w=window.open("showpicture.html","smallwin","width=300,height=225");
	w.focus();


}

function showform(ref) {
	filename="requestdetails.php?ref="+ref;
	w=window.open(filename,"","width=430,height=330");
}
	

function display_message() {
	w=window.resizeTo(280,160);
	self.setTimeout('self.close()',3000);

}


function validate(f) {
  if (!checkName(f.name.value)) {
    return false;
  }
  if(!checkEmail(f.email.value)){
	  return false;
  }
  return true;
}

function validate_entry(f) {
  	if(!checkRef(f.ref.value)) {
		return false;
  	}
	if(!checkNumber("Bedrooms",f.bedrooms.value)) {
		return false;
  	}
  	if(!checkNumber("Bathrooms",f.bathrooms.value)) {
		return false;
  	}
  	if(!checkPrice(f.price.value)) {
		return false;
  	}
  	return true;
}

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

function checkNumber(name,value) {
	if(value) {
		//var v = parseInt(value);
		if(isNaN(value)) {
			alert(name+" must be empty or contain a whole number");
			return false;
		}
	}
	return true;
}
function checkPrice(value) {
	value=value.replace(',','');
	if(isNaN(value)) {
		alert(name+" Price must be empty or contain a whole number");
	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 loadimages(ref) {
	(new Image(300,225)).src="images/"+ref+"a.jpg";
	(new Image(300,225)).src="images/"+ref+"b.jpg";
	(new Image(300,225)).src="images/"+ref+"c.jpg";
	(new Image(300,225)).src="images/"+ref+"d.jpg";
}

//This function is not currently used
//It is a prototype of a fucntion to load pics dynamically
function loadimagesdynamically(ref) {
 
 image1 = new Image();
 image1.src="images/"+ref+"1.jpg";
 if(image1.width)
  {
   document.images.img1.src = image1.src;
  }
  else
  {
    alert("image does not exist");
  }
}



















function preload() {
	(new Image(180,22)).src="images/cblancai.gif";
	(new Image(180,22)).src="images/ccalidai.gif";
	(new Image(180,22)).src="images/cdealii.gif";
	(new Image(180,22)).src="images/cdelaluzi.gif";
	(new Image(180,22)).src="images/cdelsoli.gif";
}
































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 oldswapPhoto(photoSRC,text) {
	document.images.imgPhoto.src = "images/" + photoSRC;
    	document.images.imgPhoto.alt = text;
	
    	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";
	}


}
function swapPhoto(photoSRC,text) {
	document.images.mainphoto.src = "images/" + photoSRC +".jpg";
    	document.images.mainphoto.alt = text;
}		