//------------------------------------------------------------------------------
// FICHIER : $RCSfile: ajaxGSiteFunc.js,v $
// AUTEUR  : $Author: guillaume $
// VERSION : $Revision: 1.64 $
// DATE    : $Date: 2010-04-13 15:51:12 $
//------------------------------------------------------------------------------
// GSite - Web site management in PHP - main ajax js file
//
// Copyright (C) 2007 PEREZ Guillaume (perez@id-alizes.fr)
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------
/*
//-- CK_editor
document.write('<script type="text/javascript" src="resources/ckeditor/ckeditor.js"></script>');

//-- ModalBox
document.write('<script type="text/javascript" src="resources/modalbox/modalbox.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="resources/modalbox/modalbox.css">');

//-- Tips
document.write('<script type="text/javascript" src="resources/scriptaculous/prototip.js"></script>');

//-- File upload
document.write('<script type="text/javascript" src="resources/upload/micoxUpload.js"></script>');

//-- Date picker
document.write('<script type="text/javascript" src="resources/date_picker_ajax/datepicker.js"></script>');

document.write('<link rel="stylesheet" type="text/css" href="resources/date_picker_ajax/datepicker.css">');


//-- Multi Date picker
document.write('<script type="text/javascript" src="resources/multi_date_picker_ajax/calendar.js"></script>');
document.write('<script type="text/javascript" src="resources/multi_date_picker_ajax/calendar-setup.js"></script>');
document.write('<script type="text/javascript" src="resources/multi_date_picker_ajax/lang/calendar-fr.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="resources/multi_date_picker_ajax/theme.css">');

//-- Color picker
document.write('<link rel="stylesheet" type="text/css" href="resources/color_pickup_ajax/colorPicker.css">');
document.write('<script src="resources/color_pickup_ajax/yahoo.color.js" type="text/javascript"></script>');
document.write('<script src="resources/color_pickup_ajax/colorPicker.js" type="text/javascript"></script>');
*/


//------------------------------------------------------------------------------
function removeReturns(stringToTrim) {
	//stringToTrim = stringToTrim.replace(/\r/g,'');
	return stringToTrim.replace(/\n|\r/g,'');
}

//------------------------------------------------------------------------------
function myCallback( rss ) {
    alert(rss.channel.title);
    for(var n=0; n<rss.items.length; n++) {
        alert(rss.items[n].title);
    }
}

function errorHandler( rss ) {
   alert('An error has occured');
}


