function $(id) { return document.getElementById(id); }

//identify browser through object detection
var browser = '';
if (Array.every)
  browser = 'Firefox';
else if (document.all)
  browser = 'IE';
else
  browser = 'other';
  
var isMSIE = /*@cc_on!@*/false;
var IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
var gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;

var no_fixed_positions = (isMSIE && !gteIE7);

function check_browser() {
  if (no_fixed_positions) {
      var bg = $('javabuttongroup'); if (bg) bg.style.position = 'absolute';
      var bg2 = $('javabuttongroup2'); if (bg2) bg2.style.position = 'absolute';      
  }
}

validate_emailform = function() {
    return true;
}

image_viewer_resize = function(i_ow, i_oh) {
    sxy = getScrollXY();
    var myWidth = 0, myHeight = 0;
    if( typeof(window.innerWidth) == 'number' ) {
        //Firefox
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE (funkar även i FF)
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    adminPanel = $('adminpanel');
    if (adminPanel && adminactive) {
      adminPanel.style.height = myHeight + 'px';
      if (adminPanel.style.position == 'absolute')
        adminPanel.style.top = sxy[1] + 'px';
    }
    imageWindow = $('image_viewer');
    if (imageWindow) {
        if (!i_ow) i_ow = imageWindow.offsetWidth;
        if (!i_oh) i_oh = imageWindow.offsetHeight;
        imageWindow.style.left = Math.round((myWidth - i_ow)/2) + 'px';
        if (imageWindow.style.position == 'absolute')
          imageWindow.style.top = Math.round((myHeight - i_oh)/3) + sxy[1] + 'px';
        else
          imageWindow.style.top = Math.round((myHeight - i_oh)/3) + 'px';
    }
    buttongroup = $('javabuttongroup');
    if (buttongroup && buttongroup.style.position == 'absolute') {
      buttongroup.style.top = (sxy[1]+10)+"px";
      buttongroup.style.left = (sxy[0]+10)+"px";
    }
    buttongroup2 = $('javabuttongroup2');
    if (buttongroup2 && buttongroup2.style.position == 'absolute') {
      buttongroup2.style.top = (sxy[1]+10)+"px";
      buttongroup2.style.right = 10-sxy[0]+"px";
    }
}

image_viewer = function(id,w,h,bt) {
    imageWindow = $('image_viewer');
    if (!imageWindow) {
        imageWindow = document.createElement('DIV');
        if (no_fixed_positions) {
          var pos = 'position:absolute;'
        } 
        else var pos = 'position:fixed;'
        imageWindow.style.cssText = pos + 'text-align:center;z-index:999999; background:white; border:1px solid #eee;display:none; border-right:2px solid #000; border-bottom:2px solid #000; ';
        imageWindow.id = 'image_viewer';
        document.body.appendChild(imageWindow);
        
        imageViel = document.createElement('DIV');
        imageViel.style.cssText = pos + 'top:0;left:0;width:100%;height:100%;z-index:999998; background:black; display:none; opacity:0.2; filter: alpha(opacity=20);';
        imageViel.id = 'image_viel';
        document.body.appendChild(imageViel);
        
    }
    imageWindow.style.display = 'block';
    $('image_viel').style.display = 'block';
    
    //imageWindow.style.width = (w*1.1) + 'px';
    //imageWindow.style.height = (h*1.1) + 'px';
    var content = "<img style=\"margin:" + (w*0.06) + "px; border:0px solid #666;\" onclick=\"$('image_viel').style.display='none'; $('image_viewer').style.display='none';\" width=\""+w+"\" height=\""+h+"\" src=\""+eg_url_path+"/eg_image.php?id="+id+"&w="+w+"&h="+h+"\"/><img title=\"St&auml;ng\" onclick=\"$('image_viewer').style.display='none'; $('image_viel').style.display='none';\" onmouseout=\"this.src='" + eg_url_path + "/admin/images/close.gif';\" onmouseover=\"this.src='"+eg_url_path+"/admin/images/close_r.gif';\" src=\"" + eg_url_path + "/admin/images/close.gif\" style=\"position:absolute;z-index:1000000;margin-top:3px;margin-left:-34px\"/>";
    content = content + "<p>"+bt+"</p>";
    imageWindow.innerHTML = content;
    window.onresize = image_viewer_resize;
    window.onscroll = image_viewer_resize;
    image_viewer_resize();
}

function getScrollXY() {
  //beroende på DOCTYPE ligger scrollTop antingen på HTML elementet eller BODY
  // funkar med IE7, IE6 och Firefox
  sx = document.body.scrollLeft + document.body.parentNode.scrollLeft;
  sy = document.body.scrollTop + document.body.parentNode.scrollTop;
  return [sx, sy];
}

var mouseover_submenu = false;
function over_sm() { mouseover_submenu = true; }
function out_sm() { mouseover_submenu = false; }

var menu_editing = false;

function menu_over(sub_id, caller) {

  if (menu_editing) return null;
  if (sub_id && (sub_id == timeout_sub_id)) timeout_caller = null;

  // hide any other menu waiting to be closed
  if (timeout_caller) hide_menu();

  if (browser == 'IE') {
    caller.firstChild.className = "menu_item_browsing"; 
  }
  else {
    caller.firstChild.setAttribute('class', 'menu_item_browsing');
  }
  if ($(sub_id)) $(sub_id).style.display = 'block';     
}

var timeout_sub_id;
var timeout_caller;

function hide_menu() {
  if (timeout_caller && !menu_editing) {
    if (browser == 'IE') 
      timeout_caller.firstChild.className = timeout_caller.firstChild.getAttribute('orig_class'); 
    else 
      timeout_caller.firstChild.setAttribute('class', timeout_caller.firstChild.getAttribute('orig_class'));
    if ($(timeout_sub_id)) {
      $(timeout_sub_id).style.display = 'none';
      timeout_sub_id = 0;
    }
    timeout_caller = false;    
  }
}

function menu_out(sub_id, caller) {
  //any other menu waiting to be hidden?
  if (timeout_caller) hide_menu();

  timeout_sub_id = sub_id;
  timeout_caller = caller;
  //if contextmenu is active, wait until it closes
  if ($('contextmenu')) if ($('contextmenu').style.display == 'block') return null;
  if (menu_editing) return null;        
  window.setTimeout('hide_menu()',150);
}

var texpanded = [];
function flipsrc(id) {
  var s2 = $(id+'_img').getAttribute('src');
  $(id+'_img').setAttribute('src', $(id+'_img').getAttribute('src2'));
  $(id+'_img').setAttribute('src2', s2);   
}
function expandtext(id) {
  if ($(id+'_short').style.display == 'none') {
      //hide
      $(id+'_short').style.display = 'block';
      $(id+'_full').style.display = 'none';
      texpanded = [];
      flipsrc(id);
  } else {
      //show
      while (texpanded.length) {
        t = texpanded.pop();
        $(t+'_short').style.display = 'block';
        $(t+'_full').style.display = 'none';
        flipsrc(t);
      }
      $(id+'_short').style.display = 'none';
      $(id+'_full').style.display = 'block';
      flipsrc(id);
      texpanded.push(id);
  }
  if (use_bsc) BodySizeChanged();
}

function inarray(a, search_phrase)
{
  for( var i = 0; i < a.length; i++ ) if( search_phrase == a[i] ) return true;
  return false;
}