﻿//----------------------------------------------------- 
//David Delpierre
//Attention les flux retournés en AJAX sont attendus par défaut en UTF-8

//recopie en local dans le fichier pour certitude de fontionnement.
//-----------------------------------------------------


var Messages = 
{
		"KO"                 : "Une erreur technique est survenue : veuillez nous en excuser...",
		"ERR_PANIER_DEBORDE" : "Ajout impossible : le nombre d&prime;articles différent dans le panier ne peut d&eacute;passer 20 articles",
		"ERR_REF01" 		   : "Erreur reference inexistante!",  
		"ERR_QTE_MAX" 	   : "Ajout impossible : la quantité; pour un article du panier ne peut être sup&eacute;rieure à 99",
		"ERR01"			   : "Erreur de connexion : identifiant inconnu",	
		"ERR02"			   : "Erreur de connexion : le mot de passe saisi n'est pas valide",
		"ERR03"			   : "Erreur de connexion : merci de renseigner votre adresse email ou numéro de client ainsi que votre mot de passe",
		"ERR0"			   : "Erreur de déconnexion suite à une erreur technique. La fermeture de votre navigateur entraînera automatique la déconnexion de votre compte."
}

//astuce pour régler les erreurs de syntaxe dans l'API ATOS, GRRR

var  KO="KO";
var  ERR_PANIER_DEBORDE="ERR_PANIER_DEBORDE";
var  ERR_REF01="ERR_REF01";
var  ERR_QTE_MAX="ERR_QTE_MAX";
var  ERR01="ERR01";
var  ERR02="ERR02";
var  ERR03="ERR03";
var  ERR0="ERR0";
//----------------------------------------------------------------------------------------------------------------------------------------


function localize(str){
	var s;
	if(Messages && (s=Messages[str]) ) return s;
	return "Une erreur non identifiée est survenue...";
}


//-----------------------------------------------------
var dropdowncontent={
		delaybeforehide: 200,
		disableanchorlink: true, 

		getposOffset:function(what, offsettype){
	return (what.offsetParent)? what[offsettype]+this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
},

isContained:function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
		else
			return false
},

show:function(anchorobj, subobj, e){
	if (!this.isContained(anchorobj, e)){
		var horizontaloffset=(subobj.dropposition[0]=="left")? -(subobj.offsetWidth-anchorobj.offsetWidth) : 0  
				var verticaloffset=(subobj.dropposition[1]=="top")? -subobj.offsetHeight : anchorobj.offsetHeight  
						//subobj.style.left=this.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px"

						subobj.style.left="480px"
							subobj.style.top=this.getposOffset(anchorobj, "offsetTop")+verticaloffset+"px"
							subobj.style.clip=(subobj.dropposition[1]=="top")? "rect(auto auto auto 0)" : "rect(0 auto 0 0)"  
								subobj.style.visibility="visible"
									subobj.startTime=new Date().getTime()
									subobj.contentheight=parseInt(subobj.offsetHeight)
									if (typeof window["hidetimer_"+subobj.id]!="undefined")  
										clearTimeout(window["hidetimer_"+subobj.id])
										this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
	}
},

curveincrement:function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2  
},

slideengine:function(obj, direction){
	var elapsed=new Date().getTime()-obj.startTime  
	if (elapsed<obj.glidetime){  
		var distancepercent=(direction=="down")? this.curveincrement(elapsed/obj.glidetime) : 1-this.curveincrement(elapsed/obj.glidetime)
				var currentclip=(distancepercent*obj.contentheight)+"px"
				obj.style.clip=(direction=="down")? "rect(0 auto "+currentclip+" 0)" : "rect("+currentclip+" auto auto 0)"
						window["glidetimer_"+obj.id]=setTimeout(function(){dropdowncontent.slideengine(obj, direction)}, 10)
	}
	else{  
		obj.style.clip="rect(0 auto auto 0)"
	}
},

hide:function(activeobj, subobj, e){
	if (!dropdowncontent.isContained(activeobj, e)){
		window["hidetimer_"+subobj.id]=setTimeout(function(){
			subobj.style.visibility="hidden"
				subobj.style.left=subobj.style.top=0
				clearTimeout(window["glidetimer_"+subobj.id])
		}, dropdowncontent.delaybeforehide)
	}
},


