/*
ModalBox - The pop-up window thingie with AJAX, based on prototype and script.aculo.us.

Copyright Andrey Okonetchnikov (andrej.okonetschnikow@gmail.com), 2006-2007
All rights reserved.
 
VERSION 1.6.0
Last Modified: 12/13/2007
*/


function valider_mailing () {	
	
	var id = document.getElementById('id_Naj').value;
    var email = document.getElementById('email').value;

   if (email=='') {
   alert ("veuillez indiquer votre email");
   return false;   
   }
   
   if (!verifiermail(email)) return false;
   	

	new Ajax.Request('/post_mailing.php', { 
      method:'post',
      parameters: $('formreact').serialize(true),
      onSuccess: function(transport){
        var response = transport.responseText;
        $('formreact_listing').innerHTML = response;
      },
      onFailure: function(){
        /*$('formreact').submit();*/
      },
	  onLoading: function(){
                loader = "<br/><br/><div style=\"text-align:center;\"><img src=\"/skin/frontend/default/magesupport/images/wait.gif\" alt=\"Envoi en cours...\" /> Envoi en cours veuillez patienter.</div><br/><br/>";
                $('formreact_listing').innerHTML = loader;
            }
	  
    });	
	return false;	
	}	





function verifiermail(mail) {
    
	if(mail==""){ 
	   alert("Mail invalide");
       return false;
	   }
	
	if(mail!=""){
       if ((mail.indexOf("@")>=0)&&(mail.lastIndexOf(".")>mail.indexOf("@"))) {
       return true
     } else {
          alert("Mail invalide");
       return false
      }
        }else{
      return true
      }
      }
   
    function valider_f () {	
	
	var surnom = document.getElementById('surnom').value;
    var vemail = document.getElementById('vemail').value;
	var vcommentaire = document.getElementById('vcommentaire').value;

   if (surnom=='') {
   alert ("veuillez indiquer votre surnom");
   return false;   
   }
   
   if (!verifiermail(vemail)) return false;
   	

	new Ajax.Request('/post_reaction.php', { 
      method:'post',
      parameters: $('formreact').serialize(true),
      onSuccess: function(transport){
        var response = transport.responseText;
        $('formreact_div').innerHTML = response;
      },
      onFailure: function(){
        /*$('formreact').submit();*/
      },
	  onLoading: function(){
                loader = "<br/><br/><div style=\"text-align:center;\"><img src=\"/skin/frontend/default/magesupport/images/wait.gif\" alt=\"Envoi en cours...\" /> Envoi en cours veuillez patienter.</div><br/><br/>";
                $('formreact_div').innerHTML = loader;
            }
	  
    });	
	return false;	
	}	


if (!window.Modalbox)
	var Modalbox = new Object();

