<!--



function CaspocDisplayImage(plaat)
{
//var Pic2;
//plaat=this
var breedte=plaat.width;
var hoogte=plaat.height;
//alert("h="+hoogte+"w="+width);
Pic2 = "#define count_width  "+breedte+ "\n" +
      "#define count_height "+hoogte  + "\n" +
      "static char count_bits[] = {" + "\n"
for (i=0;i<hoogte;i++) {
  Pic2 = Pic2 + "\n";
  ex = 1;
  bite = 0;
  for (j=0;j<breedte;j++) {
    //pixel = (Math.sqrt(((i-48)*(i-48)+(j-48)*(j-48)))%7 < 4 )?1:0;
    pixel=0;
    pixel=plaat.imagearray[i*breedte+j];
    // rand om het figuur
    // if ((i ==  0) || (i == hoogte-1)) { pixel = 1;};
    // if ((j ==  0) || (j == breedte-1)) { pixel = 1;};
    bite = bite + (pixel * ex);
    ex = ex * 2;
    if ((j+1) % 8 == 0) {
      if ((i+j)>7) {
        Pic2 = Pic2 + ",";
      }
      Pic2 = Pic2 + "0x" + ((bite < 16)?"0":"") + bite.toString(16);
      ex = 1;
      bite = 0;
    }
  }
}
Pic2 = Pic2 + "};";
document.write ("<center><img height="+2*hoogte+" width="+2*breedte+" src=\"JavaScript:Pic2\"></center>\n");

}

function CaspocCreateImage(breedte,hoogte)
{
//var plaat = new Object();
this.imagearray=new Array(breedte*hoogte);
this.width=breedte;
this.height=hoogte;
for (i=0;i<hoogte;i++) 
  {
  for (j=0;j<breedte;j++) 
    {
    this.imagearray[i*breedte+j]=0;
//    if(i==j) 
  //    this.imagearray[i*breedte+j]=1;
    }
  }
return this;
}

function CaspocDrawPoint(plaat,x,y)
{
plaat.imagearray[x*plaat.width+y]=1;
}

function f1(tau,taurr,T1,didt,IRM)
{
return tau-tau*Math.exp(-T1/tau)-taurr+taurr*Math.exp(-T1/tau)-IRM/didt;
}

function fa(tau,taurr,T1)
{
return 1-Math.exp(-T1/tau)-tau*Math.exp(-T1/(tau*tau))+taurr*Math.exp(-T1/(tau*tau));
}

function pipo()
{
alert("pipo");
document.CalcRevRec.TM.value=1;

return 0;
}
function CaspocCalcRevRecPar()
{
var IF=0;
var IS=0;
var IRM=0;
var T0=0;
var T1=0;
var taurr=0;

var didt=0;
var tau=0;
var TM=0;
var i=0;

IF       = eval(document.CalcRevRec.IF.value);
IS       = eval(document.CalcRevRec.IS.value);
IRM       = eval(document.CalcRevRec.IRM.value);
T0       = eval(document.CalcRevRec.T0.value);
T1       = eval(document.CalcRevRec.T1.value);
taurr = eval(document.CalcRevRec.taurr.value);


didt=-IF/T0;
tau=T1;

for(i=0;i<100;i++)
  {
  tau=tau-f1(tau,taurr,T1,didt,IRM)/fa(tau,taurr,T1);
  }

TM=1/((1/taurr)-(1/tau));


    document.CalcRevRec.tau.value=tau*1e6;
    document.CalcRevRec.TM.value=TM*1e6;
    document.CalcRevRec.IS2.value=document.CalcRevRec.IS.value;
//    document.CalcRevRec.IRM.value=didt*(tau-taurr)*(1-Math.exp(-T1/tau));

document.CalcRevRec.Model.value=".model "+ document.CalcRevRec.ModelName.value +" user "+" tau="+document.CalcRevRec.tau.value*1e-6+" TM="+document.CalcRevRec.TM.value*1e-6+" IS="+document.CalcRevRec.IS.value+" N="+document.CalcRevRec.N.value+"   * end of model"

}



