/* --------------------------------------------------------------------
	Title: toolshed
		Basic little helpers for your everyday DOM-manipulation
	
	Author: Frank Boës <mailto:fboes@berlinonline.de>
	
	Company: BerlinOnline <http://www.berlinonline.de>
	
	Created: 2005-11-14
	
	Updated: 22006-01-05
-------------------------------------------------------------------- */

	// Function: $href
	// Return object where id matches "#"-fraction of el.href
try{
	if (typeof($href) == 'undefined')
	function $href(el) {
		return document.getElementById(el.href.replace(/^.*#/,''));
	}
	
	// Function: requireOnce
	// Load js-file if not already present
	if (typeof(requireOnce) == 'undefined')
	function requireOnce(file) {
		var scriptz = document.getElementsByTagName('script');
		for (i=0;i<scriptz.length;i++) {
			if (scriptz[i].getAttribute('src') == file) {
				return true;
			}
		}
		if (document.getElementsByTagName('head')) {
			var t = document.createElement('script');
			t.setAttribute('type', 'text/javascript');
			t.setAttribute('src', file);
			return (document.getElementsByTagName('head')[0].appendChild(t));
		}
		else {
			document.writeln('<script src="'+file+'" type="text/java'+'script"></'+'script>');
			return true;
		}
	}
	

	// Function: addCladdName
	// Add classname cl to el, if not already present
	if (typeof(addClassName) == 'undefined')
	function addClassName (el, cl) {
		if (el && el.className.indexOf(cl) == -1) return (el.className = (el.className)
			? el.className+' '+cl
			: cl
		);
	}
	
	// Function: removeClassName
	// Remove classname cl from el, if present
	if (typeof(removeClassName) == 'undefined')
	function removeClassName (el, cl) {
		if (el) return (el.className = el.className.replace(new RegExp("\s?"+cl+"\\b"), ''));
	}
	
	// Function: toggleClassName
	// Remove class if present, add if not present
	if (typeof(toggleClassName) == 'undefined')
	function toggleClassName (el, cl) {
		if (el) if (el.className.indexOf(cl) != -1) {
			removeClassName(el,cl);
		}
		else {
			addClassName(el,cl);
		}
	}
	
	// Function: toggleStyleDisplay
	// If object is visible, hide it and vice versa
	if (typeof(toggleStyleDisplay) == 'undefined')
	function toggleStyleDisplay(el) {
		return el.style.display = (el.style.display != 'block') ? 'block' : 'none';
	}

// Function: toggleInnerHTML
// if el.innerHTML = html1 it will be set to html2 and vice versa
if (typeof(toggleInnerHTML) == 'undefined')
function toggleInnerHTML(el, html1, html2) {
	el.innerHTML = (el.innerHTML != html1) ? html1 : html2;
}

// Function: getElementsByAttribute
// returns object(s), if their attr matches value
if (typeof(getElementsByAttribute) == 'undefined')
function getElementsByAttribute(attr, value, exact) {
	if (!exact)
		exact = false;
	if (!attr || !value) return false;
	if (document.all)
		{var all_obj=document.all;}
	else if (document.getElementsByTagName && !document.all)
		{var all_obj=document.getElementsByTagName("*");}
	else return false;
	var ret_obj = new Array();
	for (i=0;i<all_obj.length;i++) {
		if (all_obj[i] && all_obj[i].getAttribute(attr)) {
			if (exact == true) {
				if (all_obj[i].getAttribute(attr) == value) {
					ret_obj[ret_obj.length] = all_obj[i];
				}
			} else if  (all_obj[i].getAttribute(attr).indexOf(value)!=-1) {
					ret_obj[ret_obj.length] = all_obj[i];
			}
		}
	}
	return ret_obj;
}

// Function: getElementsByClassName
// returns object(s), if their classes matches value
if (typeof(getElementsByClassName) == 'undefined')
function getElementsByClassName(node,classname) {
	if (node.getElementsByClassName)
		return node.getElementsByClassName(classname);
	else {
		return getElementsByAttribute('class', classname);
	}
}

// Function: getNextSibling
// get nextSibling ignoring white space nodes
if (typeof(getNextSibling) == 'undefined')
function getNextSibling(el) {
	do {
		el = el.nextSibling;
	}	while (el && el.nodeType != 1);
	return (el);
}

// Function: getPreviousSibling
// get previousSibling ignoring white space nodes
if (typeof(getPreviousSibling) == 'undefined')
function getPreviousSibling(el) {
	do {
		el = el.previousSibling;
	}	while (el && el.nodeType != 1);
	return (el);
}

// Function: getFirstChild
// get firstChild ignoring white space nodes
if (typeof(getFirstChild) == 'undefined')
function getFirstChild(el) {
	el = el.firstChild;
	while (el && el.nodeType != 1) {
		el = el.nextSibling;
	}
	return (el);
}

// Function: getLastChild
// get lastChild ignoring white space nodes
if (typeof(getLastChild) == 'undefined')
function getLastChild(el) {
	el = el.lastChild;
	while (el && el.nodeType != 1) {
		el = el.previousSibling;
	}
	return (el);
}

// Function: getParentNode
// get parentNode ignoring white space nodes
if (typeof(getParentNode) == 'undefined')
function getParentNode(el) {
	el = el.parentNode;
	while (el && el.nodeType != 1) {
		el = el.parentNode;
	}
	return (el);
}

// Function: getChildNodes
// get childNodes ignoring white space nodes
if (typeof(getChildNodes) == 'undefined')
function getChildNodes(el) {
  var objs = new Array();
  var i = 0;
  el = el.firstChild;
  while (el) {
    if (el.nodeType == 1) {objs[i++] = el;}
    el = el.nextSibling;
  }
  return objs;
}

// Function: getAncestorsByTagname
// search for ancestors containing a specific tagname
if (typeof(getAncestorsByTagname) == 'undefined')
function getAncestorsByTagname(el,nodename) {
	while (el && el.nodeName != nodename) {
			el = el.parentNode;
	}
  return el;
}

// Function: focusElement
// get position for an element and focus it on the screen
if (typeof(focusElement) == 'undefined')
function focusElement(el) {
  if (! el.offsetLeft)
    el=document.getElementById(el)
    if (! el.offsetLeft)
      return false;
  window.scrollTo(el.offsetLeft, el.offsetTop);
} 

// Function: insertAfter
// Insert DOM-Node as nextSibling
if (typeof(insertAfter) == 'undefined')
function insertAfter(src,tgt) {
	if (tgt.nextSibling)
		tgt.parentNode.insertBefore(src, tgt.nextSibling);
	else 
		tgt.parentNode.appendChild(src);
}


/* in frad selber definieren ? */
if (typeof(closeLayer) == 'undefined')
function closeLayer (L) {
  el=document.getElementById(L);
  el.style.display='none';
  el.style.visibility='hidden';
}

/* from nz */
if (typeof(Pop) == 'undefined')
function Pop(url,width,height,status,toolbar,scrollbars) {
 if (width == null) w = 600; else w = width;
 if (height == null) h = 460; else h = height;
 if (status == null) st = 0; else st = status;
 if (toolbar == null) tb = 0; else tb = toolbar;
 if (scrollbars == null) sb = 1; else sb = scrollbars;
 open(url,"_blank","status="+st+",toolbar="+tb+",scrollbars="+sb+",resizable=1,width="+w+",height="+h+",screenX=30,screenY=30,left=30,top=30");
}


// for including toolshed.js in bookmarklets
var toolshed_loaded = true;
}catch(err){
}


