// Database Variables
pixelWidth =new Array(20,20,26,13,24,26,26,26,50,25,25);
chiplength=new Array(26.8,26.8,26.6,27.6,24.6,18,18,25,25.6,25.6);
horPixel=new Array(1340,1340,1024,2048,1024,1024,1024,1024,512,1024);
vertPixel=new Array(100,400,256,512,252,256,256,256,1,1);
res = new Array(3,3,3,3,3.6,3.6,3.1,3.6,3,3);
focal=new Array(500,1500,750,1750,750,2250,750,1000,350,275);
ebert=new Array(9,9,9,7,7,7,10,7,21,10);
mode= new Array(1,0,1,0,1,0,1,0,1);
gratingsize=new Array("68 x 84","68 x 84","68 x 68","68 x 68","68 x 68","68 x 68","68 x 68","68 x 68","68 x 68")
gratinglines1=new Array(50,75,150,300,600,750,900,1000,1100,1200,1500,1800,2000,2400,3600)
gratinglines2=new Array(50,75,150,300,600,750,900,1000,1100,1200,1500,1800,2000,2400,3600)
Slit=new Array(1,2,4,8,12)
data=0;

function swCamera() {
data=document.forms[0].Camera.selectedIndex;
document.forms[0].ccdPixelWidth.value  =pixelWidth[data];
document.forms[0].Chiplength.value  = chiplength[data];
document.forms[0].horPixel.value  = horPixel[data];
document.forms[0].vertPixel.value  = vertPixel[data];
document.forms[0].factor.value  = res[data];
calculateFocalLength();
}

function swMono() {
data=document.forms[0].Mono.selectedIndex;
document.forms[0].focallenght.value  = focal[data];
document.forms[0].ebert.value = ebert[data];
document.forms[0].mode.value = mode[data];
calculateFocalLength();}

function swGrating1() {
data=document.forms[0].Grating1.selectedIndex;
document.forms[0].gratinglines1.value = gratinglines1[data];
calculateFocalLength();}

function swGrating3() {
data=document.forms[0].Grating3.selectedIndex;
document.forms[0].gratinglines2.value = gratinglines2[data];
calculateFocalLength();}

function swSlit() {
data=document.forms[0].Slit.selectedIndex;
document.forms[0].Slitsize.value = Slit[data];
calculateFocalLength();}


function calculateFocalLength() 
{

//    Camera Data
wE = document.forms[0].ebert.value;
pW = document.forms[0].ccdPixelWidth.value;
cL = document.forms[0].Chiplength.value;
//    Mono Data
fL = document.forms[0].focallenght.value;
rS = document.forms[0].factor.value; 
gL1 = document.forms[0].gratinglines1.value;
gL3 = "Grating 1 " + document.forms[0].gratinglines2.value +"g/mm";
// NEU Mode Select (Add = 1 Sub = 0) und Mono Select index
mD  = document.forms[0].mode.value; 
sel  = document.forms[0].Mono.selectedIndex;

//    Grating Data
// Central Wavelength
cW = document.forms[0].centerwavelength.value;


A8 = (cW/1000*gL1/2000)/Math.cos(wE*2/180*Math.PI);

C8 = Math.cos(wE*2/180*Math.PI); 
E8 = Math.asin(A8)*180/Math.PI;
     document.forms[0].E8.value = Math.round(E8*100)/100; 
D8 = Math.tan(Math.asin(A8)*180/Math.PI*Math.PI/180); 
F8 = (cW)/(2*fL*(D8));
F9 = 10000000*(1/(cW-F8)-(1/cW));


//    START NEU RS
//    Bp = BandPass Factor
//    EffectiveCL = Effective CCD Illumination


gL2 = document.forms[0].gratinglines2.value;

// Width of Intermediate Slit
SlitData = 12; // default
SlitData = document.forms[0].Slitsize.value;

// for additive or subtractive mode 
if (mD  ==0){Bp = 2};
if (mD  ==1){Bp = 1};

// special for for TR 557 
if (sel  ==2){Bp = Bp*1.5};
if (sel  ==3){Bp = Bp*1.5};


// Bp as f(Groove Density in 3rd Stage divided by Groove Density in Double)
Bp = Bp*gL1/gL2;


EffectiveCL = SlitData*Bp;

// if width of illumination > CCD width
// set as a comment to show the full width of illuminations for test !!!!!!!!!!!!!!!!!!!!!!!!!!!!
// if (EffectiveCL >= cL){EffectiveCL = cL};

//    END NEU RS


document.forms[0].F8.value = Math.round(F8*100)/100 +" nm/mm";
document.forms[0].F9.value = Math.round(F9*100)/100 +" cm-1/mm";


//    START NEU RS
document.forms[0].Coverage.value = Math.round(F8 * ((EffectiveCL)/1)/1)+"nm/"+Math.round(((EffectiveCL)/1)/1)+"mm";
document.forms[0].WCoverage.value = Math.round(F9 * ((EffectiveCL)/1)/1)+" cm-1";
document.forms[0].CCDCoverage.value ="<-   "+((Math.round(EffectiveCL*100)/100)/1)+"   mm ->";
document.flashfile1.GotoFrame((Math.round(EffectiveCL)/1)/1);

//    END NEU RS



BWPixel = ((F8/1000)*pW);
WBWPixel = ((F9/1000)*pW);
document.forms[0].Resolution.value = Math.round(BWPixel*1000)/1000 +" nm";
document.forms[0].WResolution.value = Math.round(WBWPixel*100)/100 +" cm-1";
document.forms[0].ccdResolution.value = Math.round(BWPixel *rS*1000)/1000 +" nm";
document.forms[0].WccdResolution.value = Math.round(WBWPixel *rS*100)/100 +" cm-1";


document.forms[0].slitResolution.value = Math.round((F8/1000)*25000)/1000 +" nm";
F10 = F9 * 0.025;
document.forms[0].WslitResolution.value = Math.round(F10 * 100)/100 +" cm-1";

// Show configuration FLASH Image
if (sel  ==0){document.flashfile.GotoFrame(1)};
if (sel  ==1){document.flashfile.GotoFrame(2)};
if (sel  ==2){document.flashfile.GotoFrame(3)};
if (sel  ==3){document.flashfile.GotoFrame(4)};
if (sel  ==4){document.flashfile.GotoFrame(5)};
if (sel  ==5){document.flashfile.GotoFrame(6)};
if (sel  ==6){document.flashfile.GotoFrame(7)};

{ document.forms[0].Meldung.value = gL1} ;
}

function setupPage() {
calculateFocalLength();
}