function CaspocCalcMosfetCap()
{
var Ciss=0;
var Coss=0;
var Crss=0;
var CGD=0;
var CGS=0;

Ciss      = eval(document.CalcMosfetPar.CISS.value);
Coss      = eval(document.CalcMosfetPar.COSS.value);
Crss      = eval(document.CalcMosfetPar.CRSS.value);



 document.CalcMosfetPar.CGD.value=Crss;
 document.CalcMosfetPar.CGS.value=Ciss-Crss;
 document.CalcMosfetPar.CDS.value=Coss-Crss;

document.CalcMosfetPar.Model.value=".model "+ document.CalcMosfetPar.ModelName.value +" user "
                                    +" VTO="+document.CalcMosfetPar.VTO.value
                                    +" KP ="+document.CalcMosfetPar.KP.value
                                    +" RD ="+document.CalcMosfetPar.RD.value*1e-3
                                    +" LD ="+document.CalcMosfetPar.LD.value*1e-9

                                    +" CGD="+document.CalcMosfetPar.CGD.value*1e-12
                                    +" CGS="+document.CalcMosfetPar.CGS.value*1e-12
                                    +" CDS="+document.CalcMosfetPar.CDS.value*1e-12
                                    +"   * end of model"

}


function CaspocCalcResFrequency(cCalcType)
{
var w=0;
var damping=0;
var R;
var L;
var C;

w       = eval(document.CalcResFreq.w.value);
f       = eval(document.CalcResFreq.f.value);
R       = eval(document.CalcResFreq.R.value);
L       = eval(document.CalcResFreq.L.value);
C       = eval(document.CalcResFreq.C.value);
damping = eval(document.CalcResFreq.d.value);

switch(cCalcType)
  {
  case 'fwd':
    w=1/Math.sqrt(L*C);
    document.CalcResFreq.w.value=w;
    document.CalcResFreq.f.value=w/(Math.PI*2);
    damping=Math.sqrt(L/C);
    damping=damping/(2*R);
    document.CalcResFreq.d.value=damping;
    break;
  case 'R':
    R=Math.sqrt(L/C);
    R=R/(2*damping);
    document.CalcResFreq.R.value=R;
    break;
  case 'L':
    // w=1/sqrt(L*C)   sqrt(L*C)=1/w     L*C=1/(w*w)   L=1/(C*w*w)
    L=1/(C*w*w);
    document.CalcResFreq.L.value=L;
    break;
  case 'C':
    // w=1/sqrt(L*C)   sqrt(L*C)=1/w     L*C=1/(w*w)   C=1/(L*w*w)
    C=1/(L*w*w);
    document.CalcResFreq.C.value=C;
    break;
  case 'f':
    document.CalcResFreq.f.value=w/(Math.PI*2);
    break;
  case 'w':
    document.CalcResFreq.w.value=f*(Math.PI*2);
    break;
  }
}



function CaspocCalcIGBTsnubberC()
{
var IC=0;
var VCE=0;
var TR=0;
var TF=0;
var R=0;
var C=0;
var TON=0;
var FS=0;
var D=0;

IC       = eval(document.IGBTsnubber.IC.value);
VCE      = eval(document.IGBTsnubber.VCE.value);
TR       = eval(document.IGBTsnubber.TR.value);
TF       = eval(document.IGBTsnubber.TF.value);
FS       = eval(document.IGBTsnubber.FS.value);
D        = eval(document.IGBTsnubber.D.value);


C=1000*IC*(TR+TF)/VCE;
document.IGBTsnubber.C.value=C;
TON=1000*D/FS;
document.IGBTsnubber.TON.value=TON;
R=TON/(3*C*0.001);
document.IGBTsnubber.R.value=R;//TO/(3*C);
document.IGBTsnubber.IDIS.value=VCE/R;
if((VCE/R)>IC*0.25)
  document.IGBTsnubber.RMIN.value=VCE/(IC*0.25);
else
  document.IGBTsnubber.RMIN.value="Resistor value is ok";

document.IGBTsnubber.PR.value=0.5*C*VCE*VCE*FS*1e-6;
}


