/*
Name: Tools
Description: Augmenter / réduire la taille du texte des éléments marqués par la classe css "resizable"
Version: 1.0
Author: ITNetwork
*/
/*function change_zoom(f) {
	switch(f) {
		// réduire la taille du texte à la taille initiale des éléments marqués par la classe css "resizable"
		case 1:
			var o2 = $$('.resizable');
			for(var i=0; i<o2.length; i++)
			{
				o2[i].style.fontSize = "13px";
			}
			var o2 = $$('.resizable h2');
			for(var i=0; i<o2.length; i++)
			{
				o2[i].style.fontSize = "17px";
			}
			break;
			
		// augmenter la taille du texte des éléments marqués par la classe css "resizable"
		case 2:
			var o2 = $$('.resizable');
			for(var i=0; i<o2.length; i++)
			{
				o2[i].style.fontSize = "17px";
			}
			var o2 = $$('.resizable h2');
			for(var i=0; i<o2.length; i++)
			{
				o2[i].style.fontSize = "19px";
			}
			break;
	}
}

*/

function getElementsByClass(searchClass, node, tag) 
{ 
	var classElements = new Array(); 
	if ( node == null ) 
	node = document; 
	if ( tag == null ) 
	tag = '*'; 
	var els = node.getElementsByTagName(tag); 
	var elsLen = els.length; 
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 
	for (i = 0, j = 0; i < elsLen; i++) 
	{ 
		if ( pattern.test(els[i].className) ) 
		{ 
			classElements[j] = els[i]; 
			j++; 
		} 
	} 
	return classElements; 
} 



function change_zoom(f) {
	var taille = new Array();
	taille[1] = [13, 17];
	taille[2] = [17 ,19];
	
	var o2 = getElementsByClass('resizable');
	for(var i=0; i<o2.length; i++)
	{
		o2[i].style.fontSize = taille[f][0]+"px";
		var h2 = o2[i].getElementsByTagName('H2');
		for(var j=0; j<h2.length; j++) h2[i].style.fontSize = taille[f][1]+"px";
	}
}


//PNG transparent IE6
function png2ie6(id)
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (document.body.filters))
    {
          var img = document.getElementById(id) || id;
          var imgName = img.src.toUpperCase();
		  var imgSplit = img.src.split('/');
		  var imgChemin = '';
		  for(var i = 0; i<imgSplit.length-1; i++){
			  imgChemin += imgSplit[i]+'/';
		  }
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"><img src='"+imgChemin+"pixel_transparent.gif' width='"+img.width+"' height='"+img.height+"' alt='' /></span>"
             img.outerHTML = strNewHTML
          }
    }
} 

//Fonction calcul de la position d'un objet par rapport Ã  la page
function calTopLeft(obje)
{
	var nb = calTopLeft.arguments;
	var calTop = 0;
	var calLeft = 0;
	
	while(obje)
	{
		calTop = calTop + obje.offsetTop;
		calLeft = calLeft + obje.offsetLeft;
		obje = obje.offsetParent;
		//if(nb[2] && nb[2]==true && (obje.style.position == 'absolute' || obje.style.position == 'relative')) break;
		if(nb[1] && nb[1]!=''){
			if(obje.className == nb[1] || obje.id == nb[1]){
				 break;	
			}
		}
	}	
	
	tabTopLeft = [calTop, calLeft];
	return tabTopLeft;
}

function debugJS() {
	
	/**
	 *	tabulation
	 */
	this.tabul			= '    ';
	
	/**
	 * fonctions
	 */
	this.dumpJS			= dumpJS;
	
	
	/**
	 *	@desc	decompose rÃ©cursivement un element
	 *	@param	mixed	elt		element a decomposer
	 *	@param	int		max		nombre maxi de recurances
	 *	@param	string	S_tab	suivi des tabulations
	 *	@param	int		rec		suivi de reccuression
	 */
	function dumpJS(elt, max, S_tab, rec) {
		if (max == undefined) {
			max = 2;	
			
		}
		rec++;
		var S_result	= '';
		if (elt == 'undefined') {
			return "undefined";
			
		}
		switch (typeof elt) {
			case 'object' : 
				S_result	+= "object {\n";
				if (rec < max) {
					for (myI in elt) {
						try {
							S_result += S_tab + this.tabul + '[' + myI + '] => ' 
							S_result += this.dumpJS(elt[myI], max, S_tab + this.tabul, rec);
							
						} catch (e) {
							S_result += S_tab + this.tabul + '[' + myI + '] => ' + "** ERROR **\n";
							
						}
						
					}
					
				} else {
					S_result += S_tab + this.tabul + "** MAX RECURSION **\n";	
					
				}
				S_result	+= S_tab + "}\n";
				break;
				
			case 'string' :
				S_result	+= typeof elt + ' "' + elt + "\"\n";
				break;
 
			default :
				S_result	+= typeof elt + '(' + elt + ")\n";
				break;
				
		}
		return S_result;
		
	}
	
}
 
___O_debugJS	= new debugJS();
/**
 *	@desc	decompose rÃ©cursivement un element et affiche une alerte
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function alert_r(elt, max) {
	alert(___O_debugJS.dumpJS(elt, max, "", 0));	
	
}
 
/**
 *	@desc	decompose rÃ©cursivement un element et affiche dans le body
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function document_r(elt, max) {
	document.write('<pre>');	
	document.write(___O_debugJS.dumpJS(elt, max, "", 0));	
	document.write('</pre>');	
	
}
 
 
/**
 *	@desc	decompose rÃ©cursivement un element et affiche une nouvelle fenetre
 *	@param	mixed	elt		element a decomposer
 *	@param	int		max		nombre maxi de recurances
 */
function window_r(elt, max) {
	win = window.open('', 'format','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
	win.document.write('<pre>' + ___O_debugJS.dumpJS(elt, max, "", 0) + '</pre>');
	win.focus();	
	
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}