Modalbox.Methods = {
	overrideAlert: false, // Override standard browser alert message with ModalBox
	focusableElements: new Array,
	currFocused: 0,
	initialized: false,
	active: true,
	options: {
		title: "ModalBox Window", // Title of the ModalBox window
		overlayClose: true, // Close modal box by clicking on overlay
		width: 500, // Default width in px
		height: 400, // Default height in px
		overlayOpacity: .65, // Default overlay opacity
		overlayDuration: .25, // Default overlay fade in/out duration in seconds
		slideDownDuration: .5, // Default Modalbox appear slide down effect in seconds
		slideUpDuration: .5, // Default Modalbox hiding slide up effect in seconds
		resizeDuration: .25, // Default resize duration seconds
		inactiveFade: true, // Fades MB window on inactive state
		transitions: true, // Toggles transition effects. Transitions are enabled by default
		loadingString: "Please wait. Loading...", // Default loading string message
		closeString: "Close window", // Default title attribute for close window link
		closeValue: "X", // Default string for close link in the header
		params: {},
		method: 'get', // Default Ajax request method
		autoFocusing: true, // Toggles auto-focusing for form elements. Disable for long text pages.
		aspnet: false // Should be use then using with ASP.NET costrols. Then true Modalbox window will be injected into the first form element.
	},
	_options: new Object,
	
	setOptions: function(options) {
		Object.extend(this.options, options || {});
	},
	
	_init: function(options) {
		// Setting up original options with default options
		Object.extend(this._options, this.options);
		this.setOptions(options);
		
		
		//Create the overlay
		this.MBoverlay = new Element("div", { id: "MB_overlay", opacity: "0" });
		
		//Create DOm for the window
		this.MBwindow = new Element("div", {id: "MB_window", style: "display: none"}).update(
			this.MBframe = new Element("div", {id: "MB_frame"}).update(
				this.MBheader = new Element("div", {id: "MB_header"}).update(
					this.MBcaption = new Element("div", {id: "MB_caption"})
				)
			)
		);
		this.MBclose = new Element("a", {id: "MB_close", title: this.options.closeString, href: "#"}).update("<span>" + this.options.closeValue + "</span>");
		this.MBheader.insert({'bottom':this.MBclose});
		
		this.MBcontent = new Element("div", {id: "MB_content"}).update(
			this.MBloading = new Element("div", {id: "MB_loading"}).update(this.options.loadingString)
		);
		this.MBframe.insert({'bottom':this.MBcontent});
		
		// Inserting into DOM. If parameter set and form element have been found will inject into it. Otherwise will inject into body as topmost element.
		// Be sure to set padding and marging to null via CSS for both body and (in case of asp.net) form elements. 
		var injectToEl = this.options.aspnet ? $(document.body).down('form') : $(document.body);
		injectToEl.insert({'top':this.MBwindow});
		injectToEl.insert({'top':this.MBoverlay});
		
		// Initial scrolling position of the window. To be used for remove scrolling effect during ModalBox appearing
		this.initScrollX = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
		this.initScrollY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
		
		//Adding event observers
		this.hideObserver = this._hide.bindAsEventListener(this);
		this.kbdObserver = this._kbdHandler.bindAsEventListener(this);
		this._initObservers();

		this.initialized = true; // Mark as initialized
	},
	
	show: function(content, options) {
	   
		if(!this.initialized) this._init(options); // Check for is already initialized
		
		this.content = content;
		this.setOptions(options);
		
		if(this.options.title) // Updating title of the MB
			$(this.MBcaption).update(this.options.title);
		else { // If title isn't given, the header will not displayed
			$(this.MBheader).hide();
			$(this.MBcaption).hide();
		}
		
		if(this.MBwindow.style.display == "none") { // First modal box appearing
			this._appear();
			this.event("onShow"); // Passing onShow callback
		}
		else { // If MB already on the screen, update it
			this._update();
			this.event("onUpdate"); // Passing onUpdate callback
		} 
	},
	
	hide: function(options) { // External hide method to use from external HTML and JS
		if(this.initialized) {
			// Reading for options/callbacks except if event given as a pararmeter
			if(options && typeof options.element != 'function') Object.extend(this.options, options); 
			// Passing beforeHide callback
			this.event("beforeHide");
			if(this.options.transitions)
				Effect.SlideUp(this.MBwindow, { duration: this.options.slideUpDuration, transition: Effect.Transitions.sinoidal, afterFinish: this._deinit.bind(this) } );
			else {
				$(this.MBwindow).hide();
				this._deinit();
			}
		} else throw("Modalbox is not initialized.");
	},
	
	_hide: function(event) { // Internal hide method to use with overlay and close link
		event.stop(); // Stop event propaganation for link elements
		/* Then clicked on overlay we'll check the option and in case of overlayClose == false we'll break hiding execution [Fix for #139] */
		if(event.element().id == 'MB_overlay' && !this.options.overlayClose) return false;
		this.hide();
	},
	
	alert: function(message){
		var html = '<div class="MB_alert"><p>' + message + '</p><input type="button" onclick="Modalbox.hide()" value="OK" /></div>';
		Modalbox.show(html, {title: 'Alert: ' + document.title, width: 300});
	},
		
	_appear: function() { // First appearing of MB
		if(Prototype.Browser.IE && !navigator.appVersion.match(/\b7.0\b/)) { // Preparing IE 6 for showing modalbox
			window.scrollTo(0,0);
			this._prepareIE("100%", "hidden"); 
		}
		this._setWidth();
		this._setPosition();
		if(this.options.transitions) {
			$(this.MBoverlay).setStyle({opacity: 0});
			new Effect.Fade(this.MBoverlay, {
					from: 0, 
					to: this.options.overlayOpacity, 
					duration: this.options.overlayDuration, 
					afterFinish: function() {
						new Effect.SlideDown(this.MBwindow, {
							duration: this.options.slideDownDuration, 
							transition: Effect.Transitions.sinoidal, 
							afterFinish: function(){ 
								this._setPosition(); 
								this.loadContent();
							}.bind(this)
						});
					}.bind(this)
			});
		} else {
			$(this.MBoverlay).setStyle({opacity: this.options.overlayOpacity});
			$(this.MBwindow).show();
			this._setPosition(); 
			this.loadContent();
		}
		this._setWidthAndPosition = this._setWidthAndPosition.bindAsEventListener(this);
		Event.observe(window, "resize", this._setWidthAndPosition);
	},
	
	resize: function(byWidth, byHeight, options) { // Change size of MB without loading content
		var wHeight = $(this.MBwindow).getHeight();
		var wWidth = $(this.MBwindow).getWidth();
		var hHeight = $(this.MBheader).getHeight();
		var cHeight = $(this.MBcontent).getHeight();
		var newHeight = ((wHeight - hHeight + byHeight) < cHeight) ? (cHeight + hHeight - wHeight) : byHeight;
		if(options) this.setOptions(options); // Passing callbacks
		if(this.options.transitions) {
			new Effect.ScaleBy(this.MBwindow, byWidth, newHeight, {
					duration: this.options.resizeDuration, 
				  	afterFinish: function() { 
						this.event("_afterResize"); // Passing internal callback
						this.event("afterResize"); // Passing callback
					}.bind(this)
				});
		} else {
			
			this.MBwindow.setStyle({width: wWidth + byWidth + "px", height: wHeight + newHeight + "px"});
			setTimeout(function() {
				this.event("_afterResize"); // Passing internal callback
				this.event("afterResize"); // Passing callback
			}.bind(this), 1);
			
		}
		
	},
	
	resizeToContent: function(options){
		
		// Resizes the modalbox window to the actual content height.
		// This might be useful to resize modalbox after some content modifications which were changed ccontent height.
		
		var byHeight = this.options.height - this.MBwindow.offsetHeight;
		if(byHeight != 0) {
			if(options) this.setOptions(options); // Passing callbacks
			Modalbox.resize(0, byHeight);
		}
	},
	
	resizeToInclude: function(element, options){
		
		// Resizes the modalbox window to the camulative height of element. Calculations are using CSS properties for margins and border.
		// This method might be useful to resize modalbox before including or updating content.
		
		var el = $(element);
		var elHeight = el.getHeight() + parseInt(el.getStyle('margin-top')) + parseInt(el.getStyle('margin-bottom')) + parseInt(el.getStyle('border-top-width')) + parseInt(el.getStyle('border-bottom-width'));
		if(elHeight > 0) {
			if(options) this.setOptions(options); // Passing callbacks
			Modalbox.resize(0, elHeight);
		}
	},
	
	_update: function() { // Updating MB in case of wizards
		$(this.MBcontent).update("");
		this.MBcontent.appendChild(this.MBloading);
		$(this.MBloading).update(this.options.loadingString);
		this.currentDims = [this.MBwindow.offsetWidth, this.MBwindow.offsetHeight];
		Modalbox.resize((this.options.width - this.currentDims[0]), (this.options.height - this.currentDims[1]), {_afterResize: this._loadAfterResize.bind(this) });
	},
	
	loadContent: function () {
		if(this.event("beforeLoad") != false) { // If callback passed false, skip loading of the content
			if(typeof this.content == 'string') {
				var htmlRegExp = new RegExp(/<\/?[^>]+>/gi);
				if(htmlRegExp.test(this.content)) { // Plain HTML given as a parameter
					this._insertContent(this.content.stripScripts());
					this._putContent(function(){
						this.content.extractScripts().map(function(script) { 
							return eval(script.replace("<!--", "").replace("// -->", ""));
						}.bind(window));
					}.bind(this));
				} else // URL given as a parameter. We'll request it via Ajax
					new Ajax.Request( this.content, { method: this.options.method.toLowerCase(), parameters: this.options.params, 
						onSuccess: function(transport) {
							var response = new String(transport.responseText);
							this._insertContent(transport.responseText.stripScripts());
							this._putContent(function(){
								response.extractScripts().map(function(script) { 
									return eval(script.replace("<!--", "").replace("// -->", ""));
								}.bind(window));
							});
						}.bind(this),
						onException: function(instance, exception){
							Modalbox.hide();
							throw('Modalbox Loading Error: ' + exception);
						}
					});
					
			} else if (typeof this.content == 'object') {// HTML Object is given
				this._insertContent(this.content);
				this._putContent();
			} else {
				Modalbox.hide();
				throw('Modalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)');
			}
		}
	},
	
	_insertContent: function(content){
		$(this.MBcontent).hide().update("");
		if(typeof content == 'string') {
			setTimeout(function() { // Hack to disable content flickering in Firefox
				this.MBcontent.update(content);
			}.bind(this), 1);
		} else if (typeof content == 'object') { // HTML Object is given
			var _htmlObj = content.cloneNode(true); // If node already a part of DOM we'll clone it
			// If clonable element has ID attribute defined, modifying it to prevent duplicates
			if(content.id) content.id = "MB_" + content.id;
			/* Add prefix for IDs on all elements inside the DOM node */
			$(content).select('*[id]').each(function(el){ el.id = "MB_" + el.id; });
			this.MBcontent.appendChild(_htmlObj);
			this.MBcontent.down().show(); // Toggle visibility for hidden nodes
			if(Prototype.Browser.IE) // Toggling back visibility for hidden selects in IE
				$$("#MB_content select").invoke('setStyle', {'visibility': ''});
		}
	},
	
	_putContent: function(callback){
		// Prepare and resize modal box for content
		if(this.options.height == this._options.height) {
			setTimeout(function() { // MSIE sometimes doesn't display content correctly
				Modalbox.resize(0, $(this.MBcontent).getHeight() - $(this.MBwindow).getHeight() + $(this.MBheader).getHeight(), {
					afterResize: function(){
						this.MBcontent.show().makePositioned();
						this.focusableElements = this._findFocusableElements();
						this._setFocus(); // Setting focus on first 'focusable' element in content (input, select, textarea, link or button)
						setTimeout(function(){ // MSIE fix
							if(callback != undefined)
								callback(); // Executing internal JS from loaded content
							this.event("afterLoad"); // Passing callback
						}.bind(this),1);
					}.bind(this)
				});
			}.bind(this), 1);
		} else { // Height is defined. Creating a scrollable window
			this._setWidth();
			this.MBcontent.setStyle({overflow: 'auto', height: $(this.MBwindow).getHeight() - $(this.MBheader).getHeight() - 13 + 'px'});
			this.MBcontent.show();
			this.focusableElements = this._findFocusableElements();
			this._setFocus(); // Setting focus on first 'focusable' element in content (input, select, textarea, link or button)
			setTimeout(function(){ // MSIE fix
				if(callback != undefined)
					callback(); // Executing internal JS from loaded content
				this.event("afterLoad"); // Passing callback
			}.bind(this),1);
		}
	},
	
	activate: function(options){
		this.setOptions(options);
		this.active = true;
		$(this.MBclose).observe("click", this.hideObserver);
		if(this.options.overlayClose)
			$(this.MBoverlay).observe("click", this.hideObserver);
		$(this.MBclose).show();
		if(this.options.transitions && this.options.inactiveFade)
			new Effect.Appear(this.MBwindow, {duration: this.options.slideUpDuration});
	},
	
	deactivate: function(options) {
		this.setOptions(options);
		this.active = false;
		$(this.MBclose).stopObserving("click", this.hideObserver);
		if(this.options.overlayClose)
			$(this.MBoverlay).stopObserving("click", this.hideObserver);
		$(this.MBclose).hide();
		if(this.options.transitions && this.options.inactiveFade)
			new Effect.Fade(this.MBwindow, {duration: this.options.slideUpDuration, to: .75});
	},
	
	_initObservers: function(){
		$(this.MBclose).observe("click", this.hideObserver);
		if(this.options.overlayClose)
			$(this.MBoverlay).observe("click", this.hideObserver);
		if(Prototype.Browser.IE)
			Event.observe(document, "keydown", this.kbdObserver);
		else
			Event.observe(document, "keypress", this.kbdObserver);
	},
	
	_removeObservers: function(){
		$(this.MBclose).stopObserving("click", this.hideObserver);
		if(this.options.overlayClose)
			$(this.MBoverlay).stopObserving("click", this.hideObserver);
		if(Prototype.Browser.IE)
			Event.stopObserving(document, "keydown", this.kbdObserver);
		else
			Event.stopObserving(document, "keypress", this.kbdObserver);
	},
	
	_loadAfterResize: function() {
		this._setWidth();
		this._setPosition();
		this.loadContent();
	},
	
	_setFocus: function() { 
		/* Setting focus to the first 'focusable' element which is one with tabindex = 1 or the first in the form loaded. */
		if(this.focusableElements.length > 0 && this.options.autoFocusing == true) {
			var firstEl = this.focusableElements.find(function (el){
				return el.tabIndex == 1;
			}) || this.focusableElements.first();
			this.currFocused = this.focusableElements.toArray().indexOf(firstEl);
			firstEl.focus(); // Focus on first focusable element except close button
		} else if($(this.MBclose).visible())
			$(this.MBclose).focus(); // If no focusable elements exist focus on close button
	},
	
	_findFocusableElements: function(){ // Collect form elements or links from MB content
		this.MBcontent.select('input:not([type~=hidden]), select, textarea, button, a[href]').invoke('addClassName', 'MB_focusable');
		return this.MBcontent.select('.MB_focusable');
	},
	
	_kbdHandler: function(event) {
		var node = event.element();
		switch(event.keyCode) {
			case Event.KEY_TAB:
				event.stop();
				
				/* Switching currFocused to the element which was focused by mouse instead of TAB-key. Fix for #134 */ 
				if(node != this.focusableElements[this.currFocused])
					this.currFocused = this.focusableElements.toArray().indexOf(node);
				
				if(!event.shiftKey) { //Focusing in direct order
					if(this.currFocused == this.focusableElements.length - 1) {
						this.focusableElements.first().focus();
						this.currFocused = 0;
					} else {
						this.currFocused++;
						this.focusableElements[this.currFocused].focus();
					}
				} else { // Shift key is pressed. Focusing in reverse order
					if(this.currFocused == 0) {
						this.focusableElements.last().focus();
						this.currFocused = this.focusableElements.length - 1;
					} else {
						this.currFocused--;
						this.focusableElements[this.currFocused].focus();
					}
				}
				break;			
			case Event.KEY_ESC:
				if(this.active) this._hide(event);
				break;
			case 32:
				this._preventScroll(event);
				break;
			case 0: // For Gecko browsers compatibility
				if(event.which == 32) this._preventScroll(event);
				break;
			case Event.KEY_UP:
			case Event.KEY_DOWN:
			case Event.KEY_PAGEDOWN:
			case Event.KEY_PAGEUP:
			case Event.KEY_HOME:
			case Event.KEY_END:
				// Safari operates in slightly different way. This realization is still buggy in Safari.
				if(Prototype.Browser.WebKit && !["textarea", "select"].include(node.tagName.toLowerCase()))
					event.stop();
				else if( (node.tagName.toLowerCase() == "input" && ["submit", "button"].include(node.type)) || (node.tagName.toLowerCase() == "a") )
					event.stop();
				break;
		}
	},
	
	_preventScroll: function(event) { // Disabling scrolling by "space" key
		if(!["input", "textarea", "select", "button"].include(event.element().tagName.toLowerCase())) 
			event.stop();
	},
	
	_deinit: function()
	{	
		this._removeObservers();
		Event.stopObserving(window, "resize", this._setWidthAndPosition );
		if(this.options.transitions) {
			Effect.toggle(this.MBoverlay, 'appear', {duration: this.options.overlayDuration, afterFinish: this._removeElements.bind(this) });
		} else {
			this.MBoverlay.hide();
			this._removeElements();
		}
		$(this.MBcontent).setStyle({overflow: '', height: ''});
	},
	
	_removeElements: function () {
		$(this.MBoverlay).remove();
		$(this.MBwindow).remove();
		if(Prototype.Browser.IE && !navigator.appVersion.match(/\b7.0\b/)) {
			this._prepareIE("", ""); // If set to auto MSIE will show horizontal scrolling
			window.scrollTo(this.initScrollX, this.initScrollY);
		}
		
		/* Replacing prefixes 'MB_' in IDs for the original content */
		if(typeof this.content == 'object') {
			if(this.content.id && this.content.id.match(/MB_/)) {
				this.content.id = this.content.id.replace(/MB_/, "");
			}
			this.content.select('*[id]').each(function(el){ el.id = el.id.replace(/MB_/, ""); });
		}
		/* Initialized will be set to false */
		this.initialized = false;
		this.event("afterHide"); // Passing afterHide callback
		this.setOptions(this._options); //Settings options object into intial state
	},
	
	_setWidth: function () { //Set size
	
		$(this.MBwindow).setStyle({width: this.options.width + "px", height: this.options.height + "px"});
	},
	
	_setPosition: function () {
		$(this.MBwindow).setStyle({left: Math.round((Element.getWidth(document.body) - Element.getWidth(this.MBwindow)) / 2 ) + "px"});
	},
	
	_setWidthAndPosition: function () {
		$(this.MBwindow).setStyle({width: this.options.width + "px"});
		this._setPosition();
	},
	
	_getScrollTop: function () { //From: http://www.quirksmode.org/js/doctypes.html
		var theTop;
		if (document.documentElement && document.documentElement.scrollTop)
			theTop = document.documentElement.scrollTop;
		else if (document.body)
			theTop = document.body.scrollTop;
		return theTop;
	},
	_prepareIE: function(height, overflow){
		$$('html, body').invoke('setStyle', {width: height, height: height, overflow: overflow}); // IE requires width and height set to 100% and overflow hidden
		$$("select").invoke('setStyle', {'visibility': overflow}); // Toggle visibility for all selects in the common document
	},
	event: function(eventName) {
		if(this.options[eventName]) {
			var returnValue = this.options[eventName](); // Executing callback
			this.options[eventName] = null; // Removing callback after execution
			if(returnValue != undefined) 
				return returnValue;
			else 
				return true;
		}
		return true;
	}
};

