// JavaScript Document

/* PARAMETRES SLIDER HOMEPAGE 
************************************* */
var indice_offre_courante=1;
var timeout_offres;
var duree_timeout_offres = 6000;
var anim_offre_in_progress = false;
/* ********************************** */


$(document).ready(function() {
	
	
	/* SCROLL ET PRIX SUR FICHE PRODUIT
	**************************************** */
	if( document.getElementById('product') != null ){
		$(window).scroll(function(){
			var windowHeight = $(window).height();
			var contentRightHeight = $('#ps_content_right').height();
			var footerHeight = $('#ps_footer').height();
			var maxMarginTop = windowHeight - contentRightHeight + footerHeight;
			var MarginTop = parseInt( getScrollHeight() - 253 )
			if( getScrollHeight() > 253  && MarginTop < maxMarginTop){
				$('#ps_content_right').css('margin-top', MarginTop );
			}else if(getScrollHeight() > 253){
				$('#ps_content_right').css('margin-top', maxMarginTop );
			}else{
				$('#ps_content_right').css('margin-top', 0 );
			}
		});
	}
	/* ************************************ */
	
	
	
	/* SLIDER CONNECTION 
	************************************ */
	var PsConnectMarginTop = $('#ps_connect').css('marginTop');
	$('.btn_connect').click(function(){	
		if( $('#ps_connect').css('marginTop') == '0px' ){
			$('#ps_connect').stop().animate({ marginTop:PsConnectMarginTop }, 300);
			$('#btn_connect_open').fadeIn(600);
			$('#btn_connect_close').fadeOut(350);
			if(_test_page == 'logon') {
				$('#ps_connect_compte_compte_logon').fadeOut(450);	
			}
			/*$('#btn_connect_open').css('display', 'block');
			$('#btn_connect_close').css('display', 'none');*/
		}else{
			if(_test_page == 'logon') {
				$('#ps_connect_compte_compte_logon').fadeIn(1000);	
			}
			$('#ps_connect').stop().animate({ marginTop:"0px" }, 300);
			$('#btn_connect_close').fadeIn(600);
			$('#btn_connect_open').css('display', 'none');				
		}
	});
	/* ********************************* */
	
	
	/* CAROUSEL INDEX
	************************************* */
	$('#carousel-news').jcarousel({
        auto: 2,
				scroll : 1,
        wrap: 'last',
				animation: 'slow',
        initCallback: mycarousel_initCallback
    });
	
	$('#carousel-plans').jcarousel({
        auto: 2,
				scroll : 1,
        wrap: 'last',
				animation: 'slow',
				easing: 'easeOutExpo',
        initCallback: mycarousel_initCallback
    });
	/* ********************************* */
	
	/* CAROUSEL PRODUCT
	************************************* */
	$('#carousel-accessoires').jcarousel({
        auto: 2,
				scroll : 1,
        wrap: 'last',
				animation: 'slow',
				easing: 'easeOutExpo',
        initCallback: mycarousel_initCallback
    });
	
	$('#carousel-gamme').jcarousel({
        auto: 2,
				scroll : 1,
        wrap: 'last',
				animation: 'slow',
				easing: 'easeOutExpo',
        initCallback: mycarousel_initCallback
    });
	
	
	/* SLIDER HOMEPAGE
	********************************** */
	var next_offre = indice_offre_courante+1;
	if($("#image_slider_"+next_offre).length==0) {
		next_offre = 1;
	}
	timeout_offres = window.setTimeout("ChangeOffres("+next_offre+");",duree_timeout_offres);
	
	/* ******************************** */
	
	
	/* SLIDERSHOW VERTICAL PRODUCT
	********************************** */	
	
	
	function slideToggle(el, bShow){
		var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
		
		// if the bShow isn't present, get the current visibility and reverse it
		if( arguments.length == 1 ) bShow = !visible;
		
		// if the current visiblilty is the same as the requested state, cancel
		if( bShow == visible ) return false;
		
		// get the original height
		if( !height ){
			// get original height
			$el.height('auto');
			height = $el.show().height();
			// update the height
			//$el.data("originalHeight", height);
			// if the element was hidden, hide it again
			if( !visible ) $el.hide().css({height: 0});
		}
		
		// expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
		if( bShow ){
			$el.show().animate({height: height}, {duration: 250});
		} else {
			$el.animate({height: 0}, {duration: 250, complete:function (){
					$el.hide();
				}
			});
		}
	}
	
	$('.title_slideshow_vertical').click(function(){																			
		for(i=0; i<$('.title_slideshow_vertical').length; i++){
			IdTitleSlideshow = $('.title_slideshow_vertical')[i].id;
			if( $(this).attr('id') == IdTitleSlideshow && $('#'+IdTitleSlideshow).next('.content_slideshow_vertical').css('display') == 'none' ){	
 				$('#'+IdTitleSlideshow).removeClass('title_slideshow_vertical_inactif');
				$('#'+IdTitleSlideshow).addClass('title_slideshow_vertical_actif');
				//$('#'+IdTitleSlideshow).next('.content_slideshow_vertical').slideDown(500);
				slideToggle($('#'+IdTitleSlideshow).next('.content_slideshow_vertical'),true);
			}else{
				$('#'+IdTitleSlideshow).removeClass('title_slideshow_vertical_actif');
				$('#'+IdTitleSlideshow).addClass('title_slideshow_vertical_inactif');
				//$('#'+IdTitleSlideshow).next('.content_slideshow_vertical').slideUp(500);
				slideToggle($('#'+IdTitleSlideshow).next('.content_slideshow_vertical'),false);
			}
		}	
	});
	
	/* ******************************** */
	
	
	/* RADIO BUTTON
	************************************* */
	$('.choix_type_verre > div > .bg_btn_input_radio').click(function(){ InputRadioTypeVerre(this) });
	$('.choix_type_verre > div > label').click(function(){ InputRadioTypeVerre( $(this).parent().children(".bg_btn_input_radio") ) });
	$('.choix_verre > div > div > .bg_btn_input_radio').click(function(){ InputRadioVerre(this) });
	$('.choix_verre > div > div > label').click(function(){ InputRadioVerre( $(this).parent().children(".bg_btn_input_radio") ) });
	$('.choix_materiau > div > .bg_btn_input_radio').click(function(){ InputRadioMateriau(this) });
	$('.choix_materiau > div > label').click(function(){ InputRadioMateriau( $(this).parent().children(".bg_btn_input_radio") ) });
	$('.choix_protection_solaire > div > .bg_btn_input_radio').click(function(){ InputRadioProtectionSolaire(this) });
	$('.choix_protection_solaire > div > label').click(function(){ InputRadioProtectionSolaire( $(this).parent().children(".bg_btn_input_radio") ) });
	$('.choix_services > div > .bg_btn_input_radio').click(function(){ InputRadioServices(this) });
	$('.choix_services > div > label').click(function(){ InputRadioServices( $(this).parent().children(".bg_btn_input_radio") ) });
	$('.choix_porteur > div > .bg_btn_input_radio').click(function(){ InputRadioPorteur(this) });
	$('.choix_porteur > div > label').click(function(){ InputRadioPorteur( $(this).parent().children(".bg_btn_input_radio") ) });
	
	/* ********************************** */
		
	
	/* MENU
	**************************************** */
	$("#ps_navigation > li").hover( function() {
		$('.sous_menu', this).data('hover', true).slideDown('fast');
	}, function() {
		$('.sous_menu', this).data('hover', false).animate( { opacity: 1 }, 'fast', function() {
			if(!$(this).data('hover')) {
				$(this).slideUp('fast');
			}
		});
	});
	
	
	/* ************************************ */
	
	
	/* LISTING PRODUIT
	**************************************** */
	/*help*/
	$("#leftColumn .help").parent().hover( function() {
		var _content = $(this).children('.help').attr('rel');
		$(this).children('.help').append("<div id='tooltipCat'><img src='"+_content+"' /></div>");
	}, function() {
		$('#tooltipCat').remove();
	});
	
	/*checkbox de gauche*/
	$('.check').click( function() {
		var el_check;
		if($(this).attr('class') == 'option check') {
			$(this).attr('class', 'optionSelect check');
			var el_check = true;
			var _content = $(this).find('span').html();
			// $('#searchBar .left').append('<div id="titreOption_1"><div class="sep"></div><div class="optionChecked"><div class="close"></div>'+_content+'</div></div>');
		}else{
			$(this).attr('class', 'option check');
			var el_check = false;
			// $('#titreOption_1').remove();		
		}
		$(this).find('input').attr('checked', el_check);
	});
	
	/*slide toggle*/
	$('.search .top').click( function () {
		if($(this).next('.bottom').css('display') == 'none') {
			$(this).next('.bottom').slideDown(450);
			$(this).css('background-position', 'top');	
		}else{
			$(this).next('.bottom').slideUp(600);
			$(this).css('background-position', 'bottom');
		}
	});
	/* ************************************ */
	
	
	/* SCROLLTO PRODUCT
	**************************************** */
	$('#choix_options').click(function(){
		$.scrollTo('#attributes', 500);
	});
	$('#add_to_cart_hidden').click(function(){
		$.scrollTo('#attributes', 500);
	});
	/* ************************************ */
	
	
	/* TOOLTIP ATTRIBUTE
	************************************** */
	$(".details_attribute").hover( function(){
		var tooltipAttributeTop =  $(this).get(0).offsetTop - $(this).parent().parent().children('.tooltipAttribute').height();
		var tooltipAttributeLeft = $(this).get(0).offsetLeft -( $(this).parent().parent().children('.tooltipAttribute').width() / 2 ) + ( $(this).width() / 2 );
		$(this).parent().parent().children('.tooltipAttribute').css('top', tooltipAttributeTop+'px' );
		$(this).parent().parent().children('.tooltipAttribute').css('left', tooltipAttributeLeft+'px' );
		$(this).parent().parent().children('.tooltipAttribute').show();
	}, function() {
		$(this).parent().parent().children('.tooltipAttribute').hide();
	});	
	/* *********************************** */
	
	
	$('.btn_add_cart > .content_slideshow_vertical_content > .add_cart').unbind('click').click(function(){
		$('body#product p#add_to_cart input').click();
	});
	
	$('.btn_essai_domicile').unbind('click').click(function(){
		$('#idCombination').val( combinationEssaiDomicile );
		$('#idEssaiDomicile').val(1);
		$('body#product p#add_to_cart input').click();
	});
	
	$('.btn_essai_domicile').hover(function(){
		var tooltipAttributeTop =  $(this).get(0).offsetTop - $(this).parent().children('.tooltipEssaiDomicile').height();
		var tooltipAttributeLeft = $(this).get(0).offsetLeft -( $(this).parent().children('.tooltipEssaiDomicile').width() / 2 ) + ( $(this).width() / 2 );
		$(this).parent().children('.tooltipEssaiDomicile').css('top', tooltipAttributeTop+'px' );
		$(this).parent().children('.tooltipEssaiDomicile').css('left', tooltipAttributeLeft+'px' );
		$(this).parent().children('.tooltipEssaiDomicile').show();
	}, function(){
		$(this).parent().children('.tooltipEssaiDomicile').hide();
	});
	
});
 /* ****************************************************** FIN READY ************************************************************** */

