
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 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 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 displayStatusMsg(msgStr)
{
	status = msgStr;
	document.returnValue = true;
}

function openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
}

function goToURL()
{
	var i, args = goToURL.arguments;
	document.returnValue = false;
	for (i = 0; i < (args.length - 1); i += 2) eval(args[i] + ".location='" + args[i+1] + "'");
}

function setTextOfLayer(objName, x, newText)
{
	if ((obj = findObj(objName)) != null)
		with (obj)
		if (navigator.appName == 'Netscape')
		{
			document.write(unescape(newText));
			document.close();
		}
    else innerHTML = unescape(newText);
}

function reloadPage(init)
{
	//reloads the window if Nav4 resized
	if (init == true)
		with (navigator)
		{
			if ((appName == "Netscape") && (parseInt(appVersion) == 4))
			{
				document.pgW = innerWidth;
				document.pgH = innerHeight;
				onresize = reloadPage;
			}
		}
	else if (innerWidth != document.pgW || innerHeight != document.pgH) location.reload();
}

function GetForm(frmName)
{
	el = GetFormInDocument(document, frmName);
	if (el != null) return el; 

	if (document.all == null)
		for (var i = 0; i < document.layers.length; i++) {
			el = GetFormInDocument(document.layers[i].document, frmName);
			if (el != null) return el;
		}
	return null;
}

function GetFormInDocument(inDoc, frmName)
{
	var elForm = null;
	with (inDoc) {
		elForm = forms[frmName];
		if (elForm != null) return elForm;

		for (var i = 0; i < forms.length; i++) {
			if (forms[i].name == frmName)
				return forms[i];
			}

		if (inDoc.all == null)
			for (var i = 0; i < inDoc.layers.length; i++) {
				el = GetFormInDocument(inDoc.layers[i].document, frmName);
				if (el != null) return el;
				}
		}
		return null;
}

function GetElementInDocument(inDoc, elementName)
{
	with (inDoc) {
		for (var i = 0; i < forms.length; i++) {
			if (forms[i].name == elementName) return forms[i];
			var el = GetElementInForm(forms[i], elementName)
			if (el != null) return el;
			}
		}
	return null;
}

function GetElementInForm(inForm, elementName)
{
	var el = null;
	with (inForm) {
		el = inForm.elementName;
		if (el != null) return el;
		for (var i = 0; i < elements.length; i++)
			if (elements[i].name == elementName)
				return elements[i];
		}
	return null;
}

function GetImageInDoc(inDoc, elementName)
{
	with (inDoc)
		for (var i = 0; i < images.length; i++)
			if (images[i].name == elementName) return images[i];
	return null;
}

function GetImage(elementname)
{
	var el = GetImageInDoc(document, elementname);
	if (el != null) return el;
	
	if (document.all == null)
		for (var i = 0; i < document.layers.length; i++) {
			el = GetImageInDoc(document.layers[i].document, elementname);
			if (el != null) return el;
		}

	return null;
}

function Focus(form_name, element_name)
{
	var el = GetElementInForm(GetForm(form_name), element_name);
	el.focus();
}

function ValidateElementString(element, min_chars, max_chars, error_message, validate_status)
{
	var return_value = validate_status;
	if (element.value.length < min_chars || element.value.length > max_chars)
	{
		alert(error_message);
		if (validate_status == true)
		{
			return_value = false;
			element.focus();
		}
	}
	return return_value;
}

function openWindow(theURL, width, height)
{
	window.open(theURL, "popup", "status=yes,scrollbars=yes,width=" + width + ",height=" + height);
}

function ValidateSearchForm()
{
	var validate = true;
	var f = GetForm('search_form');
	if (f)
	{
		validate = ValidateElementString(f.keywords, 2, 100, 'Please enter your keywords to begin search, 2 characters minimum.', validate);
	}
	return validate;
}
