﻿// Javascript functions
function reload(filename,title)
{
	document.mainform.filename.value=filename;
	document.mainform.title.value=title;
	document.mainform.submit();
} // reload

var pic = null;
var popImg = null;  // use this when referring to pop-up image
var picTitle = null;
var imgCount = 0;
var imgWinName = "popImg";

function openPopImg(picName, windowTitle, windowWidth, windowHeight)
{
	closePopImg();
	picTitle = "Image " + windowTitle;
	imgWinName = "popImg" + imgCount++; //unique name for each pop-up window
	popImg = openPopImgWin(imgWinName, picName, windowWidth, windowHeight);
} // openPopImg

function closePopImg()
{
	// close pop-up window if it is open unless early version of IE
	if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4)
		if(popImg != null) if(!popImg.closed) popImg.close();
} // closePopImg

function openPopImgWin(imgWinName, picName, windowWidth, windowHeight)
{
	var leftX = 20;  // distance of window's left side from left of screen
	var topY = 20;   // distance of window's top side from top of screen
	var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight;
	if (leftX>0)
	{
		winFeatures += ",screenX=" + leftX + ",left=" + leftX + ",screenY=" + topY + ",top=" + topY
	}
	return window.open("pimg.php?imagefile="+picName, "" + imgWinName, winFeatures);
}

function setStatus(msg)
{
	status = msg;
	return true;
} // setStatus

function checkEmail(str)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))
		return true;
	return false;
} // checkEmail

function checkform()
{
	// Name field is required
	if(document.contactform.name.value=="")
	{
		alert("WARNING:\n\nYour name is required.");
		document.contactform.name.focus();
		return;
	} // if
	name=document.contactform.name.value;
	
	// Email and/or phone required
	if(document.contactform.email.value=="")
	{
		alert("WARNING:\n\nYour email address is required.");
		document.contactform.email.focus();
		return;
	} // if

	// Check for proper email address form
	eStr=document.contactform.email.value;
	if(!checkEmail(eStr))
	{
		str ="WARNING:\n\nThe email address provided does not look ";
		str+="like a valid email address.\n\nPlease re-enter your email address.";
		alert(str);
		document.contactform.email.focus();
		return;
	} 	
	
	// Check message
	if(document.contactform.message.value=="")
	{
		// Check for comments
		alert("WARNING:\n\nA message is required.");
		document.contactform.message.focus();
		return;
	}

	// Submit form
	document.contactform.submit();
} // checkform

function clearform()
{
	document.contactform.name.value="";
	document.contactform.email.value="";
	document.contactform.message.value="";
	document.contactform.secret.value="";
	document.contactform.name.focus();	
} // clearform
