/* Ajouté par Issam BOUZIANE Hack pour firefox 3.6, page ma question santé. */
if(navigator.userAgent.indexOf("Firefox/3.6")!=-1){
    $('.axa-btn-gris > span > span > span').css('padding-top','5px');
}
/* Ajouté par Issam BOUZIANE Hack pour firefox 3.6, page ma question santé. */
/* Ajouts Issam BOUZIANE 15/12/2011: limitation de nombre de caractères sujet/question */
$.fn.limitChars = function(limit) {

    this.each(function() {

        var $this = $(this),
		limit = limit || $this.attr('maxlength'),
		display_chars = $('#' + $this.attr('id') + '-limitChars');
		
        $this.keyup(function() {

            var text = $this.val(),
            text_length = text.length;

			if (display_chars.length != 0) {
				display_chars.text(limit - text_length);
			}

            if(text_length > limit) {

                $this.val(text.substr(0, limit));

                return false;

            }

            return true;

        }).trigger('keyup');

    });

};
/* Fin Ajouts Issam BOUZIANE 15/12/2011: limitation de nombre de caractÃ¨res sujet/question */
$(function(){

	if( jQuery.browser.msie && (jQuery.browser.version == "6.0") ) { 
		DD_belatedPNG.fix('.image-tronc .triangle, .title-main1,.content-side,.sidebar_left ,.title-main2,.content-side1,.first-diver,.title-main3,.content-side3,.sidebar_right,.content-side4,.sidebar_left_under,.title-main4 ,.content-side5,.sidebar_right_vitalite,.title-main2 a img,.title-main4 h2 a,.title-menu,.menu,.menu ul,.article img,ul.sett,.impr img,.zoomin img,.zoomout img,.addfav img,ul.sett li.addspace,.social-network a img,.titliste,.sidebareleft-in ul li a,.spaceperso-in,.spaceperso,.axa-menu ul li,.editinfo-in,.valid input,.editinfo,.info-in,.sidebar_right_in p.asking a,.sidebar_right_in p.asking,.alim img,.service-in,.quiz-title,.quiz,.quiz-cont,.content-in2,.content-actus,.content-actus-bg,.content-side5 p.specialbtn a,.block-flash .rub-special, #axa_li-forum a, .axa_bloc-pagination-recherche-forum, .axa_liste-pagination-recherche-forum .axa_page-en-cours a span, #axa_forum-top-bg, .axa_recherche-forum, .axa_table-forum th, .axa_table-forum .axa_vie-forum-td, .axa_bloc-salon-infos-bottom ul li a, .axa_li-citer, .axa_li-repondre, .axa_gab-expert #axa_forum-top-bg, .axa_gab-expert .axa_table-forum .axa_vie-forum-td, .axa_gab-expert .axa_bloc-salon-infos-bottom ul li a, .axa_lisret-turquoise, .axa_gab-expert .axa_bloc-salon-infos, .axa_gab-expert .axa_bloc-salon-infos-global, .axa_vignette-bleu-top, .axa_vignette-bleu-bottom, .axa_vignette-bleu-top p, .axa_bt-vert-entrainement span, .axa_home-mini-block .fond-oblique, .axa_flux-rss a, .forum-in, .forum, .inner-popin-content, #cboxClose, .inner-popin-content, .popin-content, .inner-popin-content img, .menus ul, .axa_top-inner-menu, .axa_right-inner-menu, .logo img, .axa_bg_new_flash span, axa_png, .axa_top-bottom-menu, .axa_content-inner-menu ul, #submenu_top, #submenu_bottom, #adblock_top, #adblock_bottom, #capacites ul li a img, #mainblock_top, #mainblock_bottom, #mainblock_content');
	}
});
$(document).ready(function() {

	/* Changement de la position du bouton Suivre le sujet */
	//$('#boutonSuivreJs').html($('#boutonSuivreForum').html());
	//$('#boutonSuivreForum').remove();
	/* Fin Changement de la position du bouton Suivre le sujet */
		
	/* Listing des thÃ©matiques: Ajouts Issam BOUZIANE 20/12/2011 */	
	$(function(){
		//$("ul.axa-sous-thematique li").each(function(){
			// un dÃ©placement des valeurs impossible avec php
			//$(this).children('a').append($(this).children("span.axa-nbr-sujet"));
		//});
		$("ul.axa-linsting-thematique").children('li').last().addClass('axa-last-thematique'); // style derniÃ¨re thÃ©matique
		//$("ul.axa-linsting-thematique > li:first > span").addClass('axa_activated');
		$(".axa-sous-thematique").hide();
		$(".axa-linsting-thematique .axa_activated").next().show();
		$(".axa-linsting-thematique .axa_activated").addClass('axa-thematique-on');
	});
	
	$(function(){
		$(".axa-linsting-thematique > li > h3").click(function(){			
			$(this).toggleClass('axa-thematique-on');
			$(this).next('ul.axa-sous-thematique').toggle(300);
			return false;
		});
	});
	/* Fin listing des thÃ©matiques */	
	/* Ajouts Issam BOUZIANE 15/12/2011: limitation de nombre de caractÃ¨res sujet/question */
	$('#axa-poser-question, #axa-title-question').limitChars();
	
	// Affichage de la premiÃ¨re lettre en caractÃ¨re plus grand.
	$('.axa-bloc-reponse > div > p').each(function(){
		var question = $(this).html();
		if(question){
			question = $.trim(question);
			var firstCharacter = question.charAt(0);
			var rest = question.substring(1);
			var result = '<span class="axa-first-lettre">'+firstCharacter+'</span>'+rest;
			$(this).html(result);
		}
	});
	/* Fin Ajouts Issam BOUZIANE 15/12/2011: limitation de nombre de caractÃ¨res sujet/question */
	
	/* Validation forumlaire d'inscription, ajouts Issam BOUZIANE 21/12/2011 */
	$('#valider_inscription').click(function(){
		erreurs = new Array();
		var identifiant = $('#Identifiant-ins').val();
		var Pass = $('#Pass-ins').val();
		var Email = $('#Email-ins').val();
		var ConfirmationPass = $('#Confirmation-Pass-ins').val();
		// informations obligatoires.
		$('input[name$="FE[fe_users][email_again]"]').val(Email);
		$('input[name$="FE[fe_users][last_name]"]').val(identifiant);
		$('input[name$="FE[fe_users][first_name]"]').val(identifiant);
		$('input[name$="FE[fe_users][password_cache]"]').val(Pass);
		// crypter les mots de passe.
		$('#Pass-ins').val(MD5(Pass));
		$('#Confirmation-Pass-ins').val(MD5(Pass));
		
		
		//if(identifiant=='' || identifiant == 'Identifiant') {erreurs.push('Attention : le champ Identifiant est obligatoire !')}
		//if(Pass == '') {erreurs.push('Attention : le champ Mot de passe est obligatoire !')}
		//if(Email == '' || Email == 'E-mail') {erreurs.push('Attention : le champ Adresse e-mail est obligatoire !')}
		//if(ConfirmationPass == '') {erreurs.push('Attention : le champ Confirmation du mot de passe est obligatoire !')}
		
		
		$.ajax({
			url : 'http://www.sante.axaprevention.fr/fr/accueil/inscrivez-vous/', 
			type: "POST",
			data: $("#registrationForm").serialize(),
			cache : false,
			async : false,
			success : function(data)
							{
								reg=new RegExp("Attention : le champ Confirmation de l'adresse e-mail est obligatoire !|Attention : le champ Confirmation de l'adresse e-mail  est incorrect !"+".*$","i");
								$('p.error-register-form',data).each(function(){
									var erreur = $(this).html();
									if(erreur.match(reg)){
										var erremail = erreur.split('<br>');
										erreur = erremail[0];
									}
									erreurs.push(erreur);
								});
							},
			error: function (data)
							{
								erreurs.push('ProblÃ¨me de connexion. Veuillez rÃ©essayer.');
							}
		});
		
		// enlever le cryptage du mot de passe entrÃ©.
		$('#Pass-ins').val(Pass);
		$('#Confirmation-Pass-ins').val(Pass);
		
		if(erreurs.length){
			$('#errors-inscription').html('');
			for(var i=0;i<erreurs.length;i++){
				$('#errors-inscription').append('<li>'+erreurs[i]+'</li>');
			}
			$('#errors-inscription').show();
			return false;
		}
		else
		{
			$('#Email').val(Email);
			$('#Pass').val(Pass);
			$('#connexionForm').submit();
			return false;
		}
		
	});
	/* FIN Validation forumlaire d'inscription, ajouts Issam BOUZIANE 21/12/2011 */
	jQuery('#block-rub-special .rub-special').click(function(){
		jQuery(this).addClass('active');	
	});
	
	/* Ajoute un <br /> aux pages articles qui n'ont pas de TOC */
	jQuery('div.articlev').filter(function(){
      
      return !jQuery('div.rubrique-con',this)[0];
	  }).children('p.axa_paragraph-articles').prepend('<br /><br />');
	  
	  
	/* Ajoute un espace en cas de texte en <b> avant la TOC dans un article. */
	jQuery('div.articlev b:first-child').filter(function(){
      // retourne true si 
      return !jQuery('ul.menu',this)[0];
	  }).css({top:'15px',position:'relative'});
	  
	jQuery('div.articlev span:first-child').prepend('<br />');
	 
	 
	jQuery('a').each(function(){
		var tabDoctype = new Array('pdf','doc');
		var exptype = '(';
		exptype += tabDoctype.join('|');
		exptype += ')';
		var link = jQuery(this).attr('href');
		var expLink = new RegExp(exptype+'$', 'g');
		//console.log(expLink.test(link));

		if (expLink.test(link)) {
			jQuery(this).attr('target','_blank');
			var content_gqr = jQuery('.articlev a');

			if (content_gqr.length > 0) {
			var imagePDF = jQuery(document.createElement("img")).attr("src","fileadmin/templates/html/GQR/images/picto-pdf.gif");
			jQuery(this).append(imagePDF);
			/*modification sofiane*/
			//jQuery(this).prepend('<br />');
			}
		}
	});
	
	/* Ajouter pour Achedar Sofiane */
	if (jQuery(".subheader p")) {
		var hpage = jQuery(".subheader p").height();
		//alert(hpage);
		if (hpage > 100){
			jQuery(".listen-artcile").attr({style: "top:132px"});
		}
		if (hpage === 105){
			jQuery(".listen-artcile").attr({style: "top:135px"});
		}
		if (hpage > 115){
			jQuery(".listen-artcile").attr({style: "top:150px"});
			jQuery(".subheader p").append("<br /><br /><br /><br /><br />");
		}
		if (hpage === 135){
			jQuery(".listen-artcile").attr({style: "top:180px"});
		}
		if (hpage > 149){
			jQuery(".listen-artcile").attr({style: "top:179px"});
			jQuery(".subheader p").append("");
		} 
	}
	
	//jQuery(jQuery("div.tx-sqligestionrubrique-pi5").html()).insertAfter("div.axa_article-intro");
	//jQuery("div.tx-sqligestionrubrique-pi5").html('');
	
	
	/*.ready(function (){
		jQuery(jQuery(this).html()).insertAfter("div.axa_article-intro");
		jQuery(this).html('');
	});*/

	jQuery("a.facebook_home").click(
     function(){
		u="http://www.axasante.fr/"+$(this).closest("div.title-main2").siblings("div.content-side1").children("h3").children("a").attr("href");
		t=$(this).closest("div.title-main2").siblings("div.content-side1").children("h3").children("a").html();
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
		}
	);
	jQuery("a.tweeter_home").click(
		function(){
			url="http://www.axasante.fr/"+$(this).closest("div.title-main2").siblings("div.content-side1").children("h3").children("a").attr("href");
			window.open('http://twitter.com/share?url='+url);
		}
	); 
});
