function buildQuery(obj) {
  var se = $('activities')
  var op = se.getElementsByTagName('option');
  var string = '(';
  var o = 0;
  for( i=0; i < op.length; i++ ) {
    if( op[i].selected != true ) continue;
    if( o != 0 ) string += ' OR ';
    string += 'attrib' + op[i].value + ':true';
    o++;
  }
  string += ')';
  var q = ( $('q').value == '' ? ( string == '()' ? '' : string ) : $('q').value + ( string == '()' ? '' : ' AND ' + string ) );
  $('query').value = q;
  
  document.employeeSearch.submit()
}

function setFavorite(type,id,link,div) {
  var url = './' +
  '?template=favorites' + 
  '&ajax=shortcuts' + 
  '&module=Favourites' + 
  '&action=Favourite.publicSetFavourite' + 
  '&object_id=' + id + 
  '&object_type=' + type + 
  '&url=' + link + 
  '&nocache=true';

  new Ajax.Updater(div, url, {asynchronous:true});
  setTimeout('updateIcon("'+ type + '", '+ id +')', 150);
  if(($('nofavs')) && ($('nofavs').className='nofavs')){
    $('nofavs').parentNode.removeChild($('nofavs'));
  }
}

function updateIcon(type,id) {
  var url = './' + 
  '?template=favorites' + 
  '&ajax=icon' + 
  '&object_id=' + id + 
  '&object_type=' + type + 
  '&nocache=true';

  new Ajax.Updater('favorit_' + id, url, {asynchronous:true});
}

function replaceSlash(temp) {
  return temp.replace(/\//g,'*');
}

function showResponse(req) {
  alert (req.responseText);
}


if (!fade) var fade = {};
opacityTimeout = false;

fade = {
	fps: 40,
	duration: 400,
  fade: function(id, to, fps, duration) {
    if( !id ) return
    if( !fps ) fps = this.fps;
    if( !duration ) duration = this.duration;
    if( to=='undefined' ) to = 0;

    var origOpacity = ( !$(id).style.opacity || $(id).style.visiblity=='hidden' || $(id).style.display=='none' ? 0 : $(id).style.opacity );
    var diff = origOpacity - to;
    
    if( origOpacity==0 && to > 0 ) { 
      $(id).style.display='';
      $(id).style.filter = 'alpha(opacity=0)';
      $(id).style.opacity = 0;
      $(id).style.visibility='';
    }

    var frames = Math.round(fps * (duration / 1000));
    var interval = duration / frames;
    var delay = interval;
    var frame = 0;

    while (frame <= frames) {
      var opacity = origOpacity - ((diff / frames) * frame);
      
      opacityTimeout = setTimeout("fade.setOpacity('"+id+"','"+opacity+"')", delay);
      if( frame == frames && to==0 ) setTimeout("$('"+id+"').style.display='none'", delay);

      frame++;
      var delay = interval * frame;
    }
  },
  setOpacity: function(id, to) {
    var element = $(id);
    if( to > 0 && ( element.style.display=='none' || element.style.visibility=='hidden' ) ) { element.style.display = ''; element.style.visibility='';} 
    element.style.filter = (to == 1) ? '' : 'alpha(opacity=' + to * 100 + ')';
    element.style.opacity = to;
    if( to < 0 ) element.style.display='none';
  }
}

function ins() {
  Event.observe($('galleryPaginator'), 'mouseover', function(e) {
    var x = Event.pointerX(e);
    var u = $('galleryPaginator');
    if( (u.offsetLeft + u.offsetWidth / 2) <= x) { // Next
      fade.setOpacity('doNext', .8);
      fade.setOpacity('doPrev', 0);
    } else { // Previous
      fade.setOpacity('doPrev', .8);
      fade.setOpacity('doNext', 0);
    }
  });
  Event.observe($('galleryPaginator'), 'mouseout', function(e) {
    fade.setOpacity('doPrev', 0);
    fade.setOpacity('doNext', 0);
  });
  Event.observe($('doPrev'), 'mousedown', function(e) {
    doPrev();
  });
  Event.observe($('doNext'), 'mousedown', function(e) {
    doNew(this);
  });
  
  Event.observe($('doPrev'), 'mouseup', function(e) {
    clearTimeout(galleryTimeout);
  });
  Event.observe($('doNext'), 'mouseup', function(e) {
    clearTimeout(galleryTimeout);
  });
}

galleryTimeout = false;

function doPrev() {
  var e = $('galleryPaginator');
  var i = e.style.textIndent;
  var p = parseInt(( i == '' ? 0 : i.replace(/[a-z]*/ig, '') ));
  if( p == 0 ) return;
  e.style.textIndent = (p + 10) + 'px';
  galleryTimeout = setTimeout('doPrev()', 25);
}

function doNew() {
  var e = $('galleryPaginator');
  var i = e.style.textIndent;
  var p = parseInt(( i == '' ? 0 : i.replace(/[a-z]*/ig, '') ));
  var l = parseInt($('lastImage').offsetLeft + $('lastImage').offsetWidth);
  var w = parseInt(e.offsetWidth)
  if( w > l ) return;
  e.style.textIndent = (p - 10) + 'px';
  galleryTimeout = setTimeout('doNew()', 25);
}
