/* Auteur : Chanh T.Do [ThoranSoft - 2006.05.01] */

/* Modifié par Chanh T.Do [ThoranSoft - 2006.10.14]
   Ajout de la fonction LoadCSSFile pour pouvoir choisir la bonne feuille de style selon le
   browser. Les browser n'interprète pas de la même façon les pixels pour le positionnement
   des images.
*/

              //Variables Globale
var topImg;   //Variables pour calculer les pixels de l'axe des x (top) et l'axe des y (left)
var leftImg;  //du logo du site (point de référence pour placer les autres images ou animations).

var agt = navigator.userAgent.toLowerCase();
var isMac = (agt.indexOf('mac') != -1);
var isOpera = (agt.indexOf('opera') != -1);
var IEver = parseInt(agt.substring(agt.indexOf('msie ') + 5));
var isIE = ((agt.indexOf('msie')!=-1 && !isOpera && (agt.indexOf('webtv')==-1)) && !isMac);
var isIE5win = (isIE && IEver >= 5);
var isIE5mac = ((agt.indexOf('msie') != -1) && isMac);
var isSafari = (agt.indexOf('safari') != -1);



/* Fonction pour différencier la famille NETSCAPE ou IE */
function CheckBrowser()
{if (navigator.appName=="Microsoft Internet Explorer")
     {
      DisableFlashBug();
     }
}


function DisableFlashBug()
{
 objects = document.getElementsByTagName("object");
 for (var i = 0; i < objects.length; i++)
     {
      objects[i].outerHTML = objects[i].outerHTML;
     }
}


/* Cette fonction permet aux animation flash d'ouvrir des POPUPS windows pour afficher les images */
function PopMe(TitleName,Content)
{
 var WindowSpecs="width=600,height=500,scrollbars=no";

 switch(Content)
       {
        case 'BonneSante300.png':               WindowSpecs="width=850,height=400,scrollbars=no"; break;
        case 'Clocks300.png':                   WindowSpecs="width=850,height=430,scrollbars=no"; break;
        case 'Coupons1_300.png':                WindowSpecs="width=760,height=530,scrollbars=no"; break;
        case 'Coupons2_300.png':                WindowSpecs="width=750,height=520,scrollbars=no"; break;
        case 'Coupons3_300.png':                WindowSpecs="width=750,height=520,scrollbars=no"; break;
        case 'Coupons4_300.png':                WindowSpecs="width=760,height=530,scrollbars=no"; break;
        case 'XploranceP1_300.png':             WindowSpecs="width=510,height=680,scrollbars=no"; break;
        case 'XploranceP2_300.png':             WindowSpecs="width=510,height=680,scrollbars=no"; break;
        case 'XploranceP3_300.JPG':             WindowSpecs="width=520,height=680,scrollbars=no"; break;
        case 'XploranceP4_300.png':             WindowSpecs="width=520,height=680,scrollbars=no"; break;
        case 'XploranceP5_300.png':             WindowSpecs="width=520,height=680,scrollbars=no"; break;
        case 'XploranceP6_300.png':             WindowSpecs="width=520,height=680,scrollbars=no"; break;
        case 'NakisaCD.png':                    WindowSpecs="width=570,height=570,scrollbars=no"; break;
        case 'NDP_300.png':                     WindowSpecs="width=850,height=650,scrollbars=no"; break;
        case 'Nickels_300.png':                 WindowSpecs="width=500,height=650,scrollbars=no"; break;
       }

 consoleRef=window.open('',TitleName,WindowSpecs)
 //consoleRef.document.write('<img src="../images/'+Content+'">');

 consoleRef.document.writeln(
   '<html><head><title>'
   +TitleName
   +'</title></head>'
   +'<body bgcolor=white onLoad="self.focus()">'
   +'<img src="../images/'
   +Content
   +'">'
   +'</body></html>'
 )
 consoleRef.document.close();

}

/* Cette fonction permet de cacher le PRIVACY POLICY */

function Cacher(strIDName)
{
 if (document.getElementById(strIDName))
     document.getElementById(strIDName).style.visibility="hidden";
}

/* Cette fonction permet de montrer le PRIVACY POLICY */
function Montrer(strIDName)
{
 if (document.getElementById(strIDName))
     document.getElementById(strIDName).style.visibility="visible";
}

/* Fonction pour insérer les Headings flash dans la page HTML */
function embedFlashHeadings(strFlash, strWidth, strHeight)
{
 document.write('<p class=\"headings\" id=\"SWFObject\">' +
 '      <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"' +
 '        codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\"' +
 '        width=\"' + strWidth + 'px\" height=\"' + strHeight + 'px\">' +
 '        <param name=\"movie\" value=\"' + strFlash + '\">' +
 '        <param name=\"quality\" value=\"high\">' +
 '' +
 '        <embed src=\"' + strFlash + '\"' +
 '          quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"' +
 '          type=\"application/x-shockwave-flash\" width=\"' + strWidth + 'px\" height=\"' + strHeight + 'px\">' +
 '        </embed>' +
 '      </object>' +
 '    </p>');
}



/* Function pour calculer la largeur et la hauteur de l'écran du client. */
function Positionner(posTop, posLeft, imgID, RefID)
{
 /* Pour différencier la famille NETSCAPE ou IE */
 if (navigator.appName=="Microsoft Internet Explorer")
    {topImg=findPosY(RefID);
     leftImg=findPosX(RefID);}
 else
    {imgRef=document.getElementById(RefID);
     topImg=imgRef.offsetTop;
     leftImg=imgRef.offsetLeft;
    }

 /* On positionne l'image ou l'animation */
 document.getElementById(imgID).style.top = parseInt(topImg) + parseInt(posTop);
 document.getElementById(imgID).style.left = parseInt(leftImg) + parseInt(posLeft);
}


