function ChangeOnglet(onglet, contenu) {	
	document.getElementById('content_1').style.display = 'none';
	document.getElementById('content_2').style.display = 'none';
	document.getElementById('content_3').style.display = 'none';
	document.getElementById('content_4').style.display = 'none';
	document.getElementById(contenu).style.display = 'block';		

	document.getElementById('tab_1').className = '';
	document.getElementById('tab_2').className = '';
	document.getElementById('tab_3').className = '';
	document.getElementById('tab_4').className = '';
	document.getElementById(onglet).className = 'active';		
}


function ChangeOnglet_3(onglet, contenu) {	
	document.getElementById('content2_1').style.display = 'none';
	document.getElementById('content2_2').style.display = 'none';
	document.getElementById('content2_3').style.display = 'none';
	document.getElementById('content2_4').style.display = 'none';
	document.getElementById(contenu).style.display = 'block';		

	document.getElementById('tabli_1').className = '';
	document.getElementById('tabli_2').className = '';
	document.getElementById('tabli_3').className = '';
	document.getElementById('tabli_4').className = '';
	document.getElementById(onglet).className = 'active';		
}


function ChangeOnglet_2(active, nombre, tab_prefix, contenu_prefix) {   
    for (var i=1; i < nombre + 1; i++) {
      document.getElementById(contenu_prefix + i).style.display = 'none';
      document.getElementById(tab_prefix + i).className = '';
    }  
    document.getElementById(contenu_prefix+active).style.display = 'block';
    document.getElementById(tab_prefix+active).className = 'active';   
}


$(function() {
	$('#footer1 a').each(function() {
		$(this).width($(this).width() + 10);
	});

	debugCss();
	
	if ($('#page_panier_paiement').length > 0) {
		var mask = $('<div></div>');
		
		mask.css({
			position: 'absolute',
			height: '302px',
			width: $('#page_panier_paiement').width() + 36,
			marginLeft: '-21px',
			marginTop: '57px',
			zIndex: 99999,
			background: 'black',
			opacity: .3
		});
		
		$('#page_panier_paiement').prepend(mask);
	}
	
    //find all form with class jqtransform and apply the plugin
    $("form.jqtransform").jqTransform();
	
	$('a[rel]').overlay({ 
		top: 350,
		expose: { 
			color: '#333', 
			loadSpeed: 200, 
			opacity: 0.9 
		}
	});	
	
	$('#bloc_droite ul li a').each(function(i) {
		var fleche = $('.bloc_gauche_img:eq(' + i + ')').find('.fleche a');
	
		if (i != 0) {
			$('.bloc_gauche_img:eq(' + i + ')').hide();
		} else {
			$(this).addClass('actif');
		}
	
		$(this).click(function() {
			$('#bloc_droite ul li a').removeClass('actif');
			
			$(this).addClass('actif');
		
			$('.bloc_gauche_img').hide();
			
			$('.bloc_gauche_img:eq(' + i + ')').show();
		});
		
		fleche.click(function() {
			var value_right1 = '0px';
			var value_right2 = '-300px';
			var bloc_move = $('.bloc_gauche_img .bloc_gauche_txt');
		
			bloc_move.css('position', 'absolute');
		
			if ($.browser.msie && ($.browser.version < 8)) {
				value_right1 = '-30px';
				value_right2 = '-300px';
				
				if ($('.bloc_gauche_img:eq(' + i + ') .bloc_gauche_txt').hasClass('has_move')) {
					value_right1 = '0px';
					value_right2 = '-300px';
				}
			}
			
			bloc_move.removeClass('has_move');
		
			if ($('.bloc_gauche_img:first .bloc_gauche_txt').css('right') <= value_right2) {
				bloc_move.animate({
					right: value_right1
				}, function() {
					bloc_move.addClass('has_move');
				});
			} else {
				bloc_move.animate({
					right: value_right2
				}, function() {
					bloc_move.addClass('has_move');
				});
			}
		});
	});
	
	$('#page_recherche th#entete1').click(function() {
		if ($(this).hasClass('checked')) {
			$(this).parent().parent().parent().find('input[type=checkbox]').removeAttr('checked');
			
			$(this).removeClass('checked');
		} else {
			$(this).parent().parent().parent().find('input[type=checkbox]').attr('checked', 'checked');
			
			$(this).addClass('checked');
		}
	});
});




