function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined')	{
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else	{
		return false;
	}
	return true;
};

function attachEventListener(target, eventType, functionRef, capture) {
    if (typeof target.addEventListener != "undefined") {
        target.addEventListener(eventType, functionRef, capture);
    } else if (typeof target.attachEvent != "undefined") {
        target.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
};

function foto(id, width, winheight, description, path){
	fotowin = window.open("", "foto", "width =" +width +",height =" + winheight +",location=no,menubar=no,directories=no,toolbar=no,scrollbars=no,resizable=no,status=no");
	fotowin.document.write("<html><head><title>foto</title></head><body leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginwidth=\"0\"><img src=\""+path+"/mma_bin.php?src=mid&amp;id=" + id + "\" onclick=\"window.close();\" /><br /><div style=\"color: #333333; font-size:60%; margin-left :10px; margin-right :10px; margin-top :5px; font-family: Arial;  align=\"justify\">"+ description +"</div></boby></html>");
	fotowin.document.close();
	document.body.onfocus = closeFotoWin;
}


function foto_ext(id, width, winheight, title, description){
	fotowin = window.open("", "foto", "width =" +width +",height =" + winheight +",location=no,menubar=no,directories=no,toolbar=no,scrollbars=no,resizable=no,status=no");
	fotowin.document.write("<html><head><title>" + title + "</title></head><body leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginwidth=\"0\"><img src=\"/mma_bin.php?src=mid&amp;id=" + id + "\" onclick=\"window.close();\" /><br /><div style=\"color: #333333; font-size:60%; margin-left :10px; margin-right :10px; margin-top :5px; font-family: Arial;  align=\"justify\">"+ description +"</div></boby></html>");
	fotowin.document.close();
	document.body.onfocus = closeFotoWin;
}

function closeFotoWin() {
	if(fotowin != null && !(fotowin.closed)) {
		fotowin.close();
	}
}

//mail decode
function mDec(ensl, enlsShow, addToHref, firstPartHrefOnly) {
	if ((enlsShow == undefined || enlsShow == "") && (firstPartHrefOnly == undefined || firstPartHrefOnly == "")) {
		enlsShow = ensl;
	}
	
	if (addToHref == undefined) {
		addToHref = "";
	}

	s="";
	for(i=0; i<enlsShow.length; i++) {
		n=enlsShow.charCodeAt(i);
		if (n >= 35 && n <= 126) {
			s+=String.fromCharCode((n-3));
		} else {
			s+=enlsShow.charAt(i);
		}
	}
	nslvShow = s;
	
	a="pdlowr="+ensl; 
	nslv = "";
	for(i=0; i<a.length; i++) {
		n=a.charCodeAt(i)-3;
		nslv+=String.fromCharCode(n);
	}
	if (firstPartHrefOnly == true) {
		document.write("<a class=\"email\" href=\"" + nslv + addToHref + "\">");		
	} else {
		document.write("<a class=\"email\" href=\"" + nslv + addToHref + "\">"+nslvShow+"</a>");		
	}
}

function printWindow() {
	window.open("?gMode=print", "print", "width=620,height=550,location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=no,status=no");
}

function dynamicLayout() {
	var browserWidth = getBrowserWidth();
	
	if (browserWidth == 0) {
		var resolutionCookie = document.cookie.match(/(^|;)tmib_res_layout[^;]*(;|$)/);
		if (resolutionCookie != null) {
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
		}
		addLoadListener(dynamicLayout);
		return false;
	}
	if (browserWidth < 1030){
		setStylesheet("");
	} else if (browserWidth > 1030){
		setStylesheet("wide");
	}
	return true;
}

function getBrowserWidth() {
	if (window.innerWidth) {
		return window.innerWidth;}	
	else if (document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;	}
	else if (document.body){return document.body.clientWidth;}		
		return 0;
}

function setStylesheet(styleTitle) {
	var currTag;

	if (document.getElementsByTagName) {
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++) {
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")) {
				currTag.disabled = true;
				if (currTag.getAttribute("title") == styleTitle) {
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};

/* open target menu item, while closing all its siblings */
function openThis(object) {
	if (document.getElementById) {
		closeMenu();
		var liEl = object.parentNode.parentNode;
		liEl.className = 'open';
	} else return false;
}

/* open the menu item with the given text */
function openMenuItemWithContent(content) {
	if (document.getElementById) {
		var menu = document.getElementById('menu');
		var firstLIElement = menu.firstChild;
		var liSibling = firstLIElement;
		do {
			if ((liSibling.nodeName == 'LI') && (liSibling.firstChild.firstChild.firstChild.firstChild.nodeValue == content)) {
				liSibling.className = 'open';
			}
			liSibling = liSibling.nextSibling;
		} while (liSibling);
	} else return false;
}

function closeMenu() {
	if (document.getElementById) {
		var menu = document.getElementById('menu');
		var firstLIElement = menu.firstChild;
		var liSibling = firstLIElement;
		do {
			if (liSibling.nodeName == 'LI') {
				liSibling.className = "";
			}
			liSibling = liSibling.nextSibling;
		} while (liSibling);
	} else return false;
}

// highlights the content module linked to the hovered waymark
function highlightAttachedModule(module_name) {
	if (document.getElementById) {
		var module_title = document.getElementById('title-' + module_name); // get module title from module name
		module_title.id = 'title-' + module_name + '-on'; // CHECK THIS: changing the id may be illegal
	} else return false;
}

// un-highlights the content module linked to the hovered waymark
function unhighlightAttachedModule(module_name) {
	if (document.getElementById) {
		var module_title = document.getElementById('title-' + module_name + '-on'); // get module title from module name
		module_title.id = 'title-' + module_name; // CHECK THIS: changing the id may be illegal
	} else return false;
}


function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function showMoreContent() {
	if (document.getElementById) {
		var object = document.getElementById('more-content');
		object.style.display = 'block';
		var object2 = document.getElementById('more-content-link');
		object2.style.display = 'none';
	} else return false;
}

function hideMoreContent() {
	if (document.getElementById) {
		var object = document.getElementById('more-content');
		object.style.display = 'none';
	} else return false;
}

/* open target dd element */
function openThisDD(ddobject, dt) {
	hideAllDDs()
	var dd = document.getElementById(ddobject); 
	dd.style.display = "block";
	dt.className = "alt";
}

function hideAllDDs() {
	if (document.getElementById) {
		var dl = document.getElementById("related-links-categories-list"); 
		var dts = dl.getElementsByTagName('dt');
		for (var i = 0; i < dts.length; i++) { 
			dts[i].className = "";
		}
		var dds = dl.getElementsByTagName("dd");
		for (var i = 0; i < dds.length; i++) { 
			dds[i].style.display = "none";
		}
	} else return false;
}


function isChecked(FormName, responseTxt){
		
	var i = 1;

	var form = document.getElementById(FormName);
	while(i <= form.elements.length){
		if(form.elements[i]){
			if(form.elements[i].checked == true){
				return true;	
			}
		}
		i++;
	}	
	alert(responseTxt);
	return false;
}

function show(element) {
	if (document.getElementById) {
		// W3C standard
		var style2 = document.getElementById(element).style;
		style2.display = "block";
	} else if (document.all) {
		// old MSIE versions
		var style2 = document.all[element].style;
		style2.display = "block";
	} else if (document.layers) {
	// Netscape 4
		var style2 = document.layers[element].style;
		style2.display = "block";
	}
}


function hide(element) {
	if (document.getElementById) {
		// W3C standard
		var style2 = document.getElementById(element).style;
		style2.display = "none";
	} else if (document.all) {
		// old MSIE versions
		var style2 = document.all[element].style;
		style2.display = "none";
	} else if (document.layers) {
	// Netscape 4
		var style2 = document.layers[element].style;
		style2.display = "none";
	}
}

function showHideAll(id_select, type) {

	var cCommonDivName = "section";
	
	var arrDivs = document.getElementsByTagName(type);

	for(i = 0 ; i < arrDivs.length ; i++) {
		if (arrDivs[ i ].id.match(cCommonDivName)) {
			if(arrDivs[ i ].id == id_select){
				show(arrDivs[ i ].id);
			}else{
				hide(arrDivs[ i ].id);    
			}
		}
	}
}

function changeClass(id_select, type){
	var cCommonDivName = "a_";
	
	var arrDivs = document.getElementsByTagName(type);
	
	for(i = 0 ; i < arrDivs.length ; i++) {
		if (arrDivs[ i ].id.match(cCommonDivName)) {
			if(arrDivs[ i ].id == id_select){
				if (document.getElementById) {
					// W3C standard
					var style2 = document.getElementById(arrDivs[ i ].id);
					style2.className  = "date";
				} else if (document.all) {
					// old MSIE versions
					var style2 = document.all[arrDivs[ i ].id];
					style2.className  = "date";
				} else if (document.layers) {
				// Netscape 4
					var style2 = document.layers[arrDivs[ i ].id];
					style2.className  = "date";
				}		
			}else{
				if (document.getElementById) {
					// W3C standard
					var style2 = document.getElementById(arrDivs[ i ].id);
					style2.className  = "";
				} else if (document.all) {
					// old MSIE versions
					var style2 = document.all[arrDivs[ i ].id];
					style2.className  = "";
				} else if (document.layers) {
				// Netscape 4
					var style2 = document.layers[arrDivs[ i ].id];
					style2.className  = "";
				}
			}
		}
	}
	
}

function showAll(type) {
	var cCommonDivName = "section";
	var arrDivs = document.getElementsByTagName(type);

	for(i = 0 ; i < arrDivs.length ; i++) {
		if (arrDivs[ i ].id.match(cCommonDivName)) {
			show(arrDivs[ i ].id);
		}
	}
}



