//drag & drop variables
var idselection;
var garbageid;
var isgarbage    = false;
var ismousedown  = false;
var isdragdrop   = false;
var enteraction ="";
var currentitemid ="";

//------------------------------------------------------------------------------
// suppress enter key 
// stops reloading page and forces user to use mouse button
// from www.WebCheatSheet.com
//------------------------------------------------------------------------------

function stopRKey(evt) 
{
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  
  {
    if (enteraction=="")
    {
      document.getElementById('warningtip').style.top = tempY;
      showpanel('warningtip');
      window.setTimeout("hidepanel('warningtip')",'3000');
      return false;
    }
    else
    {
      eval (enteraction);
      return false;
    }
    
  }
}
document.onkeypress = stopRKey;
//------------------------------------------------------------------------------
// find mouse XY coordinates
//------------------------------------------------------------------------------

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s and vertical scroll position of the browser window
var tempX = 0;
var tempY = 0;
var Y_CurrentScrollPos = 0;
var Y_PreviousScrollPos = 0;

// Main function to retrieve mouse x-y pos.s and reposition menu
function getMouseXY(e) 
{
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = (event.clientX + document.body.scrollLeft);
    tempY = (event.clientY + document.body.scrollTop);
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }
  reposition_menu();
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}


//------------------------------------------------------------------------------
// find position on screen
//------------------------------------------------------------------------------

function findPos(obj) //find relative-absolute position of an item - not used yed - useful for image annotation tool
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
  {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
    {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//------------------------------------------------------------------------------
// font size functions
//------------------------------------------------------------------------------

var min=8; //minimum font size
var max=18; // maximum font size

function increaseFontSize() // increase font size of all span entities
{
   var p = document.getElementsByTagName('span'); 
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px";
   }
}

function decreaseFontSize() // increase font size of all span entities
{
   var p = document.getElementsByTagName('span');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px";
   }   
}
      
//------------------------------------------------------------------------------
// general functions
//------------------------------------------------------------------------------

// Left function----------------------------------------------------------------
// left VB like function - returns a number of characrers from left side of a 
// string
// parameters:
//// str - input string
//// n - number of characters to return
function Left(str, n)
{
	if (n <= 0)
	  return "";
	else if (n > String(str).length)
	  return str;
	else
	  return String(str).substring(0,n);
}

