function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
		} 	 		
	else if (obj.attachEvent) {
		 obj.attachEvent('on'+evType, fn);
		return true;
		} 	 		
	else {
		 obj.attachEvent('on'+evType, fn);
		return false;
		}
}
function transformXml(urlXml,urlXsl,tagHtml)
{	
	new XSLTHelper( urlXml, urlXsl ).loadView( tagHtml );	
}
function transformXmlPost(urlXml,urlXsl,tagHtml,formulaireId)
{	
	new XSLTHelperPost( urlXml, urlXsl,formulaireId ).loadView( tagHtml );	
}
function transformMultiXsl(urlXml,tabXsl,tabTag,xml)
{
	var afficheXsl = new multiXsl(urlXml,tabXsl,tabTag,xml);	
	afficheXsl.initXslHelper();
	if(xml==null)
		afficheXsl.loadXml();
}
function getXmlAjax(url,method)
{
	this.method=method;
	this.xmlURL=url;
}
getXmlAjax.prototype = {
	init:function()
	{ 
		new Ajax.Request( this.xmlURL,
	                        {method: "GET",onSuccess: this.setXMLDocument.bind(this),asynchronous:false} );
	},
	setXMLDocument: function(request) {
      this.xmlDocument = request;  
      eval(this.method(request));
   }
}
function multiXsl(urlXml,tabXsl,tabTag,xml)
{
	this.xmlURL=urlXml;
	this.tabXsl=tabXsl;
	this.tabTag=tabTag;
	this.tabXslHelper = new Array(tabXsl.length);
	this.finInit=false;
	this.xmlDocument=xml;
}
multiXsl.prototype = {
	initXslHelper: function() {
		for(var i=0;i<this.tabXsl.length;i++)
		{
			this.tabXslHelper[i] = new XSLTHelper( null, this.tabXsl[i] );	
			this.tabXslHelper[i].loadView( this.tabTag[i] );
		}
		this.finInit=true;
		this.updateViewIfDocumentsLoaded();
	},
	loadXml : function(){
		 new Ajax.Request( this.xmlURL,
	                        {method: "GET",onSuccess: this.setXMLDocument.bind(this)} );
	},
	setXMLDocument: function(request) {
      this.xmlDocument = request;
      this.updateViewIfDocumentsLoaded();
   },
    updateViewIfDocumentsLoaded: function() {  
      if ( this.xmlDocument == null || !this.finInit )
         return;
         for(var i=0;i<this.tabXslHelper.length;i++)
         {
         	try
         	{
         		this.tabXslHelper[i].setXMLDocument(this.xmlDocument);
     		 	this.tabXslHelper[i].updateViewIfDocumentsLoaded();
     		 }
     		 catch(e)
     		 {
     		 	alert(e);
     		 }
     	 }
   }
}
var net = new Object();

net.READY_STATE_UNINITIALIZED= 0;
net.READY_STATE_LOADING      = 1;
net.READY_STATE_LOADED       = 2;
net.READY_STATE_INTERACTIVE  = 3;
net.READY_STATE_COMPLETE     = 4;

net.ContentLoader = function( component, url, method, requestParams ) {
   this.component     = component;
   this.url           = url;
   this.requestParams = requestParams;
   this.method        = method;
}

net.ContentLoader.prototype = {

   getTransport: function() {
      var transport;
      if ( window.XMLHttpRequest )
         transport = new XMLHttpRequest();
      else if ( window.ActiveXObject ) {
         try {
            transport = new ActiveXObject('Msxml2.XMLHTTP');
         }
         catch(err) {
            transport = new ActiveXObject('Microsoft.XMLHTTP');
         }
      }
      return transport;
   },

   sendRequest: function() {

      //if ( window.netscape && window.netscape.security.PrivilegeManager.enablePrivilege)
      //   netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');

      var requestParams = []
      for ( var i = 0 ; i < arguments.length ;  i++ )
         requestParams.push(arguments[i]);

      var oThis = this;
      var request = this.getTransport();
      request.open( this.method, this.url, true );
      request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');
      request.onreadystatechange = function() { oThis.handleAjaxResponse(request) };
      request.send( this.queryString(requestParams) );
  },

  queryString: function(args) {

     var requestParams = [];
     for ( var i = 0 ; i < this.requestParams.length ; i++ )
        requestParams.push(this.requestParams[i]);
     for ( var j = 0 ; j < args.length ; j++ )
        requestParams.push(args[j]);

     var queryString = "";
     if ( requestParams && requestParams.length > 0 ) {
        for ( var i = 0 ; i < requestParams.length ; i++ )
           queryString += requestParams[i] + '&';
        queryString = queryString.substring(0, queryString.length-1);
     }
     return queryString;
  },

  handleAjaxResponse: function(request) {
     if ( request.readyState == net.READY_STATE_COMPLETE ) {
        if ( this.isSuccess(request) )
           this.component.ajaxUpdate(request);
        else
           this.component.handleError(request);
     }
  },

  isSuccess: function(request) {
    return  request.status == 0
        || (request.status >= 200 && request.status < 300);
  }

};



