function maak_vergl()
{
check_teller=0;
document.opg.antw.value='';
document.opg.fac1.value="";
document.opg.fac2.value="";
a=0;b=0;
while (a == 0 || b == 0) 
with (Math)
	{
	 a = floor(random()*10-10)
	 b = floor(random()*20-5)
	 }
som=a+b;
prod=a*b
if (som<0)
	plmsom='-';
	 else
	  plmsom='+';
if (som==-1 || som==1)
{
	schrijf='';
}
else 
	{
	schrijf=Math.abs(som);
	}

if (a*b<0)
	plmprod='-'
	 else
	  plmprod='+';
kw=(String.fromCharCode(178));
if (som!=0)
{
document.opg.formule.value='x'+kw+' '+plmsom+' '+schrijf+'x'+' '+plmprod+' '+Math.abs(prod);
}
else
	{
	document.opg.formule.value='x²'+' '+plmprod+' '+Math.abs(prod);
	}



haak1='(';
haak2=')';
if (a<0)
	plma=''
		else
		  plma='+';
if (b<0)
	plmb=''
		else
		  plmb='+';
term1=haak1+'x'+plma+a+haak2;
term2=haak1+'x'+plmb+b+haak2;
}

function check()
{
if (document.opg.fac1.value=="" || document.opg.fac2.value=="")
	{
	 alert('Je moet eerst de factoren invullen');
	 return false;
	}
else
	{ 
	 check_teller++;
	 if (check_teller==1)
		{
		 p=document.opg.fac1.value;
		 q=document.opg.fac2.value;
	 		if ((p==term1 && q==term2) || (p==term2 && q==term1))
				{
		 		 antw_goed();
		 		 tellen();
				}
			else
				{
		 		 antw_fout();
	 	 		 tellen();
				}
		}
	else
		{
		 alert("Je kan deze opgave maar\néén keer maken.");
		}	
	}
}

function antw_goed() {
document.opg.antw.value='Goed!';
	teller++;goed++;	
document.opg.goed.value='Aantal goed: '+goed;
}


function antw_fout() {
	document.opg.antw.value='Jouw antwoord was niet goed, het antwoord is  '+term1+term2; 
	teller++;fout++;
	document.opg.fout.value='Aantal fout: '+fout;
}

teller=0
goed=0
fout=0
function tellen() {
if (document.opg.antw.value=="") 
{teller=0;
goed=0;fout=0;
teller++;
}
document.opg.aantgem.value='Aantal gemaakte opgaven: '+ teller;
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
    newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

