var $j = jQuery.noConflict();
	$j(document).ready( function() {
	
		$j("#tip_inscription").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false,
			'onClosed' : function() {
				$j('input[type=radio]').removeAttr("checked");
				}		
		});
		
		$j("#tip_connexion_we").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false
		});

		$j("#tip_connexion_we2").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false
		});

		$j("#tip_connexion_we3").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false
		});
		
		$j("#tip_espace_famille").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false
		});

		$j("#tip_espace_enseignant").fancybox({
			'scrolling'		: 'no',
			'transitionIn' : 'fade',
			'speedIn' : 300,
			'titleShow'		: false
		});
		
		$j("#login_form").bind("submit", function() {
			if ($j("#pseudo").val().length < 1 || $j("#password").val().length < 1) {
				$j("#login_error").html('Données incomplètes.');
			    $j.fancybox.resize();
			    return false;
			}
			$j.fancybox.showActivity();
			var url = "membres/auth/ajax/authentification";
			var x = $j(this).serializeArray();
			$j.getJSON(url,  { pseudo : $j("#pseudo").val(), password: $j("#password").val(), format : 'json' }, 
					function(data) {
					$j.fancybox.hideActivity();
					if(data.connect == 0) {
						if(data.err == 1) { $j("#login_error").html('Caractères non autorisés.'); }
						else if (data.err == 2) { $j("#login_error").html('Merci de saisir un pseudo.'); } 
						else if (data.err == 3) { $j("#login_error").html('Non reconnu.'); }
					}
					else if(data.connect == 1) {
						if(data.profil == 'eleve') { $j(location).attr("href", "membres/eleve"); $j.fancybox.close();}
						else if(data.profil == 'webeleve') { $j(location).attr("href", "membres/eleve"); $j.fancybox.close();}
						else if(data.profil == 'professeur') { $j(location).attr("href", "membres/professeur"); $j.fancybox.close();}
						else if(data.profil == 'administrateur') { $j(location).attr("href", "membres/admin"); $j.fancybox.close();}
						else if(data.profil == 'prof1') { $j(location).attr("href", "membres/profadmin"); $j.fancybox.close();}
						else { $j("#login_error").html('Profil non reconnu.'); }	
					}
			    });
			return false;
		});
		
		$j("input[type=submit]").bind("click", function(e){
			if($j(this).attr('id') == 'validation') {
				$j('#validation').attr("was_clicked","yes");
				$j('#retour').attr("was_clicked","no");
			}			
			else if($j(this).attr('id') == 'retour') {
				$j('#validation').attr("was_clicked","no");
				$j('#retour').attr("was_clicked","yes");
			}			
		});
		
		// pour la récup de l'id du bouton sumbit cliqué : on tague le
		$j("#inscription_form").submit(function(e) {
			// récup de l'id du bouton sumbit cliqué : validation ou retour
			var clicked_submit = $j("[was_clicked=yes]").get(0);
//				alert(clicked_submit.id);
			if(clicked_submit.id == 'validation') {
				$j("#validation").show();
				// action si aucun choix n'a été fait
				if($j('input[type=radio][name=choix]:checked').length == 0 && $j('input[type=radio][name=classe_stage]:checked').length == 0
						&& $j('input[type=radio][name=classe_we]:checked').length == 0) {
					alert('Saisir un choix');
					return false;
				}
				// sinon				
				// choix du soutien (cours à domicile)
				else if($j('input[type=radio][name=choix]:checked').attr('value') == 'soutien')  {
					$j(location).attr("href", "ficheeleve.php");
					return false;
				}
				// choix stage - hec
				else if($j('input[type=radio][name=classe_stage]:checked').attr('value') == 'hec')  {
					alert('Il ne vous reste qu\'à imprimer la fiche d\'inscription et nous la retourner par courrier.');
					$j(location).attr("href", "pdf/inscriptionHEC20112012.pdf");
					return false;
				}	
				// choix stage - sup spe
				else if($j('input[type=radio][name=classe_stage]:checked').attr('value') == 'supspe')  {
					alert('Il ne vous reste qu\'à imprimer la fiche d\'inscription et nous la retourner par courrier.');
					$j(location).attr("href", "pdf/inscriptionSUPSPE.pdf");
					return false;
				}
				// choix stage - lycee				
				else if($j('input[type=radio][name=classe_stage]:checked').attr('value') == 'lycee')  {
					alert('Il ne vous reste qu\'à imprimer la fiche d\'inscription et nous la retourner par courrier.');
					$j(location).attr("href", "pdf/inscription-stage-lycee.pdf");
					return false;
				}	
				// choix stage - pas de classe choisie
				else if($j('input[type=radio][name=choix]:checked').attr('value') == 'stage')  {
					// reset
					$j('input[type=radio]').removeAttr("checked");
					$j(clicked_submit).attr("was_clicked","no");
					// affichage
					$j("#inscription_message").html('Pour s\'inscrire à un stages, imprimer une fiche d\'inscription.');
					$j("#inscription_choix").hide();
					$j("#inscription_stage").show();
					$j("#retour").show();
					return false;
				}	
				// choix we prépas - pas de classe choisie
				else if($j('input[type=radio][name=choix]:checked').attr('value') == 'we')  {
					// reset
					$j('input[type=radio]').removeAttr("checked");
					$j(clicked_submit).attr("was_clicked","no");
					// affichage
					$j("#inscription_message").html('Pour les Week-Ends Prépas, le choix des séances se fait depuis votre compte.');
					$j("#inscription_choix").hide();
					$j("#validation").hide();
					$j("#inscription_we").show();
					$j("#retour").show();
					return false;
				}			
			}
			else if(clicked_submit.id == 'retour') {
					$j('input[type=radio]').removeAttr("checked");
					$j(clicked_submit).attr("was_clicked","no");
					$j("#inscription_message").html('');
					$j("#inscription_choix").show();
					$j("#inscription_stage").hide();
					$j("#inscription_we").hide();
					$j("#validation").show();
					$j("#retour").hide();
					return false;
			}
		});
		
	});