Object.extend(Modalbox, Modalbox.Methods);

if(Modalbox.overrideAlert) window.alert = Modalbox.alert;

Effect.ScaleBy = Class.create();
Object.extend(Object.extend(Effect.ScaleBy.prototype, Effect.Base.prototype), {
  initialize: function(element, byWidth, byHeight, options) {
    this.element = $(element)
    var options = Object.extend({
	  scaleFromTop: true,
      scaleMode: 'box',        // 'box' or 'contents' or {} with provided values
      scaleByWidth: byWidth,
	  scaleByHeight: byHeight
    }, arguments[3] || {});
    this.start(options);
  },
  setup: function() {
    this.elementPositioning = this.element.getStyle('position');
      
    this.originalTop  = this.element.offsetTop;
    this.originalLeft = this.element.offsetLeft;
	
    this.dims = null;
    if(this.options.scaleMode=='box')
      this.dims = [this.element.offsetHeight, this.element.offsetWidth];
	 if(/^content/.test(this.options.scaleMode))
      this.dims = [this.element.scrollHeight, this.element.scrollWidth];
    if(!this.dims)
      this.dims = [this.options.scaleMode.originalHeight,
                   this.options.scaleMode.originalWidth];
	  
	this.deltaY = this.options.scaleByHeight;
	this.deltaX = this.options.scaleByWidth;
  },
  update: function(position) {
    var currentHeight = this.dims[0] + (this.deltaY * position);
	var currentWidth = this.dims[1] + (this.deltaX * position);
	
	currentHeight = (currentHeight > 0) ? currentHeight : 0;
	currentWidth = (currentWidth > 0) ? currentWidth : 0;
	
    this.setDimensions(currentHeight, currentWidth);
  },

  setDimensions: function(height, width) {
    var d = {};
    d.width = width + 'px';
    d.height = height + 'px';
    
	var topd  = Math.round((height - this.dims[0])/2);
	var leftd = Math.round((width  - this.dims[1])/2);
	if(this.elementPositioning == 'absolute' || this.elementPositioning == 'fixed') {
		if(!this.options.scaleFromTop) d.top = this.originalTop-topd + 'px';
		d.left = this.originalLeft-leftd + 'px';
	} else {
		if(!this.options.scaleFromTop) d.top = -topd + 'px';
		d.left = -leftd + 'px';
	}
    this.element.setStyle(d);
  }
});


