// Gallery image open function. Copyright Craig Lawson 2001. All rights reserved

function openPic(imgFile,imgWidth,imgHeight,imgAlt,collection,collection_name,subset_name) {
		 var theLink = 'gallery/picture.php?filename='
			+ imgFile + '&width=' + imgWidth + '&height=' + imgHeight + '&alt=' + imgAlt +
			'&collection=' + collection  + '&collection_name=' + collection_name + '&subset_name=' + subset_name;
		 var winWidth = imgWidth + 30;
		 if (winWidth < 400) { winWidth = 400; }
		 var winHeight = imgHeight + 150;
		 var winSize = "width=" + winWidth + ",height=" + winHeight;
		 window.open(theLink,'',winSize);
		 }

// End of gallery image open function

// Email form field validity checker

function IsEmailValid(FormName,MailElement)
{
   var EmailOk = true
   var TheMailElement = document.forms[FormName].elements[MailElement]

   var AtSym = TheMailElement.value.indexOf('@')
   var Length = TheMailElement.value.length - 1   // Array is from 0 to length-1

   // Check a valid e-mail address has been entered
   if ((AtSym < 1)  ||	(AtSym == Length)) // '@' cannot be in first or last position.
   {
   	  EmailOk = false
   	  alert('You must enter a valid E-Mail address.')
   	  TheMailElement.focus()
   }
   return EmailOk
}

// End of Mail form validity checker


// Blank form field checker

function IsElementBlank(FormName,ElementName)
{
   var ElementOk = true
   var TheElement = document.forms[FormName].elements[ElementName]

   // Check the field hasn't been left blank
   if (TheElement.value.length == 0)
   {
   	  ElementOk = false
   	  alert('You must enter some text in the ' + ElementName + ' box.')
   	  TheElement.focus()
   }
   return ElementOk
}

// End of Blank form field checker function


// Mail form check and submit function

function IsFormValid(FormName,EmailElement,SubjectElement,MessageElement)
{
   var FormOk = true
   var EmailField = IsEmailValid(FormName,EmailElement)

   if (EmailField == false)
   {
   	  FormOk = false;
   	  return FormOk;
   }

   var SubjectField = IsElementBlank(FormName,SubjectElement)
   if (SubjectField == false)
   {
   	  FormOk = false;
   	  return FormOk;
   }

   var MessageField = IsElementBlank(FormName,MessageElement)
   if (MessageField == false)
   {
   	  FormOk = false;
   	  return FormOk;
   }

   if (FormOk == true)
   {
   	  document.forms[FormName].submit();
   	  return FormOk;
   }
}

// End of Mail form check and submit function