myshow:function(anchorid) {
	var anchorobj=document.getElementById(anchorid)
	var subobj=document.getElementById(anchorobj.getAttribute("rel"))
	var horizontaloffset=(subobj.dropposition[0]=="left")? -(subobj.offsetWidth-anchorobj.offsetWidth) : 0  
			var verticaloffset=(subobj.dropposition[1]=="top")? -subobj.offsetHeight : anchorobj.offsetHeight  

					subobj.style.left="480px"
						subobj.style.top=this.getposOffset(anchorobj, "offsetTop")+verticaloffset+"px"
						subobj.style.clip=(subobj.dropposition[1]=="top")? "rect(auto auto auto 0)" : "rect(0 auto 0 0)"  
							subobj.style.visibility="visible"
								subobj.startTime=new Date().getTime()
								subobj.contentheight=parseInt(subobj.offsetHeight)
								if (typeof window["hidetimer_"+subobj.id]!="undefined")  
									clearTimeout(window["hidetimer_"+subobj.id])
									this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down");
	window["glidetimer_"+subobj.id] = setTimeout( function(){
		subobj.style.visibility="hidden"
			subobj.style.left=subobj.style.top=0
			clearTimeout(window["glidetimer_"+subobj.id])
	}, 2000 );
},


init:function(anchorid, pos, glidetime){
	var anchorobj=document.getElementById(anchorid)
	var subobj=document.getElementById(anchorobj.getAttribute("rel"))
	subobj.dropposition=pos.split("-")
	subobj.glidetime=glidetime || 1000
	subobj.style.left=subobj.style.top=0
	anchorobj.onmouseover=function(e){dropdowncontent.show(this, subobj, e)}
	anchorobj.onmouseout=function(e){dropdowncontent.hide(subobj, subobj, e)}
	if (this.disableanchorlink) anchorobj.onclick=function(){return false}
	subobj.onmouseout=function(e){dropdowncontent.hide(this, subobj, e)}
}
}

//----------------------------------------------------- 
//----------------------------------------------------- 
//PARAMETRAGE


sUrlApiATOS_InfoClient       = '/VAD/InfoClient';
sUrlApiATOS_AjoutArticlesVus = '/portal/portal/SiteInternet/App/Ajax/Ajax?action=2&viewId=/jsp/ajax/ajax.jsp&toInit=true&API=2&id_article=%id%&libelle_article=%lib%&prix_bas=%pv%&url_vignette=%urlimg%&url_FicheProduit=%urlfp%';
sUrlApiATOS_UnLogin          = '/VAD/Deconnexion';
sUrlApiATOS_ChangeUser       = '/VAD/Deconnexion';


//----------------------------------------------------- 
//----------------------------------------------------- 

var bustcachevar=1;
var loadedobjects="";
var rootdomain="http://"+window.location.hostname;
var bustcacheparameter="";

function Ajax_DisplayNothing () {};

function Ajax_Call(url, func4print){
	var varSessionId=getSessionId();
	var varTimeStampRefresh=getTimeStamp();
	
	$.ajax({
		url: url,
		cache: false,
		dataType: "text",
		data : {SessionId: varSessionId, TimeStampRefresh: varTimeStampRefresh},
		success: function(data){
			traitementAjaxResult(data, func4print);
		}
	});
}

/**
 * Méthode d'évaluation pour l'exécution
 * @param data données retournée par la fonction ajax
 * @param func4print Fonction à éxécuter après l'interprétation du retour ajax
 * 
 */
function traitementAjaxResult(data,func4print){
	scriptFlow =data;

	var debut = scriptFlow.indexOf("<AJAX>");
	var fin = scriptFlow.indexOf("</AJAX>");
	scriptFlow = scriptFlow.substring(debut+6,fin);

	try {
		eval(scriptFlow); 
		if(func4print!=null)
			func4print(scriptFlow) ;
	} catch(e) {
		alert(localize('KO'));
	}

}

//-------------------------------------------------
//-------------------------------------------------
//lancement AJAX automatique 
/*
last_func_win_onload = window.onload ; 

function AJAX_onload() {
	if (last_func_win_onload != null) last_func_win_onload() ;
	// image d'attente de chargement des appels Ajax ? 
	document.getElementById("toppanier").innerHTML='<img src="/VAD/res/quelle/images/commun/loading.gif">';
	//document.getElementById("articlesdejavus").innerHTML='<img src="/VAD/res/quelle/images/commun/loading.gif">';
	Ajax_Call_InfoClient ();
	//dropdowncontent.init("panier", "right-bottom", 500);
	//dropdowncontent.init("dejavuslink", "right-bottom", 500);
}

window.onload = AJAX_onload ;*/

