var currentCp=null;
var currentCpInduc=null;
var currentCpStreet=null;
var selectedLigne=null;
var minDateAccepted="02/01/2011";
/*
if (typeof minDateAcceptedPhp != undefined && minDateAcceptedPhp != ""){
	minDateAccepted=minDateAcceptedPhp;
}
*/
function isMailValid(chaine){
	
	var pattern=/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9_\.\-]+\.[a-zA-Z0-9_\-]+$/;
	if(!pattern.test(chaine)){
		
		return false;
	}
	
	
	return true;

}
function switchLanguage(langue){
	location.href="changeLanguage.php?langue="+langue;
}
function isZipCodeValid(chaine){
	
	var pattern=/^[0-9]{4}$/;
	if(!pattern.test(chaine)){
		
		return false;
	}
	
	
	return true;

}
function isPhoneNumberValid(chaine){
	
	if(trim(chaine).length < 9)
		return false;
	else
		return true;
	
	
	
	return true;

}
function isGsmNumberValid(chaine){
	
	if(trim(chaine).length < 10)
		return false;
	else
		return true;
	
	
	
	return true;

}
function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}
function openStreetResearch(champ,bypass){
		champ.blur();
		var popupName="streetResearch";
		var cellLeft=((browserWidth()-750)/2)+130;
		document.getElementById(popupName).style.left=cellLeft;
		//alert(document.forms[0].code_postal.value);
		//document.getElementById(popupName).document.forms[0].street_field.value=document.forms[0].code_postal.value;
		
		if(champ.value=="" || bypass==true)
		{
			//controle du code postal
			if(!isZipCodeValid(document.forms[0].postal_code.value)){
				alert(alertWrongZipCode);
				return false;
			}
			//alert(window.streetResearch.src);
			
			afficherPopup(popupName);
			//alert(document.forms[0].code_postal.value);
			window.streetResearch.setZip(document.forms[0].postal_code.value);
			
		//document.getElementById(popupName).setZipCode(document.forms[0].code_postal.value);
		}
		
	}
	function afficherPopup(popupName) {
      document.getElementById(popupName).style.visibility = "visible";
   }
    function masquerPopup(popupName) {
      document.getElementById(popupName).style.visibility = "hidden";
   }
   function surlignerLigne(ligne,mustUnderline){
	
	
	var ligne=ligne.parentNode;
	
	if(selectedLigne==ligne)
		return;
	if(mustUnderline){
		
		ligne.style.cursor = 'hand';
		for(var i=0;i<ligne.childNodes.length;i++){
			ligne.childNodes[i].className="tabSurligne";
		}
		
	}
	else{
		for(var i=0;i<ligne.childNodes.length;i++){
			ligne.childNodes[i].className="tab";
		}
	}
	
	
	
}
function selectLine(ligne){
	//deselectionner l'ancienne ligne
	var ligne=ligne.parentNode;
	if(selectedLigne!=null){
		for(var i=0;i<selectedLigne.childNodes.length;i++){
			selectedLigne.childNodes[i].className="tab";
		}
		
	}
	//on selectionne la nouvelle
	for(var i=0;i<ligne.childNodes.length;i++){
			ligne.childNodes[i].className="tabSelectionne";
		}
	
	selectedLigne=ligne;
	
}
function addStreet(){
	if(window.liste.selectedLigne==null || window.liste.selectedLigne==''){
		alert(parent.alertMustSelectStreet);
		return false;
	}
	var streetName=window.liste.selectedLigne.id;
	//alert(streetName);
	parent.document.forms[0].street.value=streetName;
	parent.masquerPopup("streetResearch");

}
function checkFormInsc(){
	//controle avant validation de l'inscription
	//controle du nom
	//controle de la case a cocher indiquant que le paneliste ne fait pas partie de bepost.
	alert(alertRegistrationClosed);
	return false;
	if(document.forms[0].not_bepost.checked==false){
			alert(alertCannotBelongToPost);
			return false;
	}
	if(trim(document.forms[0].id_parrain.value)!=""){
		//verifier qu'il s'agit d'une valeur numerique
		var pattern=/^[0-9]+$/;
		if(!pattern.test(trim(document.forms[0].id_parrain.value))){
			alert(alertIdParrainMustBeNumeric);
			return false;
		}

	}
	
	var typePart = document.forms[0].type_participation.value;
	var typePart2 = document.forms[0].type_participation_2.value;
	
	if(trim(document.forms[0].last_name.value) ==""){
		alert(alertMustFillLastName);
		return false;
	}
	if(trim(document.forms[0].first_name.value) ==""){
		alert(alertMustFillFirstName);
		return false;
	}
	if(!isValidDate(document.forms[0].birth_date.value)){
		alert(alertFillValidDate);
		return false;
	}
	//controle de la societe (sauf pour le particulier)
	
	
	if(typePart=="company"){
		if(trim(document.forms[0].company_name.value) ==""){
			alert(alertMustFillCompanyName);
			return false;
		}
	}
	if(trim(document.forms[0].street.value) ==""){
		alert(alertMustFillStreet);
		return false;
	}
	if(trim(document.forms[0].street_number.value) ==""){
		alert(alertMustFillStreetNumber);
		return false;
	}
	if(!isZipCodeValid(document.forms[0].postal_code.value)){
			alert(alertWrongZipCode);
			return false;
		}
		
	//test de la commune
	var commune= document.forms[0].locality.selectedIndex;
	if(commune == -1 || commune ==0){
		alert(alertMustFillLocality);
			return false;
	}
	
	if(trim(document.forms[0].phone_number.value) != "" && !isPhoneNumberValid(document.forms[0].phone_number.value)){
			alert(alertMustFillPhoneNumber);
			return false;
		}
	if(trim(document.forms[0].gsm_number.value) != "" && !isGsmNumberValid(document.forms[0].gsm_number.value)){
			alert(alertMustFillGsmNumber);
			return false;
		}
	if(trim(document.forms[0].phone_number.value) == "" && trim(document.forms[0].gsm_number.value) == ""){
			alert(alertMustFillAtLeastOnePhoneNumber);
			return false;
	}
	if(trim(document.forms[0].fax_number.value) != "" && !isPhoneNumberValid(document.forms[0].fax_number.value)){
			alert(alertMustFillFaxNumber);
			return false;
		}
		
	if(!isMailValid(document.forms[0].email.value)){
		alert(alertWrongEmail);
		return false;
	}
	
	if(trim(document.forms[0].account_number_1.value) != "" && !isAccountNumberValid(document.forms[0].account_number_1.value)){
		alert(alertWrongAccountNumber);
		return false;
	}
	
	if(typePart=="company" && typePart2=="sender" ){
		if(trim(document.forms[0].account_number_2.value) != "" && !isAccountNumberValid(document.forms[0].account_number_2.value)){
			alert(alertWrongAccountNumber);
			return false;
		}
	}
	
	if(typePart2=="sender" ){
		if(typePart=="single"){
			if(document.forms[0].induction.selectedIndex ==2){
				alert(alertNoRemovingServiceAllowed);
				return false;
			}
		}
	}
	
	if(typePart2=="sender" ){
		
		if(document.forms[0].induction.selectedIndex ==0){
			//boite aux lettres, donc, il faut indiquer l'adresse de la boite aux lettres
			
			if(document.forms[0].induction_adr_1.selectedIndex <= 0){
				alert(alertMustSelectInductionAddress);
				return false;
				
			}
			//si la personne a indique "autres" dans la liste des boites aux lettres, il faut qu'il ai ecrit kekchose dans le champ de texte
			if(document.forms[0].induction_adr_1.options[document.forms[0].induction_adr_1.options.length-1].selected==true){
				if(trim(document.forms[0].induction_adr_2.value) ==""){
					alert(alertMustSelectInductionAddress);
					return false;
				}
			}
			
			
			
			
			
		}
		
		if(document.forms[0].induction.selectedIndex ==1){
			//guichet => adresse du bureau de poste
			if(trim(document.forms[0].induction_adr_2.value) ==""){
				alert(alertMustSelectInductionAddressPO);
				return false;
			}
			
		}
		
		if(document.forms[0].induction.selectedIndex ==2 && typePart=="company"){
			//enlevement => controler les heures d'enlevement pour les jours disponibles
			//alert("controe des heures d'enlevement");
			
			for(var c = 1;c<=6;c++){
				//alert(document.forms[0]["availability_days_"+c]);
				if(document.forms[0]["availability_days_"+c].checked==true){
					//tester si l'heure d'enlevement est valide
					if(!isTimeValid(document.forms[0]["time_removal_"+c].value)){
						alert(alertMustFillTimeRemoval);
						return false;
					}
				}
			}
			
			
		}
		
		
	}
	
	if(typePart2=="sender" ){
		//verifier qu'il y a au moins 3 items de selectionnés
		if(typePart=="single"){
			var cptDays=0;
			if(document.forms[0].availability_days_1.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_2.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_3.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_4.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_5.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_6.checked==true)
				cptDays++;
			if(cptDays <3){
					alert(alertMustSelectAtLeastOneDayAvailable);
					return false;
			}
			
		}
		if(typePart=="company"){
			var cptDays=0;
			if(document.forms[0].availability_days_1.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_2.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_3.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_4.checked==true)
				cptDays++;
			if(document.forms[0].availability_days_5.checked==true)
				cptDays++;
		
			if(cptDays <2){
					alert(alertMustSelectAtLeastOneDayAvailable);
					return false;
			}
		}
	}
	/*
	if(typePart2=="sender" ){
		
		if(typePart=="company"){
			if(document.forms[0].induction.selectedIndex ==2){
				if(!isTimeValid(document.forms[0].time_removing.value)){
					alert(alertMustFillRemovingTime);
					return false;
				}
			}
		}
	}
	*/

}
function isAccountNumberValid(chaine){
	//alert(trim(chaine));
	var pattern=/^[0-9]{3}-[0-9]{7}-[0-9]{2}$/;
	if(chaine == "000-0000000-00"){
		return false;
	}
	if(!pattern.test(chaine)){
		
		return false;
	}
	//tester le modulo
	
	var cptValue=chaine.substring(0,3)+chaine.substring(4,11);
	var reste=cptValue%97;
	//alert(compte.substring(12,14)+" / "+reste);
	if(chaine.substring(12,14) == "97" && reste ==0 )
		return true;
	if(reste != chaine.substring(12,14)){
		
		return false;
	}
	return true;
	
	
	

}
function isValidDate(chaineDate) {
	
	
//Je regarde tout d'abord si la chaîne n'est pas vide, sinon pas la peine d'aller plus loin
    var pattern=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
    if(!pattern.test(chaineDate)) return false;
          

	var ladate=new Array();
	ladate[0]=chaineDate.substring(0,2);
	ladate[1]=chaineDate.substring(3,5);
	ladate[2]=chaineDate.substring(6,10);	
// Sinon, c'est maintenant que je crée la date correspondante. Attention, les mois sont étalonnés de 0 à 11
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))

