function $() {

	// from http://www.ajaxify.com/run/wiki/util.js
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {

      var element = arguments[i];

      if (typeof element == 'string') {
        if (document.getElementById) {
          element = document.getElementById(element);
        } else if (document.all) {
          element = document.all[element];
        }
      }

      elements.push(element);

    }

    if (arguments.length == 1 && elements.length > 0) {
      return elements[0];
    } else {
      return elements;
    }
}
function resize_vertical(textarea) {

	// adapted from http://www.ajaxify.com/run/wiki/wiki.js
	
    var textRows = textarea.value.split('\n');
    var newRowAmount = textRows.length + 2;

    for ( var i=0; i<textRows.length; i++ ) {
      if ( textRows[i].length > textarea.cols ) {
        newRowAmount += Math.floor(textRows[i].length/textarea.cols);
      }
    }
    newRowAmount = Math.max(newRowAmount, 3);
    newRowAmount = Math.min(newRowAmount, 30);
    textarea.rows = newRowAmount;
}
function openurl(url, newwin, newwidth, newheight)
{
	if (newwin) {
		open(url, "_blank");
	} else {
		open(url, "_top");
	}
}
function opencommentswin(id)
{
	open("/comments.pl?id=" + id, "_blank", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=320,height=415");
}
function doKeyPress(evt)
{
	if (!evt) var evt = window.event;
	var targ = get_event_target(evt);
	
	if (evt.keyCode) code = evt.keyCode;
	else if (evt.which) code = evt.which;

	if (targ.type != "text" && targ.type != "textarea") {
		if (code == 122) { // 122 = 'z'
			toggle_childsmartlists_display();
		}
	}
}
function get_event_target(ev)
{
	//http://www.quirksmode.org/js/events_properties.html
	var targ;
	if (!ev) var ev = window.event;
	if (ev.target) targ = ev.target;
	else if (ev.srcElement) targ = ev.srcElement;
	while (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}
function getElementsByTagNames(list,obj) {
	// from http://www.quirksmode.org/dom/getElementsByTagNames.html
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
function toggle_childsmartlists_display()
{
 // toggle display of all smartlists which are children of another smartlist
 
 var ULslist = getElementsByTagNames('ul');
 for (var i=0; i<ULslist.length; i++) {
  
  if (ULslist[i].className == "smartlist") {
   
   var childULslist = getElementsByTagNames('ul',ULslist[i]);
   for (var j=0; j<childULslist.length; j++) {
    
    if (childULslist[j].className == "smartlist") {
     
     if (childULslist[j].style.display == "none") {
      childULslist[j].style.display = "block";
     } else {
      childULslist[j].style.display = "none";
     }
    }
   }
  }
 }
}
document.onkeypress = doKeyPress;