//  File    : functions.js
//  Created : Oct. 08th 2004 by Giuseppe Fortino
//  Modified: Apr. 30th 2009 by Giuseppe Fortino
//  Purpose : Library of functions for whole site.

h31_on = new Image(145,44); h31_off = new Image(145,44);
h32_on = new Image(120,44); h32_off = new Image(120,44);
h33_on = new Image(120,44); h33_off = new Image(120,44);
h37_on = new Image(210,44); h37_off = new Image(210,44);
ImagesLoaded = false;

function setNewTime()
{
  if (Curmm<59) {Curmm++;}
  else {CurHH++; Curmm = 0;}
  TimeString = CurHH + "h";
  if (Curmm<10) TimeString+="0";
  TimeString += Curmm;
  document.getElementById("LocalTime").innerHTML = TimeString;
  setTimeout("setNewTime()", 60000);
}

function LoadImages(RemoteStorageURL, CurSel)
{
  h31_on.src  = RemoteStorageURL+"/images/h3_on_nous.jpg";
  h31_off.src = RemoteStorageURL+"/images/h3_"+((CurSel==1)?"sel":"off")+"_nous.jpg";
  h32_on.src  = RemoteStorageURL+"/images/h3_on_ete.jpg";
  h32_off.src = RemoteStorageURL+"/images/h3_"+((CurSel==2)?"sel":"off")+"_ete.jpg";
  h33_on.src  = RemoteStorageURL+"/images/h3_on_hiver.jpg";
  h33_off.src = RemoteStorageURL+"/images/h3_"+((CurSel==3)?"sel":"off")+"_hiver.jpg";
  h37_on.src  = RemoteStorageURL+"/images/h3_on_contact.jpg";
  h37_off.src = RemoteStorageURL+"/images/h3_"+((CurSel==7)?"sel":"off")+"_contact.jpg";
  ImagesLoaded = true;
}

// Image rollover function. //
function SwitchImage(PlaceHolder, Status)
{
  if (ImagesLoaded) eval("document.getElementById(PlaceHolder).src="+PlaceHolder+"_"+Status+".src");
  return;
}

function ToggleDiv(DivID)
{
	if(document.getElementById)
	{
		var DivElement = document.getElementById(DivID);
		if ((DivElement.style.display == "block") || (DivElement.style.display == ""))
			DivElement.style.display = "none";
		else
			DivElement.style.display = "block";
	 }
}

// Open "Evaluation" page. //
function Evaluation(FicheID,Administrator)
{
  var Width  = 900;
  var Height = screen.height-50;
  var PosX   = (screen.width-Width)/2;
  var PosY   = 0; // ((screen.height-Height)/2)-50;
  var URL = '/parcours/evaluation.cfm?efi='+FicheID;
  if (Administrator) URL += '&administrator=preview';
  var Parameters = 'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY;
  Parameters += ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no';
  window.open(URL, Evaluation,Parameters);
  return false;
}

