// JavaScript Document

/* document Ready */
$( function () {
	addEvent(window, "load", tmt_validatorInit);
	doOnLoad($("body"));
});

function doOnLoad(context){

	$('.errorMessage', context).hide();
	
	$('.sortableListWithPagination', context).sortableListWithPagination();
	
	$(".submit", context).click(function(){
		$('#errorMessage').html('');									 
		$(this).parents("form").children('.errorMessage').hide();;
		if($(this).parents("form")[0].onsubmit()){
			$(this).parents("form")[0].submit();
		}
	});
	
}

//Affichage des erreurs, fonction appellée par TMTValidator
function displayError(frm){
	$('#errorMessage').html('Certaines informations sont incomplètes ou invalides :<br>');
	$('#errorMessage').show();
	$(frm).children('.errorMessage').show();
}




var popUpWin=0;

function popUpWindow(URLStr, width, height) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
		
		w_left = (screen.width - width)/2;
		w_top = (screen.height - height)/2;
		
  	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+w_left+', top='+w_top+',screenX='+w_left+',screenY='+w_top+'');
}
//Différence de 2 dates
function diffDate(dateDeb,dateFin,sep)
{
	// Attention, en javascript les mois commencent é zéro
	var nbj=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	
	datedeb = dateDeb.split(sep);
	datefin = dateFin.split(sep);
		
	
	var datedeb=new Date(datedeb[2],datedeb[1],datedeb[0],00,00,00); // Année, Mois, Jour, Heure, Minutes, Secondes
	var datefin=new Date(datefin[2],datefin[1],datefin[0],00,00,00); // Vous pouvez prendre la date du jour : var datefin=new Date();
	aad=datedeb.getYear();mmd=datedeb.getMonth()+1;jjd=datedeb.getDate();hhd=datedeb.getHours();mnd=datedeb.getMinutes();ssd=datedeb.getSeconds();
	aaf=datefin.getYear();mmf=datefin.getMonth()+1;jjf=datefin.getDate();hhf=datefin.getHours();mnf=datefin.getMinutes();ssf=datefin.getSeconds();
	if(aaf<1900){aaf=aaf+1900;}
	if(aad<1900){aad=aad+1900;}
	if(aaf%4==0){nbj[2]=29;}
	if((aaf%100==0)&&(aaf%400!=0)){nbj[2]=28;}
	if(ssf<ssd){ssf=ssf+60;mnf=mnf-1;}
	if(mnf<mnd){mnf=mnf+60;hhf=hhf-1;}
	if(hhf<hhd){hhf=hhf+24;jjf=jjf-1;}
	if(jjf<jjd){jjf=jjf+nbj[mmf];mmf=mmf-1;}
	if(mmf<mmd){mmf=mmf+12;aaf=aaf-1;}
	//Diff en année,mois,jours,min,sec
	//mes=(aaf-aad)+" ans "+(mmf-mmd)+" mois "+(jjf-jjd)+" jours "+(hhf-hhd)+" heures "+(mnf-mnd)+" minutes "+(ssf-ssd)+" secondes";
	return (aaf-aad);
}
