NumChars = "0123456789";
function verifNombre(quantite,msg) {
	var bReturn = true;
	var c;
	for (var x = 0; x < quantite.length; x++)
		if (bReturn)
		{
			c = quantite.charAt(x);
			bReturn = ( NumChars.indexOf(c) != -1);
		}
	if (bReturn == true)
		if (quantite == 0)
			bReturn = false;
	if ((bReturn != true) && (msg!=''))
		alert(msg);
	return bReturn;
}
NumTaux = "0123456789.";
function verifTaux(quantite,msg) {
	var bReturn = true;
	var c;
	for (var x = 0; x < quantite.length; x++)
		if (bReturn)
		{
			c = quantite.charAt(x);
			bReturn = ( NumTaux.indexOf(c) != -1);
		}
	if (bReturn == true)
		if (quantite == 0)
			bReturn = false;
	if ((bReturn != true) && (msg!=''))
		alert(msg);
	return bReturn;
}

// Ajoute la fonction trim comme méthode de l'objet String.
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}


function toInt(val)
{

	val.value = val.value.trim();

	if(val.value=='')
		val.value="0";

	if(isNaN(val.value))
		val.value="0";

	return parseInt(val.value);

}

function calculerCoutTotal(form)
{
	coutProjet = toInt(form.dossier_COUTACQUISITION);
	construction = toInt(form.dossier_COUTCONSTRUCTION);
	terrain = toInt(form.dossier_COUTTERRAIN);
	travaux = toInt(form.dossier_COUTTRAVAUX);
	sousTotalAutreFrais = toInt(form.dossier_COUTSSTOTAL);
	totalAutreFrais = toInt(form.dossier_COUTFRAIS);
	fraisNotaire = toInt(form.dossier_COUTNOTAIRE);
	
	coutTotal = coutProjet + construction + terrain + travaux + sousTotalAutreFrais + totalAutreFrais + fraisNotaire;
	form.total.value = coutTotal;
	form.dossier_COUTTOTAL.value = coutTotal;
}

