﻿/*-------------------------------
	Copyright (c) 2004-2005 Eira inc.
	http://www.origano.com
-------------------------------*/
var enCours=false;
var oDate=new Date();
var tempsPrc=null;
var VitLum=299792458.0;
var DstMir=38440300;
var enMarche=false;
var horMaitre=null;
var xInitPhoton1=0;
var yInitPhoton1=0;
var xInitPhoton2=0;
var yInitPhoton2=0;
var	objMirH1=null;
var	objMirB1=null;
var	objPht1=null;
var	objMirH2=null;
var	objMirB2=null;
var	objPht2=null;
var objTicks1=null;
var objTicks2=null;
var	objLstDist=null;
var	objLstVit1=null;
var	objLstVit2=null;
var	objEdtDist=null;
var	objEdtVit1=null;
var	objEdtVit2=null;
var param=null;
var horF=null;
var hor1=null;
var hor2=null;
var msParTick=1;
var oFen=null;
var verifier=true;
function objSimSvlDeb(){
with(document.getElementById("dvObjetSim").style){color="#cc6633";cursor=(xHote.navIE599ea?'hand':'pointer');}
}
function objSimSvlFin(){
with(document.getElementById("dvObjetSim").style){color="#999999";cursor='default';}
}
function objSimClk(){
verifier=false;
oFen=window.open("objSim_"+xm.nom+".htm",null,"top=100,left=100,height=428,width=465,status=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
oFen.focus();
}
function _AfficherNouvellePosition(){
var xMir=0;
if(!enMarche)return;
with(this){
phoSty.left=xPho+'px';
xMir=xPho-29;
phoSty.top=yPho+'px';
if(verifier && yPho>500){
horlogeDepartArret();
if(xm.nom=='f')
alert("Cet ordinateur n'est pas assez rapide pour soutenir "+
"la simulation en cours :\n\n"+
"Veuillez augmenter la distance séparant les "+
"deux miroirs !\n\n"+
"À titre indicatif, une distance minimale de 6 500 000 m "+
"est nécessaire pour un ordinateur de 1,6 gHz et ce, dans des "+
"conditions optimales. Toute activité d'une autre application "+
"en cours d'exécution ou même déplacer la souris "+
"peut stopper la simulation.\n\n"+
"Sur un ordinateur plus lent, cette distance minimale devra d'autant "+
"plus être élevée !");
else
alert("This computer is not fast enough to sustain the actual simulation:\n\n"+
"Please increase the distance between mirrors!\n\n"+
"As a guideline, a minimal distance of 6,500,000 meters is necessary "+
"for a 1.6 gHz machine. And this is under optimal conditions : any concurrent "+
"activity from another application or just moving the mouse can stop "+
"the simulation.\n\n"+
"On a slower computer, such distance should be increased accordingly!");
return;
}
if(xMir<xDeb){
xMir=xDeb;
}
else if((xMir+mirLrg)>xFin){xMir=xFin-mirLrg;}
else{
}
document.getElementById("imMirH"+numero).style.left=xMir+'px';
document.getElementById("imMirB"+numero).style.left=xMir+'px';
}
}
function tickSurvenu(){
if(enCours)return;
enCours=true;
var d=new Date();
var tempsAct=d.getTime();
var msDepuisDernierTick=tempsAct-tempsPrc;
var ecart=0;
tempsPrc=tempsAct;
with(hor1){
depH=((coteAB*2*msDepuisDernierTick/1000)/nbrSecTic)*yDlt/DstMir;
depV=((DstMir*msDepuisDernierTick/1000)/(nbrSecTic/2))*yDlt/DstMir;
if(dirH==1){
xPho+=depH;
if((xPho+phoDim)>xFin){dirH=-1;ecart=xPho-xFin+phoDim-1;xPho-=ecart*2;}
}
else if(dirH==-1){
xPho-=depH;
if(xPho<xDeb){dirH=1;xPho=xDeb+(xDeb-xPho);}
}
else{
}
if(dirV==1){
yPho+=depV;
if((yPho+phoDim)>yFin){
dirV=-1;
nbrTicks++;
objTicks1.innerHTML=nbrTicks;
ecart=yPho-yFin+phoDim-1;
yPho-=ecart*2;
}
}
else if(dirV==-1){
yPho-=depV;
if(yPho<yDeb){dirV=1;yPho=yDeb+(yDeb-yPho);}
}
else{
}

afficherNouvellePosition();
}
with(hor2){
depH=((coteAB*2*msDepuisDernierTick/1000)/nbrSecTic)*yDlt/DstMir;
depV=((DstMir*msDepuisDernierTick/1000)/(nbrSecTic/2))*yDlt/DstMir;

if(dirH==1){
xPho+=depH;
if((xPho+phoDim)>xFin){dirH=-1;ecart=xPho-xFin+phoDim-1;xPho-=ecart*2;}
}
else if(dirH==-1){
xPho-=depH;
if(xPho<xDeb){dirH=1;xPho=xDeb+(xDeb-xPho);}
}
else{
}
if(dirV==1){
yPho+=depV;
if((yPho+phoDim)>yFin){
dirV=-1;
nbrTicks++;
objTicks2.innerHTML=nbrTicks;
ecart=yPho-yFin+phoDim-1;
yPho-=ecart*2;
}
}
else if(dirV==-1){
yPho-=depV;
if(yPho<yDeb){dirV=1;yPho=yDeb+(yDeb-yPho);}
}
else{
}
afficherNouvellePosition();
}

enCours=false;
}
function paramSimulation(dstMir,vit1,vit2){
this.dstMir=dstMir;
this.vit1=vit1;
this.vit2=vit2;
}
function chnFormatteeDe(nbr,sep){
var vct=new Array('0'),i=0;
while(nbr>0){vct[i]=''+nbr%1000;nbr=Math.floor(nbr/1000);i++;}
vct=vct.reverse();
for(var i in vct)
if(i>0)	while(vct[i].length<3)vct[i]='0'+vct[i];
return vct.join(sep);
}
function nombreEntierEpureDe(chn){
var nbrCars=chn.length;
var nouvNbr="";
var car="";
for(var i=0;i<nbrCars;i++){
car=chn.charCodeAt(i);
if(car>47 && car<58){
nouvNbr+=chn.substr(i,1);
}
}
return (isNaN(parseInt(nouvNbr,10))?0:parseInt(nouvNbr,10));
}
function edtDistEnModif(){objLstDist.selectedIndex=0;}
function edtDistModifie(){
objLstDist.selectedIndex=0;
param.dstMir=nombreEntierEpureDe(objEdtDist.value);
objEdtDist.value=chnFormatteeDe(param.dstMir,(xm.nom=="f")?" ":",");
}
function lstDistModifiee(){
var ndx=objLstDist.selectedIndex;
param.dstMir=parseInt(objLstDist.options[ndx].value,10);
objEdtDist.value=chnFormatteeDe(param.dstMir,(xm.nom=="f")?" ":",");
if(ndx==0){objEdtDist.focus();objEdtDist.select();}
}
function edtVit1EnModif(){objLstVit1.selectedIndex=0;}
function edtVit1Modifie(){
objLstVit1.selectedIndex=0;
param.vit1=nombreEntierEpureDe(objEdtVit1.value);
objEdtVit1.value=chnFormatteeDe(param.vit1,(xm.nom=="f")?" ":",");
}
function lstVit1Modifiee(){
var ndx=objLstVit1.selectedIndex;
param.vit1=parseInt(objLstVit1.options[ndx].value,10);
objEdtVit1.value=chnFormatteeDe(param.vit1,(xm.nom=="f")?" ":",");
if(ndx==0){objEdtVit1.focus();objEdtVit1.select();}
}
function edtVit2EnModif(){objLstVit2.selectedIndex=0;}
function edtVit2Modifie(){
objLstVit2.selectedIndex=0;
param.vit2=nombreEntierEpureDe(objEdtVit2.value);
objEdtVit2.value=chnFormatteeDe(param.vit2,(xm.nom=="f")?" ":",");
}
function lstVit2Modifiee(){
var ndx=objLstVit2.selectedIndex;
param.vit2=parseInt(objLstVit2.options[ndx].value,10);
objEdtVit2.value=chnFormatteeDe(param.vit2,(xm.nom=="f")?" ":",");
if(ndx==0){
objEdtVit2.focus();
objEdtVit2.select();
}
}
function saisieOK(){
var fr=(xm.nom=='f');
var msg="";
if(param.dstMir<1){
msg=fr?"Distance erronée.\n\nEntrez une valeur supérieure à zéro (et préférablement supérieure à 6 000 000 mètres) !":
"Erroneous distance\n\nPlease enter a value greater than zero (and preferably superior to 6,000,000 meters)!";
alert(msg);
objEdtDist.focus();
objEdtDist.select();
return false;
}
if(param.vit1<0){
msg=fr?"Vitesse de l'horloge 1 erronée.\n\nEntrez zéro ou un nombre positif !":
"Erroneous speed for clock 1\n\nPlease enter zero or a positive number!";
alert(msg);
objEdtVit1.focus();
objEdtVit1.select();
return false;
}
if(param.vit2<0){
msg=fr?"Vitesse de l'horloge 2 erronée.\n\nEntrez zéro ou un nombre positif !":
"Erroneous speed for clock 2\n\nPlease enter zero or a positive number!";
alert(msg);
objEdtVit2.focus();
objEdtVit2.select();
return false;
}
return true;
}
function resetPositions(){
objMirH1.style.left="95px";
objMirH1.style.top="11px";
objMirB1.style.left="95px";
objMirB1.style.top="89px";
objPht1.style.left="124px";
objPht1.style.top="85px";
objMirH2.style.left="95px";
objMirH2.style.top="109px";
objMirB2.style.left="95px";
objMirB2.style.top="187px";
objPht2.style.left="124px";
objPht2.style.top="183px";
xInitPhoton1=parseInt(objPht1.style.left);
yInitPhoton1=parseInt(objPht1.style.top);
xInitPhoton2=parseInt(objPht2.style.left);
yInitPhoton2=parseInt(objPht2.style.top);
}
function horlogeDepartArret(){
if(enMarche){
if(horMaitre!=null){
window.clearInterval(horMaitre);
horMaitre=null;
}
enMarche=false;
hor1.rendreInvisible();
hor2.rendreInvisible();
if(xm.nom=='f')
document.getElementById("btnDepartArret").value="Démarrer";
else
document.getElementById("btnDepartArret").value="Start";
resetPositions();
document.getElementById("dvAideVisDst").style.visibility='visible';
document.getElementById("dvAideVisVit").style.visibility='visible';
}
else{
if(saisieOK()){
DstMir=param.dstMir;
delete hor1;
delete hor2;
objTicks1.innerHTML="0";
objTicks2.innerHTML="0";
document.getElementById("dvAideVisDst").style.visibility='hidden';
document.getElementById("dvAideVisVit").style.visibility='hidden';
resetPositions();
hor1=new horlogePhotonique(1,param.vit1);
hor2=new horlogePhotonique(2,param.vit2);
hor1.rendreVisible();
hor2.rendreVisible();
if(xm.nom=='f')
document.getElementById("btnDepartArret").value="Arrêter";
else
document.getElementById("btnDepartArret").value="Stop";
enMarche=true;
oDate=new Date();
tempsPrc=oDate.getTime();
horMaitre=window.setInterval("tickSurvenu()",msParTick);
}
}
}
function _RendreVisible(){this.phoSty.display='block';}
function _RendreInvisible(){this.phoSty.display='none';}
function horlogePhotonique(numHor,vitHor){
var airSty=null;
this.numero=numHor;
if(numHor==1 && vitHor==299792458)debugger;
if(this.numero==1||this.numero==2){
this.phoSty=document.getElementById("imPht"+this.numero).style;
this.phoDim=parseInt(this.phoSty.width);
this.mirLrg=parseInt(document.getElementById("imMirH1").style.width);
this.phoSty.display='none';
airSty=document.getElementById("dvAire"+this.numero).style;
this.xDeb=parseInt(airSty.left);
this.xFin=this.xDeb+parseInt(airSty.width)-1;
this.yDeb=parseInt(airSty.top);
this.yFin=this.yDeb+parseInt(airSty.height)-1;
this.yDlt=this.yFin-this.yDeb+1;
this.xPho=(this.numero==1?xInitPhoton1:xInitPhoton2);
this.yPho=(this.numero==1?yInitPhoton1:yInitPhoton2);
this.dirH=1;
this.dirV=-1;
this.nbrTicks=0;
}
this.vitesse=vitHor;
this.nbrSecTic=(DstMir*2/VitLum)/Math.sqrt(1-(Math.pow(this.vitesse,2)/Math.pow(VitLum,2)));
this.hypotenuse=this.nbrSecTic/2*VitLum;
if(DstMir>this.hypotenuse)
this.coteAB=0;
else
this.coteAB=Math.sqrt(Math.pow(this.hypotenuse,2)-Math.pow(DstMir,2));
this.rapportMirSurHyp=DstMir/this.hypotenuse;
if(this.rapportMirSurHyp<-1)this.rapportMirSurHyp=-1;
if(this.rapportMirSurHyp>1)this.rapportMirSurHyp=1;
this.angleRad=Math.asin(this.rapportMirSurHyp);
this.angleDeg=this.angleRad*180/Math.PI;
this.depH=0;
this.depV=0;
this.rendreVisible=_RendreVisible;
this.rendreInvisible=_RendreInvisible;
this.afficherNouvellePosition=_AfficherNouvellePosition;
}
function horlogesInit(){
objMirH1=document.getElementById("imMirH1");
objMirB1=document.getElementById("imMirB1");
objPht1=document.getElementById("imPht1");
objMirH2=document.getElementById("imMirH2");
objMirB2=document.getElementById("imMirB2");
objPht2=document.getElementById("imPht2");
objTicks1=document.getElementById("divTicks1");
objTicks2=document.getElementById("divTicks2");
objEdtDist=document.getElementById("edtDstMir");
objLstDist=document.getElementById("lstDst");
objEdtVit1=document.getElementById("edtVitHor1");
objLstVit1=document.getElementById("lstVit1");
objEdtVit2=document.getElementById("edtVitHor2");
objLstVit2=document.getElementById("lstVit2");
resetPositions();
horF=new horlogePhotonique(0,0);
hor1=new horlogePhotonique(1,83);
hor2=new horlogePhotonique(2,224844344);
param=new paramSimulation(38440300,83,224844344);

document.getElementById("dvObjetSim").href="#";

if(xHote.navOpera){
if(xm.nom=='f')
alert("Message n'apparaissant qu'aux utilisateurs d'Opera :\n\n"+
"Un bogue propre à ce navigateur fait en sorte que les trois listes "+
"déroulantes affichées au bas de la fenêtre ne réagissent pas si "+
"l'icône à leur extrémité droite est cliquée!\n\n"+
"Cliquez sur le milieu d'une liste ou un peu à plus à gauche "+
"pour qu'elle réagisse...!");
else
alert("This message appears only for Opera users:\n\n"+
"A bug proper to this navigator makes the 3 drop-down lists "+
"shown at the bottom of the window to not react when their icon "+
"at right is clicked!\n\n"+
"Just click in the middle or on the left of these drop-down lists "+
"to make them react...!");
}
}