//Ajouté par Chanh T.Do [2005.11.19]
//Sert à trouver la position de l'axe des X d'une image
function findPosY(imageTofind)
         {var img = document.getElementById(imageTofind);
          var thisTop = (document.all)? img.offsetTop :
          document.defaultView.getComputedStyle(img, "").getPropertyValue("top");
          return(thisTop);
         }

//Ajouté par Chanh T.Do [2005.11.19]
//Sert à trouver la position de l'axe des Y d'une image
function findPosX(imageTofind)
         {var img = document.getElementById(imageTofind);
          var thisLeft = (document.all)? img.offsetLeft :
          document.defaultView.getComputedStyle(img, "").getPropertyValue("left");
          return(thisLeft);
         }


function LoadPrivacy(strFlash, strFlaID, strWidth, strHeight, strFlashVersion, strBGColor, strTagID)
{
 Montrer(strTagID);
 loadFlash(strFlash, strFlaID, strWidth, strHeight, strFlashVersion, strBGColor, strTagID);
}

function UnloadPrivacy(strFlash, strFlaID, strWidth, strHeight, strFlashVersion, strBGColor, strTagID)
{
 Cacher(strTagID);
 loadFlash(strFlash, strFlaID, strWidth, strHeight, strFlashVersion, strBGColor, strTagID);

}

/* Fonction pour Menu en image */
function imgOn(myImgName)
  {//we need to name the image in the BODY
   //so we can use its name here
   document[myImgName].src=eval(myImgName+ 'H' ).src;
  }

function imgOut(myImgName)
{document[myImgName].src=eval(myImgName+ 'N' ).src;}


function GoToURL(strURL)
  {window.status=('Connection en cours....');
   var location=(strURL);
   this.location.href = location;
   window.status=('Connection à http://www.ginetteroy.com...');
  }


//Fonction pour valider les champs du e-learning
function validate_form(lng)
{
  var msg = "";
  valid = true;
  
  var e_prenom = document.getElementById('e_prenom_id');
  if ((e_prenom != undefined) && (e_prenom.value.length == 0))
  {
    if (lng == 0) { msg += "- Le prénom est un champ obligatoire.\n"; }
    else { msg += "- The first name is a required field.\n"; }
  }

  var e_nom = document.getElementById('e_nom_id');
  if ((e_nom != undefined) && (e_nom.value.length == 0))
  {
    if (lng == 0) { msg += "- Le nom est un champ obligatoire.\n"; }
    else { msg += "- The last name is a required field.\n"; }
  }

  var e_email = document.getElementById('e_email_id');
  if ((e_email != undefined) && (e_email.value.length == 0))
  {
    if (lng == 0) { msg += "- L'adresse courriel est un champ obligatoire.\n"; }
    else { msg += "- The e-mail is a required field.\n"; }
  }
  
  var e_tel1 = document.getElementById('e_tel1_id');
  if ((e_tel1 != undefined) && (e_tel1.value.length == 0))
  {
    if (lng == 0) { msg += "- Le numéro de téléphone 1 est un champ obligatoire.\n"; }
    else { msg += "- The telephone 1 is a required field.\n"; }
  }
  
  if (msg == "") { valid = true; }
  else { valid = false; alert(msg); }
      
  return valid;
}


/** Fonction permettant d'afficher et de cacher les tabs.<br>
    <b>Note</b>: le premier élément du array est le paneau que l'on veut afficher. Les autres sont cachés par défaut.
    On ajoute le préfix 'p_' devant chaque argument. On passe le ID du tab à afficher et la fonction se charge d'inscrire
    le ID du panel à cacher ou à afficher (p_IdDuPanel)
    @param {array} arguments - Vecteur contenant les ID des paneau qu'on veut afficher ou cacher */
function swapPanel()
{
  //Afficher le premier paneau (arguments[0])
  var panel = document.getElementById('p_' + arguments[0]);
  if (panel != undefined)
  {
    panel.style.display = 'block';             //Affichage du panel en block avant d'effectuer l'animation d'opacité.
    
    var tab = document.getElementById(arguments[0]);        	//ID du tab
    if (tab != undefined) { tab.style.color = '#767676'; }    	//Tab courrant
    
    //Boucler dans le vecteurs des arguments pour cacher les autres panels
    for (var i=1; i<arguments.length; i++)
    {
      var other_panel = document.getElementById('p_' + arguments[i]);
      if (other_panel != undefined) 
      {
        other_panel.style.display = 'none'; 
        var other_tab = document.getElementById(arguments[i]);
        if (other_tab != undefined) {other_tab.style.color = '#0053c7'; }
      }
    }   //Fin boucle for i
  }     //Fin if panel
}       //Fin fonction


/** Fonction permettant de précharger les images en javascript.<br>
    Retourne undefined s'il ne trouve pas l'objet.
    @param {array} arguments - Vecteur contenant les images à charger (SRC)
    @return vecteur des images qui ont été pré-chargées
    @type array */
function preloadImg()
{ 
  var vImg = new Array();   //Initialiser le tableau d'image
  if (document.images)      //Vérifier s'il y a des images dans le documents
  {
    //Boucler dans le array des arguments pour pré-charger les images
    for (var i=0; i<arguments.length; i++)
    {
      vImg[i] = new Image();
      vImg[i].src = arguments[i];
    }
    return vImg;    //Retourner le tableau d'image préchargée
  }
}
