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);
	});
	
	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();
			
			var value_right = '0px';
			var bloc_move = $('.bloc_gauche_img .bloc_gauche_txt');
		
			bloc_move.css('position', 'absolute');
		
			if ($.browser.msie && ($.browser.version < 8)) {
				value_right = '-30px';
				
				if ($('.bloc_gauche_img:eq(' + i + ') .bloc_gauche_txt').hasClass('has_move')) {
					value_right = '0px';
				}
			}
			
			bloc_move.removeClass('has_move');
		  
			
			bloc_move.animate({
				right: value_right
			}, function() {
				bloc_move.addClass('has_move');
			});
		});
		
		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');
		}
	});
});


// New cart init
$(function()
{
    if (!$('div.cart-item').length) return;

    $('div.cart-item').each(function() {
	var $$ = $(this);
	var bloc_select = $$.find('div.benef-select');
	var contrat_id = $$.find('input.work-id').val();
	var this_content = $$.find('div.beneficiary strong:first-child');
	var content = $$.find('div.beneficiary strong:first-child').text();
	
	// Sets (CSS) current used beneficiary
	bloc_select.find('li').each(function() {
	    var v = $(this).find('input.beneficiary-id').val();
	    if (content == v)
		$(this).addClass('current');
	});
	this_content.html(bloc_select.find('li.current strong').html());

	// Prevents selection of -/+ buttons
	$$.find('a.fan-btn').mousedown(function () {return false;});

	/* DEPRECATED
	// Displays indemn value
	var input_indemn_val = $$.find('input.indemn').val();
	$$.parent().find('.tabletd2 span').text(input_indemn_val);
	*/
	
	/* DEPRECATED: done in CSS
	// Positions beneficiary select bloc
	bloc_select.css({
	    marginTop: -bloc_select.height() - 15,
	    marginLeft: bloc_select.width() - 70
	});
	*/
	if (bloc_select.find('ul li').length > 1)
	{
	    // On/Off animation (same object)
	    $$.find('div.beneficiary p').hover(function() {
		bloc_select.fadeIn('fast');
	    });
	    $$.find('div.benef-select').mouseleave(function() {
		bloc_select.fadeOut('fast');
	    });
	}
	else
	    $$.find('div.beneficiary p').click(function() {
		var li = $(this).parent().find('div.benef-select ul li:first-child a:first-child').trigger('click');
	    });

	// Activates selection :
	bloc_select.find('ul li strong').click(function() {
	    var benef = $(this).html();
	    var li = $(this).parent();
	    // Updates compensation value
	    var input_indemn_val = li.find('input.indemn').val();
	    li.siblings().removeClass('current');
	    li.addClass('current');
	    li.closest('div.beneficiary').find('strong:nth-child(2)').text(input_indemn_val);
	    // Updates beneficiary id (then name with checkStatusCart())
	    var v = li.find('input.beneficiary-id').val();
	    li.closest('div.beneficiary').find('strong:first-child').val(v);

	    checkStatusCart2();
	    $.ajax({type: "POST", url: "panier/update", data: "contrat_id="+contrat_id+"&beneficiary="+v, success: function(data){
		$$.find('div.beneficiary strong:first-child').html(benef);
		bloc_select.fadeOut('fast');
	    }});
	});
    });
    
    // Removes a row
    $('a.cart-del').click(function() {
	var size_cart = $('div.cart-item').length;
	
	if (size_cart >= 1)
	{
	    $(this).closest('div.cart-item').animate({
		opacity: 0
	    }, 'slow', function() {
		$(this).remove();
		checkPriceCart2();
	    });
/* Why remove next ?
	    $(this).parent().parent().next().animate({
		opacity: 0
	    }, 'slow', function() {
		$(this).remove();
	    });
*/
	}
	else
	{
	    $('#page_panier form').fadeOut('slow', function() {
		$(this).remove();
	    });
	}
		
	checkSizeCart2(1);
	
	var id = $(this).parent().parent().find('input.work-id').val();
	$.ajax({type: "POST", url:"panier/delete", data:{id: id}, success: function(){}});
    });
	
    $('div.cart-item input.price').keydown(onlyNumber2);
    $('div.cart-item input.price').blur(checkPriceCart2);
    $('div.cart-item input.price').keyup(checkPriceCart2);
	
    checkSizeCart2();
    checkPriceCart2();
});


$(function() {
    	
    if (!$('.table_panier .tabletd5').length) return;

	$('.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();
});

// Checks users input (donation field)
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;
}
// v2
function onlyNumber2(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)
	chiffre2($(this).parent().find('a'), '+', 0.10);	
    if (e.which == 40)
	chiffre2($(this).parent().find('a'), '-', 0.10)
	
    return safe;
}

/*
** Updates 'rewarded'/'settled' messages
*/
function checkStatusCart2()
{
    $('div.cart-item').each(function() {
	var input_value = $(this).find('input.price').val();
	var necessary_value =  $(this).find('strong.indemn-disp').text();
	
	if (parseFloat(input_value) >= parseFloat(necessary_value))
	{
	    $(this).find('div.settled').show();
	    $(this).find('div.rewarded').hide();
	} 
	else
	{
	    $(this).find('div.settled').hide();
	    $(this).find('div.rewarded').show();
	}
    });
}

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');
		}
	});
}

