function characterCount() {
	if( $('input#limiteCartaInput')[0])
	{
		var text = tinyMCE.selectedInstance.getBody().innerHTML.replace(/(<([^>]+)>)/ig,'');
	    $('#compteurCara').html(text.length);
	     if (text.length > $('input#limiteCartaInput').val())
	     {
	    	 $('#compteurCara').addClass('tropdeCara');
	    	 $('div.send_form').hide();
	    	 $('.erreurCara').show();
	     }
	     else
	     {
	    	 $('#compteurCara').removeClass('tropdeCara');
	    	 $('div.send_form').show();
	    	 $('.erreurCara').hide();
	     }
	}
}
function noaccent(chaine) {
	temp = chaine.replace(/[àâä]/gi,"a");
	temp = temp.replace(/[éèêë]/gi,"e");
	temp = temp.replace(/[îï]/gi,"i");
	temp = temp.replace(/[ôö]/gi,"o");
	temp = temp.replace(/[ùûü]/gi,"u");
	return temp;
}	
function regionSuivante()
{
	/*var active = $('ul.listeRegions a.active').attr('class');
	var toto = false;
	$('ul.listeRegions a').each(function()
			{
		if(toto)
		{
			setRegion($(this).attr('class'));
			return false;
		}
		else
		{
			if($(this).attr('class') == active) 
			{
				toto = true;
			}
		}
			});*/
	var active = $('#carte area.active').attr('alt');
	var toto = false;
	$('#carte area').each(function()
	{
		 if(toto)
		 {
			 setRegion($(this).attr('alt'));
			 return false;
		 }
		 else
		 {
			if($(this).attr('alt') == active) 
			{
				toto = true;
				if(active == $('#carte area:last').attr('alt'))
				{
					 setRegion($('#carte area:first').attr('alt'));
				}
			}
		 }
	 });
}
function setRegion(region)
{
	$('img#carteImage').attr("src", '/img/carte/' + region + '.gif');
	$('#carte area').removeClass('active');
	$('#carte area.' + region).addClass('active');
}

function regionSuivante2()
{
	var active = $('#carte2 area.active').attr('alt');
	var toto = false;
	$('#carte2 area').each(function()
	{
		 if(toto)
		 {
			 setRegion2($(this).attr('alt'));
			 return false;
		 }
		 else
		 {
			if($(this).attr('alt') == active) 
			{
				toto = true;
				if(active == $('#carte2 area:last').attr('alt'))
				{
					 setRegion2($('#carte2 area:first').attr('alt'));
				}
			}
		 }
	 });
}
function setRegion2(region)
{
	$('img#carteImage2').attr("src", '/img/carte2/' + region + '.gif');
	$('#carte2 area').removeClass('active');
	$('#carte2 area.' + region).addClass('active');
}