$(function() {
    	
	$('.table_panier .tabletd5').each(function() {
		var $$ = $(this);
		var bloc_select = $$.find('div');
		var bloc_input = bloc_select.find('input:first');
		var this_content = $$.find('p');
		var content = $$.find('p').text();
	

		bloc_select.find('tr:gt(0)').each(function() {
			var value_td = $(this).find('td.pop_up-table-td1 input').val();
			
			if (content == value_td) {
				$(this).addClass('current');
			}
		});
		
		this_content.html(bloc_select.find('tr.current td:eq(1)').html());
		
		var input_indemn_val = $$.find('input.indemn').val();
		$$.parent().find('.tabletd2 span').text(input_indemn_val);
		
/*		if (input_indemn_val != '-') {
			var input_indemn_val_td3 = input_indemn_val.split(' ');
		
			$$.parent().find('.tabletd3 input').val(input_indemn_val_td3[0]);
		} else {
			$$.parent().find('.tabletd3 input').val('1.00');
		}
*/		
		bloc_select.css({
			marginTop: -bloc_select.height() - 15,
			marginLeft: bloc_select.width() - 70
		});
		
		$$.hover(function() {
			bloc_select.fadeIn('fast');
		}, function() {
			bloc_select.fadeOut('fast');
		});
		
		bloc_select.find('tr:gt(0)').click(function() {
			var input_indemn_val = $(this).find('input.indemn').val();
		
			bloc_select.find('tr:gt(0)').removeClass('current');
			
			$(this).addClass('current');
			
			$$.parent().find('.tabletd2 span').text(input_indemn_val);
			
	/*		if (input_indemn_val != '-') {
				$$.parent().find('.tabletd3 input').val(input_indemn_val);
			} else {
				$$.parent().find('.tabletd3 input').val('1.00');
			}
	*/		
			
			var value_td = $(this).find('td.pop_up-table-td1 input').val();
			
			bloc_input.val(value_td);
			
			this_content.html($(this).find('td:eq(1)').html());
			
			checkStatusCart();
		});
	});
	
	$('.table_panier input[type=checkbox]').click(function() {
		var size_cart = $('.table_panier tbody tr.tabletd').length;
		
		if (size_cart > 1) {
			$(this).parent().parent().animate({
				opacity: 0
			}, 'slow', function() {
				$(this).remove();
				
				checkPriceCart();
			});
			
			$(this).parent().parent().next().animate({
				opacity: 0
			}, 'slow', function() {
				$(this).remove();
			});
		} else {
			$('#page_panier form').fadeOut('slow', function() {
				$(this).remove();
			});
		}
		
		checkSizeCart(1);
	
		var id = $(this).parent().parent().find('.tabletd_img1 input[type=hidden]').val();
		$.ajax({type: "POST", url:"panier/delete", data:{id: id}, success: function(){}});
	});
	
	$('.table_panier .tabletd3 input, #box_right #minimum input').keydown(onlyNumber);
	
	$('.table_panier .tabletd3 input').blur(checkPriceCart);
	
	checkSizeCart();
	
	checkPriceCart();
});

function onlyNumber(e) {
	var safe = true;
	var input_value = $(this).val();
	
	if (e.which > 105) {
		safe = false;
	}
	
	if (e.which < 96) {
		safe = false;
	}
	
	if (e.which == 110 && !input_value.match('[.]')) {
		safe = true;
	}
	
	if (input_value.match('[.]')) {
		var input_value_float = input_value.split('.');
	
		if (input_value_float[1].length > 1) {
			safe = false;
		}
	}
	
	if (e.which == 8 || e.which == 46) {
		safe = true;
	}
	
	if (e.which == 37 || e.which <= 39) {
		safe = true;
	}
	
	if (e.which == 38) {
		chiffre($(this).parent().find('a'), '+', 0.10)
	}
	
	if (e.which == 40) {
		chiffre($(this).parent().find('a'), '-', 0.10)
	}
	
	return safe;
}

function checkStatusCart() {
	$('.table_panier .tabletd2').each(function() {
		var input_value = $(this).parent().find('.tabletd3 input').val();
		var necessary_value =  $(this).find('span').text();
		var cell_status = $(this).parent().find('.tabletd4');
		
		if (parseFloat(input_value) >= parseFloat(necessary_value)) {
			cell_status.find('.tabletd4-span_1').show();
			cell_status.find('.tabletd4-span_2').hide();
			
			cell_status.css('background-color', '#e2ba13').css('color', '#fff');
		} else {
			cell_status.find('.tabletd4-span_1').hide();
			cell_status.find('.tabletd4-span_2').show();
			
			cell_status.css('background-color', '#fff').css('color', '#000');
		}
	});
}

