function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Fonctions pour les couvs

var nn6 = document.getElementById && !document.all;
var clickX, clickY, initX, initY;
var divcouv;
var traine = false;
var plan = 0;

function appuie(e) {
	var clic = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";
	while (clic.tagName != topelement && clic.className != "divcouv")
		clic = nn6 ? clic.parentNode : clic.parentElement;
	if (clic.className=="divcouv") {
		traine = true;
		divcouv = clic;
		plan++;
		divcouv.style.zIndex = 200+plan;
		divcouv.style.opacity = 0.5;
		divcouv.style.MozOpacity = 0.5;
		divcouv.style.KhtmlOpacity = 0.5;
		divcouv.style.filter = "alpha(opacity=50)";
		initX = parseInt(divcouv.style.left+0);
		initY = parseInt(divcouv.style.top+0);
		clickX = nn6 ? e.clientX : event.clientX;
		clickY = nn6 ? e.clientY : event.clientY;
		document.onmousemove=bouge;
		return false;
	}
}

function relache() {
	if (traine) {
		traine = false;
		divcouv.style.opacity = 1;
		divcouv.style.MozOpacity = 1;
		divcouv.style.KhtmlOpacity = 1;
		divcouv.style.filter = "alpha(opacity=100)";
//		divcouv.style.cursor = "auto";
	}
}

function bouge(e) {
	if (traine) {
		divcouv.style.left = nn6 ? initX + e.clientX - clickX + 'px' : initX + event.clientX - clickX + 'px';
		divcouv.style.top = nn6 ? initY + e.clientY - clickY + 'px' : initY + event.clientY - clickY + 'px';
	}
	return false;
}

function ferme() {
	divcouv.style.display="none";
}

var count;
var x;
var y;
var ratio;
var departX;
var departY;
var pic;

function ouvre(div) {
	divcouv = document.getElementById(div);
	pic = document.getElementById(div+"imgg");
	plan++;
	count=0;
	divcouv.style.display="block";
	divcouv.style.zIndex=200+plan;
	x=pic.width;
	y=pic.height;
	departX=divcouv.offsetLeft+x/2;
	departY=divcouv.offsetTop+y/2;
	ratio=y/x;
	res();
}

function res() {
	if (count<x) {
		divcouv.style.left=departX-count/2+'px';
		divcouv.style.top=departY-count*ratio/2+'px';
		pic.width=count;
		count=count+40;
		setTimeout(res,0);
	} else {
		divcouv.style.left=departX-x/2+'px';
		divcouv.style.top=departY-x*ratio/2+'px';
		pic.width=x;
	}
}

// Fonctions sur les chaines

String.prototype.trim = function() {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}


function nom_droit(nom){
	var parenthese="";
	if((nom.indexOf(" (The)",0)!=-1)&&(nom.indexOf(" (The)",0)==nom.length -6)){
		return( "The "+nom.substring(0,nom.length -6));
	}
	var lgt=nom.length-1;
	if((nom.indexOf(" (",0)!=-1) && (nom.indexOf(" (",0)!= lgt) && (nom.indexOf(")",0)!=-1) && (nom.indexOf(")",0)== lgt)){
		parenthese=" "+nom.substring((nom.indexOf(" (",0)+1),nom.indexOf(")",0)+1).trim();
		nom=nom.substring(0,nom.indexOf(" (",0)).trim();
	}
	if(nom.indexOf(",",0)==-1 || ( nom.indexOf(",",0)!=-1 && nom.indexOf(",",nom.indexOf(",",0)+1)!=-1)){
		return(nom+parenthese);
	}
	else{
		var temp = new Array();
		temp=nom.split(",");
		return(temp[1].trim()+" "+temp[0].trim()+parenthese);
	}
}

// Recherche

function effacertout() {
	var rech = document.forms['recherche'];
	rech.genre.selectedIndex=0;
	rech.mots_titre.value = '';
	rech.compositeur.value = '';
	rech.compo.value = '';
	rech.cotage.value = '';
	rech.no_article.value = '';
	rech.instru_p.selectedIndex=0;
	rech.editeur.selectedIndex=0;
}

