function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=" );
	 if (start<0) start=location.search.indexOf("&"+name+"=" );
	 if (start<0) return '';
	 start += name.length+2;
	 var end=location.search.indexOf("&",start)-1;
	 if (end<0) end=location.search.length;
	 var result='';
	 for(var i=start;i<=end;i++) {
		var c=location.search.charAt(i);
		result=result+(c=='+'?' ':c);
	 }
	 return unescape(result);
}



function RunFlash(fichier,largeur,hauteur){

    var_get = "?action="+GetParam("action");
    if ( GetParam("ssmenu") !="") {
	var_get += "&ssmenu="+GetParam("ssmenu");
    }
    else var_get += "&ssmenu=false"
    var_get += "&categorie="+GetParam("categorie");
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largeur+'" height="'+hauteur+'">\n');
    document.write('<param name="movie" value="'+fichier+var_get+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<embed wmode="transparent" src="'+fichier+var_get+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  width="'+largeur+'" height="'+hauteur+'"></embed>\n');
    document.write('</object>\n');
    //confirm('fonction execute');
}


function PopupImage(img,comm) {
titre="Agrandissement";
w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no');
w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
w.document.write("<SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+30); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>");
w.document.write("<BODY onload='checksize()' onclick='window.close()' onblur='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
w.document.write("<TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>");
w.document.write('<TD valign="middle" align="center"><IMG src="'+img+'" border=0 title="'+comm+'" alt="'+comm+'">');
w.document.write("</TD></TR></TABLE>");
w.document.write("</BODY></HTML>");
w.document.close();
}

function openPopup(lien,largeur,hauteur,nom){
	var resolution_hauteur = screen.height;
	if (resolution_hauteur<hauteur) hauteur=resolution_hauteur;
	popup = window.open (lien, nom,'height='+hauteur+', width='+largeur+', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
	if (popup.window.focus) {popup.window.focus();}
}

function masque(id) {
	document.getElementById(id).style.display='none';
}

function montre(id) {
	document.getElementById(id).style.display='block';
}


function validForm(nomform,array) {

	msg_alerte = false;
	for (var i=0; i<array.length; i++) {
		var valeur = array[i];
		//alert(valeur);
		 if (document.forms[nomform].elements[valeur].value.length == 0) {
			document.forms[nomform].elements[valeur].className="champsincomplet";
			msg_alerte = true;
		 }
		 else document.forms[nomform].elements[valeur].className="";
	}


	if (msg_alerte == true) {
		alert("Les champs de saisie sur fond rouge sont incomplets");
		return false;
	}
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}


function validForm2 (form){
	var couleur = '#fa2222';
	var msg_alerte = false;

	//verification des champs simplement vide
 	var array_element = getElementsByClassName('milkValidator_required',"*",document.getElementById(form));
	var nbre_element = array_element.length;
	for (var i=0; i<nbre_element; i++) {
		if (array_element[i].value.length == 0) {
			array_element[i].style.backgroundColor = couleur;
			msg_alerte = true;
		 }
		 else array_element[i].style.backgroundColor = '';
	 }

	//verification des champs de type mail
 	array_element = getElementsByClassName("milkValidator_mail","*",document.getElementById(form));
  	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
  	         // /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}[.][a-zA-Z0-9]{2,4}$/ ;
 	for (i=0; i<array_element.length; i++) {
        if(reg.exec(array_element[i].value)==null) { /*si l'email n'est pas valide*/
        	array_element[i].style.backgroundColor = couleur;
			msg_alerte = true;
        }
		 else array_element[i].style.backgroundColor = '';
	 }

	//verificaion des champs de type date
	array_element = getElementsByClassName("milkValidator_date","*",document.getElementById(form));
  	reg = /^\d{1}\d{1}\/\d{1}\d{1}\/\d{1}\d{1}\d{1}\d{1}$/;
  	         // /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}[.][a-zA-Z0-9]{2,4}$/ ;
 	for (i=0; i<array_element.length; i++) {
        if(reg.exec(array_element[i].value)==null) { /*si l'email n'est pas valide*/
        	array_element[i].style.backgroundColor = couleur;
			msg_alerte = true;
        }
		 else array_element[i].style.backgroundColor = '';
	 }

	//verification de champs de type entier
	array_element = getElementsByClassName("milkValidator_integer","*",document.getElementById(form));
  	reg = /^\d+$/
 	for (i=0; i<array_element.length; i++) {
        if(reg.exec(array_element[i].value)==null) { /*si l'email n'est pas valide*/
        	array_element[i].style.backgroundColor = couleur;
			msg_alerte = true;
        }
		 else array_element[i].style.backgroundColor = '';
	 }

	//gestion de la reponse envoi ou non du formulaire
	 if (msg_alerte == true) {
		alert("Les champs de saisie sur fond rouge sont incomplets ou non valides. ");
		return false;
	}
	else return true;

}

var liste_effet = new Array();
function changerImage(img, src, maxWidth, maxHeight)
{
	var img_id = img;
	//if ( typeof(global_href)!= 'undefined' && global_href == src) return false;
	if ( $(img).getProperty('src') != src ) {
		if ( !liste_effet[img_id]) {
		//var effet = new Fx.Morph(img, {duration: 500, transition: Fx.Transitions.Sine.easeOut,wait:true});
	 		liste_effet[img_id] = new Fx.Morph(img, {duration: 500, transition: Fx.Transitions.Sine.easeOut,wait:false});
		}
	 	$(img).setStyle('opacity', 0);

	   var image = new Image();

	   image.onerror = function()
	   {
	      alert("Erreur lors du chargement de l'image");
	   }

	   image.onabort = function()
	   {
	      alert("Chargement interrompu");
	   }

	   // une fois l'image chargée :
	   image.onload = function()
	   {
	   		liste_effet[img_id].start({
	    		'opacity': [0,1]
			});
	      // si l'image est désignée par son id
	      if(typeof img == "string")
	         img = document.getElementById(img);

	      // si l'image doit être redimensionnée
	      var reduction = 1;
	      if(maxWidth && maxHeight)
	         if(image.width > maxWidth || image.height > maxHeight)
	            reduction = Math.max(image.width/maxWidth, image.height/maxHeight);

		if (image.width < maxWidth ){
			difference = maxWidth-image.width;
			padding_left = 0;
		}
		else padding_left=0;
	      // on affiche l'image
	      img.src = image.src;
	      img.width = image.width;
	      img.style.margin = "0px "+padding_left+"px";
	      //img.width = Math.round(image.width / reduction);
	      //img.height = Math.round(image.height / reduction);
	      //fx_opacity_image.start(0,1);
	   }
		global_href = src;
	   image.src = src;
   }// fin if
   return false;
}

var image_en_cours_prevNextImageNav = 0;
function prevNextImageNav(image_cible,array_image,prev,next)
{


	 $(prev).addEvent('click', function(){
	 	if (image_en_cours_prevNextImageNav>0) {
		 	 changerImage(image_cible,array_image[image_en_cours_prevNextImageNav],260,355);
		 	 image_en_cours_prevNextImageNav--;
		 }
	 	 return false;
	  });

	 $(next).addEvent('click', function(){
	 	  if (image_en_cours_prevNextImageNav<array_image.length-1) {
		 	 changerImage(image_cible,array_image[image_en_cours_prevNextImageNav],260,355);
		 	 image_en_cours_prevNextImageNav++;
		  }else {
			image_en_cours_prevNextImageNav = 0;
		  }
	 	 return false;
	  });
}


function changeImage2(id_image,chemin)
{
	//document.fiche_image.src = chemin
	document.getElementById(id_image).src = chemin;
}

function intro(string_elements,delay,vitesse){
var x= new Chain();
	var divz = $$(string_elements);
	//var divz = $$("body *");
		divz.each(function(div, i) {
			//li.fade('hide');
			//mot_principal= li.getElement('H3');
			if( !div.hasClass("no_effet") && div.getStyle('opacity').toInt() > 0 ) {
				var opacite = div.getStyle('opacity').toInt();
				div.fade('hide');
				//description.fade('hide');
				var Fx1 = new Fx.Morph(div, {duration:vitesse, transition: Fx.Transitions.Sine.easeIn,wait:false});
				window['effet'+i]= function(){
					Fx1.start({
						//'padding':['50px','0px'],
						//'font-size':['0px','20px'],
						'opacity':[0,opacite]
					});
				};
				x.chain(window['effet'+i]);
				x.callChain.delay((i*delay), x);
			}//fin if
			//gestion description
			//gestionDesMotclefs(mot_principal,description);

		});//fin boucle each
}


//scrollbar sur un element
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	if(content.getScrollSize().y - content.getSize().y>0){
				var x = 0;
				var y = 0;
				var position = 0;
				//var smooth_scroll = new Fx.Scroll(content,{wait:true,duration:200,transition: Fx.Transitions.Sine.easeOut});

				$(scrollbar).setStyle('display', 'block');
				//$(handle).setStyle('display', 'none');
				//document.write('dimensionscroll'+content.getSize().scrollSize.y );
				//var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
				var slider = new Slider(scrollbar, handle, {
					steps: content.getScrollSize().y - content.getSize().y,
					mode: 'vertical',
					onChange: function(step){
						// Scrolls the content element in x or y direction.
						x = (horizontal?step:0);
						y = (horizontal?0:step);
						//content.scrollTo(x,y);
						//smooth_scroll.start(x,y);
					}
				}).set(0);
				if( !(ignoreMouse) ){
					// Scroll the content element when the mousewheel is used within the
					// content or the scrollbar element.
					$$(content, scrollbar).addEvent('mousewheel', function(e){
						e = new Event(e).stop();
						var step = slider.step - e.wheel * 30;
						slider.set(step);
					});
				}


				var deplacement = ( function(){
					var position_actuel = content.getScroll().y;
					position += (y-position_actuel.toInt())/20;
					//var difference = Math.abs(position_actuel.toInt()-scrollX.toInt());
					//if (difference > 0) {
						//content.scrollTo(position.toInt(),0);
					content.scrollTo(0,position);

					//$('colonne_left').set('html','position <br />executée! '+position );
					///}
			//else $('info').set('html','position non executée...'+position);
				}).periodical(10);
				// Stops the handle dragging process when the mouse leaves the document body.
				//$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
				return slider;
	}//fin if
	var ancre = parseInt(GetParam("ancre"));
	//document.write(ancre);
	if(!isNaN(ancre)) slider.set(ancre);
}

