//  File    : functions.js
//  Created : Oct. 08th 2004 by Giuseppe Fortino
//  Modified: Mar. 03rd 2011 by Giuseppe Fortino
//  Purpose : Library of functions for whole site.

h41_on = new Image( 46,21); h41_off = new Image( 46,21);
h42_on = new Image( 76,21); h42_off = new Image( 76,21);
h43_on = new Image( 59,21); h43_off = new Image( 59,21);
h44_on = new Image(161,21); h44_off = new Image(161,21);
lmp = new Image(11,11); lmm = new Image(11,11);

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 openDashboard(section,province)
{
  var Width  = 1175;
  var Height = 575;
  var PosX   = (screen.width-Width)/2;
  var PosY   = 0; // ((screen.height-Height)/2)-50;
  var Parameters = 'width='+Width+',height='+Height+',screenX='+PosX+',screenY='+PosY+',left='+PosX+',top='+PosY;
  var URL = '/tableaudebord.cfm?section='+section;
  if (province!=undefined) URL += '&province='+province;
  Parameters += ',resizable=no,scrollbars=yes,location=no,menubar=no,status=no,titlebar=no';
  window.open(URL,'Dashboard',Parameters);
  return false;
}

function setNewTime()
{
  if (Curmm<59) {Curmm++;}
  else {CurHH++; Curmm = 0;}
  if (CurHH<10) TimeString = "0" + CurHH + "h";
  else TimeString = CurHH + "h";
  if (Curmm<10) TimeString+="0";
  TimeString += Curmm;
  document.getElementById("LocalTime").innerHTML = 'Montréal '+TimeString;
  setTimeout("setNewTime()", 60000);
}

function LoadImages(RemoteStorageURL, CurSel)
{
  h41_on.src  = RemoteStorageURL+"/images/headerMenuEteRO.gif";
  h41_off.src = RemoteStorageURL+"/images/headerMenuEte.gif";
  h42_on.src  = RemoteStorageURL+"/images/headerMenuHiverRO.gif";
  h42_off.src = RemoteStorageURL+"/images/headerMenuHiver.gif";
  h43_on.src  = RemoteStorageURL+"/images/headerMenuFAQRO.gif";
  h43_off.src = RemoteStorageURL+"/images/headerMenuFAQ.gif";
  h44_on.src  = RemoteStorageURL+"/images/headerMenuQuiRO.gif";
  h44_off.src = RemoteStorageURL+"/images/headerMenuQui.gif";
  lmp.src = RemoteStorageURL+"/images/menuLeftPlus.gif";
  lmm.src = RemoteStorageURL+"/images/menuLeftMinus.gif";

  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;
}

var LastDM = 1;
function SwitchDetails(RemoteStorageURL, detail)
{
  eval("document.getElementById('DM"+LastDM+"').src='"+RemoteStorageURL+"/images/t4"+LastDM+"b.gif'");
  eval("document.getElementById('DM"+detail+"').src='"+RemoteStorageURL+"/images/t4"+detail+"o.gif'");
  eval("document.getElementById('DD"+LastDM+"').style.display='none'");
  eval("document.getElementById('DD"+detail+"').style.display='block'");
  LastDM = detail;
  return false;
}

// Image rollover function. //
function SwitchImage(PlaceHolder, Status)
{
  if (ImagesLoaded) eval("document.getElementById(PlaceHolder).src="+PlaceHolder+"_"+Status+".src");
  return;
}

var LastListShown = 'pp_ete_a';
function ShowList(DivID)
{
/*  SwitchImage(LastListShown,'off');*/
  ToggleDiv(LastListShown+'_liste');
  LastListShown = DivID;
/*  SwitchImage(LastListShown,'on');*/
  ToggleDiv(LastListShown+'_liste');
}

function ToggleMenu(MenuID)
{
  var openInd = document.getElementById('openInd'+MenuID);
  if (openInd.src==lmm.src) openInd.src=lmp.src;
  else                      openInd.src=lmm.src;
  ToggleDiv('Section'+MenuID);
  return false;
}

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";
  }
  return false;
}

// 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', 'P'+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 Itineraire(ItineraryID)
{
  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/itineraires/'+ItineraryID+'.pdf', 'I'+ItineraryID,
    '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 PopupCategories(RemoteStorageURL,eImage,eDiv)
{
  var catA = document.getElementById('PMA');
  var catC = document.getElementById('PMC');
  var catS = document.getElementById('PMS');
  var catV = document.getElementById('PMV');
  var catD = document.getElementById('PMD');
  var catM = document.getElementById('PMM');
  var catN = document.getElementById('PMN');
  var catO = document.getElementById('PMO');
  var catT = document.getElementById('PMT');
  var catH = document.getElementById('PMH');
  var divA = document.getElementById('ILA');
  var divC = document.getElementById('ILC');
  var divS = document.getElementById('ILS');
  var divV = document.getElementById('ILV');
  var divD = document.getElementById('ILD');
  var divM = document.getElementById('ILM');
  var divN = document.getElementById('ILN');
  var divO = document.getElementById('ILO');
  var divT = document.getElementById('ILT');
  var divH = document.getElementById('ILH');
  if (catA!=undefined) catA.src=RemoteStorageURL+"/images/t47p.gif";
  if (catC!=undefined) catC.src=RemoteStorageURL+"/images/t47p.gif";
  if (catS!=undefined) catS.src=RemoteStorageURL+"/images/t47p.gif";
  if (catV!=undefined) catV.src=RemoteStorageURL+"/images/t47p.gif";
  if (catD!=undefined) catD.src=RemoteStorageURL+"/images/t47p.gif";
  if (catM!=undefined) catM.src=RemoteStorageURL+"/images/t47p.gif";
  if (catN!=undefined) catN.src=RemoteStorageURL+"/images/t47p.gif";
  if (catO!=undefined) catO.src=RemoteStorageURL+"/images/t47p.gif";
  if (catT!=undefined) catT.src=RemoteStorageURL+"/images/t47p.gif";
  if (catH!=undefined) catH.src=RemoteStorageURL+"/images/t47p.gif";
  if (divA!=undefined) divA.style.display="none";
  if (divC!=undefined) divC.style.display="none";
  if (divS!=undefined) divS.style.display="none";
  if (divV!=undefined) divV.style.display="none";
  if (divD!=undefined) divD.style.display="none";
  if (divM!=undefined) divM.style.display="none";
  if (divN!=undefined) divN.style.display="none";
  if (divO!=undefined) divO.style.display="none";
  if (divT!=undefined) divT.style.display="none";
  if (divH!=undefined) divH.style.display="none";
  eImage.src=RemoteStorageURL+"/images/t47m.gif";
  eDiv.style.display="block";
  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;
*/

