﻿if(typeof LOC == 'undefined') {
	var LOC = {};
}
//variables globales
var gSite = "/_en/_us/";
LOC.gSite = "/_en/_us/"; //pour construire les chemins
LOC.IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
LOC.IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
LOC.gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
LOC.isMSIE = /*@cc_on!@*/false;
//array pour stocker les objets menu composant les menus de la mainNav
var navtopmenu_arr = new Array();
//array pour stocker les objets menu composant les menus la secondaryNav
var navdroitemenu_arr = new Array();
//array pour stocker les objets ssmenu composant les menus la secondaryNav
var navdroitessmenu_arr = new Array();
//indices rub, ssrub et ssSsRub
var gRub, gSsRub, gSsSsRub;
LOC.gRub = "";
LOC.gSsRub = "";
LOC.gSsSsRub = "";
//DETEC TAILLE ECRAN
detec = function(){
	//init des width et height de la fenêtre document.body.clientHeight
	initW = (window.innerWidth) ? window.innerWidth : (document.documentElement.clientWidth)?document.documentElement.clientWidth:document.body.clientWidth;
	initH = (window.innerHeight) ? window.innerHeight : (document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight;
}


//AJAX
var ajaxLoading = "<div class='ajaxLoad'><div class='message'><img src='/_en/_us/html/common/Img/ajax-loader.gif' /> <p>loading...</p></div></div>";
var ajaxError = "<div class='ajaxLoad'><img src='/_en/_us/html/common/Img/ajax-error.gif' /> <p>Error...</p></div></div>";
LOC.makeRequest = function (hurle, container, typ, js, loading, callback) {
	//affichage loading
	if(document.getElementById(container)){
		if(loading){
			document.getElementById(container).innerHTML = ajaxLoading;
		}
	}
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
		    if (typ == "XML") http_request.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) { // IE
		try {
		    http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		    try {
		        http_request = new ActiveXObject("Microsoft.XMLHTTP");
		    } catch (e) {}
		}
	}
	if (!http_request) {
		alert(ajaxNot);
		return false;
	}
	http_request.onreadystatechange = function() {
	//alert("onreadystatechange(), http_request.readyState = " + http_request.readyState);
		if (http_request.readyState == 4) {
		//alert("http_request.responseText = " + http_request.responseText);
		//alert("typ = " + typ);
			if (typ.toUpperCase() == "XML"){
				parseContent(http_request, container);
			}		
			else if(typ.toUpperCase() == "HTML"){
				//alert("http_request.responseText = " + http_request.responseText);
				LOC.afficheContents(http_request, container, js, callback, loading); 
			}
			else if(callback){
				if (http_request.status == 200) {
					args = [http_request.responseText];
					callback.apply(this, args);
				}
			}
		}
	}
	//alert("appel AJAX vers: " + hurle);
	http_request.open('GET', hurle, true);
	http_request.send('');	
}
LOC.afficheContents = function (http_request, container, js, callback, loading) {
//alert("LOC.afficheContents()! http_request.status: " + http_request.status); 
	if (http_request.status == 200) {
		document.getElementById(container).innerHTML = http_request.responseText;
		document.getElementById(container).style.display = "block";
		document.getElementById(container).focus();
		if(js){
			LOC.execScript(document.getElementById(container));
		}
		if(callback){
			callback.apply();
		}
	} 
	else {
	//alert("ajaxError: " + ajaxError);
		document.getElementById(container).innerHTML = ajaxError;
	}
}
LOC.execScript = function (obj){
	scripts_obj = obj.getElementsByTagName("script");
	for(i=0; i < scripts_obj.length; i++){
		eval(scripts_obj[i].innerHTML);
	}
}
//FIN AJAX

//AJASON CROSS-DOMAIN
function SqueereHTTP(url, instance) {
	//alert("SqueereHTTP()! url: " + url + " & instance: " + instance);
	this.loaded = false;
	this.url = url;
	this.script;
	this.firstparam = true;
	this.serverResponse;
	this.instance = instance;
	that = this;
	
	this.AddParam = function(p, v) {
		if (that.firstparam) {
			that.url += '?' + p + '=' + v;
			that.firstparam = false;
		}
		else {
			that.url += '&' + p + '=' + v;
		}
	}
	
	this.Request = function(force) {
		that.AddParam('instance', that.instance);
		if (force) {
			var axd = new Date();
			var shake = axd.getDate()+""+axd.getMonth()+1+""+axd.getFullYear()+""+axd.getHours()+""+axd.getMinutes()+""+axd.getSeconds();
			that.AddParam('squeereshaker', shake);
		}
		that.script = document.createElement('script');
		that.script.setAttribute('charset','UTF-8');
		that.script.setAttribute('type','text/javascript');
		that.script.setAttribute('src', that.url);
		that.script.onload = that.onLoad;
		that.script.onreadystatechange = that.onLoad;
		document.getElementsByTagName('head')[0].appendChild(that.script);
	}
	
	this.onComplete = function(serverResponse) { }
	
	this.onLoad = function() {
		if (that.loaded) { return; }
		that.loaded = true;
	};
	
	return this;
}
//method appel
/*
var myReq;
myReq = new SqueereHTTP('http://www.regaloeb.com/tests/offres.aspx', 'myReq');
myReq.onComplete = function(serverResponse) {
	var json = eval('(' + serverResponse + ')');
	alert("json: " + json);
}
myReq.Request(true);
*/
//FIN AJASON CROSS-DOMAIN

