﻿// gestion de l'intitulé de message d'erreur utilisé dans la validation
// des formulaires
var formErrorTitle = new Array();
formErrorTitle["fr_FR"] = "Les champs suivants sont incomplets ou contiennent des erreurs";
formErrorTitle["en_US"] = "The following fields are missing or incomplete";
formErrorTitle["en_GB"] = "The following fields are missing or incomplete";
formErrorTitle["zh_CN"] = "The following fields are missing or incomplete";
formErrorTitle["ko_KR"] = "The following fields are missing or incomplete";
formErrorTitle["es_ES"] = "The following fields are missing or incomplete";
formErrorTitle["ja_JP"] = "The following fields are missing or incomplete";
formErrorTitle["de_DE"] = "The following fields are missing or incomplete";
formErrorTitle["el_GR"] = "The following fields are missing or incomplete";

// substitution de la police contenue dans les h1
Cufon.replace('h1, .splashTitle');

/******************************************************************************************************/
/** INITIALISATION DECLENCHEE SUR CHACUNE DES PAGES
/******************************************************************************************************/
$(document).ready(function()
{
	// menu deroulant principal
	$('#navigation').droppy();

	// panel de sélection des langues
	$(".showPanel").click(function()
	{
		$("#regionLanguageWrapper").slideToggle("normal");
		$(this).toggleClass("hidePanel"); return false;
	});
	$("#regionLanguageContainer").tabs({ fx: { opacity: "toggle" }, cookie: { name: "olea_region", path: "/" } }).tabs;

	// smooth scroll sur le lien "back to top"
	$.smoothAnchors("normal", "swing", false);


	// HOMEPAGE
	if (pageName == "homepage")
	{
		$('ul#newsTicker').innerFade(
		{
			animationtype: 'fade',
			speed: 800,
			timeout: 3000,
			type: 'sequence',
			containerheight: '100%'
		});
		$('ul#splash').innerFade(
		{
			speed: 800,
			timeout: 9000,
			type: 'sequence',
			containerheight: '285px'
		});
	}
	// ENVIRONMENT
	if (pageName == "environment")
	{
		$('ul#splash').innerFade(
		{
			speed: 400,
			timeout: 6000,
			containerheight: '285px',
			indexContainer: '#previewsIndex'
		});
	}
	// CAREERS
	if (pageName == "join-us")
	{
		$('ul#splash').innerFade(
		{
			speed: 400,
			timeout: 6000,
			containerheight: '285px',
			indexContainer: '#previewsIndex'
		});
	}
	
	
	
	// CUSTOMER SUPPORT
	if (pageName == "support")
	{
		jQuery().ready(function(){
		var wizard = $("#wizardFormWrapper").accordion({
		header: '.wizardPanelTitle',
		event: false
		});
 		var wizardButtons = $([]);
		$("div.wizardPanelTitle", wizard).each(function(index) {
		wizardButtons = wizardButtons.add($(this)
		.next()
		.children(":button")
		.filter(".nextPanelButton, .previousPanelButton")
		.click(function() {
		wizard.accordion("activate", index + ($(this).is(".nextPanelButton") ? 1 : -1))
		}));
		});
 		// bind to change event of select to control first and seconds accordion
		// similar to tab's plugin triggerTab(), without an extra method
		var accordions = jQuery('#wizardFormWrapper');
	 	jQuery('#switch select').change(function() {
		accordions.accordion("activate", this.selectedIndex-1 );
		});
		jQuery('#close').click(function() {
		accordions.accordion("activate", -1);
		});
		jQuery('#switch2').change(function() {
		accordions.accordion("activate", this.value);
		});
		jQuery('#enable').click(function() {
		accordions.accordion("enable");
		});
		jQuery('#disable').click(function() {
		accordions.accordion("disable");
		});
		jQuery('#remove').click(function() {
		accordions.accordion("destroy");
		wizardButtons.unbind("click");
		});
		});

	}
	
	
	

	// CONTACT + CAREERS (gestion du formulaire)
	if (pageName == "contact" || pageName == "join-us" || pageName == "support")
	{
		var userForm = document.getElementById("userForm");

		// recuperation des libelles de champs obligatoires
		// => permet de faire varier le message d'erreur en fonction de la langue courante
		var mLabels = new Array();
		var index = 0;
		$('span.dataName', userForm).each(function(i)
		{
			var html = $(this).html();
			var text = $(this).text();
			if (html.indexOf("colorRed") != -1)
			{
				text = text.replace("*", "");
				mLabels[index++] = text;
			}
		});

		// affectation d'un evenement a la validation des formulaires des pages "contact", "career" et "support"
		userForm.onsubmit = function()
		{
			YY_checkform('myform','civility[0]','#q','2',mLabels[0],'lastname','#q','0',mLabels[1],'firstname','#q','0',mLabels[2],'phone','#q','0',mLabels[3],'email','#S','2',mLabels[4]);
			return document.MM_returnValue;
		}
	}
});
