7/* -------------------------------------------------------------------------------------------
	File : jscript/include_form.js
	Abstract : ensemble de fonctions générales

	Fonctions définies :
	Author : Emmanuel PODVIN
	Modifications :
		- 30/09/04 - Emmanuel PODVIN - 
   ------------------------------------------------------------------------------------------- */

/* //--------------------------------------------------------------------
//	Function name :
//	Description		: 
//	input 			:
//  return value 	: 
//  global variables:
//--------------------------------------------------------------------
*/

//--DEBUT CODE INTERDIRE SELECTION TEXTE-->
function disableselect(e){
return false
}
function reEnable(){
return true
}        
// Désactivation de la sélection du texte
function desableTextSelection()
{
	//if IE4+
	document.onselectstart=new Function ("return false")
	//if NS6
	if (window.sidebar)
	{
		document.onmousedown=disableselect
		document.onclick=reEnable
	}
}
//-- Fin CODE Interdire Selection texte                                                      
 
// Affichage d'un texte sur la barre de statut
function DisplayStatusTitle(aTitle)
{
	window.status=aTitle;
    return true;
}

// décryptage simple d'une adresse mail (anti-spam)
var a, s, n;
function Decrypt(s) 
{
	r='';
    for(i=0;i<s.length;i++)
    {
    	n=s.charCodeAt(i); 
        if (n>=8364) 
        {
    	    n = 128;
	    } 
	    r += String.fromCharCode( n - 3 ); 
    }
    return r;
}           
// affichage d'une adresse mail perturbante pour les moteurs spamm
// input:
//	- name : partie login d'une adresse mail
//	- domain : partie domaine d'une adresse mail (name@domain)
//	- args : argument de mailto (permet d'ajouter un CC, etc...
//	- Text : texte à afficher pour le lien
// Output :
//		sortie html : <a href='mailto:name@domain args> Text </a>
// où name, domain args Text sont les variables d'input
function print_mail(name,domain,args,Text)
{
	a ="pdlowr=";
	m='@';d=unescape(m);
	var nom = name;
	var domaine = domain;
	var aro = nom + d + domaine;
	document.write('<a href=');
    document.write(Decrypt(a));
    document.write(aro);
    document.write(args);
    document.write('>');  
	document.write(Text + '</a>');    
}
/* //--------------------------------------------------------------------
//	Function name : TrouveObjet
//	Description		:  permet de retrouver un objet depuis son ID
//		La syntaxe d'appel de cette fonction est
//   var objet = trouveobjet(idf);
//	input 			:  idf est l'identificateur (ID) d'un élément. 
//  return value 	:  objet associé à idf
//  global variables:
//--------------------------------------------------------------------
*/
 function TrouveObjet(idf) { 
 
 doc=document;
 
    if (doc.getElementById && doc.getElementById(idf)) 	//IE
	{
	  	return doc.getElementById(idf);
    } 
	else if (doc.all && doc.all[idf]) //Mozilla
	{
      return doc.all[idf];
    } 
	else if (doc.layers) 
	{
      return doc.layers[idf];
    } 
	else 
	{ 
		return null; 
	}
  }
/* //--------------------------------------------------------------------
//	Function name : TrouveStyle
//	Description		:  permet de retrouver le style d'un objet depuis son ID
//		La syntaxe d'appel de cette fonction est
//   var objet_style = trouvestyle(idf);
//	input 			:  idf est l'identificateur (ID) d'un élément. 
//  return value 	:  objet de style associé à idf
//  global variables:
//--------------------------------------------------------------------
*/
 function TrouveStyle(idf) { 
 
 doc=document;
 
    if (doc.getElementById && doc.getElementById(idf)) 	//IE
	{
	  	return doc.getElementById(idf).style;
    } 
	else if (doc.all && doc.all[idf]) //Mozilla
	{
      return doc.all[idf].style;
    } 
	else if (doc.layers) 
	{
      return doc.layers[idf];
    } 
	else 
	{ 
		return null; 
	}
  }