// Fonction lancée sur chaque page
$(function(){
	
	$("body").ajaxSend(function(request, settings){
		$(".ajaxLoad").show();
		$(".notAjaxLoad").hide();
	});
	
	$("body").ajaxStop(function(request, settings){
		$(".ajaxLoad").hide();
		$(".notAjaxLoad").show();
	});
	
	$.ajaxSetup({
		cache: false,
		error: function(){
			
		
			setTimeout("alert(\"L'action en cours n'a pu aboutir, merci de réessayer ultérieurement.\");"+
			"$('.ajaxLoad').hide();"+
			"$('.notAjaxLoad').show();"+
			"$('#boutonok').show();"+
			"$('#loginLoader').hide();",30000);
	
		}		
	});

	$("#open_panier_link").attr("href","/VAD/Panier?"+getEnteteUrl());
	$("#direct").attr("href","/VAD/Panier?"+getEnteteUrl());
	
	
	Ajax_Call_InfoClient ();
	
});


//------------------------------------------------
//------------------------------------------------
//AJAX PANIER

var Ajax_Result_code=null;
var Ajax_Result_msg=null;
var Ajax_Result_host=null;

var Ajax_Panier_nbCall=0;

function result(code, message, host){
	Ajax_Result_code=code;
	Ajax_Result_msg=message;
	Ajax_Result_host=host;
}


function clearMiniPanier(){
	$(".item_mini_panier").remove();
	$("#panier_total").html("0");
	$("#panier_nbre_article").html("0");
}

function connexionAffichePass(){
	$('#pass_text').hide();
	$('#pass').show();
	$('#pass').focus();
	
}



/**
 * 
 * @param libelle
 * @param quantite
 * @param prix
 * @param libelleCouleur
 * @param libelletaille
 * @param urlVignette
 * @param urlFicheProduit
 */
function addLigneArticle(libelle,quantite,prix,libelleCouleur,libelletaille,urlVignette,urlFicheProduit){
	html = "<div class='item item_mini_panier'>"+
	"<img src='"+urlVignette+"' class='item_image' width='80'/>"+
	"<div class='item_text'><strong>"+libelle.replace(/\+/g,' ')+"</strong><br/>Couleur : "+libelleCouleur+
	"<br/>Taille : "+libelletaille+
	"<br/>Quantité : "+quantite+
	"<br/>Prix : "+getSomme(prix)+" €</div><div class='item_clear'></div></div>";

	$("#panier_rapide").prepend(html);

	nbreArticle = parseInt($("#panier_nbre_article").html());
	nbreArticle = nbreArticle+1;

	$("#panier_nbre_article").html(nbreArticle);
}

/**
 * Fonction qui renvoie la somme au bon format
 * @param prix
 * @return
 */
function getSomme(prix){
	var totLigne;
	totLigne = parseFloat(prix); 
	prix = totLigne.toFixed( 2 );
	prix = prix.replace(".",",");
	
	return prix;
}

function displayInfoAjoutPanierPopup () {
	Ajax_Panier_nbCall=0;
	if (Ajax_Result_code==1) {
		//alert("test ajout panier 2");
		CacheClient_delete();
		RAZ();
		Ajax_Call_InfoClient () ;
		//alert('Article(s) ajouté(s) au panier.');
	} else {
		alert(localize(Ajax_Result_msg));
	}
}

function Ajax_Call_AjoutArticlesvus (article_id, libelle, prix, url_img, url_FP) {

	sUrl = sUrlApiATOS_AjoutArticlesVus ;

	sUrl = sUrl.replace('%id%', encodeURI(article_id)) ;
	sUrl = sUrl.replace('%lib%', encodeURI(libelle)) ;
	sUrl = sUrl.replace('%pv%', encodeURI(prix));
	sUrl = sUrl.replace('%urlimg%', encodeURI(url_img)) ;
	sUrl = sUrl.replace('%urlfp%', encodeURI(url_FP));

	// Appel Ajax 
	Ajax_Call(sUrl, 	CacheClient_delete);
}