//-------------------- mLiveSearch.js

function LiveSearch( pageURL, lookupField, xmlURL, xsltURL, options ) {
   this.pageURL      = pageURL;
   this.lookupField  = lookupField;
   this.xmlURL       = xmlURL;
   this.xsltURL      = xsltURL;
   this.setOptions(options);

   var oThis = this;
   lookupField.form.onsubmit = function() { oThis.doSearch(); return false; };
   this.initialize();
}

LiveSearch.prototype = {

   doSearch: function() {
      if ( XSLTHelper.isXSLTSupported() )
         this.doAjaxSearch();
      else
         this.submitTheForm();
   },

   setOptions: function(options) {
      this.options = options;

      if ( !this.options.loadingImage        ) this.options.loadingImage = 'images/loading.gif';
      if ( !this.options.bookmarkContainerId ) this.options.bookmarkContainerId = 'bookmark';
      if ( !this.options.resultsContainerId  ) this.options.resultsContainerId  = 'results';
      if ( !this.options.bookmarkText        ) this.options.bookmarkText = 'Bookmark Search';
   },

   initialize: function() {
      var currentLocation  = document.location.href;
      var qIndex = currentLocation.indexOf('q=');
      if ( qIndex != -1 ) {
         this.lookupField.value = currentLocation.substring( qIndex + 2 );
   this.doSearch();
      }
   },

   doAjaxSearch: function() {
      this.showLoadingImage();
      var searchUrl = this.appendToUrl( this.xmlURL, 'q', this.lookupField.value );
      new XSLTHelper( searchUrl, this.xsltURL ).loadView( this.options.resultsContainerId );
      this.updateBookmark();
   },

   submitTheForm: function() {
      var searchForm = this.lookupField.form;
      searchForm.onsubmit = function() { return true; };
      searchForm.submit();
   },

   showLoadingImage: function() {
      var newImg = document.createElement('img');
      newImg.setAttribute('src', this.options.loadingImage );
      document.getElementById(this.options.resultsContainerId).appendChild(newImg);
   },

   appendToUrl: function(url, name, value) {
      var separator = '?';
      if (url.indexOf(separator) > 0)
         separator = '&';

      return url + separator + name + '=' + value;
   },

   updateBookmark: function() {
      var container = document.getElementById(this.options.bookmarkContainerId);
      var bookmarkURL = this.appendToUrl( this.pageURL, 'q', this.lookupField.value );
      if ( container )
         container.innerHTML = '<a href="' + bookmarkURL + '" >' +
               this.options.bookmarkText + '</a>';
   }
}


//-------------------- mxsltHelper.js

function XSLTHelper( xmlURL, xslURL  ) {
   this.xmlURL = xmlURL;
   this.xslURL = xslURL;
}

XSLTHelper.isXSLTSupported = function() {
   return (window.XMLHttpRequest && window.XSLTProcessor ) ||
          XSLTHelper.isIEXmlSupported();
}

XSLTHelper.isIEXmlSupported = function() {
   if ( ! window.ActiveXObject )
      return false;
   try { new ActiveXObject("Microsoft.XMLDOM");  return true; }
   catch(err) { return false; }
}

XSLTHelper.prototype = {

   loadView: function(container) {
      if ( ! XSLTHelper.isXSLTSupported() )
         return;

      this.xmlDocument   = null;
      this.xslStyleSheet = null;
      this.container     = $(container);
      if(this.xmlURL !=null)
      {
	      new Ajax.Request( this.xmlURL,
	                        {method: "GET",onSuccess: this.setXMLDocument.bind(this)} );
	  }
      new Ajax.Request( this.xslURL,
                        {method: "GET",
                        onSuccess: this.setXSLDocument.bind(this)} );
			
   },

   setXMLDocument: function(request) {  
      this.xmlDocument = request.responseXML;
      this.updateViewIfDocumentsLoaded();
   },

   setXSLDocument: function(request) {
      this.xslStyleSheet = request.responseXML;  
      this.updateViewIfDocumentsLoaded();
   },

   updateViewIfDocumentsLoaded: function() {   
      if ( this.xmlDocument == null || this.xslStyleSheet == null )
         return;
      this.updateView();
   },

   updateView: function () {
      if ( ! XSLTHelper.isXSLTSupported() )
         return;
     if ( window.XMLHttpRequest && window.XSLTProcessor )
         this.updateViewMozilla(); 
      else if ( window.ActiveXObject )
         this.updateViewIE();
     try
     {
     	getScript(this.container);
     }
     catch(e){}
   },

   updateViewMozilla: function() {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(this.xslStyleSheet);
    
      var fragment = xsltProcessor.transformToFragment(this.xmlDocument, document);	
      
      this.container.innerHTML = "";
    
      try
      {
    	  this.container.appendChild(fragment);
    	   
      }
      catch(e){alert(e);}
      var e =this.container.innerHTML;
       this.container.innerHTML = "";
      this.container.innerHTML=e;
     // alert(this.container.innerHTML);
   },

   updateViewIE: function(container) {
      this.container.innerHTML = this.xmlDocument.transformNode(this.xslStyleSheet);
   }

}