// Right function---------------------------------------------------------------
// right VB like function - returns a number of characrers from right side of a 
// string
// parameters:
//// str - input string
//// n - number of characters to return
function Right(str, n) //rigt VB like function
{
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else 
  {
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}


//action timer function --------------------------------------------------------
//triggers a javascript function in x milliseconds
function function_actiontimer(functionname, timeInMilliseconds)
{
  window.setTimeout(functionname,timeInMilliseconds);
}

function eventsatresize()
{
  if (document.getElementById('mycanvas'))
  {
    if (document.getElementById('mycanvas').innerHTML != ""); 
    load_imageannotations();
  }
}

//------------------------------------------------------------------------------
//AJAX & search functions
//------------------------------------------------------------------------------

// paginate function------------------------------------------------------------
// paginates records retrieved from a search
// parameters:
//// searchtype - eg. image, glossary
//// searchstring  - the string criterion that was used to generate the recordset 
//// this needs to be forwarded to the other pages 
//// page - current page number
//// limits - is the number of records per page
//// searchlike - e.g. begining, containing
//// orderby - a custom string that defines a way to order results
function paginate(modulename,targetname,searchtype,searchstring,page,limits,searchlike,orderby)
{
  new Ajax.Updater(targetname, 'modules/'+modulename+'.php?searchtype='+searchtype+'&searchstring='+searchstring+'&page='+page+'&limits='+limits+'&searchlike='+searchlike+'&orderby='+orderby, {asynchronous:true, evalScripts:true });
}

// paginatethematic function----------------------------------------------------
// paginates thematic images
// parameters: 
//// thematicid - is the ID of a certain thematic
//// page - is current page number
//// limits - is the number of records per page
//// searchstring  - the string criterion that was used to generate the recordset 
//// searchtype - !!here: images/lastimages (sort order)!!
//// searchlike - e.g. begining, containing
function paginatethematic(thematicid,page,limits,searchstring,searchtype,searchlike)
{
  new Ajax.Updater('thematic_images', 'modules/thematic_images.php?thematicid='+thematicid+'&page='+page+'&limits='+limits+'&searchstring='+searchstring+'&searchtype='+searchtype+'&searchlike='+searchlike, {asynchronous:true, evalScripts:true });
}

// loadfunction_get--------------------------------------------------------------
// calls a certain function through AJAX using GET method
// parameters: 
//// functionname - is the name of the function file
//// targetname - is the name of the panel to which this function outputs content (e.g. the ID of a div or span)
//// parameters - is any parameter string needed by the function; they are 
//// rendered as parameters for any GET method (e.g. itemid=10&details=yes)
function loadfunction_get(functionname,targetname,parameters)
{
  new Ajax.Updater(targetname, 'functions/'+functionname+'.php?'+parameters, {asynchronous:true, evalScripts:true});
}

// loadmodule_get----------------------------------------------------------------
// calls a certain module through AJAX using GET method
// parameters: 
//// modulename - is the name of the module file
//// targetname - is the name of the panel where the module is loaded (e.g. the ID of a div or span)
//// parameters - is any parameter string needed by the function; they are rendered as parameters for any GET method (e.g. itemid=10&details=yes)
function loadmodule_get(modulename,targetname,parameters)
{
  new Ajax.Updater(targetname, 'modules/'+modulename+'.php?'+parameters, {asynchronous:true, evalScripts:true});
  switch (targetname) {
    case 'content_panel':
      if (document.getElementById('content_panel'))   {maximizepannel('content_panel', 'content_toogle');};
      break;
    case 'search_panel':
      if (document.getElementById('search_panel'))    {maximizepannel('search_panel', 'search_toogle');};
      break;
    case 'thematics_panel':
      if (document.getElementById('thematics_panel')) {maximizepannel('thematics_panel', 'thematics_toogle');};
      break;
    default:
      break;
  }
}

// loadperiodicalmodule_get-----------------------------------------------------
// calls a certain module through AJAX using GET method but adds periodical calls
// parameters 
//// modulename - is the name of the module file
//// targetname - is the name of the panel where the module is loaded (e.g. the ID of a div or span)
//// parameters - is any parameter string needed by the function; they are rendered as parameters for any GET method (e.g. itemid=10&details=yes)
//// frequencyvalue - value in seconds defining intervals of calls
//// decayvalue - object refresh rate when the received response is the same as the last one; for example, if you use 2, after one of the refreshes produces the same result as the previous one, the object will wait twice as much time for the next refresh; use 1 to avoid the slowdown.
function loadperiodicalmodule_get(modulename,targetname,parameters,frequencyvalue,decayvalue)
{
  new Ajax.PeriodicalUpdater(targetname, 'modules/'+modulename+'.php?'+parameters, {asynchronous:true, evalScripts:true, frequency : frequencyvalue, decay : decayvalue });
}

// loadbits_get-----------------------------------------------------------------
// calls a certain HTML bit through AJAX using GET; perhaps this will become obsolete
// parameters: 
//// bitname - is the name of the HTML file
//// targetname - is the name of the panel where the module is loaded (e.g. the ID of a div or span)
//// parameters - is any parameter string needed by the function; they are rendered as parameters for any GET method (e.g. itemid=10&details=yes)
function loadbits_get(bitname,targetname,parameters)
{
  new Ajax.Updater(targetname, 'bits/'+bitname+'.php?'+parameters, {asynchronous:true, evalScripts:true});
}

// loadmodule_post--------------------------------------------------------------
// calls a certain module through AJAX using POST method
// parameters 
//// formname - is the name of a form that contains variables
//// modulename - is the name of the module file that will be loaded
//// targetname - is the name of the panel where the module is loaded (e.g. the ID of a div or span)
function loadmodule_post(formname,modulename,targetname)
{
  var params = Form.serialize(document.getElementById(formname));
  new Ajax.Updater(targetname, 'modules/'+modulename+'.php', {method:'post',asynchronous:true, evalScripts:true, parameters:params});
}

// loadfunction_post--------------------------------------------------------------
// calls a certain module through AJAX using POST method
// parameters 
//// formname - is the name of a form that contains variables
//// functionname - is the name of the function file that will be loaded
//// targetname - is the name of the panel where the module is loaded (e.g. the ID of a div or span)
function loadfunction_post(formname,functionname,targetname)
{
  var params = Form.serialize(document.getElementById(formname));
  new Ajax.Updater(targetname, 'functions/'+functionname+'.php', {method:'post',asynchronous:true, evalScripts:true, parameters:params});
}

// loadcontent function----------------------------------------------------------
// searches for an article (e.g. information, contact us, a certain help page) 
// using the article page ID; the article is loaded within the content_panel
// parameters 
//// itemid - is the ID of a certain article (an integer)
function loadcontent_id(itemid)
{
  new Ajax.Updater('content_panel', 'modules/content_details.php?itemid='+itemid, {asynchronous:true, evalScripts:true});
}

// loadcontent_entity function----------------------------------------------------------
// searches for an article (e.g. information, contact us, a certain help page) 
// using the article title-entity ID (page entity id); the article is loaded within the content panel
// parameters 
//// pageentityid - is the page entity ID of a certain article (a string; e.g. contact, information)
function loadcontent(pageentityid)
{
  var url_array=pageentityid.split("#");
  var internalanchor = "";
  if (url_array.length >1)
    internalanchor = "&internalanchor="+url_array[1];
  new Ajax.Updater('content_panel', 'modules/content_details.php?pageentityid='+url_array[0]+internalanchor, {asynchronous:true, evalScripts:true});
  maximizepannel('content_panel', 'content_toogle');
}

// loadnews function------------------------------------------------------------
// searches for a news item using the news item ID
// the article is loaded within the content_panel
// parameters 
//// newsid - is the ID of a certain news
function loadnews(newsid)
{
  new Ajax.Updater('content_panel', 'functions/ajax/search_news.php?newsid='+newsid, {asynchronous:true, evalScripts:true});
}

//------------------------------------------------------------------------------
//functions that are used to set visibility and appeareance of panels displayed 
//within the biodiv main template. Some of them will reposition the menu.
//------------------------------------------------------------------------------

// dp_controlcombobox function--------------------------------------------------
// This function controls the visibility of combobox items during data input.
// parameters
//// entity - the id of the combobox selection list
//// currentvalue - the current value of the combobox
function dp_controlcombobox(entity,currentvalue)
{
  if (currentvalue == ""){
    document.getElementById(entity).style.display = "none";
    document.getElementById(entity).style.visibility = "hidden";
  }else{
    document.getElementById(entity).style.display = "block";
    document.getElementById(entity).style.visibility = "visible";
  }
}

// dp_highlightcbitems function-------------------------------------------------
// This function highlights matching combobox items during data input.
// parameters
//// entity - the id of the combobox selection list
//// currentvalue - the current value of the combobox
function dp_highlightcbitems(entity,currentvalue)
{
  var itemtxt = "";
  var cbitems = document.getElementById(entity).getElementsByTagName("div");
  if(cbitems.length > 0){
    for (var i = 0; i < cbitems.length; i++) {
      if (cbitems[i].className == "comboboxitem"){
        itemtxt = cbitems[i].innerHTML;
        if ((currentvalue != "") && (itemtxt.indexOf(currentvalue) == 0)){
          cbitems[i].style.color = "black";
        } else {
          cbitems[i].style.color = "gray";
        }
      }
    }
  }
}

// dp_hideblock function--------------------------------------------------------
// hides a DIV or any other block element.
// parameter
//// entity - the id of the element
function dp_hideblock(entity)
{
  if (document.getElementById(entity))
  {
    document.getElementById(entity).style.display = "none";
    document.getElementById(entity).style.visibility = "hidden";
  }
}

// dp_toggleblock function-------------------------------------------------------
// shows or hides a DIV or any other block element.
// parameter
//// entity - the id of the element
function dp_toggleblock(entity)
{
  if (document.getElementById(entity))
  {
    if (document.getElementById(entity).style.display == "block")
    {
      document.getElementById(entity).style.display = "none";
      document.getElementById(entity).style.visibility = "hidden";
    }
    else
    {
      document.getElementById(entity).style.display = "block";
      document.getElementById(entity).style.visibility = "visible";
    }
  }
}

// tooglepannel function--------------------------------------------------------
// shows or hides a panel and repositions menu
// parameters 
//// entity - panel entityid
//// entitybutton - button entityid
function tooglepannel(entity,entitybutton) //show hide panel
{
  if (document.getElementById(entity).style.display == "block")
  {
    document.getElementById(entity).style.display = "none";
    document.getElementById(entity).style.visibility = "hidden";
    document.getElementById(entitybutton).src="images/arrow_down_1.png";
  }
  else
  {
    document.getElementById(entity).style.display = "block";
    document.getElementById(entity).style.visibility = "visible";
    document.getElementById(entitybutton).src="images/arrow_up_1.png";
  }
  reposition_menu();
}

// minimizepannel function--------------------------------------------------------
// hides a panel and repositions menu
// parameters 
//// entity - panel entityid
//// entitybutton - button entityid
function minimizepannel(entity,entitybutton) //hide panel
{
  document.getElementById(entity).style.display = "none";
  document.getElementById(entity).style.visibility = "hidden";
  document.getElementById(entitybutton).src="images/arrow_down_1.png";
  reposition_menu();
}

// maximizepannel function--------------------------------------------------------
// shows a panel and repositions menu
// parameters 
//// entity - panel entityid
//// entitybutton - button entityid
function maximizepannel(entity,entitybutton) //show panel
{
  document.getElementById(entity).style.display = "block";
  document.getElementById(entity).style.visibility = "visible";
  document.getElementById(entitybutton).src="images/arrow_up_1.png";
  reposition_menu();
}

// hidepanel function-----------------------------------------------------------
// hides any panel (without button control) and repositions menu
// parameters 
//// entity - panel entityid
function hidepanel(entity)
{
  document.getElementById(entity).style.display = "none";
  document.getElementById(entity).style.visibility = "hidden";
  reposition_menu();
}

// showpanel function-----------------------------------------------------------
// shows any panel (without button control) and repositions menu
// parameters 
//// entity - panel entityid
function showpanel(entity) //show any panel
{
  document.getElementById(entity).style.display = "block";
  document.getElementById(entity).style.visibility = "visible";
  reposition_menu();
}

//functions for moving panels---------------------------------------------------
movepanelup = function(objectname)
{
  var sp2 = document.getElementById('frame_'+objectname);
  var parentObject = sp2.parentNode;
  if (parentObject.firstChild!=sp2) //if not first child in list
  {
    if (parentObject.childNodes[1]==sp2)
    {
      document.getElementById("moveupicon_"+objectname).src="images/move_up_disabled.png";
      var firstchildid = parentObject.childNodes[0].id;
      var firstchildrootname = firstchildid.replace(/frame_/, "");
      document.getElementById("moveupicon_"+firstchildrootname).src="images/move_up.png";
    }
    if (parentObject.childNodes[parentObject.childNodes.length-1]==sp2)
    {
      var penlastchild = parentObject.childNodes[parentObject.childNodes.length-2].id;
      var penlastchildrootname = penlastchild.replace(/frame_/, "");
      document.getElementById("movedownicon_"+penlastchildrootname).src="images/move_down_disabled.png";
      var lastchild = parentObject.childNodes[parentObject.childNodes.length-1].id;
      var lastchildrootname = lastchild.replace(/frame_/, "");    
      document.getElementById("movedownicon_"+lastchildrootname).src="images/move_down.png";
    }
    var sp1 = sp2.previousSibling;
    parentObject.insertBefore(sp2, sp1);
    generatepanelarray(parentObject);
  }
}
movepaneldown = function(objectname)
{
  var sp2 = document.getElementById('frame_'+objectname);
  var parentObject = sp2.parentNode;
  if (parentObject.lastChild!=sp2) //if not first child in list
  {
    var sp1 = sp2.nextSibling;
    if (parentObject.childNodes[parentObject.childNodes.length-1]==sp1)
    {
      var penlastchild = parentObject.childNodes[parentObject.childNodes.length-2].id;
      var penlastchildrootname = penlastchild.replace(/frame_/, "");
      document.getElementById("movedownicon_"+penlastchildrootname).src="images/move_down_disabled.png";
      var lastchild = parentObject.childNodes[parentObject.childNodes.length-1].id;
      var lastchildrootname = lastchild.replace(/frame_/, "");
      document.getElementById("movedownicon_"+lastchildrootname).src="images/move_down.png";
    }
    if (parentObject.childNodes[0]==sp2)
    {
      document.getElementById("moveupicon_"+objectname).src="images/move_up.png";
      var penfirstchild = parentObject.childNodes[1].id;
      var penfirstchildrootname = penfirstchild.replace(/frame_/, "");
      document.getElementById("moveupicon_"+penfirstchildrootname).src="images/move_up_disabled.png";
    }  
    parentObject.insertBefore(sp2, sp1.nextSibling);
    generatepanelarray(parentObject);
  }
}

//function for generating an array of central panels; this will be used to sort panels by user
generatepanelarray = function (parentObject)
{
    var children = parentObject.childNodes;
    var nodesstring ="";
    var arr = new Array(children.length)
    for (var i = 0; i < children.length; i++) 
    {
      arr[i]=parentObject.childNodes[i].id;
    }   
    nodesstring=arr.join(',');
    createCookie('centralpanelsort',nodesstring,30);
}

//function for cleaning returns, spaces and other entities than elements - necessary for Mozilla
cleanpanelarray = function (objectname) 
{
  if (document.getElementById(objectname))
  {
    parentObject =document.getElementById(objectname);
    var children = parentObject.childNodes;
    var arr = new Array(children.length)
    for (var i = 0; i < children.length; i++) 
    {
      if (parentObject.childNodes[i].nodeType >1)
        parentObject.removeChild(parentObject.childNodes[i]);
    }
  }
}

//function for sorting panels according to user preferences
getuserpanelsort = function(objectname)
{
  resizepanelstatus = readCookie('centralpanelsort');
  if (resizepanelstatus != null)
  {
    var parentObject = document.getElementById(objectname);
    var arr = resizepanelstatus.split(',');
    for (var i = 0; i < arr.length; i++) 
    {
      try
      {
        var index = arr.length - i -1;
        if (document.getElementById(arr[index]))
        {
          var sp1=document.getElementById(arr[index]);
          parentObject.insertBefore(sp1, parentObject.firstChild);
        }
      }
      catch(err)
      {
      }
    }
  }   
  resetmovefirstlasticons(parentObject);
}
//function for resetting first and last for move up move down icons
resetmovefirstlasticons = function(parentObject)
{
  //disable icon for first up and last down
  if (parentObject)
  {
    var children = parentObject.childNodes;
    var firstchild = parentObject.childNodes[0].id;
    var firstchildrootname = firstchild.replace(/frame_/, "");
    document.getElementById("moveupicon_"+firstchildrootname).src="images/move_up_disabled.png";
    document.getElementById("movedownicon_"+firstchildrootname).src="images/move_down.png";
    var lastchild = parentObject.childNodes[children.length-1].id;
    var lastchildrootname = lastchild.replace(/frame_/, "");
    document.getElementById("movedownicon_"+lastchildrootname).src="images/move_down_disabled.png";
    document.getElementById("moveupicon_"+lastchildrootname).src="images/move_up.png";
  }
}

//This function controls the initial min/max status of the Content, Search and Set Panel:
//The panel referenced by URL anchor, or the upper panel will be maximized,
//the other two panels will be minimized, in order to simplify the initial appearance of the website.
//The function will be called after website (re)load or after login (via 'template_1.htm' or 'sign_in.php').
minimaxmainpanels = function(objectname)
{
  var anchorstring = window.location.hash;
  switch (anchorstring) {
    case '#content':
      //alert("Content Panel will be maximized, the other will be minimized.");
      maximizepannel('content_panel', 'content_toogle');
      minimizepannel('search_panel', 'search_toogle');
      minimizepannel('thematics_panel', 'thematics_toogle');
      break;
    case '#search':
      //alert("Search Panel will be maximized, the other will be minimized.");
      maximizepannel('search_panel', 'search_toogle');
      minimizepannel('content_panel', 'content_toogle');
      minimizepannel('thematics_panel', 'thematics_toogle');
      break;
    case '#thematics':
      //alert("Set Panel will be maximized, the other will be minimized.");
      maximizepannel('thematics_panel', 'thematics_toogle');
      minimizepannel('content_panel', 'content_toogle');
      minimizepannel('search_panel', 'search_toogle');
      break;
    default:
      //alert("The upper panel will be maximized, the other will be minimized.");
      var parentObject = document.getElementById(objectname);
      var children = parentObject.childNodes;
      var isupperpanel = true;
      for (var i = 0; i < children.length; i++) {
        var childrootname = children[i].id.replace(/frame_/, "");
        switch (childrootname) {
          case 'content':
            if (isupperpanel) {
              //alert(i + ' content_panel will be maximized.');
              maximizepannel('content_panel', 'content_toogle');
              isupperpanel = false;
            }else{
              //alert(i + ' content_panel will be minimized.');
              minimizepannel('content_panel', 'content_toogle');
            };
            break;

          case 'search':
            if (isupperpanel) {
              //alert(i + ' search_panel will be maximized.');
              maximizepannel('search_panel', 'search_toogle');
              isupperpanel = false;
            }else{
              //alert(i + ' search_panel will be minimized.');
              minimizepannel('search_panel', 'search_toogle');
            };
            break;

          case 'thematics':
            if (isupperpanel) {
              //alert(i + ' thematics_panel will be maximized.');
              maximizepannel('thematics_panel', 'thematics_toogle');
              isupperpanel = false;
            }else{
              //alert(i + ' thematics_panel will be minimized.');
              minimizepannel('thematics_panel', 'thematics_toogle');
            };
            break;

          default:
            //alert(i + ' ' + childrootname + '_panel will not be toggled.');
            break;
        }
      }
      break;
  }
}

//The following two functions transform the menu into a collapsible menu.
postprocess_menu = function()
{
  var counter = 0, showme = 1;
  var menudivs = document.getElementById("menu_panel").getElementsByTagName("div");
  var togglebuttn = "<img src='images/show_submenu.png' style='margin:2px; cursor:pointer; float:right' onclick='togglesubmenu(this);'>";
  for (var i = 0; i < menudivs.length; i++) {
    if (menudivs[i].className == "buttons") {
      menudivs[i].innerHTML = togglebuttn + menudivs[i].innerHTML;
      menudivs[i].style.marginTop = "1px";
      counter++;
      if (counter == showme) {var showthis = menudivs[i].getElementsByTagName("img")[0];};
    }else{
      if (menudivs[i].className == "buttons2") {
        menudivs[i].style.display = "none";
      }
    }
  }
  if (showthis) {togglesubmenu(showthis);};
}

togglesubmenu = function(obj)
{
  var togglefrom = -1, toggleto = -1;
  var imguri   = obj.src.split("/");
  var imgname  = imguri[imguri.length - 1];
  var header   = obj.parentNode;
  var menudivs = document.getElementById("menu_panel").getElementsByTagName("div");
  for (var i = 0; i < menudivs.length; i++) {
    if (menudivs[i].className == "buttons") {
      if (menudivs[i] == header) {togglefrom = i + 1;};
      if ((menudivs[i] != header) && (togglefrom != -1) && (toggleto == -1)) {toggleto = i - 1;};
    }
  }
  if (toggleto == -1) {toggleto = menudivs.length - 1;};
  //alert("toggle items from " + togglefrom + " to " + toggleto);
  switch (imgname) {
    case 'show_submenu.png':
      for (var i = togglefrom; i <= toggleto; i++) {
        if (menudivs[i].className == "buttons2") {menudivs[i].style.display = "block";};
      }
      obj.src = 'images/hide_submenu.png';
      break;

    case 'hide_submenu.png':
      for (var i = togglefrom; i <= toggleto; i++) {
        if (menudivs[i].className == "buttons2") {menudivs[i].style.display = "none";};
      }
      obj.src = 'images/show_submenu.png';
      break;

    default:
      alert('wrong image file name for toggle menu button!');
      break;
  }
}

//This function repositions the menu to be always available
//triggered by functions: getMouseXY, tooglepannel, minimizepannel, maximizepannel, hidepanel, showpanel, menu_panel.onclick (delay:1000)
reposition_menu = function()
{
  var banner = IE? 130 : 124;
  Y_CurrentScrollPos = IE? document.body.scrollTop : window.pageYOffset;
  while (Y_CurrentScrollPos != Y_PreviousScrollPos) {
    //alert("You vertically scrolled to " + Y_CurrentScrollPos);
    Y_PreviousScrollPos = Y_CurrentScrollPos;
    if (Y_CurrentScrollPos < banner) {
      document.getElementById("menu_panel").style.marginTop = 0;
    }else{
      document.getElementById("menu_panel").style.marginTop = Y_CurrentScrollPos - banner;
    }
    Y_CurrentScrollPos = IE? document.body.scrollTop : window.pageYOffset;
  }
}



// printcontent function--------------------------------------------------------
// pens a popup window and present the content of a module for printing
// parameters 
//// divid - the entity ID of module to be printed
function printcontent(divid)
{
  win = window.open('about:blank','Popup_Window','width=800,height=700,scrollbars=yes,menubar=yes,toolbar=no,location=no,status=no');
  var tmp = win.document;
  var stylestring = "<link rel='stylesheet' type='text/css' href='css_stylepages/dataprovider_css_1.css'>";
  tmp.write(stylestring + "<div class='simpletext' style='text-align:left;'>" + document.getElementById(divid).innerHTML + "</div>");
  tmp.close();
  if (window.print) win.print();

}

// scrollpage function----------------------------------------------------------
// scrolls the document to a certain position in page
// parameters 
//// pagetag -  is the internal anchor to which the document will be scrolled (e.g. #top, #thematics, #content)
function scrollpage(pagetag)
{
  window.location=pagetag;
}


//scrolls page for internal anchors at first load of webapplication
function scrollfirstload()
{
  urlstring=window.location.href; //get url
  var urlparts = urlstring.split("#"); //split url
  if (urlparts.length >1) //if anchor provided
  {
    internalanchor = urlparts[1]; //get anchorname
    var functionstring = "scrollpage('#" + internalanchor + "')"; //build function string
    window.setTimeout(functionstring,4000); //redirect to anchor in x miliseconds
  }
}

// changetitle function---------------------------------------------------------
// changes the title in the title bar (header) of a panel
// parameters 
//// titleids is the id of the span entity that contains the title of a panel
//// title text is any string
function changetitle(titleid,titletext)
{
  document.getElementById(titleid).innerHTML=titletext
}

//------------------------------------------------------------------------------
// tooltips and popup menus
//------------------------------------------------------------------------------

// showglossarytooltip function-------------------------------------------------
// function for displaying a glossary internal tooltip 
// parameters:
//// glossaryid - an ID of a glossary term
function showglossarytooltip(glossaryid)
{
  new Ajax.Updater('tooltip', 'functions/search_glossary_term.php?glossaryid='+glossaryid, {asynchronous:true, evalScripts:true});
  document.getElementById('tooltip').style.display = "block";
  document.getElementById('tooltip').style.visibility = 'visible';
  document.getElementById('tooltip').style.left = tempX-100;
  document.getElementById('tooltip').style.top = tempY+20;
}

// showtooltip function---------------------------------------------------------
// generic function for displaying any internal tooltip 
// parameters:
//// tootipcontent - any string that will be displayed in the tooltip
function showtooltip(tootipcontent)
{
  document.getElementById('tooltip').innerHTML= tootipcontent;
  document.getElementById('tooltip').style.display = "block";
  document.getElementById('tooltip').style.visibility = "visible";
  document.getElementById('tooltip').style.left = tempX-100;
  document.getElementById('tooltip').style.top = tempY+20;
}

// showpopupmenu function---------------------------------------------------------
// generic function for displaying any popup menu
// parameters:
//// popupcaption - any html content that will be displayed in the popup menu header
//// popupcontent - any html content that will be displayed in the popup menu body
function showpopupmenu(popupcaption, popupcontent)
{
  document.getElementById("popupcaption").innerHTML = popupcaption;
  document.getElementById("popupcontent").innerHTML = popupcontent;
  document.getElementById("popupmenu").style.display = "block";
  document.getElementById("popupmenu").style.visibility = "visible";
  document.getElementById("popupmenu").style.left = tempX-75;
  document.getElementById("popupmenu").style.top = tempY+20;
}

// wiki_tooltip function--------------------------------------------------------
// used to harvest content from wikipedia in a tooltip; user selects a string in 
// document and clicks on the Wikipedia button. This function allows checks if
// a text was selected and if YES places a call to Wikipedia remote resource
function wiki_tooltip()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    else return;
    if (txt != '') //if text selected
    {
      loadmodule_get('wikipedia_dictionary','tooltip',"term="+txt);
      document.getElementById('tooltip').style.display = "block";
      document.getElementById('tooltip').style.visibility = 'visible';
      document.getElementById('tooltip').style.left = tempX-100;
      document.getElementById('tooltip').style.top = tempY+20;
    }
  else //if text not selected
    showtooltip('select a term in text and then click on this button to check in Wikipedia');  
}