function CaspocCalcMOSFETGateDriveImpedance()
{
var CISS=0;
var RGISS=0;
var RG=0;
var TR=0;
var TF=0;
//var DVDT=0

CISS       = eval(document.MOSFETGateDriveImpedance.CISS.value);
RGISS      = eval(document.MOSFETGateDriveImpedance.RGISS.value);
RG         = eval(document.MOSFETGateDriveImpedance.RG.value);
//FS         = eval(document.MOSFETGateDriveImpedance.FS.value);
//D          = eval(document.MOSFETGateDriveImpedance.D.value);
//DVDT       = eval(document.MOSFETGateDriveImpedance.DVDT.value);

TR=2.2*(RGISS+RG)*CISS/1000;
TF=TR;
document.MOSFETGateDriveImpedance.TR.value=TR;
document.MOSFETGateDriveImpedance.TF.value=TF;

//document.MOSFETGateDriveImpedance.IG.value=CISS*DVDT*0.001;

}



function CaspocCalcPushPullSnubber()
{
var LT=0;
var CJ=0;
var CS=0;
var RS=0;
var N=0;
var FS=0;
var VIN=0;

LT       = eval(document.PushPullSnubber.LT.value);
CJ       = eval(document.PushPullSnubber.CJ.value);
CS       = eval(document.PushPullSnubber.CS.value);
N        = eval(document.PushPullSnubber.N.value);
FS       = eval(document.PushPullSnubber.FS.value);
VIN      = eval(document.PushPullSnubber.VIN.value);


document.PushPullSnubber.RS.value=(1000/N)*Math.sqrt(LT/CJ);
document.PushPullSnubber.PR.value=(CS*1e-9*FS*1000/2)*(VIN/N)*(VIN/N)*1000;

}


function CaspocCalcThyristorSnubber()
{
var VLL=0;
var LC=0;
var TRR=0;
var ID=0;
var F=0;
var R=0;
var C=0;
var W=0;
var IRR=0;

VLL       = eval(document.ThyristorSnubber.VLL.value);
LC        = eval(document.ThyristorSnubber.LC.value)*1e-3;
TRR       = eval(document.ThyristorSnubber.TRR.value)*1e-6;
ID        = eval(document.ThyristorSnubber.ID.value);
F         = eval(document.ThyristorSnubber.F.value);

IRR=((Math.sqrt(6))*6.28*F*TRR*ID)/(0.1);
C=LC*(IRR/VLL)*(IRR/VLL);
R=20*VLL/ID;
W=3*C*VLL*VLL;
document.ThyristorSnubber.C.value=C*1e9;
document.ThyristorSnubber.R.value=R;
document.ThyristorSnubber.W.value=W*1000;

}

function CaspocCalcESR()
{
var IOUT=0;
var VOUT=0;
var FS=0;
var C=0;
var RESR=0;

IOUT       = eval(document.ESR.IOUT.value);
VOUT       = eval(document.ESR.VOUT.value);
FS         = eval(document.ESR.FS.value);

C=(IOUT/4)/(8*FS*1000*VOUT);
RESR=VOUT/(IOUT/4);

document.ESR.C.value=C*1e6;
document.ESR.RESR.value=RESR;

}


function CaspocCalcSimPar()
{
var FS=0;

FS         = eval(document.SimPar.FS.value)*1000;

document.SimPar.DT10.value=(1000000/FS)/10;
document.SimPar.DT20.value=(1000000/FS)/20;
document.SimPar.DT50.value=(1000000/FS)/50;
document.SimPar.DT100.value=(1000000/FS)/100;

document.SimPar.NDT10.value=(1000000000/FS)/10;
document.SimPar.NDT20.value=(1000000000/FS)/20;
document.SimPar.NDT50.value=(1000000000/FS)/50;
document.SimPar.NDT100.value=(1000000000/FS)/100;

}


function InitArray(n,init)
{
this.size=n;
for(i=1;i<=n;i++)
  {this[i]=init;}
return this;
}

