﻿function showForm()
{
 if (document.getElementById('contact').style.display == 'none')
 {
  document.getElementById('contact').style.display = 'block';
  document.getElementById('property-search-photos').style.display = 'none';
 }
 else
 {
  document.getElementById('contact').style.display = 'none';
  document.getElementById('property-search-photos').style.display = 'block';
 }
}


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


function ValidateForm(form)
{
 errorMessage = '';
 fieldCount = document.getElementsByTagName('input');
 for (x=0; x<fieldCount.length; x++)
  if (fieldCount[x].className == 'required' && trim(fieldCount[x].value) == '')
	 errorMessage += ' - ' + fieldCount[x].name.substr(7) + '\n';

 fieldCount = document.getElementsByTagName('textarea');
 for (x=0; x<fieldCount.length; x++)
  if (fieldCount[x].className == 'required' && trim(fieldCount[x].value) == '')
	 errorMessage += ' - ' + fieldCount[x].name.substr(7) + '\n';

 if (errorMessage != '')
 {
  alert('Before we can submit your enquiry, please complete the following fields:\n' + errorMessage);
  return false;
 }
 
 return true;
}