// Bug de l'an 2000 oblige, lorsque je récupère l'année, je n'ai pas toujours 4 chiffres selon les navigateurs, je rectifie donc ici le tir.
   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 1900
	 //verifier qu'on est bien en 2007
 	
	
// Il ne reste plus qu'à vérifier si le jour, le mois et l'année obtenus sont les mêmes que ceux saisis par l'utilisateur.
//alert((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])));
   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])));
   
  
   
}
function isTimeValid(chaine){
	var pattern=/^[0-9]{2}:[0-9]{2}$/;
	if(!pattern.test(chaine)){
		
		return false;
	}
	//verifier que le nombre des heures soit compris entre 0 et 24
	var hh =persoParseInt(chaine.substring(0,2));
	var mm =persoParseInt(chaine.substring(3,5));
	
	if(hh < 0 || hh > 23 || mm < 0 || mm > 59){
		return false;
	}
	if(chaine=="00:00"){
		return false;
	}
	return true;
}
function persoParseInt(str){
	var val="";
	for(var i=0;i<str.length;i++){
		if(val != ""  || str.substring(i,i+1) != "0")
			val+=str.substring(i,i+1);
	}
	return parseInt(val);
}
function checkFormLogon(){
	//controle email
	if(!isMailValid(document.forms[0].login.value)){
		alert(alertWrongEmail);
		return false;
	}
	if(trim(document.forms[0].currentPwd.value)==""){
		alert(alertFillPwd);
		return false;
	}

}
function checkClusterForm(checkQuotrax,adrPostalBox){
	//controle de la date
	//alert("controle date");
	if((!isValidDate(document.forms[0].effective_sending_date.value)) || isDateAfterNow(document.forms[0].effective_sending_date.value) || isDate2AfterDate1(document.forms[0].effective_sending_date.value,minDateAccepted)  ){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDate);
		return false;
	}
	
	var theDate = document.forms[0].planned_date.value;
	var ladate=new Array();
	ladate[0]=theDate.substring(0,2);
	ladate[1]=theDate.substring(3,5);
	ladate[2]=theDate.substring(6,10);	

	var theDateFrom = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0])-3);
	var theDateTo = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0])+3);
	
	theDate = document.forms[0].effective_sending_date.value;
	
	ladate=new Array();
	ladate[0]=theDate.substring(0,2);
	ladate[1]=theDate.substring(3,5);
	ladate[2]=theDate.substring(6,10);	

	var theDateWritten = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
	var msgConfirm=confirmSuspiciousSendingDate.replace(/plannedDate/,document.forms[0].planned_date.value);
	
	if(theDateWritten.getTime() < theDateFrom.getTime() || theDateWritten.getTime() > theDateTo.getTime()){
		if(!confirm(msgConfirm))
			return false;
	}
	
	//controle de l'heure
	if(!isTimeValid(document.forms[0].effective_sending_time.value)){
		alert(alertFillValidSendingTime);
		return false;
	}
	if(checkQuotrax){
		if(document.forms[0].scan_quotrax_correct.selectedIndex == 0){
			alert(alertFillQuotraxScanningResult);
			return false;
		}
	}
	if(adrPostalBox !=""){
		if(document.forms[0].postal_box_correct.selectedIndex == 0){
			alert(alertIndicateInductionBoxMail);
			return false;
		}
		if(document.forms[0].postal_box_correct.selectedIndex == 2){
			if(document.forms[0].other_postal_box.value ==""){
				alert(alertFillInductionOtherBoxMail);
				return false;
			}
		}
		
		
	}
	 

}
function checkLetterForm(){
	//si jamais la case "non recue" est checkée, pas la peine d'aller plus loin
	if(document.forms[0].letter_not_received){
		if(document.forms[0].letter_not_received.checked==true){
			return true;
		}
	}
	//controle de la date 
	if(trim(document.forms[0].receiving_date.value) != "" || document.forms[0].present.selectedIndex == 0 ){
		if((!isValidDate(document.forms[0].receiving_date.value)) ||  isDateAfterNow(document.forms[0].receiving_date.value) || isDate2AfterDate1(document.forms[0].receiving_date.value,minDateAccepted)){
			alert(alertFillValidDate);
			document.forms[0].receiving_date.focus();
			document.forms[0].receiving_date.select();
			return false;
		}
	}
	
	
	//verifier que le paneliste a bien indique si l'obliteration etaiyt visible
	if(document.forms[0].visible_stamp.selectedIndex == 0){
		alert(alertSelectVisibleStamp);
		return false;
	}
	if(document.forms[0].visible_stamp.selectedIndex == 1){
		//controle des infos d'obliteration
		if((!isValidDate(document.forms[0].stamping_date.value)) ||  isDateAfterNow(document.forms[0].stamping_date.value) || isDate2AfterDate1(document.forms[0].stamping_date.value,minDateAccepted)){
			alert(alertFillValidDate);
			document.forms[0].stamping_date.focus();
			document.forms[0].stamping_date.select();
			return false;
		}
		//si la lettre n'a pas ete affranchie par une machine, on verifie l'heure d'obliteration
		var tabHeures = new Array();
		for(var i=0;i<24;i++){
			//alert(formatNumber(i,2));
			tabHeures[tabHeures.length]=formatNumber(i,2);
		}
		
		if(document.forms[0].type_letter.value != "company" && trim(document.forms[0].stamping_time.value) != "" ){
			if(!isTabContaining(tabHeures,document.forms[0].stamping_time.value)){
				alert(alertFillValidStampingTime);
				return false;
			}
			
			
		}
		
	}
	
	

}
function isTabContaining(tab,val){
		//alert("recherche dans "+tab+" de "+val);
		for(var z=0;z<tab.length;z++){
			//alert("comparaison entre "+tab[z]+" et "+val);
			
			if(tab[z]==val)
				return true;
				
			
		}
		return false;
	
}
function formatNumber(number,nbrPos){
	
		var strVal=""+number;
        var strReturn="";
        var nbrZeros = nbrPos-strVal.length;
		for(var i=0;i < nbrZeros;i++){
			strReturn+="0";
		}
            
            return strReturn+strVal;

}
function isDateAfterNow(theDate){
	
	var ladate=new Array();
	ladate[0]=theDate.substring(0,2);
	ladate[1]=theDate.substring(3,5);
	ladate[2]=theDate.substring(6,10);	

	var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
	var currentDate=new Date();
	currentDate.setHours(0);
	currentDate.setMinutes(0);
	currentDate.setSeconds(0);
	
	
	//alert(currentDate+" vs "+unedate);
	
	if(currentDate.getTime() < unedate.getTime()){
		//alert("date incorrecte");
		return true;
	}
	
	// je rajoute un controle 
	return false;
}
function isDate2AfterDate1(theDate1,theDate2){
	
	var ladate=new Array();
	ladate[0]=theDate1.substring(0,2);
	ladate[1]=theDate1.substring(3,5);
	ladate[2]=theDate1.substring(6,10);	

	var unedate1 = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
	
	ladate[0]=theDate2.substring(0,2);
	ladate[1]=theDate2.substring(3,5);
	ladate[2]=theDate2.substring(6,10);	

	var unedate2 = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
	
	
	//alert(unedate1+" vs "+unedate2);
	if(unedate1.getTime() < unedate2.getTime() || theDate1 == theDate2){
		//alert("date incorrecte");
		return true;
	}
	return false;
}
function updateFormPresent(){
if(document.forms[0].present.selectedIndex == 0){
		//on affiche
		document.getElementById("date_reception").className="tabform";
}
else{
		document.getElementById("date_reception").className="maskable";
		}
	
}
function checkFormSendPwd(){
	//controle email
	if(!isMailValid(document.forms[0].adresse_email.value)){
		alert(alertWrongEmail);
		return false;
	}

}
function checkFormOtherStudies(){
	//verifier qu'il y a au moins 1 case de cochée
	var ok=false;
	for(var c = 1;c<=6;c++){
				//alert(document.forms[0]["availability_days_"+c]);
				if(document.forms[0]["availability_days_"+c].checked==true){
					ok=true;
				}
			}
			if(!ok){
				alert(alertMustSelectAtLeastOneDayAvailable);
				return false;
			}
			return ok;

}
function checkOtherStudySendingForm(){
//verifier qu'il y a bien un code barres qui a ete selectionne
//alert(document.forms[0].bar_code.selectedIndex);

if(document.forms[0].bar_code.selectedIndex < 1){
	alert(alertMustSelectBarCode);
	return false;
}
//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte

if(document.forms[0].bar_code.options[document.forms[0].bar_code.options.length-1].selected==true){
	if(trim(document.forms[0].bar_code_other.value) == ""){
		alert(alertMustSelectBarCode);
		return false;
	}
}
if((!isValidDate(document.forms[0].effective_sending_date.value)) || isDateAfterNow(document.forms[0].effective_sending_date.value) || isDate2AfterDate1(document.forms[0].effective_sending_date.value,minDateAccepted)){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDate);
		return false;
	}
	//controle de l'heure
	if(!isTimeValid(document.forms[0].effective_sending_time.value)){
		alert(alertFillValidSendingTime);
		return false;
	}
