
var pprMarque = {
    pprMarque:{co:'W6G18',mappedCo:'W6GGG'},
    doChangeBackgroundImage:false,
    gclid:null,
    getURLParam:function (strParamName, isCaseSensitive)
    {
        var strReturn = "";
        var strHref = window.location.href;
        if ( strHref.indexOf("?") > -1 ){
            var strQueryString = (isCaseSensitive!=undefined && isCaseSensitive) ? strHref.substr(strHref.indexOf("?")) : strHref.substr(strHref.indexOf("?")).toLowerCase();
            var aQueryString = strQueryString.split("&");
            for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
                if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
                    var aParam = aQueryString[iParam].split("=");
                    strReturn = aParam[1];
                    break;
                }
            }
        }
        return unescape(strReturn);
    },
    run:function()
    {
    	//traitement du co
    	co = this.getURLParam('co');
    	if(co!="")
    	   cookie_writeCookie('co',co,null,'/');
    	   
        co = cookie_readCookie('co');

        var flag = cookie_readCookie('pprMarqueFlag');
        if(flag)
        {
            //déjà fait
            if(co.toUpperCase() == this.pprMarque.mappedCo)
            {
                //alert('home avec num telephone co=' + co);
                this.doChangeBackgroundImage = true;
            }
        }
        else
        {
            //jamais fait
            if(co.toUpperCase()==this.pprMarque.co)
            {
                co=(Math.round(Math.random())==1) ? this.pprMarque.co : this.pprMarque.mappedCo;
                cookie_writeCookie('pprMarqueFlag','1',null,'/');
            }
            this.redirect(co);
        }
    },
    showEncartPhone:function(){
        var divEncart = document.getElementById('block_ii');
        if(this.doChangeBackgroundImage)
        {
            divEncart.innerHTML = '';
            divEncart.style.backgroundImage = 'url(/system/modules/com.tangane.mediatis.www/resources/img/home/backBlock_encart.png)';
        }
        divEncart.style.visibility = 'visible';
    },
    redirect:function(_co){
        this.gclid = this.getURLParam('gclid',true);
        this.gclid = (!this.gclid) ? '' : ('&gclid='+this.gclid);
        if(_co == this.pprMarque.mappedCo)
            location.replace('?co=' + this.pprMarque.mappedCo + this.gclid);
    }
    
}

var co;
pprMarque.run();