function VerifierPrecision(fr, n)
{
	precision = String(Math.SQRT1_2)
	if (precision.indexOf("0.") != -1) precision = precision.substring(2, precision.length)
	precision = precision.length
	if (n.length > precision)
	{
		if (fr) alert("Erreur : le nombre "+n+" est trop grand ! ("+precision+" chiffres maximum)"); else alert("Error : the number "+n+" is to big ! ("+precision+" digits maximum)");
		return false
	}
	else return true;
}
function Verifier(fr,v1,v2)
{
	if (fr)
	{
		msg='Erreur : '
		msg2=' n\'est pas un nombre valide.'
		msg3 = 'vous devez indiquer un nombre.'
	}
	else
	{
		msg='Error : '
		msg2=' is not a valid number.'
		msg3 = 'you must give a number.'
	}
	if (v1.length == 0)
	{
		alert(msg+msg3)
		return false
	}
	else if (isNaN(v1))
	{
		alert(msg+"\'"+v1+"\'"+msg2)
		return false
	}
	else if (!VerifierPrecision(fr, v1)) return false;
	else if (Verifier.arguments.length==3)
	{
		if (v2.length == 0)
		{
			alert(msg+msg3)
			return false
		}
		else if (isNaN(v2))
		{
			alert(msg+"\'"+v2+"\'"+msg2)
			return false
		}
		else if (!VerifierPrecision(fr, v2)) return false;
		else return true;
	}
	else return true;
}
function Div()
{
	this.n=0;
	this.p=0;
	return this;
}
function Decomposer(fr, x, p1, p2, p3)
{
	if (Verifier(fr, x))
	{
		x=Math.abs(Math.round(eval(x)))
		var x1=x;
		var d;
		var prem=true;
		var div=new Div();
		var r="";
		if (Math.floor(x/2)==(x/2) && (x!=2))
		{
			div.n=2;
			prem=false;
			while (Math.floor(x/2)==(x/2))
			{
				div.p++;
				x=x/2;
			}
		}
		if (div.p!=0)
		{
			if (r=="")
				if (div.p==1) r=div.n; else r=div.n+"^"+div.p
			else
				if (div.p==1) r=r+"*"+div.n; else r=r+"*"+div.n+"^"+div.p
			div.p=0;
		}
		d=3;
		while (d*d<=x)
		{
			if (Math.floor(x/d)==(x/d))
			{
				prem=false;
				div.n=d;
				while (Math.floor(x/d)==(x/d))
				{
					div.p++;
					x=x/d;
				}
			}
			if (div.p!=0)
			{
				if (r=="")
					if (div.p==1) r=div.n; else r=div.n+"^"+div.p
				else
					if (div.p==1) r=r+"*"+div.n; else r=r+"*"+div.n+"^"+div.p
				div.p=0;
			}
			d=d+2;
		}
		if (x!=1) r+="*"+x
		if (prem)
			if (x==1)
				alert(p1)
			else
				alert(x+p2)
		else
			alert(x1+p3+x1+" = "+r);
		document.f2.combien.focus()
	}
}
function Calcul(fr,max,x,p1,p2,p3,p4,p5,p6,p7)
{
	if (Verifier(fr,max,x))
	{
		max=Math.round(Math.abs(eval(max)))
		x=Math.round(Math.abs(eval(x)))
		nbl = 1;
		n=0
		if (fr) s=' &agrave; '; else s=''
		if (max == 0)
			alert(p1)
		else
		{
			x = Math.max(2,x)
			if (max == 1)
				titre = p2
			else
			{
				titre = p3+max+p4
				if (fr) s='s'+s
			}
			if (x>=3) titre+=p5+s+x
			NP = window.open("","_blank",'scrollbars=yes,width='+(screen.width-50)+',height='+(screen.height-150)+',menubar=yes,location=no,status=yes');
			NP.moveTo(0,0);
			NP.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\"><html><head><title>"+titre+"</title>");
			NP.document.write('<link rel="stylesheet" href="../style.php" type="text/css">');
			NP.document.write("</head><body background='np.gif'><center><table border=1>");
		}
		NP.document.write("<tr><td>&nbsp;</td>");
		for (k=1;k<=Math.min(20, max);k++)
			NP.document.write("<th>"+k+"</th>");
		NP.document.write("</tr>");
		if (x == 2)
		{
			NP.document.write("<tr><th>"+nbl+"</th><td>2</td>");
			nbl++;
			n=1;
		}
		if ((x == 2) && (max >= 2) || (x == 3))
		{
			NP.document.write('<td>3</td>');
			n=4-x
		}
		x = Math.max(3,x)
		// si nombre pair -> soustraire 1
		if (x == 2*Math.floor(x/2)) x = x-1;
		else if (n == 0) x = x-2;
		while (n<max)
		{
			d=3;
			x=x+2;
			while ((d*d<x) && (Math.floor(x/d)!=(x/d)))
				d=d+2;
			if (d*d>x)
			{
				if ((n % 20) == 0)
				{
					NP.document.writeln("</tr><tr><th>"+nbl+"</th>");
					nbl++;
				}
				n=n+1;
				NP.document.write("<td>"+x+"</td>"); //Math.ceil(5*n/max-1)
				NP.status = p6+' : '+n;
			}
		}
		NP.document.write('</tr></table></center></body></html>');
		NP.status = p7;
	}
}