function isFirefox()
{
  if(navigator.userAgent.indexOf("Firefox")!=-1){
  var versionindex=navigator.userAgent.indexOf("Firefox")+8
  if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
   return true;
  }
  return false;
}

function gotourl(url, target, confirmclick, confirmtext, confirmparams) {
  var ok
  ok = true
  if (confirmtext == '') {
    confirmtext = confirmparams;
	confirmparams = '';
  }
  
  if (confirmclick == 1) {
    
    if (!confirm(paramtext(confirmtext, confirmparams.split('|')))) ok = false
  }
  if (ok) {
    if (target != '') {
      window.open(url, target);
      // 'toolbar=no,resizable=yes,width='+ width +',height='+ height +',left='+left+',top='+top+',scrollbars=yes'
    } else
      location.href = url;
  }
  return true;  
}

function actionmouseover(obj) {
  var firefox = isFirefox();
  if (firefox==false){
    for (var i = 0; i < obj.children.length; i++) {
      obj.children[i].className = 'actionwindow_highlight';
      obj.children[i].background = getbasehttp +'/images_action/popupmenubackgroundhigh.gif';;
    }
  }
}

function actionmouseout(obj) {
  var firefox = isFirefox();
  if (firefox==false){
    for (var i = 0; i < obj.children.length; i++) {
      obj.children[i].background = getbasehttp +'/images_action/popupmenubackground.gif';
      obj.children[i].className = 'actionwindow_normal';
    }
  }
}

// action er en linie i funktionerne for en record
function taction( url, title, img, target, confirmclick, confirmtext, confirmparams ) {
  this.url     = url;
  this.title   = title; 
  this.img     = img; 
  this.target  = target;
  this.show    = taction_show;
  this.confirmtext = confirmtext;
  this.confirmclick = confirmclick
  this.confirmparams = confirmparams;
  this.index = -1;
}

