var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

var currentExtrait="";
var xmlhttp;
function request_post(url,datas,fonction) {
	xmlhttp=null
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=eval(fonction);
		xmlhttp.open("POST",url,true)
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(datas)
		
	} else {
		alert("Votre navigateur ne supporte pas l'ajax 1.")
	}
}


function AfficheInfo(txt,annee,isbn,prix,swf) {
	currentExtrait = swf;
	document.getElementById('little_couv_img').src= 'albums/m/'+txt+'.jpg';
	
	document.getElementById('lien_bdnet').href= 'http://darg.bdnet.com/'+isbn+'/alb.htm';
	document.getElementById('lien_amazon').href= 'http://www.amazon.fr/gp/search?ie=UTF8&keywords='+isbn+'&tag=dargaud&index=blended&linkCode=ur2&camp=1642&creative=6746';
	document.getElementById('lien_fnac').href= 'http://ad.zanox.com/ppc/?11299070C61699151T&ULP=[[http://www3.fnac.com/advanced/book.do?isbn='+isbn+']]';
	
	data = 'idmedia='+txt+'&annee='+annee+'&isbn='+isbn+'&prix='+prix;
	request_post('scripts/ajax_update_album.php',data,'gestion_refresh_results');
}

function gestion_refresh_results() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {	
			if(xmlhttp.responseText){
				document.getElementById('txt_album_ajax').innerHTML = xmlhttp.responseText;
			}
			else {
				alert('Aucune réponse');
			}
		} else {
			alert("Erreur ajax. "+xmlhttp.status)
		}
	}
}

var pagecalqueCourant = 1;
function pageId(num) {
	document.getElementById('calque_news'+pagecalqueCourant).style.display='none';
	document.getElementById('calqueActu'+pagecalqueCourant).className = 'Linkpagination2';
	
	document.getElementById('calque_news'+num).style.display='block';
	document.getElementById('calqueActu'+num).className = 'Linkpagination1';
	pagecalqueCourant=num;
}

function pageSuivante() {
}


function affichage_popup(nom_interne_de_la_fenetre) {
	window.open ('http://www.lucky-luke.com/library/images/'+currentExtrait, nom_interne_de_la_fenetre, config='height=500, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no')
}


var regExpEmailAdress=/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/g; 	// Accepte une adresse email. Ex : toto@toto.com
function matchRegularExpression(valeur, regularExpression)
{
	var resultat = valeur.match(regularExpression);
	if(resultat!=null && resultat.length==1) return true;
	else return false;
}
function verif_form() {
	if (!matchRegularExpression(document.getElementById('newsletterForm').value, regExpEmailAdress)) {
		alert('cette adresse email n\'est pas valide');
		return false;
	} else {
		data = 'mail='+document.getElementById('newsletterForm').value;
		//alert('data = '+data);
		request_post('scripts/ajax_update_newsletter.php',data,'gestion_refresh_newsletter');
		return true;
	}
	
}

function gestion_refresh_newsletter() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {	
			if(xmlhttp.responseText){
				alert(xmlhttp.responseText);
				//document.getElementById('txt_album_ajax').innerHTML = xmlhttp.responseText;
			}
			else {
				alert('Aucune réponse');
			}
		} else {
			alert("Erreur ajax. "+xmlhttp.status)
		}
	}
}
