// 2009
//-- XHR - utiliser doCall

var xhr_object = null;
if(window.XMLHttpRequest) // Ff
  xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // IE
  xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else {
  alert("Votre navigateur est incompatible avec ce site");
}

var xhr_fifo = null;

function xhr_call(filename,func,data,retfunc) // ne pas appeler directement
{
  this.filename = filename;
  this.func = func;
  this.data = data;
  this.retfunc = retfunc;
  this.next = null;
  this.last = null;
  this.exec = function() { execCall(this.filename,this.func,this.data,this.retfunc); }
}
 
function doCall(filename,func,data,retfunc)
{
  var xc = new xhr_call(filename,func,data,retfunc);
  if (xhr_fifo==null)
  {
     xhr_fifo = xc;
     xhr_fifo.last = xhr_fifo;
     xhr_fifo.exec();
  }
  else
  {
     xc.last = xc;
     xhr_fifo.last.next = xc;
     xhr_fifo.last = xc;
  }
}

function execCall(filename,func,data,retfunc) // ne pas appeler directement
{
	data = "func="+func+"&"+data
  	if (xhr_object==null) return;
  
	var method   = "POST";
	xhr_object.open(method, filename, true);
	  
	xhr_object.onreadystatechange = function() {
	  if(xhr_object.readyState == 4) {
//	    alert(xhr_object.responseText);
	    if (xhr_object.responseText!="")
	    {
	      var ret;
	      try{
	      eval("ret="+xhr_object.responseText);
	      }
	      catch(e)
	      {
	    	  ret = {ret:"Erreur du serveur"};
	      }
	      if (ret.ret=="OK")
	      {
	        retfunc(ret);
	      }
	      else {
	    	  gereErreur(ret.ret);
	      }
	      xhr_fifo = xhr_fifo.next;
	      if (xhr_fifo!=null) { setTimeout("xhr_fifo.exec()",300); }
	    }
	    else{
	    	gereErreur("Pas de réponse du serveur");
	    }
	  }
	}

	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(data);
}
var preg=new RegExp("([+])", "g");
function uec(s)
{
	//return(encodeURIComponent(s));
	return(escape(s).replace(preg,"%2B"));
}
//-- wheel

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
var wheelfunc = null;
function handle(delta) {
	if (wheelfunc==null) return(false);
        if (delta < 0)
        	return(wheelfunc(-1));
        else
        	return(wheelfunc(1));
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        var res = false;
        if (delta)
        	res = handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if ((res)&&(event.preventDefault))
                event.preventDefault();
	event.returnValue = !res;
}
if (window.addEventListener)
    /** DOMMouseScroll is for mozilla. */
    window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;

var keymanagefunc = null;
var keymanagefunc2 = null;
function keymanage(e) {
	if (keymanagefunc==null) return(true);
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	return(keymanagefunc(code));
}

window.onkeydown = keymanage;

//-- div

function showElt(e)
{
  e.style.height="";
  e.style.visibility="visible";
}
function hideElt(e)
{
  e.style.height="1px";
  e.style.visibility="hidden";
  e.style.overflow="hidden";
}

function showDiv(divid)
{
  var di = document.getElementById(divid);
  if (di==null) return;
  showElt(di);
}
function hideDiv(divid)
{
  var di = document.getElementById(divid);
  if (di==null) return;
  hideElt(di);
}

function mkhtml(e)
{
  return(document.createElement(e));
}
function mkaddhtml(e,o)
{
  var elt = document.createElement(e);
  o.appendChild(elt);
  return(elt);
}
function getelt(i)
{
  return(document.getElementById(i));
}

function windowWidth()
{
  var d = document.body.parentNode.clientWidth;
  if (d==0) d = window.innerWidth;
  return(d);
}
function windowHeight()
{
  var d = document.body.parentNode.clientHeight;
  if (d==0) d = window.innerHeight;
  return(d);
}

function getTop (e) {
	var o=e.offsetTop;
	while ((e=e.offsetParent) != null) { o += e.offsetTop; }
	return o;
}

function getLeft (e) {
	var o=e.offsetLeft;
	while ((e=e.offsetParent) != null) { o += e.offsetLeft; }
	return o;
}

//-- centrer div principale
var mainDiv = null;
var mainDivWidth = 960;
var mainDivLeft = 0;
function centerMainDiv() 
{
	if (mainDiv==null) return;
	mainDiv.style.position="absolute";
	var w = mainDiv.offsetWidth;
	if (w<10) w = mainDivWidth;
	var mdl = (windowWidth()-w)/2;
	if (mdl<0) mdl = 0;
	if (Math.abs(mainDivLeft-mdl)>25)
	{
		mainDivLeft = mdl;
		mainDiv.style.left=mainDivLeft+"px";
	}
	mainDiv.style.top="0px";
}

