
	$(function() {

		/**
		 * jQuery UI Dialog Box
		 * Articles de type JDB
		 *
		 */
		$(".afficherDialogBox").click( function() {
			var article = $(this).attr("href");
			article = article.split("#");
			article = article[1].toLowerCase();
			
			var id_article = article.replace("article", "");
			$.ajax({
				cache: false,
				async: false,
				type: "POST",
				url: "/ajax/getArticleTitre",
				data: "id_article=" + id_article,
				success: function(codeHTML){
					$("#jqueryUIDialogBox").dialog("option", "title", codeHTML);					
					$("#jqueryUIDialogBox").html( $("#" + article).html() );			
					setTimeout(
						function() {
							$("#jqueryUIDialogBox").dialog("open")
						},
						100
					);					
					return false;
				}
			});			
			return false;
		});

		/**
		 * BOITE DE DIALOGUE D'AUTHENTIFICATION AU K-LINE MANAGER
		 *
		 */
		$("#kDialogueAuthentification").dialog({
			autoOpen: false,
			width: 400,
			height: 250,
			modal: true,
			buttons: {

				"Se connecter": function() {
					var urlPost = "/administration/manager/authentifier";
					var strPost = "";
					$("input").each(function(){
						strPost = strPost.concat($(this).attr("id") + "=" + $(this).val() + "&");
					});
					$.ajax({
						cache: false,
						async: false,
						type: "POST",
						url: urlPost,
						data: strPost,
						success: function(codeRetour){
							if ( codeRetour == "oui" ) {
								window.location.reload();
							}
							else {
								return false;
							}
						}
					});
				}, 

				"Annuler": function() { 
					$(this).dialog("close");
				} 

			}

		});
	
	});

	$(document).ready( function() {

		/**
		 * BOITE DE DIALOGUE D'AUTHENTIFICATION AU K-LINE MANAGER
		 *
		 */

		$("#kOuvrirAdministration").click( function() {
			$("#kDialogueAuthentification").dialog("open");
			return false;
		});

		/**
		 * GESTION DES LIENS EXTERNES
		 *
		 */
		$("a[href]").live("click", function(){
			if ( $(this).hasClass("encMail") ) {
				/* Encodage des emails, via la classe encMail */
				var email = $(this).attr("title") + "@" + $(this).attr("href").replace("http://www.", "");
				window.location.href = "mailto:" + email;
				return false;
			}
			else {
				/* Gestion des liens vers des sites externes */	
				var siteExterne = $(this).attr("href");
				if ( $(this).hasClass("gaEventsTracking") ) {
					/* Tracker d'événements dédié à Google Analytics, via la classe gaEventsTracking */
					$(this).attr("target", "_blank");
					var attributs = $(this).attr("rel");
					attributs = attributs.split("|");
					if ( attributs[2] == "" ) {
						attributs[2] = $(this).attr("href");
					}
					_gaq.push(["_trackEvent", attributs[0], attributs[1], attributs[2]]);
				}
				else {
					/* Tracker d'événements libre */
					if ( siteExterne.substr(0, 7) == "http://" ) {
						$(this).attr("target", "_blank");
						_gaq.push(["_trackEvent", "Liens externes", "Clic", siteExterne]);
					}
				}
			}
		});

		/**
		 * SYSTEME QAPTCHA SUR LE FORMULAIRE DE CONTACT
		 *
		 */
		$('#QapTcha').QapTcha({
			txtLock: "Sytème Captcha : Faites glisser le curseur de la gauche vers la droite avec votre souris pour déverrouiller le formulaire",
			txtUnlock: "Vous pouvez désormais envoyer votre demande"
		});

	});

