var dynamicElements;
var selectsElements;

function isIE()
{
	return (document.all?true:false);
}
function setFocus(formElement)  
{
	// W3C approved DOM code that will work in all modern browsers
	if (document.getElementById) 
		document.getElementById(formElement).focus();
	else 
    // To support older versions of IE:
    if (document.all)
        document.all(formElement).focus();  
    return false; 
}  
function openHelpWindow(target){
	var l_win = window.open(target,null,'width=300,height=255,top=250,left=250','true');
	l_win.focus();
	return l_win;
}
function openHelp(e,target)
{
	openHelpContainer(e,target,"helpContainer");
}
function openHelpContainer(e,target, containerElementId)
{
	hideSelects();
	var l_pos = getMouseXY(e);
	var l_helpElem = document.getElementById(containerElementId);
	l_helpElem.innerHTML = "<span class=\"processing\">Loading...</span>";
	if (l_helpElem != null){
		doAJAXRequest(target, containerElementId);
		//Need blank page to prevent secure connection message
		l_helpElem.style.display = "";
		l_helpElem.style.left = l_pos.X;
		l_helpElem.style.top = l_pos.Y;
		//in case any striping is required on the ajax window
	}
}
function closeHelp()
{
	showSelects();
	var l_helpElem = document.getElementById("helpContainer");
	l_helpElem.style.display = "NONE";
	l_helpElem.innerHTML = "";
}
function pos()
{
	this.X = 0;
	this.Y = 0;
}
function getMouseXY(e) {
	if (!e){
		var e = window.event;
	}
	var l_pos = new pos();
	if (e.pageX || e.pageY) {
		l_pos.X = e.pageX;
		l_pos.Y = e.pageY;
	} else if (e.clientX || e.clientY) {
		l_pos.X = e.clientX + document.body.scrollLeft;
		l_pos.Y = e.clientY + document.body.scrollTop;
	}  
	// catch possible negative values in NS4
	if (l_pos.X < 0){l_pos.X = 0};
	if (l_pos.Y < 0){l_pos.Y = 0};
	return l_pos;
}
function setEnableDisable(formElement, value)
{
   formElement.disabled = value;
}
function getRequestParameter (parameterName) {
	var queryString = window.top.location.search.substring(1);
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
} 
function clickButton(e, buttonid)
{ 
	var bt = document.getElementById(buttonid);
	if (typeof bt == 'object'){ 
		if(navigator.appName.indexOf("Netscape")> -1){ 
			if (e.keyCode == 13){
				if (bt != null){
					bt.click(); 
					return false;
				}
			} 
		}else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
			if (event.keyCode == 13){
				if (bt != null){
					bt.click();
					return false;
				}
			} 
		} 
	} 
}
String.prototype.toProperCase = function()
{
  return this.toLowerCase().replace(/^(.)|\s(.)/g, 
      function($1) { return $1.toUpperCase(); });
}
Array.prototype.contains = function (element) {
	for (var i = 0; i < this.length; i++){
		if (this[i] == element) {
			return true;
		}
	}
		return false;  
}
function invertRegExValidate(val)
{
	var value = ValidatorGetValue(val.controltovalidate);
    if (ValidatorTrim(value).length == 0)
    {
		return true;
	}
	else if (typeof RegularExpressionValidatorEvaluateIsValid == "function")
	{
		return ! RegularExpressionValidatorEvaluateIsValid(val);
	} else {
		return true;
	}
}
function startProcessing()
{
	document.getElementById("processing").style.display = "";
}
function endProcessing()
{
	document.getElementById("processing").style.display = "NONE";
}
// Add a BookMark
function addBookMark()
{
	if ( window.external ) 
	{
		window.external.AddFavorite( document.location.href,document.title );
	} 
	else 
	{
		alert("Your browser doesn't support bookmarking this page.  Please try pressing Control + D instead." );
	}
}
function toggleSection(elementId)
{
	var l_style;
	if (document.getElementById) {
		l_style = document.getElementById(elementId).style;
		if (l_style.display)
		{
			l_style.display = "";
			return false;
		} else {
			l_style.display = "block";
			return true;
		}
	}
}

function hideAndShow(elementId)
{
	var l_style;
	if (document.getElementById) {
		l_style = document.getElementById(elementId).style;
		if (l_style.display.toUpperCase() == "NONE")
		{
			l_style.display = "";
			return false;
		} else {
			l_style.display = "NONE";
			return true;
		}
	}
}
function createDynDisplayArray()
{
	dynamicElements = new Array();
	// First get them the "old" way
	getDynamicElements(document.body);
	// Then get them the "new" way
	getDynDisplayRules(document.body);
	// Apply rules
	dynDisplay();
}

function getDynamicElements (o)
{
	if(o.nodeType == 1 && o.getAttribute('displayif')) 
	{
		dynamicElements[dynamicElements.length] = new DynamicElement(o,o.getAttribute('displayif'));
	}

	for(var i=0; i < o.childNodes.length; getDynamicElements(o.childNodes[i++]));
}

function getDynDisplayRules (o)
{
	var RULE_SUFFIX = '_displayRule';
	var inputTags = o.getElementsByTagName('INPUT');
	
	for (var i=0; i < inputTags.length; i++) 
	{
		e=inputTags[i];
		if (e.name.substr(e.name.length-RULE_SUFFIX.length) == RULE_SUFFIX) 
		{
			dynamicElements[dynamicElements.length] = new DynamicElement(document.getElementById(e.name.substr(0,e.name.length-RULE_SUFFIX.length)),e.value);
		}
	}
}

function dynDisplay()
{
	if (dynamicElements != null) {
		for (var i=0;i<dynamicElements.length;i++)
		{
			dynamicElements[i].element.style.display = eval(dynamicElements[i].rule) ? '' : 'none';
		}
	}
}

DynamicElement = function (element,rule) {
	this.element = element;
	this.rule = rule;
}
function fbs_click() {
	return fbs_clickUrl(null, null)
}
function fbs_clickUrl(encodedUrl, encodedTitle) {
	if (encodedUrl == null)
	{
		encodedUrl = encodeURIComponent(location.href);
	}
	if (encodedTitle == null)
	{
		encodedTitle = encodeURIComponent(document.title);
	}
	window.open('http://www.facebook.com/sharer.php?u=' + encodedUrl + '&t=' + encodedTitle,'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function getSelectObjects()
{
	selectsElements = document.getElementsByTagName('select');
}
function isIE7()
{
	return (document.all && !window.opera && window.XMLHttpRequest);
}
function hideSelects()
{
	
	if (! isIE7()) {
		if (selectsElements == undefined)
		{
			getSelectObjects();
		}
		if (document.all)
		{
			for (var i=0; i<selectsElements.length;i++)
			{
				selectsElements[i].style.display = 'none';
			}
		}
	}
}
function showSelects()
{
	if (! isIE7()) {
		if (document.all)
		{
			for (var i=0; i<selectsElements.length;i++)
			{
				selectsElements[i].style.display = '';
			}
		}
	}
}
function $(id){
	if(document.getElementById(id)){
		return document.getElementById(id);
	}
}
function stripeTables(){
	
	var tbls = document.getElementsByTagName("table"); // get all the tables withing content
	
	// loop over the tables in content, if the id is striped, the stripe it
	
	for( var x=0; x<tbls.length;x=x+1){
		if(tbls[x].id == "striped") {
			
			stripe(tbls[x]); // stripes this table
		}
	}
}
function stripe(tbl) {
    var trs = tbl.getElementsByTagName("tr");
    for (var i = 0; i < trs.length; i += 2) {
      trs[i].className += " even";
    }
}