/*//////////////////*/

var affiche_prd = 0;
if ( document.all ){
	function blink_show()	{
		blink_tags  = document.all.tags('blink');
		blink_count = blink_tags.length;
		for ( i = 0; i < blink_count; i++ )
		{
			blink_tags[i].style.visibility = 'visible';
		}
		window.setTimeout( 'blink_hide()', 700 );

	}
	
	function blink_hide()	{
		blink_tags  = document.all.tags('blink');
		blink_count = blink_tags.length;
		for ( i = 0; i < blink_count; i++ )
		{
			blink_tags[i].style.visibility = 'hidden';
		}
		
		window.setTimeout( 'blink_show()', 250 );
	}
	//window.onload = blink_show;
}
function compteur_js()	{
		cpt_tags  = document.getElementsByTagName('compteur');
		cpt_count = cpt_tags.length;
		for ( i = 0; i < cpt_count; i++ ) {
		  temps_restant = cpt_tags[i].getAttribute('tmp');
		  if(temps_restant){
		    div = cpt_tags[i].getAttribute('idc');
		    document.getElementById(div).innerHTML = '<b>'+GetDateFormat(temps_restant)+'</b>';
        //cpt_tags[i].innerHTML = GetDateFormat(temps_restant);
        cpt_tags[i].setAttribute('tmp',temps_restant-1);
			}
		}
		
		window.setTimeout( 'compteur_js()', 1000 );
	}
	function GetDateFormat(tmprestant){
    DiffSec = tmprestant;//Math.floor((TempFuture-TempMaintenant)/1000);
    DiffMin = Math.floor(DiffSec/60);
    Diffheure = Math.floor(DiffMin/60);
    DiffJour = Math.floor(Diffheure/24);
    while (DiffMin>=60){
    	DiffMin = DiffMin-60;
    }
    while (Diffheure>=24){
    	Diffheure = Diffheure-24;
    }
    while (DiffSec>=60){
    	DiffSec = DiffSec-60;
    }
    text_rtn = ' ';
    if(DiffJour>0)
      text_rtn=text_rtn + DiffJour + 'j ';
    if(DiffJour!=0 || Diffheure>0)
      text_rtn=text_rtn + Diffheure + 'h ';
      
    return text_rtn + DiffMin + 'min ' + DiffSec + 's ';
  }