if(document.forms[0].post_office.selectedIndex < 1){
	alert(alertMustSelectPostOffice);
	return false;
}
//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
	
	if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
		if(trim(document.forms[0].post_office_2.value) == ""){
			alert(alertMustSelectPostOffice);
			return false;
		}
	}
if(trim(document.forms[0].sending_charges.value) == ""){
	alert(alertMustIndicateSendingCharges);
	return false;
}


//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
//alert(document.forms[0].post_office.selectedIndex);
if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
	
	if(trim(document.forms[0].post_office_2.value) == ""){
		alert(alertMustSelectPostOffice);
		return false;
	}
	
}
if(document.forms[0].type_mail.value=="recommande" && trim(document.forms[0].date_acknowledgment.value) != "" && (    (!isValidDate(document.forms[0].date_acknowledgment.value)) || isDateAfterNow(document.forms[0].date_acknowledgment.value) || isDate2AfterDate1(document.forms[0].date_acknowledgment.value,minDateAccepted))){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDateAcknowledgment);
		return false;
	}


}

function checkOtherStudyReceivingForm(){
//verifier qu'il y a bien un code barres qui a ete selectionne
//alert(document.forms[0].bar_code.selectedIndex);
/*
if(document.forms[0].has_received.checked == true){
	return true;
}
*/
if(document.forms[0].bar_code.selectedIndex < 1){
	alert(alertMustSelectBarCode);
	return false;
}
//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte

if(document.forms[0].bar_code.options[document.forms[0].bar_code.options.length-1].selected==true){
	if(trim(document.forms[0].bar_code_other.value) == ""){
		alert(alertMustSelectBarCode);
		return false;
	}
}
//cas ou la personne etait presente
if(document.forms[0].present_at_presentation.selectedIndex==0){
	if((!isValidDate(document.forms[0].date_presentation.value)) || isDateAfterNow(document.forms[0].date_presentation.value) || isDate2AfterDate1(document.forms[0].date_presentation.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	//controle de l'heure
	if(!isTimeValid(document.forms[0].time_presentation.value)){
		alert(alertFillValidPresentationTime);
		return false;
	}
}
else{
	//la personne n'etait pas presente
	//date de l'avis de passage
	if((!isValidDate(document.forms[0].transit_advice_date.value)) || isDateAfterNow(document.forms[0].transit_advice_date.value) || isDate2AfterDate1(document.forms[0].transit_advice_date.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	if((!isValidDate(document.forms[0].date_pickup_post_office.value)) || isDateAfterNow(document.forms[0].date_pickup_post_office.value) || isDate2AfterDate1(document.forms[0].date_pickup_post_office.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	if(!isTimeValid(document.forms[0].time_pickup_post_office.value)){
		alert(alertFillValidPickupTime);
		return false;
	}
	//check du bureau de poste
	
	if(document.forms[0].post_office.selectedIndex < 1){
		alert(alertMustSelectPostOffice);
		return false;
	}
	
	
	//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
	
	if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
		if(trim(document.forms[0].post_office_2.value) == ""){
			alert(alertMustSelectPostOffice);
			return false;
		}
	}
}

if(trim(document.forms[0].date_stamping.value) != "" && ((!isValidDate(document.forms[0].date_stamping.value)) || isDateAfterNow(document.forms[0].date_stamping.value) || isDate2AfterDate1(document.forms[0].date_stamping.value,minDateAccepted))){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	//controle de l'heure
	if(trim(document.forms[0].time_stamping.value) != "" && !isTimeValid(document.forms[0].time_stamping.value)){
		alert(alertFillValidStampingTime);
		return false;
	}

}
function checkFormClusterAdmin(){
	//controle de la date
	//alert("controle date");
	if(  !isValidDate(document.forms[0].date_sending.value)  ){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDate);
		return false;
	}
	if( trim(document.forms[0].effective_sending_date.value) != "" && !isValidDate(document.forms[0].effective_sending_date.value)){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDate);
		return false;
	}
	//controle de l'heure
	if( trim(document.forms[0].effective_sending_time.value) != "" && !isTimeValid(document.forms[0].effective_sending_time.value)){
		alert(alertFillValidSendingTime);
		return false;
	}
	

}

function checkLetterFormAdmin(){
	
	//controle du code process status
	if(document.forms[0].code_process_status.selectedIndex==0){
			alert("veuillez indiquer un code process status");
			return false;
	}
	
	//controle du transponder
	if( trim(document.forms[0].transponder_code.value) != "" &&  (   (trim(document.forms[0].transponder_code.value)).length !=10 || (trim(document.forms[0].transponder_code.value).substring(0,2) != "75" && trim(document.forms[0].transponder_code.value).substring(0,2) != "77") ) )  {
		alert("veuillez indiquer un numero de transpondeur valide");
			return false;
	}
	
		
	//controle de la date 
	if(trim(document.forms[0].receiving_date.value) != ""  ){
		if((!isValidDate(document.forms[0].receiving_date.value)) ||  isDateAfterNow(document.forms[0].receiving_date.value) || isDate2AfterDate1(document.forms[0].receiving_date.value,minDateAccepted)){
			alert(alertFillValidDate);
			document.forms[0].receiving_date.focus();
			document.forms[0].receiving_date.select();
			return false;
		}
	}
	
	
	
	//controle des infos d'obliteration
	if( trim(document.forms[0].stamping_date.value) != "" &&   ((!isValidDate(document.forms[0].stamping_date.value)) ||  isDateAfterNow(document.forms[0].stamping_date.value) || isDate2AfterDate1(document.forms[0].stamping_date.value,minDateAccepted))){
		alert(alertFillValidDate);
		document.forms[0].stamping_date.focus();
		document.forms[0].stamping_date.select();
		return false;
	}
	if(trim(document.forms[0].stamping_time.value) != "" &&  !isTimeValid(document.forms[0].stamping_time.value)){
			alert(alertFillValidStampingTime);
			
			return false;
	}
	
	
	
	

}
function checkFormMisbestellingen(){
	if(document.forms[0]["accept_misbestellingen"].checked!=true){
		alert(alertMustSelectCheckBox);
		return false;
	
	}

}
function checkMisbestellingenForm(){
	//verifier que le nbre de lettres belex n'est pas superieur au nombre de lettres tout court
	var nbrLettres = document.forms[0].nbr_letters_received.options[document.forms[0].nbr_letters_received.selectedIndex].value;
	var nbrLettresBelex = document.forms[0].nbr_letters_belex.options[document.forms[0].nbr_letters_belex.selectedIndex].value;
	var nbrLettresMisbestellingen = document.forms[0].nbr_misbestellingen.options[document.forms[0].nbr_misbestellingen.selectedIndex].value;
	if(nbrLettresMisbestellingen == 0 && document.forms[0].misbestellingen_received.selectedIndex==1){
		alert(alertMisMustSelectAtLesatOneMisbestelling);
		return false;
	}
	
	if(nbrLettres==0 && nbrLettresBelex ==0 && (document.forms[0].misbestellingen_received.selectedIndex==1)){
		
		alert(alertNoMisbestillingenAvailableIfNoLetter);
		return false;
	}
	
	/*
	if(parseInt(nbrLettresBelex) > parseInt(nbrLettres)){
		alert(alertMisBelexLettersNotMoreThanTotal);
		return false;
	}
	
	if(parseInt(nbrLettresMisbestellingen) > parseInt(nbrLettres)){
		alert(alertMisbestellingenLettersNotMoreThanTotal);
		return false;
	}
	*/
	/*
	alert(nbrLettres+" - "+nbrLettresBelex);
	return false;
	*/
	
	
	
}
function checkFormRemun(){
	//verifier que le montant est superieur à 5 € (20 lettres)
	if(document.forms[0].admin_user_mode.value == "Y"){
	
	}
	else{
		if(parseInt(document.forms[0].remuneration_amount.value) < 5){
			alert(alertRemunerationAmountNotEnough);
			return false;
		}
	}
	//controler le numero de compte
	if(!isAccountNumberValid(document.forms[0].account_number.value)){
		alert(alertWrongAccountNumber);
		return false;
	}
	if(!confirm(confirmRemuneration)){
		return false;
	}
}
function checkFormRemunStamping(){
	//verifier que le montant est superieur à 5 € 
	if(parseInt(document.forms[0].remuneration_amount.value) < 5){
		alert(alertRemunerationStampingAmountNotEnough);
		return false;
	}
	//verifier le numero de compte
	
	if(!isAccountNumberValid(document.forms[0].account_number.value)){
		alert(alertWrongAccountNumber);
		return false;
	}
	
	//verifier qu'il y a une communication
	if(trim(document.forms[0].communication_payment.value).length == 0 || trim(document.forms[0].communication_payment.value).length > 53){
		alert(alertInvalidCommunication);
		return false;
	}
	
	if(!confirm(confirmRemuneration)){
		return false;
	}
	
}
function checkLetterFormNotReceived(){
	//verifier que la case a bien ete cochee
	if(document.forms[0].letter_not_received.checked == false){
		alert(alertMustCheckBoxNotReceived);
		return false;
	}

}
function checkFormUpdatePwd(){
	//verifier que le mot de passe actuel contient au moins 5 char
	if(document.forms[0].current_pwd.value.length < 5){
		alert(alertWrongNumberedPwd);
		return false;
	}
	//verifier que les nouveaux pwd font au moins 5 char et qu'ils sont identiques
	if(document.forms[0].new_pwd_1.value.length <5 || document.forms[0].new_pwd_2.value.length <5 ){
		alert(alertWrongNumberedPwd);
		return false;
	}
	if(document.forms[0].new_pwd_1.value != document.forms[0].new_pwd_2.value){
		alert(alertNotIdenticalPwd);
		return false;
	}
	
	
	
	
	

}
function checkFormStopParticipation	(){
	//verifier qu'il y a au moins 1 case qui a ete cochee
	var ok = false;
	if(document.forms[0].belex_bulk && document.forms[0].belex_bulk.checked == true){
		ok=true;
	} 
	if(document.forms[0].parcels && document.forms[0].parcels.checked == true){
		ok=true;
	} 
	if(document.forms[0].misbestellingen && document.forms[0].misbestellingen.checked == true){
		ok=true;
	} 
	if(ok){
		if(!confirm(confirmStoppingStudy)){
			return false;
		}
	}
	else{
		alert(alertMustIndicateOneStoppedStudy);
		return false;
	}
}
function checkFormBulkMail(){

	//verifier les dates et la veleur numerique
	
	if(trim(document.forms[0].inpak.value) != ""  ){
		if(!isValidDate(document.forms[0].inpak.value)) {
			alert("veuillez indiquer une date valide (inpak) ");
			
			return false;
		}
	}
	if(trim(document.forms[0].afgifte.value) != ""  ){
		if(!isValidDate(document.forms[0].afgifte.value)) {
			alert("veuillez indiquer une date valide (afgifte) ");
			
			return false;
		}
	}
	
	if(trim(document.forms[0].bezoek.value) != ""  ){
		if(!isValidDate(document.forms[0].bezoek.value)) {
			alert("veuillez indiquer une date valide (bezoek) ");
			
			return false;
		}
	}
	if(trim(document.forms[0].rapport.value) != ""  ){
		if(!isValidDate(document.forms[0].rapport.value)) {
			alert("veuillez indiquer une date valide (rapport) ");
			
			return false;
		}
	}
	var pattern=/^[0-9]+$/;
	if(!pattern.test(document.forms[0].quotrax_aantal.value)){
		alert("veuillez indiquer une valeur numerique (quotrax aantal)");
		return false;
	}
	
}
function checkTrackstickReceivingForm(){
	/*
	//alert(document.forms[0].bar_code_reception.value +" = "+document.forms[0].bar_code_from_db.value);
	if(document.forms[0].bar_code_reception.value != document.forms[0].bar_code_from_db.value){
		if(!confirm(confirmDifferentBarCode+" "+document.forms[0].bar_code_from_db.value)){
			return false;
		}
	}
	*/
	
//cas ou la personne etait presente
if(document.forms[0].method_reception.selectedIndex != 3){
	if((!isValidDate(document.forms[0].date_presentation.value)) || isDateAfterNow(document.forms[0].date_presentation.value) || isDate2AfterDate1(document.forms[0].date_presentation.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	//controle de l'heure
	if(document.forms[0].method_reception.selectedIndex != 2 && !isTimeValid(document.forms[0].time_presentation.value)){
		alert(alertFillValidPresentationTime);
		return false;
	}
}
else{

	//la personne n'etait pas presente
	//date de l'avis de passage
	if((!isValidDate(document.forms[0].transit_advice_date.value)) || isDateAfterNow(document.forms[0].transit_advice_date.value) || isDate2AfterDate1(document.forms[0].transit_advice_date.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	if((!isValidDate(document.forms[0].date_pickup_post_office.value)) || isDateAfterNow(document.forms[0].date_pickup_post_office.value) || isDate2AfterDate1(document.forms[0].date_pickup_post_office.value,minDateAccepted)){
			//alert(document.forms[0].effective_sending_date.value);
			alert(alertFillValidDate);
			return false;
	}
	if(!isTimeValid(document.forms[0].time_pickup_post_office.value)){
		alert(alertFillValidPickupTime);
		return false;
	}
	//check du bureau de poste
	
	if(document.forms[0].post_office.selectedIndex < 1){
		alert(alertMustSelectPostOffice);
		return false;
	}
	
	
	//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
	
	if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
		if(trim(document.forms[0].post_office_2.value) == ""){
			alert(alertMustSelectPostOffice);
			return false;
		}
	}
	
}

}
function checkTrackstickSendingForm(){
//alert(document.forms[0].bar_code_reception.value +" = "+document.forms[0].bar_code_from_db.value);
	/*
	if(document.forms[0].bar_code_sending.value != document.forms[0].bar_code_from_db.value){
		if(!confirm(confirmDifferentBarCode+" "+document.forms[0].bar_code_from_db.value)){
			return false;
		}
	}
	*/
	
if((!isValidDate(document.forms[0].date_sending.value)) || isDateAfterNow(document.forms[0].date_sending.value) || isDate2AfterDate1(document.forms[0].date_sending.value,minDateAccepted)){
		//alert(document.forms[0].effective_sending_date.value);
		alert(alertFillValidDate);
		return false;
	}
	//controle de l'heure
	if(!isTimeValid(document.forms[0].time_sending.value)){
		alert(alertFillValidSendingTime);
		return false;
	}
if(document.forms[0].post_office.selectedIndex < 1){
	alert(alertMustSelectPostOffice);
	return false;
}
//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
	
	if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
		if(trim(document.forms[0].post_office_2.value) == ""){
			alert(alertMustSelectPostOffice);
			return false;
		}
	}



//si jamais le paneliste a selectionne autres, il faut qu'il remplisse le chmap de texte
//alert(document.forms[0].post_office.selectedIndex);
if(document.forms[0].post_office.options[document.forms[0].post_office.options.length-1].selected==true){
	
	if(trim(document.forms[0].post_office_2.value) == ""){
		alert(alertMustSelectPostOffice);
		return false;
	}
	
}




}
function hideOtherPostalBox(){
		if(document.forms[0].postal_box_correct && document.forms[0].postal_box_correct.options[1].selected==true){
				document.getElementById("id_other_postal_box").className="maskable";
		}
		else{
				document.getElementById("id_other_postal_box").className="affiche";
		}
}

function checkFormUcLetter(){
	var pattern=/^[0-9]{9,10}$/;
	if(!pattern.test(document.forms[0].letter_unique_code.value)){
		alert(alertMustFillValidUniqueCodeLetter);
		return false;
	}
}
function openStreetResearchAdmin(champ,bypass){
		
		champ.blur();
		var popupName="streetResearch";
		//var cellLeft=((browserWidth()-750)/2)+130;
		
		
		//document.getElementById(popupName).style.left=cellLeft;
		//alert(document.forms[0].code_postal.value);
		//document.getElementById(popupName).document.forms[0].street_field.value=document.forms[0].code_postal.value;
		
		if(champ.value=="" || bypass==true)
		{
			//controle du code postal
			if(!isZipCodeValid(document.forms[0].postal_code.value)){
				alert(alertWrongZipCode);
				return false;
			}
			//alert(window.streetResearch.src);
		
			afficherPopup(popupName);
			//alert(document.forms[0].code_postal.value);
			window.streetResearch.setZip(document.forms[0].postal_code.value);
			
			
		//document.getElementById(popupName).setZipCode(document.forms[0].code_postal.value);
		}
		
		
	}
	