//readCookie -------------------------------------------------------------------
//js function for reading cookies
//http://www.quirksmode.org/js/cookies.html
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//readCookie -------------------------------------------------------------------
//js function for reading cookies
//http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function setenteraction(actionstring)
{
  enteraction=actionstring;
}

function unsetenteraction()
{
  enteraction="";
}


//help functions ---------------------------------------------------------------
// author:      Spindler                                     
// last update: 20070917                                     
// content:     bookmark functions for help text navigation   
// feature:     enables back navigation to last internal link 


var hlp_bookm_isset = false;

hlp_set_bookmark = function(peid) {
   hlp_bookmXscroll = document.body.scrollLeft;
   hlp_bookmYscroll = document.body.scrollTop;
   hlp_bookmPEID    = peid;
   hlp_bookm_isset  = true;
};

hlp_goto_bookmark = function() {
   hlp_bookm_isset = false;
   loadcontent(hlp_bookmPEID);
   setTimeout("scrollTo(hlp_bookmXscroll, hlp_bookmYscroll);", 1000);
};

hlp_control_bookmark_buttons = function() {
   if (document.getElementById("hlp_bmtip")) {document.getElementById("hlp_bmtip").style.display = "none";};
   hlp_bookm_buttns = document.getElementsByName("hlp_nav_bookm");
   if (hlp_bookm_buttns.length > 0) {
      for (var i = 0; i < hlp_bookm_buttns.length; i++) {
         hlp_bookm_buttns[i].style.display = (hlp_bookm_isset) ? "" : "none";
      };
   };
};

hlp_show_bmtip = function() {

    if (document.getElementById("hlp_bmtip")) {

       document.getElementById("hlp_bmtip").style.left = tempX+15;

       document.getElementById("hlp_bmtip").style.top  = tempY+15;

       document.getElementById("hlp_bmtip").style.display = "";

       setTimeout("if (document.getElementById('hlp_bmtip')) {document.getElementById('hlp_bmtip').style.display = 'none';};", 2000);

    };

};


//--------------------------------------------------------------------------------
