
/**
*** ************************** ***
***           COMMON           ***
*** ************************** ***
**/

/* Return the ID of an element */
var ID = function( id ) {
	return $( id );
	// return document.getElementById( id );
}

/**
*** ************************** ***
***         SITE TOOLS         ***
*** ************************** ***
**/

/* Display application specified message */
var displayAlert = function( msg ) {
	if( msg != "" ) {
		alert( msg.unescapeHTML() );
	}
}

/* Display application errors messages */
var displayMessage = function() {
	if( last_error != "" ) {
		displayAlert( last_error );
	}
}

/* Manages effects on top band menu */
var initTopBand = function( id, men_obj ) {
	if( ! isId( id ) ) return "";
	men_init( id, men_obj );
}

/* Manages effects on left band menu */
var initLeftBand = function ( id, root ) {
	if( ! isId( id ) ) return "";
	var root = 'left_menu_ul';
	var a = $$('#'+root+' a');
	var ul = $$('#'+root+' ul.level_2');
	var css_off = 'off';
	var css_on = 'on';	
	ul.each( function(e,index) {
		if(e.style.display!='block'){
			e.style.display='none';
		}
	});
	a.each( function(e) {
		if(!e.id.empty()){
			Event.observe(e,'click',function(){
				var ul_affiche = $(e.id).nextSibling.nextSibling;
				if(ul_affiche.style.display=='none'){
					$(e.id).blur();
					$(e.id).className = css_on;
					new Effect.BlindDown(ul_affiche,{duration:0.5});
				}else{
					$(e.id).blur();
					$(e.id).className = css_off;
					new Effect.BlindUp(ul_affiche,{duration:0.5});
				}
			});
		}
	});
}

function afficherMasquer()
/* change la classe CSS des objets donnés en parametres. Syntaxe :
afficherMasquer('id_div1','afficher','id_div2','masquer','id_div3','masquer',...) */
{
 var args=afficherMasquer.arguments;
 var action, objet, css;

 // on parcours tous les arguments de la fonction
 for(var i=0; i<(args.length-1); i+=2)
 {
 if((objet=document.getElementById(args[i]))!=null)
 {
 action=args[i+1];
 switch(action)
 {
 /* la valeur de "css" est a remplacer avec les noms des classes
 utilisées dans la feuille de style */
 case 'afficher':
 case '1':
 css='visible';
 break;

 case 'cache':
 case '0':
 default:
 css='cache';
 }

 objet.className=css;
 }
 }
}





function Affichecalque(Nomcalque)
{

 window.document.getElementById(Nomcalque).style.display="block";


}

function Masquecalque(Nomcalque)
{

 window.document.getElementById(Nomcalque).style.display="none";

}


/* Affiche ou masque le bandeau haut */
var showHideTopBand = function( top_band )
{
	Effect.toggle( top_band, "Appear", { duration: 0.5 } );
}

/* Manages send page to a friend action */
var sendToFriend = function( rid ) {
	displayAlert( "Sending a link to rubrik "+rid+" to your firend !" );
}

/* Display the About site message */
var displayAbout = function() {
	displayAlert( cl_message_11 );
}

/* Launch printing of current page */
var printPage = function() {
	window.print();
}


/**
*** ************************** ***
***         MORE TOOLS         ***
*** ************************** ***
**/

/* Invoke an url using ajax get mode without callback */
var invokeAjaxUrl = function( url ) {
	new Ajax.Request(url, {
		method: 'get',
		asynchronous: false
	});
}

/* Display a popup window and fill it's body with url contents */
var popup = function( title, url, width, height ) 
{
	option = "width="+width+",height="+height+",toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,alwaysRaised=1,dependent=1";
	w = window.open(url, title, option);
	w.style.left = window.style.left+100;
	w.style.top = window.style.top+100;
	w.focus();
}

/* Display a scrollable resizable popup window */
var zoomImage = function( title, url, width, height ) {
	// To do : replace popup by lightbox
	var option = "width="+width+",height="+height+",toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,alwaysRaised=1,dependent=1";
	w = window.open(url, title, option);
	w.focus();
}

/* Encode une url */
var urlEncode = function( str ) {
    var str = escape(str);
    str = str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

/* Check or uncheck all checkbox element of a form */
var checkUncheckAll= function( itm, ignore ) {
	var theForm = itm.form, z = 0;
	for(z=0; z<theForm.length;z++) {
		if(theForm[z].type == 'checkbox' && theForm[z].name != ignore) {
			theForm[z].checked = itm.checked;
		}
	}
}

/* Select all items of a list box */
var selectAllComboItems = function( sel_src, value ) {
	var src_id = ID(sel_src);
	if( ! src_id ) return;
	var src_opt = src_id.options;
	for( i=0; i<src_opt.length; i++ ) {
		src_opt[i].selected = ( value ? true : false );
	}
}

