// verify that a textarea does not exceed a maximum length (called on keyup events)
function CheckLength(item,limit)
	{
	if(item.value.length > limit)
		{
		item.value = item.value.substring(0,limit);
		SetErroredField(item,"You cannot enter more than " + limit + " characters in this field");
		}
	}

// colour an errored field yellow
function ColorErroredField(item)
	{
	item.style.background = "#FFFF00";
	item.style.border = "1px solid highlight";
	}

// set an errored field by colour and alert the user
function SetErroredField(item,errtext)
	{
	ColorErroredField(item);
	alert(errtext);
	item.focus();
	}

// verify that a form entry does not exceed a maximum length
function ValidateLength(item,limit,errtext)
	{
	if(item.value.length > limit)
		{
		SetErroredField(item,errtext);
		return(false);
		}

	return(true);
	}

// verify a form entry is non-blank
function ValidateNonBlank(item,errtext,extra)
	{
	if(item.value == "")
		{
		// if we have an extra edit to highlight colour it first
		if(extra)
			ColorErroredField(extra)
		SetErroredField(item,errtext);
		return(false);
		}

	return(true);
	}

// validate that two form entries are identical
function ValidateIdentical(a,b,errtext)
	{
	if(a.value != b.value)
		{
		ColorErroredField(a);
		SetErroredField(b,errtext);
		return(false);
		}

	return(true);
	}

// validate that a form entry represents a non-blank value in an acceptable decimal format
function ValidateNonBlankDecimalFormat(item,pre,post,errtext)
	{
	var str = item.value;
	var points = 0;
	var wholes = 0;
	var decimals = 0;

	if(!ValidateNonBlank(item,errtext))
		return(false);

	for(var i=0;i<str.length;i++)
		{
		var ch = str.charAt(i);
		if(ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && ch != '6' && ch != '7' && ch != '8' && ch != '9' && ch != '.')
			{
			SetErroredField(item,errtext);
			return(false);
			}

		// accumulate the points
		if(ch == '.')
			points++;

		// accumulate whole places before the point
		if(points == 0 && ch != '.')
			wholes++;

		// accumulate decimal places after the point
		if(points > 0 && ch != '.')
			decimals++;
		}

	// can only have one decimal point and must be of specified format
	if(points > 1 || wholes > pre || decimals > post)
		{
		SetErroredField(item,errtext);
		return(false);
		}

	return(true);
	}

function PopPicture(szTitle,szImage,nWidth,nHeight)
	{
	var nWinWidth = nWidth + 30;
	var nWinHeight = nHeight + 40;
	var nTop = (window.screen.availHeight/2) - (nWinHeight/2) - 10;
	var nLeft = (window.screen.availWidth / 2) - (nWinWidth/2) - 10;
	var szImageUrl = "graphics/" + szImage + ".jpg";

	var wPicture = open('',szImage,'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top='+nTop+',left='+nLeft+',width='+nWinWidth+',height='+nWinHeight+'');

	wPicture.document.open();
	wPicture.document.writeln('<html><head><title>'+szTitle+'</title></head>');
	wPicture.document.writeln('<body bgcolor="#F1F1F1">');
	wPicture.document.writeln('<table height="100%" width="100%">');
	wPicture.document.writeln('<tr><td align="center">');
	wPicture.document.writeln('<img src="'+szImageUrl+'" border="1" width="'+nWidth+'" height="'+nHeight+'">');
	wPicture.document.writeln('</td></tr></table></body></html>');
	wPicture.document.close();

	wPicture.focus();
	}

function PopCamera(szTitle,szImage,nWidth,nHeight)
	{
	var nWinWidth = nWidth + 30;
	var nWinHeight = nHeight + 40;
	var nTop = (window.screen.availHeight/2) - (nWinHeight/2) - 10;
	var nLeft = (window.screen.availWidth / 2) - (nWinWidth/2) - 10;
	var szImageUrl = "cameras/" + szImage + ".jpg";

	var wPicture = open('',szImage,'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top='+nTop+',left='+nLeft+',width='+nWinWidth+',height='+nWinHeight+'');

	wPicture.document.open();
	wPicture.document.writeln('<html><head><title>'+szTitle+'</title></head>');
	wPicture.document.writeln('<body bgcolor="#F1F1F1">');
	wPicture.document.writeln('<table height="100%" width="100%">');
	wPicture.document.writeln('<tr><td align="center">');
	wPicture.document.writeln('<img src="'+szImageUrl+'" border="1" width="'+nWidth+'" height="'+nHeight+'">');
	wPicture.document.writeln('</td></tr></table></body></html>');
	wPicture.document.close();

	wPicture.focus();
	}

function showFirearm(photokey)
	{
	var height = 500;
	var width = 790;
	var top = (window.screen.availHeight/2) - (height/2);
	var left = (window.screen.availWidth / 2) - (width/2);
	var url = "showfirearm.php?photokey=" + photokey;

	var win = window.open(url,photokey,'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top='+top+',left='+left+',width='+width+',height='+height+'')
	win.focus();
	}

function zebedeeRefer()
	{
	var szReferrer = document.referrer.toLowerCase();

	if(szReferrer.indexOf('zebedee')>-1)
		window.location = "ballooning.php";
	}

function bookMark()
	{
	window.external.AddFavorite("http://www.peterlawman.co.uk","Peter Lawman");
	}
