
//------------------------------------------------------------------------------
// fonctions utilitaires
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
function trim(str)
//------------------------------------------------------------------------------
{
   return str.replace(/(^\s*)|(\s*$)/g,"");
}

//--------------------------------
function toEuro(value,nbdecimales)
//--------------------------------
{
    var negatif=value<0?true:false;
    var string=new String(Math.floor(Math.abs(value)));
    var result="";
    var indice=string.length;
    while (indice>3)
    {
       result=" "+string.substring(indice-3,indice)+result;
       indice-=3;
    }
    if (indice>0)
       result=string.substring(Math.max(indice-3,0),indice)+result;
    if (nbdecimales==2)
    {
       value=Math.floor(100*(Math.abs(value)-Math.floor(Math.abs(value))));
       if (value<10) result+=",0"+value;
       else result+=","+value;
    }
    result+=" €";
    if (negatif) result="- "+result;
    return result;
	// return Math.round(value)+ " &#8364;";
}

//------------------------------------------------------------------------------
function codeTouche(evenement)
//------------------------------------------------------------------------------
// implémentation différente selon le navigateur
{
   for (prop in evenement)
      if(prop=='which')
         return(evenement.which);
   return(evenement.keyCode);
}

//------------------------------------------------------------------------------
function scanInteger(evenement)
//------------------------------------------------------------------------------
{
   var reCarSpeciaux = /[\x00\x08\x0D]/;
   var reCarValides = /\d/;
   var codeDecimal  = codeTouche(evenement);
   var car = String.fromCharCode(codeDecimal);
   var autorisation = (reCarValides.test(car) || reCarSpeciaux.test(car));
   return autorisation;
}

//------------------------------------------------------------------------------
/*function setParagrahText(elementPID,newText)
//------------------------------------------------------------------------------
{
  var elementP;
  var old_child;
  var new_child;
  elementP=document.getElementById(elementPID);
  old_child=elementP.firstChild;
  new_child=document.createTextNode(newText);
  elementP.replaceChild(new_child,old_child);
}*/

//------------------------------------------------------------------------------
/*function ControlInteger(saisie_value,paragraph_id)
//------------------------------------------------------------------------------
{
    var alert_msg=" ";
    if (saisie_value=="")
       alert_msg=" (*) obligatoire";
    setParagrahText(paragraph_id,alert_msg);
}*/

//------------------------------------------------------------------------------
// fonctions spécifiques
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
function window_onload()
//------------------------------------------------------------------------------
{
	document.getElementById("Natop").value="Neuf";
	document.getElementById("Localisation").value="I";
	document.getElementById("MontantAchat").value="";
/*  	ControlInteger(document.getElementById("MontantAchat").value,"MontantAchatP");*/
	Calcul();
}

//------------------------------------------------------------------------------
function Calcul()
//------------------------------------------------------------------------------
{
	var Natop=document.getElementById("Natop").value;
	var Localisation=document.getElementById("Localisation").value;
	var MontantAchat=document.getElementById("MontantAchat").value;

	if (trim(MontantAchat)=="")
    {
    	var comment="";
    	document.getElementById("EmolumentsNotaire").value=comment;
    	document.getElementById("DroitsEtTaxes").value=comment;
    	document.getElementById("FormalitesDebours").value=comment;
    	document.getElementById("Total").value=comment;

    }
    else
    {
    	document.getElementById("EmolumentsNotaire").value=toEuro(FEmolumentsNotaire(MontantAchat,Localisation),0)+"           ";
    	document.getElementById("DroitsEtTaxes").value=toEuro(FDroitsNotaire(MontantAchat,Natop),0)+"           ";
    	document.getElementById("FormalitesDebours").value=toEuro(FFormalitesDeboursNotaire(Localisation),0)+"           ";
    	document.getElementById("Total").value=toEuro(FFraisNotaire( MontantAchat,Localisation, Natop),0)+"           ";
    }
}