function Ajax_Call_AjoutPanier ( niv_oper, radicalId, article_id, libelle, couleur, codtaille, libtaille, quantite, prix, url_img, url_FP, typeAjout) {

	sUrl  = '/VAD/AjoutPanier?niv_oper='+ encodeURI(niv_oper) +'&articleId=' + encodeURI(article_id) + '&radicalId=';
	sUrl += encodeURI(radicalId) + '&taille=' + encodeURI(codtaille) + '&qte=' + encodeURI(quantite) + '&typeAjout=' + typeAjout;
	
	// Appel Ajax 
	Ajax_Panier_nbCall++;

	Ajax_Call(sUrl, function(){
		Ajax_Call_InfoClient();
	});
}

//------------------------------------------------
//------------------------------------------------
//AJAX CLIENT


//Singleton Client en cours de surf
var oClient=null;

//------------------------ Definition des objet
function SeenItem(sId, sLib, sPV, sUrlImg, sUrlPage) {
	this.sId= sId;
	this.sLib = sLib;    
	this.sPV = sPV;     
	this.sUrlImg = sUrlImg;
	this.sUrlPage = sUrlPage;
}

function OrderLine (sId, sLib, sCol, sTaille, iQty, sPV, sUrlImg, sUrlPage) {
	this.sId=sId;
	this.sLib=sLib; 
	this.sCol=sCol; 
	this.sTaille=sTaille; 
	this.iQty=iQty; 
	this.sPV=sPV; 
	this.sUrlImg=sUrlImg;
	this.sUrlPage=sUrlPage;
}

function Client(bIsLogged, sNom, sPrenom, sTotPanier, sNumCli,email,civilite){
	this.bIsLogged=bIsLogged;
	this.sNom=sNom;
	this.sPrenom=sPrenom;
	this.sNumCli=sNumCli;
	this.oPanier=new Array();
	if (typeof sTotPanier=='undefined') sTotPanier=0.00;
	this.sTotPanier=sTotPanier;
	this.oArticlesVus=new Array();
	this.email=email;
	this.civilite=civilite;
};

//------------------------ Methode appele par l'ajax pour l'instanciation et le rattachement au singleton courant

function addSeenItem (sId, sLib, sPV, sUrlImg, sUrlPage) {
	var oSeenItem = new SeenItem (sId, sLib, sPV, sUrlImg, sUrlPage);
	if (oClient!=null) oClient.oArticlesVus[oClient.oArticlesVus.length]=oSeenItem;
}


function addOrderLine(sId, sLib, sCol, sTaille, iQty, sPV, sUrlImg, sUrlPage){
	var oOrderLine=new OrderLine(sId, sLib, sCol, sTaille, iQty, sPV, sUrlImg, sUrlPage);
	if (oClient!=null) oClient.oPanier[oClient.oPanier.length]=oOrderLine;
}

//---------------------------- méthode appele par l'ajax pour l'instanciation du singleton
function createClient(bIsLogged, sNom, sPrenom, sTotPanier, sNumCli,email,civilite) {
	oClient = new Client(bIsLogged, sNom, sPrenom, sTotPanier, sNumCli,email,civilite) ;	
}



//------------------------------ Function Cache Client en cookie

//var CacheClient_Cname = "QuelleAjaxCache" ;
var CacheClient_Auth = "QuelleAuthValid";
var CacheClient_Cname = "QuelleInfoClient";
var CacheClient_Panier = "QuellePanier";


function CacheClient_set(sScriptFlow) {
	// set cookie to memorize the status during 20 minutes
	var expdate = new Date() ;
	expdate.setTime(expdate.getTime() + (1000*1200));
	document.cookie = CacheClient_Cname + "=" + encodeURI(sScriptFlow) + ";domain="+document.location.host+"; path=/; expires=" + expdate.toGMTString();
	document.cookie = CacheClient_Auth + "=" + encodeURI(sScriptFlow.replace("createClient(2,","createClient(1,")) + ";domain="+document.location.host+"; path=/;";
}

