// small collection of JavaScript tools for the SuP template
// Bernhard Barkow 2009

function removeClass(o,c) {	var re=new RegExp("(s*|\\b)"+c+"(\\b|$)"); o.className = o.className.replace(re,''); }
function addClass(o,c) { var re=new RegExp("(^|\\b)"+c+"(\\b|$)"), b=!re.test(o.className); if(b) o.className += " "+c; return b; }
function toggleClass(o,s) { if (o) if (!addClass(o,s)) removeClass(o,s); }

function initSwitchModule(o) {
	o.onclick=function() { toggleClass(this.parentNode, 'opened'); }
}

function getForms(s) {
	var i,d=document,o=d.getElementsByTagName('FORM'), x=new Array(), a;
	for (i=o.length-1; i>=0; i--) {
		a = o[i];
		if (a.className == s) x.push(a);
	}
	return x;
}
function initForms() {
	var x = getForms("form-login"), o, p;
	for (var i=x.length-1; i>=0; i--) {
		o = x[i].parentNode, p = o.firstChild;
		do { if (p!=x[i]) initSwitchModule(p); } while (p=p.nextSibling);
	}
}

tempFunc = window.onload;
window.onload = function(){
	if (typeof (tempFunc) == "function"){
		try{
			tempFunc();
		} catch(e){}
	}
	initForms();
}
