
var onloads = new Array();

var color_over_init = '#dedede';

function bodyOnLoad(opt) {
	for ( var i = 0 ; i < onloads.length ; i++ ) {
		onloads[i]();
	}
	window.setInterval("perpetuel()",60000);
}



/**
 * Permet de maintenir la connexion active
 */
 
function perpetuel() {
	var opt = {
				method: 'post',
			    parameters: '',
			    onSuccess: function(t) {
			    }
			}

	new Ajax.Request('/inc/ajax/perpetuel.ajax.php', opt)
	return true;
}

function lien_over(e) {
	color_over_init  = $(e).style.backgroundColor;
	$(e).style.backgroundColor="white";
  	$(e).style.cursor="pointer";
  	
  	if ($($(e).id + '_2')) {
	  	$($(e).id + '_2').style.backgroundColor="white";
	  	$($(e).id + '_2').style.cursor="pointer";
  	}
  	
}


function lien_out(e) {
	// On remet la couleur originale en place
	$(e).style.backgroundColor = color_over_init;
	
	if ($($(e).id + '_2')) {
	  	$($(e).id + '_2').style.backgroundColor = color_over_init;
  	}
  	
}


Ajax.Responders.register({ 

	onCreate: function() { 
		if($('notification') && Ajax.activeRequestCount> 0) 
			Effect.Appear('notification',{duration: 0.25, queue: 'end'}); 
	}, 
	 
	onComplete: function() { 
		if($('notification') && Ajax.activeRequestCount == 0) 
	 	Effect.Fade('notification',{duration: 0.25, queue: 'end'}); 
	} 
	 
}); 



function MessageFlash (txt) {
	
	txt += '<p><a href="#" onclick="$(\'MessageFlash\').hide();return false;">Fermer</a></p>';
	$('MessageFlashContent').innerHTML =  txt;		
	$('MessageFlash').show();
}



function getVersion () {
	var opt = {
			    // Use POST
			    method: 'post',
			    postBody: '',
			    onSuccess: function(t) {
			    	$('DIASYS-Version').innerHTML = "Révision : " + t.responseText;
			    },
			    on404: function(t) {
			        alert('Error 404: location "' + t.statusText + '" was not found.');
			    },
			    onFailure: function(t) {
			        alert('Error ' + t.status + ' -- ' + t.statusText);
			    }
			}

	new Ajax.Request('/inc/ajax/getversion.ajax.php', opt)
	return true;
}
  
  

/**
 * Observer  permettant de tester si un champ de formulaire à été modifié
 * sur un formulaire.
 */
function verifChangeOnForm()
{
  if(document.getElementsByTagName)  {
  
    var tags = new Array('input', 'select', 'textarea');
    for(var i = 0; i<tags.length; i++) {
		var obj = document.getElementsByTagName(tags[i]);
      	for(var j=0; j<obj.length; j++) {
        	if((obj[j].type=='submit')||(obj[j].type=='button')||(obj[j].type=='image') ) {
          		continue;
        	}
        
        	Event.observe(obj[j], 'change',
	          	function(evt) {
	          		var target = evt['target']?evt['target']:evt['srcElement'];
	          		$('verifChangeForm').innerHTML += target.id + '|';
	          	}
	        );
        
      	}
   	}
  }
} 


function appliqueChangeOnForm(evt) {
	
	var target =   Event.element(evt );
	
	if ($('verifChangeForm').innerHTML != '') {
		if (target.tagName == 'A') {
			if ( !Element.hasClassName(target,'lienValid') && !Element.hasClassName(target,'lienValid4js') ) {
					if ( !confirm ("Des modifications ont été apportées et seront perdues si vous continuez.\nVoulez vous continuer et perdre vos modifications ?")) {
						Event.stop (evt);
					}
			}
		}
	}
}




function showInfos(mode) {
	
	var opt = {
			    // Use POST
			    method: 'post',
			    parameters: 'mode=' + mode,
			    onSuccess: function(t) {
			    
					$('showInfos').show();
					$('showInfos').innerHTML = t.responseText;
			    }
			}

	new Ajax.Request('/inc/ajax/showinfos.ajax.php', opt)
	return true;
	
	
}

function VTopenfile(opt) {
	location.href=  '/openfile.php?file=' + opt.file + '&format=' + opt.format + '&name=' + opt.name;
}