// v2
function checkSizeCart2(value_count) {
	var value_count = value_count || 0;
	var count_size_cart = $('.count_size_cart');
	var size_cart = $('div.cart-item').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 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;
        var transaction_fees = 0;
        var cart_currency = $('#cart_currency').val();
        var price_cart_value = $('#price_cart_value');
        var transaction_fees_value = $('#transaction_fees');

	if (count_price_cart) {
		$('.table_panier .tabletd3 input').each(function() {
			var value = parseFloat($(this).val());
			
			if ($(this).val() == '') {
				value = 0;
			}
		
			price_cart += value;
		});

                // Frais transaction
                price_cart_temp = price_cart;
                transaction_fees = price_cart * 0.0527;

                // Euro
                if(cart_currency == '1') {
                  transaction_fees += 0.11;
                }
                else {
                  transaction_fees += 0.06;
                }

                price_cart += transaction_fees;


                //
		price_cart = parseFloat(price_cart);		
		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';
			}
		}


                //
                price_cart_temp = parseFloat(price_cart_temp);
		price_cart_temp = Math.round(price_cart_temp * 100) / 100;
		price_cart_temp = price_cart_temp.toString();

		if (price_cart_temp.match('[.]')) {
			var temp = price_cart_temp.split('.');

			if (temp[1].length < 2) {
				price_cart_temp = price_cart_temp + '0';
			}
		}
                
                //              
                transaction_fees = parseFloat(transaction_fees);
		transaction_fees = Math.round(transaction_fees * 100) / 100;
		transaction_fees = transaction_fees.toString();

		if (transaction_fees.match('[.]')) {
			var temp = transaction_fees.split('.');

			if (temp[1].length < 2) {
				transaction_fees = transaction_fees + '0';
			}
		}

                price_cart_value.text(price_cart_temp);
                transaction_fees_value.text(transaction_fees);
		count_price_cart.text(price_cart);
		
		checkStatusCart();
	}
}
/*
** v2
*/
function checkPriceCart2()
{
    var count_price_cart = $('.count_price_cart');
    var price_cart = 0;
    var transaction_fees = 0;
    var cart_currency = $('#cart_currency').val();
    var price_cart_value = $('#price_cart_value');
    var transaction_fees_value = $('#transaction_fees');
    
    if (count_price_cart)
    {
	$('div.cart-item input.price').each(function() {
	    var value = parseFloat($(this).val());
	    
	    if ($(this).val() == '')
		value = 0;
	    price_cart += value;
	});
	
        // Frais transaction
        price_cart_temp = price_cart;
        transaction_fees = price_cart * 0.0527;
	
        // Euro
        if(cart_currency == '1') {
            transaction_fees += 0.11;
        }
        else {
            transaction_fees += 0.06;
        }
	
        price_cart += transaction_fees;
	
        //
	price_cart = parseFloat(price_cart);		
	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';
	    }
	}
	
	
        //
        price_cart_temp = parseFloat(price_cart_temp);
	price_cart_temp = Math.round(price_cart_temp * 100) / 100;
	price_cart_temp = price_cart_temp.toString();
	
	if (price_cart_temp.match('[.]')) {
	    var temp = price_cart_temp.split('.');
	    
	    if (temp[1].length < 2) {
		price_cart_temp = price_cart_temp + '0';
	    }
	}
        
        //              
        transaction_fees = parseFloat(transaction_fees);
	transaction_fees = Math.round(transaction_fees * 100) / 100;
	transaction_fees = transaction_fees.toString();
	
	if (transaction_fees.match('[.]')) {
	    var temp = transaction_fees.split('.');
	    
	    if (temp[1].length < 2) {
		transaction_fees = transaction_fees + '0';
	    }
	}

        price_cart_value.text(price_cart_temp);
        transaction_fees_value.text(transaction_fees);
	count_price_cart.text(price_cart);
	
	checkStatusCart2();
    }
}

/*
** Updates a row donation according to -/+ user's action
*/
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();
}
/*
** Cart v2 update :
*/
function chiffre2(element, montant, ajout)
{
    var element_value = $(element).parent().find('input');
    var current_value = parseFloat(element_value.val()); // see toFixed();
    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);
    
    checkPriceCart2();
}

//Fonctions pour les ayants-droits

//Code pour faire d'un radio une checkbox
function InactiveCheckBox(element, element_current){
	var element = $('#' + element);
	var element_current = $(element_current);
	
	if (element_current.is(':checked')) {
		element_current.val('ok');
		element.val('ko');
	} else {
		element_current.val('ko');
	}
	
	element.removeAttr('checked');
}

//Calendrier pour la saisie
$(function() {
		$('.datepicker').datepicker({
			yearRange: '1920:2100',	
			dateFormat: 'yy-mm-dd',	
			//changeMonth: true,
			changeYear: true
	});
});

$(function() {
		$('#datepicker-over18').datepicker({
			yearRange: '1920:2100',
			dateFormat: 'yy-mm-dd',
			//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
	}

//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) {
if (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() {
	
	$('legend img[title], img.help[title], strong.help[title]').tooltip().dynamic({
		offset: [10, 2],
		bottom: {
			direction: 'down',
			bounce: true
		}
	});
});

$(function() {
	
	debugCss();
	
});

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'
		});
	}
	
	if (/chrome/.test(ua)) {
		$('body.ayantsdroit #search_input').css({
			width: '220px'
		});
		
		$('.tabletd_img1').css({
			fontSize: 0
		});
		
		$('#page_cat_saisie .page_cat_saisie-list_items-table').css({
			marginTop: '83px'
		});
	}
	
	if (/opera/.test(ua)) {
		$('.tabletd_img1').css({
			fontSize: 0
		});
	}
}

function refresh_cpt_cart()
{
	if ((parseInt($('.cart > span').text(), 10)) > 0)
		$('.cart > span').text(parseInt($('.cart > span').text(), 10) - 1);
}

 $(function()
 {
             $("a.delete_link").click(function(){
									alert('TEST !');
                                 return confirm('Would you really delete this title ?');
         })
 })