/* fonction affichage masquage */
function ShowEditRes(id){
  var elm_l = document.getElementById('res_'+id);
  var elm_e = document.getElementById('res_edit_'+id);
  
  elm_l.style.display = 'none';
  elm_e.style.display = '';
  
}
function hideId(id){
  var elm = document.getElementById(id);
  elm.style.visibility="hidden";
  elm.style.display="none";
}
function showEditEnchr(id){
  hideId('ench_norm_'+id);
  showId('ench_mod_'+id);
}
function showId(id){
  var elm = document.getElementById(id);
  elm.style.visibility="visible";
  elm.style.display="";
}
var position_img = 1;
var nb_img = 0;
function loadDataDI(pi,ni){
  position_img=pi;
  nb_img=ni;
}
var img_is_changing=false;


function deplaceImage(num){
  if(img_is_changing){ 
    return false;
  }
  
  var nb_img = document.getElementById('nb_img').value;
 
 
  if(position_img == 1 && num == -1){  

  }else if(position_img == nb_img && num == 1){

  }else{
  
    img_is_changing=true;
    var img_div = document.getElementById('img_div_'+position_img);
	if (img_div) { 
	Effect.Fade(img_div, {
      duration:0.1,
      afterFinish: function(){
		position_img = num + position_img;
        
        var img_div2 = document.getElementById('img_div_'+position_img);
        Effect.Appear(img_div2);
        //img_div2.show();
        if(position_img == 1){
          $('last_img').hide();
        }else{
          $('last_img').show();
        }
        if(position_img == nb_img){
          $('next_img').hide();
        }else{
          $('next_img').show();
        }
        img_is_changing=false;
      }
    });
	}
    
  }
  
}
var last_id = '';
var last_id2 = '';
function echangeVisibleCacheAncien(inv_id,vis_id){
  if(last_id==''){
    echangeVisible(inv_id,vis_id);
    last_id = inv_id;
    last_id2 = vis_id;
  }else{
    echangeVisible(last_id2,last_id);
    echangeVisible(inv_id,vis_id);
    last_id = inv_id;
    last_id2 = vis_id;
  }
}
function AfficheAvecEffet(vis_id){
  Effect.SlideDown (vis_id);
}
var l_id_evi = '';
function EchangeVisibleInv(id){
  var vis_id = document.getElementById(id);
  if(l_id_evi != id){
    Effect.SlideDown (vis_id);
    l_id_evi = id;
  }else{
    Effect.SlideUp (vis_id);
    l_id_evi = '';
  }
}
function echangeVisible(inv_id,vis_id){
  Effect.SlideUp(inv_id, {
      afterFinish: function(){
        Effect.SlideDown (vis_id);
      }
    });

}
/*apres l'ajout d'un produit*/
var id_produit = -1;
function produit_ajoute(ifrm){
  if(id_produit!=-1){
    var add_p = document.getElementById('addtocart_'+id_produit);
    var add_td_p = document.getElementById('addtocart_td_'+id_produit);
    add_p.innerHTML='<a href="Voir_mon_panier.html">Produit ajout&eacute;</a>';
    add_p.className = 'ProduitDansPanier';
    add_td_p.className = 'ProduitDansPanier';
    add_td_p.vAlign  = 'middle';
    add_td_p.align  = 'center';
  }
}

