// given any object within a form, this function will find the containing form and submit it
function submitForm(object)
{
	document.forms[0].submit();
}

// Given an object and a type of ancestor to find, locates the first ancestor of the given object that is of the specified type.
// If none is found, null is returned
function findAncestor(object, type)
{
	oParent = object.parentElement;
	while (oParent != null)
	{
		if (oParent.tagName == type)
			return oParent;
		oParent = oParent.parentElement;
	}
	return null;
}

// returns an array of the url parameters, with each element in the form of "param=value"
function GetURLParameters()
{
	var url = window.document.URL.toString();
	
	if (url.indexOf("?") > 0)
	{
		var parts = url.split("?");
		var paramsArray = parts[1].split("&");
		return paramsArray;
	}
	return null;
}

// given a URL parameter name, finds the parameter in the URL string and returns its value, or null if not found
function FindURLParameter(paramName)
{
	paramName = paramName.toUpperCase();
	var paramsArray = GetURLParameters();
		for (i=0;i<paramsArray.length;i++)
		{
			var sParam =  paramsArray[i].split("=");
			if (sParam[0].toUpperCase() == paramName)
				return sParam[1];
		}	
	return null;
}

// opens a window given the url, paramaters to pass and a size
function ShowWindow(url, args, width, height) 
{
	var cursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.open(url, "Dialog", "status=no,scrollbars=yes,menubar=yes,width=" + width + ",height=" + height);
	document.body.style.cursor = cursor;
	return result;
}

// opens a dialog given the url, paramaters to pass and a size
function ShowDialog (url, args, width, height) 
{
	var cursor = document.body.style.cursor;
	document.body.style.cursor = "wait";
	var result = window.open(url, "Dialog", "status=no,width=" + width + ",height=" + height);
	document.body.style.cursor = cursor;
	return result;
}

// Shows the larger version of a picture
function ViewLarger(pictureURL)
{
	var picWindow = window.open("", "", 'width=560,height=400,');
	picWindow.document.write('<div style="width:100%; text-align:center; font-family:verdana,tahoma,arial,helvetica; font-size:80%;"><img src="' + pictureURL + '" border=0 /><br />');
	picWindow.document.write('<a href="javascript:window.close();">Close window</a></div>');
}