
	function checkEmptyAgencies() {
	
	  	iAgencies = removeAllWhiteSpaces(document.getElementById('agencies').value);
	  	document.getElementById('agencies').value = iAgencies;
		if ( (iAgencies == "") || (iAgencies == 0) || (iAgencies < 0) ) {
			alert("Nombre d'agences : Veuillez saisir le nombre d'agences");
			document.getElementById('agencies').focus();
		}
		
	}			
	
	function checkAgencies() {
	
	  	iAgencies = removeAllWhiteSpaces(document.getElementById('agencies').value);
		if (isNaN(iAgencies) == true) {
			alert("Nombre d'agences : Seulement les chiffres sont permis");
			iAgencies = "1"
	  		document.getElementById('agencies').value = iAgencies;
			document.getElementById('agencies').focus();
		} else {
			calcSimTotal();
			if (vBolPropsShowing=='False'){
				calcPayTotal();
			}
		}
	}			
	
	function checkEmptyDeps() {
	
	  	iDeps = removeAllWhiteSpaces(document.getElementById('deps').value);
	  	document.getElementById('deps').value = iDeps;
		if ( (iDeps == "") || (iDeps == 0) || (iDeps < 0) ) {
			alert("Départements : Veuillez saisir le nombre de départements");
			document.getElementById('deps').focus();
		}
		
	}			
	
	function checkDeps() {
	
	  	iDeps = removeAllWhiteSpaces(document.getElementById('deps').value);
		if (isNaN(iDeps) == true) {
			alert("Départements : seulement les chiffres sont permis");
			iDeps = "1"
	  		document.getElementById('deps').value = iDeps;
			document.getElementById('deps').focus();
		} else {
			calcSimTotal();
		}
	}			
	
	function checkDataTypes() {
	
		if ( ( document.getElementById('dataTypeS').checked ) || ( document.getElementById('dataTypeB').checked ) || ( document.getElementById('dataTypeR').checked ) || ( document.getElementById('dataTypeT').checked ) ) {
			calcSimTotal();
		} else {
			alert("Service(s) : Veuillez choisir un service");
		}
		
	}	

	function calcSimTotal() {
	
	  	iAgencies = parseInt(removeAllWhiteSpaces(document.getElementById('agencies').value));
	  	iDeps = parseInt(removeAllWhiteSpaces(document.getElementById('deps').value));
	
		iPromo = parseInt(document.getElementById('promo').value) / 100;
		i1m = parseInt(document.getElementById('1m').value);
		i3m = parseInt(document.getElementById('3m').value);
		i6m = parseInt(document.getElementById('6m').value);
		i12m = parseInt(document.getElementById('12m').value);
	
		iServices = 0;
		iServicesFactor = 0;
	
		if ( document.getElementById('dataTypeS').checked ) {
			iServices = iServices + 1
		}
		if ( document.getElementById('dataTypeB').checked ) {
			iServices = iServices + 1
		}
		if ( document.getElementById('dataTypeR').checked ) {
			iServices = iServices + 1
		}
		if ( document.getElementById('dataTypeT').checked ) {
			iServices = iServices + 1
		}
		
		if (iServices == 1) {
			iServicesFactor = 1
		} else if (iServices == 2) {
			iServicesFactor = 1.5 
		} else if (iServices == 3) {
			iServicesFactor = 1.8 
		} else if (iServices == 4) {
			iServicesFactor = 2 
		}
		
		i1mAgencies = i1m * 0.1 * (iAgencies-1);
		i3mAgencies = i3m * 0.1 * (iAgencies-1);
		i6mAgencies = i6m * 0.1 * (iAgencies-1);
		i12mAgencies = i12m * 0.1 * (iAgencies-1);
	
		i1mDeps = i1m * 0.1 * (iDeps-1);
		i3mDeps = i3m * 0.1 * (iDeps-1);
		i6mDeps = i6m * 0.1 * (iDeps-1);
		i12mDeps = i12m * 0.1 * (iDeps-1);
	
		i1mHT = Math.round ( ( i1m + i1mAgencies + i1mDeps ) * iServicesFactor );
		i3mHT = Math.round ( ( i3m +i3mAgencies + i3mDeps ) * iServicesFactor );
		i6mHT = Math.round ( ( i6m + i6mAgencies + i6mDeps ) * iServicesFactor );
		i12mHT = Math.round ( ( i12m + i12mAgencies + i12mDeps ) * iServicesFactor );
		
		document.getElementById('1mHT').innerHTML = i1mHT;	
		document.getElementById('3mHT').innerHTML = i3mHT;	
		document.getElementById('6mHT').innerHTML = i6mHT;	
		document.getElementById('12mHT').innerHTML = i12mHT;	
	
		//show the promo line
		if (document.getElementById('promo').value != "100") {
			document.getElementById('1mPromo').innerHTML =  Math.round ( i1mHT * iPromo );	
			document.getElementById('3mPromo').innerHTML = Math.round ( i3mHT * iPromo );	
			document.getElementById('6mPromo').innerHTML = Math.round ( i6mHT * iPromo );	
			document.getElementById('12mPromo').innerHTML = Math.round ( i12mHT * iPromo );	
		}
	
		//show the per agency line
		if ( iAgencies > 1 ) {
			document.getElementById('1mPerAgency').innerHTML = "(" + Math.round ( i1mHT * iPromo / iAgencies ) + " / agence)";	
			document.getElementById('3mPerAgency').innerHTML = "(" + Math.round ( i3mHT * iPromo / iAgencies ) + " / agence)";	
			document.getElementById('6mPerAgency').innerHTML = "(" + Math.round ( i6mHT * iPromo / iAgencies ) + " / agence)";	
			document.getElementById('12mPerAgency').innerHTML = "(" + Math.round ( i12mHT * iPromo / iAgencies ) + " / agence)";	
		} else {
			document.getElementById('1mPerAgency').innerHTML = "";	
			document.getElementById('3mPerAgency').innerHTML = "";	
			document.getElementById('6mPerAgency').innerHTML = "";	
			document.getElementById('12mPerAgency').innerHTML = "";	
		}

		//the payment screen is displayed and no proposals are showing
		if ( (document.getElementById('1mPromoTTC') != null) && (document.getElementById('tableProposal') == null) ){
			document.getElementById('1mPromoTTC').value = (i1mHT * iPromo * 1.196).toFixed(2);	
			document.getElementById('3mPromoTTC').value = (i3mHT * iPromo *  1.196).toFixed(2);	
			document.getElementById('6mPromoTTC').value = (i6mHT * iPromo *  1.196).toFixed(2);	
			document.getElementById('12mPromoTTC').value = (i12mHT * iPromo *  1.196).toFixed(2);	
			calcPayTotal('');
		}
	}


	function calcPayTotal(pAction) {
		
		iDuration = document.getElementById('duration').value;
		iMethod = document.getElementById('method').value;
		objPayPal = document.getElementById('byPayPal');
		objPayBox = document.getElementById('byPayBox');
		objVirement = document.getElementById('byVirement');
		objCheque = document.getElementById('byCheque');
		
		//cheques must be for 12 months only
		if ( (iMethod == 4) && (iDuration != 12) ) {	
			iDuration = 12
			document.getElementById('duration').value = iDuration;
		} else if (iMethod == 1) {
			alert('ATTENTION : vous avez choisi le mode de règlement \'carte de crédit (renouvellement automatique)\'. Ce mode de paiment renouvellera votre abonnement par tacite reconduction. Si vous souhaitez effectuer un seul règlement, choisissez le mode de règlement \'carte de crédit\'.');			
		}
		
		iPromoTTC = parseFloat(document.getElementById(iDuration + 'mPromoTTC').value);
		if (iMethod == 4) {
			iPromoTTC = (iPromoTTC * 1.1).toFixed(2);
		} else {
			iPromoTTC = iPromoTTC.toFixed(2);
		}
		document.getElementById('payTotalRight').innerHTML = iPromoTTC + ' Euros TTC';

		if (pAction == "") {
			objPayPal.style.display = 'none';		
			objPayBox.style.display = 'none';		
			objVirement.style.display = 'none';
			objCheque.style.display = 'none';
			if (iMethod == 1) {
				objPayPal.style.display = 'block';		
				objPayBox.style.display = 'none';		
				objVirement.style.display = 'none';
				objCheque.style.display = 'none';
			} else if (iMethod == 2) {
				objPayPal.style.display = 'none';		
				objPayBox.style.display = 'block';		
				objVirement.style.display = 'none';
				objCheque.style.display = 'none';
			} else if (iMethod == 3) {
				objPayPal.style.display = 'none';		
				objPayBox.style.display = 'none';		
				objVirement.style.display = 'block';
				document.getElementById('payTotalVirement').innerHTML = iPromoTTC + ' Euros';
				objCheque.style.display = 'none';
			} else if (iMethod == 4) {
				objPayPal.style.display = 'none';		
				objPayBox.style.display = 'none';		
				objVirement.style.display = 'none';
				objCheque.style.display = 'block';
				document.getElementById('payTotalCheque').innerHTML = iPromoTTC + ' Euros';
			}
		} else if (pAction == "submit") {
		
			if (iMethod == 1) {
			
				document.payPal.a3.value = iPromoTTC; 
				document.payPal.p3.value = iDuration;
				document.payPal.submit();
						
			} else if (iMethod == 2) {

				strEmail = trim(removeMultipleWhiteSpaces(document.getElementById('payEmail').value));
				document.getElementById('payEmail').value = strEmail;
			
				if (strEmail == "")	{
					alert('Veuillez saisir l\'adresse email\n');
				} else if (isAgentEmailOk(strEmail) == false)	{
					alert('L\'adresse email n\'est pas valide\n');
				} else {
					document.payBox.PBX_PORTEUR.value = strEmail;		
					document.payBox.PBX_TOTAL.value = (iPromoTTC * 100).toFixed(0);	
					document.payBox.submit();
				}
			}
		}			
	}