//-- mvt

var gstMvt = null;

function makedivdepl() // ne pas appeler directement
{
	if ((gstMvt.modedeplfirst==0)&&((Math.abs(gstMvt.mousestx-gstMvt.mousex)>10)||(Math.abs(gstMvt.mousesty-gstMvt.mousey)>10)))
	{
		if (gstMvt.modedepl_md==null)
		{
			var md = mkhtml('div');
			gstMvt.modedepl_md = md;
			md.className="mvbx";
			md.style.position = "absolute";
			document.body.appendChild(md);
			md.onmouseup = function onmouseup(event)
			{
				stopmodedepl(gstMvt.modedepl_div);
			}
		}
		gstMvt.modedeplfirst = 1;
		var md = gstMvt.modedepl_md;
		md.style.left = (gstMvt.mousex-50)+"px";
		md.style.top = (gstMvt.mousey-20)+"px";
		md.innerHTML=gstMvt.modedepl_div.id;
		md.style.visibility = "visible";
		// gstMvt.modedepl_dest.style.visibility  = "visible";
		if (gstMvt.eventInit!=null) gstMvt.eventInit(); 
	}
}
function bodymousemove(evenement) // ne pas appeler directement
{
	if ((typeof(event) == "undefined")||(event.clientX==null))
	{
	gstMvt.mousex = evenement.pageX;
	gstMvt.mousey = evenement.pageY;
	}else{
	gstMvt.mousex = event.clientX;
	gstMvt.mousey = event.clientY;
	}
	if (gstMvt.modedepl==1)
	{
		makedivdepl();
		
		var d = new Date();
		var ms = d.getMilliseconds();
		if (ms<gstMvt.lastms) gstMvt.lastms=gstMvt.lastms-1000;
		if (ms-gstMvt.lastms>20)
		{
			gstMvt.lastms=ms;
			if ((gstMvt.modedepl_md)&&(gstMvt.modedepl_md.style.visibility == "visible"))
			{
				gstMvt.modedepl_md.style.left = (gstMvt.mousex-50)+"px";
				gstMvt.modedepl_md.style.top = (gstMvt.mousey-20)+"px";
			}
			if ((gstMvt.eventMove!=null)&&(gstMvt.modedeplfirst==1)) gstMvt.eventMove(gstMvt.mousex,gstMvt.mousey); 
		}
	}
 }
function stopmodedepl(dv) // ne pas appeler directement sauf besoin particulier
{
	if (gstMvt.modedepl_div!=dv) return;
	gstMvt.modedepl=0;
	gstMvt.modedeplfirst=0;
	if (gstMvt.modedepl_md==null) return;
	gstMvt.modedepl_md.style.visibility = "hidden";
	gstMvt.modedepl_md.style.left="0px";
	gstMvt.modedepl_md.style.top="0px";

	if (gstMvt.eventDrop!=null) gstMvt.eventDrop(gstMvt.mousex,gstMvt.mousey);
/*
	gstMvt.modedepl_dest.style.visibility = "hidden";
	var y = Math.floor(1+(gstMvt.mousey-10)/120);
	if (y<1) y = 1; if (y>=boxcpt) y = boxcpt-1;
        boxmove(y);
        */
}

function gestionMvt(einit, emove, edrop) // ne pas appeler directement
{
	this.mousex=0;
	this.mousey=0;
	this.mousestx=0;
	this.mousesty=0;
	this.modedepl=0;
	this.modedeplfirst = 0;
	this.modedepl_div = null;
	this.modedepl_md = null;
	//this.modedepl_dest = null;
	this.lastms = -1000;
	this.eventInit = einit;
	this.eventMove = emove;
	this.eventDrop = edrop;

	document.onmousemove = bodymousemove;
	//document.onselectstart = function() {return false;}
}

function activemodedepl(dv) // appeler lors d'un clic sur un objet deplacable (dv), doit avoir un id
{
	gstMvt.mousestx = gstMvt.mousex;
	gstMvt.mousesty = gstMvt.mousey;
	gstMvt.modedepl_div=dv;
	gstMvt.modedepl=1;
	gstMvt.modedeplfirst = 0;
	gstMvt.lastms = -1000;
}

function initGestionMvt(einit, emove, edrop) // initialise la gestion des deplacer
{
	gstMvt = new gestionMvt(einit, emove, edrop);
}

//-- overlay

