NumChars = "0123456789";

function IsNumeric(Data) {

var It = true;
var c;

	for (var x = 0; x < Data.length; x++)

		if (It) {
			c = Data.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}

		return It;
}

function checkNumber(car,zone) {
	if(car!="")
	{
	    if (IsNumeric(car) == false)
	    {
		alert("Saisissez un montant numérique");
		var car2="";
	
		for (var i = 0; i < car.length; i++) 
		{
	        	var ch = car.substring(i, i + 1)
			if (IsNumeric(ch) == false)
			{
				ch="";
			}
	        car2=car2+ch;
	    	}
	    	if (zone==1) {
		   document.notaire.mont.value=car2;
 	  	   document.notaire.mont.focus();
		   return car2;
		}
	        if (zone==2) {
		   document.notaire.emprunt.value=car2;
   	           document.notaire.emprunt.focus();
	           return car2;
	        }
	    }
	}
}

function calcul (){
	var s=document.notaire.sel.selectedIndex;
	if(document.notaire.mont.value == ""){
		alert("Saisissez le montant du bien");
		document.notaire.mont.focus();
		return;
	}
	if(document.notaire.emprunt.value == ""){
		alert("Saisissez le montant de votre emprunt");
		document.notaire.emprunt.focus();
		return;
	}
	if(s == 0){
		alert("Vous devez indiquer si le bien est neuf ou ancien");
		return;
	}

	mtbien = parseInt(document.notaire.mont.value);
	mtemprunt = parseInt(document.notaire.emprunt.value);

	if(s == 1) { // NEUF
	    montant = Math.round(((mtbien*0.78936)/100)    + 
	               	         ((mtbien*0.615)/100)     +
	    			 ((mtbien*0.10)/100)      +
	    			 ((mtemprunt*0.6578)/100) +
	    			 ((mtemprunt*0.05)/100));
	    			 
		if (mtbien != "0") {montant = montant + 1044;}
		if (mtemprunt != "0") {montant = montant + 615;}
	   
	   document.notaire.total.value = montant ;
	}

	if(s == 2) { //ANCIEN
	    montant = Math.round(((mtbien*0.9867)/100)    +
	    			 ((mtbien*4.89)/100)      +
	    			 ((mtbien*0.10)/100)      +
	    			 ((mtemprunt*0.6578)/100) +
	    			 ((mtemprunt*0.05)/100));
	    			 
		if (mtbien != "0") {montant = montant + 1524;}
		if (mtemprunt != "0") {montant = montant + 615;}
	   
	   document.notaire.total.value = montant ;
	}
	
}

function annuler() {
	document.notaire.sel.value="0";
	document.notaire.total.value="";
	document.notaire.mont.value="";
	document.notaire.emprunt.value="";
}