function stripeTable(id) {
  var table = document.getElementById(id);
  if (! table) { return; }
  var tbodies = table.getElementsByTagName("tbody");
    
  for (var h = 0; h < tbodies.length; h++) {
    var even = true;
    var trs = tbodies[h].getElementsByTagName("tr");
   
    for (var i = 0; i < trs.length; i++) {
      trs[i].onmouseover=function(){
        this.className += " ruled"; return false
      }
      trs[i].onmouseout=function(){
        this.className = this.className.replace("ruled", ""); return false
      }
      
      if(even)
        trs[i].className += " even";
      
      even = !even;
    }
  }
}

function findSelectedValues(name)
	{
	var elements = document.getElementsByName(name);
    var ids = new Array;
    var pos = 0;
    for (var i=0; i < elements.length; i++)
        {
        if (elements[i].type == 'checkbox' && elements[i].checked)
			ids[pos++] = elements[i].value;
        }
    return ids;
    }
	
function openViewPic(ID, set)
{
  var set = (set == null) ? "" : set;
  //var opt = "width=940,height=670,resizable,top=0,left=0";
	//openInNewWindow("/viewpic.htm?ID=" + ID + "&set=" + set, "pop", opt);
	document.location = "/viewpic.htm?ID=" + ID + "&set=" + set;

}

function openFolderSlideshow(folderID)
{
  var opt = "width=900,height=900,resizable,top=0,left=0";
	openInNewWindow("/viewslideshow.htm?ID=" + folderID, "pop", opt);
}

function openSelectionSlideshow(qstr)
{
  var opt = "width=900,height=900,resizable,top=0,left=0";
	openInNewWindow("/selectionslideshow.htm" + qstr, "pop", opt);
}


function openPopUp(strURL,strType,strWidth,strHeight)
	{
	var strOptions="";
	if (strType=="console")
		strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed")
		strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic")
		strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;

	window.open(strURL + "?__style=popup", '_blank', strOptions);
	return false;
	}
  
function setThumbnailSize(thumbSize)
{
  var pics;
  var i = 0;
  var containerID;
  
  if (thumbSize=="small")
  {
    var iconSize = 12;
    var multiplier = 0.5;    
    var thumbClass = "thumbnail smallThumb";
  }
  else if (thumbSize=="medium")
  {
    var iconSize = 14;
    var multiplier = 0.7;
    var thumbClass = "thumbnail mediumThumb";
  }
  else
  {
    var iconSize = 16;
    var multiplier = 1;
    var thumbClass = "thumbnail";
  }
  
  var thumbs = $$('div.thumbnail');
  thumbs.each(function(item) {
    item.className = thumbClass;
        
    pics = $$('#'+item.id+' img');
    
    containerID = item.id;
    
    pics.each(function(item) {
      if (item.className=='thumbnailicon')
      {
        item.width = iconSize;
        item.height = iconSize;
      }
      else
      {
        item.width = Math.round(  $('w_'+containerID).value  * multiplier);
        item.height = Math.round( $('h_'+containerID).value  * multiplier);
        if (item.className=='theThumb')
          item.style.marginLeft = '-' + (Math.round(($('w_'+containerID).value  * multiplier) / 2)) + 'px';

      }
    });
  });
  
  var cb = function(s) {}
  asyncRpcCall("picturo.setSessionData", 'thumbnailSize', thumbSize, cb);
  
}

function mouseLeaves(element, evt) 
{
  if (typeof evt.toElement != 'undefined' && typeof element.contains != 'undefined')
    return !element.contains(evt.toElement);
  else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) 
    return !contains(element, evt.relatedTarget);
}

function contains(container, containee) 
{
  while (containee) 
  {
    if (container == containee) 
    {
      return true;
    }
    containee = containee.parentNode;
  }
  return false;
}

function openLightboxActions(caller)
{
  //console.log("test");
  openPopMenu(caller, "lbact");
}

function openPopMenu(caller, name)
{
  if (caller) 
	{
    pos = findPosition(caller);
    hideElement(name);
    moveElement(name, pos[0]-1, pos[1]-3);
    }
  $(name).show(); //showElement(name);       
}

function emptySearchField()
{
  if ($('barsearchfield').value=="Ange sökord" || $('barsearchfield').value=="Search")
    $('barsearchfield').value="";
}

function showAlertBox(str, time)
{
  $('alertbox').innerHTML = str;
  $('alertbox').style.display = 'block';

  if (!time)
    time = 2000;  
  var t=setTimeout("$('alertbox').style.display='none'", time)
}

function toggleHeaderDisplay()
{
  if ($('headertoggler').hasClassName('closedheadertoggler'))
  {
    Effect.Appear('logopanel', { duration: 0.5 });
    Effect.SlideDown('menupanel', { duration: 0.5 });
    $('footers').show();
    $('headertoggler').removeClassName('closedheadertoggler');
    asyncRpcCall("picturo.setSessionData", "hideHeaders", 0);
  }
  else
  {
    Effect.Fade('logopanel', { duration: 0.5 });
    Effect.SlideUp('menupanel', { duration: 0.5 });
    $('footers').hide();
    $('headertoggler').addClassName('closedheadertoggler');
    asyncRpcCall("picturo.setSessionData", "hideHeaders", 1);    
  }
}

/*
CSS Browser Selector v0.3.4 (Sep 29, 2009)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
