/****************************************************************************************
>> FORM VALIDATION << 
*****************************************************************************************/
// Enquiry Form
function validate_enquiry()
{
	if (document.enquiry._01_First_Name.value=="") {
		window.alert ("Please enter your first name.");
		document.enquiry._01_First_Name.focus();
		return false;
	}
	if (document.enquiry._02_Last_Name.value=="") {
		window.alert ("Please enter your last name.");
		document.enquiry._02_Last_Name.focus();
		return false;
	}
	// EMAIL
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.enquiry._03_Email.value)) {
		window.alert ("Please enter a valid email address (e.g., user@domain.com)");
		document.enquiry._03_Email.focus();
		return false;
	}
	if (document.enquiry._04_Phone.value=="") {
		window.alert ("Please enter your phone number.");
		document.enquiry._04_Phone.focus();
		return false;
	}
}
/* Clear Textfield on focus */
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)thefield.value = ""
}

/****************************************************************************************
>> PHOTO GALLERY << 
*****************************************************************************************/
function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
 return false;
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
    links[i].onkeypress = links[i].onclick;
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(prepareGallery);
