function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function helpPopUp(helpURL)
	{
	win = window.open(helpURL, "PopUp", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizeable=yes,copyhistory=no,width=320,height=240")
	if (parseInt(navigator.appVersion) >= 4) {
	win.window.focus();
	}
}

function validateAmCat(amenityCategory){
	if(amenityCategory.amenityCategory.value==""){
		alert("You haven't entered a Category Name.\nPlease complete this section to continue.")
		amenityCategory.amenityCategory.focus()
		return false
	}
}

function validateEventCat(eventCategory){
	if(eventCategory.eventCategory.value==""){
		alert("You haven't entered a Category Name.\nPlease complete this section to continue.")
		eventCategory.eventCategory.focus()
		return false
	}
}

function validatePartCat(participantCategory){
	if(participantCategory.partCatName.value==""){
		alert("You haven't entered a Category Name.\nPlease complete this section to continue.")
		participantCategory.partCatName.focus()
		return false
	}
}

function validateBullNo(bulletinNo){
	if(bulletinNo.bulletinNo.value==""){
		alert("You haven't entered a Bulletin Number.\nPlease complete this section to continue.")
		bulletinNo.bulletinNo.focus()
		return false
	}
}

function validateNews(news){
	if(news.day.value==""){
		alert("You haven't entered a day.\nPlease make a selection to continue.")
		news.day.focus()
		news.day.select()
		return false
	}

	if(news.month.value==""){
		alert("You haven't entered a Month.\nPlease complete this section to continue.")
		news.month.focus()
		news.month.select()
		return false
	}

	if(news.year.value==""){
		alert("You haven't entered a Year.\nPlease complete this section to continue.")
		news.year.focus()
		news.year.select()
		return false
	}

	if(news.newsTitle.value==""){
		alert("You haven't entered a News Title.\nPlease complete this section to continue.")
		news.newsTitle.focus()
		news.newsTitle.select()
		return false
	}

	if(news.newsDetails.value==""){
		alert("You haven't entered any Details.\nPlease complete this section to continue.")
		news.newsDetails.focus()
		news.newsDetails.select()
		return false
	}
}

function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {							// cannot be empty
		return false
	}
	
	for (i=0; i<invalidChars.length; i++) {		// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	
	atPos = email.indexOf("@",1)				// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	
	if (email.indexOf("@",atPos+1) != -1) {		// and only one "@" symbol
		return false
	}
	
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {						// and at least one "." after the "@"
		return false
	}
	
	if (periodPos+3 > email.length)	{			// must be at least 2 characters after the "."
		return false
	}
	
	return true
}

function RUSure() {
	if(confirm("Are you sure you want to delete the selected item(s) from the Database?")){
		return true
	}
	else  {
		return false
	}
}

function checkme(newEdit){
	chooseOption = -1
	for(i=0; i < newEdit.selectme.length; i++){
		if(newEdit.selectme[i].checked){
			chooseOption = i
		}
	}

	if(chooseOption == -1){
		alert("You haven't selected an item to edit.\nPlease make a selection to continue.")
		return false
	}
}

function validateMail(mailList) {
	// check to see if a name has been entered
	if(mailList.name.value==""){
		alert("You haven't entered your Name.\nPlease complete this section to continue.")
		mailList.name.focus()
		mailList.name.select()
		return false
	}

	// check to see if the email is valid
	if (!validEmail(mailList.email.value)) {
		alert("You have entered an invalid Email Address.\nPlease complete this section correctly to continue.")
		mailList.email.focus()
		mailList.email.select()
		return false
	}
}

function validateExhibit(exhibit){
	if(exhibit.title.value==""){
		alert("You haven't selected a Title.\nPlease make a selection to continue.")
		exhibit.title.focus()
		return false
	}

	if(exhibit.givenName.value==""){
		alert("You haven't entered a Given Name.\nPlease complete this section to continue.")
		exhibit.givenName.focus()
		exhibit.givenName.select()
		return false
	}

	if(exhibit.surname.value==""){
		alert("You haven't entered a Surname.\nPlease complete this section to continue.")
		exhibit.surname.focus()
		exhibit.surname.select()
		return false
	}

	//if (!validEmail(exhibit.email.value)) {
		//alert("You have entered an invalid Email Address.\nPlease complete this section correctly to continue.")
		//exhibit.email.focus()
		//exhibit.email.select()
		//return false
	//}

	if(exhibit.address1.value==""){
		alert("You haven't entered an Address.\nPlease complete this section to continue.")
		exhibit.address1.focus()
		exhibit.address1.select()
		return false
	}

	if(exhibit.town.value==""){
		alert("You haven't entered a Town/City.\nPlease complete this section to continue.")
		exhibit.town.focus()
		exhibit.town.select()
		return false
	}

	if(exhibit.postcode.value==""){
		alert("You haven't entered a Postcode.\nPlease complete this section to continue.")
		exhibit.postcode.focus()
		exhibit.postcode.select()
		return false
	}

	if(exhibit.phone.value==""){
		alert("You haven't entered a Phone Number.\nPlease complete this section to continue.")
		exhibit.phone.focus()
		exhibit.phone.select()
		return false
	}

	if(exhibit.exhibitTitle.value==""){
		alert("You haven't entered the Exhibit Title.\nPlease complete this section to continue.")
		exhibit.exhibitTitle.focus()
		exhibit.exhibitTitle.select()
		return false
	}

	if(exhibit.className.value==""){
		alert("You haven't selected a Class.\nPlease make a selection to continue.")
		exhibit.className.focus()
		return false
	}

	if(exhibit.description.value==""){
		alert("You haven't entered a Description.\nPlease complete this section to continue.")
		exhibit.description.focus()
		exhibit.description.select()
		return false
	}

	if(exhibit.frames.value==""){
		alert("You haven't entered the Number of Frames.\nPlease complete this section to continue.")
		exhibit.frames.focus()
		exhibit.frames.select()
		return false
	}

	if(exhibit.height.value==""){
		alert("You haven't entered the sheet Height.\nPlease complete this section to continue.")
		exhibit.height.focus()
		exhibit.height.select()
		return false
	}

	if(exhibit.width.value==""){
		alert("You haven't entered the sheet Width.\nPlease complete this section to continue.")
		exhibit.width.focus()
		exhibit.width.select()
		return false
	}

	chooseOption = -1
	for(i=0; i < exhibit.deliveryMethod.length; i++){
		if(exhibit.deliveryMethod[i].checked){
			chooseOption = i
		}
	}

	if(chooseOption == -1){
		alert("You haven't selected a Delivery Method,\nPlease make a selection to continue.")
		return false
	}

	chooseOption2 = -1
	for(i=0; i < exhibit.returnMethod.length; i++){
		if(exhibit.returnMethod[i].checked){
			chooseOption2 = i
		}
	}

	if(chooseOption2 == -1){
		alert("You haven't selected a Return Method,\nPlease make a selection to continue.")
		return false
	}
}

function validateFeedback(feedback) {
	// check to see if a name has been entered
	if(feedback.name.value==""){
		alert("You haven't entered your Name.\nPlease complete this section to continue.")
		feedback.name.focus()
		feedback.name.select()
		return false
	}

	// check to see if the email is valid
	if (!validEmail(feedback.email.value)) {
		alert("You have entered an invalid Email Address.\nPlease complete this section correctly to continue.")
		feedback.email.focus()
		feedback.email.select()
		return false
	}

	if(feedback.comments.value==""){
		alert("You haven't entered any Comments.\nPlease complete this section to continue.")
		feedback.comments.focus()
		feedback.comments.select()
		return false
	}
}

function validateSearch(search) {
	// check to see if a name has been entered
	if(search.keyword.value==""){
		alert("Please enter a Keyword to continue.")
		search.keyword.focus()
		search.keyword.select()
		return false
	}
}

function checkRemove(removeMe) {
	// check to see if the email is valid
	if (!validEmail(removeMe.email.value)) {
		alert("You have entered an invalid Email Address.\nPlease complete this section correctly to continue.")
		removeMe.email.focus()
		removeMe.email.select()
		return false
	}
}

function checkSelect(selection) {
	if (selection.selectMe.value=="") {
		alert("Please make a selection to continue.")
		selection.selectMe.focus()
		return false
	}
}

function validateBulletin(bulletin){
	if(bulletin.bulletinNo.value==""){
		alert("You haven't selected a Bulletin No.\nPlease make a selection to continue.")
		bulletin.bulletinNo.focus()
		return false
	}
	
	if(bulletin.itemNo.value==""){
		alert("You haven't entered an Item No.\nPlease complete this section to continue.")
		bulletin.itemNo.focus()
		bulletin.itemNo.select()
		return false
	}

	if(bulletin.headline.value==""){
		alert("You haven't entered a Headline.\nPlease complete this section to continue.")
		bulletin.headline.focus()
		bulletin.headline.select()
		return false
	}

	if(bulletin.text.value==""){
		alert("You haven't entered any Details.\nPlease complete this section to continue.")
		bulletin.text.focus()
		bulletin.text.select()
		return false
	}
}

function validateParticipants(participants) {
	if(participants.partCategory.value==""){
		alert("You haven't selected a Category.\nPlease make a selection to continue.")
		participants.partCategory.focus()
		return false
	}

	if(participants.standNo.value==""){
		alert("You haven't entered a Stand No.\nPlease complete this section to continue.")
		participants.standNo.focus()
		participants.standNo.select()
		return false
	}

	if(participants.partName.value==""){
		alert("You haven't entered a Participant Name.\nPlease complete this section to continue.")
		participants.partName.focus()
		participants.partName.select()
		return false
	}
}

function validatePersonnel(personnel) {
	if(personnel.name.value==""){
		alert("You haven't entered a Name.\nPlease complete this section to continue.")
		personnel.name.focus()
		personnel.name.select()
		return false
	}

	if(personnel.role.value==""){
		alert("You haven't entered a Role.\nPlease complete this section to continue.")
		personnel.role.focus()
		personnel.role.select()
		return false
	}

	if(personnel.roleType.value==""){
		alert("You haven't selected a Role Type.\nPlease make a selection to continue.")
		personnel.roleType.focus()
		return false
	}
}

function validateGuide(visitorGuide) {
	if(visitorGuide.amenityCategory.value==""){
		alert("You haven't selected a Category.\nPlease make a selection to continue.")
		visitorGuide.amenityCategory.focus()
		return false
	}

	if(visitorGuide.amenityName.value==""){
		alert("You haven't entered a Name.\nPlease complete this section to continue.")
		visitorGuide.amenityName.focus()
		visitorGuide.amenityName.select()
		return false
	}

	if(visitorGuide.amenityAddress1.value==""){
		alert("You haven't entered an Address.\nPlease complete this section to continue.")
		visitorGuide.amenityAddress1.focus()
		visitorGuide.amenityAddress1.select()
		return false
	}

	if(visitorGuide.amenityTown.value==""){
		alert("You haven't entered a Suburb.\nPlease complete this section to continue.")
		visitorGuide.amenityTown.focus()
		visitorGuide.amenityTown.select()
		return false
	}

	if(visitorGuide.amenityPostcode.value==""){
		alert("You haven't entered a Postcode.\nPlease complete this section to continue.")
		visitorGuide.amenityPostcode.focus()
		visitorGuide.amenityPostcode.select()
		return false
	}

	if(visitorGuide.amenityPhone.value==""){
		alert("You haven't entered a Phone Number.\nPlease complete this section to continue.")
		visitorGuide.amenityPhone.focus()
		visitorGuide.amenityPhone.select()
		return false
	}
}

function validateGallery(gallery) {
	if(gallery.caption.value==""){
		alert("You haven't entered a Caption.\nPlease complete this section to continue.")
		gallery.caption.focus()
		gallery.caption.select()
		return false
	}
}

function validateEvents(events) {
	if(events.eventCategory.value==""){
		alert("You haven't selected a Category.\nPlease make a selection to continue.")
		events.eventCategory.focus()
		return false
	}

	if(events.day.value==""){
		alert("You haven't selected a Day.\nPlease make a selection to continue.")
		events.day.focus()
		return false
	}

	if(events.hour.value==""){
		alert("You haven't entered an Event Hour.\nPlease complete this section to continue.")
		events.hour.focus()
		events.hour.select()
		return false
	}

	if(events.minute.value==""){
		alert("You haven't entered the Minutes.\nPlease complete this section to continue.")
		events.minute.focus()
		events.minute.select()
		return false
	}

		if(events.eventName.value==""){
		alert("You haven't entered the Event Name.\nPlease complete this section to continue.")
		events.eventName.focus()
		events.eventName.select()
		return false
	}

	if(events.eventDetails.value==""){
		alert("You haven't entered any Event Details.\nPlease complete this section to continue.")
		events.eventDetails.focus()
		events.eventDetails.select()
		return false
	}
}

function validateSiteMap(sitemap){
	if(sitemap.pageName.value==""){
		alert("You haven't entered a Page Name.\nPlease complete this section to continue.")
		sitemap.pageName.focus()
		sitemap.pageName.select()
		return false
	}

	if(sitemap.pageURL.value==""){
		alert("You haven't entered the Page File Name.\nPlease complete this section to continue.")
		sitemap.pageURL.focus()
		sitemap.pageURL.select()
		return false
	}
}