// viser action linien
function taction_show(number) {
  var options = '';
  
  var confirmtext = ''
  confirmtext = this.confirmtext;
  if (isundefined(confirmtext)) confirmtext = '';
  if (confirmtext == '') confirmtext = eval('res = this.owner.owner.confirmtext[number]')
  if (isundefined(confirmtext)) confirmtext = '';
  confirmtext = confirmtext.replace( /"/gi, "'");
  confirmtext = confirmtext.replace( /'/gi, "\\'");
  confirmtext = confirmtext.replace( /\r/gi, "\\r");
  if (this.url != '') {
    if (this.target != '') 
      options += ' target="' + this.target + '" ';
    
    if (this.img.toLowerCase().indexOf('http://') == -1 && this.img.toLowerCase().indexOf('https://') == -1) this.img = getbasehttp + this.owner.owner.imageoffset + this.img;
    
    var cururl = this.url;
    if (cururl.indexOf('javascript:') == -1) 
      cururl = 'return gotourl(\''+this.url +'\', \'' + this.target + '\','+ this.confirmclick +', \'' + confirmtext + '\',  \'' + this.confirmparams + '\' )'
    else
      cururl = this.url;
      
    var res = '<tr onMouseOver="actionmouseover(this)" onMouseOut="actionmouseout(this)" >'+
                '<td nowrap background="'+ getbasehttp +'/images_action/popupmenubackground.gif" onClick="dblist_hideall(); '+ cururl +'">'+
                  '<img align="absmiddle" src="'+ this.img + '" border=0 hspace="2">' + 
                  '<img src="'+ getbasehttp + 'images/trans.gif" width="6">'+
                  this.title + 
                '</td>'+
              '</tr>';
  } else {
    var res = '<tr>'+ 
                '<td class="actionwindow_splitter" background="'+ getbasehttp +'/images_action/popupmenubackgroundsplitter.gif">'+
                  '<img src="'+ getbasehttp + 'images/trans.gif" width="1">'+
                '</td>'+
              '</tr>';
  }       
  return res;           
}

// actiongroup er samlingen af funktioner for en record
function tactiongroup(id) {
  var res  = new deflist()
  res.id   = id;
  res.classname = 'actionlisttable';
  res.show = tactiongroup_show;
  res.add  = tactiongroup_add;
  return res; 
}

// tilføjer actionen, hvis url ikke er blank
function tactiongroup_add(index, item) {
//  if (item.url == '') {
//    item = undefined
//  } else {
    item.owner = this;
    item.index = index;
    this[this.length] = item;
//  }
}

// viser listen af actions for en record
function tactiongroup_show() {
  if (this.length == 0) return '';
  res = '<table class="'+this.classname+'" cellpadding="3" cellspacing="0" border="0" width="100%">'+
	         '<tr>'+
					   '<td style="padding:0px;" bgcolor="#2B2762" align="right">'+
						   '<img src="/images_action/close_actionwindow.gif" />'+
						 '</td>'+
					 '</tr>'

  for ( var i = 0; i < this.length; i++) {
    res += this[i].show(i);
  }
  res += '</table>'
  return res;
}

// tactionlist er en liste af actiongroup
function tactionlist(spanid) {
  var res = new deflist()
  res.curitem = -1;
  res.show = tactionlist_show;
  res.focus = tactionlist_focus;
  res.hide = tactionlist_hide;
  res.find = tactionlist_find;
  res.add  = tactionlist_add;
  res.spanid = spanid;
  res.confirmtext = new deflist();
  res.imageoffset = '';
  res.autoselect = true;
	res.ownerobject = null;
  return res; 
}

function tactionlist_add(item) {
  item.owner = this;
  this[this.length] = item;
}


function tactionlist_hide() {
  var aw = getElement(this.spanid);
  aw.style.display = 'none';
}

function tactionlist_focus(obj, actionlistname, id) {
  var cur = this.find(id);
  if (obj.originalclassName == undefined) obj.originalclassName = obj.className;
  obj.className = obj.originalclassName + '_focus';

  for (var i = 0; i < obj.children.length; i++) {
    if (obj.children[i].originalclassName == undefined) obj.children[i].originalclassName = obj.children[i].className;
    obj.children[i].className = obj.children[i].originalclassName + '_focus';
  }
  if (cur) {
    gotourl(cur.focusline.url, cur.focusline.target);
  }
}

function tactionlist_show(actionlistname, id, choosefirst, isrightclick,ownerjs) {
  // finder aktuel post og viser vinduet
  if (ownerjs) 
    elename = ownerjs.substring(0,ownerjs.length-1) + 'action' + actionlistname + '_' + id;
  else
    elename = 'action' + actionlistname + '_' + id;
  dblist_hideall(elename);  
  var aw = getElement(this.spanid);
  if (aw != null) {
    if (choosefirst == '1' && isrightclick != 1) {
      var cur = this.find(id);
      if (cur) {
        this.hide();
        document.onclick=null;
        gotourl(cur[0].url, cur[0].target);
      }
    } else {
      if (aw.style.display == 'block' && this.curitem == id) {
        document.onclick=null;
        this.hide();
      } else {
        var cur = this.find(id);
        if (cur) {
          if (cur.length == 1 && (this.autoselect == true || choosefirst == '1') && isrightclick !=1) 
            gotourl(cur[0].url, cur[0].target)
          else {
            var content = cur.show();
            // find x,y for knap-image
            if (content != '') {
              if (isrightclick == '1')
                var firefox = isFirefox();
                if (firefox==false){
                  var x = document.body.scrollLeft + window.event.clientX;
                }
              else
                var x = getRealLeft(elename);
  					  if (this.ownerobject == null)
                var y = getRealTop(elename)
  					  else {
  					  	var offset = getElement(this.ownerobject).scrollTop
  						  var y = getRealTop(elename) - offset;
  					  }
              this.curitem = id;
              aw.style.left = x;
              //for at sikre at indholdet kan blive vist
              var CurTableHeight=16;
              for (var i=0;i<cur.length;i++){
                if (cur[i].title){
                  CurTableHeight=CurTableHeight+22;
                }
                else
                {
                  CurTableHeight++;
                }
              }
              if (y+17>document.body.clientHeight-CurTableHeight)
              {
                y = y-(CurTableHeight+10);
              }
              aw.style.top = y+17;
              aw.style.display = 'block';
              aw.innerHTML = content;
              currentownerjs = ownerjs
              currentmenushown = actionlistname
              currentmenuid = id;
              if (window.event) window.event.cancelBubble = true;
              document.onclick=dblist_hideall;
            }
          }
        }  
      }
    }
  }
}

var currentmenushown = '';
var currentmenuid = '';
var currentownerjs = '';

function tactionlist_find(id) {
  for (var i = 0; i < this.length; i++) {
    if (id == this[i].id) return this[i]
  }
  return false;
}

function dblist_hideall(except) {
  var firefox = isFirefox();
  if (firefox==false){
  var ele = getElement("simaDBListActionWindow");
    if (ele) {
      for (var i = 0; i < ele.children.length; i++) {
        if (ele.children(i).id != except) {
          ele.children(i).style.display = 'none';
        }
      }
    }  
  }else{
    var ele = getElement("simaDBListActionWindow");
    var children = [];
    if (ele){
      var allChildren = ele.getElementsByTagName('*');
      for (var i = 0; i < allChildren.length; i++)
      {
        if (allChildren.item(i).parentNode == ele){
          if (ele.getElementsByTagName(allChildren.item(i).name).id != except){
            allChildren.item(i).style.display='none';
          }
        }              
      }
    }
  }
}



function dblist_mouseover(obj) {
  var firefox = isFirefox();
  if (firefox==false){
    for (var i = 0; i < obj.children.length; i++) {
      obj.children[i].style.backgroundColor = 'white';
    }
  }
}

function dblist_mouseout(obj) {
  var firefox = isFirefox();
  if (firefox==false){
    for (var i = 0; i < obj.children.length; i++) {
      obj.children[i].style.backgroundColor = document.body.style.backgroundColor;
    }
  }
}
 
