function addCss(class_name, def) {
	css = '<style>' + class_name + '{' + def + '}</style>';
	document.write(css);
}
addCss('.hide', 'display:none;');


function jscss(a,o,c1,c2) {
	switch (a){
    	case 'swap':
			o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
			break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
    	break;
	}
}

function fixLinks() { 
	if (!document.getElementsByTagName) return; 
	var alinks=document.getElementsByTagName("a");
	for (var i=0; i<alinks.length; i++) { 
		if (alinks[i].getAttribute("href") && alinks[i].getAttribute("rel") == "external")  {
			alinks[i].target = "_blank";
		} else if (alinks[i].getAttribute("href") && alinks[i].getAttribute("rel") == "popup") {
			alinks[i].onclick = function() {
				remote = window.open("", "", "resizable=yes, status=no, scrollbars=yes, left=50, top=20, width=320,height=470");
				remote.location.href = this.getAttribute('href');
				if (remote.opener == null) remote.opener = window;
				return false;
			}
		} else if (alinks[i].getAttribute("href") && alinks[i].getAttribute("rel") == "toggle") {
			alinks[i].onclick = function() {
				if (jscss('check', this.parentNode.parentNode, 'active')) {
					jscss('remove', this.parentNode.parentNode, 'active');
				} else {
					jscss('add', this.parentNode.parentNode, 'active');
				}
				return false;
			}
		}
	} 
}

function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			oldonload(); 
			func(); 
		} 
	} 
} 

addLoadEvent(fixLinks);