var overlaydiv=null;
var opainit = 5;
function makeoverlay()
{
	if (overlaydiv==null)
	{
		var od = mkhtml('div');
		var ods = od.style;
		ods.position = "absolute";
		ods.left="0px";
		ods.top="0px";
		ods.width=windowWidth()+"px";
		ods.height=windowHeight()+"px";
		ods.backgroundColor="#000000";
		ods.opacity=0.5;
		ods.filter="alpha(opacity=50)"; 
		ods.zIndex=10;
		overlaydiv = od;
		overlaydiv.opa = opainit;
		window_onscroll();
		document.body.appendChild(od);
	}
	//overlaydiv.style.opacity=overlaydiv.opa*0.1;
	overlaydiv.style.visibility="visible";
	overlaydiv.visible = true;
	//if (overlaydiv.opa<5) setTimeout('overlaytimer()', 40);
}
function overlaytimer()
{
	overlaydiv.opa += 1;
	overlaydiv.style.opacity=overlaydiv.opa*0.1;
	if (overlaydiv.opa<5) setTimeout('overlaytimer()', 40);
}
function hideoverlay()
{
	if (overlaydiv!=null)
	{
		overlaydiv.style.visibility="hidden";
		overlaydiv.opa = opainit;
		overlaydiv.visible = false;
	}
}


//-- mixte

var resizetime = 0;
var resizelastms = 0;
var resizelastx = 0;
var resizelasty = 0;
function window_resize()
{
	resizelastms = resizelastms-1;
	var tx = windowWidth();
	var ty = windowHeight();

	if ((tx!=resizelastx)||(ty!=resizelasty))
	{
		resizelastx = tx;
		resizelasty = ty;
		if (overlaydiv!=null)
		{
			overlaydiv.style.width=tx+"px";
			overlaydiv.style.height=ty+"px";
		}
		centerMainDiv();
	
		resizelastms = 6;
	}
	setTimeout('window_resize_retry()', 100);
}
function window_resize_retry()
{
	if (resizelastms>0)
	{
		window_resize();
	}
}
function window_onscroll() {
	var da=document.documentElement.scrollTop;
	if (document.body.scrollTop>da) da = document.body.scrollTop;
	var db=document.documentElement.scrollLeft;
	if (document.body.scrollLeft>db) db = document.body.scrollLeft;
	if (overlaydiv!=null)
	{
		overlaydiv.style.top =  da+"px";
		overlaydiv.style.left =  db+"px";
	}
	window_resize();
}

window.onresize=window_resize;
window.onscroll=window_onscroll;


//--- popup calendrier

var datecal_div = null;

var datecal_jrs = new Array("Lun.","Mar.","Mer.","Jeu.","Ven.","Sam.","Dim.");
var datecal_mois = new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre");

function datecalAff()
{
 var mois=datecal_div.mois.value-1;
 var annee=datecal_div.annee.value;
 var cdt = new Date();
 var jour=-1;

 var dte = new Date(annee,mois,1,0,0,0,0);
 var dcl =dte.getDay()-1;
 if (dcl<0) dcl=6;
 
 var mxj = 31;
 var ns;
 var nj;
 var snj;

 if ((mois==cdt.getMonth())&&(annee==cdt.getFullYear())) { jour=cdt.getDate(); }
 if ((mois==3)||(mois==5)||(mois==8)||(mois==10)) { mxj=30; }
 if (mois==1)
 {
   mxj=28;
   if ((annee%4==0)&&((annee%100!=0)||(annee%400==0))) { mxj=29; }
 }
 var cpt = 0;
 var jours = datecal_div.jours;
 for (cpt=0;cpt<dcl;cpt++) { jours[cpt].innerHTML = "&nbsp;"; jours[cpt].val = 0; }
 for (nj=0;nj<mxj;nj++)
 {
   snj = "" + (nj+1); if (snj.length<2) { snj = "0"+snj;  }
   jours[cpt].innerHTML = snj;
   jours[cpt].val = 1+nj;
   cpt++;
   //if (nj+1==jour) { res = res.substr(0,res.length-1)+"#"+snj+"#"; }
   //else { res = res+snj+" "; }
 }
 for (;cpt<42;cpt++) { jours[cpt].innerHTML = "&nbsp;"; jours[cpt].val = 0; }
}

