var lpNumber = "15509568"; // Add Site ID (LP-NUMBER)
var lpServerName = "server.iad.liveperson.net";
// DEFINED REP STATES:
// var LPREPSTATEONLINE = "online" : Reps available online
// var LPREPSTATEOFFLINE = "offline" : No available reps online - offline or away
// var LPREPSTATEOCCUPIED = "occupied" : Rep in "back in 5" state
// var LPREPSTATEUNKNOWN = "unknown" : Unable to contact server

// Définition des variables
var videodir = "http://www.web2ads.net/fortier/videos/"; //URL du répertoire contenant les vidéos.
var videobackground = "background.flv";//Vidéo en arrière plan.

//Définition de la séquence vidéo
//Veilliez à conserver la structure et la nomenclature des variables lors de la modification de la séquence
var video1    =  "video10.flv";  // Assise
var video2    =  "video16.flv";  // Attente 5
var video3    =  "video06.flv";  // En tout temps vous peuvez cliquer ici
var video4    =  "video14.flv";  // Attente 3
var video5    =  "video04.flv";  // Besoin d'aide
var video6    =  "video16.flv";  // Attente 5
var video7    =  "video01.flv";  // Vous vous posez des questions sur crédit
var video8    =  "video14.flv";  // Attente 3
var video9    =  "video05.flv";  // N'ésitez pas... la pour vous assister
var video10   =  "video15.flv";  // Attente 4
var video11   =  "video03.flv";  // Recherche véhicule spécifique, bouton
var video12   =  "video14.flv";  // Attente 5
var video13   =  "video02.flv";  // Mode de financement 
var video14   =  "video14.flv";  // Attente 3
var video15   =  "video13.flv";  // Attente 2
var video16   =  "video14.flv";  // Attente 5
var video17   =  "video09.flv";  // Toujours pas trouvé le véhicule que vous cherchez
var video18   =  "video11.flv";  // Debout
var video19   =  "video10.flv";  // Assise
var video20   =  "video14.flv";  // Attente 5
var video21   =  "video14.flv";  // Attente 5
var video22   =  "video14.flv";  // Attente 5
var video23   =  "video06.flv";  // En tout temps vous peuvez cliquer ici
var video24   =  "video14.flv";  // Attente 5
var video25   =  "video14.flv";  // Attente 5
var video26   =  "video14.flv";  // Attente 5
var video27   =  "video08.flv";   // Plusieurs minutes que vous naviguez
var video28   =  "video14.flv";  // Attente 5
var video29   =  "video14.flv";  // Attente 5
var video30   =  "video14.flv";  // Attente 5
var video31   =  "video03.flv";  // Recherche véhicule spécifique, bouton
var video32   =  "video14.flv";  // Attente 5
var video33   =  "video14.flv";  // Attente 5
var video34   =  "video14.flv";  // Attente 5
var video35   =  "video11.flv";  // Debout

//var video9  =  "video07.flv";   // Pas première visite
//var video13   =  "video11.flv";  // Debout
//var video14 =  "video12.flv";   // Attente 1
//var video15 =  "video16.flv";   // Attente 5

//Fin de la définition des variables

function aideenligne() 
{
window.open('http://server.iad.liveperson.net/hc/15509568/?cmd=file&file=visitorWantsToChat&site=15509568&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/French/General/3a&referrer='+escape(document.location),'chat15509568','width=475,height=400,resizable=yes');
}


//Fonction d'affichage, ne pas modifier !
function ShowVideo(){
    // Show Video in LPTag
    var index = 1;
    var concater = "";
    while(typeof( window['video'+index] ) != "undefined"){	
        if(index == 1){
            concater = eval('video'+index);
        }else{
            concater = concater+"/"+eval('video'+index);	
        }
        index++;
    }
    var numVidz = index-1;
    document.getElementById('LPTag').innerHTML = 
    '<div style="margin-left: 7px">\n\
            <table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse" bordercolor="#111111">\n\
                <tr>\n\
                <TD "style="PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; PADDING-BOTTOM: 0px; VERTICAL-ALIGN: top">\n\
                    \n\
                    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"\n\
                    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"\n\
                    width="191" height="222">\n\
                    <param name="movie" value="/swf/aideenligne.swf?idv='+numVidz+'&flvSeq='+concater+'&videodir='+videodir+'&videobackground='+videobackground+'"> \n\
                    <param name="quality" value="high">\n\
                    <param name="menu" value="false">\n\
                    <!--[if !IE]> <-->\n\
                        <object data="/swf/aideenligne.swf?idv='+numVidz+'&flvSeq='+concater+'&videodir='+videodir+'&videobackground='+videobackground+'"\n\
                             width="191" height="222" type="application/x-shockwave-flash">\n\
                             <param name="quality" value="high">\n\
                             <param name="menu" value="false">\n\
                             <param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer">\n\
                             FAIL (Votre navigateur ne peut afficher le contenu de cette page).\n\
                        </object>\n\
                    <!--> <![endif]-->\n\
                    </object>\n\
                    \n\
                </td>\n\
                </tr>\n\
            </table>\n\
    </div>\n'
}

