function show_hide(field_id, is_visible)
{
    document.getElementById(field_id).style.display = is_visible ? "" : "none";
}

var myPopupWindow = '';
function openPopupWindow(url, name, width, height)
{
    //Remove special characters from name
    name = name.replace(/\/|\-|\./gi, "");

    //Remove whitespaces from name
    var whitespace = new RegExp("\\s","g");
    name = name.replace(whitespace,"");

    //If it is already open
    if (!myPopupWindow.closed && myPopupWindow.location)
    {
        myPopupWindow.location.href = url;
    }
    else
    {
        myPopupWindow= window.open(url,name, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height );
        if (!myPopupWindow.opener) myPopupWindow.opener = self;
    }

     //If my main window has focus - set it to the popup
    if (window.focus) {myPopupWindow.focus()}
}

function tabselect(tabcontrol_id,tab) {
  var tablist = $(tabcontrol_id).getElementsByTagName('li');
  var nodes = $A(tablist);
  var lClassType = tab.className.substring(0, tab.className.indexOf('-') );

  nodes.each(function(node){
    if (node.id == tab.id) {
      tab.className=lClassType+'-selected';
    } else {
      node.className=lClassType+'-unselected';
    };
  });
}

function paneselect(panecontrol_id,pane) {
  var panelist = $(panecontrol_id).getElementsByTagName('li');
  var nodes = $A(panelist);

  nodes.each(function(node){
    // Only change nodes that are panes
    if (node.className.substring(0,5) == 'pane-') {
      if (node.id == pane.id) {
        pane.className='pane-selected';
      } else {
        node.className='pane-unselected';
      };
    };
  });
}

function loadPane(pane, src) {
  if (pane.innerHTML=='' || pane.innerHTML=='<img alt="Wait" src="/images/spinner.gif" style="vertical-align:-3px" /> Loading...') {
    reloadPane(pane, src);
  }
}

function reloadPane(pane, src) {
  new Ajax.Updater(pane, src, {asynchronous:1, evalScripts:true, onLoading:function(request){pane.innerHTML='<img alt="Wait" src="/images/spinner.gif" style="vertical-align:-3px" /> Loading...'}})
}

/* findMaxNumber: finds maximum integer of the provident argument(s) */
function findMaxNumber() {
	if(arguments.length > 0){
		myMax = arguments[0];
		for(a=0;a<arguments.length;a++){
			if(arguments[a] > myMax){
				myMax = arguments[a];
			}
		}
		return myMax;
	}
}

function getComputedHeightOfElement(theElt){
        var browserName=navigator.appName;
         if (browserName=="Microsoft Internet Explorer"){
                var is_ie=true;
         } else {
                var is_ie=false;
         }
        if(is_ie){
                tmphght = theElt.offsetHeight;
        }
        else{
                docObj = theElt;
                var tmphght1 = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
                tmphght = tmphght1.split('px');
                tmphght = tmphght[0];
        }
        return tmphght;
}

/* findMaxHeightOfElements(): finds maximum height (in px) given some element(s) */
function findMaxHeightOfElements() {
	if(arguments.length > 0)
	{
		allElementsHeights = [];
		for(a = 0; a < arguments.length; a++)
		{
			currentElement = document.getElementById(arguments[a]);
			if(currentElement)
			{
				currentElementsHeight = getComputedHeightOfElement(currentElement);
				allElementsHeights[a] = currentElementsHeight;
			}
		}
		
		myMax = findMaxNumber(allElementsHeights);
		return myMax;
	}
}