function datecal_clic()
{
	var v = this.val;
	if (v<1) return;
	if (v<10) v="0"+v;
	var m = datecal_div.mois.value; 
	if (m<10) m="0"+m;
	datecal_div.input.value=v+"/"+m+"/"+datecal_div.annee.value;
	datecalHide();
}
function datecalInit(input)
{
	if (datecal_div==null)
	{
		var d = mkhtml("div");
		var ds = d.style;
		ds.visibility = "hidden";
		var i;
		var j;
		var s;
		datecal_div = d;
		
		d.className="boxpop";
		ds.position = "absolute";
		ds.left="40%";
		ds.top="20%";
		ds.zIndex=30;
		
		d.titre = mkaddhtml("p",d);
		
		d.mois = mkaddhtml("select",d);
		for (i=0;i<12;i++)
		{
		    d.mois.options[i] = new Option(datecal_mois[i],i+1,false,false);
		}
		d.mois.onchange = datecalAff;
		d.annee = mkaddhtml("select",d);
		for (i=0;i<50;i++)
		{
			s = i+2000;
		    d.annee.options[i] = new Option(s,s,false,false);
		}
		d.annee.onchange = datecalAff;
		mkaddhtml("br",d);
		
		var jtable = mkaddhtml("table",d);
		var jtb = mkaddhtml("tbody",jtable);
		jtb.cellspacing="2";
		jtb.cellpadding="2";
		var jtr = mkaddhtml("tr",jtb);
		var jtd;
		for (i=0;i<7;i++)
		{
			jtd = mkaddhtml("td",jtr);
			jtd.innerHTML=datecal_jrs[i];
		}
		
		d.jours = new Array();
		for(j=0;j<6;j++)
		{
			jtr = mkaddhtml("tr",jtb);
			for (i=0;i<7;i++)
			{
				jtd = mkaddhtml("td",jtr);
				jtd.className="caltd";
				jtd.innerHTML="&nbsp;";
				jtd.onclick=datecal_clic;
				d.jours[i+j*7] = jtd;
			}
			
		}
		var btns = mkaddhtml("div",d);
		btns.innerHTML="<input type='button' value='Annuler' onClick='datecal_div.style.visibility=\"hidden\"';datecal_div.input=null;/>";
		document.body.appendChild(d);
	}
	
	var dd = datecal_div;
	
	if (dd.input==input)
	{
		dd.input=null;
		hideElt(dd);
		return;
	}
	
	dd.input = input;
	
	dd.style.left = (110+getLeft(input))+"px";
	dd.style.top = (0+getTop(input))+"px";
	showElt(dd);
	
	var v = input.value;
	dd.mois.value=1*v.substr(3,2);
	dd.annee.value=1*v.substr(6,4);

	datecalAff();
}
function datecalHide()
{
	hideElt(datecal_div);
	datecal_div.input = null;
}

//--- popup infos

var popup_div = null;

function popupInit(ref,texte,decx)
{
	if (popup_div==null)
	{
		var d = mkhtml("div");
		var ds = d.style;
		ds.visibility = "hidden";
		var i;
		var j;
		var s;
		popup_div = d;
		
		d.className="boxpop";
		ds.position = "absolute";
		ds.zIndex=30;
		
		d.texte = mkaddhtml("div",d);
		
		document.body.appendChild(d);
	}

	
	var dd = popup_div;
	dd.texte.innerHTML = texte;
	dd.ref = ref;
	dd.style.left = (decx+getLeft(ref))+"px";
	dd.style.top = (0+getTop(ref))+"px";
	dd.style.visibility = "visible";
}

function popupHide()
{
	var dd = popup_div;
	if (dd==null) return;
	dd.style.visibility = "hidden";
}


//--- modales globales

var quotainfo = null;
var locurl = null;

function retDeco()
{
	window.location="index.jsp";
}
function deconnexion()
{
	var data = "";
	doCall("_session.jsp","quit",data,retDeco);
	setTimeout('retDeco()', 1000);
	affMessage("Déconnexion ...");
}

function gereErreur(m)
{
	alert(m);
	if (locurl==null)
	{
		window.location.reload();
	}
}

function affquota(q)
{
	var r = "";
	if (q<=1) r = q+" crédit";
	else  r = q+" crédits";
	if (quotainfo!=null) quotainfo.innerHTML = r;
}

var divmsg = null;
var divmsglbl = null;
function affMessage(s,od)
{
	if (divmsg==null) return;
	window.scrollTo(0, 0);
	makeoverlay();
	divmsglbl.innerHTML = s;
	if (od!=null)
	{
		overlaydiv.style.zIndex=30;
		divmsg.od = true;
		keymanagefunc2 = keymanagefunc; 
		keymanagefunc = function(v) { if (v==27) hideMessage(); return(true); }
	}
	else
	{
		overlaydiv.style.zIndex=10;
		divmsg.od = false;
		keymanagefunc = function(v) { if (v==27) hideMessage(); return(true); }
	}
	showElt(divmsg);
}
function hideMessage()
{
	divmsg.titre.innerHTML = "";
	if (divmsg.od)
	{
		keymanagefunc = keymanagefunc2;
		overlaydiv.style.zIndex=10;
	}
	else
	{
		keymanagefunc = null;
		hideoverlay();
	}
	hideElt(divmsg);
}


