var Sexy = null;
var http = '';
var https = '';
var counter = 0;

var Site = {
	start: function() {
		Sexy = new SexyAlertBox();
		
		if($('http')) http = $('http').value;
		if($('https')) https = $('https').value;
		
		// Menu
		Site.sliding(); //Add slider effect on elements
		Site.notice(); //Add notice effect on elements
		Site.toolTip(); //Add tool-tip effect on elements

		if ($('tabsMenu')){
			Site.tabsMenu();
		}
		if ($('tabsMenuInter')){
			Site.tabsMenuInter();
		}
		if ($('subTabsMenu')){
			Site.subTabsMenu();
		}
		if ($('myActionSubTabsMenu')){
			Site.myActionSubTabsMenu();
			Site.updateActionPlan();
		}

		//Sidebox login
		if ($('sideboxLoginForm')){
			Site.sideboxLogin();
		}
		if ($('logout')) {
			Site.logout();
		}
		//Login form
		if ($('loginForm')){
			Site.login();
		}
		if ($('orderProcess')){
			Site.orderProcess();
		}
		/*if ($('offerColumn')){
			Site.offerAccordion();
		}*/
		if ($('indexQuiz')){
			Site.indexQuiz();
		}
		if ($('submitAgreement')){
			Site.agreement();
		}
		if ($('quizzPage')){
			Site.quizz();
		}
		if ($('ruffierSlider')){
			Site.ruffierDickinson();
			Site.validateRuffierPageSubmit();
		}
		if ($('answerBMIInput')){
			Site.validateBMI();
		}
		if ($('bmiSlider')){
			Site.bmi();
		}
		if ($('quizzPage') && $('question_type_code').value == 'qcm'){
			Site.slider();
		}
		if ($('pDetail')){
			Site.tabPartnerMenu();
		}
		if ($('feedbackMonitorResults')) {
			Site.feedbackResults();
		}
		if($('partnerContact')){
			Site.partnerContact();
		}
		if($('contact')){
			Site.contact();
		}
		if($('createAccountForm')){
			Site.createAccount();
		}
		
		// Added By E - Sales Conquest - Start
		if($('campaign')){
			Site.campaign();
		}
		if($('createAccountFormCheckout')){
			Site.createAccountCheckout();
		}
		if($('checkoutBillingForm')){
			Site.checkoutBilling();
		}
		if($('checkoutLoginForm')){
			Site.checkoutLoginFn();
		}
		if($('createAccountQuizForm')){
			Site.createAccountQuiz();
		}
		if ($('quizLoginForm')){
			Site.quizLogin();
		}
		if ($('SlideItMoo_vertical_items')){
			Site.partnerSlider();
		}
		if ($('SlideItMoo_outer')){
			Site.partnerSliderHome();
		}
		
		if ($('drop_down_menu')){
			Site.dropDownMenu();
		}
		
		// E - Sales Conquest  - end
		
		if($('editAccount')){
			Site.editAccount();
		}
		if($('actionPlanForm')){
			Site.actionPlan();
		}
		if($('myActionPlan')){
			Site.updateActionPlan();
		}
		if($('my_action_container')){
			Site.updateActionPlan();
		}
		if($('checkout')){
			Site.checkout();
		}
		Site.forgetPassword();
		
		if($('offerPage')){
			Site.updateCart();
		}
		if($('action_plan_overview')){
			Site.addGoals();
			Site.removeGoals();
		}
		if($('categoriesResults')){
			//Site.showFeedbackCategories();
			Site.addGoals();
			Site.removeGoals();
		}
		if($('questionsResults')){
			Site.showFeedbackQuestions();
			Site.addGoals();
			Site.removeGoals();
		}
		if($('quizzQuestionsResultsSingle')){
			Site.showFeedbackQuestionsSingle();
		}
		
		
		if($('indicatorsResults')){
			Site.showFeedbackIndicators();
			Site.addGoals();
			Site.removeGoals();
		}
		if($('indicatorsResultsInterrelated')){
			Site.showFeedbackIndicatorsOverall();
			Site.addGoals();
			Site.removeGoals();
		}
		
		if($('ticker')){
			Site.ticker();
		}
		
		if ($('homebox')) {
			Site.tabsHome();
			Site.offerSlider();
		}
/*		if ($('homebox')) {
			Site.tabsHome();
			Site.offerSlider();
		}*/
		if ($('myAccountMessage')) {
			$('myAccount').setStyle('height', '75px');
		}

		if ($('order_status_list')) {
			Site.initOrderStatusList();
		}
	},
	
	//Sidebox login
	sideboxLogin: function () {
		//Initialise les sliders
		/*loginSlide = new Fx.Slide('login');
		accountSlide = new Fx.Slide('myAccount');

		if ($('login').hasClass('invisible')) {
			loginSlide.hide();
		} else {
			accountSlide.hide();
		}*/
		
		/* Formulaire de login */
		var loginForm = new AjaxForm ({
			form: $('sideboxLoginForm'),		//Form element
			log: $('errorLogin') 		//Log element (Texte et image de retour)
		});
	
			// Login r�ussi
		loginForm.addEvent('responseSuccess', function(response) {
			/*loginSlide.slideOut().chain(function () {
				//Affiche le box My Account
				accountSlide.slideIn();
				$('myAccount').setStyle('height', 'auto');
				$('loginName').empty().set('html', response.data['login']);
				//Cache le compte Login
				loginForm.options.slide.slideOut();
				loginForm.reset_style();
				loginForm.reset_values();
			});*/
			//location = https + 'survey_list.php';
			location.href = response.target;
		});
	},
	
	logout: function (){
		//Clic sur le lien de d�connexion
		$('logoutLink').addEvent('click', function(e) {
			e.stop();
			var jsonRequest = new Request.JSON({
				url: "ajax/logout.php",
				onComplete: function(result) {
					if (result.success) {
						//Cache le box My Account et affiche le box Login
						/*accountSlide.slideOut().chain(function () {
							loginSlide.slideIn().chain(function () {
								$('login').getParent().setStyle('height', 'auto');
							});
						});*/
						//Redirige sur l'accueil
						location.href = https + 'index.php';
					}
				}
			}).get();
		});
	},

	//Login Page
	login: function () {
		/* Formulaire de login */
		var loginForm = new AjaxForm ({
            form: $('loginForm'),		//Form element
            log: $('returnLogin') 		//Log element (Texte et image de retour)
		});

		// Login r�ussi
	    loginForm.addEvent('responseSuccess', function(response) {
				var errorLogin = new Fx.Slide('returnLogin').slideOut();
				this.reset_style();
				this.reset_values();
				location.href = response.target;
	    });
	},

	forgetPassword: function() {
		$$('.forgetPassword').each(function(el){
			el.addEvent('click', function(e) {
					e.stop();
					//Requ�te permettant de r�cup�rer le label
					var jRequest = new Request.JSON({
							url: "ajax/get_label.php",
							onComplete: function(myResult) {
									Site.forgetPasswordForm(myResult.label);
							}
					}).get({label: 'LBL_FORGET_PASSWORD_MAIL'});
			});
		});
	},

	forgetPasswordForm: function(label) {
			//Une fois le label r�cup�r�, l'afficher dans le MSGBox
			Sexy.prompt(label,'' , {
					onComplete: function(returnvalue) {
							if(returnvalue) {
									//Requ�te AJAX pour v�rifier si l'e-mail existe
									//et si on lui envoie un e-mail avec le nouveau mot de passe
									var jsonRequest = new Request.JSON({
											url: "ajax/forget_password.php",
											onComplete: function(result){
													//alert(JSON.encode(result));
													if (result.success) {
															Sexy.info(result.message);
													} else {
															Sexy.error(result.message);
													}
											}
									}).get({'login': returnvalue});
							}
					}
			});
	},

	//Teste si l'utilisateur est logg� pour le rediriger sur le formulaire de commande
	orderProcess: function () {
		$('orderProcess').addEvent('click', function(e){
			/*e.stop();
			
			var jsonRequest = new Request.JSON({
				url: "ajax/check_login.php",
				onComplete: function(result) {
					if (result.success) {
						location = https + 'checkout.php';
					} else {
						Sexy.error(result.label);
					}
				}
			}).get();*/
			e.stop();
			location.href = https + 'checkout.php';
		});
	},
	
	/*offerAccordion: function () {
		$position = 0;
		if($('accordionPosition')) $position = $('accordionPosition').value;
		//create our Accordion instance
		var myAccordion = new Accordion($('offerColumn'), 'div.toggler', 'div.element', {
			opacity: false,
			display: $position
		});
	},*/

	updateCart: function() {
		$$('.addToCart').each (
			function(el) {
				el.addEvent('click', function(event) {
					$('ajax_loading').setStyle('visibility', 'visible');
					var jsonRequest = new Request.JSON({
						url: "ajax/update_cart.php",
						onComplete: function(result) {
							$('cart_overview').set('html', result.page);
							$('ajax_loading').setStyle('visibility', 'hidden');
							if(!result.success){
								Sexy.error(result.message);
							}
							else
							{
								setTimeout("location.href = 'checkout_confirm.php'",2000);
							}
						}
					}).get({'id': el.getProperty('offer'), 'action': 'add'});
				});
			}
		);
		$$('.removeFromCart').each (
			function(el) {
				el.addEvent('click', function(event) {
					$('ajax_loading').setStyle('visibility', 'visible');
					var jsonRequest = new Request.JSON({
						url: "ajax/update_cart.php",
						onComplete: function(result) {
							$('cart_overview').set('html', result.page);
							$('ajax_loading').setStyle('visibility', 'hidden');
						}
					}).get({'id': el.getProperty('offer'), 'action': 'remove'});
				});
			}
		);
	},
	
	addGoals: function() {
		$$('.addGoal').each (
			function(el) {
				el.addEvent('click', function(event) {
					//va rechercher le label
					//Vas chercher le label et affiche l'erreur
					var jsonRequest = new Request.JSON({
						url: "ajax/get_label.php",
						onComplete: function(result) {
						
							//test afin de savoir si l'internaute veut ajouter ou non
							Sexy.confirm(result.label, {
							  onComplete:
							    function(returnvalue) {
							      if (returnvalue) {
									$('ajax_loading').setStyle('visibility', 'visible');
									var jsonRequest = new Request.JSON({
										url: "ajax/bookmark_action.php",
										onComplete: function(result) {
											$('action_plan_overview').empty().set('html', result.page);
											$('ajax_loading').setStyle('visibility', 'hidden');
											if(!result.success){
												Sexy.error(result.message);
											}else{
											//	$('selectedActionPlanTab').removeClass('none');
												Sexy.info(result.message);
											//	Site.removeGoals(); //R�initialisation des �l�ments Action Plan
											}
										}
									}).get({'id': el.getProperty('goal')
										, 'survey': el.getProperty('survey')
										, 'object_id': el.getProperty('object_id')
										, 'object_type': el.getProperty('object_type')
										, 'action': 'add'});							        
							      }
							    }
							  });
						}
					}).get({label: 'LBL_CONFIRM_ACTION_BOOKMARK'});	
					
				});
			}
		);
	},
	
	removeGoals: function() {
		$$('.removeGoal').each (
			function(el) {
				el.addEvent('click', function(event) {
					$('ajax_loading').setStyle('visibility', 'visible');
					var jsonRequest = new Request.JSON({
						url: "ajax/update_action_plan.php",
						onComplete: function(result) {
							$('action_plan_' + el.getProperty('goal')).destroy();
							//$('action_plan_overview').empty().set('html', result.page);
							$('ajax_loading').setStyle('visibility', 'hidden');
							Site.removeGoals(); //R�initialisation des �l�ments Action Plan
						}
					}).get({'id': el.getProperty('goal'), 'survey': el.getProperty('survey'), 'action': 'remove'});
				});
			}
		);
	},
	
	showFeedbackCategories: function(){
		$$('.quizzResultsCategory').each (
			function(el) {
				el.addEvent('click', function(event) {
					//Hide box content
					$$('.quizzCategoriesFeedbackTips').each (
						function(box) {
							box.setStyle('display', 'none');
						}
					);
					
					var category = el.getProperty('category_id');
					$('feedbackCategory'+category).setStyle('display', 'block');
					var myFx = new Fx.Scroll(window).toElement('categoriesFeedback'+category);
				});
			}
		);
	},
	
	showFeedbackQuestions: function(){
		$$('.resultsQuestionsBar').each (
			function(el) {
				el.addEvent('click', function(event) {
				
				//commented - E- Sales Conquest - May 19, 2011 - for enabling tab activation on bar graph result click - Starts
				/*
					//Hide box content
					$$('.quizzQuestionsFeedbackTips').each (
						function(box) {
							//box.empty().set('html', '');
							box.setStyle('display', 'none');
						}
					);
					
					var question = el.getProperty('question_id');
					var feedback = el.getProperty('feedback');
					if (feedback == 1) {
						$('feedbackQuestions'+question).setStyle('display', 'block');
						//Scroll auto
						var myFx = new Fx.Scroll(window).toElement('questionsCategoryTarget' + el.getProperty('category_id'));
					}
				*/
				//commented - E- Sales Conquest - May 19, 2011 - for enabling tab activation on bar graph result click - Ends
				
				//E-Sales Conquest - May 19 , 2011 - For tab activation  on bar graph result click - Starts
				
					$$('.tabContainer').each(function(element) {
					element.setStyle('display', 'none');
					});
					$$('.menuTab').each(function(element) {
						element.removeClass('active');
						if(element.getProperty('tab') == el.getProperty('tab'))
						element.addClass('active');
					});
					 $(el.getProperty('tab')).setStyle('display', 'block');
					 
					 $$('.tabContainerInter').each(function(element) {
					element.setStyle('display', 'none');
					});
					$$('.menuTabInter').each(function(element) {
						element.removeClass('active');
						if(element.getProperty('tab') == el.getProperty('tab'))
						element.addClass('active');
					});
					 $(el.getProperty('tab')).setStyle('display', 'block');
					 
					//Hide box content
					$$('.quizzQuestionsFeedbackTipsSingle').each (
						function(box) {
							//box.empty().set('html', '');
							box.setStyle('display', 'none');
						}
					);
					
					var question = el.getProperty('question_id');
					var feedback = el.getProperty('feedback');
					if (feedback == 1) {
						$('feedbackQuestionsSingle'+question).setStyle('display', 'block');
						//Scroll auto
						var myFx = new Fx.Scroll(window).toElement(el.getProperty('tab'));
					}
				
				//E-Sales Conquest - May 19 , 2011 - For tab activation  on bar graph result click - Ends
				
				});
			}
		);
	},
	
	showFeedbackQuestionsSingle: function(){
		$$('.resultsQuestionsBarSingle').each (
			function(el) {
				el.addEvent('click', function(event) {
					//Hide box content
					$$('.quizzQuestionsFeedbackTipsSingle').each (
						function(box) {
							//box.empty().set('html', '');
							box.setStyle('display', 'none');
						}
					);
					
					var question = el.getProperty('question_id');
					var feedback = el.getProperty('feedback');
					if (feedback == 1) {
						$('feedbackQuestionsSingle'+question).setStyle('display', 'block');
						//Scroll auto
						var myFx = new Fx.Scroll(window).toElement('questionsCategoryTarget' + el.getProperty('category_id'));
					}
				});
			}
		);
	},

	showFeedbackIndicators: function(){
		$$('.resultsIndicatorsBar').each (
			function(el) {
				el.addEvent('click', function(event) {
					//Hide box content
					$$('.quizzIndicatorsFeedbackTips').each (
						function(box) {
							//box.empty().set('html', '');
							box.setStyle('display', 'none');
						}
					);
					
					var indicator = el.getProperty('indicator_id');
					var feedback = el.getProperty('feedback');
					if (feedback == 1) {
						$('feedbackIndicators'+indicator).setStyle('display', 'block');
						//Scroll auto
						var myFx = new Fx.Scroll(window).toElement('indicatorsCategoryTarget' + el.getProperty('category_id'));
					}
				});
			}
		);
	},

	//Teste que les conditions g�n�rales ont �t� accept�es
	indexQuiz: function () {
		/*$('indexQuiz').addEvent('click', function(e) {
			e.stop();
			
			//Si les conditions g�n�rales sont accept�es
			if ($('conditionsCheckbox').checked) {
				var jsonRequest = new Request.JSON({
					url: "ajax/check_login.php",
					onComplete: function(result) {
						if (result.success) {
							location = https + 'survey_list.php';
						} else {
							//Sexy.error(result.label);
							location = https + 'create_account.php?t=survey_list';
						}
					}
				}).get();
			} else {
				//Vas chercher le label et affiche l'erreur
				var jsonRequest = new Request.JSON({
					url: "ajax/get_label.php",
					onComplete: function(result) {
						Sexy.error(result.label);
					}
				}).get({label: 'LBL_CGU_NOT_CHECKED'});
				//var label = Site.getLabel('LBL_CGU_NOT_CHECKED');
			}
		});*/
	},
	
	agreement: function() {
		$('submitAgreement').addEvent('click', function(e) {
			e.stop();
			
			var quizz_id = this.getProperty('quizz');
			var survey_id = this.getProperty('survey');
			if ($('checkAgreement').checked) {
				location.href = https + 'quizz.php?quizz=' + quizz_id + '&survey=' + survey_id + '&check';
			} else {
				if(quizz_id == 6)
				{
					//Vas chercher le label et affiche l'erreur
					var jsonRequest = new Request.JSON({
						url: "ajax/get_label.php",
						onComplete: function(result) {
							Sexy.error(result.label);
						}
					}).get({label: 'LBL_CGU_NOT_CHECKED'});
				}else{
					//Vas chercher le label et affiche l'erreur
					var jsonRequest = new Request.JSON({
						url: "ajax/get_label.php",
						onComplete: function(result) {
							Sexy.error(result.label);
						}
					}).get({label: 'LBL_INTRO_NOT_CHECKED'});				
				}
			}
		});
	},
	
	quizz: function () {
		var quizzForm = new AjaxForm ({
            form: $('quizzForm'),		//Form element
            log: $('returnQuizz') 		//Log element (Texte et image de retour)
		});
		
		//Initialise la barre de progression et le highlight de la cat�gorie
		Site.reinitQuiz();
		
		quizzForm.addEvent('sendRequest', function() {
			//Affiche le loading et d�sactive le bouton
			$('ajax_loading').setStyle('visibility', 'visible');
			$('submitQuestion').disabled = true;
		});

		quizzForm.addEvent('responseSuccess', function(response) {
			var myFx = new Fx.Scroll(window).toElement('topAnchor');
			
			//Efface les erreurs
			this.reset_style();
			this.options.slide.hide();
			$('ajax_loading').setStyle('visibility', 'hidden');
			$('submitQuestion').disabled = false;
			
			if (response.finish) {
				location.href = https + 'quizz_success.php';
			} else {
				//Affiche la nouvelle question
				//$('quizz_form').empty().set('html', response.question);
				
				//Remets la direction par d�faut � Next
				//$('submitDirection').value='next';
				
				//Relance le site.start pour r�appliquer les effets JS
				//Site.start();
				
				//Rafraichissement de la page pour
				//l'affichage de la prochaine question
				var myFx = new Fx.Scroll(window).toElement('topAnchor');
				window.location=window.location;
				//window.location.reload();
				//window.location.href.reload('#topAnchor');
			}
		});
		
		quizzForm.addEvent('responseError', function(response) {
			//Remonte en haut de la page
			var myFx = new Fx.Scroll(window).toElement('topAnchor');
			$('ajax_loading').setStyle('visibility', 'hidden');
			$('submitQuestion').disabled = false;
    });
	},
	
	reinitQuiz: function () {
		
		//Active la cat�gorie de la question en cours
		$$('.categoryItem').removeClass('active');
		var category_id = $('category_id').value;
		if($('categoryList' + category_id)){
			$('categoryList' + category_id).addClass('active');
		}
		
		//Barre de progression
		var progression = ($('position_on_questionnaire_only_active_question').value - 0.5) / $('nb_of_active_questions_in_questionnaire').value * 100;
		$('bar').setStyle('width', progression + '%');
		
		//Slider pour les explications de la question
		if ($('questionExplanationContent')) {
			var whySlider = new Fx.Slide('questionExplanationContent').hide();
			$('questionExplanationTrigger').addEvent('click', function(e) {
				e.stop();
				whySlider.toggle();
			});
		}
	},
	
	slider: function () {
		var el = null;
		var subquestion = new Array();
		
		$$('.slider').each(function(slider, i) {
			el = slider;
			subquestion[i] = el.getProperty('subquestion');
			
			// Create the new slider instance
			var monSlider = new Slider(el, el.getElement('.knob'), {
				range: [0, $('rangeMaxSlider' + subquestion[i]).value],
				steps: $('stepsSlider' + subquestion[i]).value,
				snap: false,
				onChange: function(value){
					var valeur = value.toInt();
					// Everytime the value changes, we change the font of an element
					if (valeur != 0) {
						if(valeur >= $('stepsSlider' + subquestion[i]).value){
							valeur = $('stepsSlider' + subquestion[i]).value - 1;
						}
						$('answerSlider' + subquestion[i]).value = $('qcmSliderLabel' + subquestion[i] + '_' + valeur).getProperty('answer');
						$$('.qcmSliderLabel' + subquestion[i]).removeClass('qcmSliderLabelActive');
						$('qcmSliderLabel' + subquestion[i] + '_' + valeur).addClass('qcmSliderLabelActive');	
					} else {
						$('answerSlider' + subquestion[i]).value = 0;
						$$('.qcmSliderLabel' + subquestion[i]).removeClass('qcmSliderLabelActive');
					}
				}
			});
		});
	},
	
	ruffierDickinson: function() {
		var jRequest = new Request.JSON({
			url: "ajax/get_label.php",
			onComplete: function(myResult) {
							
				var ecart = null;
				var ecartDisplay = null;
				var inputBoxesStatus = new Array();
				var box_id;
				//Pour calculer la somme 
				$$('.inputRuffierP').each(function(input) {
					input.addEvent('blur', function(e){
						var somme = null;
						var allComplete = true;
						var isNumeric = false;
						$$('.inputRuffierP').each(function(input2) {
							if (input2.value!='')
							{
								box_id = input2.getProperty('id');
								//input2.value = input2.value.replace(/-/,"");
								var inputVal = parseFloat(input2.value.replace(/'/,""));
								
								if(inputVal < 35 || inputVal > 220 || isNaN(inputVal))
								{
									/*alert(myResult.label);
									inputBoxesStatus.push(box_id);
									$(input2.id).setProperty('value', '');
									$(inputBoxesStatus[0]).setProperty('value', '');*/
									allComplete = false;
								}
								else
								{
									somme += parseFloat(input2.value.replace(/'/,""));
								}
							}
							else
							{
								
								allComplete = false;
							}
							/*if(inputBoxesStatus.length > 0) {
								$(inputBoxesStatus[0]).focus();
								inputBoxesStatus.length = 0;
							}*/
							
						});
						if (!isNaN(somme) && allComplete){
							if(somme < 200)
							somme = 200;
							var finalSomme = (somme-200)/10;
							
							//Si la somme est plus grande que 0
							if (finalSomme >= 0) {
								$('ruffierResult').value = finalSomme;
							
								ecart = Site.calculeEcartRuffier(finalSomme)
								if(ecart > 370)
								ecartDisplay = 370;
								else
								ecartDisplay = ecart;
								$('ruffierKnob').setStyle('left', ecartDisplay + 'px');
							}
						}
					});
				});
				
				//Place le slider en fonction du r�sultat d�j� affich�
				if ($('ruffierResult').value != '') {
					ecart = Site.calculeEcartRuffier($('ruffierResult').value)
					$('ruffierKnob').setStyle('left', ecart + 'px');
				}
			}
		}).get({label: 'LBL_RUFFIER_DICKINSON_HEART_RATE_ERROR', label1: 'LBL_PLEASE_ENTER_VALUE'});
		//end ajax get label here
	},
	validateRuffierPageSubmit: function() {
		var textbox_id;
		var inputStatusArray = new Array();
		var inputRangeStatus = new Array();
		var isInputValueOk = false;
		$$('#submitQuestion').addEvent('click', function (e1) {
			var isInputEmpty = true;											  
			$$('.inputRuffierP').each(function(input2) {
				if(!input2.value.match(/\S/) ) {
					isInputEmpty = true;
					textbox_id = input2.getProperty('id');
					inputStatusArray.push(textbox_id);
					//alert(textbox_id);
				} else {
					if(input2.value < 35 || input2.value > 220 || isNaN(input2.value)) {
						textbox_id = input2.getProperty('id');
						isInputValueOk = false;
						inputRangeStatus.push(textbox_id);
					} else {
						isInputValueOk = true;
					}
				}
															   
			});
			if(inputStatusArray.length > 0) {
				var jRequest = new Request.JSON({
					url: "ajax/get_label.php",
					onComplete: function(myResult) {
						alert(myResult.label);
						$(inputStatusArray[0]).focus();
						inputStatusArray.length = 0;
					}
				}).get({label: 'LBL_RUFFIER_DICKINSON_HEART_RATE_ERROR_EMPTY_BOXES'});
				return false;
			} else if(!isInputValueOk) {
				var jRequest = new Request.JSON({
					url: "ajax/get_label.php",
					onComplete: function(myResult) {
						alert(myResult.label);
						for(i=0; i < inputRangeStatus.length; i++) {
							$(inputRangeStatus[i]).setProperty('value', '');
						}
						$(inputRangeStatus[0]).focus();
						inputRangeStatus.length = 0;
					}
				}).get({label: 'LBL_RUFFIER_DICKINSON_HEART_RATE_INCORRECT_VALUES'});
				return false;
			} else {
				return true
			}
		});
		//inputStatusArray = '';
	},
	calculeEcartRuffier: function (finalSomme) {
		//Bouge le slider
		var ecart = null;
		
		// LRU - Hardcoding assum� des �carts entre les niveaux du Ruffier-Dickinson
		if (finalSomme >= 0 && finalSomme <= 5) {
			ecart = 8;
		} else if (finalSomme > 5 && finalSomme <= 10) {
			ecart = 100;
		} else if (finalSomme > 10 && finalSomme <= 15) {
			ecart = 200;
		} else if (finalSomme > 15 && finalSomme <= 20) {
			ecart = 300;
		} else {
			ecart = 400;
		}
		ecart -= 8;
		
		return ecart;
	},
	
	bmi: function() {
		var bmi_box_id;
		var bmiStatusArray = new Array();
		bmiRangeStatusArray = new Array();
		var isbmiKgValueOk = false;
		var isbmiMValueOk = false;
		$$('#submitQuestion').addEvent('click', function (e1) {
			var isBMIInputEmpty = true;											  
		  	$$('.inputBMIkg').each(function(input){
				if(!input.value.match(/\S/) ) {
					isBMIInputEmpty = true;
					bmi_box_id = input.getProperty('id');
					bmiStatusArray.push(bmi_box_id);
					//alert(textbox_id);
				} else {
					if(input.value < 20 || input.value > 400 || isNaN(input.value)) {
						bmi_box_id = input.getProperty('id');
						bmiRangeStatusArray.push(bmi_box_id);
						isbmiKgValueOk = false;
					} else {
						isbmiKgValueOk = true;
					}
				}
			});
			/*$$('.inputBMIlb').each(function(input1){
				var input_lb = input1.value.replace(/-/,"");
				alert(input_lb);
			});*/
			$$('.inputBMIm').each(function(input2){
				if(!input2.value.match(/\S/) ) {
					isBMIInputEmpty = true;
					bmi_box_id = input2.getProperty('id');
					bmiStatusArray.push(bmi_box_id);
					//alert(textbox_id);
				} else {
					if(input2.value < 100 || input2.value > 300 || isNaN(input2.value)) {
						bmi_box_id = input2.getProperty('id');
						bmiRangeStatusArray.push(bmi_box_id);
						isbmiMValueOk = false;
					} else {
						isbmiMValueOk = true;
					}
				}
			});
			if(bmiStatusArray.length > 0) {
				var jRequest = new Request.JSON({
					url: "ajax/get_label.php",
					onComplete: function(myResult) {
						alert(myResult.label);
						$(bmiStatusArray[0]).focus();
						bmiStatusArray.length = 0;
					}
				}).get({label: 'BMI_ERROR_EMPTY_BOXES'});
				return false;
			} else if(!isbmiKgValueOk || !isbmiMValueOk) {
					var jRequest = new Request.JSON({
						url: "ajax/get_label.php",
						onComplete: function(myResult) {
							alert(myResult.label);
							for(i=0; i < bmiRangeStatusArray.length; i++ ) {
								$(bmiRangeStatusArray[i]).setProperty('value', '');
							}
							$(bmiRangeStatusArray[0]).focus();
							bmiRangeStatusArray.length = 0;
						}
					}).get({label: 'BMI_INCORRECT_VALUES'});
					return false;
			} else {
				return true;
			}
		});
		// convertisseur de poids
		$$('.inputBMIkg').each(function(input){
			input.addEvent('keyup', function(e){
				input.value = input.value.replace(/-/,"");
				// calcul le champs en unit� anglosaxonne
				$(input.id + '_lb').setProperty(
					'value',Math.round((input.value / 0.45359237)*100)/100
				);
			});
			/*input.addEvent('blur', function(e){
				input.value = input.value.replace(/-/,"");
				if(input.value !='') {
					if(input.value < 20 || input.value > 400) {
						var jRequest = new Request.JSON({
							url: "ajax/get_label.php",
							onComplete: function(myResult) {
								alert(myResult.label);
								$(input.id + '_lb').setProperty('value','');
								$(input.id).setProperty('value','');
								$(input.id).focus();
								return false;
							}
						}).get({label: 'LBL_BMI_KG_VALUE_ERROR'});
					}
				}
			});*/
			
		});
		$$('.inputBMIlb').each(function(input){
			input.addEvent('keyup', function(e){
				input.value = input.value.replace(/-/,"");							 
				// calcul le champs en unit� internationnal
				$(input.id.substring(0, (input.id.length - 3) )).setProperty(
					'value',Math.round((input.value * 0.45359237)*100)/100
				);
			});
			/*input.addEvent('blur', function(e){
				input.value = $(input.id).value.replace(/-/,"");
				if(input.value !='') {
					if(input.value < 20 || input.value > 400) {
						var jRequest = new Request.JSON({
							url: "ajax/get_label.php",
							onComplete: function(myResult) {
								alert(myResult.label);
								$(input.id + '_lb').setProperty('value','');
								$(input.id.substring(0, (input.id.length - 3) )).setProperty('value','');
								$(input.id).focus();
								return false;
							}
						}).get({label: 'LBL_BMI_KG_VALUE_ERROR'});
					}
				}
			});*/
			
		});
		
		// convertisseurs de longueur
		$$('.inputBMIm').each(function(input){
			input.addEvent('keyup', function(e){
				input.value = input.value.replace(/-/,"");							 
				// calcul le champs en unit� anglosaxonne
				var feet = Math.floor(input.value / 30.48);
				var inch = Math.round((((input.value / 30.48) - feet)*12));
				$(input.id + '_feet').setProperty('value',feet);
				$(input.id + '_inch').setProperty('value',inch);
			});
		});
		$$('.inputBMIft').each(function(input){
			input.addEvent('keyup', function(e){
				input.value = input.value.replace(/-/,"");							 
				// calcul le champs en unit� internationnale
				var m = ( this.value * 0.3048 + $( input.id.substring( 0, (input.id.length - 5) ) + '_inch').value * 0.0254 );
				$(input.id.substring( 0, (input.id.length - 5) )).setProperty('value', Math.round(m*100)/*/100*/);
			});
		});
		$$('.inputBMIin').each(function(input){
			input.addEvent('keyup', function(e){
				input.value = input.value.replace(/-/,"");							 
				// calcul le champs en unit� internationnale
				var m = ( $(this.id.substring( 0, (input.id.length - 5) ) + '_feet').value * 0.3048 + input.value * 0.0254 );
				$(input.id.substring( 0, (input.id.length - 5) )).setProperty('value', Math.round(m*100)/*/100*/);
			});
		});
		
		// calcul du bmi
		var ecart = null;
		var ecartDisplay1 = null;
		$$('.inputBMI').each(function(input){
			input.addEvent('keyup', function(e){
				var bmiweights = $$('.inputBMIkg');
				var bmiheights = $$('.inputBMIm');
				var bmiresults = $$('.inputBMIResult').each(function(input2, key){
					var bmiresult = Math.round(bmiweights[key].value/(bmiheights[key].value/100*bmiheights[key].value/100)*100)/100;
					if (!isNaN(bmiresult)){					
						input2.setProperty(
							'value', bmiresult
						);
						ecart = Site.calculeEcartbmi(bmiresult);
						if(ecart > 578)
						ecartDisplay1 = 578;
						else
						ecartDisplay1 = ecart;
						$('bmiKnob').setStyle('left', ecartDisplay1 + 'px');
					}
				}
				);
			});
		});
		
		//Place le slider en fonction du r�sultat d�j� affich�
		$$('.inputBMIResult').each(function(input){
			if (input.value != '') {
				ecart = Site.calculeEcartbmi(input.value);
				$('bmiKnob').setStyle('left', ecart + 'px');
			}
		});
	},
	
	calculeEcartbmi: function (bmiresult) {
		//Bouge le slider
		var ecart = null;
		// LRU - Hardcoding assum� des �carts entre les niveaux du BMI
		if (bmiresult >= 0 && bmiresult < 18.5) {
			ecart = 8;
		} else if (bmiresult >= 18.5 && bmiresult < 22) {
			ecart = 100;
		} else if (bmiresult >= 22 && bmiresult < 23) {
			ecart = 200;
		} else if (bmiresult >= 23 && bmiresult < 25) {
			ecart = 300;
		} else if (bmiresult >= 25 && bmiresult < 27) {
			ecart = 400;
		} else if (bmiresult >= 27 && bmiresult <= 30) {
			ecart = 500;
		} else {
			ecart = 600;
		}
		ecart -= 8;
		
		return ecart;
	},
	
	/*setEditor: function()	{
		tinyMCE.init({
			// General options
			mode : "specific_textareas",
			editor_selector : "inputHtml",
			theme : "advanced",

			// File path pour images et files
			//imagemanager_rootpath: "../",
			//filemanager_rootpath: "../",
			document_base_url : "/",

			plugin_preview_width : "800",
			plugin_preview_height : "600",
			//plugin_preview_pageurl : "/backend/plugins/tinymce/jscripts/tiny_mce/plugins/preview/example.html",

			// Normalement mettre CSS du frontend pour afficher les "content" comme sur le frontend !
			// Comme (document_base_url : "/") on doit mettre le chemin du css depuis le root du domaine
			content_css : "backend/css/backend.css",
			//content_css : "backend/plugins/tinymce/examples/css/word.css",
			

			//plugins : "searchreplace,media",
			plugins : "searchreplace,media,safari,spellchecker,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,ibrowser",
			//plugins : ",imagemanager,filemanager",

			// Theme options
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,media,ibrowser,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			////theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",

			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true
		});
	},*/

	sliding: function () {
		$$('.sliders').each(function(el) {
			var toggler = el.getFirst('.toggler');
			var element = el.getFirst('.element');
			if(element != null){
				var mySlide = new Fx.Slide(element);
				if(el.hasClass('closed')) mySlide.hide();
				toggler.addEvent('click', function(e){
					e.stop();
					mySlide.toggle();
				});
			}
		});
	},

	notice: function () {
			$$('.notice').each(function(el) {
					var checkbox = el.getProperty('id');
					el.addEvent('click', function(e){
							var myValue = 0;
							if(el.checked == true) myValue = 1;
							var jsonRequest = new Request.JSON({
								url: "ajax/notice.php",
								onComplete: function(result) {
									if(!result.success){
										JS_Growl.notify(result.message);
									}else{
										JS_Growl.notify(result.message);
									}
								}
							}).get({'t': checkbox, 'v': myValue});
					});
			});
	},

	toolTip: function(){
			//store titles and text  
			$$('.infobulle').each(function(element,index) {
				var content = element.get('title').split('::');
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			//create the tooltips  
			var tipz = new Tips('.infobulle',{
				 className: 'tips',
				 offsets: {'x': 10, 'y': 10},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
			
			//store titles and text  
			$$('.historic').each(function(element,index) {
				var content = element.get('title').split('::');
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			//create the tooltips  
			var tipz = new Tips('.historic',{
				 className: 'historic',
				 offsets: {'x': 10, 'y': 10},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
			
			//store titles and text  
			$$('.resultsBar').each(function(element,index) {
				var content = element.get('title').split('::');
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			//create the tooltips  
			var tipz = new Tips('.fullAttentionBar',{
				 className: 'fullAttentionTip',
				 offsets: {'x': 20, 'y': 70},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
			//create the tooltips  
			var tipz = new Tips('.improveBar',{
				 className: 'improveTip',
				 offsets: {'x': 20, 'y': 70},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
			//create the tooltips  
			var tipz = new Tips('.monitorBar',{
				 className: 'monitorTip',
				 offsets: {'x': 20, 'y': 70},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
			//create the tooltips  
			var tipz = new Tips('.goodBar',{
				 className: 'goodTip',
				 offsets: {'x': 20, 'y': 70},
				 fixed: false,
				 hideDelay: 50,
				 showDelay: 50
			});
	},
	
  tabPartnerMenu: function(){
    var first = true;
		$$('.tabsContainer').each(function(element) {
			if(first) element.setStyle('visibility', 'visible');
			first = false;
		});
		$$('.mItem').each(function(el) {
			el.addEvent('click', function(event) {
				$$('.tabsContainer').each(function(element) {
					element.setStyle('visibility', 'hidden');
				});
				$$('.mItem').each(function(element) {
					element.removeClass('active');
				});
                $(el.getProperty('tab')).setStyle('visibility', 'visible');
				el.addClass('active');
            });
		});
	},
	
	tabsMenu: function(){
		//R�cup�re la semaine courante pour afficher le bon bloc
		var block = null;
		if ($('container')) block = $('container').value; //input invisible
		else block = 1;

		var tab = 1;
		$$('.tabContainer').each(function(element) {
			if(tab == block) element.setStyle('display', 'block');
			tab++;
		});
		
		$$('.menuTab').each(function(el) {
			el.addEvent('click', function(event) {
				$$('.tabContainer').each(function(element) {
					element.setStyle('display', 'none');
				});
				$$('.menuTab').each(function(element) {
					element.removeClass('active');
				});
        $(el.getProperty('tab')).setStyle('display', 'block');
				el.addClass('active');
      });
		});
		
		$$('.menuTabImage').each(function(el) {
			el.addEvent('click', function(event) {
				$$('.tabContainer').each(function(element) {
					element.setStyle('display', 'none');
				});
				$$('.menuTab').each(function(element) {
					element.removeClass('active');
					if(element.getProperty('tab') == el.getProperty('tab'))
					element.addClass('active');
				});
				 $(el.getProperty('tab')).setStyle('display', 'block');

      });
		});
	},
	
	tabsMenuInter: function(){
		//R�cup�re la semaine courante pour afficher le bon bloc
		var block = null;
		if ($('container')) block = $('container').value; //input invisible
		else block = 1;

		var tab = 1;
		$$('.tabContainerInter').each(function(element) {
			if(tab == block) element.setStyle('display', 'block');
			tab++;
		});
		
		$$('.menuTabInter').each(function(el) {
			el.addEvent('click', function(event) {
				$$('.tabContainerInter').each(function(element) {
					element.setStyle('display', 'none');
				});
				$$('.menuTabInter').each(function(element) {
					element.removeClass('active');
				});
        $(el.getProperty('tab')).setStyle('display', 'block');
				el.addClass('active');
      });
		});
		
		$$('.menuTabImageInter').each(function(el) {
			el.addEvent('click', function(event) {
				$$('.tabContainerInter').each(function(element) {
					element.setStyle('display', 'none');
				});
				$$('.menuTabInter').each(function(element) {
					element.removeClass('active');
					if(element.getProperty('tab') == el.getProperty('tab'))
					element.addClass('active');
				});
				 $(el.getProperty('tab')).setStyle('display', 'block');

      });
		});
	},
	
	subTabsMenu: function(){
		//R�cup�re la semaine courante pour afficher le bon bloc
		var block = null;
		if ($('block')) block = $('block').value; //input invisible
		else block = 1;
		
			
		var tab = 1;
		$$('.subTabContainer').each(function(element) {
											 
			if(tab == block) element.setStyle('display', 'block');
			tab++;
		});
		
		$$('.menuSubTab').each(function(el) {
										
			el.addEvent('click', function(event) {
										  
				$$('.subTabContainer').each(function(element) {
					element.setStyle('display', 'none');
				});
				$$('.menuSubTab').each(function(element) {
					element.removeClass('active');
				});
        $(el.getProperty('tab')).setStyle('display', 'block');
				el.addClass('active');
      });
		});
	},
	
	//New Sub tabs menu for week range in my_action_plan.tpl(Jan 13 01 2011)
	myActionSubTabsMenu: function(){
		//R�cup�re la semaine courante pour afficher le bon bloc
		var block = 1;
		
		$$('.hidden_week_range').each(function(e2) {
			block= e2.getProperty('week_rangeindex'); 
			var weekrange = e2.value;
			var week_range_title = e2.getProperty('week_range_title'); 
			var week_range_min = e2.getProperty('week_range_min');
			var week_range_max = e2.getProperty('week_range_max');
			var jsonRequest = new Request.JSON({
				url: "ajax/get_label.php",
				onComplete: function(result) {
					$('week_range_title_'+weekrange).set("html", 'My Action Plan for '+result.label+'&nbsp;'+week_range_min+'-'+week_range_max).setStyle('display', 'block');	
				}
			}).get({label: 'LBL_WEEK'});
			$$('.subTabContainer_'+weekrange).each(function(element1) {
				element1.setStyle('display', 'none');
				element1.removeClass('active');
			});
			$$('#tab'+block).setStyle('display', 'block');

			$$('.menuSubTab_'+weekrange).each(function(el) { 

				if($(el.getProperty('tab')) != null)
				{								   
					el.addEvent('click', function(event) {
						$$('.subTabContainer_'+weekrange).each(function(element) {
							element.setStyle('display', 'none');
					});
					$$('.menuSubTab_'+weekrange).each(function(element) {
						element.removeClass('active');
					});
					$(el.getProperty('tab')).setStyle('display', 'block');
					el.addClass('active');
					});
				}
		});
	});
		$$('.historic_tab').each(function(h1) {
			h1.addEvent('click', function(event) {
				var tab_id = h1.getProperty('id');
				$(document.body).getElements('.tab_historic_content').setStyle('display', 'none');
				$(document.body).getElements('#'+'tab_historic_content_'+tab_id).setStyle('display', 'block');
			});
		});	
											   
	},
	
	
	
	
	feedbackResults: function() {
		Array.each($$('.feedbackTexts'), function(element) {
		
			var myAccordion = new Fx.Accordion('h4.feedbackToggler', '.feedbackResultText', element.get('id'), {
				display: 0,
				show: 0,
				onActive: function (toggler, element) {
					toggler.addClass('active');
				},
				onBackground: function (toggler, element) {
					toggler.removeClass('active');
				}
			});
		});
	},
	
	partnerContact: function() {
		var contactForm = new AjaxForm ({
			form: $('formPartnerContact'),		//Form element
			log: $('returnPartnerContact') 		//Log element (Texte et image de retour)
		});
		
		contactForm.addEvent('responseSuccess', function(response) {
			
			//Ferme la fen�tre d'envoi � un ami
			var errorContact = new Fx.Slide('returnPartnerContact').slideOut();
			this.reset_style();
			this.reset_values();
			Sexy.info(response.message);
			$('contact_submitter').disabled = false;
		});
		
		contactForm.addEvent('responseError', function(response) {
			$('contact_submitter').disabled = false;
		});
		
		$('formPartnerContact').addEvent('submit', function (e) {
			e.stop();
			$('contact_submitter').disabled = true;
		});
	},
	
	contact: function() {
		var contactForm = new AjaxForm ({
			form: $('formContact'),		//Form element
			log: $('returnContact') 		//Log element (Texte et image de retour)
		});
		
		contactForm.addEvent('responseSuccess', function(response) {
			//Ferme la fen�tre d'envoi � un ami
			var errorContact = new Fx.Slide('returnContact').slideOut();
			this.reset_style();
			this.reset_values();
			Sexy.info(response.message);
			$('contact_submitter').disabled = false;
			//Google AdWords
			//$('contact_response').set('html', response.html);
		});
		
		contactForm.addEvent('responseError', function(response) {
			$('contact_submitter').disabled = false;
		});
		
		$('formContact').addEvent('submit', function (e) {
			e.stop();
			$('contact_submitter').disabled = true;
		});
	},
	//campaign form - E - Sales conquest - March 25, 2011 - starts
	campaign: function() {
		var campaignForm = new AjaxForm ({
			form: $('formCampaign'),		//Form element
			log: $('returnCampaign') 		//Log element (Texte et image de retour)
		});
		
		campaignForm.addEvent('responseSuccess', function(response) {
			//Ferme la fen�tre d'envoi � un ami
			var errorCampaign = new Fx.Slide('returnCampaign').slideOut();
			this.reset_style();
			this.reset_values();
			Sexy.info(response.message);
			$('campaign_submitter').disabled = false;

		});
		
		campaignForm.addEvent('responseError', function(response) {
			$('campaign_submitter').disabled = false;
		});
		
		$('formCampaign').addEvent('submit', function (e) {
			e.stop();
			$('campaign_submitter').disabled = true;
		});
	},
	//campaign form - E - Sales conquest - March 25, 2011 - ends
	
	createAccount: function() {
		var createAccountForm = new AjaxForm ({
			form: $('createAccountForm'),		//Form element
			log: $('returnCreateAccount') 		//Log element (Texte et image de retour)
		});
		
		createAccountForm.addEvent('responseSuccess', function(response) {
			var errorCreateAccount = new Fx.Slide('returnCreateAccount').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//Google AdWords
			$('create_account_response').set('html', response.html);
			location.href = response.target;
			$('account_submitter').disabled = false;
		});
		
		createAccountForm.addEvent('responseError', function(response) {
			$('account_submitter').disabled = false;
		});
		
		$('createAccountForm').addEvent('submit', function (e) {
			e.stop();
			$('account_submitter').disabled = true;
		});
	},
	
	editAccount: function() {
		var contactForm = new AjaxForm ({
			form: $('editAccountForm'),		//Form element
			log: $('returnEditAccount') 		//Log element (Texte et image de retour)
		});
		
		contactForm.addEvent('responseSuccess', function(response) {
			var errorEditAccount = new Fx.Slide('returnEditAccount').slideOut();
			this.reset_style();
			this.reset_values();
			Sexy.info(response.message);
			$('account_submitter').disabled = false;
		});
		
		contactForm.addEvent('responseError', function(response) {
			$('account_submitter').disabled = false;
		});
		
		$('editAccountForm').addEvent('submit', function (e) {
			e.stop();
			$('account_submitter').disabled = true;
		});
	},

	actionPlan: function() {
		var actionPlanForm = new AjaxForm ({
			form: $('actionPlanForm'),		//Form element
			log: $('returnActionPlan') 		//Log element (Texte et image de retour)
		});
		
		actionPlanForm.addEvent('responseSuccess', function(response) {
			var errorActionPlan = new Fx.Slide('returnActionPlan').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			location.href = response.target;
			$('action_submitter').disabled = false;
		});
		
		actionPlanForm.addEvent('responseError', function(response) {
			$('action_submitter').disabled = false;
		});
		
		$('actionPlanForm').addEvent('submit', function (e) {
			e.stop();
			$('action_submitter').disabled = true;
		});
	},

	updateActionPlan: function() {
		$$('.save_text_done').each (
			function(el) {
				//el.removeEvent('click', function(evt) { alert('removed'); });
				el.addEvent('click', function(event) {
					//$('ajax_loading').setStyle('visibility', 'visible');
					var status_text_missing_error = $('status_text_missing_error').value;
					var myBlock = el.getParents('.actionPlanViewer');
					var parent_survey_id = parseInt(myBlock.getProperty('parent_survey_id'));
					$$('#'+myBlock.getProperty('id')+' .text-done').each (
											
						function(txtArea) {
							if(txtArea.value !="")
							{
								var jsonRequest = new Request.JSON({
									url: "ajax/update_action_plan_status.php",
									onComplete: function(result) {
										if(result.success){
											txtArea.getParent().getParent().set('html', result.page);
										} else {
											Sexy.error(result.message);
										}
									}
								}).post({
									'survey': parseInt(myBlock.getProperty('survey')),
									'parent_survey_id': parent_survey_id,
									'id': parseInt(myBlock.getProperty('action_plan_item')),
									'week': parseInt(myBlock.getProperty('week')),
									'week_range_id': parseInt(myBlock.getProperty('week_range_id')),
									'text': txtArea.value,
									'action': 'text-done'
								});
							}
							else
							{
								Sexy.error(status_text_missing_error);
							}
						}
					);
				});
			}
		);
 
		
		$$('.save_text_will').each (
									
			function(el) {
				el.addEvent('click', function(event) {
					//$('ajax_loading').setStyle('visibility', 'visible');
					var myBlock = el.getParents('.actionPlanViewer');
					var parent_survey_id = parseInt(myBlock.getProperty('parent_survey_id'));
					var status_text_missing_error = $('status_text_missing_error').value;
					$$('#'+myBlock.getProperty('id')+' .text-will').each (
						function(txtArea) {
							if(txtArea.value !="")
							{
								var jsonRequest = new Request.JSON({
									url: "ajax/update_action_plan_status.php",
									onComplete: function(result) {
										if(result.success){
											txtArea.getParent().getParent().set('html', result.page);
										} else {
											Sexy.error(result.message);
										}
									}
								}).post({
									'survey': parseInt(myBlock.getProperty('survey')),
									'parent_survey_id': parent_survey_id,
									'id': parseInt(myBlock.getProperty('action_plan_item')),
									'week': parseInt(myBlock.getProperty('week')),
									'week_range_id': parseInt(myBlock.getProperty('week_range_id')),
									'text': txtArea.value,
									'action': 'text-will'
								});
							}
							else
							{
								Sexy.error(status_text_missing_error);
							}
						}
					);
				});
			}
		);
		
		$$('.failed').each (
			function(el) {
				el.addEvent('click', function(event) {
					//$('ajax_loading').setStyle('visibility', 'visible');
					var myBlock = el.getParents('.actionPlanViewer');
					var parent_survey_id = parseInt(myBlock.getProperty('parent_survey_id'));
					var jsonRequest = new Request.JSON({
						url: "ajax/update_action_plan_status.php",
						onComplete: function(result) {
							//alert('Failed -> ' + JSON.encode(result));
							//alert($$('#'+myBlock.getProperty('id')).getChildren('.actionPlanTitle').length);
							if(result.success=='redirect'){
								document.location.href='quizz_results.php?survey='+parent_survey_id+'&rtype=6';		
							}
							if(result.success){
								$$('#'+myBlock.getProperty('id')).getChildren('.actionPlanTitle').each(function(e2){ e2.addClass('failed');});
								$$('#'+myBlock.getProperty('id')).getChildren('.actionPlanStatus').each(function(e2) { e2.dispose(); });
							} else {
								Sexy.error(result.message);
							}
						}
					}).post({
						'survey': parseInt(myBlock.getProperty('survey')),
						'parent_survey_id': parent_survey_id,
						'id': parseInt(myBlock.getProperty('action_plan_item')),
						'week': parseInt(myBlock.getProperty('week')),
						'week_range_id': parseInt(myBlock.getProperty('week_range_id')),
						'success': 0,
						'action': 'status'
					});

				});
			}
		);
		
		$$('.success').each (
				
			function(el) {
				
				el.addEvent('click', function(event) {
					//$('ajax_loading').setStyle('visibility', 'visible');
					var myBlock = el.getParents('.actionPlanViewer');
					var parent_survey_id = parseInt(myBlock.getProperty('parent_survey_id'));
					var jsonRequest = new Request.JSON({
						url: "ajax/update_action_plan_status.php",
						onComplete: function(result) {
							if(result.success=='redirect'){
								document.location.href='quizz_results.php?survey='+parent_survey_id+'&rtype=6';		
							}
							if(result.success){
								$$('#'+myBlock.getProperty('id')).getChildren('.actionPlanTitle').each(function(e2){ e2.addClass('success');});
								$$('#'+myBlock.getProperty('id')).getChildren('.actionPlanStatus').each(function(e2) { e2.dispose(); });
							} else {
								Sexy.error(result.message);
							}
						}
					}).post({
						'survey': parseInt(myBlock.getProperty('survey')),
						'parent_survey_id': parent_survey_id,
						'id': parseInt(myBlock.getProperty('action_plan_item')),
						'week': parseInt(myBlock.getProperty('week')),
						'week_range_id': parseInt(myBlock.getProperty('week_range_id')),
						'success': 1,
						'action': 'status'
					});

				});
			}
		);
	},

	checkout: function() {
		var checkoutForm = new AjaxForm ({
			form: $('checkoutForm'),		//Form element
			log: $('returnCheckout') 		//Log element (Texte et image de retour)
		});
		
		checkoutForm.addEvent('responseSuccess', function(response) {
			var errorCheckout = new Fx.Slide('returnCheckout').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//location.href = https + 'order.php?pm=' + response.data.billing_payment_method;
			location.href = https + 'order.php?pm=ogone';
			$('submitter').disabled = false;
		});
		
		checkoutForm.addEvent('responseError', function(response) {
			$('submitter').disabled = false;
		});
		
		$('checkoutForm').addEvent('submit', function (e) {
			e.stop();
			$('submitter').disabled = true;
		});
	},
	
	//Added By E - Sales Conquest
	checkoutBilling: function() {
		var checkoutBillingForm = new AjaxForm ({
			form: $('checkoutBillingForm'),		//Form element
			log: $('returnUpdateBilling') 		//Log element (Texte et image de retour)
		});
		
		checkoutBillingForm.addEvent('responseSuccess', function(response) {
			var errorCheckoutBilling = new Fx.Slide('returnUpdateBilling').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//location.href = response.target;
			location.href = 'checkout_confirm.php';
			$('stepsubmitter').disabled = false;
		});
		
		checkoutBillingForm.addEvent('responseError', function(response) {
			$('stepsubmitter').disabled = false;
			
		});
		
		$('checkoutBillingForm').addEvent('submit', function (e) {
			e.stop();
			$('stepsubmitter').disabled = true;
		});
	},
	
	checkoutLoginFn: function() {
		var checkoutLoginForm = new AjaxForm ({
			form: $('checkoutLoginForm'),		//Form element
			log: $('returnCheckoutLogin') 		//Log element (Texte et image de retour)
		});
		
		checkoutLoginForm.addEvent('responseSuccess', function(response) {
			var errorCheckoutBilling = new Fx.Slide('returnCheckoutLogin').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//location.href = response.target;
			location.href = 'checkout_confirm.php';
			$('submitCheckoutLogin').disabled = false;
		});
		
		checkoutLoginForm.addEvent('responseError', function(response) {
			$('submitCheckoutLogin').disabled = false;
			
		});
		
		$('checkoutLoginForm').addEvent('submit', function (e) {
			e.stop();
			$('submitCheckoutLogin').disabled = true;
		});
	},
	
	createAccountCheckout: function() {
		var createAccountFormCheckout = new AjaxForm ({
			form: $('createAccountFormCheckout'),		//Form element
			log: $('returnCreateAccountCheckout') 		//Log element (Texte et image de retour)
		});
		
		createAccountFormCheckout.addEvent('responseSuccess', function(response) {
			var errorCreateAccountCheckout = new Fx.Slide('returnCreateAccountCheckout').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//location.href = response.target;
			location.href = 'checkout_confirm.php';
			$('account_submitter_checkout').disabled = false;
		});
		
		createAccountFormCheckout.addEvent('responseError', function(response) {
			$('account_submitter_checkout').disabled = false;
			
		});
		
		$('createAccountFormCheckout').addEvent('submit', function (e) {
			e.stop();
			$('account_submitter_checkout').disabled = true;
		});
	},
	
	createAccountQuiz: function() {
		var createAccountQuizForm = new AjaxForm ({
			form: $('createAccountQuizForm'),		//Form element
			log: $('returnCreateAccountQuiz') 		//Log element (Texte et image de retour)
		});
		
		createAccountQuizForm.addEvent('responseSuccess', function(response) {
			var errorCreateAccountQuiz = new Fx.Slide('returnCreateAccountQuiz').slideOut();
			this.reset_style();
			this.reset_values();
			//Sexy.info(response.message);
			//Google AdWords
			$('create_account_response').set('html', response.html);
			location.href = response.target;
			$('account_submitter').disabled = false;
		});
		
		createAccountQuizForm.addEvent('responseError', function(response) {
			$('account_submitter').disabled = false;
		});
		
		$('createAccountQuizForm').addEvent('submit', function (e) {
			e.stop();
			$('account_submitter').disabled = true;
		});
	},
	
	//Sidebox login
	quizLogin: function () {
		//Initialise les sliders
		/*loginSlide = new Fx.Slide('login');
		accountSlide = new Fx.Slide('myAccount');

		if ($('login').hasClass('invisible')) {
			loginSlide.hide();
		} else {
			accountSlide.hide();
		}*/
		
		/* Formulaire de login */
		var quizLoginForm = new AjaxForm ({
			form: $('quizLoginForm'),		//Form element
			log: $('returnQuizLogin') 		//Log element (Texte et image de retour)
		});
	
			// Login r�ussi
		quizLoginForm.addEvent('responseSuccess', function(response) {
			/*loginSlide.slideOut().chain(function () {
				//Affiche le box My Account
				accountSlide.slideIn();
				$('myAccount').setStyle('height', 'auto');
				$('loginName').empty().set('html', response.data['login']);
				//Cache le compte Login
				loginForm.options.slide.slideOut();
				loginForm.reset_style();
				loginForm.reset_values();
			});*/
			//location = https + 'survey_list.php';
			location.href = response.target;
		});
	},
	//partner slider
	partnerSlider: function() { 
			var partnerCount = $('partner_sidebox_nb_partners').value;
			var sliderItemWidth = $('partner_sidebox_img_width').value;
			var sliderItemHeight = $('partner_sidebox_img_height').value;

			var sMoo = new SlideItMoo({
						overallContainer: 'SlideItMoo_vertical_outer',
						elementScrolled: 'SlideItMoo_vertical_inner',
						thumbsContainer: 'SlideItMoo_vertical_items',		
						itemsVisible:partnerCount,
						elemsSlide:1,
						duration:300,
						itemsSelector: '.SlideItMoo_element',
						itemWidth: sliderItemWidth,
						itemHeight: sliderItemHeight,
						slideVertical: true,
						showControls:1,
						direction:-1,
						autoSlide:null,
						onChange: function(index){
							
							
							
						}
			
			});
		},
		
		//partner slider home - E -Sales conquest - Feb 22, 2011
		partnerSliderHome: function() {
			var partnerCount = $('partner_homebox_nb_partners').value;
			var sliderItemWidth = $('partner_homebox_img_width').value;
			var sliderItemHeight = $('partner_homebox_img_height').value;
			
			var hMoo = new SlideItMoo({
						overallContainer: 'SlideItMoo_outer',
						elementScrolled: 'SlideItMoo_inner',
						thumbsContainer: 'SlideItMoo_items',		
						itemsVisible:partnerCount,
						elemsSlide:1,
						duration:300,
						itemsSelector: '.SlideItMoo_element',
						itemWidth: sliderItemWidth,
						itemHeight: sliderItemHeight,
						showControls:1,
						startIndex:5,
						onChange: function(index){
							
						}
			
			});
		},
	
		//dropDownMenu slider
		dropDownMenu: function() {
		$('drop_down_menu').getElements('li.menu').each( function( elem ){
			var list = elem.getElement('ul.links');	
			if(list)
			{
			var myFx = new Fx.Slide(list).hide();			
			elem.addEvents({
				'mouseenter' : function(){ 					
					myFx.cancel();
					myFx.slideIn();					
				},
				'mouseleave' : function(){ 
					myFx.cancel();
					myFx.slideOut();					
				}
			});	
			}
		});
		},
		showFeedbackIndicatorsOverall: function(){
		$$('.resultsIndicatorsBar').each (
			function(el) {
				el.addEvent('click', function(event) {
					//Hide box content
					$$('.quizzIndicatorsFeedbackTips').each (
						function(box) {
							//box.empty().set('html', '');
							box.setStyle('display', 'none');
						}
					);
					
					var indicator = el.getProperty('indicator_id');
					var feedback = el.getProperty('feedback');
					if (feedback == 1) {
						$('feedbackIndicators'+indicator).setStyle('display', 'block');
						//Scroll auto
						//var myFx = new Fx.Scroll(window).toElement('indicatorsCategoryTarget' + el.getProperty('category_id'));
						var myFx = new Fx.Scroll(window).toElement('feedbackIndicators' + indicator);
						
					}
				});
			}
		);
	},
	//E - Sales Conquest
	
	ticker: function(){
		var news = new cvNewsTicker('tickerPartners',{speed:1000,delay:5000,direction:'vertical'})
	},
	
	//Slider des offres
	offerSlider: function() {
		
		Array.each($$('.p_info'), function(element) {
			var mySlideFx = new Fx.Slide(element.getProperty('id'));
			mySlideFx.hide();
			
			element.getParent('.first').getFirst('h2').getFirst('.click_info').addEvent('click', function(e) {
				mySlideFx.toggle();
			});
		});
	},
	
	tabsHome: function() {
		// On parcourt chaque panel
		$$('.homebox').each(function(panelElt) {
			// On récupère les onglets ...
		    var tabs = panelElt.getFirst('ul').getElements('a');
			var tablis = panelElt.getFirst('ul').getElements('li');
			
						
		    // Et on les parcourt à leur tour
		    tabs.each(function(tab) {
		    	/*
		       	* Ajout de l'évèment click
		       	*/
		      	tab.addEvent('click', function() {
		        	// On regarde si le panel-content lié à cet onglet existe
		        	var contentDiv = $(this.rel);
		        	if(contentDiv != null) {
		          		// Si c'est le cas, on masque les panel-content
		          		panelElt.getElements('div').removeClass('display');
		          		// On déselectionne tous les onglets
		          		panelElt.getFirst('ul').getElements('li').removeClass('active');
		          		// On affiche le panel-content sélectionné
		          		contentDiv.addClass('display');
		          		// On sélectionne l'onglet
		          		this.getParent().addClass('active');
		        	}
		
		        	return false;
		      	});
				
				$$('#home_buy_button').addEvent('click', function() {
		        	// On regarde si le panel-content lié à cet onglet existe
		        	var contentDiv = $(this.rel);
					var resultTab = $$('#home_buy_button').getProperty('restab');
					//alert(resultTab);
		        	if(contentDiv != null) {
		          		// Si c'est le cas, on masque les panel-content
		          		panelElt.getElements('div').removeClass('display');
		          		// On déselectionne tous les onglets
		          		panelElt.getFirst('ul').getElements('li').removeClass('active');
		          		// On affiche le panel-content sélectionné
		          		contentDiv.addClass('display');
		          		// On sélectionne l'onglet
		          		$$('#'+resultTab).addClass('active');
						var myFx = new Fx.Scroll(window).toElement('main');
		        	}
		
		        	return false;
		      	});
				
		    });
			tablis.each(function(tabli) {
		    	/*
		       	* Ajout de l'évèment click
		       	*/
		      	tabli.addEvent('click', function() {
		        	// On regarde si le panel-content lié à cet onglet existe
		        	var contentDivli = $(this.getProperty('rel'));
		        	if(contentDivli != null) {
		          		// Si c'est le cas, on masque les panel-content
		          		panelElt.getElements('div').removeClass('display');
		          		// On déselectionne tous les onglets
		          		panelElt.getFirst('ul').getElements('li').removeClass('active');
		          		// On affiche le panel-content sélectionné
		          		contentDivli.addClass('display');
		          		// On sélectionne l'onglet
		          		this.addClass('active');
		        	}
		
		        	return false;
		      	});
		    });
		});
	},
	
	// order status list box - E - Sales conquest - Feb 24, 2011
	initOrderStatusList: function() {
	
		$('order_status_list').addEvent('change', function(e) {
			var selected = $('order_status_list').selectedIndex;
			location = $('order_status_list').options[selected].value;
		});
	}
	
};

window.addEvent('domready', Site.start);
//window.addEvent('load', Site.setEditor);

//once the DOM is ready
window.addEvent('domready', function() {
	
if($('progressBar1'))
{
	/* create the progress bar 1 */
	pb1 = new dwProgressBar({
		container: $('progressBar1'),
		startPercentage: 10,
		speed:1000,
		boxID: 'progressBox1',
		percentageID: 'progressPerc1',
		displayID: 'progressText',
		displayText: false,
		step:15,
		onComplete: function() {
			//alert('Done!');
		},
		onChange: function() {
			//alert('Changed!');
		}
	});
	pb1.set($('progressBar1Value').value);
}
if($('progressBar2'))
{
	/* create the progress bar 2 */
	pb2 = new dwProgressBar({
		container: $('progressBar2'),
		startPercentage: 10,
		speed:1000,
		boxID: 'progressBox2',
		percentageID: 'progressPerc2',
		displayID: 'progressText',
		displayText: false,
		step:15,
		onComplete: function() {
			//alert('Done!');
		},
		onChange: function() {
			//alert('Changed!');
		}
	});
	 
	pb2.set($('progressBar2Value').value); 
}
});

//simple hide and show element - E- Sales Conquest - Dec 29, 2010
window.addEvent('domready',function(){
Element.extend(
			{
			show:function(e){
			this.setStyle('display','block');
			},
			hide:function(e){
				this.setStyle('display','none');
			}
		}
		);
});