var cache = new Array();
var saisiebak = "";
var intervalID;
var lang;

function initrech() {
	document.forms['recherche'].elements['compo'].setAttribute("autocomplete","off");
	saisiebak = document.forms['recherche'].elements['compo'].value;
	positionne();
	intervalID = window.setInterval(boucle,500);
}

function positionne() {
	var zoneres = document.getElementById('zoneResultats');
	var elmtcpo = document.forms['recherche'].elements['compo'];
	zoneres.style.left  = elmtcpo.offsetLeft+"px";
	zoneres.style.top   = elmtcpo.offsetTop+elmtcpo.offsetHeight-1+"px";
	zoneres.style.width = elmtcpo.offsetWidth+"px";
}

function boucle() {
	var saisie = document.forms['recherche'].compo.value;
	if (saisiebak != saisie) {
		if (cache[saisie])
			afficherResultats(cache[saisie]);
		else
			appel(saisie);
		saisiebak = saisie;
	}
}

function afficherResultats(reponse) {
	var zoneres = document.getElementById('zoneResultats');
	zoneres.innerHTML = reponse;
	if (reponse != '<b></b>')
		zoneres.style.display = 'block';
	else
		zoneres.style.display = 'none';
}

function bas(event) {
	if(!event&&window.event)
		event=window.event;
	if (event.keyCode==40) {
		var selcpo = document.forms['recherche'].elements['selcompo'];
		if (selcpo) {
			selcpo.focus();
			selcpo.options[0].selected=true;
		}
	}
}

function nav(event) {
	if(!event&&window.event)
		event=window.event;
	if (event.keyCode==13) {
		pick();
	}
	if ((event.keyCode==38||event.keyCode==37) && document.forms['recherche'].elements['selcompo'].options[0].selected==true) {
		document.forms['recherche'].elements['compo'].focus();
		afficherResultats(cache[document.forms['recherche'].elements['compo'].value]);
	}
}

function flou() {
	document.getElementById('zoneResultats').style.display = 'none';
}

function pick() {
	var champs = document.forms['recherche'].elements;
	var Cindex = champs['selcompo'].options.selectedIndex;
	if (Cindex >= 0) {
		champs['compo'].value       = champs['selcompo'].options[Cindex].text;
		champs['compositeur'].value = champs['selcompo'].options[Cindex].value;
		saisiebak = champs['compo'].value;
//		document.getElementById('zoneResultats').style.display = 'none';
		champs['compo'].focus();
	}
}

// Ajax

function getXhr() {
	var xhr = null;
	if (window.XMLHttpRequest) // FF et autres
		 xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) { // IE
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else
		xhr = false; // pas de XMLHttpRequest
	return xhr
}

function appel(saisie) {
	if (saisie.length < 2) {
		afficherResultats('<b></b>');
		return;
	}
	var xhr = getXhr()
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			cache[saisie] = xhr.responseText;
			afficherResultats(xhr.responseText);
		}
	}
	var req="ajax.php";
	xhr.open("POST",req,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if(lang=='jp')
		saisie=unescape(encodeURIComponent(saisie));

	xhr.send("lettres="+saisie);
}

function appelP(id) {
	var xhr = getXhr()
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			if(xhr.responseText!="")
				document.getElementById('id_texte').innerHTML= xhr.responseText;
		}
	}
	var req="Apanier.php";
	xhr.open("POST",req,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id="+id);
}

// infos_recherche
function 	appel_enregistrement(id) {
	var xhr = getXhr()
	var req="ajax_enregistrement.php";
	xhr.open("POST",req,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id="+id);
}

// Fenetre deroulante

function initscroll() {
	dataobj=document.all? document.all.deroul_data : document.getElementById("deroul_data");
	dataobj.style.top="1px";
	thelength=dataobj.offsetHeight;
	scrolltest();
}

function scrolltest() {
	dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px";
	if (parseInt(dataobj.style.top)<thelength*(-1))
		dataobj.style.top="330px";
	//Regler ici le parametre pour la vitesse
	var vitesse = 50;
	setTimeout("scrolltest()",vitesse);
}