// Elizabeht Clark Scripts
//Pop-up script


function largePic(picRef) {
picRef= "gallery/"+ picRef
 gWindow = window.open (picRef, "galleryWindow","location=0,status=0,scrollbars=0,width=620,height=620");
 gWindow.focus();

}


// Form validation


//name, email and telephone

function validateForm(f) {

// Strip whitespace and place into variables
	name				= stripWhitespace(f.name.value);
	email				= stripWhitespace(f.email.value);
	telephone			= stripWhitespace(f.telephone.value);
	
	
	// Check required fields have information
	if(name.length == 0)						{ alert('Please tell us your name'); f.name.focus(); return false; }
	if(email.length == 0)						{ alert('Please enter your email address'); f.email.focus(); return false; }
	if(!validateEmail(email))				{ alert('This email address does not appear to be valid, please check it'); f.email.focus(); return false; }
	if(telephone.length == 0)			{ alert('Please enter your phone number'); f.telephone.focus(); return false; }
	if(!validateTelephone(telephone)) 	{alert ('This telephone number does not appeat to be valid, please check and try again'); f.telephone.focus(); return false;  }
	
	
	
	// If all ok then return true (validation passed)
	
	return true;

}







/* Function to validate email */
function validateEmail(email) {
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(email);
}
/* Function to validate Telephone number, ie 11-13 digits */

function validateTelephone(telephone) {
telephone = telephone.replace (/[^\d]/g,'');
var regex = /^\d{11,13}/;
return regex.test(telephone);
}

/* Remove white space from start & end of string */
function stripWhitespace(str) {
	str = this != window ? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}





