// *********************** BARRE DE PROGRESSION ********************//
var count=0;p1=0;
function prgs() {
   count++; p2=parseInt(5*count/nbmax);
   if (p2>p1) { p1=p2;
				document.getElementById('btn1').innerHTML=20*p2+'%';
				document.getElementById('pic1').style.width=40*p2+'px'; }
   if (count==nbmax) {
      document.getElementById('progressbar').style.display='none';
      document.getElementById('btn1').style.display='none';
      document.getElementById('btn2').style.display='none';
      document.getElementById('btn3').style.display='none';}
   }
   
// *********************** FIN DE BARRE DE PROGRESSION ********************//

var xhr_object = null; var xhr_object2 = null;
var timer;
function creation_ajax() {
	if (window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); 
	else if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
function creation_ajax2() {
	if (window.XMLHttpRequest) xhr_object2 = new XMLHttpRequest(); 
	else if (window.ActiveXObject) xhr_object2 = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
function overlb(texte) { overlib(texte, RIGHT,TEXTSIZE, 2,WIDTH, 110, FGCOLOR, '#c4c5c3',BGCOLOR,'#985050'); }
function overlb2(texte) { overlib(texte, RIGHT,TEXTSIZE, 2,WIDTH, 60, FGCOLOR, '#c4c5c3',BGCOLOR,'#985050'); } 
// *********************** FONCTIONS POUR LA PAGE PRINCIPALE (miniatures en bas de page) ********************//

function survol(i) { // asynchrone (seule solution)
	clearTimeout(timer);
	xhr_object.open("GET", "survol_index.php?i="+i, true); // true=asynchrone
	xhr_object.send(null);
	xhr_object2.open("GET", "survol_index.php?i="+i, true);
	xhr_object2.send(null);
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState != 4)  { return; }
		if (xhr_object.status == 200 && xhr_object.responseText!="")  {
					document.getElementById('bphotos2').innerHTML=xhr_object.responseText;}  }
	xhr_object2.onreadystatechange = function() {
		if (xhr_object2.readyState != 4)  { return; }
		if (xhr_object2.status == 200 && xhr_object2.responseText!="")  {
					document.getElementById('bphotos2bis').innerHTML=xhr_object2.responseText;
					timer=setTimeout('affich()',300);}  }
}

function affich() {document.getElementById('bphotos').innerHTML=document.getElementById('bphotos2').innerHTML;
							document.getElementById('bphotosbis').innerHTML=document.getElementById('bphotos2bis').innerHTML; }
							
// *************** FIN DE FONCTIONS POUR LA PAGE PRINCIPALE (miniatures en bas de page) *************//

function cadreOK() { if (parent.name!='secondaire') window.top.location.href = 'http://www.photozoom2.com'; }

// *****************  APERCU DES IMAGES **********************//

function afg(photo) { // affichage des photos en rangées dans les pages courantes
	photo=photo+"_mini.JPG";
	document.write("<img src='../../photos/"+chemin+"/"+photo+"' id='"+photo+"'class='miniature' onClick=afa('"+photo+"') onload=prgs() onmouseover=msp('"+photo+"',event) onmouseout=nd() oncontextmenu='return false'>");
return true; }

function mess_ferme() {overlib('Fermer l\'aperçu', LEFT, WIDTH,80,FGCOLOR, '#d5e3fd',DELAY ,1500,TIMEOUT ,2500);}

function msp(id,e) { /* overlib sur photo */
			url=document.getElementById(id).src;
			var a=CENTER; // pour positionner selon x
			url2=url.replace('_mini','');
			largeur=document.getElementById(id).width;
			if (largeur==150) hauteur=200; else hauteur=280; 
			if (chemin!="Media_Press/Collontrek_2009") message="Cliquez pour commander"; else message="Crédit : Photozoom";
			imgp="<table class='bandeaucaddie2' cellpadding=0 cellspacing=0><tr><td><img src='"+url2+"' height="+hauteur+"></td></tr><tr><td>"+message+"</td></tr></table>";
			if (e.pageX<250) a=RIGHT; if (e.pageX>950) a=LEFT;
			if ((e.pageY-document.body.scrollTop)>600) overlib(imgp, WIDTH,largeur,a,FGCOLOR, '#d5e3fd',ABOVE);
			else overlib(imgp, WIDTH,largeur,a,FGCOLOR, '#d5e3fd');
			}
			