function ShowImage(){
    // Show Online Image in LPTag
    //Var OnlineTag;
    //Var OfflineTag;
    document.getElementById('LPTag').innerHTML = 
    '<div style="margin-left: 7px">\n\
        <table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse" bordercolor="#111111">\n\
            <tr>\n\
                <TD style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; VERTICAL-ALIGN: top">\n\
                    <a href=\'http://server.iad.liveperson.net/hc/15509568/?cmd=file&file=visitorWantsToChat&site=15509568&byhref=1&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/French/General/3a\' target=\'chat15509568\'  onClick="javascript:window.open(\'http://server.iad.liveperson.net/hc/15509568/?cmd=file&file=visitorWantsToChat&site=15509568&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/French/General/3a&referrer=\'+escape(document.location),\'chat15509568\',\'width=475,height=400,resizable=yes\');return false;" >\n\
                    <IMG title="Aide en ligne" alt="Aide en ligne" src="http://www.web2ads.net/fortier/images/aideenligne.jpg" width="190" height="222">\n\
                    </a>\n\
                </td>\n\
            </tr>\n\
        </table>\n\
    </div>\n'
}

function ShowImageEn(){
    // Show Online Image in LPTag
    //Var OnlineTag;
    //Var OfflineTag;
    document.getElementById('LPTag').innerHTML = 
    '<div style="margin-left: 7px">\n\
        <table cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse" bordercolor="#111111">\n\
            <tr>\n\
                <TD style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; VERTICAL-ALIGN: top">\n\
                    <a href=\'http://server.iad.liveperson.net/hc/15509568/?cmd=file&file=visitorWantsToChat&site=15509568&byhref=1&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/French/General/3a\' target=\'chat15509568\'  onClick="javascript:window.open(\'http://server.iad.liveperson.net/hc/15509568/?cmd=file&file=visitorWantsToChat&site=15509568&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/French/General/3a&referrer=\'+escape(document.location),\'chat15509568\',\'width=475,height=400,resizable=yes\');return false;" >\n\
                    <IMG title="Online Help" alt="Online Help" src="http://www.web2ads.net/fortier/images/onlinehelp.jpg" width="190" height="222">\n\
                    </a>\n\
                </td>\n\
            </tr>\n\
        </table>\n\
    </div>\n'
}

function ShowHelp(){
    hostname = location.hostname;
    pathname= location.pathname;
    switch (hostname)
    {
    case "www.fortier6000moins.com":
        if (
            pathname == "/contact-us.html" ||
            pathname == "/faq.html" ||
            pathname == "/financing.html" ||
            pathname == "/index-en.html" ||
            pathname == "/inventory.html" ||
            pathname == "/testimonies.html" ||
            pathname == "/warranties-inspections.html"
            ) 
        {
            ShowImageEn();
        }else{
            if (
                pathname == "/inventaire.html" ||
                pathname == "/inventairev.html"
                )
            {
                ShowImage();
                //ShowVideo();
            }else{
                ShowImage();
            }        
        }
        break;
    case "fortier6000moins.com":
        if (
            pathname == "/contact-us.html" ||
            pathname == "/faq.html" ||
            pathname == "/financing.html" ||
            pathname == "/index-en.html" ||
            pathname == "/inventory.html" ||
            pathname == "/testimonies.html" ||
            pathname == "/warranties-inspections.html"
            ) 
        {
            ShowImageEn();
        }else{
            if (
                pathname == "/inventaire.html" ||
                pathname == "/inventairev.html"
                )
            {
                ShowImage();
                //ShowVideo();
            }else{
                ShowImage();
            }        
        }
        break;
    case "fortieroccasion.com":
                ShowImage();
        break;
    case "www.fortieroccasion.com":
                ShowImage();
        break;
    case "occasion.fortierauto.com":
                ShowImage();
        break;
    case "www.fortierautocredit.com":
                ShowImage();
        break;
    case "fortierautocredit.com":
                ShowImage();
        break;
    case "www.fortierford.com":
                ShowImage();
        break;
    case "fortierford.com":
                ShowImage();
        break;
    case "ford.fortierauto.com":
                ShowImage();
        break;
    default:
        break;
    }

}

