//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>");
	}
}

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

/*
 * function get elements by class name ... simiar to getElementsByTagName
 * leave container arg out, and will default to document.
 */
function getElementsByClassName(className, container) {
  if (!container) {
  	container = document;
  }
  if (container.all) {
  	var all = container.all;
  } else {
  	var all = container.getElementsByTagName('*');
  }
  var arr = [] ;
  for(var k=0;k<all.length;k++) {
    if (all[k].className == className) {
      arr[arr.length] = all[k];
     }
  }
  return arr;
}

/*
 * Closes a tree of uls/lis (a menu for example) if scripts are enabled. Else leaves
 * the list open, so it is accessible to other users.
 * Note: this could be done in jQuery, but the list needs to close
 * as soon as it is loaded, so jQuery is not an option here.
 */
function closeList(listId, sublevelsClassName, closeAtLevel) {
	var list = document.getElementById(listId);
	
	for (i = closeAtLevel; i < 5; ++i) {
		var aUls = getElementsByClassName(sublevelsClassName+i, list);
		for (j = 0; j < aUls.length; ++j) {
			if (aUls[j].tagName == 'UL') { // only close ULs
				aUls[j].style.display = "none";
			}
		}
	}
}

/*
 * Closes any element by ID
 */
function hideElementById(elId) {
	var el = document.getElementById(elId);
	el.style.display = "none";
}

function isArray(obj) {
   return (obj.constructor.toString().indexOf("Array") == -1) ? false : true;
}