/* ##########################################
 * #	FONCTIONS DIVERSES					#
 * #	Mis a jour le 26 juin 2007			#
 * ##########################################
 * 
 * 
 * 
 * 
 * 
 * 
 */

/*
 * FONCTION DE POPUP SANS LES SCROLL BAR
 */
function popup(target,width,height){
   if(window.innerWidth){
	   LeftPosition =(window.innerWidth-width)/2;
	   TopPosition =((window.innerHeight-height)/4)-50;
    }
   else{
	   LeftPosition =(parseInt(window.screen.width)-width)/2;
	   TopPosition=((parseInt(window.screen.height)-height)/2)-50;
    }
 	//attribut: no scrollBar
   attr = 'resizable=no,scrollbars=no,location=no,width=' + width + ',height=' +
   height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
   TopPosition + '';
  
   popWin=open(target, 'GLENAT', attr);
 }
 
  
 /*
  * FONCTION POPUP AVEC SCROLLBAR
  */ 
 function popup2(target,width,height){
   if(window.innerWidth){
	   LeftPosition =(window.innerWidth-width)/2;
	   TopPosition =((window.innerHeight-height)/4)-50;
    }
   else{
	   LeftPosition =(parseInt(window.screen.width)-width)/2;
	   TopPosition=((parseInt(window.screen.height)-height)/2)-50;
    }
   //attribut: Scrollable
   attr = 'resizable=no,scrollbars=yes,location=no,width=' + width + ',height=' +
   height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
   TopPosition + '';
  
   popWin=open(target, 'GLENAT', attr);
 }
 
 /*
 * FONCTION DE POPUP simple POUR OUVRIR LES LIVRE 
 */
function openGlenat(URL){
	attr = 'resizable=yes,toolbar=yes' ;
	new_win = window.open(URL, 'GLENAT', attr);
}  

/*
 * FONCTION Qui va fermer la fenetre html d'appel du script
 * utilisé pour fermé l'OEKAKI
 */
function CloseWindow(){
	window.opener = self;
  	window.close();
}
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 /*
  * FONCTION POUR GERER LE SWITCH DE QUESTIONS DANS LA FAQ
  */
function setFAQ(maReponse,maQuestion,nbFaq){		
	for(var i=1; i<(nbFaq+1);i++){				
		var divFaq=document.getElementById('faq_reponse'+i);				
		divFaq.style.display='none';		
	}
	var divVisible=document.getElementById(maReponse);				
	divVisible.style.display='block';						
	document.getElementById("current_question").innerHTML=document.getElementById(maQuestion).innerHTML	;	
}

/*
 * FONCTION DE SUBMIT DE LA NEWSLETTER
 */
/*function submitNewsletter(){
	var myForm=document.getElementById("formNewsletter");
	var email=document.getElementById("newsletterEmail").value;
	
	var url="http://v2.mlmgr.com/forms.pl?splio-0="+email+"&couleur=%23e7ddb7&splio-list=11020&splio-12=La+lettre+Gl%E9nat+BD&splio-12=La+lettre+Gl%E9nat+Manga";
	var url="http://s3s.fr/form?univers=glenat&cssurl="+escape("http://www.glenatmanga.com/css/form.css")+"&email="+email+"&listes[]=1";
	popup2(url,'600','450');		
}*/
function submitNewsletter(){
	//alert('ok');
		var id='formNewsletter'
	var email=document.getElementById("newsletterEmail").value;
	var url='/inscription-nl-simple.asp?email='+email;

	var xhr_object = null;
	var position = id;
	   if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
	  else
	    if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

	// On ouvre la requete vers la page désirée
	xhr_object.open("GET", url, true);
	xhr_object.onreadystatechange = function(){
	if ( xhr_object.readyState == 4 )
	{
		// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
		document.getElementById(position).innerHTML = xhr_object.responseText;
	}
	}
	// dans le cas du get
	xhr_object.send(null);
 return false;
}

function retourNewsletter(){
	var id='formNewsletter'
	txtForm='<fieldset><label>Abonnement à la newsletter: </label><input type="text" id="newsletterEmail" name="email" value="mon@mail.com" size="20" onfocus="if (this.value==\'mon@mail.com\') this.value=\'\'" onblur="if (this.value==\'\') this.value=\'mon@mail.com\'"  /><img src="/img/menu/ok2.jpg" id="bt_nl_ok" alt="ok" onclick="submitNewsletter();" class="imgCliquable"  /></fieldset>';
	// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
	document.getElementById(id).innerHTML =txtForm;
	return false;
}





/*
 * FONCTION DE SOUMISSION DE FORMULAIRE
 */
function submitForm(idForm) {
	var myForm=document.getElementById(idForm);
	myForm.submit();
}
/*
 * FONCTION POUR ENLEVER LE CADRE D'ALERTE DES INPUTS ( monGlenat )
 */
function reInitMyInput(myInput){
	var monInput=document.getElementById(myInput)
	monInput.style.backgroundColor='white';

}

/*Alertes***************/
function submitAlerte(){
	//alert('ok');
		var id='fieldAlerte'
	var email=document.getElementById("AlerteEmail").value;
	var fiche_codeserie=document.getElementById("fiche_codeserie").value;
	var fiche_ean=document.getElementById("fiche_ean").value;
	var url='/scripts/inscription-alerte.asp?email='+email+'&fiche_ean='+fiche_ean+'&fiche_codeserie='+fiche_codeserie;

	var xhr_object = null;
	var position = id;
	   if(window.XMLHttpRequest)  xhr_object = new XMLHttpRequest();
	  else
	    if (window.ActiveXObject)  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

	// On ouvre la requete vers la page désirée
	xhr_object.open("GET", url, true);
	xhr_object.onreadystatechange = function(){
	if ( xhr_object.readyState == 4 )
	{
		// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
		document.getElementById(position).innerHTML = xhr_object.responseText;
	}
	}
	// dans le cas du get
	xhr_object.send(null);
 return false;
}


function isDate(d) {
	// Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
	// Par Romuald
	
	if (d == "") // si la variable est vide on retourne faux
		return false;
	
	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	
	if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
		return false; // Si pas bon, retourne faux

	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	j = parseInt(d.split("/")[0], 10); // jour
	m = parseInt(d.split("/")[1], 10); // mois
	a = parseInt(d.split("/")[2], 10); // année

	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) {
		if (a < 89)	a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a+=1900;
	}

	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 28;

	// Nombre de jours pour chaque mois
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);

	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}