/*XSLT HelperPost*/
function XSLTHelperPost( xmlURL, xslURL,formulaireId) {
   this.xmlURL = xmlURL;
   this.xslURL = xslURL;
   if(formulaireId!='')
	this.formulaire=document.getElementById(formulaireId);
   
}

XSLTHelperPost.isXSLTSupported = function() {
   return (window.XMLHttpRequest && window.XSLTProcessor ) ||
          XSLTHelperPost.isIEXmlSupported();
}

XSLTHelperPost.isIEXmlSupported = function() {
   if ( ! window.ActiveXObject )
      return false;
   try { new ActiveXObject("Microsoft.XMLDOM");  return true; }
   catch(err) { return false; }
}

XSLTHelperPost.prototype = {

   loadView: function(container) {
      if ( ! XSLTHelperPost.isXSLTSupported() )
         return;

      this.xmlDocument   = null;
      this.xslStyleSheet = null;
      this.container     = $(container);
     new Ajax.Request( this.xmlURL,
                        {method: "POST",onSuccess: this.setXMLDocument.bind(this),parameters:this.getOption()} );
      
      new Ajax.Request( this.xslURL,
                        {method: "GET",
                        onSuccess: this.setXSLDocument.bind(this)} );
			
   },
   loadOptionView: function(container,options) {
      if ( ! XSLTHelperPost.isXSLTSupported() )
         return;
      this.xmlDocument   = null;
      this.xslStyleSheet = null;
      this.container     = $(container);

      new Ajax.Request( this.xmlURL,
                        {method: "POST",onSuccess: this.setXMLDocument.bind(this),parameters:options} );
      new Ajax.Request( this.xslURL,
                        {method: "GET",
                        onSuccess: this.setXSLDocument.bind(this)} );
			
   },

   setXMLDocument: function(request) {
      this.xmlDocument = request.responseXML;
      this.updateViewIfDocumentsLoaded();
   },

   setXSLDocument: function(request) {
      this.xslStyleSheet = request.responseXML;
      this.updateViewIfDocumentsLoaded();
   },

   updateViewIfDocumentsLoaded: function() {
      if ( this.xmlDocument == null || this.xslStyleSheet == null )
         return;
      this.updateView();
   },

   updateView: function () {
      if ( ! XSLTHelperPost.isXSLTSupported() )
         return;

     if ( window.XMLHttpRequest && window.XSLTProcessor )
         this.updateViewMozilla();
      else if ( window.ActiveXObject )
         this.updateViewIE();
      try
	     {
	     	getScript(this.container);
	     }
	     catch(e){}
   },

   updateViewMozilla: function() {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(this.xslStyleSheet);
      var fragment = xsltProcessor.transformToFragment(this.xmlDocument, document);	
      this.container.innerHTML = "";
      this.container.appendChild(fragment);
      var e =this.container.innerHTML;
       this.container.innerHTML = "";
      this.container.innerHTML=e;
     // alert(this.container.innerHTML);
   },

   updateViewIE: function(container) {
      this.container.innerHTML = this.xmlDocument.transformNode(this.xslStyleSheet);
       //alert(this.container.innerHTML);
   },
   getOption : function(){
	try
	{
		var s='';
		for(var i=0;i<this.formulaire.length;i++)
		{
			try
			{
				var e=this.formulaire.elements[i];
				if(e.type!='checkbox' && e.type!='radio')
					s=s+e.name+'='+e.value+'&';
				else if(e.checked) s=s+e.name+'='+e.value+'&';
			}
			catch(exe)
			{
				alert(i+' '+exe);	
			}
			
		}
		var tab=s.split(";");
		return s;
	}
	catch(ex)
	{
		alert('get formulaire :'+ex);	
		return "";
	}
   }

}
function getScript(el)
{	
	var allscript = el.getElementsByTagName('script');
	for(var i=0;i< allscript.length;i++)
	{
		//var action=allscript[i].getAttribute('action');
		//if(action=='eval')
		{
			//var textEval=(allscript[i].text != undefined ? allscript[i].text : allscript[i].textContent);
			eval(allscript[i].text);
		}
	}	
}
function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}
function getJsonData(url,synchro)
{
	var data;
	var xhr=createXHR();
		xhr.open("GET",url,true);
		xhr.onreadystatechange=function() 
		{		
			if (xhr.readyState == 4) 
			{	
				if (xhr.status != 404) 
				{	
					 data=eval("(" + xhr.responseText + ")");
					 if(synchro)
					 	eval(synchro(data));
				} 
				else 
				{
					alert('lecture demande');
				}
				
			}
		}		
		xhr.send(null);
	
	return data;
}
function sendData(url,retour)
{
	var xhr=createXHR();
		xhr.open("GET",url,true);
		xhr.onreadystatechange=function() 
		{		
			if (xhr.readyState == 4) 
			{
				if (xhr.status != 404) 
				{	
					//alert(xhr.responseText);
					 if(retour)
					 	eval(retour(xhr.responseText));
				} 
				else 
				{
					alert('lecture url');
				}
				
			}
		}		
		xhr.send(null);
}

