/* 
 * Utilitaires pour c4mins
 */
 
 
/**
 *  tagFolding 
 */
function tagFolding (oTag,oLink,sCaption)
{
  if(oTag.style.display != 'none') {
	  oTag.style.display = 'none';
	  if(oLink) {
	  	oLink.innerHTML = oLink.caption_back;
	  } 
  } else {
  	oTag.style.display = '';
  	if(oLink) {
  		oLink.caption_back = oLink.innerHTML;
      oLink.innerHTML = sCaption;
  	}  	
  }
  
}

/**
 * Boite de dialogue 
 */
var C4mUtilsDialog = Class.create({
  
  // Id de la boite de dialogue : 
  dialogID: null,
  
  // Url de l'utilitaire :
  dialogURL: null,

  
  initialize:function ()
  {
  },
  
  open: function(parameters)
  {
    if(!parameters) parameters = {};
 
    // Afficher chargement
    $('coverall').show();
    $('loading').show();
    
    // Chargement de l'utilitaire : 
    this.loadDialog(parameters);
  },
  
  getDialogBox: function ()
  {
   var popup = $(this.dialogID);
   if(!popup) var popup = dialogBox(this.dialogID, this.dialogID + 'Update', this.leave.bind(this) );
   return popup;
  },
  
  loadDialog: function (parameters)
  {
    // Boite de dialogue :
    var popup = this.getDialogBox();
    
    new Ajax.Updater(
    this.dialogID + 'Update',
    this.dialogURL, 
    {
      asynchronous: true, 
      evalScripts:  true, 
      onComplete:   function(request, json)
      {
        $('loading').hide(); 
        $(this.dialogID).show(); 
        $(this.dialogID).move('center','center');
        this.onOpen();
      }.bind(this), 
      parameters:parameters
    }); 
  },
  
  getDialogElement: function ()
  {
    return $(this.dialogID);
  },
  
  getUpdateElement: function ()
  {
    return $(this.dialogID + 'Update');
  },
  
  leave: function()
  {
    $('coverall').hide();
    $(this.dialogID).hide(); 
    $('loading').hide(); 
  },
  
  /**
   * Appellé lorsque la boite de dialogue est ouverte
   */
  onOpen: function () {}
});