/**
 * Function to bust out of frames.
 * Frame Buster - code by Gordon McComb
 */
function fBustFrames() 
{
	if (self.parent.frames.length != 0)
	{
		self.parent.location=document.location;
	}
}


/**
 * Do nothing
 */
function noop() {}

/**
 * Hide an HTML element
 */
function fHideElement( elemId )
{
	var e = document.getElementById( elemId );
	
	e.style.display = 'none';
	e.style.visibility = 'hidden';
}

/**
 * Show an HTML element
 */
function fShowElement( elemId )
{
	var e = document.getElementById( elemId );
	
	e.style.display = 'block';
	e.style.visibility = 'visible';
}

/**
 * Show or hide all elements that have the given ID, and are or
 * The same HTML element tag name (e.g., tr, td, etc.)
 */
function fShowOrHideAll( tagName,  withId, hideOrShow )
{
	var e = document.getElementsByTagName( tagName );
	
	for (var i = 0; i < e.length; i++ )
	{
		if ( e[i].id.indexOf( withId ) != -1 )
		{
			if ( hideOrShow == false )
			{
				e[i].style.display = 'none';
				e[i].style.visibility = 'hidden';
			}
			else
			{
				e[i].style.display = '';
				e[i].style.visibility = 'visible';
			}			
		}
	}
}

/**
 * Check all checkboxes
 */
function fCheckAll( ctrlName, trueOrFalse )
{
	var e = document.getElementsByName(ctrlName);
	var n = e.length;

	if ( n == null )
	{
		e.checked = trueOrFalse;
	}
	else
	{
		for ( i = 0; i < n; i++ )
		{
			e[i].checked = trueOrFalse;
		}
	}
}


/**
 * Open a standard popup window using provided settings
 */
function fkOpenPopupWindow(url, windowName, settings) 
{
	if ( settings == null )
	{
		settings = 'location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=400';
	}
	return window.open(url, windowName, settings);
}

 
/**
 * Open a popup window centered on the screen
 */
function fOpenCenteredPopupWindow(url, windowName, windowWidth, windowHeight, settings ) 
{
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;

	if ( settings == null ) 
	{
		settings = 'location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes';
	}

	settings = settings + ",width=" + windowWidth + ",height=" + windowHeight + ",top=" + windowY + ",left=" + windowX;

	return window.open(url, windowName, settings);
}


/**
 * Ajax Functions
 */
function fGetXmlHttpRequestObject( error_div_id ) 
{
	if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest();
	} 
	else if(window.ActiveXObject) 
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
		document.getElementById( error_div_id ).innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.';
	}
}




function fGetAjaxContentForDiv( url, div_id ) 
{
	var httpReq =fGetXmlHttpRequestObject( div_id );
	
	httpReq.onreadystatechange = function() 
	{ 
       	if ( httpReq.readyState==4 || httpReq.readyState == 0 )
       	{
           	if ( httpReq.status == 200 )
           	{
               	var htmlDoc = httpReq.responseText;
				var theDiv = document.getElementById( div_id );
				theDiv.innerHTML = htmlDoc;
           }
        }
   	}
	
	httpReq.open("GET", url, true);
	httpReq.send(null);
}

	


/**
 * This is an array of functions that should be called
 * during the onload event.  Pages should call registerOnLoadEvent()
 * to add to the array
 */
var fLoadEventFunctions = new Array();
var fUnLoadEventFunctions = new Array();

function fRegisterLoadEvent( functionName )
{
	fLoadEventFunctions[ fLoadEventFunctions.length ] = functionName;
}

function fRegisterUnLoadEvent( functionName )
{
	fUnLoadEventFunctions[ fUnLoadEventFunctions.length ] = functionName;
}

function fExecLoadEvents()
{
	for ( var i = 0; i < fLoadEventFunctions.length; i++ )
	{
		eval( fLoadEventFunctions[i] );
	}
}

function fExecUnLoadEvents()
{
	for ( var i = 0; i < fUnLoadEventFunctions.length; i++ )
	{
		eval( fUnLoadEventFunctions[i] );
	}
}


// set the onload event
window.onload = fExecLoadEvents;
window.onunload = fExecUnLoadEvents;




String.prototype.endsWith = function(str)
{
	return (this.match(str+"$")==str);
}

String.prototype.trim = function () 
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function fCat( toString, newString, delim ) 
{
	if ( newString.trim() != '' )
	{
		if ( toString.trim() != '' )
		{
			toString = toString + delim;
		}		
		
		toString = toString + newString;
	}
	
	return toString;
}

function fCatElement( toString, elementId, delim ) 
{
	var e = document.getElementById( elementId );
	return fCat( toString, e.value, delim );
}


