function submitSearch( defaultQuery )
{
	if ( document.searchform.query.value == defaultQuery )
		document.searchform.query.value = "";
	if ( document.searchform.query.value == "" )
	{
		document.searchform.query.focus();
		return false;
	}
	document.searchform.tfoto.value = "cm,rf";
	if ( document.searchform.rm.checked && !document.searchform.rf.checked )
		document.searchform.tfoto.value = "cm";
	else if ( !document.searchform.rm.checked && document.searchform.rf.checked )
		document.searchform.tfoto.value = "rf";
	return true;
}

function validate()
{
	var el1 = eval( "document.forms['search'].term" );
	if ( el1 == null )
		return false;
	var searchTerm = trim( el1.value );
	if ( searchTerm.length == 0 )
	{
		alert( "Please enter your search criteria in the search field." );
		document.forms["search"].term.focus();
		return false;
	}
	if ( el1.value.indexOf( ">" ) >= 0 || el1.value.indexOf( "<" ) >= 0 )
	{
		alert( "Entry may not contain '<' and '>'." );
		document.forms["search"].term.focus();
		return false;
	}
	el2 = eval( "document.forms['search'].RM" );
	el3 = eval( "document.forms['search'].RF" );
	if ( el2 == null || el3 == null )
		return false;
	if ( !el2.checked && !el3.checked )
	{
		alert( "Please select at least one image type." );
		return false;
	}
	return true;
}

function trim( sData )
{
	if ( sData.length == 0 )
		return sData;
	else
		return sData.replace( /(^\s*)|(\s*$)/g, "" );
}

function HandleSearch()
{
	if ( validate() )
		document.forms["search"].submit();
	return true;
}

function setfocus()
{
	var el1 = eval( "document.forms['search'].term" );
	if ( el1 != null )
		el1.focus();
}

function HandleEnterKey()
{
	if ( event.keyCode == 13 )
	{
		var elButton = eval( "document.forms['search'].btnsearch" );
		if ( elButton != null )
		{
			event.cancelBubble = true;
			event.returnValue = false;
			if ( IsSafari() )
				eval( elButton.onClick );
			else
				elButton.click();
		}
	}
}

function IsSafari()
{
	var detectedSafari = false;
	var userAgent = navigator.userAgent;
	if ( typeof( userAgent ) != "undefined" )
	{
		if ( userAgent.toUpperCase().indexOf("APPLEWEBKIT") > -1 )
			detectedSafari = true;
	}
	return detectedSafari;
}

var viewport =
{
	getWinWidth: function()
	{
		this.width = 0;
		if ( window.innerWidth )
			this.width = window.innerWidth - 18;
		else if ( document.documentElement && document.documentElement.clientWidth )
			this.width = document.documentElement.clientWidth;
		else if ( document.body && document.body.clientWidth )
			this.width = document.body.clientWidth;
	},
	getWinHeight: function()
	{
		this.height = 0;
		if ( window.innerHeight )
			this.height = window.innerHeight - 18;
		else if ( document.documentElement && document.documentElement.clientHeight )
			this.height = document.documentElement.clientHeight;
		else if ( document.body && document.body.clientHeight )
			this.height = document.body.clientHeight;
	},
	getScrollX: function()
	{
		this.scrollX = 0;
		if ( typeof( window.pageXOffset ) == "number" )
			this.scrollX = window.pageXOffset;
		else if ( document.documentElement && document.documentElement.scrollLeft )
			this.scrollX = document.documentElement.scrollLeft;
		else if ( document.body && document.body.scrollLeft )
			this.scrollX = document.body.scrollLeft;
		else if ( window.scrollX )
			this.scrollX = window.scrollX;
	},
	getScrollY: function()
	{
		this.scrollY = 0;
		if ( typeof( window.pageYOffset ) == "number" )
			this.scrollY = window.pageYOffset;
		else if ( document.documentElement && document.documentElement.scrollTop )
			this.scrollY = document.documentElement.scrollTop;
		else if ( document.body && document.body.scrollTop )
			this.scrollY = document.body.scrollTop;
		else if ( window.scrollY )
			this.scrollY = window.scrollY;
	},
	getAll: function()
	{
		this.getWinWidth();
		this.getWinHeight();
		this.getScrollX();
		this.getScrollY();
	}
}
