function validate_image_form(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.address.value == ""){
alert("Please enter your address.");
theForm.address.focus();
return (false);
}

if (theForm.postcode.value == ""){
alert("Please enter your postcode.");
theForm.postcode.focus();
return (false);
}

if (theForm.age.value == ""){
alert("Please enter your age.");
theForm.age.focus();
return (false);
}

if (theForm.image_title.value == ""){
alert("Please enter the title of your piece.");
theForm.image_title.focus();
return (false);
}



var emailaddress=theForm.email.value;
if (checkemailaddress(emailaddress)==false) {
alert("Please enter a valid email address."); 
theForm.email.focus();
return (false);
}

return (true);
}
function checkemailaddress (emailStr) {
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

var matchArray=emailStr.match(emailPat);
if (matchArray==null)
return false;

var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127)
return false;
}

for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127)
return false;
}

if (user.match(userPat)==null)
return false;

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255)
return false;
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1)
return false;
}

if (len<2)
return false;

return true;
}
