/* Permet de faire la connexion avec le code qui est à la fin du fichier 
* ATTENTION L'ANCIENNE PAGE DE LOGIN POSSEDE L'ID CONNEXION
*/

// Utilise la Vrai librairie Mootool
function connexion(url){
	
	if (!$('connexion'))
		var ID_connexion = 'connexion_login';
	else
		var ID_connexion = 'connexion';
	if (url == undefined)
		url = '';
	
	var Effect_fond = new Fx.Morph('connexion_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	if ($('page')) {
		var height_page = $('page').getSize().y;
		if (parseInt(height_page) < parseInt(window.screen.height))
			height_page = window.screen.height;
	} else
		var height_page = window.screen.height;
	
	// On scroll tout en haut
	window.scroll(0,0);
	$('connexion_fond').setStyle('display','block');
	$('connexion_fond').setStyle('opacity','0');
	$('connexion_fond').setStyle('zIndex','300000');
	$('connexion_fond').setStyle('height',height_page);//on récupère la taille de la page pouyr bien mettre le voile sur toute la hauteur
	$('connexion_fond').setStyle('width',"100%");
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$('connexion_fond').setStyle('width','980px');
	Effect_fond.start({
		'opacity' : 0.5
	});
	var Effect_connexion = new Fx.Morph(ID_connexion, {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	var top_windows = window.getSize().y/2 - $(ID_connexion).getStyle('height').toInt()/2 - 100;
	if (top_windows < 0)
		top_windows = 0;
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$(ID_connexion).setStyles({'display':'block','opacity' : 0,'top' : window.screen.height/2 - $(ID_connexion).getStyle('height').toInt()/2 - 100, 'left' : 100,'zIndex' : '300001'});
	else
		$(ID_connexion).setStyles({'display':'block','opacity' : 0,'top' : top_windows, 'left' : window.getSize().x/2 - $(ID_connexion).getStyle('width').toInt()/2,'zIndex' : '300001'});
	Effect_connexion.start({
		'opacity' : 1
	});
	if (url != '')
		$('connexion_form').action = url;
}

function close_connexion(){
	
	if (!$('connexion'))
		var ID_connexion = 'connexion_login';
	else
		var ID_connexion = 'connexion';
	
	var Effect_fond = new Fx.Morph('connexion_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_fond.start({
		'opacity' : 0
	});
	var Effect_connexion = new Fx.Morph(ID_connexion, {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_connexion.start({
		'opacity' : 0
	});
	setTimeout(function(){$('connexion_fond').setStyle('display','none');$(ID_connexion).setStyle('display','none');},600);
}

// Dispo dans medipass
function verif_email() {
	// On regarde si le champs email est différent de vide
	if ($('f_email').value != '') {
		$('f_email_erreur').style.display = 'none';
		$('f_email_erreur').innerHTML = "";
		run_envoie_email($('f_email').value);
	} else {
		$('f_email_erreur').style.display = 'block';
		$('f_email_erreur').innerHTML = "Le champ est vide";
	}
}

function run_envoie_email(email) {
	update_ajax('envoie_email_content',"/ajax/ajax_get_html_code_oublie.php","email="+email);
}

// Si jamais l'email n'est pas renseigné alors on ne l'envoie pas (on fait juste un affichage du champs email pour l'envoyé)
function envoie_email(email){
	
	// Si jamais email == form alors on force à afficher le formulaire
	if (email == 'form')
		$('envoie_email_content').innerHTML = '<form action="" method="post" id="form_envoie_email">Entrez votre email pour recevoir vos codes d\'identifications<br/><div id="f_email_erreur" class="erreur"></div><input type="text" name="f_email" id="f_email" value="" /><br/><br/><input type="button" value="Valider" onclick="verif_email();" /></form>';
	
	var Effect_fond = new Fx.Morph('envoie_email_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	if ($('page')) {
		var height_page = $('page').getSize().y;
		if (parseInt(height_page) < parseInt(window.screen.height))
			height_page = window.screen.height;
	} else
		var height_page = window.screen.height;
	var top_windows = window.getSize().y/2 - $('envoie_email').getStyle('height').toInt()/2;
	if (top_windows < 0)
		top_windows = 0;
	$('envoie_email_fond').setStyle('display','block');
	$('envoie_email_fond').setStyle('opacity','0');
	$('envoie_email_fond').setStyle('zIndex','300002');
	$('envoie_email_fond').setStyle('height',height_page);//on récupère la taille de la page pouyr bien mettre le voile sur toute la hauteur
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$('envoie_email_fond').setStyle('width','960px');
	Effect_fond.start({
		'opacity' : 0.5
	});
	var Effect_connexion = new Fx.Morph('envoie_email', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$('envoie_email').setStyles({'display':'block','opacity' : 0,'top' : window.screen.height/2 - $('envoie_email').getStyle('height').toInt()/2 - 100, 'left' : 100,'zIndex' : '300003'});
	else
		$('envoie_email').setStyles({'display':'block','opacity' : 0,'top' : top_windows, 'left' :  window.getSize().x/2 - $('envoie_email').getStyle('width').toInt()/2,'zIndex' : '300003'});
	Effect_connexion.start({
		'opacity' : 1
	});
	if (email != '' && email != 'form')
		run_envoie_email(email);
}

function close_envoie_email(){
	
	var Effect_fond = new Fx.Morph('envoie_email_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_fond.start({
		'opacity' : 0
	});
	var Effect_connexion = new Fx.Morph('envoie_email', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_connexion.start({
		'opacity' : 0
	});
	setTimeout(function(){$('envoie_email_fond').setStyle('display','none');$('envoie_email').setStyle('display','none');$('envoie_email_content').innerHTML = '<form action="" method="post" id="form_envoie_email">Entrez votre email pour recevoir vos codes d\'identifications<br/><div id="f_email_erreur" class="erreur"></div><input type="text" name="f_email" id="f_email" value="" /><br/><br/><input type="button" value="Valider" onclick="verif_email();" /></form>';},600);
	
}




// Pour l'affichage de la boite de demande de mail pour l'inscription (utilisé dans scoop/modeles/etapes.php pour medipad)
function email_inscription(url){
	
	var contener = 'email_inscription';
	
	if (url == undefined)
		url = '';
	
	var Effect_fond = new Fx.Morph('connexion_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	if ($('page')) {
		var height_page = $('page').getSize().y;
		if (parseInt(height_page) < parseInt(window.screen.height))
			height_page = window.screen.height;
	} else
		var height_page = window.screen.height;
	$('connexion_fond').setStyle('display','block');
	$('connexion_fond').setStyle('opacity','0');
	$('connexion_fond').setStyle('zIndex','300000');
	$('connexion_fond').setStyle('height',height_page);//on récupère la taille de la page pouyr bien mettre le voile sur toute la hauteur
	$('connexion_fond').setStyle('width',"100%");
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$('connexion_fond').setStyle('width','960px');
	Effect_fond.start({
		'opacity' : 0.5
	});
	var Effect_connexion = new Fx.Morph(contener, {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	var top_windows = window.getSize().y/2 - $(contener).getStyle('height').toInt()/2 - 100;
	if (top_windows < 0)
		top_windows = 0;
	if(navigator.userAgent.match(/iPhone|iPod|iPad/i))
		$(contener).setStyles({'display':'block','opacity' : 0,'top' : window.screen.height/2 - $(contener).getStyle('height').toInt()/2 - 100, 'left' : 100,'zIndex' : '300001'});
	else
		$(contener).setStyles({'display':'block','opacity' : 0,'top' : top_windows, 'left' : window.getSize().x/2 - $(contener).getStyle('width').toInt()/2,'zIndex' : '300001'});
	Effect_connexion.start({
		'opacity' : 1
	});
	if (url != '')
		$('email_inscription_form').action = url;
}

function close_email_inscription(){
	
	var contener = 'email_inscription';
	
	var Effect_fond = new Fx.Morph('connexion_fond', {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_fond.start({
		'opacity' : 0
	});
	var Effect_connexion = new Fx.Morph(contener, {duration: 500, transition: Fx.Transitions.Sine.easeIn});
	Effect_connexion.start({
		'opacity' : 0
	});
	setTimeout(function(){$('connexion_fond').setStyle('display','none');$(contener).setStyle('display','none');},600);
}
/***CODE HTML EMAIL INSCRIPTION***/
/*
<div id="email_inscription" style="display:none;">
	<div id="email_inscription_content">
        <a href="javascript:close_email_inscription()" id="email_inscription_close"><img src="/images_communes/connexion_close.png" border="0" /></a>
    	<div class="email_inscription_txt">
        	Pour vous inscrire il vous suffit de rentrer votre mail. Après vérification de votre mail, nous vous enverrons un email avec votre identifiant et mot de passe. Ensuite vous remplirez votre profil pour télécharger les contrats vous permettant d'intégrer le panel de mediscoop.
        </div>
        <div class="email_inscription_form_contener">
            <form action="%PHP_SELF%" method="post" id="email_inscription_form">
                <input type="text" name="email_inscription" value="" id="email_inscription_input" onkeypress="verif_email_inscription()" onblur="verif_email_inscription()"/> &nbsp; <img src="/images_index/fleche-uncheck.png" align="absmiddle" id="erreur_email_inscription"/>
                <br/>
        		<input type="hidden" name="pageID" value="%pageID%"/>
                <input type="button" name="action" id="btn_email_inscription" value="Valider" onclick="valid_email(this.form)">
            </form>
        </div>
	</div>
</div>
*/
/*FIN CODE HTML EMAIL INSCRIPTION*/
/***CODE JAVASCRIPT EMAIL INSCRIPTION***/
/*


function verif_email_inscription() {
	var erreur_mail = true;
	var champ = $('email_inscription_input');
	var verif = false;
	for (var j=0 ; j<(champ.value.length) ; j++) {
	//Ici, ouverture d'une boucle for à 1 qui permettra de tester du premier jusqu'au dernier caractère de l'adresse e-mail entrée.
		if (champ.value.charAt(j)=="@") {
		// La on commence les conditions de tests. Ici on cherche l'@
			if (j<(champ.value.length-4)){
			// Ici on regarde si il y a bien 4 caractère après le @
				for (var k=j ; k<(champ.value.length-2) ; k++) {
				// On ouvre une seconde boucle pourvérifier les caractère après le @
				   if (champ.value.charAt(k)=="."){
					 verif = true;
				   	 erreur_mail = false;
					 $('erreur_email_inscription').src = '/images_index/fleche-check.png';
					 break;
				   }
				   else{
				   	   erreur_mail = true;
					   $('erreur_email_inscription').src = '/images_index/fleche-uncheck.png';
				   }
				}//fin foreach
			}
			else{
				erreur_mail = true;
				$('erreur_email_inscription').src = '/images_index/fleche-uncheck.png';
			}
		}
		else{
			erreur_mail = true;
			$('erreur_email_inscription').src = '/images_index/fleche-uncheck.png';
		}
		if(verif)
			break;
	//on vérifie qu'il y ai bien un point et on met la variable verif à true (implicitement si toutes les conditions sont remplies) puis on ferme les conditions et boucles
	}	
	return erreur_mail;
}
function valid_email(form) {
	var erreur = verif_email_inscription();
	
	if (!erreur)
		form.submit();
}
*/
/*FIN CODE JAVASCRIPT EMAIL INSCRIPTION*/


/***CODE HTML***/
/*
<div id="connexion">
	<div id="connexion_content">
    	<div class="connexion_operation">
            <a href="javascript:close_connexion()" id="connexion_close"><img src="/images_index/connexion_close.png" border="0" /></a>
             	%detail_operation%
    	</div>
        <div class="connexion_titre">
        	<img src="/images_index/cadenas.png" style="float:left;margin-right:10px;" />
            Identifiez-vous ou inscrivez-vous<br/>à la médiathèque
        </div>
        <div class="connexion_left">
        	<div class="connexion_left_content">
                Pour consulter les communications du congrès, vous devez 
                vous identifier ou vous inscrire
                <div class="connexion_form_contener">
                    <form action="%PHP_SELF%" method="post" id="connexion_form">
           				%failed_login_code1%
                        <input type="text" name="username" value="Identifiant ou e-email" onclick="this.value = ''" maxlength="32" id="input_username"><br/>
                        <input type="password" name="password" value="Mot de passe" onclick="this.value = ''" maxlength="32" id="input_password"><br/>
                        <input type="hidden" name="loggin_on" value="log"><br/>
                        <div style="float:right;"><a href="http://www.medipass.fr/envoyerlogin.php" id="lien_mot_passe">Mot de passe oubli&eacute;?</a></div>
                        <input type="submit" id="connexion_bouton" name="relog" value="Connexion">
                    </form>
                </div>
                 
                <img src="/images_index/crayon-inscription.png" style="float:left;margin-right:10px;"/> Pas encore inscrit ? <br/><a href="http://www.medipass.fr/inscription.php?idsit=%idsit%" id="lien_inscription">Inscrivez-vous gratuitement !</a>
            </div>
        </div>
        <div class="connexion_right">
        	<div class="connexion_right_content">
             	<img src="/images_index/logo-mediatheque-lightgrey.png" />
             </div>
        </div>
	</div>
</div>
<div id="connexion_fond" style="position:absolute;top:0;left:0;opacity:0;filter:alpha('opacity=0');">&nbsp;</div>
*/
/*FIN CODE HTML*/
/***CSS***/
/*
#connexion{
	display:none;
	position:absolute;
	top:0;
	left:0;
	background-color:#FFFFFF;
	width:760px;
	height:430px;
	text-align:left;
	-moz-border-radius:15px;
	-webkit-border-radius:15px;
	border-radius:15px;
}
#connexion_fond{
	display:none;
	position:absolute;
	background-color:#000000;
	width:100%;
	height:100%;
}
*/
/*FIN CSS*/