function tagexists(tag){
    var tagexists = document.getElementById(tag);
    if (tagexists) {
        return true;
    }else {
        return false;
   }
}

function repStateNotifyFunction(state) {
    
    if (CurrentState!=state){
        //Changed State - and when page is loaded for the first time.
        
        if (state==LPREPSTATEONLINE){
            // "ONLINE"
            if (tagexists("LPTag")) { 
                ShowHelp();
            }
        }else{
            // Occupied, Offline or Unknown
            if (tagexists("LPTag")){ 
                document.getElementById('LPTag').innerHTML = "<!-- Empty -->";
            }
        }
        
        // Set State to CurrentState
        CurrentState=state;
    }
}

function CheckState() {

    if (typeof(lpServerName) == "undefined") 
        lpServerName = "server.iad.liveperson.net";
    if (typeof(lpSkill) == "undefined") 
        skillparam = "";
    else
        skillparam = "&skill=" + escape(lpSkill);
    if (typeof(lpOperator) == "undefined") 
        operatorParam = "";
    else
        operatorParam = "&operator=" + escape(lpOperator);
    if (typeof(lpChannel) == "undefined")
        channelParam = "";
    else
        channelParam = "&channel=" + escape(lpChannel);
    
    var LPREPSTATEONLINE = "online";
    var LPREPSTATEOFFLINE = "offline";
    var LPREPSTATEOCCUPIED = "occupied";
    var LPREPSTATEUNKNOWN = "unknown";
    
    var lpDOM = (document.getElementById) ? true : false;
    var lpIE = (document.all) ? true : false;
    var lpMAC_IE = ((navigator.platform) && (navigator.platform.toUpperCase().indexOf("MAC") >= 0) && (lpIE));
    var lpFindRepstateImage = new Image();
    var LPProtocol = document.location.toString().indexOf("https") == 0 ? "https" : "http";
    
    if ((! lpIE) && (lpDOM))
    {
        lpFindRepstateImage = document.createElement('IMG');
        lpFindRepstateImage.style.visibility = "hidden";
        document.body.appendChild(lpFindRepstateImage);
    } else
    if (lpMAC_IE)
    {
        document.writeln("<div style='visibility:hidden'><img src='blank' id='lpFindRepstateImage' name='lpFindRepstateImage'></div>");
        lpFindRepstateImage = document.lpFindRepstateImage;
    }
    
    function lpGetDate()
    {
        var d = new Date();
        return d.getTime();
    }
    
    function lpCheckFindRepstate() {
        lpFindRepstateImage.src = LPProtocol + "://" + lpServerName + "/hc/" + lpNumber + "/?cmd=repstate&site=" + lpNumber + "&useSize=true" + skillparam + operatorParam + channelParam + "&d=" + lpGetDate();
        lpFindRepstateLoopImage();
    }
    
    function lpFindRepstateLoopImage() {
        if (lpFindRepstateCheckImage())
            return;
        setTimeout("lpFindRepstateLoopImage()", 1000);
    }
    
    function lpFindRepstateCheckImage() {
        if (((lpDOM && !lpIE) || (lpMAC_IE)) && (! lpFindRepstateImage.complete))
            return false;
        var imageWidth = lpFindRepstateImage.width;
        if (imageWidth > 0) {
            if (imageWidth == 40) {
                lpNotifyRepstate(LPREPSTATEONLINE);
            } else 
            if (imageWidth == 50) {
                lpNotifyRepstate(LPREPSTATEOFFLINE);
            } else
            if (imageWidth == 60) {
                lpNotifyRepstate(LPREPSTATEOCCUPIED);
            } else
                lpNotifyRepstate(LPREPSTATEUNKNOWN);
            return true;
        }
        return false;
    }
    
    function lpNotifyRepstate(state) {
        if (typeof(repStateNotifyFunction) != "undefined"){
                repStateNotifyFunction(state);
                //setTimeout("CheckState()",5000);
            }
    }
    setTimeout("lpCheckFindRepstate()", 500);
    setTimeout("CheckState()", 5000);
}

CurrentState="NoState";
setTimeout("CheckState()", 1000);