/* //--------------------------------------------------------------------
//	Function name : ChangeStyle
//	Description		: Permet de modifier le style d'un objet
//	input 			:
//		idf : Id d'un objet
//		prop : nom d'une propriété
//	Dans le cas des noms composés comme background-image, la règle est de
     — mettre en majuscule la lettre après un tiret,
     — et de supprimer le(s) tiret(s).
//  return value 	:
//		aucune
//  global variables:       
//	exemple :
//		ChangeStyle("aaa","visibility","hidden");
//		ChangeStyle("aaa","border","5px ridge green"); 
//      ChangeStyle("aaa","backgroundImage","url(image_bis.jpg)") 
//--------------------------------------------------------------------
*/
  function ChangeStyle(idf,prop,value) 
  {
     var objet_style= TrouveStyle(idf);
	 if(objet_style) 					  
	 {
        eval( 'objet_style.' + prop + '="' + value+ '"' );
	 }
	 DisplayImgText(idf);
  }
/* //--------------------------------------------------------------------
//	Function name : GetStyle
//	Description		: Permet de récupérer la valeur d'un style d'un objet
//	input 			:
//		idf : Id d'un objet
//		prop : nom d'une propriété
//	Dans le cas des noms composés comme background-image, la règle est de
     — mettre en majuscule la lettre après un tiret,
     — et de supprimer le(s) tiret(s).
//  return value 	:
//		aucune
//  global variables:       
//	exemple :
//		val=GetStyle("aaa","visibility");
//--------------------------------------------------------------------
*/
  function GetStyle(idf,prop) 
  {
	 var result=null;
     var objet= TrouveObjet(idf);	
	 if (objet)
	 {
		 if (objet.currentStyle) 
		 { 
			result= objet.currentStyle[prop];	
	     } 
		 else if (window.getComputedStyle) 
		 { 
	        var compStyle = window.getComputedStyle(objet, ""); 
	        result = compStyle[prop]; 
	     }      
	}
	 return result;
  }
 
