// Script used to display a random quote (image) on the home page

    var numOfQuotes = 6;
    var cookieName = "randomQuotes";
    var expDays = 1825; // 5 years
    var randNum;

    var alt;
    
    var altENG = new Array();
    altENG[0] = "";
    altENG[1] = "Stikeman Elliott - They are exceptional. They execute transactions seamlessly and flawlessly. - Client interview, IFLR 1000 (2009)";
    altENG[2] = "Stikeman Elliott - Hands down the best business law firm in the country - Client interview, IFLR 1000 (2009)";
    altENG[3] = "Stikeman Elliott - #1 in Canadian Corporate Finance - Bloomberg (by volume of equity offerings)";
    altENG[4] = "Stikeman Elliott - #1 in Cross-border M&A (top Canadian firm in U.S-based deals) - Mergerstat Review";
    altENG[5] = "Stikeman Elliott - #1 in Canadian M&A - Thomson Financial (by value)";
    altENG[6] = "Stikeman Elliott - Top Corporate and Commercial Team in Canada - World Finance, 2008";
    
    var altFRC = new Array();
    altFRC[0] = "";
    altFRC[1] = "Stikeman Elliott - « Ils sont exceptionnels. Ils m&egrave;nent les op&eacute;rations de fa&ccedil;on impeccable et sans heurts. » - Entrevue avec un client, IFLR 1000 (2009)";
    altFRC[2] = "Stikeman Elliott - « Sans conteste le meilleur cabinet d&#039;avocats en droit des affaires au pays » - Entrevue avec un client, IFLR 1000 (2009)";
    altFRC[3] = "Stikeman Elliott - No 1 en financement des entreprises (selon le volume d&#039;offres publiques de valeurs mobili&egrave;res) - BLOOMBERG";
    altFRC[4] = "Stikeman Elliott - No 1 en fusions et acquisitions transfrontali&egrave;res (meilleur cabinet canadien dans les op&eacute;rations am&eacute;ricaines) - Mergerstat Review";
    altFRC[5] = "Stikeman Elliott - No 1 en fusions et acquisitions canadiennes (selon la valeur des op&eacute;rations) - Thomson Financial";
    altFRC[6] = "Stikeman Elliott - Meilleure &eacute;quipe en droit des soci&eacute;t&eacute;s et des affaires au Canada - World Finance, 2008";

    
function getRandomQuote(lang)
    {                    
        // Search for existing cookie    
        var existingCookie = getCookie(cookieName);
        
        if (existingCookie == null)
        {
            // Cookie was not found, create a new one
            getRandNum();
            createCookie(cookieName, randNum, expDays);        
        }
        else
        {
            // Cookie was found
                    
            // Creating an array of all the already viewed quotes
            var alreadyViewed = new Array();
            alreadyViewed = existingCookie.split(',');

            // If all quotes have been displayed create a fresh new cookie.
            // If the number of already viewed quotes is larger than the total number of available quotes,
            // That means that the total number of quotes recently changed and having the number of already viewed quotes
            // larger than the total number of available quotes will result in a infinite loop below.
            if (alreadyViewed.length >= numOfQuotes)
            {            
                existingCookie = "";
                getRandNum();
                createCookie(cookieName, randNum, expDays);    
            }
            else
            {        
                var uniqueNum = false;

                // Select a random number that hasn't been used yet
                while(!uniqueNum)
                {
                    getRandNum();
                    uniqueNum = true;    
        
                    for (var i=0; i < alreadyViewed.length; i++)
                    {                
                        if (randNum == parseInt(alreadyViewed[i]))
                        {
                            uniqueNum = false;
                            break;                    
                        }
                    }
                }

                createCookie(cookieName, existingCookie+','+randNum, expDays)
            }
        }
        
        // Determining which language alt tag to use
        if (lang == "ENG")
            alt = altENG[randNum];
        else
            alt = altFRC[randNum];
        
        document.write("<img src='/images/core/quote"+lang+randNum+".jpg' alt='"+alt+"' border='0' width='555' height='165' vspace='0' hspace='0'>");                
    }
    

    function getRandNum()
    {
        randNum = Math.floor(Math.random()*numOfQuotes+1);
    }
    
    function createCookie(name,value,days) 
    {
        if (days) 
        {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else 
            var expires = "";
        
        document.cookie = name+"="+value+expires+"; path=/";
    }

    function eraseCookie(name) 
    {
        createCookie(name,"",-1);
    }

    function getCookie(name) 
    {
        var allCookies = document.cookie;
        var prefix = name + "=";
        var search = allCookies.indexOf("; " + prefix);
        
        if (search == -1) 
        {
            search = allCookies.indexOf(prefix);
            
            if (search != 0) 
                return null;
        } 
        else
            search += 2;
        var end = document.cookie.indexOf(";", search);
        
        if (end == -1)
            end = allCookies.length;
        return unescape(allCookies.substring(search + prefix.length, end));
    }