/* FONCTIONS SLIDING LABELS 
**************************************** */
function LabelRight(ID){
	var input = $(ID).children('div').children('div').children('input');
	var label = $(ID).children('label');
	if( label.css('marginRight') != "0px" && $(input).val()==''){
		label.stop().animate({ marginRight:"0px" }, 300);
	}else if( $(input).val() == '' ){
		var WidthLabel = label.width() + 20;
		label.stop().animate({ marginRight:"-"+WidthLabel+"px" }, 300);
	}else if( $(input).val() != '' ){
		label.stop().animate({ marginRight:"0px" }, 300);
	}
}
function LabelLeft(ID){
	var input = $(ID).children('div').children('div').children('input');
	var label = $(ID).children('label');
	if( label.css('marginLeft') != "0px" && $(input).val()==''){
		label.stop().animate({ marginLeft:"0px" }, 300);
	}else if( $(input).val()=='' ){
		var WidthLabel = label.width() + 20;
		label.stop().animate({ marginLeft:"-"+WidthLabel+"px" }, 300);
	}else if( $(input).val()!='' ){
		label.stop().animate({ marginLeft:"0px" }, 300);
	}
}

/* ************************************** */


/* FONCTIONS CAROUSEL 
**************************************** */
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
/* ************************************** */



/* SLIDER OFFRES
**************************************** */