function afa(id) { // affich_apercu dans pages courantes
	
	if (navigator.appName=="Microsoft Internet Explorer" ) {defilement=document.body.scrollTop;} else {defilement=window.scrollY;}
	xhr_object.open("GET", "../../commandes/ajax_maj_defilement.php?defilement="+defilement+"&chemin="+chemin, true); // true=asynchrone
	xhr_object.send(null); // pour enregistrer le défilement vertical

	url=document.getElementById(id).src;
	photo=chemin+"/"+id; /*chemin+"/"+basename(url, '.JPG')+'.JPG';  /* Référence de commande AVEC _mini */

	dateprise=rechdateprise(url);
	var contenu="<center><IMG onClick='ferme_apercu()' src='"+url.replace('_mini','')+"' class='apercuphoto' oncontextmenu='return false'><br>";

	if (chemin!="Media_Press/Collontrek_2009") contenu +="<table class='bandeaucaddie' ><tr>"
	
	+"<td><A onClick=rotation('"+photo+"',270) style='cursor:pointer'><img src='../../images/rot1.png' height=25 onMouseover=\"overlib('Rotation gauche',WIDTH,50,LEFT,FGCOLOR,'#c0c0c0')\" onMouseOut=nd()></A> "
	+"<A onClick=rotation('"+photo+"',90) style='cursor:pointer'><img src='../../images/rot2.png' height=25 onMouseover=\"overlib('Rotation droite',WIDTH,50,RIGHT,FGCOLOR,'#c0c0c0')\" onMouseOut=nd()></A></td>"
	+"<td><b><A onClick='ferme_apercu()' style='cursor:pointer'>Fermer l'aperçu</A></b></td>"
	+"<td width=300>Date de prise de vue :&nbsp;<b>"+dateprise+"</b></td>"
	+"<td><b><A onClick=add_caddie('"+photo+"') style='cursor:pointer'>Ajouter au panier</A></td><td><A onClick=add_caddie('"+photo+"') style='cursor:pointer'>"
	+"<IMG SRC='../../images/panier.gif' border=0 style='height:25px'></A></b></td></tr></table>";
	else contenu+="<table class='bandeaucaddie' style='width:450px'><tr><td>Photo originale grand format à télécharger dans le dossier de Presse</td></tr></table>";
	var apercu_jpg = document.getElementById('apercu_jpg');
	var y=document.body.scrollTop; 
	apercu_jpg.style.top=40+y;
	apercu_jpg.innerHTML=contenu;
	apercu_jpg.style.visibility='visible';
	document.getElementById('fondgris').style.top=y;
	document.getElementById('fondgris').style.visibility='visible';
	return true; }

function afa2(photo) { // affich_apercu dans page recherche
	dateprise=rechdateprise(photo);
	// fin de recherche de prise de vue
	var contenu="<center><IMG onClick='ferme_apercu()' src='../photos/"+photo.replace('_mini','')+"' class='apercuphoto' oncontextmenu='return false'><br>";
	contenu +="<table class='bandeaucaddie' ><tr><td><b><A onClick='ferme_apercu()' style='cursor:pointer'>Fermer l'aperçu</A></b></td>"
	+"<td width=300>Date de prise de vue :&nbsp;<b>"+dateprise+"</b></td>"
	+"<td><b><A onClick=add_caddie2('"+photo+"') style='cursor:pointer'>Ajouter au panier</A></td><td><A onClick=add_caddie('"+photo+"') style='cursor:pointer'>"
	+"<IMG SRC='../images/panier.gif' border=0 style='height:25px'></A></b></td></tr></table>";
	var apercu_jpg = document.getElementById('apercu_jpg');
	var y=document.body.scrollTop; 
	apercu_jpg.style.top=40+y;
	apercu_jpg.innerHTML=contenu;
	apercu_jpg.style.visibility='visible';
	document.getElementById('fondgris').style.top=y;
	document.getElementById('fondgris').style.visibility='visible';
	return true; }