var compatible_ajax = true;
function UpdateBox(bx){
  if(compatible_ajax){
   /* Effect.Puff('box_'+bx, {
      afterFinish: function(){
     */ 
        new Ajax.Request('ajax.php', { 
                        method: 'post',
                        parameters: {box: bx} ,
                        onSuccess: function(transport){
                          var response = transport.responseText;
                          $('box_'+bx).innerHTML = response;
                          //Effect.Grow('box_'+bx);
                        }
        });
      /*}
    }
    );*/
    }
}
function AddEnchere(id){
  $('addtocart_form_'+id).action.value='addenchajax';
  if(compatible_ajax)
    new Ajax.Request('enchere.html', { 
      method:'post',
      parameters: $('addtocart_form_'+id).serialize(true),
      onSuccess: function(transport){
        var response = transport.responseText;
          if($('addtocart2_td_'+id))
            $('addtocart2_'+id).innerHTML = response;
          //if($('addtocart_td_'+id))
            $('addtocart_'+id).innerHTML = response;
          if($('addtocart2_td_'+id))
            new Effect.Shake('addtocart2_'+id);
          else
            new Effect.Shake('addtocart_'+id);
      },
      onFailure: function(){
        compatible_ajax = false;
        $('addtocart_form_'+id).submit();
      }
    });
  if(compatible_ajax)
    return false;
  else
    return true;
}
function AddToCart(id){
  $('addtocart_form_'+id).action.value='addcartajax';
  if(compatible_ajax)
    new Ajax.Request('ajax.php', { 
      method:'post',
      parameters: $('addtocart_form_'+id).serialize(true),
      onSuccess: function(transport){
        var response = transport.responseText;
        switch(response.substr(0,1)){
          case '0':
            if($('addtocart_td_'+id)){
              $('addtocart_td_'+id).className = "ProduitDansPanier";
              $('addtocart_td_'+id).vAlign = "top";
              $('addtocart_td_'+id).align = "center";
            }
            if($('addtocart2_td_'+id)){
              $('addtocart2_td_'+id).className = "ProduitDansPanier";
              $('addtocart2_td_'+id).vAlign = "middle";
              $('addtocart2_td_'+id).align = "center";
            }
          break;
          case '1':
            if($('addtocart_td_'+id)){
              $('addtocart_td_'+id).className = "ProduitEnRupture";
              $('addtocart_td_'+id).vAlign = "middle";
              $('addtocart_td_'+id).align = "center";
            }
            if($('addtocart2_td_'+id)){
              $('addtocart2_td_'+id).className = "ProduitEnRupture";
              $('addtocart2_td_'+id).vAlign = "middle";
              $('addtocart2_td_'+id).align = "center";
            }
          break;
        }
        if($('addtocart2_td_'+id))
          $('addtocart2_'+id).innerHTML = response.substr(1,response.length-1);
        if($('addtocart_td_'+id))
          $('addtocart_'+id).innerHTML = response.substr(1,response.length-1);
        if($('addtocart2_td_'+id))
          new Effect.Shake('addtocart2_'+id);
        else
          new Effect.Shake('addtocart_'+id);
        //box_panier
        UpdateBox('panier');
      },
      onFailure: function(){
        compatible_ajax = false;
        $('addtocart_form_'+id).submit();
      }
    });
  if(compatible_ajax)
    return false;
  else
    return true;
}
function AddToRes(id){
  if(compatible_ajax){
    $('addtocart_form_'+id).ajax.value='1';
    new Ajax.Request('reservation.html', { 
      method:'post',
      parameters: $('addtocart_form_'+id).serialize(true),
      onSuccess: function(transport){
        var response = transport.responseText;
        if($('addtocart_td_'+id)){
          $('addtocart_td_'+id).className = "ProduitaReserve";
          $('addtocart_td_'+id).vAlign = "top";
          $('addtocart_td_'+id).align = "center";
        }
        if($('addtocart2_td_'+id)){
          $('addtocart2_td_'+id).className = "ProduitaReserve";
          $('addtocart2_td_'+id).vAlign = "top";
          $('addtocart2_td_'+id).align = "center";
        }
        if($('addtocart2_td_'+id))
          $('addtocart2_'+id).innerHTML = response;
        if($('addtocart_td_'+id))
          $('addtocart_'+id).innerHTML = response;
        if($('addtocart2_td_'+id))
          new Effect.Shake('addtocart2_'+id);
        else
          new Effect.Shake('addtocart_'+id);
        //box_panier
        //UpdateBox('panier');
      },
      onFailure: function(){
        compatible_ajax = false;
        $('addtocart_form_'+id).submit();
      }
    });
  }
  if(compatible_ajax)
    return false;
  else
    return true;
}
/* fonctions qui verifie les input */
function check_input(elm,formulaire){
  switch(formulaire){
    case 0: //inscription
      var elm_msg = document.getElementById('check_'+elm.id);
      var animate = false;
      switch(elm.id){
        case 'code':
          var elm_vcode = document.getElementById('vcode');
          var elm_msgv = document.getElementById('check_v'+elm.id);
          if(elm_vcode.value != '' && (elm.value != elm_vcode.value || elm.value.length < 6) ){
            elm_msgv.innerHTML = '<img src="template/images/ierr.png" width="20" />';
            animate = true;
          }else if(elm_vcode.value != ''){
            animate = true;
            elm_msgv.innerHTML = '<img src="template/images/iok.png" width="20" />';
          }
          if(elm.value.length<6){
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/ierr.png" width="20" />';
          }else{
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/iok.png" width="20" />';
          }
        break;
        case 'vcode':
          var elm_code = document.getElementById('code');
          var elm_vcode = document.getElementById('vcode');
          //alert(elm_vcode.value+' ;;; '+elm_code.value);
          if(elm_vcode.value.length<6 || elm_vcode.value != elm_code.value){
            animate = false;
            //elm_msg.innerHTML = '<img src="template/images/ierr.png" width="20" />';
          }else{
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/iok.png" width="20" />';
          }
        break;
        case 'email':
          var at_ = elm.value.indexOf("@",1);
          var dot_ = elm.value.indexOf(".",at_ + 2);
          if(elm.value.length <= 6 || at_ == -1 || dot_ < 2 || dot_ == elm.value.length - 1){
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/ierr.png" width="20" />';
          }else{
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/iok.png" width="20" />';
          }
        break;
        case 'f_complement':
        case 'tel':
        case 'complement':
        break;
        default: 
          if(elm.value==''){
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/ierr.png" width="20" />';
          }else{
            animate = true;
            elm_msg.innerHTML = '<img src="template/images/iok.png" width="20" />';
          }
        break;
      }
      if(animate){
        var myEffect = new Effect.Opacity(elm_msg, { 
          duration: 2.0,
          transition: Effect.Transitions.pulse,
          from: 0, 
          to: 1
        });
      }
    break;
  }
}

