/*
  depends on: mootools with Ajax - option included
*/

function msg(msg,id,type){
  //new div element, displaying failure case
  var msgDiv = new Element('div');
  msgDiv.id = 'errordiv_'+id;
  msgDiv.injectInside($E('body'));
  msgDiv.setStyle('position','absolute');
  msgDiv.setStyle('top','10px');
  msgDiv.setStyle('left','10px');
  if(type === 'error'){
   msgDiv.setStyle('background-color','#FF0000');
  } else if(type === 'msg') {
   msgDiv.setStyle('background-color','#0000FF');
  }
  msgDiv.setStyle('color','#fff');
  msgDiv.setStyle('fontWeight','bold');
  var errorStartDuration = 500;
  var errorEndDuration   = 500;
  var myEffects = new Fx.Styles(msgDiv, {
   duration:errorStartDuration,
   transition: Fx.Transitions.linear,
   onComplete: function(){
   }
  }); 
  myEffects.start({
    'height': [0, 40],
    'width': [0, 100]
  }).chain(function(){
         msgDiv.appendText(msg);
         (function(){msgDiv.setText('')}).delay(3000);
         this.start.delay(3000, this, {
		         'width': [100, 0],
		         'height': [40, 0]         
	       });
         (function(){msgDiv.remove()}).delay(3500);
  });
}

function doAjax(url,target){
  var ajax = new Ajax(url, {method: 'get', update: target}).request();
}

function getContentFadeIn(url,id){
   var ajax = new Ajax(url, {
      method:  'get', 
      update:  $(id),
      evalScripts: true,
      onRequest: function() { 
         actImg.setStyle('display','block'); 
         $(id).effect('opacity').start(0);
      },
      onComplete: function(){ 
         $(id).effect('opacity').start(1);
         actImg.setStyle('display','none');  
      }, 
      onFailure: function(){ msg('Toiming ebaġnnestus!',id,'error') }
  });
  ajax.request();
}