//ajout de class
LOC.tools = {
	hasClass: function(n, v) {
		var a = ' '+n.className+' ';
		if(a == '  ') {return false;}
		return (a.indexOf(' '+v+' ') == -1) ? false : true;
	},
	addClass: function(n, v) {
		if(this.hasClass(n, v)) {return false;}
		n.className += n.className ? ' '+v : v;
		return true;
	},
	removeClass: function(n, v) {
		if(!this.hasClass(n, v)) {return false;}
		var r = (n.className.indexOf(' '+v) != -1) ? ' '+v : v;
		n.className = n.className.replace(r, '');
		return true;
	}
}
// changer le contexte d'exécution
if(!Function.prototype.context && Function.prototype.apply) {
	Function.prototype.context = function(context) {
		var that = this;
		var args = [];
		if(arguments.length > 1) {
			for(var i = 1, arg; arg = arguments[i]; i++) {
				args[args.length] = arg;
			}
		}
		return function() {
			that.apply(context, args);
		};
	}
}
// gestion des menus déroulants javascript
LOC.showLists = {
	init: function(content){
		if(!Function.prototype.context) {return;}
		var selector = document.getElementById(content);
		if((!selector)){return;}
		var opener = selector.getElementsByTagName('a')[0];
		var list = selector.getElementsByTagName('ul')[0];
		if((!opener)||(!list)){return;}
		LOC.addListener(opener, 'click', LOC.showLists.show);
		LOC.addListener(list, 'click', LOC.showLists.hide);
	},
	show: function(e){
		var list = this.parentNode.parentNode.getElementsByTagName('ul')[0];
		LOC.tools.addClass(list, "js");
		LOC.showLists.mouseDownId = LOC.addListener(document, 'mousedown', function(e, options) {
			var t = LOC.getEventTarget(e);
			while(t.parentNode && t != list) {t = t.parentNode;}
			if(t != list) {
				LOC.showLists.hide.context(list)();
			}
		});
		return false;
	},
	hide: function(){
		LOC.tools.removeClass(this, "js");
		LOC.removeListener(document, 'mousedown', LOC.showLists.mouseDownId);
	}
}
//liens vers player video FLV
LOC.initVideo = function(){
	if(document.getElementById("page")){
		var lesLinks = document.getElementById("page").getElementsByTagName("a");
		for(var i=0; i<lesLinks.length; i++){
			var leLink = lesLinks[i];
			if(leLink.className.indexOf("vid")>=0){
				leLink.xmlFile = leLink.href.substring(leLink.href.indexOf("?video=")+7, leLink.href.length);
				leLink.page = leLink.href.substring(0, leLink.href.indexOf("?video="));
				leLink.onclick = function(){
					//alert("leLink.xmlFile = " + this.xmlFile);
					LOC.videoXMLfile = this.xmlFile;
					//LOC.makeRequest(this.page, 'ajaxvideo', 'html', true, true);
					var fo = new FlashObject('/_en/_us/html/common/player_FLV.swf', "anim", "925", "436", "8.0.0.0", "#000000");
					fo.addParam("wmode", "transparent");
					fo.addParam("scale", "noscale");
					fo.addParam("allowScriptAccess", "always");
					fo.addVariable("vxml", this.xmlFile);
					fo.write("videoplayer");
					document.getElementById("videoplayer").style.display = "block";
					document.getElementById("content").style.display = "none";
					document.getElementById("secondaryNav").style.display = "none";
					
					return false;
				}
			}
		}
	}
}
LOC.closeVideo = function(){
	document.getElementById("videoplayer").innerHTML = "";
	document.getElementById("videoplayer").style.display = "none";
	document.getElementById("content").style.display = "block";
	document.getElementById("secondaryNav").style.display = "block";
}
//onload events videos links
addEvent(window, "load", LOC.initVideo);

// corrige les PNGs sur IE5.5 et IE6
LOC.fixPNG = function(){
	// test IE
	if(document.all != null && window.opera == null){
		// test IE 6
		if(window.XMLHttpRequest == null && document.implementation != null && document.compatMode != null){
			// recuperation des images
			var imgs = document.getElementsByTagName('img');
			for(var i = 0, img; img = imgs[i]; i++){
				if(/png$/i.test(img.src)){
					var src = img.src;
					img.src = '/_en/_us/html/common/Img/dot.gif';
					img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='image');";
				}
			}
		}
	}
}
//domloadevent FixPng
if(LOC.IE6) addDOMLoadEvent(LOC.fixPNG);
//pour transformer les caractères spéciaux en code compatible html
LOC.htmlEncode = function(source){
	var result = '';
	for (var i = 0; i < source.length; i++){
		var c = source.charAt(i);
		if (c < ' ' || c > '~'){
			c = '&#' + c.charCodeAt() + ';';
		}
		result += c;
	}
	return result;
}
//pour détecter la présence d'un screenReader actif
//un SWF /html/common/detcScreenReaders.swf appelle cette fonction après détection (val)
//ce SWF est embeddé dans /webbox/includes/bottomNav.html
LOC.screenReaderActif = false;
LOC.isScreenReaderActif = function(val){
	LOC.screenReaderActif = val;
}