//Copyright (C) ParadiVision Inc.
//  http://www.paradivision.com

var strBaseURL = 'http://www.gohfs.org/fr/';
var strSecureURL = 'http://www.gohfs.org/fr/';

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;		
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 

menus = new makeArrayImplicit("Menu1");
menus[1] = new makeArrayImplicit("regularfood_menu","specialdiets_menu","services_menu","aboutus_menu");
menus[2] = new makeArrayImplicit("152","152","152","152");  //width
menus[3] = new makeArrayImplicit("152","304","456","608");  //left position
menus[4] = new makeArrayImplicit("bt_regular_foods_nr.gif","bt_special_diets_nr.gif","bt_services_nr.gif","bt_abousus_nr.gif");  //picture normal
menus[5] = new makeArrayImplicit("bt_regular_foods_hg.gif","bt_special_diets_hg.gif","bt_services_hg.gif","bt_aboutus_hg.gif");  //picture rollover

homephotos = new makeArrayImplicit("../Images/cover_photo_wtext.jpg","../Images/cover_expertise.jpg","../Images/cover_chef.jpg");
var homeCurrentPic = 0;
var homePicDelay = 15;

var lngWebPageID = 0;
var lngCurentCatalogueID=0;
var lngChildCatalogueID=0;

function isValidNumeric(x) {  return isNaN(parseFloat(x)) ? false: true;}

function BrowserInfo() { 
  var agent = navigator.userAgent.toLowerCase(); 
  this.major = parseInt(navigator.appVersion); 
  this.minor = parseFloat(navigator.appVersion); 
  this.op = (agent.indexOf("opera")!= -1); 
} 

function makeArrayImplicit() {
   var Count;
   this.length=makeArrayImplicit.arguments.length;
   for (Count=1;Count<makeArrayImplicit.arguments.length+1;Count++)
      this[Count]=makeArrayImplicit.arguments[Count-1];
   return(this);
}

function GetPageOffset(PageWidth) {
  //Some Browser Detection 
  var is = new BrowserInfo(); 
  //Determine the Available Width on the page 
  var fWidth; 

  //For old IE browsers 
  if(document.all)
    fWidth = document.body.clientWidth; 
  //For DOM1 browsers 
  else if(document.getElementById &&!document.all) 
//     fWidth = innerWidth; 
     fWidth = PageWidth;
  else if(document.getElementById) 
     fWidth = PageWidth; 
//    fWidth = innerWidth; 
  //For Opera 
  else if (is.op) 
     fWidth = PageWidth; 
//    fWidth = innerWidth; 
  //For old Netscape 
  else if (document.layers) 
    fWidth = window.innerWidth; 

  var layerleft; 
  layerleft = (fWidth - PageWidth) / 2;
//  alert(layerleft);
  return(layerleft > 0 ? layerleft : 0);
}

function changestyle(obj, classname)
{  
   obj.className=classname;
}

function toggleMenu(intMenuNo,visible) 
{
//   alert(document.getElementById(menus[1][intMenuNo])));
   var currElem = menus[1][intMenuNo];
//   menuObj = (document.all) ? eval("document.all" + currElem + ".style") : eval("document." + currElem + ".style");
//   menuObj = eval("document.all" + currElem + ".style");
   menuObj = document.getElementById(currElem).style;
   if (visible)
      {
         //alert('Hello');
         var left = GetPageOffset(760) + parseInt(menus[3][intMenuNo]) + 'px';  
         menuObj.left = left;
         menuObj.top=90;
         //menuObj.top=114;
         menuObj.visibility='';
      }
   else
         menuObj.visibility='hidden';
//   alert(currElem + ' = ' + menuObj.visibility);
}