function CacheClient_delete() {
	document.cookie = CacheClient_Cname + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function CacheClient_get() {
	if (document.cookie.length>0)   {
		c_start=document.cookie.indexOf(CacheClient_Cname + "=");

		if (c_start!=-1) { 
			c_start=c_start + CacheClient_Cname.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return decodeURI(document.cookie.substring(c_start,c_end));
		}else{
			c_start=document.cookie.indexOf(CacheClient_Auth + "=");
			if (c_start!=-1) { 
				c_start=c_start + CacheClient_Auth.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return decodeURI(document.cookie.substring(c_start,c_end));
			}
		}
	}
	return null;
}

function getEnteteUrl(){
	return "SessionId="+getSessionId()+"&TimeStampRefresh="+getTimeStamp();
}

function getSessionId(){
	return  getCookie("JSESSIONID");
}

function getTimeStamp(){
	var demain=new Date();
	return  ""+demain.getDate()+demain.getMonth()+demain.getFullYear()+demain.getHours()+demain.getMinutes()+demain.getSeconds();
	
}

//----------------------------- Function d'affichage lancée pr récupération des infos clients .

function displayArticlesVus(oArticlesVus) {
	if (oArticlesVus==null || oArticlesVus.length==0){return;}
	var sHTML='';
	for (i=0 ; i<oArticlesVus.length ; i++) {
		sHTML += '<div style="font-size:11px;clear:both;height:83px;border-bottom:1px ' +
		'solid #CAA9B0;padding-bottom:5px;padding-top:3px;cursor:pointer;" onclick="FicheProduit(\''+oArticlesVus[i].sUrlPage+'\');">' +
		'<img src="/'+ oArticlesVus[i].sUrlImg +'" border=0 class="header_vignette"' +
		' style="margin-right:5px;margin-left:5px;margin-top:2px;">' + 
		'<b><font style="color:#975362">' + oArticlesVus[i].sLib + '</font></b><br>'+
		'Prix : <b>' + oArticlesVus[i].sPV +' &euro;</b>'+
		'</div>' ;
	}
	sHTML='<div style="background-color:#ffffff;width:200px;">' + sHTML + 
	'<img src="/VAD/res/quelle/images/commun/1ptrans.gif" width=1 height=1 style="clear:both;"><br>' +
	'<center><a href="#" onclick="dropdowncontent.init(\'dejavuslink\', \'right-bottom\', 500);' +
	'document.getElementById(\'articlesdejavus\').style.visibility=\'hidden\';">' + 
	'<img src="/VAD/res/quelle/images/commun/up.gif" border=0></a></center>' +
	'</div>' ;
	document.getElementById("articlesdejavus").innerHTML=sHTML;
};


function displayInfoClient() {
	
	
	
	if(oClient != null){	
		// si pas loggué on garde la mise en page du formulaire par d�efaut sinon affichage des infos de logins
		if (oClient.bIsLogged==2) {
			var domaine = (window.location.hostname.indexOf("quelle.fr") != -1) ? "https://" + window.location.hostname +"/VAD/" : "";
						
			$("#unlogin").show();
			$("#changeUser").hide();
			$("#msg_welcome").html('Bonjour '+oClient.civilite+' <br> '+oClient.sPrenom + ' ' + oClient.sNom +' !');
			$("#msg_welcome_link").html('<a href="'+ domaine +'Client?page=accueil&'+getEnteteUrl()+'" id="creationcompte">Cliquez ici pour acc&eacute;der &agrave; votre espace personnel</a>');
			$("#loginEspace").hide();
			$("#menuHeader").attr("style","left: 456px;");
			$("#espaceClient").attr("style","width: 278px; left: 685px;");
			$("#panier").attr("rel","toppanier");

		} else {
			
			if (oClient.bIsLogged==1) {
				
				$("#unlogin").hide();
				$("#changeUser").show();
				$("#loginEspace").show();
				$("#menuHeader").removeAttr("style");
				$("#espaceClient").removeAttr("style");
				$("#msg_welcome").html('Bonjour '+oClient.civilite+' <br> '+oClient.sPrenom + ' ' + oClient.sNom +' !');
				$("#msg_welcome_link").html('Entrer votre mot de passe pour acc&eacute;der &agrave; votre espace');
				$("#login").val(oClient.email);
				$("#login").hide();
				$("#ident_mail").show();

			} else {
				$("#unlogin").hide();
				$("#changeUser").hide();
				$("#menuHeader").removeAttr("style");
				$("#espaceClient").removeAttr("style");
				$("#loginEspace").show();
				$("#ident_mail").hide();
				$("#msg_welcome").html('Vous n\'avez pas encore d\'espace ?');
				$("#msg_welcome_link").html('<a href="javascript:lightbox(\'lb4\');" id="creationcompte">Créez-le ici et profitez pleinement de La Source !</a>');

				$("#login").show();

			}
		}
	} 
	
	$("#ident").show();

};

//-------------------------------------------------------------------------------
function checkResultLogin(sScriptFlow){
	$("#loginLoader").hide();
	$("#boutonok").show();
	if (Ajax_Result_code==1) {
		// écriture du cookie
		if (Ajax_Result_host!=null){
			var expdate = new Date() ;
			expdate.setTime(expdate.getTime() + (1000*3600*24*30));
			document.cookie = "QuelleCookie=" + oClient.sNumCli + "; expires=" + expdate.toGMTString() + "; path=/; domain=." + Ajax_Result_host;
		}
		
		displayInfoClient();
	} else {
		// ICI message sous une autre forme qu'une alert()?
		alert(localize(Ajax_Result_msg));
	}
}

function LoginProceed () {
	var passwordCrypte;
	var login =$("#login").val();
	var password = $("#pass").val();
	
	$("#boutonok").hide();$("#loginLoader").show();
	
	if (login.length==0 || password.length==0 ){
		alert('Merci de renseigner votre adresse email ou numéro de client');
		$("#boutonok").show();$("#loginLoader").hide();
		return false;
	}
	if(password!='')
		passwordCrypte=password;
	else
		passwordCrypte='';
	Ajax_Call_Login (login,passwordCrypte);
}



function setPrixMiniPanier(prix){

	$("#panier_total").html(getSomme(prix));
}

//----------------------------- Functions d'appel AJAX client : formatage de l'url et appel
function Ajax_Call_InfoClient () {
	

	var cookie  = getJsonCookie(CacheClient_Cname);
	var lancementAjax = false;

	var cookie_panier  = getJsonCookie(CacheClient_Panier);

	// Traitement du panier d'il y a moins de 4 articles
	
	if( cookie_panier!=null && cookie_panier.lignesCommande.length<4){
		clearMiniPanier();
		lignes = cookie_panier.lignesCommande;

		for(var i=0;i<lignes.length;i++){
			var ligne = lignes[i];
			addLigneArticle(ligne.libArt,ligne.qteCdeLigArt,ligne.totalLigne,ligne.libColoris,ligne.libelleTaille,ligne.urlVignette,ligne.urlFp);
		}

		setPrixMiniPanier(cookie_panier.mntTotCdeCli);
		// Pour rafraichir la vignette panier
		lancementAjax = true;
		
	}else{
		lancementAjax = true;
	}
	
	if (!lancementAjax && cookie!=null) {
		
		var cookie_auth  = getCookie(CacheClient_Auth);
		
		var isLogged=1;
		
		if(cookie_auth !=  null){
			var now = new Date();
			var datecook= new Date();
			datecook.setTime(datecook.getTime()+(30*60*1000));
			document.cookie =
				CacheClient_Auth+'="valide"; expires='+datecook.toGMTString()+'; path=/VAD/';
			isLogged=2;
			
		}else if((cookie != null) && (cookie.emLibNomCli != null) && (cookie.emLibNomCli!="")){
			
			isLogged=1;
		}else{
		
			isLogged=0;
		}
	}

	
	
	if(cookie !=null && cookie.emLibNomCli != null && cookie.emLibNomCli != ""){
		var civilite = "Mr";
		if(cookie.emCodIdentiteCli == "1"){
			civilite = "Monsieur";
		}else if(cookie.emCodIdentiteCli == "2"){
			civilite = "Madame";
		}else {
			civilite = "Mademoiselle";
		}
		tab = cookie.emLibNomCli.split("/");


		createClient(isLogged, tab[0], tab[1], 0, cookie.emId,cookie.emEmail,civilite);
	}

//	Lancement du chargemùent
	if(lancementAjax){
		Ajax_Call(sUrlApiATOS_InfoClient,displayInfoClient);
		
	}else{
		displayInfoClient();
	}

}

function Ajax_Call_Login (login, password) {
	Ajax_Call('/VAD/Identification?login=' + encodeURI(login) + '&pass=' + encodeURI(password), checkResultLogin);
}

function UnLoginProceed () {

	Ajax_Call("/VAD/Deconnexion");
}


function ChangeUserProceed(){
	Ajax_Call("/VAD/Deconnexion?user=clear");
	clearMiniPanier();
}




function FicheProduit(url){
	eval('window.location="'+url+'"');
}



