﻿if(typeof LOC == 'undefined') {
	var LOC = {};
}
LOC.gRub = 1;
//modif variables pour loading AJAX
ajaxLoading = '<div class="ajaxLoad"><p><img src="/_en/_us/html/careers/Img/common/ajax-loader.gif" /><br/>Loading...</p></div>';
ajaxError = '<div class="ajaxLoad"><p><img src="/_en/_us/html/careers/Img/common/ajax-error.gif" /><br/>Error loading datas...<br/><a href="http://www.loreal.com/_en/_ww/careers/index.aspx?https://mycareer.loreal.com/candidate/searchjobresults.asp?l=15" target="_blank">See all the openings</a></p></div></div>';
//sous-welcome rollovers
LOC.ssWelcomeRoll = function(){
	if(document.getElementById("sswelcome")){
		var sswelclinks = document.getElementById("sswelcome").getElementsByTagName("a");
		var contentStyle = document.getElementById("content").className;
		for(var i=0; i<sswelclinks.length; i++){
			var lien = sswelclinks[i];
			lien.contentStyle = contentStyle;
			lien.onmouseover = function(){
				this.parentNode.className = "lion";
				document.getElementById("content").className = this.id;
				//document.getElementById("rollingBckg").src = "/_en/_us/html/careers/Img/backgrounds/" + this.id + ".jpg";
				//alert("this.id = " + this.id);
			}
			lien.onmouseout = function(){
				this.parentNode.className = "";
				//document.getElementById("content").className = this.contentStyle;
				//document.getElementById("rollingBckg").src = "/_en/_us/html/common/Img/dot.gif";
			}
		}
	}
}
//actions profiles
LOC.initProfiles = function(){
	if(document.getElementById("profileCombo")){
		var profileTomb_arr = document.getElementById("profileCombo").getElementsByTagName("li");
		for(var i=0; i<profileTomb_arr.length; i++){
			var profileTomb = profileTomb_arr[i].getElementsByTagName("a")[0];
			profileTomb.onclick = function(){
				var curhurle = top.location.href;
				var niouhurle = "";
				if(curhurle.indexOf("profile=") >= 0){
					var curProfile = curhurle.substring(curhurle.indexOf("profile="));
					if(curProfile.indexOf("&") >= 0) curProfile = curProfile.substring(0, curProfile.indexOf("&"));
				}
				if(curhurle.indexOf("profileExcl=") >= 0){
					var curProfileExcl = curhurle.substring(curhurle.indexOf("profileExcl="));
					if(curProfileExcl.indexOf("&") >= 0) curProfileExcl = curProfileExcl.substring(0, curProfileExcl.indexOf("&"));
				}
				var niouProfile = this.id.replace("profile_", "");
				if(niouProfile == ""){
					var niouProfileExcl = "";
				}
				else if (niouProfile == "senior"){
					var niouProfileExcl = "student";
				}
				else{
					var niouProfileExcl = "nostudent";
				}
				if(curhurle.indexOf("profile=") >= 0){
					niouhurle = curhurle.replace(curProfile, "profile=" + niouProfile);
				}
				else{
					niouhurle = curhurle + "&profile=" + niouProfile;
				}
				if(curhurle.indexOf("profileExcl=") >= 0){
					niouhurle = niouhurle.replace(curProfileExcl, "profileExcl=" + niouProfileExcl);
				}
				else{
					niouhurle = niouhurle + "&profileExcl=" + niouProfileExcl;
				}
				if(niouhurle.indexOf(".aspx?")<0){
					niouhurle = niouhurle.replace(".aspx", ".aspx?");
				}
				
				//gestion cas particulier nouveau profil n'a pas accès à la page en cours
				// => on renvoie sur la welcome careers avec le nouveau profil
				if(LOC.pageProfile == niouProfileExcl && niouProfileExcl != ""){
					//récupération URL welcome rubrique careers dans #secondaryNav (cause problème URL rewritting !)
					var secondaryNavLink = document.getElementById("secondaryNav").getElementsByTagName("li")[0].getElementsByTagName("a")[0].href;
					if(secondaryNavLink.indexOf("profile=") >= 0){
						var curProfile = secondaryNavLink.substring(secondaryNavLink.indexOf("profile="));
						if(curProfile.indexOf("&") >= 0) curProfile = curProfile.substring(0, curProfile.indexOf("&"));
					}
					if(secondaryNavLink.indexOf("profileExcl=") >= 0){
						var curProfileExcl = secondaryNavLink.substring(secondaryNavLink.indexOf("profileExcl="));
						if(curProfileExcl.indexOf("&") >= 0) curProfileExcl = curProfileExcl.substring(0, curProfileExcl.indexOf("&"));
					}
					var niouhurle = secondaryNavLink;//.substring(0, secondaryNavLink.indexOf("?"));
					if(niouhurle.indexOf("profile=") >= 0){
						niouhurle = niouhurle.replace(curProfile, "profile=" + niouProfile);
					}
					else{
						niouhurle = niouhurle + "&profile=" + niouProfile;
					}
					if(niouhurle.indexOf("profileExcl=") >= 0){
						niouhurle = niouhurle.replace(curProfileExcl, "profileExcl=" + niouProfileExcl);
					}
					else{
						niouhurle = niouhurle + "&profileExcl=" + niouProfileExcl;
					}
					//niouhurle = niouhurle + "&profile=" + niouProfile + "&profileExcl=" + niouProfileExcl;
					//alert("profil incompatible avec page en cours, renvoi vers welcome, niouhurle = " + niouhurle);
				}
				top.location.href = niouhurle;
				return false;
			}
		}
	}
}
//pushes offres
LOC.initPushOffers = function(){
	if(document.getElementById("pushOffers")){
		/*
		//on ne fait rien pour le site US, c'est le message générique en dur dans la sharedWebbox /webbbox/includes/careersPushes.html qui est affiché
		//on récupère le profil dans les var déclarées dans la façade facade_disability_careers.html
		var pouche = LOC.curPush;
		var cure = LOC.cur;
		var spec;
		if(pouche.indexOf("3_careersJobs") >= 0 ){
			spec = LOC.curSsMenu;
		}
		else{
			if(top.location.search.indexOf("profile=") >= 0){
				spec = LOC.profile;
			}
			else{
				spec = "";
			}
		}
		//alert("spec = " + spec);
		//LOC.makeRequest('/_en/_us/html/careers/offers/offers_'+spec+'.aspx', 'pushOffers', 'HTML', true, true);
		//ajax cross-domain with flash
		
		var hurle = "http://www.loreal.com/_en/_ww/html/careers/offers/offers_"+spec+".aspx";
		var fo = new FlashObject("/_en/_us/html/careers/offers/offersCrossDomain.swf?hurle="+hurle, "anim", "1", "1", "8", "#FFFFFF");
		fo.addParam("wmode", "transparent");
		fo.addParam("scale", "noscale");
		fo.addParam("allowScriptAccess", "always");
		//setTimeout('fo.write("ajaxOffers")', 5000);
		fo.write("ajaxOffers");
		document.getElementById('pushOffers').innerHTML = ajaxLoading;
		*/
	}
}
//ajax cross-domain with flash
LOC.displayOffers = function(datas){
	//alert("datas: " + datas);
	if(datas == null) datas = ajaxError;
	document.getElementById('pushOffers').innerHTML = datas;
	document.getElementById('pushOffers').style.display = "block";
	document.getElementById('pushOffers').focus();
}
//focus par tabulation
LOC.initFocusTab = function(){
	var eltsbold = ["sswelcome"];
	for(var i=0; i<eltsbold.length; i++){
		if(document.getElementById(eltsbold[i])){
			elt = document.getElementById(eltsbold[i]);
			//alert("elt " + eltsbold[i] + " = " + elt)
			var eltsa = elt.getElementsByTagName("a");
			for(var u=0; u<eltsa.length; u++){
				var elta = eltsa[u];
				//alert("elta = " + elta);
				elta.onfocus = function(){
					this.onmouseover();
					this.style.color = "#FFFFFF";
				}
				elta.onblur = function(){
					this.onmouseout();
					this.style.color = "#00A2DD";
				}
			}
		}
	}
	var eltscoul = ["thirdNav", "fourthNav", "fifthNav"];
	for(var i=0; i<eltscoul.length; i++){
		if(document.getElementById(eltscoul[i])){
			elt = document.getElementById(eltscoul[i]);
			//alert("elt " + eltsbold[i] + " = " + elt)
			var eltsa = elt.getElementsByTagName("a");
			for(var u=0; u<eltsa.length; u++){
				var elta = eltsa[u];
				//alert("elta = " + elta);
				elta.onfocus = function(){
					this.style.color = "#660033";
				}
				elta.onblur = function(){
					if(this.className.indexOf("selected")<0) this.style.color = "#666666";
				}
			}
		}
	}
}
addDOMLoadEvent(function(){
	//menu déroulant profils
	//if(document.getElementById("content").className != "welcome") LOC.showLists.init("profileCombo");//si menu différent sur la welcome
	LOC.showLists.init("profileCombo");
	//rollovers sswelcome
	LOC.ssWelcomeRoll();
	//actions profile
	LOC.initProfiles();
	//pushes offres
	LOC.initPushOffers();
	//focus par tabulation
	LOC.initFocusTab();
});
