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("?vie=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(objectId) {
	if (document.getElementById) {
		closeMenu();
		object = document.getElementById(objectId);
		object.className = 'menu-l2-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 closeMenuList() {
	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;
}

function closeMenu() {
	if (document.getElementById) {
		var submenus = getElementsByClassName("menu-l2-open"); // get level 2 menu elements
		var x;
		// close all submenus in array
		for (x in submenus) {
			submenus[x].className = "menu-l2";
		}
	} else return false;
}

function closeMenuWithTimer(object, event) {
	if (!isMouseInObject(object, event)) {
		menuTimeoutId = setTimeout("closeMenu()", 1000);
		object.onMouseOver="cancelMenuWithTimer("+menuTimeoutId+")";
	}
}

function isMouseInObject(object, event) {
	mousePos = getMousePosition(event);
	mousePosX = mousePos.x;
	mousePosY = mousePos.y;
	objectPos = findElementPos(object);
	objectPosX = objectPos[0];
	objectPosY = objectPos[1];
	objWidth = GetWidth(object);
	objHeight = GetHeight(object);
	if (((mousePosX > objectPosX) && mousePosX < (objectPosX+objWidth)) && ((mousePosY > objectPosY) && mousePosY < (objectPosY+objHeight))) {
		return true;
	} else {
		return false;
	}
}

function cancelMenuWithTimer(menuTimeoutId) {
	alert("id:"+menuTimeoutId);
	clearTimeout(menuTimeoutId);
}

// get element position
function findElementPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


// get mouse position
function getMousePosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

// 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)
}*/

/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

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  = "";
				}
			}
		}
	}
	
}

// Bookmark the current page
// title = bookmark title
// url = bookmark url
function arctBookmarkIt(title,url) {
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if (window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if (document.all)// ie
		window.external.AddFavorite(url, title);
}

// Set the page as the home page - Only works in IE
// object = this
// url = 'http://www.karkoli.com'
function arctSetAsHomepage(object, url) {
	if (document.all) { // ie
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}
}

/*** Copy Right Information ***
  * Please do not remove following information.
  * Element Size v1.0
  * Author: John J Kim
  * Email: john@frontendframework.com
  * URL: www.FrontEndFramework.com
  * 
  * You are welcome to modify the codes as long as you include this copyright information.
 *****************************/
 
GetWidth = function(elem) {
	function _convertValue(val) {
		if (!val) {return;}
		val = parseInt(val.replace("px",""));
		if (!val || isNaN(val)) {return 0;}
		return val;
	}
	var currentStyle;
	if (elem.currentStyle)	{ currentStyle = elem.currentStyle; }
	else if (window.getComputedStyle) {	currentStyle = document.defaultView.getComputedStyle(elem, null); }
	else { currentStyle = elem.style; }
	
	return (elem.offsetWidth -
			_convertValue(currentStyle.marginLeft) -
			_convertValue(currentStyle.marginRight) -
			_convertValue(currentStyle.borderLeftWidth) -
			_convertValue(currentStyle.borderRightWidth));
}

GetHeight = function(elem) {
	function _convertValue(val) {
		if (!val) {return;}
		val = parseInt(val.replace("px",""));
		if (!val || isNaN(val)) {return 0;}
		return val;
	}
	var currentStyle;
	if (elem.currentStyle)	{ currentStyle = elem.currentStyle; }
	else if (window.getComputedStyle) {	currentStyle = document.defaultView.getComputedStyle(elem, null); }
	else { currentStyle = elem.style; }
	return (elem.offsetHeight -
	        _convertValue(currentStyle.marginTop) -
    	    _convertValue(currentStyle.marginBottom) -
        	_convertValue(currentStyle.borderTopWidth) -
        	_convertValue(currentStyle.borderBottomWidth));	
}