function ChangeOffres(num_new_offre){
	if(!anim_offre_in_progress) {
		anim_offre_in_progress = true;
		// on retire l'execution du timeout
		if(typeof(timeout_offres)!="undefined") { 
			window.clearTimeout(timeout_offres);
		}
		
		var next_offre = num_new_offre+1;
		if($("#image_slider_"+next_offre).length==0) {
			next_offre = 1;
		}
		$("#image_slider_"+indice_offre_courante).fadeOut(500,function(){
															$("#btn_slider_"+indice_offre_courante).removeClass('btn_slider_actif');
															$("#btn_slider_"+indice_offre_courante).addClass('btn_slider');
															$("#btn_slider_"+num_new_offre).removeClass('btn_slider');
															$("#btn_slider_"+num_new_offre).addClass('btn_slider_actif');
															$("#link_slider_"+indice_offre_courante).css('display', 'none');
															$("#link_slider_"+num_new_offre).css('display', 'block');
															$("#image_slider_"+num_new_offre).fadeIn(500,function(){
																										indice_offre_courante=num_new_offre;
																										anim_offre_in_progress=false;})});
		
		timeout_offres = window.setTimeout("ChangeOffres("+next_offre+");",duree_timeout_offres);
	}

};
/* ************************************** */


/* RADIO BUTTON
****************************************** */
	/* TYPE DE VERRES --------------- */
	function InputRadioTypeVerre(id){		
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".choix_type_verre > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
			$(id).children(".btn_input_radio").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			
			$('#option_choix_verre').html('&nbsp;');
			$('#option_choix_materiau').html('&nbsp;');
			$('#option_choix_protection_solaire').html('&nbsp;');
			$(".content_slideshow_vertical_inactif .bg_btn_input_radio .btn_input_radio").fadeOut(500);
			$(".button_radio_null").attr('checked',true);
			$(id).children("input[type='radio']").attr('checked',true);

			findCombination();
			GetResumeCommande();
			$('#option_choix_type_verre').html( $(id).next('label').html() );
			$('#option_choix_type_verre img').remove();
			$('#title_slideshow_vertical_2').click();
		}
	}
	/* ------------------------------ */
	
	/* DETAILS DE VERRES --------------- */
	function InputRadioVerre(id){
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".choix_verre > div > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
			$(id).children(".btn_input_radio").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			
			$('.choix_materiau').parent().children(".button_radio_null").attr('checked',true);
			$('.choix_protection_solaire').parent().children(".button_radio_null").attr('checked',true);
			$('.choix_materiau .btn_input_radio').fadeOut(500);
			$('.choix_protection_solaire .btn_input_radio').fadeOut(500);
			$('.choix_protection_solaire select').hide();
			$('#option_choix_materiau').html('&nbsp;');
			$('#option_choix_protection_solaire').html('&nbsp;');
			
			findCombination();
			GetResumeCommande();
			$('#title_slideshow_vertical_3').click();		
			$('#option_choix_verre').html( $(id).next('label').html() );
			$('#option_choix_verre img').remove();
		}
	}
	/* ------------------------------ */
	
	/* TYPE DE MATERIAU  ------------ */
	function InputRadioMateriau(id){
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".choix_materiau > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
			$(id).children(".btn_input_radio").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			
			$('.choix_protection_solaire').parent().children('.button_radio_null').attr('checked',true);
			$('.choix_protection_solaire .btn_input_radio').fadeOut(500);
			$('.choix_protection_solaire select').hide();
			$('#option_choix_protection_solaire').html('&nbsp;');
			
			$(".container_input_radio > .bg_btn_input_radio > input[name='group_"+attribute_group_protection+"']").each(function(){
				if( $(this).val() == attribute_protection_clair ){
					$(this).attr('checked',true);
					$(this).parent().children(".btn_input_radio").fadeIn(500);
				}										
			});
			
			findCombination();
			GetResumeCommande();
			$('#title_slideshow_vertical_4').click();
			$('#option_choix_materiau').html( $(id).next('label').html() );
			$('#option_choix_materiau img').remove();
		}
	}	
	/* ------------------------------ */
	
	/* TYPE DE PROTECTION SOLAIRE -------*/
	function InputRadioProtectionSolaire(id){
		if( $(id).children("input[type='radio']").attr('checked') != true ){
			$(".choix_protection_solaire > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
			$(id).children(".btn_input_radio").fadeIn(500);
			$(id).children("input[type='radio']").attr('checked',true);
			$(".choix_protection_solaire select").hide();
			$(id).parent().children('select').show();
			if( $(id).parent().children('select').length > 0) AddCustomizationSolaire( $(id).parent().children('select').val() );
			else AddCustomizationSolaire('_');
			findCombination();
			GetResumeCommande();
			$('#option_choix_protection_solaire').html( $(id).next('label').html() );
			$('#option_choix_protection_solaire img').remove();
		}
	}	
	/* -------------------------------- */
	
	/* TYPE DE SERVICES -------*/
	/* function InputRadioServices(id){
		$(".choix_services > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
		$(id).children(".btn_input_radio").fadeIn(500);
		$(id).children("input[type='radio']").attr('checked',true);
		findCombination();
		GetResumeCommande();
	}	*/
	/* -------------------------------- */

	/* CHOIX DU PORTEUR -------*/
	/* function InputRadioPorteur(id){
		$(".choix_porteur > div > .bg_btn_input_radio > .btn_input_radio").fadeOut(500);
		$(id).children(".btn_input_radio").fadeIn(500);
		$(id).children("input[type='radio']").attr('checked',true);
		findPorteur();
		GetResumeCommande();
	}	*/
	/* -------------------------------- */
	
	

/* ************************************** */



/* GET SCROLL POSITION
****************************************** */
	/* WIDTH SCROLL -------*/
	function getScrollWidth(){
		 var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
		 return w ? w : 0;
	}
	/* -------------------------------- */

	/* HEIGHT SCROLL -------*/
	function getScrollHeight(){
		 var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
		 return h ? h : 0;
	}
	/* -------------------------------- */
/* ************************************** */




/* TEST AJOUT AU PANIER
****************************************** */
/* function AddProductCart(porteur){
	if(porteur == true){
		if($('#idPorteur').val() == '' || parseInt($('#idPorteur').val()) <1 ){
			if($('#title_slideshow_vertical_4').next('.content_slideshow_vertical').css('display') == 'none'){
				for(i=0; i<$('.title_slideshow_vertical').length; i++){
					IdTitleSlideshow = $('.title_slideshow_vertical')[i].id;
					if( $('#title_slideshow_vertical_4').attr('id') == IdTitleSlideshow){	
						$('#'+IdTitleSlideshow).removeClass('title_slideshow_vertical_inactif');
						$('#'+IdTitleSlideshow).addClass('title_slideshow_vertical_actif');
						$('#'+IdTitleSlideshow).next('.content_slideshow_vertical').slideDown(200);
					}else{
						$('#'+IdTitleSlideshow).removeClass('title_slideshow_vertical_actif');
						$('#'+IdTitleSlideshow).addClass('title_slideshow_vertical_inactif');
						$('#'+IdTitleSlideshow).next('.content_slideshow_vertical').slideUp(200);
					}
				}	
			}
			$.scrollTo('#attributes', 200);
			return false;
		}else{
			return true;
		}
	}else{
		return true;
	}
} */
/* ************************************** */





/* TEST VALIDATION SHOPPING CART
****************************************** */
function SubmitShoppingCart(){	
	var submitForm = true;
	var nbSelect = $('select').length;
	var SelectPosition = 0;
	
	if(submitForm && $('#noConnect').length > 0){
		submitForm = false;
		alert(errorCreateCompte);	
	}
	if(submitForm && $('#aucunPorteur').length > 0){
		submitForm = false;
		alert(errorCreatePorteur);	
	}
	var idCart = $('#id_cart').val();
	$('select').each(function(){
		if(submitForm && $(this).val() == -1 ){
			submitForm = false;
			alert(errorAddPorteur);			
		}
	});
	
	if(submitForm != false){
		$('select').each(function(){
			var idPorteur = $(this).val();
			var selectName = $(this).attr('name');
			var iteration = parseInt( selectName.replace('porteur_product_', '') );
			var idProductAttribute = $('#idProductAttribute_'+iteration).val();
			var oldidPorteur = $('#oldidPorteur_'+iteration).val();
			var idProduct = $('#idProduct_'+iteration).val();
			var dateAdd = $('#dateAdd_'+iteration).val();
			//alert('idPorteur -> ' + idPorteur + '\n idProductAttribute -> ' + idProductAttribute + '\n oldidPorteur -> ' + oldidPorteur + '\n idProduct -> ' + idProduct );
			$.ajax({
			 type: 'POST',
			 url: baseDir + 'add_porteur_cart.php',
			 async: true,
			 cache: false,
			 data: 'idPorteur='+idPorteur+'&idCart='+idCart+'&idProductAttribute='+idProductAttribute+'&idProduct='+idProduct+'&oldidPorteur='+oldidPorteur+'&dateAdd='+dateAdd,
			 dataType : 'json',
			 success: function(response){
				 SelectPosition++;
				 if(response['addPorteurCart'] != 'ok'){
					submitForm = false;
				 }else{
				 		$('#oldidPorteur_'+iteration).val( idPorteur ); 
				 }
				 if(SelectPosition == nbSelect) $('#shoppingCartForm').submit() ;
			 },
			 error: function(XMLHttpRequest, textStatus, errorThrown) {
				 submitForm = false;
				 alert("TECHNICAL ERROR: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
			 }
			});
		});
	}	
}
/* ************************************** */


var CustomValueActuel = '';
function AddCustomizationSolaire(CustomValue){
	if(CustomValueActuel != CustomValue){
		CustomValueActuel = CustomValue;
		$('#customizationForm > .customization_block_input').val(CustomValue);
		saveCustomization();
	}
	GetResumeCommande();
}


function controle_date_porteur()
{
	var anneeNaissance = $('#anneeNaissance').val();
	var anneeOrdonnance = $('#anneeOrdonnance').val();
	var moisOrdonnance = $('#moisOrdonnance').val();
	var jourOrdonnance = $('#jourOrdonnance').val();
	
	if(anneeNaissance == 'AAAA' || anneeOrdonnance == 'AAAA' || isNaN(anneeNaissance) || isNaN(anneeOrdonnance)){
		return true;
	}
	var date = new Date()
	var anneEnCours = date.getFullYear();
	var moisEnCours = date.getMonth();
	var jourEnCours = date.getDate();
	
	var ecart = anneEnCours-anneeOrdonnance;
	
	var age = anneEnCours-anneeNaissance;
	//alert([parseInt(anneEnCours), parseInt(moisEnCours), parseInt(jourEnCours)]+" ,  "+[parseInt(anneeOrdonnance), parseInt(moisOrdonnance), parseInt(jourOrdonnance)])
	var nbreJour  = nb_jour([(jourOrdonnance), (moisOrdonnance), (anneeOrdonnance)],[jourEnCours, (moisEnCours), (anneEnCours)] );
	
	
	//alert(Math.round(strtotime(anneeOrdonnance+'-'+moisOrdonnance+'-'+jourOrdonnance) - strtotime(anneEnCours+'-'+moisEnCours+'-'+jourEnCours))/(60*60*24)-1);
	
	if(age > 16){
		if(nbreJour <= 365*3){
			return true;
		}
		else{
			alert('Le porteur a plus de 16 ans, votre ordonnance doit être datée de moins de 3 ans.');
			return false;
			
		}
	} else {
		if(nbreJour <= 365){
			return true;
		}else{
			alert('Le porteur a moins de 16 ans, votre ordonnance doit être datée de moins de 1 ans.');
			return false;
		}
	}
}

function bissextile(annee) {
if (annee%4==0 && annee %100!=0 || annee%400==0) return true; else return false
}

function nb_01_01(date){
nb_mois=new Array(13);
nb_mois=[,0,31,59,90,120,151,181,212,243,273,304,334];
j=eval(date[0]) ; m=eval(date[1]) ; a=eval(date[2]);
nb=nb_mois[m]+j-1 ;
if (bissextile(a) && m>2) nb++;
return nb;
}

function nb_jour_annee(a1,a2){
n=0;
if (a1==a2) n=0 ; else
for (i=a1; i<a2; i++) {n += 365; if (bissextile(i)) n++}
return n;
}

function nb_jour(date1,date2){
	a1=date1[2] ; a2=date2[2] ;

	nb=nb_jour_annee(date1[2],date2[2]) - nb_01_01(date1) + nb_01_01(date2);
		
	return nb;
}