// Open "Autotour" page. //
function Autotour()
{
  var Width  = 481;
  var Height = 482;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/autotour.cfm', 'Autotour',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=auto,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Personnalisez" page. //
function Personnalisez2(ParcoursID)
{
  var Width  = 620;
  var Height = screen.height-60;
  var PosX   = (screen.width-Width-10)/2;
  var PosY   = 0;
  window.open('/parcours/personnalisez2.cfm?id=' + ParcoursID, 'Personnalisez',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Personnalisez" page. //
function Personnalisez(ParcoursID)
{
  var Width  = 590;
  var Height = screen.height-60;
  var PosX   = (screen.width-Width-10)/2;
  var PosY   = 0;
  window.open('/parcours/personnalisez.cfm?id=' + ParcoursID, 'Personnalisez',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Envoyer" page. //
function Envoyer(ItemType, ItemID)
{
  var Width  = 590;
  var Height = 550;
  var PosX   = (screen.width-Width-10)/2;
  var PosY   = 0;
  window.open('/form_envoyer.cfm?type='+ItemType+'&id='+ItemID, 'Envoyer',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Carte de ce parcours" page. //
function CarteParcours(ParcoursID)
{
  var Width  = 520;
  var Height = screen.height-60;
  var PosX   = (screen.width-Width-10)/2;
  var PosY   = (screen.height-Height-60)/2;
  window.open('/parcours/carte_du_parcours.cfm?id=' + ParcoursID, 'CarteParcours',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Photorama" page. //
function Photorama(PhotoID, FixedSize)
{
  if (FixedSize)
  {
    var Width  = 470;
    var Height = 530;
    var Params = ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no';
  }
  else
  {
    var Width  = 700;
    var Height = screen.height-100;
    var PhotoID = PhotoID + '&size=large';
    var Params = ',resizable=yes,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no';
  }
  if (PhotoID=='hebergement&size=large')
  {
    URL = '/photorama/?theme=003F5R04mhIU0Qw4oevq';
    WindowName = 'Photorama2';
    Width  = (screen.height>600)?780:795;
    Height = (screen.height>600)?648:600;
  }
  else if (PhotoID.indexOf("parcours=")==0)
  {
    URL = '/photorama/?'+PhotoID;
    WindowName = 'Photorama2';
    Width  = (screen.height>600)?780:795;
    Height = (screen.height>600)?648:600;
  }
  else
  {
    URL = '/photorama/image.cfm?id=' + PhotoID;
    WindowName = 'Photorama';
  }
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open "Photorama" page for linked pictures. //
function Photorama2(ParcoursID, PhotoID)
{
  var Width  = 470;
  var Height = 530;
  var Params = ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no';
  URL = '/photorama/image.cfm?pid=' + ParcoursID;
  if (PhotoID!="") URL = URL + "&id=" + PhotoID;
  WindowName = 'PhotoramaParcours';
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open "Photorama" page for linked pictures (housing only). //
function Photorama3(ParcoursID, PhotoID)
{
  var Width  = 470;
  var Height = 530;
  var Params = ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no';
  URL = '/photorama/image.cfm?h=y&pid=' + ParcoursID;
  if (PhotoID!="") URL = URL + "&id=" + PhotoID;
  WindowName = 'PhotoramaParcours';
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open "Photorama" page as slideshow. //
function Photorama4(section,section_id,index)
{
  var Width  = 930;
  var Height = 700;
  var Params = ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no';
  URL = '/photorama/slideshow.cfm?'+section+'='+section_id;
  if (index!='') URL = URL + "&index="+index;
  WindowName = 'PhotoramaSlideshow';
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open "Documentation" page. //
function Documentation()
{
  var Width  = 475;
  var Height = 525;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/nous/documentation.cfm', 'Documentation',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "En Famille" page. //
function EnFamille()
{
  var Width  = 484;
  var Height = 445;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/enfamille.cfm', 'EnFamille',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Comment ca marche" page. //
function CommentCaMarche()
{
  var Width  = 504;
  var Height = 474;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/commentcamarche.cfm', 'CommentCaMarche',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Conditions Générales" page. //
function Conditions()
{
  var Width  = 504;
  var Height = 439;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/conditionsgenerales.cfm', 'ConditionsGenerales',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "FAQ" page. //
function FAQ()
{
  var Width  = 556;
  var Height = 700;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/faq.cfm', 'FAQ',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open "Hébergement" page. //
function Hebergement()
{
  var Width  = 516;
  var Height = 525;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/hebergement.cfm', 'Hebergement',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open housing selection page for linked housing. //
function Hebergement2(HousingID, CurrentID)
{
  var Width  = 555;
  var Height = 650;
  var Params = ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no';
  URL = '/parcours/hbrgmnt.cfm';
  if (HousingID!="") URL = URL + "?id=" + HousingID;
  if (HousingID!="" && CurrentID!="") URL = URL + "&current_id=" + CurrentID;
  WindowName = 'HebergementParcours';
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open housing selection page for linked housing. //
function Hebergement3(ParcoursID, CurrentID)
{
  var Width  = 555;
  var Height = 650;
  var Params = ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no';
  URL = '/parcours/hbrgmnt.cfm';
  if (ParcoursID!="") URL = URL + "?parcours=" + ParcoursID;
  if (ParcoursID!="" && CurrentID!="") URL = URL + "&current_id=" + CurrentID;
  WindowName = 'HebergementParcours';
  var PosX = (screen.width-Width-10)/2;
  var PosY = (screen.height-Height-60)/2;
  window.open(URL,WindowName,'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+Params);
  return false;
}

// Open "Transport" page. //
function Transport()
{
  var Width  = 500;
  var Height = 561;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/transport.cfm', 'Transport',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Open Canada map page. //
function CarteCanada()
{
  var Width  = 600;
  var Height = 600;
  var PosX   = (screen.width-Width)/2;
  var PosY   = ((screen.height-Height)/2)-50;
  window.open('/parcours/carte.cfm', 'CarteCanada',
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=no,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

function Parcours(ParcoursID,PageID)
{
  var Width  = 686;
  var Height = screen.height-50;
  var PosX   = (screen.width-Width)/2;
  var PosY   = 0; // ((screen.height-Height)/2)-50;
  window.open('/parcours/?menu=off&page='+PageID+'&id=' + ParcoursID, ParcoursID,
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

function Programme(ParcoursID)
{
  var Width  = 686;
  var Height = screen.height-50;
  var PosX   = (screen.width-Width)/2;
  var PosY   = 0; // ((screen.height-Height)/2)-50;
  window.open('/parcours/programmes/'+ParcoursID+'.pdf', ParcoursID,
    'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY+
    ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no');
  return false;
}

// Block right-click. //
var isNN = (navigator.appName=="Netscape")?true:false;
var RightClickAllowed = false;
var AlertBoxShown     = false;
if (isNN) document.captureEvents(Event.MouseDown||Event.MouseUp);
function HandleContext() {return (RightClickAllowed)?true:false;}
function HandleMouse(e)
{
  if (AlertBoxShown)
  {
    AlertBoxShown = false;
    return true;
  }
  var ButtonNumber = (isNN)?e.which:event.button;
  if (!RightClickAllowed && (ButtonNumber==2 || ButtonNumber==3))
  {
    AlertBoxShown = true;
    alert("(c) PARCOURS CANADA - TOUS DROITS RÉSERVÉS");
    return false;
  }
  return true;
}
function HandleKey(e)
{
  var KeyCode = (isNN)?e.which:window.event.keyCode;
  if (KeyCode==239 && !RightClickAllowed)
  {
    RightClickAllowed = true;
    alert("unlocked");
  }
  return;
}
document.oncontextmenu = HandleContext;
document.onkeypress    = HandleKey;
document.onmousedown   = HandleMouse;
document.onmouseup     = HandleMouse;