var divwait = null;
var divwaitlbl = null;
function affWaitMessage(s,t,od)
{
	if (divwait==null) return;
	window.scrollTo(0, 0);
	makeoverlay();
	divwaitlbl.innerHTML = s;
	divwait.titre.innerHTML = t;
	if (od!=null)
	{
		overlaydiv.style.zIndex=30;
		divwait.od = true;
		keymanagefunc2 = keymanagefunc; 
		keymanagefunc = function(v) { return(false); }
	}
	else
	{
		overlaydiv.style.zIndex=10;
		divwait.od = false;
		keymanagefunc = function(v) { return(false); }
	}
	showElt(divwait);
}
function hideWaitMessage()
{
	divwait.titre.innerHTML = "";
	if (divwait.od)
	{
		keymanagefunc = keymanagefunc2;
		overlaydiv.style.zIndex=10;
	}
	else
	{
		keymanagefunc = null;
		hideoverlay();
	}
	hideElt(divwait);
}


var divconf = null;
var divconflbl = null;
var divconfretf = null;
function affConfirmation(s,retf)
{
	if (divconf==null) return;
	window.scrollTo(0, 0);
	makeoverlay();
	divconflbl.innerHTML = s;
	divconfretf = retf;
	showElt(divconf);
	keymanagefunc = null;
}
function hideConfirmation()
{
	hideElt(divconf);
	hideoverlay();
	keymanagefunc = null;
}

var divcontact = null;
function affContact()
{
	if (divcontact!=null)
	{
		window.scrollTo(0, 0);
		var fi = document.frmcontact;
		fi.email.value = "";
		fi.sujet.value = "";
		fi.message.value = "";
		fi.nom.value="";
		fi.prenom.value="";
		fi.answer.value="";
		
		if ((client!=null)&&(client!=""))
		{
			fi.email.value = client.email;
			fi.nom.value=client.lastname;
			fi.prenom.value=client.firstname;
		}

		var c = getelt("captchacontact");
		if (c.aff==0) { c.src=captchaIRL(); c.aff=1; }
		
		makeoverlay();
		divcontact.style.left=(mainDivLeft+150)+"px"; 
		divcontact.style.zIndex=20;
		divcontact.style.visibility="visible";
		keymanagefunc = function(v) { if (v==27) closeContact(); return(true); }
	}
}
function closeContact()
{
	hideoverlay();divcontact.style.visibility='hidden';
	keymanagefunc=null;
}

function retSendContact(ret)
{
	hideMessage();
	if (ret.contact=="OK")
	{
		divcontact.style.visibility='hidden';
		keymanagefunc=null;
		affMessage("Message envoyé");
	} else {
		affMessage(ret.contact,true);		
	}
}

