/* Function to open popup window */
var newwindow;
function popopen(propertyId)
{
	newwindow=window.open('/property_listing.php?preview=yes&id=' + propertyId,'PreviewListing','width=820, height=550, scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow2;
function popopen2(url)
{
	newwindow2=window.open(url,'ShowWindow','width=400, height=550, scrollbars=yes');
	if (window.focus) {newwindow2.focus()}
}

function openSearch(){
	document.getElementById('search-box').style.display = 'block';
	document.getElementById('search-link').style.display = 'none';
}

function ValidatorEmailForm(theForm)
{

  if (theForm.name.value == "")
  {
    alert("Please enter your name");
    theForm.name.focus();
    return (false);
  }

  if (theForm.name.value.length < 4)
  {
    alert("Please provide your real name");
    theForm.name.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter your email address");
    theForm.email.focus();
    return (false);
  }

  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
	return (true);
  }
  
  alert("Please enter a valid email address so we can get back to you.");
  theForm.email.focus();
  return (false);

}


function ValidatorPropertyEmail(theForm)
{

  if (theForm.name.value == "")
  {
    alert("Please enter your name");
    theForm.name.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter your email address");
    theForm.email.focus();
    return (false);
  }

  if (theForm.message.value == "")
  {
    alert("You have not written a message to the owner");
    theForm.message.focus();
    return (false);
  }

  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
	return (true);
  }
  
  alert("Please enter a valid email address so the owner can get back to you.");
  theForm.email.focus();
  return (false);

}



function checkKidsBox() {
	document.theForm.suitability_kids.checked = true;
}

// Stage 4 - Text Limiter

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

// Stage 7 - Photos

function Validator(theForm)
{

	if((theForm.the_picture.value.lastIndexOf(".jpg")==-1) && (theForm.the_picture.value.lastIndexOf(".jpeg")==-1)
	&& (theForm.the_picture.value.lastIndexOf(".JPEG")==-1) && (theForm.the_picture.value.lastIndexOf(".JPG")==-1)) {
	   alert("Error: that does not appear to be an image file. Please check it is a jpeg.");
	   return false;
	}

	return true;

}