function rssRead(rss,id,showMax){

	rss = encodeURIComponent(rss);

	var url = 'rssreader.php';
	Element.setOpacity( id, 0.3 );
	$(id).innerHTML = '<img src="Local/ajax/load.gif" alt="" />';

	ajaxClass = new Ajax.Updater(id, url, { 
		success: id,
		method:'post' ,
		postBody: 'rss='+rss+'&nb='+showMax+'&id='+id ,
		evalScripts: false,

		onComplete: function(response) {

		Try.these( function() {
	      if ($(id+'_load') != null)
			Element.hide( id+'_load');
		});
		Try.these( function() {
			Element.setOpacity( id, 1.0 );
		});
	}

	});

	}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function gs_element_hide (id) {
  Try.these( function() {
    if ($(id) != null && $(id).visible() === true )
      Element.hide(id);
  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function gs_element_show (id) {
  Try.these( function() {
    if ($(id) != null && $(id).visible() === false )
      Element.show(id);

  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function gs_element_toggle (id) {
  Try.these( function() {
    if ($(id) != null)
      Effect.toggle(id);
  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
  
function appli_search_upd_select (id) {

  //-- get option selected on select
  var selected_val = $(id).getValue();
  
  //-- get the input field for the selected option
  var import_from = $('input_field_'+selected_val).innerHTML;
  
  //-- update the input edition
  $(id).next().firstDescendant().update(import_from);
  
    return false;
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function appli_search_upd_form (id) {

  //-- get the id of the div wich is into the form
  var import_in_form = $(id).ancestors();
  import_in_form = import_in_form[0].next().firstDescendant().next();
  
  appli_search_upd_form_base (id, import_in_form);
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function appli_search_upd_form2 (id) {
  Try.these( function() {

  //-- get the id of the div wich is into the form
  var import_in_form = $(id).ancestors();
  import_in_form = import_in_form[1].next().firstDescendant().next();
  
  appli_search_upd_form_base (id, import_in_form);
  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function appli_search_upd_form_base (id, import_in_form) {

  //-- get the field name to add
  var selected_name = $('search').value;
  
  //-- get the field name to add
  var selected_text = $('search').options[$('search').selectedIndex].text;
  
  //-- get the field value
  var selected_val = $(id).firstDescendant().firstDescendant().getValue();

  //-- create hidden field for the form
  var input_hidden = '<input type="hidden" name="posted_field_'+selected_name+'" id="posted_field_'+selected_name+'" value="'+selected_val+'" />';
  
  //-- We verif if exist an other search on the current field

  if ($('head_search_'+selected_name) != null) {
    //-- If field already exist, we add the new value

    $('head_search_value_'+selected_name).innerHTML += ';'+selected_val;

    $('posted_field_'+selected_name).value = $('posted_field_'+selected_name).value +'|'+ selected_val;

  } else {
    //-- If field don't exist, we create a new field and a new hidden field
    var text_to_add = 
      
      $('search_previous_zone').innerHTML+
      '<div id="head_search_'+selected_name+'">'+
      '<span style="float:left;width: 200px;">'+selected_text+' :</span>'+
      '<span id="head_search_value_'+selected_name+'">'+selected_val+'</span>'+
      '&nbsp;&nbsp;&nbsp;(<a href="#" onClick="javascript:remove_search_element (this,\''+selected_name+'\');return false;">Supprimer ce critre</a>)'+
      '</div>';
  
      Element.show('search_previous_zone');
      $('search_previous_zone').update(text_to_add);

      import_in_form.update(import_in_form.innerHTML+input_hidden);

  }



    return false;

}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
  
function remove_search_element (id,field_name) {

  // remove the field
  var fathers = $(id).ancestors();

  fathers[0].remove();
  
  var name = 'search_previous_'+field_name;

	var tInp = Form.getElements('my_form_search','');

	for (var i=0;i<tInp.length;i++) {
  
    if ((tInp[i].name == 'search_previous_'+field_name) || !field_name)
      $(tInp[i]).remove();
      
	}

  var myform  = $('my_form_search');
  myform.submit();

  
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
  
function createCompletion (my_id, datas, nbchoices) {
  
  new Autocompleter.Local(
    $(my_id),
    $(my_id).next(),
    datas,
    'Yes',
    {
      partialChars:2,
      choices: nbchoices
    }
  );
  //new Autocompleter.Local($(my_id), $(my_id).next(), datas, 'Yes' );

  Element.setOpacity($(my_id).next(),1);
  
 // $(my_id).next().makePositioned();
 // $(my_id).next().show();
}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSiteDebug (txt) {


}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
  
var preloaded = new Array();
function preload_images() {

    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
    
};

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSiteSimple (url,id) {
	

  Try.these( function() {
    if ($(id+'_load') != null)
      Element.show( id+'_load');
  });

  //Element.setOpacity( 'loading', 0.5 );

  ajaxClass = new Ajax.Updater(id, url, { 
  	
    success: id,
    method:'post' ,
    evalScripts: false,
    onComplete: function(response) {
      //-- Eval response scripts
      response.responseText.evalScripts();
    }
  });	
}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function refreshBoxApp (id, url) {
  Try.these( function() {
    //ajaxClass = new Ajax.Updater('alias_'+id, url);
    id = 'alias_'+id;
    
    ajaxClass = new Ajax.Updater(id, url, { 
      success: id,
      method:'post' ,
      evalScripts: false,
      onComplete: function(response) {
        //-- Eval response scripts
        response.responseText.evalScripts();
      }
    });	
  
  });
}

function refreshBoxAppForm (id, url) {
  Try.these( function() {
    ajaxClass = new Ajax.Updater(id, url);
  });
}


function deleteBoxApp (id) {
  Try.these( function() {
    $(id).remove();
  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSite (url,fct,id, show, hide) {
	
  
  Try.these( function() {
	if ($('boxContainer') != null)
      Element.hide('boxContainer');
	
	if ($('boxContainerBack') != null)
      Element.hide('boxContainerBack');
  });

  ourDate = new Date( );

  if (typeof show == 'undefined' ) show = '';
  if (typeof hide == 'undefined' ) hide = '';

  if (show == 'box') id = 'boxContainerContents';
  if ((id   == '') && (fct != '@all'))    id = 'boxContainerContents';
  if ((id   == '') && (fct == '@all'))    id = 'main';

  if (hide != ''){
	if ($(hide) != null)
      Element.hide(hide);
  }
  
  var typeModal = null;
  if (id == 'message_box') {
    typeModal = 'message_box';
    $('modalbox').innerHTML = '<div></div>';
    jQuery('#modalbox').dialog({ 
              width: 600,
              modal: true
        });
    jQuery( "#progressbar" ).progressbar({
			value: 59
		});
  } else if (id == 'message_box_large') {
    typeModal = 'message_box_large';
    $('modalbox').innerHTML = '<div></div>';
    jQuery('#modalbox').dialog({ 
              width: 800,
              modal: true
        });
    jQuery( "#progressbar" ).progressbar({
			value: 59
		});
    //id = 'test';
  }

  if (id != '')  {

    Try.these( function() {
      if ($(id+'_load') != null)
        Element.show( id+'_load');
    });

    //Element.setOpacity( 'loading', 0.5 );

    ajaxClass = new Ajax.Updater(id, url, { 
      success: id,
      method:'post' ,
      postBody: 'targetBoxName='+id+'&execAction='+fct ,
      evalScripts: false,
      onSuccess: function(response) {
      },  
      onCreate: function() {

          Try.these( function() {
            Element.setOpacity( id, 0.5 );
            
            var dim = $(id).getDimensions();
            
            var middleHeight = Math.round((dim.height/2)-15);
            var middleWidth = Math.round((dim.width/2)-15);
            
            if (middleHeight<0) middleHeight = 0;
            if (middleWidth<0) middleWidth = 0;

            $(id).insert(
              '<div style="position:absolute;top:0px;left:0px;">'+
              '<div style="'+
              'position:relative;width:'+dim.width+'px;'+
              'height:'+dim.height+'px;text-align:center;">'+
              '  <div style="position:absolute;top:'+middleHeight+'px;left:'+middleWidth+'px;">'+
              '    <img src="Local/ajax/loading2.gif" alt="loading"/>'+
              '  </div>'+
              '</div>'+
              '</div>'
            );

          });
      },
      onComplete: function(response) {
    	
    	//-- If msgbox
    	if (typeModal == 'message_box') {
        
        jQuery('#modalbox').dialog("destroy");
        jQuery('#modalbox').dialog({ 
              width: 600,
              modal: true,
              position: ['center',30]
        });
        $('modalbox').innerHTML = response.responseText;
        
    	} else if (typeModal == 'message_box_large') {
        
        jQuery('#modalbox').dialog("destroy");
        jQuery('#modalbox').dialog({ 
              width: 800,
              modal: true,
              position: ['center',30]
        });
        $('modalbox').innerHTML = response.responseText;
      }
    	
        Try.these( function() {
          if ($(id+'_load') != null)
            Element.hide( id+'_load');
        });
        
        Try.these( function() {
          Element.setOpacity( id, 1.0 );
        });

        if (show != '')
          new Effect.Appear(show);

        //-- Eval response scripts
        response.responseText.evalScripts();
        
        jQuery("button").button();
        jQuery("input:submit").button();
        jQuery(".button_round").button();
        
        
        
        //-- Init button set
        jQuery(".group_buttons").buttonset();
        
        //-- Init button disabled
        jQuery(".btn_disabled").button( "option", "disabled", true );
      }
    });	  
  }
  
}

function openModalBox(content) {  
  $('modalbox').innerHTML = content;
  jQuery('#modalbox').dialog({ 
    modal: true
  });
}

function setModalBoxTitle(title) {
  Try.these( function() {
    jQuery('#modalbox').dialog( "option", "title", title );
  });
}

function closeModalBox() {
  Try.these( function() {
    jQuery('#modalbox').dialog('close');
  });
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSiteForm (url,fct,id,idForm) {

  ourDate = new Date( );

    Try.these( function() {
          Element.setOpacity( id, 0.3 );
    });
    Try.these( function() {
      Element.show( id+'_load');
    });

    var postVars = $(idForm).serialize();
    
	  new Ajax.Updater(id, url, {
		success: id,
	    method:'post' ,
	  	postBody: 'targetBoxName='+id+'&execAction='+fct+'&'+postVars ,
			evalScripts: false,

			onComplete: function(response) {

	          Try.these( function() {
	            Element.hide( id+'_load');
	          });

	          Try.these( function() {
	            Element.setOpacity( id, 1.0 );
	          });
	
		      response.responseText.evalScripts();

			  if (effect != '') {
				    new Effect.toggle(id,effect);
					}
			}
	  });
		
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSiteUpdate (url,fct) {

  ajaxClass = new Ajax.Updater('', url, { 
	      method:'post' ,
		  postBody: '&execAction='+fct , //+'&'+Form.serialize(idForm)
		  evalScripts: false

        


	  });
		
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================

function ajaxGSiteOnChange (url,fct,nameSelect) {

  var val = $F(nameSelect);

	
  ajaxClass = new Ajax.Updater('', url, {
    method:'post' ,
    postBody: '&execAction='+fct+'&changeval='+val ,
    evalScripts: false,
    onComplete: function(response) {
      //-- Eval response scripts
      response.responseText.evalScripts();
    }
  });
			
}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function ajaxGSiteSort (id,url,sortFromAction) {
  
	Sortable.create(id, {
    	handle:'handle',
    	overlap:'vertical',
    	constraint:'vertical',
    	format: '([A-Za-z0-9\-\_]*)',
	    onUpdate: function() {
	        new Ajax.Request(url, {
	            method: "post",
	            parameters: { 
	              data: Sortable.serialize(id),
                  execAction: 'sort_list',
                  sortActionFrom: sortFromAction
	            }
                //postBody: 'execAction='+sortFromAction
	        });
	    }
	});

}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createApplicationContainerDrop (id, column, url, listContainers, pattern) {
  
  Sortable.create(id, {
      dropOnEmpty: true,
      tag:'div',
      handle:'handle',
      constraint: false,
      hoverclass: 'drop_hover',
      ghosting: false,
      containment: listContainers,
      
      //-- on update
      onUpdate:function(element) {

        var order = '';

        var childList = $(element).select('div.application_box');

        childList.each(function(child) {
        	order += '&order[]='+child.id;
          }
        );


       /* var box_display = document.getElementById('column_1_'+column);
        if (box_display.getElementsByTagName('div').length == 5) {
          document.getElementById('box_box_display_'+column).style.display = 'block';
        } else if (box_display.getElementsByTagName('img').length > 1) {
          document.getElementById('box_box_display_'+column).style.display = 'none';
        }*/
      
        new Ajax.Request(url+'&module=node_admin', {
          method: 'post',
          postBody: 'execAction=APP_MOVE&'+order+'&column='+column+'&pattern='+pattern
        });

      }

    }
  );
  
  createApplicationContainerHover (id, listContainers);
	
}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createAppDashboardContainerDrop (id, column, url, listContainers) {

  Sortable.create(id, {
      dropOnEmpty: true,
      tag:'div',
      handle:'handle',
      constraint: false,
      hoverclass: 'drop_hover',
      ghosting: false,
      containment: listContainers,

      //-- on update
      onUpdate:function(element) {

        var order = '';

        var childList = $(element).select('div.dash_box');

        childList.each(function(child) {
        	order += '&order[]='+child.id;
          }
        );

        new Ajax.Request(url+'&module=node_admin', {
          method: 'post',
          postBody: 'execAction=DASH_MOVE&'+order+'&column='+column
        });

      }

    }
  );

  createApplicationContainerHover (id, listContainers);

}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createBoxDashboardDrop (id, column, url, listContainers) {

  Sortable.create(id, {
      dropOnEmpty: true,
      tag:'div',
      handle:'handle',
      constraint: false,
      hoverclass: 'drop_hover',
      ghosting: false,
      containment: listContainers,

      //-- on update
      onUpdate:function(element) {

        var order = Sortable.serialize(element.id,{tag:'div', name:'order'});

        var box_display = document.getElementById('column_1_'+column);

        if (box_display.getElementsByTagName('div').length == 5) {
          document.getElementById('box_box_display_'+column).style.display = 'block';
        } else if (box_display.getElementsByTagName('img').length > 1) {
          document.getElementById('box_box_display_'+column).style.display = 'none';
        }

        new Ajax.Request(url, {
          method: 'post',
          postBody: 'execAction=ON_DROP&'+order+'&column='+column
        });

      }

    }
  );

  createApplicationContainerHover (id, listContainers);

}

function createApplicationContainerHover (id, listContainers) {
	
  $(id).childElements().each(function(child) {
    Element.observe(child, 'mouseover', function(e) {
      listContainers.each(function(zone) {
        $(zone).addClassName('zone_hover');
      });
      }
    )
  });

  $(id).childElements().each(function(child) {
    Element.observe(child, 'mouseout', function(e) {
      listContainers.each(function(zone) {
        $(zone).removeClassName('zone_hover');
      });
      }
    )
  });
}
//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createDropZone (id, column, url) {
  if ($(id) != null)
	  
  Sortable.create(id, {
    onUpdate:function(element) {

      var order = Sortable.serialize(element.id,{tag:'div', name:'order'});

      var box_display = document.getElementById('column_1_'+column);

      if (box_display.getElementsByTagName('div').length == 5) {
        document.getElementById('box_box_display_'+column).style.display = 'block';
      } else if (box_display.getElementsByTagName('img').length > 1) {
        document.getElementById('box_box_display_'+column).style.display = 'none';
      }
      
      new Ajax.Request(url, {
        method: 'post',
        postBody: 'execAction=ON_DROP&'+order+'&column='+column
      });

    },
    //hoverclass:'box_drag',
    tag:'div',
    overlap:'horizontal',
    constraint: false,
    handle:'handle',
    containment:$(id)
  });

}


//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createDroplist (id, url) {

      alert("created"+id);
  Sortable.create(id, {
    onUpdate:function(element) {
      alert("drop");
      //var order = Sortable.serialize(element.id,{tag:'div', name:'order'});

      /*new Ajax.Request(url, {
        method: 'post',
        postBody: 'execAction=ON_DROP&'+order+'&column='+column
      });*/

    },
    //hoverclass:'box_drag',
    //tag:'div',
    overlap:'horizontal',
    constraint: false,
    handle:'handle'
    /*containment:$(id).next()*/
  });

}

//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function createDraggable (id) {

  new Draggable(id);

}



//==============================================================================
/**
* (description de la fonction).
*
* @public | @private
* @param (type) (nom_variable) (commentaire)
* @param (type) (nom_variable) (commentaire)
* @return (type)
*/
//==============================================================================
function onMouseOverTabRow (id, myStartColor) {

  //new Effect.Highlight(id, {startcolor:myStartColor});

}

function onMouseOutTabRow (id, myStartColor) {

  //var myEndcolor = rvb2hex($(id).getStyle('background-color'));

  //new Effect.Highlight(id, {startcolor:myStartColor, restorecolor:myStartColor,duration: 0.1});

}

function rvb2hex(val){
  if (val.indexOf("rgb") >= 0)  {
  var rgb_string = val.slice(val.indexOf('(') + 1,val.indexOf(')'));
  var rgb_val = rgb_string.split(",");
  val = "#";
  var hexChars = "0123456789ABCDEF";
  for (var i = 0; i < 3; i++)  {
  var v = rgb_val[i].valueOf();
  val += hexChars.charAt(v/16) + hexChars.charAt(v%16);
  }
  }
return val;
}

var startX      = 0;
var startY      = 0;
var idToResize  = '';

function startResizing (id, event) {
  startX = Event.pointerX(event);
  startY = Event.pointerY(event);
  idToResize = id+'-main';
}

function makeResizing (event) {
  var newSizeX;
  var newSizeY;
  if (idToResize != '') {
    newSizeX = Event.pointerX(event)-startX;
    newSizeY = Event.pointerY(event)-startY;

    $(idToResize).setStyle({
      width: $(idToResize).offsetWidth-newSizeX,
      height: $(idToResize).offsetWidth-newSizeY
    });

  }
}

function stopResizing () {
 idToResize = '';
}



function debug(data){ console.log(data); }

function hideMeShowNext (element) {
  element.up().toggle();
  element.up().next().toggle();
}

function hideMeShowPrevious (element) {
  element.up().toggle();
  element.up().previous().toggle();
}

//------------------------------------------------------------------------------
/**
 * Reload all CSS on page
 */
//------------------------------------------------------------------------------

function updateStylesheets() {
	var i,a,s;
	a=document.getElementsByTagName('link');
	for(i=0;i<a.length;i++) {
		s=a[i];
		if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {
			var h=s.href.replace(/(&|\\?)forceReload=d /,'');
			s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf());
		}
	}
}

//------------------------------------------------------------------------------
/**
 * Toggle sub task bar
 */
//------------------------------------------------------------------------------

function toggleSubTaskBar () {  
  jQuery('#task_bar_sub').toggle();
  jQuery('#tb_btn_more').toggleClass('btn_more_on');
}


function updateTxtVal (id) {
  $(id).observe('clic', function(event){
    $(id).innerHTML = $('e_'+id).innerHTML;
  });
}


//------------------------------------------------------------------------------
/**
 * Toggle sub task bar
 */
//------------------------------------------------------------------------------

function toggleTreePart (idPart) {
  
  $(idPart).toggle();
  
  this.toggleClassName('btn_more_on');
  
}



/*
function htmlentities(txt) {
	txt = txt.replace(/"/g,'&quot;'); // 34 22
	txt = txt.replace(/&/g,'&amp;'); // 38 26
	txt = txt.replace(/\'/g,'&#39;'); // 39 27
	txt = txt.replace(/</g,'&lt;'); // 60 3C
	txt = txt.replace(/>/g,'&gt;'); // 62 3E
	txt = txt.replace(/\^/g,'&circ;'); // 94 5E
	txt = txt.replace(/?/g,'&lsquo;'); // 145 91
	txt = txt.replace(/?/g,'&rsquo;'); // 146 92
	txt = txt.replace(/?/g,'&ldquo;'); // 147 93
	txt = txt.replace(/?/g,'&rdquo;'); // 148 94
	txt = txt.replace(/?/g,'&bull;'); // 149 95
	txt = txt.replace(/?/g,'&ndash;'); // 150 96
	txt = txt.replace(/?/g,'&mdash;'); // 151 97
	txt = txt.replace(/?/g,'&tilde;'); // 152 98
	txt = txt.replace(/?/g,'&trade;'); // 153 99
	txt = txt.replace(//g,'&scaron;'); // 154 9A
	txt = txt.replace(/?/g,'&rsaquo;'); // 155 9B
	txt = txt.replace(//g,'&oelig;'); // 156 9C
	txt = txt.replace(//g,'&#357;'); // 157 9D
	txt = txt.replace(//g,'&#382;'); // 158 9E
	txt = txt.replace(//g,'&Yuml;'); // 159 9F
	txt = txt.replace(/ /g,'&nbsp;'); // 160 A0
	txt = txt.replace(//g,'&iexcl;'); // 161 A1
	txt = txt.replace(//g,'&cent;'); // 162 A2
	txt = txt.replace(//g,'&pound;'); // 163 A3
	txt = txt.replace(/ /g,'&curren;'); // 164 A4
	txt = txt.replace(//g,'&yen;'); // 165 A5
	txt = txt.replace(/?/g,'&brvbar;'); // 166 A6
	txt = txt.replace(//g,'&sect;'); // 167 A7
	txt = txt.replace(/?/g,'&uml;'); // 168 A8
	txt = txt.replace(//g,'&copy;'); // 169 A9
	txt = txt.replace(//g,'&ordf;'); // 170 AA
	txt = txt.replace(//g,'&laquo;'); // 171 AB
	txt = txt.replace(//g,'&not;'); // 172 AC
	txt = txt.replace(//g,'&reg;'); // 174 AE
	txt = txt.replace(//g,'&macr;'); // 175 AF
	txt = txt.replace(//g,'&deg;'); // 176 B0
	txt = txt.replace(//g,'&plusmn;'); // 177 B1
	txt = txt.replace(//g,'&sup2;'); // 178 B2
	txt = txt.replace(//g,'&sup3;'); // 179 B3
	txt = txt.replace(/?/g,'&acute;'); // 180 B4
	txt = txt.replace(//g,'&micro;'); // 181 B5
	txt = txt.replace(//g,'&para'); // 182 B6
	txt = txt.replace(//g,'&middot;'); // 183 B7
	txt = txt.replace(/?/g,'&cedil;'); // 184 B8
	txt = txt.replace(//g,'&sup1;'); // 185 B9
	txt = txt.replace(//g,'&ordm;'); // 186 BA
	txt = txt.replace(//g,'&raquo;'); // 187 BB
	txt = txt.replace(/?/g,'&frac14;'); // 188 BC
	txt = txt.replace(/?/g,'&frac12;'); // 189 BD
	txt = txt.replace(/?/g,'&frac34;'); // 190 BE
	txt = txt.replace(//g,'&iquest;'); // 191 BF
	txt = txt.replace(//g,'&Agrave;'); // 192 C0
	txt = txt.replace(//g,'&Aacute;'); // 193 C1
	txt = txt.replace(//g,'&Acirc;'); // 194 C2
	txt = txt.replace(//g,'&Atilde;'); // 195 C3
	txt = txt.replace(//g,'&Auml;'); // 196 C4
	txt = txt.replace(//g,'&Aring;'); // 197 C5
	txt = txt.replace(//g,'&AElig;'); // 198 C6
	txt = txt.replace(//g,'&Ccedil;'); // 199 C7
	txt = txt.replace(//g,'&Egrave;'); // 200 C8
	txt = txt.replace(//g,'&Eacute;'); // 201 C9
	txt = txt.replace(//g,'&Ecirc;'); // 202 CA
	txt = txt.replace(//g,'&Euml;'); // 203 CB
	txt = txt.replace(//g,'&Igrave;'); // 204 CC
	txt = txt.replace(//g,'&Iacute;'); // 205 CD
	txt = txt.replace(//g,'&Icirc;'); // 206 CE
	txt = txt.replace(//g,'&Iuml;'); // 207 CF
	txt = txt.replace(//g,'&ETH;'); // 208 D0
	txt = txt.replace(//g,'&Ntilde;'); // 209 D1
	txt = txt.replace(//g,'&Ograve;'); // 210 D2
	txt = txt.replace(//g,'&Oacute;'); // 211 D3
	txt = txt.replace(//g,'&Ocirc;'); // 212 D4
	txt = txt.replace(//g,'&Otilde;'); // 213 D5
	txt = txt.replace(//g,'&Ouml;'); // 214 D6
	txt = txt.replace(//g,'&times;'); // 215 D7
	txt = txt.replace(//g,'&Oslash;'); // 216 D8
	txt = txt.replace(//g,'&Ugrave;'); // 217 D9
	txt = txt.replace(//g,'&Uacute;'); // 218 DA
	txt = txt.replace(//g,'&Ucirc;'); // 219 DB
	txt = txt.replace(//g,'&Uuml;'); // 220 DC
	txt = txt.replace(//g,'&Yacute;'); // 221 DD
	txt = txt.replace(//g,'&THORN;'); // 222 DE
	txt = txt.replace(//g,'&szlig;'); // 223 DF
	txt = txt.replace(//g,'&agrave;'); // 224 E0
	txt = txt.replace(//g,'&aacute;'); // 225 E1
	txt = txt.replace(//g,'&acirc;'); // 226 E2
	txt = txt.replace(//g,'&atilde;'); // 227 E3
	txt = txt.replace(//g,'&auml;'); // 228 E4
	txt = txt.replace(//g,'&aring;'); // 229 E5
	txt = txt.replace(//g,'&aelig;'); // 230 E6
	txt = txt.replace(//g,'&ccedil;'); // 231 E7
	txt = txt.replace(//g,'&egrave;'); // 232 E8
	txt = txt.replace(//g,'&eacute;'); // 233 E9
	txt = txt.replace(//g,'&ecirc;'); // 234 EA
	txt = txt.replace(//g,'&euml;'); // 235 EB
	txt = txt.replace(//g,'&igrave;'); // 236 EC
	txt = txt.replace(//g,'&iacute;'); // 237 ED
	txt = txt.replace(//g,'&icirc;'); // 238 EE
	txt = txt.replace(//g,'&iuml;'); // 239 EF
	txt = txt.replace(//g,'&eth;'); // 240 F0
	txt = txt.replace(//g,'&ntilde;'); // 241 F1
	txt = txt.replace(//g,'&ograve;'); // 242 F2
	txt = txt.replace(//g,'&oacute;'); // 243 F3
	txt = txt.replace(//g,'&ocirc;'); // 244 F4
	txt = txt.replace(//g,'&otilde;'); // 245 F5
	txt = txt.replace(//g,'&ouml;'); // 246 F6
	txt = txt.replace(//g,'&divide;'); // 247 F7
	txt = txt.replace(//g,'&oslash;'); // 248 F8
	txt = txt.replace(//g,'&ugrave;'); // 249 F9
	txt = txt.replace(//g,'&uacute;'); // 250 FA
	txt = txt.replace(//g,'&ucirc;'); // 251 FB
	txt = txt.replace(//g,'&uuml;'); // 252 FC
	txt = txt.replace(//g,'&yacute;'); // 253 FD
	txt = txt.replace(//g,'&thorn;'); // 254 FE
	txt = txt.replace(//g,'&yuml;'); // 255 FF
	return txt;
}*/
