function toTop() 
{
  if(document.getElementById("totop") != null)
  {
    if (document.body.clientHeight) 
    {
      if(document.body.scrollHeight > document.body.clientHeight) 
      {
        //alert(document.body.clientHeight)
        //toTopHeight = document.body.scrollHeight - 100;		
        toTopLeft = document.body.clientWidth - 85;
        toTopHeight = document.body.clientHeight - 40;		
        document.getElementById("totop").style.left = toTopLeft;		
        document.getElementById("totop").style.top = toTopHeight;		
        document.getElementById("totop").style.visibility = "visible";		
      }
      else 
      {
        document.getElementById("totop").style.visibility = "hidden";		
      }
    }
  }
}

function topScroll() {
  if (document.body.scrollTop) 
  {
    topPosition = document.getElementById("totop").style.top;
    newPosition = document.body.scrollTop + document.body.clientHeight - 40;
    document.getElementById("totop").style.top = newPosition;		
  }
}

//
// not nice, but we need to trap when the enter button is pressed after entering a
// search string in the seach box for a given group
//
function SubmitSearch(buttonID)
{
  if(event.keyCode==13)
  { 
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  	document.getElementById(buttonID).click();
    return false
  }
  return true;    
}

function Search(groups)
{
    var word = encodeURI(document.forms[0].ankiro_input.value);
    document.location.href = "/toplinks/Search.aspx?subq=" + word + "&subsr=1&mainq=" + word + "&mainsr=1";

  /*
  var word = document.forms[0].ankiro_input.value;
  var href = location.href;
  
  // strip off previous single search
  if(href.indexOf('lg=sitesearch')>0)
  {
    href = href.substr(0,href.indexOf('lg=searchsingle')-1);
  }
  
  // stip off previos seach string if found
  if(href.indexOf('q=')>0)
  {
    href = href.substr(0,href.indexOf('q=')-1);
  }
  
  // append the info to make the group search...
  
  if(href.indexOf('?') != -1)
    document.location = href + '&q='+word + '&results=5&lg=groupsearch&searchgroups=' +groups;
  else
    document.location = href + '?q='+word + '&results=5&lg=groupsearch&searchgroups=' +groups;
  */
}

var oldID = "";
var groupID = "";

function answer(ID,group) {
  if(oldID!="" && groupID==group) {
    document.getElementById(oldID).style.visibility = "hidden";
  }
  document.getElementById(ID).style.visibility = "visible";
  oldID = ID;
  groupID = group;
}

function answerHide(ID) {
  document.getElementById(ID).style.visibility = "hidden";
}

function DetectActivate(e)
{
 if (e)  //firefox etc.
  {
    if(e.keyCode==0 || e.keyCode == 13)  //tab
      return true;
  }
  else if (window.event)  //IE etc.
  {
    if(window.event.keyCode == 32 || window.event.keyCode==13)   //tab
      return true;
  }
  return false
}


function answerLink(path,e) 
{
  if (DetectActivate(e)){
    var win = window.open(path,"","width=640,height=480,resizable=0,status=0,toolbar=1,scrollbars=1");
    if (win == null)
      alert("Ikke tilgængelig før du har tilladt brug af pop-up vinduer på denne side.");
    return false;
  }
//  return true;
}

function goback() {
  window.opener.alert("Tilbage til testen");
  window.focus();
}

/*********************************
        shareLink
*********************************/
function shareLink(linkID)
{
  var url="/arbejdsmiljoweb.dk/global/share_link.aspx" + "?link=" + linkID;
  var win = window.open(url,"","modal=yes,resizeable=yes,width=725,height=505,scrollbars=no")

  if (win == null)
  {
    alert("For at tippe en ven skal du tillade brug af pop-up vinduer på denne side.");
  }
  
}


/*********************************
        New search field
*********************************/

function updateSIFieldStyling(sfld) {
    sfld.style.color = '#000000';
    sfld.style.fontStyle = 'normal';
    sfld.value = '';
}

function resetSIFieldStyling(sfld) {
    if (sfld.value == '') {
        sfld.style.color = '#999999';
        sfld.style.fontStyle = 'italic';
        sfld.value = "S\u00F8g...";
    }
}


/*********************************
        Open javascript window
*********************************/

function OpenWindow(url, name, w, h) {
    w += 32;
    h += 96;
    var win = window.open(url, name, 'width=' + w + ', height=' + h + ', location=no, menubar=yes, status=yes, toolbar=no, scrollbars=no, resizable=no');
    win.resizeTo(w, h);
    win.focus();
}