// opens a new window
function newWindow(url) 
{
  var win = open(url);
}

// removes trailing spaces from string
function rtrim(string)
{
        return string.replace(/\s+$/gi, "");
}
 
// removes leading spaces from string
function ltrim(string)
{
        return string.replace(/^\s*/gi, "");
}
 
// removes trailing and leading spaces from string
function trim(string)
{
        return ltrim(rtrim(string));
}


// Returns an upper-cased extension.
function getExtension (text)
{
        return text.substr(text.lastIndexOf('.')).toUpperCase();
}


// Returns true if a GIF or a JPG.
function gifOrJpg (text)
{
        var extension = getExtension(text);

        return extension == ".GIF" || extension == ".JPG"
}


// checks required fields on a form
// you can pass in an arbitrary number of parameters
// parameters must be made up of a seqence of field and label.  
// Label will be displayed in the message box if the field is missing.
// e.g. checkRequiredFields(field1, "Description")
// if field1 is blank, a message box will display the following
// Description is required
// focus will then be set to that field
function checkRequiredFields()
{
	if( (arguments.length % 2) != 0 )
	{
		alert("Invalid parameter list [checkRequiredFields]");
		return false;
	}
	
	for( var i = 0; i < arguments.length; i += 2)
	{
		if( trim(arguments[i].value) == "" )
		{
			alert( arguments[i+1] + " is required." );
			arguments[i].focus();
			return false;
		}
	}
	
	return true;
}

// checks the length of fields
// you can pass in an arbitrary number of parameters
// parameters must be made up of a seqence of field, length, and label.  
// Label will be displayed in the message box if the field is too long.
// e.g. checkRequiredFields(field1, 25, "Description")
// if field1.length > 25 then , a message box will display the following
// Description is too long.
// focus will then be set to that field
function checkFieldLengths()
{
	if( (arguments.length % 3) != 0 )
	{
		alert("Invalid parameter list [checkFieldLengths]");
		return false;
	}

	for( var i = 0; i < arguments.length; i += 3)
	{
		if( arguments[i].value.length > arguments[i+1] )
		{
			alert( arguments[i+2] + " is too long." );
			arguments[i].focus();
			return false;
		}
	}
	
	return true;
}