function CaspocCalcHeatsink()
{
var B=0;
var H=0;
var D=0;
var R=0;
var C=0;
var MATERIAL=0;
var p=new InitArray(8,0);
var LAMBDA=new InitArray(8,0);
var c=new InitArray(8,0);

p[1]=2.4*1e6;  LAMBDA[1]=140;  c[1]=0.7;
p[2]=9*1e6;    LAMBDA[2]=60;   c[2]=0.2;
p[3]=8*1e6;    LAMBDA[3]=350;  c[3]=0.4;
p[4]=2.7*1e6;  LAMBDA[4]=220;  c[4]=0.95;
p[5]=3.8*1e6;  LAMBDA[5]=24;   c[5]=0.8;
               LAMBDA[6]=0.3;
               LAMBDA[7]=2;
               LAMBDA[8]=1.1;

B       = eval(document.Heatsink.B.value)*0.01;// all Dimensions in m
H       = eval(document.Heatsink.H.value)*0.01;
D       = eval(document.Heatsink.D.value)*0.001;
MATERIAL= eval(document.Heatsink.MATERIAL.value);

R=D/(LAMBDA[MATERIAL]*B*H);
C=c[MATERIAL]*p[MATERIAL]*B*H*D;

document.Heatsink.R.value=R;
document.Heatsink.C.value=C;
document.Heatsink.T.value=Math.PI*R*C/4;

document.Heatsink.V.value=B*100*H*100*D*100;
document.Heatsink.M.value=B*H*D*p[MATERIAL];
document.Heatsink.A.value=B*100*H*100;



}
function CaspocShowModelFile()
{
open(document.CalcResFreq.file.value,"model")
}

function CaspocShowModelFileRevRec()
{
open(document.CalcRevRec.file.value,"model")
}

function CaspocShowModelFileMosfetPar()
{
open(document.CalcMosfetPar.file.value,"model")
}


function CaspocDrawLine (plaat,x1,y1,x2,y2) {
  var x,y,e,temp;
  var dx = Math.abs(x1-x2);
  var dy = Math.abs(y1-y2);
  if ((dx >= dy && x1 > x2) || (dy > dx && y1 > y2)) {
    temp = x2;
    x2 = x1;
    x1 = temp;
    temp = y2;
    y2 = y1;
    y1 = temp;
  }
  if (dx >= dy) {
    e = (y2-y1)/((dx == 0) ? 1 : dx);
    for (x = x1, y = y1; x <= x2; x++, y += e)
      CaspocDrawPoint(plaat,x,Math.round(y));
  }
  else {
    e = (x2-x1)/dy;
    for (y = y1, x = x1; y <= y2; y++, x += e)
      CaspocDrawPoint(plaat,Math.round(x),y);
  }
}

function CaspocDrawRect (plaat,x1,y1,x2,y2) {
  CaspocDrawLine (plaat,x1,y1,x2,y1);
  CaspocDrawLine (plaat,x1,y1,x1,y2);
  CaspocDrawLine (plaat,x1,y2,x2,y2);
  CaspocDrawLine (plaat,x2,y1,x2,y2);
}

function CaspocDrawFilledRect (plaat,x1,y1,x2,y2) {
  var x,temp;
  if (x1 > x2) {
    temp = x2;
    x2 = x1;
    x1 = temp;
    temp = y2;
    y2 = y1;
    y1 = temp;
  }
  for (x = x1; x <= x2; x++)
    CaspocDrawLine(plaat,x,y1,x,y2);
}

function CaspocDrawCircle (plaat,x,y,radius) {
  for (var a=0, b=1; a < b; a++) {
    b = Math.round(Math.sqrt(Math.pow(radius,2)-Math.pow(a,2)));
    CaspocDrawPoint(plaat,x+a,y+b);
    CaspocDrawPoint(plaat,x+a,y-b);
    CaspocDrawPoint(plaat,x-a,y+b);
    CaspocDrawPoint(plaat,x-a,y-b);
    CaspocDrawPoint(plaat,x+b,y+a);
    CaspocDrawPoint(plaat,x+b,y-a);
    CaspocDrawPoint(plaat,x-b,y+a);
    CaspocDrawPoint(plaat,x-b,y-a);
  }
}

function CaspocDrawFilledCircle (plaat,x,y,radius) {
  for (var a=0, b=1; a < b; a++) {
    b = Math.round(Math.sqrt(Math.pow(radius,2)-Math.pow(a,2)));
    CaspocDrawLine(plaat,x+a,y+b,x+a,y-b);
    CaspocDrawLine(plaat,x-a,y+b,x-a,y-b);
    CaspocDrawLine(plaat,x+b,y+a,x+b,y-a);
    CaspocDrawLine(plaat,x-b,y+a,x-b,y-a);
  }
}

function CaspocSetMax(plaat,x,y)
{
plaat.xMax=x;
plaat.yMax=y;
}

