///
///	$RCSfile: lib.js,v $
///	$Author: bobby $
///	$Date: 2007/06/19 03:29:00 $
///	$Revision: 1.2 $
///

function UrlEncode(text)
{
	var SAFECHARS = "0123456789"
		+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		+"abcdefghijklmnopqrstuvwxyz"
		+"-_.!~*'()";
	var retval = "";
		
	for(var i = 0; i < text.length; i++)
	{
		if(SAFECHARS.indexOf(text.charAt(i)) != -1)
		{
			retval += text.charAt(i);
		}
		else if(text.charAt(i) == " ")
		{
			retval += "+";
		}
		else
		{
			retval += "%"+text.charCodeAt(i).toString(16);
		}
	}
	
	return retval;
}

function displayFlash(filename, width, height)
{
	document.write("<object type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" data=\""+UrlEncode(filename)+"\">");
	document.write("	<param name=\"movie\" value=\""+UrlEncode(filename)+"\" />");
	document.write("	<param name=\"menu\" value=\"false\" />");
	document.write("</object>");
}

function displayTitle(text)
{
	document.write("<object type=\"application/x-shockwave-flash\" width=\"405\" height=\"32\" data=\"Images/loader.swf?path=Images%2Ftext.swf%3Ftext%3D"+UrlEncode(UrlEncode(text))+"\">");
	document.write("	<param name=\"movie\" value=\"Images/loader.swf?path=Images%2Ftext.swf%3Ftext%3D"+UrlEncode(UrlEncode(text))+"\" />");
	document.write("	<param name=\"quality\" value=\"high\" />");
	document.write("	<param name=\"menu\" value=\"false\" />");
	document.write("	<param name=\"wmode\" value=\"transparent\" />");
	document.write("</object>");
}

/// Triggers the click event of element with <Enter> (keycode = 13) is pressed
function clickElementOnEnter(evnt, elementId)
{
	/// For IE, use window.event
	/// For FF, use evnt
	var	oEvent	= (window.event)
		? window.event
		: evnt;
	
	if(evnt.keyCode == 13)
	{
		var	element	= document.getElementById(elementId);
		
		/// If the element has a click event, invokeit
		if(element.click != null)
		{
			element.click();
		}
		/// Assume is a hyperlink
		else
		{
			window.location	= element.href;
		}
		
		return false;
	}
	
	return true;
}

/// Opens a new popup window
function openWindow(url, name, width, height)
{
	window.open(url, name, "height="+height+", location=no, menubar=no, resizable=no, scrollbars=yes, status=no, titlebar=yes, toolbar=no, width="+width);
}

/// Adds trim function to String object
String.prototype.trim	= function()
{
	return this.replace(/^\s+/, "").replace(/\s+$/, "");
}