function checkSizeCart(value_count) {
	var value_count = value_count || 0;
	var count_size_cart = $('.count_size_cart');
	var size_cart = $('.table_panier tbody tr.tabletd').length;
	var count_size_cart_top = $('#bloc_panier a').text().split(' ');
	
	if (count_size_cart) {
		count_size_cart.text(size_cart - value_count);
		
		$('#bloc_panier a').text((count_size_cart_top[0] - value_count) + ' ' + count_size_cart_top[1]);
	}
}

function checkPriceCart() {
	var count_price_cart = $('.count_price_cart');
	var price_cart = 0;

	if (count_price_cart) {
		$('.table_panier .tabletd3 input').each(function() {
			var value = parseFloat($(this).val());
			
			if ($(this).val() == '') {
				value = 0;
			}
		
			price_cart += value;
		});
		
		price_cart = parseFloat(price_cart);
		
		if (price_cart < 10) {
			price_cart += 0.30;
		}
		
		price_cart = Math.round(price_cart * 100) / 100;
		price_cart = price_cart.toString();
		
		if (price_cart.match('[.]')) {
			var temp = price_cart.split('.');
		
			if (temp[1].length < 2) {
				price_cart = price_cart + '0';
			}
		}
		
		count_price_cart.text(price_cart);
		
		checkStatusCart();
	}
}

function chiffre(element, montant, ajout) {
	var element_value = $(element).parent().find('input');
	var current_value = +element_value.val();
	var dec = 0;
	
	if (ajout.toString().indexOf('.') > -1){
		dec = ajout.toString().split('.')[1].length;
	}
	
	switch (montant) {
	
		case '+' :
			
			current_value = Math.round((current_value + ajout) * Math.pow(10, dec), 0) / Math.pow(10, dec);
		
		break;
		
		case '-' :
			
			current_value = (current_value > 0) ? Math.round((current_value - ajout) * Math.pow(10, dec), 0) / Math.pow(10, dec) : current_value;
			
			if (current_value < .3) {
				return false;
			}
		
		break;
	
	}
	
	current_value = current_value.toString();
	
	if (current_value.match('[.]')) {
		current_value = current_value + '0';
	}
	
	element_value.val(current_value);
	
	checkPriceCart();
}

//Fonctions pour les ayants-droits

//Code pour faire d'un radio une checkbox
function InactiveCheckBox(Quoi){
  document.getElementById(Quoi).checked = false ;
}

//Calendrier pour la saisie
$(function() {
		$('.datepicker').datepicker({
			yearRange: '1920:2100',		
			//changeMonth: true,
			changeYear: true
	});
});

$(function() {
		$('.datepicker-over18').datepicker({
			yearRange: '1920:2100',
			//changeMonth: true,
			changeYear: true,
			maxDate: '-17Y'
	});
});
//			
//Changement d'onglet inscription


function ChangeOnglet_4(onglet, contenu) {	
	document.getElementById('content_1').style.display = 'none';
	document.getElementById('content_2').style.display = 'none';
	document.getElementById(contenu).style.display = 'block';

	document.getElementById('tab_1').className = '';
	document.getElementById('tab_2').className = '';
	document.getElementById(onglet).className = 'active';		
}


//affichage d'option image avec un li
function showHideSelect(element) {
	var element_ul = $(element).parent().find('ul');
	
	$('.inputsSelect ul').hide();

	if (element_ul.is(':visible')) {
		element_ul.hide();
	} else {
		element_ul.show();
	}
}

function validAndHide(value_input, element) {
	$(element).parent().parent().parent().parent().find('input').val(value_input);
	$(element).parent().parent().hide();
	

	$(element).parent().parent().parent().find('p').html($(element).html());
}

function validAndHideIndem(value_input, element) {
	$(element).parent().parent().parent().parent().find('input').val(value_input);
	$(element).parent().parent().hide();
	
	if (value_input == 'NO') {
		$('#minimum').hide();
		$('#territoire').hide();
	} else {
		$('#minimum').show();
		$('#territoire').show();
	}
	
	$(element).parent().parent().parent().find('p').html($(element).html());
}

//menu principal déroulant
function get_elt(id) {
		  var itm = null;
		  if (document.getElementById) {
			itm = document.getElementById(id);
		  } else if (document.all){
			itm = document.all[id];
		  } else if (document.layers){
			itm = document.layers[id];
		  }
		return itm
	}

jQuery(function($){
	$.datepicker.regional['fr'] = {
		closeText: 'Fermer',
		prevText: '&#x3c;Pr&eacute;c',
		nextText: 'Suiv&#x3e;',
		currentText: 'Courant',
		monthNames: ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin',
		'Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','D&eacute;cembre'],
		monthNamesShort: ['Jan','F&eacute;v','Mar','Avr','Mai','Jun',
		'Jul','Ao&ucirc;','Sep','Oct','Nov','D&eacute;c'],
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dateFormat: 'dd/mm/yy', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
});

