//-----------------------------------------------------------------
// systeme de changement de fond sur le click des sous menu

// Atteint une Url après une confirmation par boîte de dialogue...
// <a href="javascript:conf('message','url');>
// préférer la syntaxe suivante
// <a href="url" onclick="return confirm('message');>
// => l'url n'est atteinte que si message validé
// => si pas javascript, url atteinte sans confirmation
function conf(m,u)
 {
	if( confirm(m) )	window.location.href=u; //'http://www.google.fr'; //u;
 }
 
 
 
/* Permet d'ajuster  la taille de la fenêtre en fct de la taille d'une image 
@param str, id de l'élément img
@param int marge horizontale à rajouter
@param int marge verticale à rajouter
@param int largeur minimale
@param int hauteur minimale
*/
function fitPic( idImage , margeW , margeH ,  minW, minH ) {
	if (margeW == null){ margeW = 0;}
	if (margeH == null){ margeH = 0;}
	if (idImage == null){ idImage = "image";}
	if (minW == null){ minW = 100;}
	if (minH == null){ minH = 100;}
//	window.alert('resize, margeW '+margeW+' - margeH '+margeH);
	var aWidth = 0;
	var aHeight = 0;
	var cWidth = 0;
	var cHeight = 0;
	if (window.innerWidth){
		if (window.innerWidth > window.outerWidth) { // bug sous firefox ???
		    aWidth = window.outerWidth;
		} else {
		    aWidth = window.innerWidth;
		}
	    aHeight = window.innerHeight;
	}else{
	    aWidth = document.body.clientWidth;
	    aHeight =document.body.clientHeight;
	}
//	window.alert('actuel, W '+aWidth+' - H '+aHeight);
	cWidth = document.getElementById(idImage).width + margeW;
	cHeight = document.getElementById(idImage).height + margeH;
//	window.alert('resizeby, W '+cWidth - aWidth+' - H '+cHeight - aHeight);
	if (cWidth < minW) { cWidth = minW;}
	if (cHeight < minH) { cHeight = minH;}
	window.resizeBy(cWidth - aWidth, cHeight - aHeight);
	window.focus();
};


function zoomimage(src,largeur,hauteur) 
{
	popUp = window.open(src,'zoomimage','width=' + largeur + ',' + 'height=' + hauteur  + ' ,left=20,top=20,resizable=yes,scrollbars=no,toolbars=no,menubars=no,location=no');
	popUp.focus();
}
function zoomimage2(src,largeur,hauteur,x,y) 
{
	popUp = window.open('/zoom.php?img='+src,'zoomimage','width=' + largeur + ',' + 'height=' + hauteur  + ' ,left=' + x + ',top=' + y + ',resizable=yes,scrollbars=no,toolbars=no,menubars=no,location=no');
	popUp.focus();
}

/* Change la visibilité d'un élément 
 * style display none ou paramètre 2
 * si param2=undefined, on prend block
 * @modif 20091001 FH : si display =="" showhide("element","");
 * on mettra la propriété display à "" et plus à block
 * utile pour les éléments TR, si on mets à table-row c'est OK pour FF mais pas pour IE
 * 							et si on mets block, c'est OK pour IE mais par pour FF
 * 							si on mets "", c'est bon pour les 2
 * @param string id de l'élément
 */
function showhide(idelement,display,force_disp)
{
	//alert(idelement+" "+display+" "+force_disp);
	if (typeof(display)=="undefined" /*|| display==""*/) display="block";
	var el = document.getElementById(idelement);
	if (el)
	{
		if (el.style.display == "none" || force_disp) {
			el.style.display = display;
		} else {
			el.style.display = "none";
		}
	}
}
function debug(message){
	if(typeof console == 'object') console.log(message);
		//else window.alert(message);
}


// Cherche remlace en RegExp
function chercheRemplace( texte, stringToFind, stringRemplacement )
{
var text = texte.toString(); var maReg = new RegExp( stringToFind, "gi") ;
var resultat = text.replace( maReg, stringRemplacement ) ;
if ( text.search( maReg ) == -1 ) { return text;} else {return resultat ;}
}
function is_empty(variable){
	if(typeof(variable)=='undefined') return true;
	if(!variable) return true;
	if(variable=='') return true;
	return false;
}

function is_numeric( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // *     example 1: is_numeric(186.31); returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld'); returns 2: false
    // *     example 3: is_numeric('+186.31e2'); returns 3: true
     return !isNaN( mixed_var );
}
function in_array(needle, haystack, strict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}
/*function tooltipOnclick(element)
{
	var t=$(element).attr('title');
	$.get("tooltip.php",{id=t},function(){});
	
}*/

function surscroll () { 
//debug("position "+$("#cadre_gauche").css("position"));  
if($("#cadre_gauche").css("position") == "static") return; // pas de CSS...
	var scroll = $(window).scrollTop();      //debug("SCROLL "+scroll); 
//	alert(scroll);
	var scrollmin = $("#top_pub_gauche").offset().top + $("#top_pub_gauche").innerHeight();//debug("pub top "+scrollmin); 
	var wh=window.innerHeight;
	//alert(wh);
	var hpgauche = $("#cadre_gauche_pub_spots").innerHeight();
	var hgauche = $("#cadre_gauche").innerHeight() + 20;
	var hcontent = $("#content_sous").innerHeight();
	var tcontent = $("#content_sous").offset().top
	//alert(hcontent);
	
	//@voir 
	if(hpgauche > wh && hgauche + 200 > hcontent)var diff=hpgauche-wh+100;
	else diff = 0;
	// /voir
	
	//alert(diff);
	//debug("windowheight:"+wh+"-windowscrolltop "+scroll+"-toppubgauche.offset+toppubgauche.height:"+scrollmin+"-cadrepubgauche.height:"+hpgauche+"-cadregauche.height:"+hgauche+"-content_sous.height:"+hcontent+"diff:"+diff);
	if(scroll > scrollmin) 
	{
		var marg = scroll - scrollmin - diff;
		
	} else {var marg = 0;}
	// limite pour ne pas dépasser la taille de content_sous
	if( (marg + scrollmin + hpgauche) > (tcontent + hcontent) )
	{
		marg = (tcontent + hcontent) - (scrollmin + hpgauche);
	}
	if(marg < 0) marg = 0;
//debug("scrollmin:"+scrollmin+"+marg:"+marg+"+hpgauche:"+hpgauche+"=>"+(scrollmin+marg+hpgauche)+" <=> (tcontent:"+tcontent+"+hcontent:"+hcontent+"):"+(tcontent+hcontent));	//alert(marg);
	 $("#cadre_gauche_pub_spots").stop();
	 $("#cadre_gauche_pub_spots").animate({marginTop:marg},0);
}

function GoToPage (url) 
{
	document.location=url;
}
		
function cliquerFormulaire(div)
{
	var idDiv = div.id;
	var selecteurCssForm = "#"+idDiv+" form";
	$(selecteurCssForm).submit();
}