function WriteTopMenu(intMenuNo) {
   var intI;
   var intMenuWidth;

   intMenuWidth = parseInt(menus[2][intMenuNo]);
//   alert(menus[1][intMenuNo]);
   document.write('<div id="' + menus[1][intMenuNo] + '" style="visibility:hidden;" class=menu onMouseover="toggleMenu(' + intMenuNo + ',true)" onMouseout="toggleMenu(' + intMenuNo + ',false)">');

   document.write(' <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=' + intMenuWidth + '>');
   document.write('    <TR><TD COLSPAN=2><IMG SRC="' + menus[5][intMenuNo] + '"></TD></TR> ');
   for (intI=1;intI<menuchoices[intMenuNo].length;intI++) {
//      alert(menuchoices[intMenuNo][intI]);
      document.write('  <TR>');
      document.write('<TD WIDTH=1><IMG SRC=\'./clearpixel.gif\'></TD>');
      document.write('   <TD CLASS="tpmenu_nr" WIDTH=' + intMenuWidth + ' onMouseOver="changestyle(this,\'tpmenu_rl\');" onMouseOut="changestyle(this,\'tpmenu_nr\');" onClick="document.location = \'' + strBaseURL + 'eStore,wciCatalogue,Type-' + ((intMenuNo == 3 || intMenuNo == 4) ? 'W' : 'C' ) + ',ID-' + menulinks[intMenuNo][intI] + '.html\';">');
      document.write('     <P CLASS="tpmenuTxt_nr"><SPAN CLASS="tpmenuTxt_nr">' + menuchoices[intMenuNo][intI] + '</SPAN></P>');
      document.write('   </TD>');
      document.write('  </TR>');
      }
   document.write(' </TABLE>');
   document.write('</div>');
}

function WriteBreadCrumbs(strBC) {
   var strTemp = String();
   var strNewBC = String();
   var intNbLevels;
   var intI;
   var intLevel;
   var strURLLink;

   intNbLevels = breadcrumbs[1].length / 2;
   strTemp = '';
   strNewBC = '';
   intLevel = 1;
   for(intI=1;intI<breadcrumbs[1].length;intI+=2) {
      if (isValidNumeric(breadcrumbs[1][intI])) 
         strURLLink = 'eStore,wciCatalogue,Type-C,ID-' + breadcrumbs[1][intI] + '.html';
      else
         strURLLink = breadcrumbs[1][intI];
      //alert('bc = ' + breadcrumbs[1][intI+1]);

      if (intLevel != 1 && (String(breadcrumbs[1][intI+1]).substring(10) != 'Magasinage')) {
         if (intLevel == 2)
            strTemp = '<SPAN class="BCStyleTopLevelLink">' + breadcrumbs[1][intI+1] + '</SPAN>';
         else if (intLevel == intNbLevels)
            strTemp = '<SPAN class="BCStyleSelected">' + breadcrumbs[1][intI+1] + '</SPAN>';
         else
            strTemp = '<A  href="' + strURLLink + '">' + breadcrumbs[1][intI+1] + '</A>';
//   alert('strTemp = ' + strTemp);
         strNewBC = strNewBC + ((strNewBC != '') ? ' > ' : '') + strTemp;
         }
      intLevel += 1;
      }
   if (lngCurentCatalogueID == 8 || lngCurentCatalogueID == 10 || lngCurentCatalogueID == 326 || lngCurentCatalogueID == 327 || lngCurentCatalogueID == 240 || lngCurentCatalogueID == 241)
      strNewBC = strNewBC + ' > ' + GetWebPageSection();
   //alert("lngWebPageNo = " + lngWebPageNo + "; lngMenuNo = " + lngMenuNo);

//   strTemp = String(strBC);
//   alert('strTemp = ' + strTemp);
//   var intPos = strTemp.indexOf("</A> > "); //length = 7
//   alert('intPos = ' + intPos);
//   strNewBC = strTemp.substring(intPos + 7);
//   alert('strNewBC = ' + strNewBC);


   document.write(strNewBC);
}

function GetWebPageSection() {
   var intX=0;
   var strMyStr = String('');
   var choices = (lngCurentCatalogueID == 8 || lngCurentCatalogueID == 326 || lngCurentCatalogueID == 240) ? menuchoices[3] : menuchoices[4];
   if (lngCurentCatalogueID == 8 || lngCurentCatalogueID == 10 || lngCurentCatalogueID == 326 || lngCurentCatalogueID == 327 || lngCurentCatalogueID == 240 || lngCurentCatalogueID == 241) {
      for (intX=1;intX < choices.length;intX++) {
//         alert('lngWebPageID=' + lngWebPageID + '; menupages[1][intX]=' + menupages[1][intX]);
         if (lngWebPageID == menupages[1][intX])
            return(choices[intX]);
         }
      }
   return (strMyStr);
}