function CaspocSetAxis(plaat,x,y)
{
plaat.xAxis=x;
plaat.yAxis=y;
}

function CaspocDrawVerAxis (plaat) 
{
x=(plaat.xAxis*plaat.width)/plaat.xMax;
CaspocDrawLine (plaat,0,x,plaat.height,x);
}

function CaspocDrawHorAxis(plaat) 
{
y=(plaat.yAxis*plaat.height)/plaat.yMax;
CaspocDrawLine (plaat,y,0,y,plaat.width);
}


function CaspocDrawPointReal(plaat,xR,yR)
{
//var q=0;
//alert(xR+","+yR);
//q=(plaat.width*xR)/plaat.xMax;
//alert(q);
x=Math.round((plaat.width*xR)/plaat.xMax);
y=Math.round(plaat.height-(plaat.height*yR)/plaat.yMax);
CaspocDrawPoint(plaat,y,x);
}

function CaspocDrawLineReal(plaat,xR1,yR1,xR2,yR2)
{
x1=Math.round((plaat.width*xR1)/plaat.xMax);
y1=Math.round(plaat.height-(plaat.height*yR1)/plaat.yMax);
x2=Math.round((plaat.width*xR2)/plaat.xMax);
y2=Math.round(plaat.height-(plaat.height*yR2)/plaat.yMax);
CaspocDrawLine(plaat,x1,y1,x2,y2);
}

var aNoteWin;

function HelpTags()
{
document.write('<HR>');
document.write('NOTE:Select the "Refresh" button on your browser to refresh the graph.<BR>');
document.write('<BR>');
document.write('<A name="HelpFile">The file is not created?</A><BR>');
document.write('<a href="#HelpFile" onmouseup="openHelpFile()">Help on file creation</A><BR>');
document.write('<BR>');
document.write('<a name="HelpDecimal">The decimal seperator is a comma instead of a dot?</A><BR>');
document.write('<a href="#HelpDecimal" onmouseup="openHelpDecimal()">Decimal seperator help</A><BR>');
document.write('<BR>');
document.write('<a href="#HelpDecimal" onmouseup="closeHelp()">Close help window</A>');
document.write('<BR><BR>');
document.write('<a href="http://www.caspoc.com/"><img src="lib/logoSR.gif" width="20%"></a><BR><small>&copy 2003 Simulation Research</small><BR>');

}



function openHelpDecimal()
{
aPopUp=window.open('','Note','toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=500, height=200');
ndoc=aPopUp.document;
astr='<HTML><HEAD><TITLE>Decimal seperator problems.</TITLE></HEAD><BODY>';
astr+='<B><I>Q</B></I><BR>';
astr+='The decimal seperator is a comma , instead of a dot . ?<BR>';
astr+='<B><I>A</B></I><BR>';
astr+='Change the default setting in windows by<BR>';
astr+='Select : [Settings] / [Control Panel] from the windows start menu<BR>';
astr+='Select the Icon : [Regional Settings]<BR>';
astr+='Select the Tab : [Numbers]<BR>';
astr+='Select [Decimal Symbol] Choose the dot [.]<BR>';
astr+='Select [OK]<BR>';
astr+='Close the Control Panel<BR>';
astr+='</BODY></HTML>  ';
ndoc.write(astr);
ndoc.close();
self.aNoteWin=aPopUp;
self.aNoteWin.focus();
}

function openHelpFile()
{
aPopUp=window.open('','Note','toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no, width=500, height=200');
ndoc=aPopUp.document;
astr='<HTML><HEAD><TITLE>File creation problems in Windows.</TITLE></HEAD><BODY>';
astr+='<B><I>Q</B></I><BR>';
astr+='There is no model file created?<BR>';
astr+='<B><I>A</B></I><BR>';
astr+='Change the security seting in windows for the intranet by<BR>';
astr+='In internet explorer select : [Tools] / [Internet Options]<BR>';
astr+='Select the Tab : [Security]<BR>';
astr+='Click [Local Intranet]<BR>';
astr+='Select [Security Level] [Low]<BR>';
astr+='Select [OK]<BR>';
astr+='</BODY></HTML>  ';
ndoc.write(astr);
ndoc.close();
self.aNoteWin=aPopUp;
self.aNoteWin.focus();
}

function closeHelp()
{
self.aNoteWin.close();
}


-->