/* fonction d'effacement */
function effaceSi(obj,texte_origine){
  if(obj.value == texte_origine)
    obj.value = '';
}

/* fonction d'ajout */
function ajouteSi(obj,texte_origine){
  if(obj.value == '')
    obj.value = texte_origine;
}

/* fonction a lancer apres le chargement */
function chargement_fini(){
  if ( document.all ){
    blink_show();
  }
  compteur_js();
  if(affiche_prd!=0){
    Modalbox.show('produit-p-'+affiche_prd+'.html?MB', {title: 'Votre sélection', width: mb_width, height: mb_height});
  }
}


function show_hide(element) {
    if(document.getElementById(element).style.display=='none') {
        $(element).appear();
        return false;
    }else {
        $(element).fade();
        return false;
    }
}


/* rend invisible un element par son id */
function AfficheId(id){
  var elm = document.getElementById(id);
  elm.style.visibility = "visible";
  elm.style.display = "";
}
Position.GetWindowSize = function(w) {
	var width, height;
        w = w ? w : window;
        this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        
        return this;
}
var dim = Position.GetWindowSize();
var mb_width;
var mb_height;
var mb_height_cnt;

function resizetheMb(){
  dim = Position.GetWindowSize();
  mb_width = dim.width-30;
  if(mb_width>1050)
    mb_width=1050;
  mb_height = dim.height-10;
  mb_height_cnt = mb_height-100;
}
resizetheMb();