//affichage de la selection a droite
$(function(){ 
    $("#onglets .onglet").hide(); 
    $("#onglets .onglet:first").addClass("actif"); 
    $("#onglets ul a").click(function(){ 
        $("#onglets ul a").parent("li").removeClass("actif"); 
        $("#onglets .onglet").hide(); 
        $(this.hash).show(); 
        $(this).blur().parent("li").addClass("actif"); 
        return false; 
    });
	
	$('.page_cat_saisie-list_items-table .btn_check').css('opacity', .3).find('a').attr('rel', $('.page_cat_saisie-list_items-table .btn_check a').attr('href')).attr('href', '#1');
	
	$('#inscr_accept').click(function(e) {
		if ($(this).is(':checked')) {
			$('.page_cat_saisie-list_items-table .btn_check').css('opacity', 1).find('a').attr('href', $('.page_cat_saisie-list_items-table .btn_check a').attr('rel'));
		} else {
			$('.page_cat_saisie-list_items-table .btn_check').css('opacity', .3).find('a').attr('rel', $('.page_cat_saisie-list_items-table .btn_check a').attr('href')).attr('href', '#1');
		}
	});
	
	$('#page_cat_defmandat #submit').css('opacity', .3).attr('disabled', 'disabled');
	$('#cg1 #inscr_accept').click(checkFormMandat);
	$('#cg2 #inscr_accept2').click(checkFormMandat);
	$('#page_cat_defmandat .checkbox input').click(checkFormMandat);
	
	$('#page_compte_creation #panier_submit').click(function(e) {
		$('#create_form').submit();
	
		return false;
	});
}); 

function checkFormMandat() {
	var safe = false;

	$('#page_cat_defmandat .checkbox input').each(function() {
		if ($(this).is(':checked')) {
			safe = true;
		}
	});

	if (($('#cg1 #inscr_accept').is(':checked') || $('#cg2 #inscr_accept2').is(':checked')) && safe) {
		$('#page_cat_defmandat #submit').css('opacity', 1).removeAttr('disabled');
	} else {
		$('#page_cat_defmandat #submit').css('opacity', .3).attr('disabled', 'disabled');
	}
}

(function($) {

	$.prompt = {
		
		load: function(text_title, text_content, settings, callback) {
			var options =  { 
				text_confirm: 'Oui',
				text_not_confirm: 'Non'
			}; 
			$.extend(options, settings);

			var bloc_prompt = $('<div id="prompt"><h1 class="titre"></h1><p></p><div class="confirm"></div></div>').hide();
			
			bloc_prompt.find('h1').html(text_title);
			bloc_prompt.find('p').html(text_content);
			bloc_prompt.find('.confirm').html('<button class="button-confirm">' + options.text_confirm + '</button><button class="button-not_confirm">' + options.text_not_confirm + '</button>');
			
			var obj_overlay = bloc_prompt.overlay({
				api: true,
				top: '30%',
				closeOnClick: false,
				onBeforeLoad: function() {
					$('body').prepend(bloc_prompt);
				},
				onClose: function() {
					bloc_prompt.remove();
				},
				expose: { 
					color: '#333',
					loadSpeed: 'fast',
					opacity: 0.9,
					zIndex: 20000
				}
			});
			
			obj_overlay.load();
			
			bloc_prompt.find('.button-confirm').focus();
			
			bloc_prompt.find('button').click(function() {
				obj_overlay.close();
				
				if ($(this).hasClass('button-confirm')) {
					callback();
				}
			});
		}
		
	}

})(jQuery);

function debugCss() {
	var ua = navigator.userAgent.toLowerCase();
	
	if ($.browser.msie || (/firefox/.test(ua) && $.browser.version < '1.9.2')) {
		$('#search_inputdiv input').css({
			height: '30px',
			paddingLeft: '20px',
			paddingTop: '7px'
		});
		
		$('#form_moozar input[type=text]').css({
			height: '32px',
			padding: '5px 0 0 0'
		});
	}
	
	if (/firefox/.test(ua) && $.browser.version < '1.9.2') {
		$('#form_moozar input[type=text]').css({
			padding: '7px 0 0 0'
		});
	}
	
	if ($.browser.msie) {
		$('#page_compte_creation #form_moozar #compte_cadre5 input').css({
			height: '15px'
		});
		
		$('#page_cat_saisie .page_cat_saisie-list_items-table').css({
			marginTop: '90px'
		});
	}
}