
/* resizes the height of an element to fill the screen given its id */

function resize(id) {
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winH = window.innerHeight - 251;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winH = document.body.offsetHeight - 211;
	 }
	}

	if (winH < 200) winH = 200;

  var obj = document.getElementById(id);
  obj.style.height = winH + 'px';

}

//searches for an object (needle) in an array of objects (haystack)
function in_array(needle,haystack) {
  return (haystack.toString().indexOf(needle) !== -1);
}

// given two arrays, merges them and returns the result
// yeah i know concat exists :)
function merge_array(source, rows) {
  var temp = source;
  for (var i=0;i<rows.length;i++) {
      temp.push(rows[i]);
  }
  return temp;
}


// given a list of types and a node element, returns an array of elements matching those types
// if no node is given, defaults to 'document'
function getElementsByType(types,obj) {
  if (!obj) obj = document;
  
    var typeNames = types.split(',');
    var results = new Array();
     var elements = obj.getElementsByTagName("*");
     for (var j=0;j<elements.length;j++) {
        if (in_array(elements[j].type,typeNames)) results.push(elements[j]);
     } 
  
  
return ((results.length>0)? results : null);
}

// given a list of tags and a node element, returns an array of elements matching those tags
// if no node is given, defaults to 'document'
// if no tags are given, defaults to "*"
function getElementsByTagNames(tags,obj) {
  if (!obj) obj = document;
 if (!tags) tags = "*";
  
    var tagNames = tags.split(',');
  var results = new Array();
  for (var i=0;i<tagNames.length;i++) {
     var elements = obj.getElementsByTagName(tagNames[i]);
     for (var j=0;j<elements.length;j++) {
        results.push(elements[j]);
     } 
  }
  
return ((results.length>0)? results : null);
}

// getElementsByClass()
// builds an array of elements of a given class

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// getIDByClass()
// returns an array of the IDs of all elements of a given class

function getIDByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = document.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i].id;
			j++;
		}
	}
	return classElements;
}

  
    
    


//hideDiv(id)
// hides an element with a given ID

function hideDiv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}


//showDiv(id)
// shows an element with a given ID

function showDiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


		function selectAll(obj, selected) {
			var element = document.getElementById(obj);
                        if (element.type == "select-multiple") {
                                for(i=0; i<element.length; i++) {
                                	element.options[i].selected=selected;
                                }
                                if( element.onchange ) {
                                	element.onchange();
                                }
                        }
		}
                

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// port of IE equivalent functions for insertion of HTML

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
                        this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}


/*
 * (c)2006 Dean Edwards/Matthias Miller/John Resig
 * Special thanks to Dan Webb's domready.js Prototype extension
 * and Simon Willison's addLoadEvent
 *
 * For more info, see:
 * http://dean.edwards.name/weblog/2006/06/again/
 * http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent
 * 
 * Thrown together by Jesse Skinner (http://www.thefutureoftheweb.com/)
 *
 *
 * To use: call addDOMLoadEvent one or more times with functions, ie:
 *
 *    function something() {
 *       // do something
 *    }
 *    addDOMLoadEvent(something);
 *
 *    addDOMLoadEvent(function() {
 *        // do other stuff
 *    });
 *
 */
 
function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}



function editor(section) {
if ((typeof(section) == "string") && (section != "")) {
  if (section != "error") window.location.href = "?command=edit&page=" + section;
}
}