function rechdateprise(photo) { // recherche de la date et de l'heure de prise de vue
	d = basename(photo, '.JPG');
	for (i=0; i < 6; i++) d = d.replace('.', '');
	d = d.replace('_mini', '');
	dateprise0=Right(d,14);
	dateprise=dateprise0.substr(0,2)+"/"+dateprise0.substr(2,2)+"/"+dateprise0.substr(4,4)+ "&nbsp;"+dateprise0.substr(8,2)+"h"+dateprise0.substr(10,2)+"mn";//+dateprise0.substr(12,2)+"s";
	return dateprise;
}

function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);}
    return b;
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function affich_apercu2(photo) { // dans le caddie (avec chemin)
	// recherche de la date et de l'heure de prise de vue
	d = basename(photo, '.JPG');
	 for (i=0; i < 6; i++) d = d.replace('.', '');
	position1=d.indexOf("_P")+2;dateprise0=d.substr(position1, 14);
	dateprise=dateprise0.substr(0,2)+"/"+dateprise0.substr(2,2)+"/"+dateprise0.substr(4,4)+ "&nbsp;"+dateprise0.substr(8,2)+"h"+dateprise0.substr(10,2)+"mn";//+dateprise0.substr(12,2)+"s";
	// fin de recherche de prise de vue
	var contenu="<center><IMG onClick='ferme_apercu()' src='"+photo.replace('_mini','')+"' class='apercuphoto' oncontextmenu='return false'>";
	contenu = contenu+"<table class='bandeaucaddie' style='width:500px'><tr><td><b><A onClick='ferme_apercu()' style='cursor:pointer'>Fermer l'aperçu</A></b></td>"
	+"<td><A onClick=rotation('"+photo+"',270) style='cursor:pointer'><img src='../images/rot1.png' height=25 onMouseover=\"overlib('Rotation gauche',WIDTH,50,LEFT,FGCOLOR,'#c0c0c0')\" onMouseOut=nd()></A> "
	+"<A onClick=rotation('"+photo+"',90) style='cursor:pointer'><img src='../images/rot2.png' height=25 onMouseover=\"overlib('Rotation droite',WIDTH,50,RIGHT,FGCOLOR,'#c0c0c0')\" onMouseOut=nd()></A></td>"
	+"<td width=300>Date de prise de vue :&nbsp;<b>"+dateprise+"</b></td></tr></table>"
	var apercu_jpg = document.getElementById('apercu_jpg');
	var y=document.body.scrollTop; 
	apercu_jpg.style.top=40+y;
	apercu_jpg.innerHTML=contenu;
	apercu_jpg.style.visibility='visible';
	document.getElementById('fondgris').style.top=y;
	document.getElementById('fondgris').style.visibility='visible';
	return true; }
	
function ferme_apercu() {
	document.getElementById('apercu_jpg').style.visibility = 'hidden';
	document.getElementById('fondgris').style.visibility = 'hidden';
}
function add_caddie(photo) {
	if (navigator.appName=="Microsoft Internet Explorer" ) {defilement=document.body.scrollTop;} else {defilement=window.scrollY;}
	xhr_object.open("GET", "../../commandes/ajax_add_caddie.php?photo="+photo+'&defilement='+defilement, false); // false=synchrone (on attend la fin de l'action)
	xhr_object.send(null);
	ferme_apercu();
	maj_caddie(xhr_object.responseText); // affichage en haut du nouveau contenu
	}
