function lectnb(si) {
 var result="";
 for (var pi=0;pi<si.length;pi++) {
  var ci=si.charAt(pi);
  if ((ci!="0")||(result!=""))
   if (ci>="0" && ci<="9")
    result+=ci
   else if ((ci==",")||(ci=="."))
    result+="."
   else if ((ci=="-")&&(result==""))
    result+="-";
 }
 if (result=="") result="0";
 return result;
}

function strtoint(si) {
 return parseInt(lectnb(si));
}

function strtofloat(sf) {
 return parseFloat(lectnb(sf));
}

function inttostr(i) {
 var result="";
 i=Math.round(parseFloat(i));
 si=i.toString();
 if (isNaN(si)) si="0";
 bi = 0;
 for (pi=si.length-1;pi>=0;pi--) {
  ci = si.charAt(pi);
  if ((bi==0)&&(pi!=si.length-1)&&(ci!="-")) {
   result=ci+" "+result;
  } else {
   result=ci+result;
  }
  bi=(bi+1)%3;
 }
 return result;
}

function floattostr(f) {
 f=Math.round(f*10000)/10000;
 var sf = f.toString();
 var result = "";
 for (pi=0;pi<sf.length;pi++) {
  cf = sf.charAt(pi);
  if (cf=='.')
   result += ','
  else
   result += cf;
 }
 return result;
}



function number_format(src,nv) {
	nv=parseInt(nv,10);
	if (nv<0||nv>9) nv=0; 
	cm = Math.pow(10,nv);
	s = src.value;
	
	if (cm>1) {	
		f= strtofloat(s);
		f2= parseFloat(Math.round(f*cm)) / cm;
		i2= Math.floor(f2);
		v2= Math.round(cm * (f2-i2));
		sv2= "0000000000"+v2;
		sv2d=sv2.length-nv;
		sv2f=sv2.length;
		sv2= sv2.substring(sv2d,sv2f);
		
		sf = inttostr(i2)+","+sv2;
	} else {
		i=strtoint(s);
		sf=inttostr(i);
	}
	src.value=sf;
}
function number_format2(src,nv) {
	nv=parseInt(nv,10);
	if (nv<0||nv>9) nv=0; 
	cm = Math.pow(10,nv);
	s = src.value;
	
	if (cm>1) {	
		f= strtofloat(s);
		f2= parseFloat(Math.round(f*cm)) / cm;
		i2= Math.floor(f2);
		v2= Math.round(cm * (f2-i2));
		sv2= "0000000000"+v2;
		sv2d=sv2.length-nv;
		sv2f=sv2.length;
		sv2= sv2.substring(sv2d,sv2f);
		
		sf = inttostr(i2)+","+sv2;
	} else {
		i=strtoint(s);
		sf=inttostr(i);
	}
	return sf;
}		

function calcFrais(nb,nv){
	if(parseInt(nb.value) <= 46000){
		document.getElementById('honoraires').value = parseInt(nb.value*10/100);		
		document.getElementById('honorairesPourcent').value = "10"
		document.getElementById('prixFAI').value = parseInt(nb.value)+(parseInt(nb.value)*10/100)
	}else if(parseInt(nb.value) > 46000 && parseInt(nb.value) < 107001){
		document.getElementById('honoraires').value = parseInt(nb.value*8/100);	
		document.getElementById('honorairesPourcent').value = "8";
		document.getElementById('prixFAI').value = parseInt(nb.value)+(parseInt(nb.value)*8/100)
	}else{
		document.getElementById('honoraires').value = parseInt(nb.value*6/100);
		document.getElementById('honorairesPourcent').value = "6";
		document.getElementById('prixFAI').value = parseInt(nb.value)+(parseInt(nb.value)*6/100)
	}
}

function calcFraisPourcent(nb,nv){
	pourcent = parseInt(nb.value);
	prix = parseInt(document.getElementById('prixnetvendeur').value);
	if(pourcent != "" && prix != ""){
		document.getElementById('honoraires').value = parseInt(prix*pourcent/100);
		document.getElementById('prixFAI').value = parseInt(prix)+(prix*parseInt(pourcent)/100);
	}else{
		if(prix == ""){
			alert("Veuillez saisir un prix net vendeur!");
		}else{
			document.getElementById('honoraires').value = 0;
			document.getElementById('prixFAI').value = parseInt(prix);
		}
	}
}


