var __UIFUNCS_JS__ = 1;

/* Pseudo-constants */
var HIDE_VISIBILITY = 1;
var HIDE_DISPLAY = 2;
var SHOW_ELEMENT = 1;
var HIDE_ELEMENT = 2;

/* Spot of browser detection */
var isIE = (navigator.userAgent.match (/MSIE/)) ? true : false; // I hate you IE

function hide_element (elm)
{
	elm.style.visibility = "hidden";

	return true;
}
function unhide_element (elm)
{
	elm.style.visibility = "visible";

	return true;
}
function display_element (elm)
{
  if (elm.oldDisplay == null) {
  	elm.style.display = "";
  } else {
    elm.style.display = elm.oldDisplay;
  }

	return true;
}
function undisplay_element (elm)
{
  elm.oldDisplay = elm.style.display;
	elm.style.display = "none";

	return true;
}

function showhide_element_async (elm, showorhide, showtype, callback) {
  switch (showtype) {
    case HIDE_VISIBILITY:
      (showorhide==SHOW_ELEMENT)?unhide_element(elm):hide_element(elm);
      break;
    case HIDE_DISPLAY:
      (showorhide==SHOW_ELEMENT)?display_element(elm):undisplay_element(elm);
      break;
    default:
      throw "No show type selected!!!";
  };
  
  if (callback != null && typeof(callback) == 'function') {
    callback(elm);
  }
  
  return;
}

function show_element_async (elm, showtype, callback) {
  return showhide_element_async(elm, SHOW_ELEMENT, showtype, callback);
}

function hide_element_async (elm, showtype, callback) {
  return showhide_element_async(elm, HIDE_ELEMENT, showtype, callback);
}

function GrabId (id)
{
	var toReturn = null;
	
	if (document.all)
	{
		toReturn = document.all[id];
	}
	else
	{
		toReturn = document.getElementById (id);
	}
	
	return toReturn;
}

function GrabIdFromDocument (id, theDoc)
{
	var toReturn = null;
	
	if (theDoc.all)
	{
		toReturn = theDoc.all[id];
	}
	else
	{
		toReturn = theDoc.getElementById (id);
	}
	
	return toReturn;
}

function HideElementById (id)
{
	return hide_element (GrabId (id));
}

function UnhideElementById (id)
{
	return unhide_element (GrabId (id));
}

function ClearFormById (id)
{
	var theForm = GrabId (id);
	
	var actionParam = theForm.action.value;
	
	theForm.reset ();
	theForm.action.value = actionParam;
	
	return true;
}

function GrabStyle(path, ie, ns)
{
	var isIE = (navigator.userAgent.indexOf ("MSIE") != -1) ? true : false;

	if (!isIE)
	{
		document.write("<link href=\""+path+ns+"\" rel=\"stylesheet\">");
	}
	else
	{
		document.write("<link href=\""+path+ie+"\" rel=\"stylesheet\">");
	}
}

function UI_Command (the_id, the_class, onclick_func, label, hide_method)
{
	this.handle = document.createElement ("a");
	this.handle.id = the_id;
	this.handle.onclick = function () {
			onclick_func(this);
			return false;
		};
	this.handle.className = the_class;
	if (typeof(label) != 'string') {
	  this.custom = true;
	  this.handle.appendChild (label);
	} else {
	  this.custom = false;
	  this.handle.appendChild (document.createTextNode (label));
	}
	this.handle.href = "#";

	if (hide_method == HIDE_VISIBILITY)
	{
		this.hide = function () { hide_element(this.handle); };
		this.show = function () { unhide_element(this.handle); };
	}
	else if (hide_method == HIDE_DISPLAY)
	{
		this.hide = function () { undisplay_element(this.handle); };
		this.show = function () { display_element(this.handle); };
	}
	else
	{
		return display_error ("Unknown display method '"+hide_method+"'");
	}
	
	return this;
}
UI_Command.prototype.changeText = function (newText) {
  this.handle.removeChild(this.handle.childNodes[0]);
  this.handle.appendChild(document.createTextNode(newText));
};
UI_Command.prototype.changeId = function (newId) {
  this.handle.id = newId;
};