function doSendContact()
{
	var fi = document.frmcontact;
	if ((fi.email.value=="")||(fi.sujet.value=="")||(fi.message.value=="")||(fi.nom.value=="")||(fi.prenom.value=="")||(fi.answer.value==""))
	{
		affMessage("Merci de remplir les champs obligatoires",true);
		return;
	}
	var verif = /^[\.a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/ ;
	if (verif.exec(fi.email.value) == null)
	{
		affMessage("Merci d'indiquer une adresse Email correcte",true);
		return;
	}
	var data = "email="+uec(fi.email.value)+"&sujet="+uec(fi.sujet.value)+"&message="+uec(fi.message.value)+"&nom="+uec(fi.nom.value)+"&prenom="+uec(fi.prenom.value)+"&answer="+uec(fi.answer.value);
	doCall("_session.jsp","contact",data,retSendContact);
	affMessage("Envoi en cours",true);
}

var divmoncompte = null;
var client = null;

function retMoncompte(ret)
{
	divmoncompte.info.innerHTML = "";
	if (ret.editcompte=="OK")
	{
		client = ret.client;
		affMoncompteClient();
	}
	else
	{
		alert(ret.editcompte);
		gereErreur(ret.editcompte);
		return;
	}
	
	var hl = ret.histoloc;
	var i;
	var tab = getelt("tablehistoloc");
	var l;
	for (l = tab.rows.length-1;l>=1;l--) tab.deleteRow(l);
	var h;
	var tr;
	var td;
	
    for (i=0;(i<hl.length)&&(i<100);i++)
    {
    	h = hl[i];
    	tr = mkaddhtml("tr",tab);
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="150px";
    	td.innerHTML=h.user;
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="120px";
    	td.innerHTML=h.datepos;
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="50px";
    	if (h.status)
    	{
    		td.innerHTML="Succès";
    		td.style.color="#00A000";
    	}
    	else
    	{
    		td.innerHTML="Echec";
    		td.style.color="#FF0000";
    	}
    	td = mkaddhtml("td",tr); td.className="tdg";
    	if (h.status)
    	{
    		td.innerHTML="1";
    	}
    	else
    	{
    		td.innerHTML="0";
    	}
    }

	hl = ret.histotxn;
	tab = getelt("tablehistotxn");
	for (l = tab.rows.length-1;l>=1;l--) tab.deleteRow(l);
	var typ;
	var reg;
    for (i=0;(i<hl.length)&&(i<100);i++)
    {
    	h = hl[i];
    	if (h.typ==1)
    	{
    		typ = "Pack"; reg="CB / Paypal";
    	}
    	if (h.typ==2)
    	{
    		typ = "Abon."; reg="Paypal";
    	}
    	if (h.typ==3)
    	{
    		typ = "Unité"; reg="SMS";
    	}
    	tr = mkaddhtml("tr",tab);
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="50px";
    	td.innerHTML=typ;
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="80px";
    	td.innerHTML=h.nb;
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="150px";
    	td.innerHTML=h.datetxn;
    	td = mkaddhtml("td",tr); td.className="tdg";
    	td.style.width="80px";
    	td.innerHTML=reg;
    }
    
    affquota((1*client.quotaloc)+(1*client.quotaabo));
}
function affMoncompteClient()
{
	var fi = document.formcompte;
	fi.lastName.value=client.lastname;
	fi.firstName.value=client.firstname;
	fi.email.value=client.email;
	fi.phone.value=client.phone;

	getelt("quotaloc").innerHTML=client.quotaloc;
	getelt("quotalocdate").innerHTML=client.quotalocdate;
	getelt("quotaabo").innerHTML=client.quotaabo;
	getelt("quotaabodate").innerHTML=client.quotaabodate;
	
	fi = document.formchpass;
	fi.password.value="";
	fi.newpass1.value="";
	fi.newpass2.value="";
}
function affMoncompte()
{
	affMoncompteClient();
	makeoverlay();

	var etds = getelt("moncomptetds");
//	etds.style.width="5px";
//	etds.style.border="1px solid #000000";
//	etds.style.borderRight="1px solid #000000";
	etds.className="brv";
	
	divmoncompte.style.left=(mainDivLeft+40)+"px";
	divmoncompte.style.height="";
	divmoncompte.style.zIndex=20;
	divmoncompte.info.innerHTML = "Mise à jour ...";
	showElt(divmoncompte);
	
	var data = "";
	doCall("_session.jsp","editcompte",data,retMoncompte);
	
	keymanagefunc = function(v) { if (v==27) closeMoncompte(); return(true); }
}
function closeMoncompte()
{
	hideElt(divmoncompte);
	hideoverlay();
	keymanagefunc = null;
}

function retNewPass(ret)
{
	divmoncompte.info.innerHTML = "";
	if (ret.chpass=="OK")
	{
		var fi = document.formchpass;
		fi.password.value="";
		fi.newpass1.value="";
		fi.newpass2.value="";
		affMessage("Mot de passe enregistré",true);
	}
	else
	{
		affMessage(ret.chpass,true);
	}
}

function doNewPass()
{
	var fi = document.formchpass;
	var pwd = fi.password.value;
	var new1 = fi.newpass1.value;
	var new2 = fi.newpass2.value;
	
	if (new1!=new2)
	{
		affMessage("Les saisies du nouveau mot de passe ne sont pas identiques.",true);
		return;
	}
	if (new1=="")
	{
		affMessage("Vous devez saisir un nouveau mot de passe.",true);
		return;
	}
	
	var data = "password="+uec(pwd)+"&newpwd="+uec(new1);
	doCall("_session.jsp","chpass",data,retNewPass);
	divmoncompte.info.innerHTML = "Enregistrement en cours ...";
}

var divachatcredit = null;
var achatpacksel = null;
var achatabosel = null;
function doAchatCredit()
{
	if (divachatcredit!=null)
	{
		getelt("if_cgv_achat").src="cgvif.jsp";
		window.scrollTo(0,0);
		makeoverlay();
		hideDiv("achatabolistdiv");
		hideDiv("achatdesabodiv");
		divachatcredit.style.left=(mainDivLeft+100)+"px";
		divachatcredit.style.zIndex=20;
		doCall("_paiement.jsp","testabo","",retTestAbo);
		divachatcredit.infoabo.innerHTML="Chargement ...";
		
		divachatcredit.achatvalidation.innerHTML = "";		
		achatDesactiveBtn();
		document.achatcgv.okbtn.disabled = true;
		
		hideDiv("divachatpassecgv");
		hideDiv("divachatvalidcgv");
		var etape = getelt("etape34");
		if (client.cgv_valid)
		{
			etape.innerHTML="3";
			showDiv("divachatpassecgv");
		}
		else
		{
			etape.innerHTML="4";
			showDiv("divachatvalidcgv");
		}

		showElt(divachatcredit);
		
		keymanagefunc = function(v) { if (v==27) hideAchatCredit(); return(true); }
	}
}
function retTestAbo(ret)
{
	if (divachatcredit.style.visibility!="visible") return;
	divachatcredit.infoabo.innerHTML="";
	if (ret.abo=="")
	{
		showDiv("achatabolistdiv");
	}
	else
	{
		var t = ret.abo.nbloc+" crédits par mois";
		if (ret.abo.promo!="") t=t+" ("+ret.abo.promo+")";
		divachatcredit.abolib.innerHTML = t;
		showDiv("achatdesabodiv");
	}
}
function genAchatCreditList()
{
	var lp = divachatcredit.lstpack;
	var sp = divachatcredit.spanpack;
	var i;
	var h = "<table style='margin-top:10px;margin-left:30px;'><tr>";
	var p;
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		h = h + "<td valign='bottom'><div class=\"bloc-credit-pack\"><input class='imgbtn' onClick=\"selectPack(this);return(false);\" name=\""+p.id+"\" type=\"image\" src=\"pack/pack"+p.id+"_0.png\" value=\""+p.lib+" pour "+p.couts+" Euros\"/><br/><p>"+p.couts+" Euros</p></div></td>\n";
	
	}
	h = h + "</tr></table>";
	sp.innerHTML = h;
	
	h="";
	sp = divachatcredit.promopack;
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		if (p.promo)
		{
		h = h + "<table class='promo_lg' width='100%'><tr><td class='promo_t'>PROMO</td><td class='promo_l'>"+p.promo.p1+" crédits offerts pour tout achat d'un pack de "+p.nbloc+" requêtes jusqu'au "+p.promo.fin+"</td></tr></table>\n";
		}
	}
	sp.innerHTML = h;
	
	lp = divachatcredit.lstabo;
	sp = divachatcredit.spanabo;
	h = "<table style='margin-top:10px;'><tr>";
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		h = h + "<td valign='bottom' style='padding-right:25px;'><div class=\"bloc-credit-abonnement\"><input class='imgbtn' onClick=\"selectAbo(this);return(false);\" name=\""+p.id+"\" type=\"image\" src=\"pack/pack"+p.id+"_0.png\" value=\""+p.lib+" pour "+p.couts+" Euros\"/><br/><p>"+p.couts+" Euros</p></div></td>\n";
	}
	h = h + "</tr></table>";
	sp.innerHTML = h;

	h="";
	sp = divachatcredit.promoabo;
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		if (p.promo)
		{
		h = h + "<table class='promo_lg' width='100%'><tr><td class='promo_t'>PROMO</td><td class='promo_l'>"+p.promo.p1+" crédits offerts pendant "+p.promo.p2+" mois pour tout achat d'un abonnement de "+p.nbloc+" requêtes jusqu'au "+p.promo.fin+"</td></tr></table>\n";
		}
	}
	sp.innerHTML = h;
}
var lstpackinp = null;
var lstpackid = null;
function deselectPack(inp)
{
	if (lstpackinp!=null) lstpackinp.src = "pack/pack"+lstpackid+"_0.png";
	lstpackinp = inp;
}
function selectPack(inp)
{
	deselectPack(inp);		
	var rech = inp.name
	var lp = divachatcredit.lstpack;
	var i;
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		if (p.id==rech) achatpacksel = p;
	}
	inp.src = "pack/pack"+achatpacksel.id+"_1.png"; lstpackid = achatpacksel.id; 
	
	divachatcredit.seltype = 1;
	divachatcredit.sellib = inp.value;
	affAchatValidation();
}
function selectAbo(inp)
{
	deselectPack(inp);		
	var rech = inp.name
	var lp = divachatcredit.lstabo;
	var i;
	for (i=0;i<lp.length;i++)
	{
		p = lp[i];
		if (p.id==rech) achatabosel = p;
	}
	inp.src = "pack/pack"+achatabosel.id+"_1.png"; lstpackid = achatabosel.id;
	
	divachatcredit.seltype = 2;
	divachatcredit.sellib = inp.value;
	affAchatValidation();
}
function selectSMS(inp)
{
	deselectPack(inp);		
	divachatcredit.seltype = 3;
	divachatcredit.sellib = inp.value;
	affAchatValidation();
	inp.src = "pack/pack31_1.png"; lstpackid = "31";
}