function add_caddie2(photo) { // pour une recherche depuis le caddie
	xhr_object.open("GET", "../commandes/ajax_add_caddie.php?photo="+photo, false); // false=synchrone (on attend la fin de l'action)
	xhr_object.send(null);
	ferme_apercu();
	maj_caddie(xhr_object.responseText); // affichage en haut du nouveau contenu
	document.location.href='caddie.php'
	}
function rotation(photo,angle) {
	//xhr_object.open("GET", "http://127.0.0.1/photozoom/commandes/ajax_rotation.php?photo="+photo+"&angle="+angle, true); // true=asynchrone
	xhr_object.open("GET", "http://www.photozoom2.com/commandes/ajax_rotation.php?photo="+photo+"&angle="+angle, true); // true=asynchrone
	//document.location.href="http://127.0.0.1/photozoom/commandes/ajax_rotation.php?photo="+photo+"&angle="+angle
	//document.location.href="http://www.photozoom2.com/commandes/ajax_rotation.php?photo="+photo+"&angle="+angle
	xhr_object.send(null);
	alert("Cette photo a été pivotée : \nPour la visualiser, veuillez actualiser ce cadre ou rafraîchir cette page. \nSous Firefox : click droit => Ce cadre => actualiser le cadre. \nIl se peut que ceci ne soit pas visible immédiatement.");
	ferme_apercu();
}

function dossard_rech() {
	document.location.href='page.php?dossard_cours='+document.getElementById('dossard_cours').value + '&dossard2_cours='+document.getElementById('dossard2_cours').value; }
function dossard_rech2(e) {
	if (e.keyCode == 13) dossard_rech();
}

// *****************  FIN APERCU DES IMAGES **********************//

function telecharge() {
	document.getElementById("patienter").style.visibility='visible';
	document.f1.submit(); }
function telech(i) {
	document.getElementById("pat"+i).style.visibility='visible';
	document.getElementById("f"+i).submit(); 
	}
	
function click_dossier(chemin,e,sup_user) {
		if (e.ctrlKey && sup_user>0) document.location.href='../../reserve/icone_dossier.php?chemin='+chemin;
		else document.location.href='page.php?chemin='+chemin;
	}
function maj_bandeau(r) { window.top.bas.secondaire.menu.document.getElementById('chemin').innerHTML=r; }  // chemins et titres
function rafraich_nom(texte) {
	if (texte!="") window.top.haut.presentation_haut.document.getElementById('contenu_client').innerHTML=texte+"<BR>Mon compte"; 
	else window.top.haut.presentation_haut.document.getElementById('contenu_client').innerHTML="Mon compte"; 
	}
function maj_caddie(texte) { 
	window.top.haut.presentation_haut.document.getElementById('contenu_caddie').innerHTML=texte; }  // chemins et titres
	
function over_dossier(rep) {
	document.getElementById('ic'+rep).className='dossier dossier2';
	document.getElementById('it'+rep).className='dossier_rep dossier_rep2';
	document.getElementById('it2'+rep).innerHTML+='<BR><blink>Clickez pour ouvrir<blink>';}

function out_dossier(rep) {
	document.getElementById('ic'+rep).className='dossier';
	document.getElementById('it'+rep).className='dossier_rep';
	document.getElementById('it2'+rep).innerHTML='';}
	
function over_panier() {
	document.getElementById('panier1').className='panier1a';
	document.getElementById('contenu_caddie').className='panier2a'; }
function out_panier() {
	document.getElementById('panier1').className='panier1';
	document.getElementById('contenu_caddie').className='panier2'; }
	
function over_login() {
	document.getElementById('login1').className='login1a';
	document.getElementById('contenu_client').className='login2a'; }
function out_login() {
	document.getElementById('login1').className='login1';
	document.getElementById('contenu_client').className='login2'; }
	
