//This script is subject to copyright law.
//This script may not be copied or used in any way without permission
//from mhSoft, Amsterdam (The Netherlands).
//
//Copyright 1999 mhSoft
monate = new Array(12);
monate[0] = 'jan.';
monate[1] = 'feb.';
monate[2] = 'mrt.';
monate[3] = 'apr.';
monate[4] = 'mei';
monate[5] = 'jun.';
monate[6] = 'jul.';
monate[7] = 'aug.';
monate[8] = 'sep.';
monate[9] = 'okt.';
monate[10] = 'nov.';
monate[11] = 'dec.';

tage = new Array(7);
tage[0] = 'zondag';
tage[1] = 'maandag';
tage[2] = 'dinsdag';
tage[3] = 'woensdag';
tage[4] = 'donderdag';
tage[5] = 'vrijdag';
tage[6] = 'zaterdag';

function machDatum(datum)
{
	var tag = tage[datum.getDay()];
	var monat = monate[datum.getMonth()];
	var jahr = datum.getYear() + 1900;
	var datumstring = tag + ' ' +datum.getDate() +' ' +monat + ' ' +jahr;
	return datumstring;
}
 
function zeit(datum)
{
	var stunde = datum.getHours();
	var minute = datum.getMinutes();
	if (stunde < 10) stunde = '0' + stunde;
	if (minute < 10) minute = '0' + minute;
	zeitstring = stunde +':' +minute;
	return zeitstring;
}



//berechne frequenzkurve
//
function direktfreqcurve()
{
	if((eval(document.b4box.vb.value.length) == 0 ) ||
	(eval(document.b4box.fb.value.length) == 0 ) ||
      (eval(document.b4box.qts.value.length) == 0 ) || 
      (eval(document.b4box.fs.value.length) == 0 ) || 
      (eval(document.b4box.vas.value.length) == 0 ) ||
      (eval(document.b4box.ql.value.length) == 0 )) { alert("een van de velden is niet ingevuld...");
 }
else

	{
		fvb = eval(document.b4box.vb.value);
		ffb = (eval(document.b4box.fb.value));
		fqts = (eval(document.b4box.qts.value));
 		ffs = (eval(document.b4box.fs.value));
 		fvas = (eval(document.b4box.vas.value));
 		fql = (eval(document.b4box.ql.value));
		start = 10;
		stop = 205; 
 		stap = 5;

	a = (ffb / ffs) * (ffb / ffs);
	b = (a / fqts) + (ffb / (fql * ffs));
	c = 1 + a +(ffb / (fql * (ffs * fqts))) + (fvas / fvb)
	d = (1 / fqts) + (ffb / (fql * ffs));

	datum = new Date();
	

	breite = screen.width;
	hoehe  = screen.height;	
	xpos = ((breite - 770)/2);
	ypos = ((hoehe - 380)/2);
			
Para = 'WIDTH=770,HEIGHT=420,screenX='+xpos+',screenY='+ypos+',status=no,toolbar=no,menubar=no,scrollbars=yes';

	myWin=open('','newWindow',Para);
	myWin.document.open();
	//dokument erstellen
	myWin.document.write('<html><head><title>Frequency Response</title></head>');
	myWin.document.write('<body bgcolor="#FFFFFF" text="#000000" background="gif/BackGroundDriver.gif">');
	myWin.document.write('<br><center><font size=+3><b>Frequency Response  ');
 	myWin.document.write(start +' Hz .. '+ stop +' Hz / '+ stap +' Hz</b></font><br>');
	myWin.document.write('Datum : '+machDatum(new Date()));
	myWin.document.write(',   '+zeit(datum)+' uur.<br><P>');
	myWin.document.write('Vas: '+fvas+' ,  fs: '+ffs+' ,  Qts: '+fqts);
	myWin.document.write(' fb: '+ffb+' ,  Vb: '+fvb+' ,  Ql: '+fql);
	myWin.document.write('<center>');
	myWin.document.write('<table border=1 width=95% cellspacing=0 cellpadding=2>');
	myWin.document.write('<tr>');

	i = 1;
	for (var zaehler=start/stap; zaehler <=stop/stap; zaehler++) 
	{
		ffs2=ffs;
		w = zaehler*stap / ffs2; 
		u = w * w;
		x = u * u;
		e = x / Math.sqrt((x - c * u + a) * (x - c * u + a) + (b * w - d * u * w) * (b * w - d 		* u *	w));
		e = 20 * Math.log(e)/Math.LN10;
		freq = zaehler*stap;
		//convert num to string
		freq = freq.toString();
		freq = freq.substring(0,5);
		tekst = e;
		tekst = tekst.toString();
		tekst = tekst.substring(0,5);
		e = tekst;
		myWin.document.write('<td>f: '+ freq +' Hz, '+ e +' dB </td>');

		if ((i % 5) == 0) myWin.document.write('</tr><tr>');
		i = i + 1;
	}

	myWin.document.write('</tr></table>');
	myWin.document.write('<table border="0"><tr><td>');
	myWin.document.write('<center><form><input type="button" Value=">> print <<" 	onClick="self.print()"></form></center>');
	myWin.document.write('</td><td>');
	myWin.document.write('<center><form><input type="button" Value=">> close <<" 	onClick="self.close()"></form></center>');
	myWin.document.write('</td></tr></table>');
	myWin.document.close();
}
}