function affAchatValidation()
{
	document.achatcgv.okbtn.disabled = true;	
	achatDesactiveBtn();
	divachatcredit.achatvalidation.innerHTML = "<table><tr><td style='width:470px;'>Vous avez sélectionné : <br/><b><i>"+divachatcredit.sellib+"</b></i> </td><td> <input type=\"button\" value=\"Valider\" onClick=\"doAchatValidetion();\" style='margin-left:5px;margin-right:30px;font-weight:bold;'/> <i><span style='font:10px'>ou modifier votre sélection<span></i></td></tr></table>";
}
function achatDesactiveBtn()
{
	divachatcredit.btnpackpaypal.disabled = true;
	divachatcredit.btnabopaypal.disabled = true;
	divachatcredit.btnpacksms.disabled = true;
	divachatcredit.btnpackpaypal.src="img/btn-acheter_d.png";
	divachatcredit.btnpackpaypal2.src="img/btn-acheter_d.png";
	divachatcredit.lblpackpaypal.innerHTML="";
	divachatcredit.btnabopaypal.src="img/btn-paypal_d.png";
	divachatcredit.btnpacksms.src="img/btn-sms_d.jpg";
	divachatcredit.lblpacksms.innerHTML="";
}
function achatActiveBtn()
{
	if (divachatcredit.seltype==1){
		divachatcredit.btnpackpaypal.disabled = false;
		divachatcredit.btnpackpaypal.src="img/paypack1.gif";
		divachatcredit.btnpackpaypal2.src="img/paypack2.gif";
		divachatcredit.lblpackpaypal.innerHTML="&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
	}
	if (divachatcredit.seltype==2){
		divachatcredit.btnabopaypal.disabled = false;
		divachatcredit.btnabopaypal.src="img/payabo.gif";
	}
	if (divachatcredit.seltype==3){
		divachatcredit.btnpacksms.disabled = false;
		divachatcredit.btnpacksms.src="img/btn-sms.jpg";
		divachatcredit.lblpacksms.innerHTML="micro paiement SMS";
	}
}
function doAchatValidetion()
{
	if (client.cgv_valid)
	{
		achatActiveBtn();
	}
	else
	{
		var fi = document.achatcgv;
		fi.okbtn.disabled=false;
	}
}

