function Trim(strValue) {
	return LTrim(RTrim(strValue));
}
function LTrim(strValue) {
	var LTRIMrgExp = /^\s */;
	return strValue.replace(LTRIMrgExp, '');
}
function RTrim(strValue) {
	var RTRIMrgExp = /\s *$/;
	return strValue.replace(RTRIMrgExp, '');
}
if (document.all && !document.getElementsByTagName) {
	document.getElementsByTagName = function(nodeName) {
		if (nodeName == '*') {
			return document.all;
		}
		var result = [], rightName = new RegExp(nodeName, 'i'), i;
		for (i=0; i<document.all.length; i++) {
			if (rightName.test(document.all[i].nodeName)) {
				result.push(document.all[i]);
			}
		}
		return result;
	};
}
document.getElementsByClassName = function(className, nodeName) {
	var result = [], tag = nodeName || '*', node, seek, i;
	if (document.evaluate) {
		seek = '//'+tag+'[@class="'+className+'"]';
		seek = document.evaluate(seek, document, null, 0, null);
		while ((node=seek.iterateNext())) {
			result.push(node);
		}
	} else {
		var rightClass = new RegExp('(^| )'+className+'( |$)');
		seek = document.getElementsByTagName(tag);
		for (i=0; i<seek.length; i++) {
			if (rightClass.test((node=seek[i]).className)) {
				result.push(seek[i]);
			}
		}
	}
	return result;
};
// sipmple swap-image function
function swapImage(evtObj, fileref, forceit) {
	if (evtObj) {
		if (evtObj.src.indexOf('selected') == -1 || forceit == true) {
			//alert (evtObj.src);
			evtObj.src = fileref;
		}
	}
}
// StyleSwitcher functions written by Paul Sowden
function setActiveSS(title) {
	var i, a, main;
	for (i=0; (a=document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if (a.getAttribute("title") == title) {
				a.disabled = false;
			}
		}
	}
	if (title.indexOf('Big') != -1) {
		document.getElementById("big_chars_button").className = "char_link_active";
		document.getElementById("small_chars_button").className = "char_link";
	} else {
		document.getElementById('small_chars_button').className = "char_link_active";
		document.getElementById('big_chars_button').className = "char_link";
	}
	// alert (document.getElementById('big_chars_button').className);
}
function getActiveSS() {
	var i, a;
	for (i=0; (a=document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
			return a.getAttribute("title");
		}
	}
	return null;
}
function getPreferredSS() {
	var i, a;
	for (i=0; (a=document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) {
			return a.getAttribute("title");
		}
	}
	return null;
}
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
}
function readCookie(name) {
	var nameEQ = name+"=";
	var ca = document.cookie.split(';');
	for (var i = 0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}
window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredSS();
	setActiveSS(title);
};
window.onunload = function(e) {
	var title = getActiveSS();
	createCookie("style", title);
};
/// //////////////
// xhtml-strict links!
function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}
// ////////////////////
// to adjust content div depending on right-height
function adjustContentHeight() {
	var referenceDiv = document.getElementById("p-review");
	var footerDiv = document.getElementById("footer");
	var bottom_def = 0;
	bottom_def += findPosY(referenceDiv);
	bottom_def += referenceDiv.offsetHeight;
	// bottom_def -= footerDiv.offsetHeight;
	var contentDiv = document.getElementById("content");
	// calculate old bottom-y
	var bottom_old = 0;
	bottom_old += findPosY(contentDiv);
	bottom_old += contentDiv.offsetHeight;
	var delta = (bottom_def-bottom_old)+contentDiv.offsetHeight-footerDiv.offsetHeight;
	if (navigator.userAgent.indexOf('MSIE') != -1) {
		delta = delta+2;
	} else {
		delta = delta-12;
	}
	if (bottom_def>bottom_old) {
		resize(contentDiv, delta);
	}
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}
function isSet(prm) {
	var und;
	return (prm != und && prm != null);
}
function resize(elmnt, height) {
	if (!isSet(elmnt)) {
		return;
	}
	if (typeof elmnt != 'object') {
		fatherElmnt = document.getElementById(elmnt);
	}
	if (!elmnt) {
		return;
	}
	if (!isSet(height)) {
		height = 0;
	}
	elmnt.style.height = height+"px";
}
/*
function toogleFeedbackForm()
{

    if(document.getElementById('contactform').style.display != 'block'){
         document.getElementById('contactform').style.display = 'block';
         document.getElementById('pfo1').focus();
    }else{
         document.getElementById('contactform').style.display = 'none';
    }

}
*/
// ///////////////////////////
// box-handling
var inner;
function openBox(id, trigger) {
	var box = document.getElementById(id);
	// alert (box);
	if(box.style.display != "block"){
		box.style.display = "block";
		inner = true;
	}
}