/* //--------------------------------------------------------------------
//	Function name : escape_plus
//	Description		: seems that the escape javascript function does not escape enough...
//					  so I hope this one does!
//	input 			: 
//		aString
//  return value 	: a escaped string
//  global variables:
//--------------------------------------------------------------------
*/							
    function escape_plus(aString) 
    {					   
		aString = escape(aString);     
//		aString = encodeURIComponent(aString);
		aString= aString.replace(new RegExp('\\+','g'),'%2B');
	    aString= aString.replace(new RegExp('%20','g'),'+');
	    aString= aString.replace(new RegExp('&amp;','g'),'&');
		return aString;
	}	


 /* //--------------------------------------------------------------------
//	Function name : DisplayImgText
//	Description		: 
//	input 			: 
//		idf : Id d'un objet
//  return value 	: a escaped string
//  global variables:
//--------------------------------------------------------------------
*/		
 
    function DisplayImgText(idf,basedir,separator) 
    {	
		myObj=	TrouveObjet(idf);	
		if (myObj)
		{	

			if (myObj.aTextLink == null)
			{
				aTextLink=myObj.innerHTML; 	
				aTextAltLink=aTextLink;
				aTextLink=escape_plus(aTextLink);					
				myObj.aTextLink=aTextLink; 		 
				myObj.separator=separator;
			}
			else aTextLink=myObj.aTextLink; 	 
				
			FontSize=GetStyle(idf,"fontSize");
			FontFamily=GetStyle(idf,"fontFamily");
			FontWeight=GetStyle(idf,"fontWeight");
			FontStyle=GetStyle(idf,"fontStyle");
			FontColor=escape_plus(GetStyle(idf,"color"));				
			FontBgColor=escape_plus(GetStyle(idf,"backgroundColor"));
			FontTextDecoration=escape_plus(GetStyle(idf,"textDecoration"));
			FontTextTransform=escape_plus(GetStyle(idf,"textTransform"));
	/*		document.write("<img src='menus_img/bouton.php?size="+FontSize+"&font=arial.ttf&fontcolor="+FontColor+"&fontbgcolor="+FontBgColor+"&hexa=1&text="+"<?echo $aTextLink?>"+"'>");
	*/
			myObj.innerHTML="<img name='"+idf+"img' src='"+basedir+"/menus_img/bouton.php?size="+FontSize+"&font="+FontFamily+"&fontweight="+FontWeight+"&fontstyle="+FontStyle+"&fontcolor="+FontColor+"&fontbgcolor="+FontBgColor+"&textdecoration="+FontTextDecoration+"&separator="+separator+"&textTransform="+FontTextTransform+"&hexa=1&text="+aTextLink+"' onMouseOver='DisplayImgTextOnMouse(\""+idf+"\",1,\""+basedir+"\")' onMouseOut='DisplayImgTextOnMouse(\""+idf+"\",0,\""+basedir+"\")' alt='"+aTextAltLink+"'>";

			myObj.imgtxtoff=new Image(); 
	myObj.imgtxtoff.src=basedir+"/menus_img/bouton.php?size="+FontSize+"&font="+FontFamily+"&fontweight="+FontWeight+"&fontstyle="+FontStyle+"&fontcolor="+FontColor+"&fontbgcolor="+FontBgColor+"&textdecoration="+FontTextDecoration+"&separator="+separator+"&textTransform="+FontTextTransform+"&hexa=1&text="+aTextLink;
		}	
		
/*			mid=TrouveObjet('toto'); if (mid==null) alert('nul');  
 	 	mid.innerHTML = myObj.imgtxtoff.src;*/

	}
	
	/* //--------------------------------------------------------------------
//	Function name : DisplayImgTextOnMouse
//	Description		: 
//	input 			: 
//		idf : Id d'un objet		  
//		InvertBg : si 1, à vrai
//  return value 	: a escaped string
//  global variables:
//--------------------------------------------------------------------
*/							
    function DisplayImgTextOnMouse(idf,InvertBg,basedir) 
    {	
		myObj=	TrouveObjet(idf);	 		
		if (myObj && document.images)
		{							
			if (myObj.imgtxton == null)
			{							   	
				if (document.all  && (myObj.className == myObj.className.replace(/\bhover\b/,'')) )
				{	
					return;					
				}
				else
				{
					
					FontSize=GetStyle(idf,"fontSize");
					FontFamily=GetStyle(idf,"fontFamily");
					FontWeight=GetStyle(idf,"fontWeight");
					FontStyle=GetStyle(idf,"fontStyle");
					FontColor=escape_plus(GetStyle(idf,"color"));					
					FontBgColor=escape_plus(GetStyle(idf,"backgroundColor"));
					FontTextDecoration=escape_plus(GetStyle(idf,"textDecoration"));	
					FontTextTransform=escape_plus(GetStyle(idf,"textTransform"));
					myObj.imgtxton=new Image(); 
		myObj.imgtxton.src=basedir+"/menus_img/bouton.php?size="+FontSize+"&font="+FontFamily+"&fontweight="+FontWeight+"&fontstyle="+FontStyle+"&fontcolor="+FontColor+"&fontbgcolor="+FontBgColor+"&textdecoration="+FontTextDecoration+"&separator="+myObj.separator+"&textTransform="+FontTextTransform+"&hexa=1&text="+myObj.aTextLink;
				}
			}						  

			if (InvertBg == 1) document.images[idf+'img'].src=myObj.imgtxton.src;
			else document.images[idf+'img'].src=myObj.imgtxtoff.src;
		}
		
	}
	
/** toCamelCase(input)
 * Converts string input to a camel cased version of itself.
 * For example:
 * toCamelCase("z-index"); // returns zIndex
 * toCamelCase("border-bottom-style"); // returns borderBottomStyle.
 * thanks to http://dhtmlkitchen.com/learn/js/setstyle
 */
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
    	oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}	

