function exptreeInit(theId,samtliga) {
  var x, y, i, j, boolExpand, boolTop, topCount;
  x = getObject(theId).getElementsByTagName('div');
  // Skapa räknare för nodtyper
  var topCount = new Object();
  for (i=0;i<x.length;i++) {
    boolExpand=false;
    x[i].id.indexOf('_content')<0 ? boolTop=true : boolTop=false
    if (boolTop==true) {
    	// Hämta nodtypen
    	var nodPrefix = x[i].id.replace(/\d+\D*/g,"")
    	// Ignorera nodtypen "utomlands"
    	if (nodPrefix!='nodTrue') {
    		// Öka nodtypen med 1
    		if (!topCount[nodPrefix]) {
    			topCount[nodPrefix] = new Object();
    			topCount[nodPrefix]._count = 1;
    		} else {
    			topCount[nodPrefix]._count++;
    		}
    		// Lagra nodens id
   			topCount[nodPrefix]._name = x[i].id;
	    }
//	    topCount++;
      x[i].onclick = function() { exptreeToggle(this.id); }
      x[i].onmouseover = function() { exptreeOver(this.id); }
      x[i].onmouseout = function() { exptreeOut(this.id); }
 		} else if (boolExpand==false) {
      y = x[i].getElementsByTagName('input');
      // Loopa igenom checkboxar
      for (j=0;j<y.length;j++) {
      	if(y[j].id.indexOf('_samtliga')>0) {
		      y[j].onclick = function() { exptreeSamtliga(this.id); }
      	}
        if(y[j].checked==true) {
          boolExpand=true;
          exptreeExpand(getObject(x[i].id.substring(0,x[i].id.lastIndexOf('_content'))).id);
          break;
        }
      }
    }
  }
  
	for (var i in topCount) {
		if (topCount[i]._count == 1) {
	    exptreeExpand(topCount[i]._name);
	  }
	}
//	if (topCount == 1) { 
//	  x = getObject(theId).getElementsByTagName('div');
//    exptreeExpand(x[0].id);
//  }
}
function exptreeToggle(theId) {
	var theContent, theDiv;
	theDiv = getObject(theId);
	theContent = getObject(theId+'_content');
	if (theContent.style.display == 'block') {
    theDiv.className = 'nod collapsed';
		theContent.style.display = 'none';
	} else {
    theDiv.className = 'nod expanded';
		theContent.style.display = 'block';
	}
}
function exptreeExpand(theId) {
	var theContent, theDiv;
	theDiv = getObject(theId);
	theContent = getObject(theId+'_content');
  theDiv.className = 'nod expanded';
	theContent.style.display = 'block';
}
function exptreeOver(theId) {
	var theDiv, theClass;
	theDiv = getObject(theId);
  theClass = theDiv.className;
  if (theClass == 'nod collapsed') {
    theDiv.className = 'nod collapsed hover';
  } else if (theClass == 'nod expanded') {
    theDiv.className = 'nod expanded hover';
  }
}
function exptreeOut(theId) {
	var theDiv, theClass;
	theDiv = getObject(theId);
  theClass = theDiv.className;
  if (theClass == 'nod collapsed hover') {
    theDiv.className = 'nod collapsed';
  } else if (theClass == 'nod expanded hover') {
    theDiv.className = 'nod expanded';
  }
}
function exptreeSamtliga(theId) {
  var x, i, isChecked;
  isChecked = getObject(theId).checked;
  x = getObject(theId.substring(0,theId.lastIndexOf('_samtliga'))+'_content').getElementsByTagName('input');
  for (i=0;i<x.length;i++) {
  	if(x[i].id!=theId) {
      x[i].checked = isChecked;
    }
  }
}
function getObject(theId) {
	if (document.getElementById) {
		return document.getElementById(theId);
	} else if (document.all) {
    return document.all[theId];
  }
}