function alert(a)
{
	console.log(a);
}
$(function() {
	 
	function attention(ou)
	{
		var idsSecteurs = new Array();
		var idsNiveau = new Array();
		$('input.secteur:checked').each(function(){
			idsSecteurs.push($(this).attr('id').substr(9));
		});
		$('input.niveau:checked').each(function(){
			idsNiveau.push($(this).attr('id').substr(7));
		});
		var recherche1 = '';
		if($('input#recherche1')[0])
		{
			recherche1 = '-' + $('input#recherche1').val();
		}
		
		var recherche2 = '';
		if($('input#recherche2')[0])
		{
			recherche2 = '-' + $('input#recherche2').val();
		}
	
		
		if(idsSecteurs.length == 0 && idsNiveau.length == 0 && recherche1 == '' && recherche2 == '')
		{
			document.location.href=ou;
		}
		else
		{
			document.location.href=ou +'/1/secteurs-' +idsSecteurs.join('-') + '/niveaux-' + idsNiveau.join('-')+'/' +recherche1 +'/' +recherche2;
		}
		return false;
	}

	$("#acachercontact").hide();
	$("#acachercontact input#contact1").val('');
	$("#acachercontact input#contact2").val('test@free.fr');
	
	$(".changeRegionCarte").click(function(){
		attention($(this).attr('rel'));
	});

	
	$(".changeRegionCarte2").click(function(){
		attention($(this).attr('rel'));
	});

	var interval;
	// Carte
	if($('#carte2 area.active')[0])
	{
	//	alert('ok une active');
		var base = $('#carte2 area.active').attr('alt');
		setRegion2(base);
		
		$('map#carte2 area').mouseenter(function(){
			setRegion2( $(this).attr("alt"));
		}).mouseleave(function(){
			//setRegion2(base);
		});
		$('img#carteImage2').mouseleave(function(){
			setRegion2(base);
		});
		
	}
	else
	{
		$('#carte2 area:first').addClass('active');
		$('map#carte2 area').mouseenter(function(){
			clearInterval(interval);
			setRegion2( $(this).attr("alt"));
		}).mouseleave(function(){
			interval = setInterval("regionSuivante2()", 1400);
		});
		interval = setInterval("regionSuivante2()", 1400);
	}
	
	//var interval;
	// Carte
	/*
	if($('#carte area.active')[0])
	{
	//	alert('ok une active');
		var base = $('#carte area.active').attr('alt');
		setRegion(base);
		
		$('map#carte area').mouseenter(function(){
			setRegion( $(this).attr("alt"));
		}).mouseleave(function(){
			//setRegion(base);
		});
		$('img#carteImage').mouseleave(function(){
			setRegion(base);
		});
		
	}
	else
	{
		$('#carte area:first').addClass('active');
		$('map#carte area').mouseenter(function(){
			clearInterval(interval);
			setRegion( $(this).attr("alt"));
		}).mouseleave(function(){
			interval = setInterval("regionSuivante()", 1400);
		});
		interval = setInterval("regionSuivante()", 1400);
	}
	
	*/
	
	// Corner
	
	if($('a.inscriptionEvenement, a.inscriptionEtablissement')[0])
	{
		$('a.inscriptionEvenement, a.inscriptionEtablissement').corner("10px");	
	}
	$('div#menu').corner("10px");
	if(!$.browser.msie)
	{
		
		
		
		$('div#content').corner("10px bottom");
		$('div#menu ul li a').corner("5px");
		$('div.affichageEvenement').corner("5px");
	}
	$('.plusinfo').corner("10px tl bl");
	
	
	//Menu
	$('div#menu a').click(function(){
		$(this).toggleClass("active");
	});

	
	
	
	$('#noaccent').keyup(function(){
		var recherche = $('#noaccent').val();
		recherche = noaccent(recherche).toLowerCase();
		recherche = recherche.replace(/ /gi, '-');
		recherche = recherche.replace(/'/gi, '-');
		recherche = recherche.replace(/"/gi, '-');
		recherche = recherche.replace(/°/gi, '-');
		recherche = recherche.replace(/--/gi, '-');
		$('#noaccent').val(recherche);
	});
	

	
	$('input.text').focusin(function(){
		$(this).parent().addClass('focus');
	  }).focusout(function(){
		$(this).parent().removeClass('focus');
	  });
	


	
	$('div.actualite').mouseenter(function(){
		// $('.liresuite',this).show();
		// $(this).css('cursor', 'pointer').addClass('gris');
		 $(this).addClass('gris');
	}).mouseleave(function(){
		// $('.liresuite',this).hide();
		 $(this).removeClass('gris');
	  });

	/* Fiche établissement*/
	
		$("#accordionFicheFormation").accordion({
			autoHeight: false,
			 collapsible: true,
			 active:false,
			 navigation: true
		});
	
	var photoSliderAlreadyRunning = false;
	
	
	
	
	/*
	$("a.linkFormation").click(function(){
		var id = $(this).attr('rel');
		$tabs.tabs('select',1);
		var index = -1;
		var count = 0;
		$("#accordionFicheFormation h3").each(function(){
			if($(this).hasClass('pos-'+id))
			{
				index = count;
			}
			count++;
		});
		
		$("#accordionFicheFormation").accordion( "activate" , index );
		
	});
	*/
	
	




	$("#photoSliderInside a").click(function(){
		if(photoSliderAlreadyRunning == false)
		{
			photoSliderAlreadyRunning = true;
			$(".slider").easySlider({
				numeric: true,
				auto:true,
				continuous:true
			});
		}
	});
	$(".tweetToggle").click(function(){
		$('li.tw').toggle()
	});
	
	
	
	//Contact sur une formation
	$("a.formationContactQuestion").click(function(){
		$tabs.tabs('select','contact');
		var name = $(this).attr('rel');
		setContactInfo("questionFormation", name);
	});
	//Contact sur salon-virtuel
	$("a.salonVirtuelQuestion").click(function(){
		$tabs.tabs('select','contact');
		var name = $(this).attr('rel');
		setContactInfo("salon-virtuel", '');
	});
	
	
		$('area.regionOver').mouseover(function(){
			var posOver = $(this).attr('pos');
			$('span#imgOver').css('background-position',posOver);
			$('div.receptionRegion').html($(this).attr('alt'));
		});
	
		 $('.plusinfo').click(function(){
			if($(this).hasClass('toto'))
			{
				$(this).removeClass('toto').css('background-color', '#89b03d');
			}
			else
			{
				$(this).addClass('toto').css('background-color', '#7D2E1F');
			}
			$('.gauche',$(this).parent().parent()).toggle();
		 }).mouseover(function(){
			 $(this).css('cursor', 'pointer');
		 });
		 
		 $('.cache').click(function(){
			var acacher = $(this).attr('id');
			 $('.'+acacher).toggle();
		 });
		 /*
		 $('#pub div.pub').each(function(){
				var hauteurTotale = 92;
				var hauteurLogo = $('a img',$(this)).height();
				var newH = (hauteurTotale - hauteurLogo) /2;
				newH = newH < 0 ? 0 : newH;
				$(this).css('margin-top', newH)
			});
		 */
		 
	
				//$('div.gauchetest').css('margin-top', '20px');

			
	
});

function stat(idEta)
{
	$.ajax({
	   type: 'POST',
	   url: '/etablissement/statClickSite/',
	   data: 'id=' + idEta
	 });
	
}



function strip_tags (str, allowed_tags) {
    // Strips HTML and PHP tags from a string  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/strip_tags
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Tomasz Wesolowski
    // *     example 1: strip_tags('<p>Kevin</p> <b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];
    var allowed_array = ['strong', 'b', 'ul', 'ol','li', 'u', 'i', 'em','br'];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
 
    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }
 
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}
