﻿var doc = document.location.href;
langue = "fr";
if (langue == "fr") {
	var link_panier = "/fr/panier.htm";
	var txtlink_panier = "Finaliser ma commande";
	var txtlink_continue = "Continuer mes achats";
	var mess_panier1 = "Cet article a bien été ajouté à votre panier";
	var mess_panier2 = "";
}
else {
	var link_panier = "/en/panier.htm";
	var txtlink_panier = "Finalise my order";
	var txtlink_continue = "Continue shopping";
	var mess_panier1 = "This item has been added to your basket";
	var mess_panier2 = "";
}

function movePanierPopup(elt) {
	if(document.all) {
		var temp = availDimScreen();
		document.getElementById(elt).style.left = temp[2];
	}
	var temporisation = new Array(1,3,2,8);
	new Effect.MoveBy(elt, 350, 0, {
		duration:temporisation[0], fps:12, afterFinishInternal: function(effect) {
			new Effect.MoveBy(elt, 0, 0, {duration:temporisation[1], fps:12, afterFinishInternal: function(effect) {
				new Effect.MoveBy(elt, -300, 0, {duration:temporisation[2], fps:12, afterFinishInternal: function(effect) {
					new Effect.MoveBy(elt, 0, 0, {duration:temporisation[3], fps:12, afterFinishInternal: function(effect) {
						new Effect.Fade(elt);
					}})
				}})
			}})
		}});
}

function availDimScreen() {
	// tableau de retour : largeur, hauteur, centreX, centreY
	var availDimScreen = new Array(0,0,0,0);
	
	availDimScreen[0] = (document.documentElement.clientWidth)?document.documentElement.clientWidth:window.innerWidth;
	availDimScreen[1] = (document.documentElement.clientHeight)?document.documentElement.clientHeight:window.innerHeight;
	availDimScreen[2] = Math.ceil(availDimScreen[0]/2);
	availDimScreen[3] = Math.ceil(availDimScreen[1]/2);

	return(availDimScreen);
}

function customPanierPopup() {
	var conteneurPopupPanier = document.createElement('div');
	conteneurPopupPanier.id = 'conteneurPopupPanier';
	document.body.appendChild(conteneurPopupPanier);
	
	var messPopupPanier = document.createElement('div');
	messPopupPanier.id = 'messPopupPanier';
	conteneurPopupPanier.appendChild(messPopupPanier);
	
	var txtMessPP1 = document.createTextNode(mess_panier1);
	messPopupPanier.appendChild(txtMessPP1);
	
	messPopupPanier.innerHTML += mess_panier2;
	
	var linkPopupPanier = document.createElement('p');
	linkPopupPanier.id = 'linkPopupPanier';
	conteneurPopupPanier.appendChild(linkPopupPanier);
	var aLinkPopupPanier = document.createElement('a');
	linkPopupPanier.appendChild(aLinkPopupPanier);
	aLinkPopupPanier.href=link_panier;
	var txtLinkMesPP = document.createTextNode(txtlink_panier);
	aLinkPopupPanier.appendChild(txtLinkMesPP);
	
	var linkContinue = document.createElement('p');
	linkContinue.id = 'linkContinue';
	conteneurPopupPanier.appendChild(linkContinue);
	var aLinkContinue = document.createElement('a');
	linkContinue.appendChild(aLinkContinue);
	aLinkContinue.href=doc;/*Lien de la page courrante*/
	var txtLinkMesContinue = document.createTextNode(txtlink_continue);
	aLinkContinue.appendChild(txtLinkMesContinue);
	/*
	aLinkContinue.onclick = function() {
		document.body.removeChild(document.getElementById('conteneurPopupPanier'));
	}
	*/
	movePanierPopup('conteneurPopupPanier');
}

/****************************************************/
/*				EFFACE VALUE						*/
/****************************************************/

function effaceValue() {
	$('inputRecherche').onclick = function(){
		$('inputRecherche').value = "";
	};
}

function verifCheck() {
	$$(".inputRadio").each(
		function(e, index) {
			if(e.checked){
				e.parentNode.next('p').className = "obligatoire";
			}
			e.onclick = function() {
				if(this.checked){
					$$(".inputCourriel").each(
						function(e, index) {
							e.parentNode.className = "";
						}
					);
					this.parentNode.next('p').className = "obligatoire";
					prepareForm();
				}
			}
		}
	);
	prepareForm();
}

/****************************************************/
/*				INITIALISATION DE LA PAGE			*/
/****************************************************/
function addLoadListenerPage(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	} else if (document.addEventListener) {
		document.addEventListener("load", func, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", func);
	}
}

if (document.getElementById && document.createTextNode) {
	addLoadListenerPage(function() {
		effaceValue();
		if ($("formPanier")) verifCheck();
		//if(panierExiste != 0) customPanierPopup();
	});
}