function closeBox(id, trigger) {
//alert('close');
	var box = document.getElementById(id);
	// alert ("closeBox");
	if (inner){
		inner = false;
		return;
	}
	if(box.style.display != "none"){
		box.style.display = "none";
	}

}


function openbox(id, trigger) {
	openBox(id, trigger);
}
function closebox(id, trigger) {
	closeBox(id, trigger);
}

function emptyHrefs() {
	var allAs = document.getElementsByTagName("a");
	for (var i = 0; i<allAs.length; i++) {
		var a = allAs[i];
		var att = a.getAttribute("href");
		if (att == "#" || att == "") {
			//a.removeAttribute ("href");
		}
	}
}
function reactToFormError() {
	// open form box if there has been an error
	if (document.getElementById("formerrors")) {
		if (document.getElementById("formerrors").childNodes.length>3) {
			openBox('feedbackF', null);
			location.href = "#formerror_anchor";
		}
	}
}
function blink() {
	// open form box if there has been an error
	if (document.getElementById('tempService')) {
		var div = document.getElementById('tempService');
		div.style.display = 'block';
		div.style.visibility = (div.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
	createCookie("tempService", 'shown');
}
function setFeedbackFormTitle() {
	
	var h1 = document.getElementsByClassName('article-title', 'h1');
	var i;
	var str = new Array();
	

	for (i in h1) {
		if (h1[i].firstChild.data.length>0) {
			str.push(Trim(h1[i].firstChild.data));
		}
	}
	if (str.length > 0){ 
		str = str.join(', ');
		// alert(str);
		var field = document.getElementById('pfo1');
		field.value = str;
	}
}



/// //////////// 
// graphics
function openGraphic(graphicUrl, base64Title, nodecode, showTitle){
	var url = graphicUrl+'?t='+base64Title;
	if(nodecode == 'true'){
		url = url + '&nodecode=1';
	}
	if(showTitle == 'false'){
		url = url + '&showTitle=0';
	}
	window.open(url, '', 'width=300, height=300, menubar=yes, scrollbars=no, resizable=yes');
}


function setFeedbackFVisibility(value){
	if(document.getElementById('feedbackF')){
		var f = document.getElementById('feedbackF');
		f.style.display = value;
	}
}

function hideFootnotes(){ //added by hg on 2006-08-18
	
	var fns = document.getElementsByClassName('box', 'span');
		
	for (i in fns) {		
		closeBox(fns[i].id, fns[i]);		
	}
}



/// ////////////
// go4it
function initAll() {
	

	setFeedbackFormTitle();	
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredSS();	
	setActiveSS(title);
	externalLinks();
	emptyHrefs();
	adjustContentHeight();	
	reactToFormError();
	var cookie = readCookie("tempService");
	setFeedbackFVisibility("none");	
	hideFootnotes();
	/*
	if(document.all){
		document.body.scrollLeft = v;
	} else {
		window.pageXOffset = v;	
	}
	*/
	
	
}
window.onload = initAll;

