$(document).ready(function() {

/*
	$('.cform:not(:#svm_login_Form)').each(function() {
    	$(this).children("fieldset").children("legend").replaceWith("<h3>Contact</h3><p>Veuillez nous contacter à l'adresse suivante: <a href='mailto:%69%6E%66%6F%40%73%76%6D%65%64%2E%63%68'>info@svmed.ch</a><p>");
    	$(this).children("fieldset").children("ol").css("display", "none");
    	$(this).children(".cf-sb").css("display", "none");
	});
	
    $('#cforms29form, #cforms20form, #cforms21form, #cforms28form').replaceWith("<h3>Contact</h3><p>Veuillez nous contacter à l'adresse suivante: <a href='mailto:%69%6E%66%6F%40%73%76%6D%65%64%2E%63%68'>info@svmed.ch</a><p>");  
*/

	$("#cforms13form").validate({
		rules: {
			cf13_field_2: "required",
			cf13_field_3: "required",
			cf13_field_4: "required",
			cf13_field_5: "required",
			cf13_field_6: "required",
			cf13_field_7: {
				required: true,
				email: true
			},
			cf13_field_8: "required",
			cf13_field_9: "required",
			cf13_field_13: "required"
		},
		messages: {
			cf13_field_13: "Veuillez accepter les conditions..."
		}
	});
	
	$(".page-item-45 a").attr("target", "_blank");
	
	$(".demande_mails_securises .cform #li-2-2, .demande_mails_securises .cform #li-2-4, .demande_mails_securises .cform #li-2-5, .demande_mails_securises .cform #li-2-6").append("<span class='url_mail'>@svmed.ch</span>");
	
	$(".demande_mails_securises .cform #li-2-1").append("<span class='point_mail'>.</span>");
	
	$(".demande_mails_securises .cform #cf2_field_1").attr("value", $("#user_name").html());
	$(".demande_mails_securises .cform #cf2_field_2").attr("value", $("#user_name_2").html());
	
	$(".demande_mails_securises #sendbutton2").click(function(){
		value1 = $(".demande_mails_securises #cf2_field_8").attr("value");
		value2 = $(".demande_mails_securises #cf2_field_9").attr("value");
		if(value1 != value2){
			alert("Veuillez contrôler l'email secondaire ainsi que la confirmation de celui-ci...");
			$(".demande_mails_securises #cf2_field_8").addClass("cf_error");
			$(".demande_mails_securises #cf2_field_9").addClass("cf_error");
			return false
		}else{
			return true
		}
 	});
	
	
				
	$("#content_left tr:even").css("background-color", "#FFF");
  	$("#content_left tr:odd").css("background-color", "#F4F4F4");
  	
  	$('#content_left table').each(function() {
    	$(this).children("tbody").children("tr").eq(0).css("background-color", "#008887");
    	$(this).children("tbody").children("tr").eq(0).css("color", "#FFF");
    	$(this).children("tbody").children("tr").eq(0).children("td").children("strong").css("font-weight", "normal");
    	$(this).children("tbody").children("tr").eq(0).css("text-transform", "uppercase");
  	});
  	
  	$('#content_right table').each(function() {
    	$(this).children("tbody").children("tr").eq(0).css("background-color", "#008887");
    	$(this).children("tbody").children("tr").eq(0).css("color", "#FFF");
    	$(this).children("tbody").children("tr").eq(0).children("td").children("strong").css("font-weight", "normal");
    	$(this).children("tbody").children("tr").eq(0).css("text-transform", "uppercase");
  	});
  	
  	pathArray = window.location.pathname.split( '/' );
  	
  	if(pathArray[2] != "comite" && pathArray[1] != "acces-membres"){
  		$("#content_full tr:even").css("background-color", "#FFF");
	  	$("#content_full tr:odd").css("background-color", "#F4F4F4");
	  	
	  	$('#content_full table').each(function() {
	    	$(this).children("tbody").children("tr").eq(0).css("background-color", "#008887");
	    	$(this).children("tbody").children("tr").eq(0).css("color", "#FFF");
	    	$(this).children("tbody").children("tr").eq(0).children("td").children("strong").css("font-weight", "normal");
	    	$(this).children("tbody").children("tr").eq(0).css("text-transform", "uppercase");
	  	});

  	}
  	
	// Reset Font Size
	var originalFontSize = $('html').css('font-size');
	
	$(".resetFont").click(function(){
		$('html').css('font-size', originalFontSize);
	});
	
	// Increase Font Size
	$(".increaseFont").click(function(){
		$i = $("#content_left").length;
		if($i == 1){
			var currentFontSize = $('#content_left p').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('#content_left p').css('font-size', newFontSize);
			$("#content").height("auto");
			height_sidebar = $("#content").height();
			$("#content_right").height(height_sidebar-50);
		}else{
			var currentFontSize = $('#content_full p').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('#content_full p, #content_full ul, #content_full a').css('font-size', newFontSize);
			$("#content").height("auto");
		}
		return false;
	});
	
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		$i = $("#content_left").length;
		if($i == 1){
			var currentFontSize = $('#content_left p').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('#content_left p').css('font-size', newFontSize);
			$("#content_right").height("auto");
			height_sidebar = $("#content").height();
			$("#content_right").height(height_sidebar-50);
		}else{
			var currentFontSize = $('#content_full p').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('#content_full p, #content_full ul, #content_full a').css('font-size', newFontSize);
			$("#content").height("auto");
		}
		return false;
	});
	
	$('#search_doctor_submit, #search_doctor_submit_page').click(function(){
		val_name = $('#tagsName').val();
		val_speciality = $('#tagsSpeciality').val();
		val_city = $('#tagsCity').val();
		url = "http://www.svmed.ch/resultats-trouver-un-medecin/?";
		if(val_name != "Nom, Prénom"){
			//val_name = no_accent(val_name);
			//val_name = val_name.toUpperCase();
			url += "Name="+val_name;
			
			// modifié pour pouvoir revenir en arrière
			window.location = url;
		}else{
			if(val_speciality != "Spécialité"){
				url += "Speciality="+val_speciality;
				if(val_city != "Localité"){
					url += "&City="+val_city;
				}
				window.location = url;
			}else{
				if(val_city != "Localité"){
					url += "City="+val_city;
				}
				window.location = url;
			}
		}
	});

	legend_exist = $('.cform').children('fieldset.cf-fs1').children('legend').length;
	if(legend_exist >= 1){
		$('.cform').each(function(){
			$(this).children('fieldset.cf-fs1').children('.cf-ol').css("display","none");
			$(this).children('.cf-sb').css("display","none");
			html = $(this).children('fieldset.cf-fs1').children("legend").html();
			$(this).children('fieldset.cf-fs1').children("legend").html("");
			$(this).children('fieldset.cf-fs1').children("legend").html("<p>"+html+"</p>");
			$(this).children('fieldset.cf-fs1').children("legend").append("<span class='arrow_form'></span>");
   		});
	}
	
	$('#jGlide_001').jGlideMenu({
				tileSource	: '.jGlide_001_tiles' , 
				demoMode : false
			}).show();
	
	$(".cform .cf-fs1 legend").click(function() {
		if($(this).children('.arrow_form').attr("class") == "arrow_form"){
			$(this).children('.arrow_form').addClass("open");
			var parent = $(this).children('.arrow_form').parent('legend').parent('.cf-fs1');
			form = parent.parent('.cform');
			parent.children(".cf-ol").slideDown();
			form.children('.cf-sb').css('display','block');
			$("#content").height("auto");
			$.scrollTo(form, 1000);
			setTimeout(function() { 
				height_content = $("#content").height();
				$("#content_right").height(height_content);
			}, 1000);  
		}else{
			$(this).children('.arrow_form').removeClass("open");
			parent = $(this).children('.arrow_form').parent('legend').parent('.cf-fs1');
			form = parent.parent('.cform');
			parent.children(".cf-ol").slideUp(); 
			form.children('.cf-sb').css('display','none');
			height_content = $("#sidebar").height();
			$("#content_right").height(height_content);
		}
	});

	
	setTimeout(function(){
		height_sidebar = $("#sidebar").height();
		height_content = $("#content").height();
		if(height_sidebar < height_content){
			$("#sidebar").height(height_content);
			$("#content").height(height_content);
		}else{
			$("#content").height(height_sidebar);
		}
	}, 600) 

	setTimeout(function(){	
		height_content_right = $("#content_right").height();
		height_sidebar = $("#sidebar").height();
		if(height_sidebar < height_content_right){
			$("#sidebar").height(height_content_right);
		}else{
			$("#content_right").height(height_sidebar-81);
		}
	}, 600) 
	
	 $("#formation").tablesorter({ 
        headers: { 
            5: { 
                sorter: false 
            }, 
            6: { 
                sorter: false 
            },
            1: {
            	sorter: "shortDate"
            }
        },
        dateFormat: 'uk',
        widgets: ['zebra']
    }); 
    
   	$("#actualites").tablesorter({ 
        headers: { 
            0: {
            	sorter: "shortDate"
            }
        },
        dateFormat: 'uk',
        widgets: ['zebra']
    }); 
	

	$('#content_full img').each(function(index) {
    	$(this).parent('a[href$=".jpg"]').addClass("fancy_img");
  	});
  	
  	$('#content_left img').each(function(index) {
    	$(this).parent('a[href$=".jpg"]').addClass("fancy_img");
  	});
  
	$('#content_full img').each(function(index) {
    	$(this).parent('a[href$=".gif"]').addClass("fancy_img");
  	});
  	
  	$('#content_left img').each(function(index) {
    	$(this).parent('a[href$=".gif"]').addClass("fancy_img");
  	});
  
	$('#content_full img').each(function(index) {
    	$(this).parent('a[href$=".png"]').addClass("fancy_img");
  	});
  	
  	$('#content_left img').each(function(index) {
    	$(this).parent('a[href$=".png"]').addClass("fancy_img");
  	});
  
	$("#menu_top_header li:last-child a").css("padding-right","0");
	$("#menu_top_header li:last-child a").css("border-right","none");
	
	$("#footer li:last-child").css("padding-right","0");
	$("#footer li:last-child").css("border-right","none");
	
	$("#footer_quicklinks li:last-child").css("padding-right","0");
	$("#footer_quicklinks li:last-child").css("border-right","none");
	
	$("#footer_quicklinks_page li:last-child").css("padding-right","0");
	$("#footer_quicklinks_page li:last-child").css("border-right","none");
	
	$("#menu>li>a>span").css("display","block");
	$("#menu>li:first-child>a>span").css("display","none");
		
	$(".scrollable").scrollable({
		circular: true,
		onSeek: function(event, i) {
			$(".items").children('div').eq(i+1).children('.slider_txt').fadeIn();
			$(".items").children('div').eq(i).children('.slider_txt').css("display","none");
			$(".items").children('div').eq(i-1).children('.slider_txt').css("display","none");
			$(".items").children('div').eq(i-2).children('.slider_txt').css("display","none");
			$(".items").children('div').eq(i+2).children('.slider_txt').css("display","none");
		}
	}).autoscroll({
		interval: 6000, autoplay: true
	}).navigator();
	
	$(".link_block_portail, .txt_selection_link_portail").click(function() {
		parent_block = $(this).parent('.selection_link_portail');
		class_block = parent_block.attr('class');
		if(class_block == "selection_link_portail"){
			$('.link_block_portail').html('+');
			parent_block.addClass('active');
			parent_block.children('.link_block_portail').html('-');
			$("#content").css("height","");
			$('.link_block_portail').css("display","block");
	  		$('.content_portail_block').slideUp();
	  		$('.selection_link_portail').css("background-color","#FFF");
	  		block = $(this).parent('.selection_link_portail');
	  		block.children('.content_portail_block').slideDown();
	  		block.css("background-color","#F2F8F8");
		}else{
			parent_block.removeClass('active');
			parent_block.children('.link_block_portail').html('+');
			$('.link_block_portail').css("display","block");
	  		$('.content_portail_block').slideUp();
	  		$('.selection_link_portail').css("background-color","#FFF");
	  		block = $(this).parent('.selection_link_portail');
	  		block.children('.content_portail_block').slideUp();
	  		block.css("background-color","#FFFFFF");
		}
	});
	
	$('.input_search_doctor').click(function() {
  		$(this).val("");
	});
	
	$('#cf3_field_2-2').click(function() {
  		if($('#li-3-7').is(":visible") == "true" ){
  			$("#li-3-7").fadeOut();
  			$("#li-3-8").fadeOut();
  			$("#li-3-9").fadeOut(); 
		}else{
  			$("#li-3-7").fadeIn();
  			$("#li-3-8").fadeIn();
  			$("#li-3-9").fadeIn();
		}

	});
	
	$('#display_other_input_search').click(function() {
		$("#display_other_input_search").css("display","none");
  		$("#div_other_input_search").slideDown("fast");
	});
	
	$('#cf13_field_10').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "Oui"){
			$("#li-13-11").fadeIn();	
		}else{
			$("#li-13-11").fadeOut();
		}
	});
	
	$('#cf26_field_14').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "Je suis membre d'une autre association"){
			$("#li-26-15").fadeIn();	
		}else{
			$("#li-26-15").fadeOut();
			height_content = $("#content_full").height();
  			$("#sidebar").height(height_content+50);
  			$("#content").height(height_content+50);
		}
	});
	
	$('#cf26_field_17').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "Travailler à temps partiel"){
			$("#li-26-18").fadeIn();	
			$("#li-26-19").fadeIn();	
			$("#li-26-20").fadeIn();	
			height_content = $("#content_full").height();
  			$("#sidebar").height(height_content+50);
  			$("#content").height(height_content+50);
		}else{
			$("#li-26-18").fadeOut();
			$("#li-26-19").fadeOut();
			$("#li-26-20").fadeOut();
		}
	});
	
	$('#cf25_field_14').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "Je suis membre d'une autre association"){
			$("#li-25-15").fadeIn();	
		}else{
			$("#li-25-15").fadeOut();
			height_content = $("#content_full").height();
  			$("#sidebar").height(height_content+50);
  			$("#content").height(height_content+50);
		}
	});
	
	$('#cf25_field_17').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "En association"){
			$("#li-25-18").fadeIn();	
			height_content = $("#content_full").height();
  			$("#sidebar").height(height_content+50);
  			$("#content").height(height_content+50);
		}else{
			$("#li-25-18").fadeOut();
		}
	});
	
	$( "#cf7_field_8" ).datepicker({
		dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		firstDay: 1,
		dateFormat: 'dd.mm.yy'
	});
	
	$( "#cf25_field_25" ).datepicker({
		dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		firstDay: 1,
		dateFormat: 'dd.mm.yy'
	});
	
	$( "#cf26_field_27" ).datepicker({
		dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		firstDay: 1,
		dateFormat: 'dd.mm.yy'
	});
	
	$("#li-25-16").append("<span class='reqtxtcheckbox'>*</span>");	
	$("#li-26-16").append("<span class='reqtxtcheckbox'>*</span>");	
	
	$("a.fancy_img").colorbox({transition:"fade",maxHeight: 600, maxWidth: 800});
	
	$("a[rel='group']").colorbox({transition:"fade",maxHeight: 600, maxWidth: 800});
	
	setTimeout(function() { 
		$("#membre").fadeIn(1000);
	}, 500);  
	
	setTimeout(function() { 
		$("#futur-membre").fadeIn(1000);
	}, 1000); 
	 
	setTimeout(function() { 
		$("#patient").fadeIn(1000);
	}, 1500);
	  
	setTimeout(function() { 
		$("#media").fadeIn(1000);
	}, 2000);
	
	
	$(".print_doctor").click(function(){
		var printDivCSS = new String ('<link href="http://www.svmed.ch/wp-content/themes/svm/css/print.css" media="print" rel="stylesheet" type="text/css">');
	    
	    //window.frames["print_frame"].document.head.innerHTML = printDivCSS ;
	    $("head",$("#print_frame").contents()).append('<link href="http://www.svmed.ch/wp-content/themes/svm/css/print.css" media="print" rel="stylesheet" type="text/css">');
	    //window.frames["print_frame"].document.getElementById("content").innerHTML = $(this).parent().html();
	    var doctor_content = $(this).parent().html();
	    $("div.target",$("#print_frame").contents()).empty().append(doctor_content);
	    window.frames["print_frame"].window.focus();
	    setTimeout(function() { 

	    	window.frames["print_frame"].window.print();
		}, 500);  

   	});
   	$(".maplink").colorbox({iframe:true, innerWidth:500, innerHeight:300});
	$(".result_doctor").hover(
	  function () {
	    $(this).children(".print_doctor").fadeIn();
	    $(this).children(".doctor_on_map").fadeIn();
	  }, 
	  function () {
	    $(this).children(".print_doctor").fadeOut();
	    $(this).children(".doctor_on_map").fadeOut();
	  }
	);	

/*
	$(".jGM_tile").each(function(index) {
    	$(this).children(".jGM_pager").css("margin-top", "25px");
 	 });
*/
	
/* 	$(".jGM_tile").children(".jGM_pager:first").css("margin-top", "25px"); */
	
});
	
function no_accent (my_string) {
	var new_string = "";
	var pattern_accent = new Array("é", "è", "ê", "ë", "ç", "à", "â", "ä", "î", "ï", "ù", "ô", "ó", "ö");
	var pattern_replace_accent = new Array("e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "o", "o", "o");
	if (my_string && my_string!= "") {
		new_string = preg_replace(pattern_accent, pattern_replace_accent, my_string);
	}
	return new_string;
}

function preg_replace (array_pattern, array_pattern_replace, my_string)  {
	var new_string = String (my_string);
		for (i=0; i<array_pattern.length; i++) {
			var reg_exp= RegExp(array_pattern[i], "gi");
			var val_to_replace = array_pattern_replace[i];
			new_string = new_string.replace (reg_exp, val_to_replace);
		}
		return new_string;
}