/////////////////////////



/**
 * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formarly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
if(!document.createElement||!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){
_16.push(key+"="+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
_19+="/>";
}else{
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(_23,_24){
var _25=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_25=new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{
var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
for(var i=3;axo!=null;i++){
axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
_25=new deconcept.PlayerVersion([i,0,0]);}}
catch(e){}
if(_23&&_25.major>_23.major){return _25;}
if(!_23||((_23.minor!=0||_23.rev!=0)&&_25.major==_23.major)||_25.major!=6||_24){
try{_25=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
catch(e){}}}
return _25;};
deconcept.PlayerVersion=function(_29){
this.major=parseInt(_29[0])!=null?parseInt(_29[0]):0;
this.minor=parseInt(_29[1])||0;
this.rev=parseInt(_29[2])||0;};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};
deconcept.util={getRequestParameter:function(_2b){
var q=document.location.search||document.location.hash;
if(q){
var _2d=q.indexOf(_2b+"=");
var _2e=(q.indexOf("&",_2d)>-1)?q.indexOf("&",_2d):q.length;
if(q.length>1&&_2d>-1){
return q.substring(q.indexOf("=",_2d)+1,_2e);
}}return "";}};
if(Array.prototype.push==null){
Array.prototype.push=function(_2f){
this[this.length]=_2f;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for backwards compatibility
var SWFObject=deconcept.SWFObject;



