		var insideinform=false;
		window.onload=init;
		var ld="";
		var allselected=new Array();
		function init() {
			menuinit();
			// forms multiple select js style
			if (allselected) {
				for (nm in allselected) {
					for (v in allselected[nm]) {
						if (allselected[nm][v] && v)
							addSelected(nm,allselected[nm][v],v);
					}
				}
			}
			var el,reg,ar;
			// check for click
			el=document.getElementsByClassName("click");
			reg=/show_([^ ]+)/;
			countclickable=1;
			for(var i=0;i<el.length;i++) {
				ar=el[i].className.match(reg);
				if (ar && ar[1]) { // has matched and layer array exists and has that index (from regex)
					if ((el[i].tagName.toUpperCase()=="INPUT") && (el[i].type.toUpperCase()=="CHECKBOX")) { // för checkboxar gäller - när den är ikryssad syns INTE divven som ska gömmas
						if (el[i].checked) document.getElementById(ar[1]).className+=" vanish";
					} else {
						document.getElementById(ar[1]).className+=" vanish";
					}
					if (!el[i].id) el[i].id="clickable_"+countclickable;
					countclickable++;
					el[i].onclick=new Function("toggleDisplay('"+ar[1]+"','"+el[i].id+"')"); // obs! går inte ha return false när det gäller checkbox...
				}
			}
		}
		

		// Forms mutliple select js style
		function addChoice(htmlname,showcode) {
			var el=document.getElementById(htmlname+"_select");
			var v=el.options[el.selectedIndex].value;
			var t=el.options[el.selectedIndex].text;

			if (v!="" && !allselected[htmlname][v]) {
				addSelected(htmlname,t,v,showcode);
			} else if (allselected[htmlname][v]) {
				alert(t+" är redan vald!");
			}
		}
		function addSelected(htmlname,t,v,showcode) {
			document.getElementById(htmlname+"_descr").style.display="block";
			var textdest=wordDestObj(htmlname);
			textdest.innerHTML+=wordMarkup(htmlname,t,v,showcode);
			allselected[htmlname][v]=t;
			var newHidden=document.createElement("input");
			newHidden.setAttribute("type","hidden");
			newHidden.setAttribute("value",v);
			newHidden.setAttribute("name",htmlname+"[]");// php array
			newHidden.id=htmlname+"_hid_"+v;
			var frm=document.getElementById(htmlname+"_select").form;
			frm.appendChild(newHidden);
		}
		function wordDestObj(htmlname) {
			return document.getElementById(htmlname+"_descr").getElementsByTagName("strong")[0];
		}
		function wordMarkup(htmlname,t,v,showcode) {
			return ' <a id="'+htmlname+"_txt_"+v+'" href="#" onclick="removeSelected(\''+htmlname+"','"+t+"','"+v+'\');return false;">'+((showcode)?v:t)+'</a>';
		}
		function removeSelected(htmlname,t,v) {
			var textdest=wordDestObj(htmlname);
			//textdest.innerHTML=textdest.innerHTML.replace(wordMarkup(htmlname,t,v),'');
			removeElementById(htmlname+"_hid_"+v);
			removeElementById(htmlname+"_txt_"+v);
			delete allselected[htmlname][v];
		}

		function removeElementById(ID) {
			var el=document.getElementById(ID);
			el.parentNode.removeChild(el);
		}
		// change visibiblity - display
		function toggleDisplay(ID,callerobjID) {
			var obj=document.getElementById(ID);
			var callerobj=document.getElementById(callerobjID);
			if (!obj) alert("There seems to be missing an object called "+ID);
/*			if (obj.style.display!="none") {
				obj.style.display="none";
			} else {
				obj.style.display="block";
			}*/
			if (obj.className.indexOf("vanish")!=-1) {
				obj.className=obj.className.replace("vanish","");
				if (insideinform) { 
					// #e9efc0 -> #fbfaf8
					toneBg(ID,new Array(233,239,192),new Array(251,250,248),10);
				} else {
					toneBg(ID,new Array(190,150,140),new Array(255,255,255),10);
				}
				callerobj.className=callerobj.className.replace("togbuttonshow","togbuttonhide");
			} else {
				//obj.className=obj.className.replace("updated","vanish");
				obj.className+=" vanish";
				callerobj.className=callerobj.className.replace("togbuttonhide","togbuttonshow");
			}
		}
		var toneBgCount=new Array(1);
		function toneBg(ID,from,to,steps,no) {
			var obj=document.getElementById(ID);
			
			if (!no) {
				var no=toneBgCount.length;
				toneBgCount[no]=0;
				var Rnew=from[0];
				var Gnew=from[1];
				var Bnew=from[2];
			} else {
			
				var Rnew=calcNewCol(from[0],to[0],steps,toneBgCount[no])
				var Gnew=calcNewCol(from[1],to[1],steps,toneBgCount[no])
				var Bnew=calcNewCol(from[2],to[2],steps,toneBgCount[no])
			}
			if (toneBgCount[no]<=steps) {
				obj.style.backgroundColor="rgb("+Rnew+","+Gnew+","+Bnew+")";
				toneBgCount[no]++;
				setTimeout("toneBg('"+ID+"',new Array("+from+"),new Array("+to+"),"+steps+","+no+")",30);
			} else {
				delete toneBgCount[no];
				obj.style.backgroundColor="rgb("+to[0]+","+to[1]+","+to[2]+")";
			}
			//obj.onclick=new Function("alert('"+obj.style.backgroundColor+"')");
		}
		function calcNewCol(from,to,steps,currentno) {
			if (to>from) {
				var diff=(to-from);
				var step=Math.round(diff/steps);
				var newCol=(from+step*currentno);
			} else {	
				var diff=(from-to);
				var step=Math.round(diff/steps);
				var newCol=(from-step*currentno);
			}
			return newCol;
		}


		// sligtly modified from inform utils, uses select ID instead
	function domSelectDate(ndate,dateY,dateM,dateD) { // input from database (ndate) and selectbox names as variables
		if (ndate) {
			year=ndate.substring(0,4);
			month=ndate.substring(5,7);
			day=ndate.substring(8,10);
		} else { // todays date
			today = new Date()
			var year=today.getYear();
			if (year < 2000) year+=1900;
			var month=today.getMonth()+1;
			if (month<10) month="0"+month;
			var day=today.getDate();
			if (day<10) day="0"+day;
		}
		domSelectRight(dateY,year);
		domSelectRight(dateM,month);
		domSelectRight(dateD,day);
	}
	function domSelectDateTime(ndate,dateY,dateM,dateD,dateH,dateMi) { // input from database (ndate) and selectbox names as variables
		domSelectDate(ndate,dateY,dateM,dateD); // date chosen here
		// start with time too:
		if (ndate) {
			hour=ndate.substring(11,13);
			minute=ndate.substring(14,16);
		} else { // todays date
			today = new Date()
			var hour=today.getHours();
			if (hour<10) hour="0"+hour;
			var minute=today.getMinutes();
			if (minute<10) minute="0"+minute;
		}
		domSelectRight(dateH,hour);
		domSelectRight(dateMi,minute);
	} 
	function domSelectRight(selectname,rvalue) {
		var obj=document.getElementById(selectname);
		for (o=0;o<obj.options.length;o++) {
			if (obj.options[o].value==rvalue) {
				obj.selectedIndex=o;
				break;
			}
		}
	}
		
// general 
function emptyNode(el) {
	while (el.firstChild)
		el.removeChild(el.firstChild);
}

/* Thanks to Jeremy Keith @media 2006 */
document.getElementsByClassName = function(name) {
  var results = new Array();
  var elems = document.getElementsByTagName("*");
  for (var i=0; i<elems.length; i++) {
    if (elems[i].className.indexOf(name) != -1) {
      results[results.length] = elems[i];
    }
  }
  return results;
}


