var DHTML = (document.getElementById || document.all || document.layers);

var uniqueObjectCount = -1;
var uniqueObjectSpaces = new Array();
var uniqueObjects = new Array();

var BoxHeights = {
	maxh: 0,
	boxes: Array(),
	num: 0,
	equalise: function() {
		this.num = arguments.length;
		for (var i=0;i<this.num;i++) if (!$(arguments[i])) return;
		this.boxes = arguments;
		this.maxheight();
		for (var i=0;i<this.num;i++) $(arguments[i]).style.height = this.maxh+"px";
	},
	maxheight: function() {
		var heights = new Array();
		for (var i=0;i<this.num;i++) {
			if (navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
				heights.push($(this.boxes[i]).scrollHeight);
			} else {
				heights.push($(this.boxes[i]).offsetHeight);
			}
		}
		heights.sort(this.sortNumeric);
		this.maxh = heights[this.num-1];
	},
	sortNumeric: function(f,s) {
		return f-s;
	}
}

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch (err) { };

//stop enter key from working in inputs
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = stopRKey;

function SetToFirstControl()
{
  var bFound = false; 

  //for each form
  for (f=0; f < document.forms.length; f++) 
  {
    //for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      //if it's not a hidden element
      if (document.forms[f][i].type != "hidden") 
      { 
        //and it's not disabled
        if (document.forms[f][i].disabled != true) 
        {
          try {
             //set the focus to it
             document.forms[f][i].focus();
             var bFound = true;
          }
          catch(er) {
          }
        }
      }
      //if found in this element, stop looking
      if (bFound == true)
        break;
    }
    //if found in this form, stop looking
    if (bFound == true)
      break;
  }
}

function updateObjectSpaceStatus(obj, objSpace) 
{
  var currentObject;
  
  currentObject = document.getElementById(obj);
  var currentUniqueObject = currentObject.options[currentObject.selectedIndex].value;
  
  for (var repeat=0; repeat<=uniqueObjectCount; repeat++) {
    if (uniqueObjectSpaces[repeat]==objSpace && uniqueObjects[repeat]!=obj && currentUniqueObject!='') {
      currentObject = document.getElementById(uniqueObjects[repeat]);
      if (currentObject.selectedIndex>-1 && currentObject.options[currentObject.selectedIndex].value == currentUniqueObject) {
        currentObject.selectedIndex = -1;
      }
    }
  }
}

function toggle(e){e.checked = !(e.checked);}
function toggle_child(e){toggle(e.firstChild);}

function addNewUniqueObject(obj, objSpace)
{
	uniqueObjectCount += 1;
        uniqueObjectSpaces[uniqueObjectCount] = objSpace;
	uniqueObjects[uniqueObjectCount] = obj;	
}

function getObj(name)
{
            if (document.getElementById)
            {
            this.obj = document.getElementById(name);
            this.style = document.getElementById(name).style;
            }
            else if (document.all)
            {
            this.obj = document.all[name];
            this.style = document.all[name].style;
            }
            else if (document.layers)
            {
            this.obj = document.layers[name];
            this.style = document.layers[name];
            }
}

            function invi2(flag, object)
            {
            var x = new getObj(object);
            x.style.display = (flag) ? 'block' : 'none';
            }

            function invi(flag, object)
            {
            var x = new getObj(object);
            x.style.display = (flag) ? 'block' : 'none';
            }

            function invitab(flag, object)
            {
            var x = new getObj(object);
            x.style.background = (flag) ? 'url(outlook/tab_background.jpg)' : 'url(outlook/tab_background_not.jpg)';
            }

            function arrangeDisplay(toDisplay, totalCount, toStart)
            {       for (i = toStart; i <= totalCount; i++)
            {  invi(0,i);
            }
            invi(1,toDisplay);
            }

            function arrangeTab(toDisplay, totalCount)
            {       for (i = 0; i <= totalCount; i++)
            {  invitab(0,i);
            }
            invitab(1,toDisplay-1);
            invitab(1,toDisplay);
            invitab(1,toDisplay+1);
            }

            function setJsTab(valuation)
            {
            document.getElementById('jsTab').value = valuation;
            }

            function show(element)
            {
            obj1 = document.getElementById(element);
            obj1.style.visibility = 'visible';
            }

            function hide(element)
            {
            obj1 = document.getElementById(element);
            obj1.style.visibility = 'hidden';
            }

            function showObject(element)
            {
            obj1 = document.getElementById(element);
            obj1.style.display = 'block';
            obj1.style.visibility = 'visible';
            }

            function hideObject(element)
            {
            obj1 = document.getElementById(element);
            obj1.style.display = 'none';
            obj1.style.visibility = 'hidden';
            }

            function hideselect(element)
            {
            obj1 = document.getElementByclassName(element);
            obj1.style.display = 'block';
            obj1.style.visibility = 'hidden';
            }

            function showselect(element)
            {
            obj1 = document.getElementByclassName(element);
            obj1.style.display = 'block';
            obj1.style.visibility = 'visible';
            }

            function hideSelects(action) {
                if (action!='visible'){action='hidden';}
                for (var S = 0; S < document.forms.length; S++){
                    for (var R = 0; R < document.forms[S].length; R++) {
                        if (document.forms[S].elements[R].options) {
                            document.forms[S].elements[R].style.visibility = action;
                        }
                    }
                }
            }


