// JavaScript Document
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function PopupCentrer(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function checkEmail(emailAddr) {
	// Cette fonction vérifie la bon format d'une adresse e-mail.
	// Comme :
	// user@domain.com ou user.perso@domain.com
	
	var i;
	
	// Recherche de @
	i = emailAddr.indexOf("@");
	if (i == -1) {
		return false;
	}
	
	// Séparation du nom de l'utilisateur et du nom de domaine.
	var username = emailAddr.substring(0, i);
	var domain = emailAddr.substring(i + 1, emailAddr.length)

	// Recherche des espaces au début du nom de l'utilisateur.
	i = 0;
	while ((username.substring(i, i + 1) == " ") && (i < username.length)) {
		i++;
	}
	// Les enlève s'il en trouve.
	if (i > 0) {
		username = username.substring(i, username.length);
	}

	// Recherche d'espaces à la fin du nom de domaine.
	i = domain.length - 1;
	while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
		i--;
	}
	// Les enlève s'il en trouve.
	if (i < (domain.length - 1)) {
		domain = domain.substring(0, i + 1);
	}

	// Vérifie que le nom de l'utilisateur et du domaine ne soit pas vide.
	if ((username == "") || (domain == "")) {
		return false;
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de l'utilisateur.
	var ch;
	for (i = 0; i < username.length; i++) {
		ch = (username.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de domaine
	for (i = 0; i < domain.length; i++) {
		ch = (domain.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}

// Ajouter ci-dessous de nouveaux noms de domaine.
// Voir tous les noms de domaine sur http://www.toulouse-renaissance.net/c_outils/c-nom-domaine.htm
//
var aSuffix = new Array("com","net","int","aero","biz","museum","name","info","coop","pro","eu","edu","org","gov","mil","bj","dz","de","ad","be","ca","bf","bi","cm","cf","cg","cd","ci","dj","fr","ga","gp","gf","lu","mg","ml","ma","mq","mr","mc","nc","pf","re","pm","sn","ch","td","tf","tn","eu");
	var bFoundSuffix = false;
	i = 0;
	while (i < aSuffix.length) {
		if (("." + aSuffix[i]) == domain.substring(domain.length - aSuffix[i].length - 1, domain.length)) {
			return true;
		}
		i++;
	}
	// Si le nom de domaine est inconnu  : return false
	return false;
	
}


// GESTION du format de la date
var t_jours = new Array(12);
t_jours[0] = 31;
t_jours[1] = 28;
t_jours[2] = 31;
t_jours[3] = 30;
t_jours[4] = 31;
t_jours[5] = 30;
t_jours[6] = 31;
t_jours[7] = 31;
t_jours[8] = 30;
t_jours[9] = 31;
t_jours[10] = 30;
t_jours[11] = 31;

function calcule_fevrier(valeur) {
	if ((valeur.substring(6)/400==parseInt(valeur.substring(6)/400)) || ((valeur.substring(6)/4==parseInt(valeur.substring(6)/4)) && (valeur.substring(6)/100!=parseInt(valeur.substring(6)/100)))){
		t_jours[1] = 29;
	} else {
		t_jours[1] = 28;
	}
}

function isNaD(valeur) {
	if ((valeur.length != 8) && (valeur.length != 10)) {
		return("erreur : longueur");
	} else {
		if (valeur.charAt(2)!="/" && valeur.charAt(5)!="/") {
			//return("erreur : mauvais séparateur de champs");
			return(true);
		} else {
			if (isNaN(valeur.substring(0,2)) || isNaN(valeur.substring(3,5)) || isNaN(valeur.substring(6))) {
				//return("erreur : type de donnée des champs");
				return(true);
			} else {
				if ((valeur.substring(3,5)<0) || (valeur.substring(3,5)>12)) {
					//return("erreur : valeur du mois");
					return(true);
				} else {
					calcule_fevrier(valeur);
					if ((valeur.substring(0,2)<0) || (valeur.substring(0,2)>t_jours[valeur.substring(3,5)-1])) {
						//return("erreur : valeur du jour");
						return(true);
					} else {
						//return("date correcte");
						return(false);
					}
				}
			}
		}
	}
}


function Interverti(idPhoto){
	tmpgrande = document.getElementById("grande").src;
	tmppetite = idPhoto.src;
	document.getElementById("grande").src = tmppetite;
	idPhoto.src = tmpgrande;
}


function Deplacer(l1,l2) {
	if (l1.options.selectedIndex>=0) {
		lfin = l1.length;
		dd=0;
		for (i=0; i<lfin; i++){
			if (l1.options[(i-dd)].selected==true){
				o=new Option(l1.options[(i-dd)].text,l1.options[(i-dd)].value);
				l2.options[l2.options.length]=o;
				l1.options[(i-dd)]=null;
				dd++;
			}
		}
	}else{
		alert("Merci de sélectionner un élément de la liste");
	}
}

function open360(lien){
	var dd = lien.split("|");
	window.open( dd[0] , dd[1] , dd[2]);
}

function flash(tag) {
	document.write(tag);
}



//--- Déclaration des variables 'domaine' et 'date d'expiration'
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
date_exp.setTime(date_exp.getTime()+(365*24*3600*1000));


function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset) ;
	if (endstr == -1) { endstr=document.cookie.length ; }
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name)
{
	var arg = name + "=" ;
	var alen = arg.length ;
	var clen = document.cookie.length ;
	var i = 0 ;
	while (i<clen)
	{
		var j = i + alen ;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j) ;
        i = document.cookie.indexOf(" ", i) + 1 ;
        if (i==0) break ;
    }
	return null ;
}

function setCookie (name, value)
{
	var argv = setCookie.arguments ;
	var argc = setCookie.arguments.length ;
	var expires =(argc > 2) ? argv[2] : null ;
	var path=(argc > 3) ? argv[3] : null ;
	var domain=(argc > 4) ? argv[4] : null ;
	var secure=(argc > 5) ? argv[5] : false ;
	
	document.cookie = name + "=" + escape(value) +
					  ((expires==null) ? "" : ("; expires="+expires.toGMTString())) +
					  ((path==null) ? "" : ("; path="+path)) +
					  ((domain==null) ? "" : ("; domain="+domain)) +
					  ((secure==true) ? "; secure" : "") ;
}

function deleteCookie (name)
{	
	setCookie (name, '') ;
}

//-------------------------------------------------------------||
// FUNCTION:    addProduct                                     ||
// PARAMETERS:  id, value							           ||
// RETURNS:     null                                           ||
// PURPOSE:     Ajoute un produit dans le cookie du caddie     ||
//-------------------------------------------------------------||
function addProduct (id, value)
{
	// Si le cookie n'existe pas, le produit n'a pas encore été sélectionné
	// --------------------------------------------------------------------
	if (!getCookie(id))
	{
		//----- inscription du cookie correspondant
		setCookie(id, value) ;
		//----- mise a jour du cookie productIDList
		var newID = (!getCookie('idList'))? id : '!' + id ;
		setCookie('idList', getCookie('idList') + newID) ;
	}
	// Sinon on met le cookie existant a jour,
	// --------------------------------------
	else
		setCookie(id, eval(value) + eval(getCookie(id))) ;
		
	//----- ouverture d'une popUp de recapitulation
	popUp('/asp/ConfirmPopUp.asp?productID=' + id + '&productQuantity=' + value, '500', '240', true, false) ;		
}

//----------------------------------------------------------||
// FUNCTION:    displayShopCart                             ||
// PARAMETERS:  null					                    ||
// RETURNS:     null                                        ||
// PURPOSE:     Affiche le caddie dans une popUp			||
//----------------------------------------------------------||
function displayShopCart()
{
	// Si le caddie est vide, on ne l'affiche pas
	// ------------------------------------------
	if (!getCookie('idList')) { alert('Votre sélection est vide...') ; return ;	}
			
	//------ redirection vers le caddie
	document.location.href = 'selection.asp' ;	    
}

//---------------------------------------------------------------------||
// FUNCTION:    changeQuantity				                           ||
// PARAMETERS:  input, increment					                   ||
// RETURNS:     null                                                   ||
// PURPOSE:     Augmente ou diminue la quantite dans la boutique       ||
//---------------------------------------------------------------------||
function changeQuantity(input, increment)
{
	if (input.value > 0) { input.value = eval(input.value) + increment ; }
}

//---------------------------------------------------------------------||
// FUNCTION:    changeShopCartQuantity                                 ||
// PARAMETERS:  id, input, increment			                       ||
// RETURNS:     null                                                   ||
// PURPOSE:     Augmente ou diminue la quantite au sein du caddie      ||
//---------------------------------------------------------------------||
function changeShopCartQuantity(id, input, increment)
{	
	// Si la quantité arrive à zero, suppression du produit
	// ----------------------------------------------------
	if (input.value == 1 && increment < 0)	{ eraseProduct(id) ; return ; }
	
	//----- appel de la fonction qui incremente le champ text
	changeQuantity(input, increment) ;	
	//----- maj du le cookie existant
	setCookie(id, escape(input.value)) ;
	//----- maj des changements du caddie
	document.location.reload();
}

//-----------------------------------------------------------||
// FUNCTION:    eraseProduct                                 ||
// PARAMETERS:  productID				                     ||
// RETURNS:     null                                         ||
// PURPOSE:     Efface un produit des cookies et du tab      ||
//-----------------------------------------------------------||
function eraseProduct(id)
{
	if (window.confirm('Etes-vous sur de vouloir supprimer ce bien de votre sélection ?'))
	{
		//----- suppression du cookie
		deleteCookie(id) ;
		//----- récupération de la chaine d'identifiant
		var strIdList = getCookie('idList') ;
		
		// Si il n'y a qu'un seul article dans le caddie, on efface le cookie
		// ------------------------------------------------------------------
		if (strIdList.indexOf('!') < 0)
		{
			//----- suppression des cookies
			deleteCookie('idList') ;
			//----- redirection vers la page de commande
			document.location.href = './selection.asp' ;
		}
		// Sinon plusieurs produits sont présents, suppression du bon
		// ----------------------------------------------------------
		else
		{
			// Si c le premier identifiant de la liste, suppression du '!' qui le suit
			// ------------------------------------------------------------------------
			if (strIdList.indexOf(id) == 0)			
				strIdList = strIdList.replace(id + '!', '') ;
				
			// Sinon suppression du '!' qui le précède
			// ---------------------------------------
			else 
				strIdList = strIdList.replace('!' + id, '') ;						
									
			//----- maj du cookie idList
			setCookie('idList', strIdList) ;
			//----- maj des changements du caddie
			document.location.reload();
		}
	}
}

//Function ouvrant un popUp
function popUp(url, width, height, bCenter, bScrollBar)
{

	var popUp ;

	//---------la popUp ne doit pas etre centrée
	if (!bCenter)
	{
		var calcLeft = 50;
		var calcTop = 50;		
	}
	//---------la popUp doit etre centrée
	else
	{
		var calcLeft = 400;
		var calcTop = 300;		
		
		//---------si la version du navigateur > 4 alors on peut centrer la popUp
		if (parseInt(navigator.appVersion) >= 4)
		{
			calcTop = screen.availHeight /2 - height ;
			calcLeft = screen.availWidth / 2 - width / 2 ;
		}
	}
	
	//------------si la version du navigateur est > 3
	if (parseInt(navigator.appVersion) > 3)
	{
		var sb = (bScrollBar) ?',scrollbars' :'' ;
		popUp = window.open('' + url + '', null,'top=' + calcTop + ',left=' + calcLeft + ',height=' + height + ',width=' + width + ',resizable' + sb) ;
		popUp.focus() ;						
    }
    else alert("Vous avez besoin d'un browser dont la version est supérieure à 3.");
}


//-->
