/*
'---
'--- JSFonctions.js - Page de fonction en Javascript
'---
'--- Par Sacha Vincent
'---     CIBLE Solutions d'affaires
'---
'--- RÉVISION
'--- 2007/01/11 -SJV	Création
*/     

// Array de preload des images
var ArrayPreload =  new Array();

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *    
 * GetReference()  - Trouve la référence pour l'objet document
 */
function GetReference(id)
{
	if(document.layers) return document.layers[id];
	if(document.all && !document.getElementById) return document.all[id];
	if(document.all && document.getElementById) return document.getElementById(id);
	if(!document.all && document.getElementById) return document.getElementById(id);
	return false;
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *    
 * OuvrirFenetre()  - Ouvrir une fenêtre
 */
function OuvrirFenetre(iNomPage, iTitre, iWidth, iHeight)
{
	fenetre = window.open(iNomPage, iTitre, "top=0, left=0, width=" + iWidth + ", height=" + iHeight + ", scrollbars=yes, location=no, toolbar=no, menubar=no");
	fenetre.focus()
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * JAVA_FormatStr() - Remplace les apostrophes (') par l'équivalent UNICODE \u0027
 *                 et les guillemets (") par l'équivalent UNICODE \u0022 pour
 *                 les fonctions JavaScript.
 */
function JAVA_FormatStr(iString)
{       
    var chaine = new String(iString);

    remplace  = new RegExp("\'","g"),
    chaine = chaine.replace(remplace, "&#39;");

    remplace  = new RegExp('\"',"g"),
    chaine = chaine.replace(remplace, '&#39;');

    return chaine;
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ImprimerPage() - Lance l'impression de la fenêtre en cours
*/
function ImprimerPage(iLangue)
{       
    if (navigator.appVersion.indexOf("Mac",0)>0)
    {
        if (iLangue=="en")
            alert("This function is not available for Macintosh. Please use Apple-P.");
        else
            alert("Cette fonction n\'est pas réalisable sur Macintosh.\n\nUtilisez plutôt la combinaison de touches  « Pomme-P »");
    }
    else
    {
        window.print();
    }
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* OuvrirPrint() - Ouvre la page pour l'impression
*/
function OuvrirPrint()
{
   OuvrirFenetre("", "PRINTWINDOW", 570, 600);
   document.FormPrint.submit();
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* AfficherEntete() - Affiche l'entête des pages
*/
function AfficherEntete()
{
    //<h1 class="blanc bold letterspace" style='text-align:right; padding-right:10px'>Le savoir-faire intégré à l'excellence</h1>        
    
    document.write('<img src="images/commun/enonce_' + g_Langue + '.gif" height="50" width="388" border="0" />');
    document.write('<h3 class="gris_pale bold" style="text-align:right; padding-right:10px; margin-top:3px"><a href="index.html" class="gris_pale">' + LangJS("Retour à l\'accueil" , "Back to homepage") + '</a></h3>');      
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* AfficherLienBasPage() - Affiche les liens du bas de la page
*/
function AfficherLienBasPage(iLien, iCopyright, iLangue)
{
    var Today = new Date();
    
    if(iLangue == "")
        iLangue = 'fr';
   
    if(iLien == true)
    {
        document.write('<h5 style="text-align:left; float:left" class="gris_pale">');
        document.write('<a href="index.html" class="gris_pale">' + LangJS("Accueil","Home") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="notre_vision_' + iLangue + '.html" class="gris_pale">' + LangJS("Qui sommes-nous ?","Who we are?") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="moule_introduction_' + iLangue + '.html" class="gris_pale">' + LangJS("Moules Industriels","Moules Industriels") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="plastech_introduction_' + iLangue + '.html" class="gris_pale">' + LangJS("Plastech","Plastech") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="emplois_' + iLangue + '.html" class="gris_pale">' + LangJS("Emplois","Jobs") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="carte_' + iLangue + '.html" class="gris_pale">' + LangJS("Carte routière","Road map") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="contact_' + iLangue + '.php" class="gris_pale">' + LangJS("Nous joindre","To Reach Us") + '</a>&nbsp;|&nbsp;');
        document.write('<a href="http://www.mi-integration.com/extranet.html" class="gris_pale">' + LangJS("Transfert de fichier","File transfer") + '</a>');
        document.write('</h5>');
    }
    
    if(iCopyright == true)    
        document.write('<h5 style="text-align:right; float:right" class="gris_pale">&copy; ' + Today.getFullYear() + ', MI-Integration - ' + LangJS("Tous droits réservés", "All rights reserved") + '</h5>');
        
    document.write('<br /><h5 style="text-align:right; float:right" class="gris_pale"><a href="http://www.ciblesolutions.com/accueil.php?ClickID=11" target="_blank">Réalisation CIBLE Solutions d\'affaires</a></h5>');
      
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * LangJS() - Retourne une string en fonction de la langue actuelle ($g_Langue).
 *
 * Paramètres:
 *   iValeurFr - Valeur française (type: String)
 *   iValeurEn - Valeur anglaise (type: String)
 *
 * Valeur de retour:
 *   La bonne valeur en fonction de la langue. Si cette valeur est vide,
 *   alors cette fonction retourne l'autre valeur (type: String).
 */
function LangJS(iValeurFr, iValeurEn)
{   
    // Français par défaut
    if(g_Langue == '')
        g_Langue == 'fr';
    
    if (g_Langue == 'fr')
    {
        if (iValeurFr != "")
            return '' + iValeurFr;
        else
            return '' + iValeurEn;
    }
    else
    {
        if (iValeurEn != "")
            return '' + iValeurEn;
        else
			return '' + iValeurFr;
    }
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * preloadImages() - Pre-charge les images contenues dans ArrayPreload
 *                   en memoire
 */
function preloadImages()
{
	if (document.images)
	{
		for (var i = 0; i < ArrayPreload.length; i++)
		{
            (new Image).src = ArrayPreload[i];
		}

		PreloadFlag = true;
	}
	
	void 0;
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Agrandissement() - Affiche les images en gros
 */
function Agrandissement(iItem)
{
    ObjImage = GetReference(iItem);    
    
    var chaine = ObjImage.src;
   
    if (chaine.length > 0) 
    {
        chaine = chaine.replace('_thumb', '');   
        
        ObjPhoto = GetReference('grand_format');
        ObjPhoto.src = chaine;             
    }                         
    
}

// Mets la diapo en cours à zéro
var CurrentDiapo = 0;
// Variable chronomètre
var Chrono = "";
// Tableau des pages schémas
var ArrayPage = new Array();

// Démarrage du diaporama
function DiapoStart()
{
    Chrono = setInterval("ChangeDiaporama()", Delay);
    
    AfficherNavigation();    
}

// Arrêt du diaporama
function DiapoStop()
{
    clearInterval(Chrono);    
}

// Séquence de chagement
function ChangeDiaporama()
{           
    CurrentDiapo = CurrentDiapo + 1;
    var ObjDiapo = GetReference("diapo" + CurrentDiapo);
    
    ObjDiapo.style.display = "block";
    
    if(CurrentDiapo == Pause || CurrentDiapo == Fin)
    {   
        DiapoStop();                    
    }
    
}

function RemoveDiapo(iStart, iEnd)
{
    for(i = iStart; i <= iEnd; i++)
    {
        var ObjDiapo = GetReference("diapo" + i);            
        ObjDiapo.style.display = "none";
    }   
}

// Relecture du diaporama
function LancerDiapo(iStartAt)
{   
    if(CurrentDiapo == Pause)
    {   
        RemoveDiapo(1, Pause);             
    }
    else if(CurrentDiapo == Fin)
    {
        RemoveDiapo(Pause, Fin);         
    } 
    
    if(iStartAt == 0)
        CurrentDiapo = 0;
    else if(iStartAt != "")
        CurrentDiapo = iStartAt;         
    
    DiapoStart();
}

function ChangerPage(iSens)
{       

    // En cas d'interruption de la première étape
    if(CurrentDiapo > 1 && CurrentDiapo < Pause)
    {
        DiapoStop();
        RemoveDiapo(1, CurrentDiapo);
        CurrentDiapo = Pause;
    }
    else if(CurrentDiapo > Pause && CurrentDiapo < Fin)
     {
        DiapoStop();
        RemoveDiapo(Pause, Fin);
        CurrentDiapo = 0;
        DiapoStart(); 
        return;
    }
    
    if(iSens == "P")
    {
        if(CurrentDiapo == 0)
            ChangerEtape(iSens);        
        else if(CurrentDiapo == Pause)        
            ChangerEtape(iSens);                       
        else if(CurrentDiapo == Fin)                                    
            LancerDiapo(0);        
    }
    else
    {               
        if(CurrentDiapo < Fin)                        
            LancerDiapo(Pause);                                    
        else      
            ChangerEtape(iSens);                  
    }
    
}

// Le sens de la lecture (iSens)"P ou S"  
function ChangerEtape(iSens)
{   

    if(iSens == "P") // Série précédente                
        iPage = g_MenuHaut - 1;                                                         
    else  // Série suivante                       
        iPage = g_MenuHaut + 1; 
        
    // Patch temporaire pour le schéma supplémentaire
    if(g_PageSpecial == 4)
        iPage = 3;
        
        
    location.href = GetPage(iPage);                 
}

function GetPage(iMenuHaut)
{
    iMenuTemp = iMenuHaut
    
    if(iMenuTemp > 4)
        iMenuTemp = 1;
        
     // Le nom des pages avec schémas
    ArrayPage[1] = "mi_schema_" + g_Langue + ".html";
    ArrayPage[2] = "moule_schema_" + g_Langue + ".html";
    ArrayPage[3] = "plastech_schema_" + g_Langue + ".html";
    ArrayPage[4] = "plastech_schema1_" + g_Langue + ".html";
    
    return ArrayPage[iMenuTemp];
}

function AfficherLienSchema()
{   
    document.write('<table width="100%" border="0" cellpadding="10" cellspacing="0">');
    document.write('<tr>');
    document.write('<td align="right" style="padding-bottom:0px"><img src="images/commun/puce.gif" border="0">&nbsp;<a href="' + GetPage(g_MenuHaut) + '"><strong>' + LangJS("Processus de développement","Development process") + ' »»</strong></a></td>');
    document.write('</tr>');
    document.write('</table>');    
}

function AfficherNavigation()
{
    ObjNavig = GetReference("NavigationPlace");
    
    if(g_MenuHaut == 3)
        iClasse = "gris";
    else if(g_MenuHaut == 2)
        iClasse = "bleu_gris";        
    else
        iClasse = "beige";
        
    var Navigation = "<span class='" + iClasse + "'>Page ";
    
    if(Pause < Fin)
    {
        if(CurrentDiapo < Pause)
        {
            Navigation += "<span class='" + iClasse + "'><strong>1</strong></span> - ";       
            Navigation += "<a class='" + iClasse + "' href='javascript:ChangerPage(\"S\")'>2</a>";
        }
        else
        {
            Navigation += "<a class='" + iClasse + "' href='javascript:ChangerPage(\"P\")'>1</a> - ";       
            Navigation += "<span class='" + iClasse + "'><strong>2</strong></span>"; 
        }
    }
    else
    {
        if(CurrentDiapo < Pause)
        {
            Navigation += "<span class='" + iClasse + "'><strong>1</strong></span>";                   
        }
    }
    
    Navigation += "</span>";
    
    ObjNavig.innerHTML = Navigation;
    
}