function executeSeriesFunction(e,nomGenerique,liste)
{
	var o=liste.split(',');
	Effect.Pulsate(e,{pulses:3,duration:1});
	/*try
	{
		var toto=$('div_COMP1').innerHTML;
		afficheChamp_COMP1();
	}
	catch(e)
		{
			alert(e.name+' '+e.message);
		}*/
	for(var i=0;i<o.length;i++)
	{	
		try
		{	
			eval(nomGenerique+o[i]+"();");
		}
		catch(e)
		{
			alert(e.name+' '+e.message);
		}
	}
}
function executeSeriesFunctionDiv(e,nomGenerique,div)
{
	var listeInput=$(div).getElementsByTagName("input");
	listeInput=$A(listeInput);
	valInput = listeInput.findAll(function(v,i)
		{
			if(v.type=='text') return true;
			else return false;
		});
	Effect.Pulsate(e,{pulses:3,duration:1});
	 valInput.each(function(v,i)
		{
			eval(nomGenerique+v.id+'()');			
		});
}

function changeClass(e,classe)
{
	$(e).className=classe;
}
function plierReplier(idPlier,idImgPlier,idImgReplier)
{
	if($(idPlier).style.display!='none')
	{	
		Effect.BlindUp(idPlier,
			{
				duration:0.5,
				afterUpdate : function (effet)
				{
					$(idImgPlier).style.display='none';
					$(idImgReplier).style.display='inline'
				}
			});
	}
	else
	{
		Effect.Appear(idPlier,
			{				
				duration:1,
				afterUpdate : function (effet)
				{	
					$(idImgPlier).style.display='inline';
					$(idImgReplier).style.display='none'
				}
			});
	}	
}
function listCheck(div)
{
	var listeInput=$(div).getElementsByTagName("input");
	listeInput=$A(listeInput);
	valInput = listeInput.partition(function(v,i)
		{
			if(v.type=='hidden') return true;
			else return false;
			//alert(v.type+' '+v.checked+' '+v.value+' '+v.name);
		});
	var champConcat = valInput[0][0].id;
	var value ="";
	 valInput[1].each(function(v,i)
		{
			value+=v.name+":"
			if(v.checked) value+="O;";
			else value+="N;";
		});
	$(champConcat).value=value;
}
function showAutoCompletion(element,update)
{
	alert($(element).id+' '+$(update).id);
}
function resizeCrm(){ 
	 try
	 {
		var h=''+window.screen.availHeight;
		var l=''+screen.availWidth;
		var doc_h=''+document.height;
		var doc_l=''+screen.height;
		var doc_ft=parseInt($('entete').style.height);
		var doc_eb=parseInt($('pied').style.height);
			var avail;
			if (document.all)
			{
				avail=document.body.clientHeight;
				
			}
			else
			{
				avail=window.innerHeight;			
			}
			var hh=(avail-doc_ft-doc_eb-70);
			$('corps').style.height=hh+'px';
			
		}
		catch(e){/*alert(e);*/}
}
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
		} 	 		
	else if (obj.attachEvent) {
		 obj.attachEvent('on'+evType, fn);
		return true;
		} 	 		
	else {
		 obj.attachEvent('on'+evType, fn);
		return false;
		}
}