function WriteLoginLogout(strLogin,strLoginURL,strLogout,strLogoutURL,intIsLoggedIn,strLevel) {
   if (intIsLoggedIn == 1) {
      strURL = String(strLogoutURL);
      document.write('<A HREF="' + strBaseURL + 'eStore.asp?WCI=Logout&WCE=NextURL=' + strURL + '">');
      document.write(strLogout);
      }
   else {
      document.write('<A HREF="' + strSecureURL + strLoginURL + '">');
      document.write(strLogin);
      }
   document.write('</A>');
   }

function BuildMessage(strExisting,strMessage) {
   if (strExisting != '')
      strMessage = strExisting + "\n" + strMessage;
   return(strMessage);
   }

function IsRadioDefined(element) {
   blnIsDefined = false;
   for (i=0;i<element.length;i++) {
      if (element[i].checked) {
         blnIsDefined = true;
         break;
         }
      }
   return(blnIsDefined);
}


function ValidateForm(theForm,strSubmitURL,strLanguage) {
   blnOK = true;
   strMessage = String("");

   var i;
   var nb = theForm.length;
   for(i=0; i<nb; i++) {
      if (theForm.elements[i].type != "hidden" && !theForm.elements[i].disabled && !theForm.elements[i].readOnly && (theForm.elements[i].value == '')) {
         if (!(theForm.elements[i].name == "txtInitial" || theForm.elements[i].name == "txtAddressL2" || theForm.elements[i].name == "txtMainFunctionOther")) {
            theForm.elements[i].focus();
            strMessage = BuildMessage(strMessage,"SVP, veuillez fournir tous les champs requis.");
            blnOK = false;
            break;
            }
         }
     }
 
   switch(theForm.name) {
       case "frmSignUp":
          if (theForm.txtEmail.value != '' || theForm.txtEmail2.value != '') {
             if (theForm.txtEmail.value != theForm.txtEmail2.value) {
                theForm.txtEmail.focus();
                strMessage = BuildMessage(strMessage,"Votre courriel n'est pas identique dans les deux champs.");
                blnOK = false;
                }
             }
          if (!IsRadioDefined(theForm.txtMainFunction)) {
             blnOK = false;
             strMessage = BuildMessage(strMessage,"SVP s&eacute;lectionner votre fonction principale.");
             }
          if (!IsRadioDefined(theForm.optTitleList)) {
             blnOK = false;
             strMessage = BuildMessage(strMessage,"SVP s&eacute;lectionner une salutation.");
             }
          break;
       } 
   if (theForm.name == "frmRFQ_n1" || theForm.name == "frmRFQ_n2" || theForm.name == "frmRFQ_n3") {
      if (!IsRadioDefined(theForm.txtMainFunction)) {
         blnOK = false;
         strMessage = BuildMessage(strMessage,"SVP s&eacute;lectionner votre fonction principale.");
         }
      if (!IsRadioDefined(theForm.optTitleList)) {
         blnOK = false;
         strMessage = BuildMessage(strMessage,"SVP s&eacute;lectionner une salutation");
         }
      }

   if (blnOK) {
      theForm.action = strSubmitURL;
      return true;
      }
   else {
      alert(strMessage);
      return false;
      }
   }


function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
   }



   function SetFocus() {
      var myForm;
      if (document.forms)
         if (document.forms[0]) {
            if (document.forms[1])
               myForm = document.forms[1];
            else
               myForm = document.forms[0];
            }
//      alert(document.forms.length);
      if (myForm != null || myForm != undefined){
         if (myForm.elements[0] != null) {
            var i;
            var nb = myForm.length;
            for(i=0; i<nb; i++) {
               if (myForm.elements[i].type != "hidden" && !myForm.elements[i].disabled && !myForm.elements[i].readOnly && (myForm.elements[i].value == '') && (myForm.elements[i].style.visibility != "hidden")) {
                  myForm.elements[i].focus();
                  break;
                  }
               }
            }
         }
      }    


function RotateHomePics() {
   homeCurrentPic = (Math.round(Math.random()*9));
   DoRotateHomePics();
   }

function DoRotateHomePics() {
   homeCurrentPic += 1;
   if (homeCurrentPic > homephotos.length)
      homeCurrentPic = 1;
   homePic = document.getElementById('HomePic');
   if (String(homePic.src) != String(homephotos[homeCurrentPic]))
      homePic.src = homephotos[homeCurrentPic];
   timeOut = homePicDelay * 1000;
   setTimeout('DoRotateHomePics();',timeOut);
   }