function doAchatValidCGV()
{
	var fi = document.achatcgv;
	if (!fi.okcgv.checked)
	{
		affMessage("Vous devez acceptez les Conditions Générales de GeoFamily pour acheter des crédits",true);
		return;
	}
	var data = "";
	doCall("_session.jsp","validcgv",data,retAchatValidCGV);
}
function retAchatValidCGV(ret)
{
	if (ret.validcgv=="OK")
	{
		if (ret.client!=null) client = ret.client;
		achatActiveBtn();
	}
	else
	{
		affMessage(ret.validcgv,true);
	}
}

function submitPackPaypal()
{
	if (achatpacksel==null) return(false);
	var f = document.packpaypal;
	f.item_name.value = achatpacksel.lib;
	f.item_number.value = achatpacksel.id;
	f.amount.value = achatpacksel.cout;
	
	return(true);
}

function submitAboPaypal()
{
	if (achatabosel==null) return(false);
	var f = document.abopaypal;
	f.item_name.value = achatabosel.lib;
	f.item_number.value = achatabosel.id;
	f.a3.value = achatabosel.cout;
	
	return(true);
}

function hideAchatCredit()
{
	deselectPack(null);
	hideDiv("achatabolistdiv");
	hideDiv("achatdesabodiv");
	hideoverlay();
	hideElt(divachatcredit);
	window.scrollTo(0,0);
	keymanagefunc = null;
}

function captchaIRL()
{
	var d = new Date();
	return('captchaImg?d='+d.getHours()+d.getMinutes()+d.getSeconds()+d.getMilliseconds());	
}

var chkreg=new RegExp("([<>])", "g");
function chkstr(s)
{
//	return(s.replace(chkreg," "));
	return(s);
}

var affreg=new RegExp("([&])", "g");
var affreg2=new RegExp("([<])", "g");
function affstr(s)
{
	return(s.replace(affreg,"&amp;").replace(affreg2,"&lt;"));
}
