adwitServer_server="ads.adwitserver.com";
/*adwitServer_server="adwitnet";*/
adwitServer_server_save="www.adwitserver.com";
/*adwitServer_server_save=adwitServer_server;*/
/*adwitServer_server_save="www.adwit-server-.com:3000";*/
var awx_al = 0;

var in_text = {
    actifTimeOut: '',
    actifTimeOutName: '',
    kC: '',
    _getGmt: function() {
        var d = new Date();
        var gmtHours = -d.getTimezoneOffset() / 60;
        return gmtHours;
    },
    _getTop: function (obj) {
        if (obj.offsetParent) return (obj.offsetTop + this._getTop(obj.offsetParent));
        else return (obj.offsetTop);
    },
    _getLeft: function (obj) {
        if (obj.offsetParent) return (obj.offsetLeft + this._getLeft(obj.offsetParent));
        else return (obj.offsetLeft);
    },
    _getST: function () {
        if (document.documentElement && document.documentElement.scrollTop) {
            theTop = document.documentElement.scrollTop;
        } else if (document.body) {
            theTop = document.body.scrollTop
        }
        return theTop;
    },
    _getSL: function () {
        if (document.documentElement && document.documentElement.scrollLeft) {
            theLeft = document.documentElement.scrollLeft;
        } else if (document.body) {
            theLeft = document.body.scrollLeft
        }
        return theLeft;
    },
    _pw: function () {
        return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;
    },
    starttime: function (obj) {
        this.actifTimeOut = window.setTimeout('in_text._hidethis()',2000);
        this.actifTimeOutName = obj.innerHTML;
    },
    stoptimeout: function () {
        if (this.actifTimeOutName!='') {
            window.clearTimeout(this.actifTimeOut);
            this.actifTimeOutName = '';
        }
    },
    _hidethis: function () {
        document.getElementById('in-text').style.visibility='hidden';
    },
    init: function (keyword_search) {
        this.keyword_search = keyword_search;
    },
    show: function (obj) {
        var myInText = document.getElementById('in-text');
        var myId = obj.name.substr(8);

        if (this.keyword_search.kC[myId][6]!='') {
            myInText.innerHTML = this.keyword_search.kC[myId][0]+'<img src="'+this.keyword_search.kC[myId][6]+'" width="1" height="1">';
            this.keyword_search.kC[myId][6]='';
        } else {
            myInText.innerHTML = this.keyword_search.kC[myId][0];
        }
//        myInText.style.backgroundColor = '#ff0000';
        myInText.style.width = this.keyword_search.kC[myId][1]+'px';
        myInText.style.height = this.keyword_search.kC[myId][2]+'px';
        myInText.style.zindex = '64999';
    
        if ((this._getTop(obj)-this._getST())<myInText.offsetHeight)
            myInText.style.top=(this._getTop(obj)+obj.offsetHeight)+'px';
        else
            myInText.style.top=(this._getTop(obj)-myInText.offsetHeight)+'px';
        if (((this._pw()-this._getLeft(obj))-this._getSL())<myInText.offsetWidth)
            myInText.style.left=(this._getLeft(obj)+obj.offsetWidth-myInText.offsetWidth)+'px';
        else
            myInText.style.left=this._getLeft(obj)+'px';
      
        myInText.style.visibility= 'visible';
        this.stoptimeout();
    }
}

var in_text_ban = {
    pic_preload : '',
    it_hiddenurl : '',
    it_imageurl : '',
    it_imagealt : '',
    it_hashview: '',
    it_hashpreview: '',
    it_height: 0,
    it_width: 0,
    it_target: 1,
    to_print: Array(),
    init : function (it_hashview, it_hashpreview, it_hiddenurl, it_imageurl, it_imagealt, it_target, it_width, it_height) {
        this.it_hiddenurl = it_hiddenurl;
        this.it_imageurl = it_imageurl;
        this.it_imagealt = it_imagealt;
        this.it_width = it_width;
        this.it_hashview = it_hashview;
        this.it_hashpreview = it_hashpreview;
        this.it_height = it_height;
        this.it_target = it_target;
        if (it_target==1) {
              this.it_target = '_blank';
        } else {
              this.it_target = '_parent';
        }
        return this._getContent();
    },
    _getContent : function () {
    
        if (this.it_imageurl.toLowerCase().substr(this.it_imageurl.toLowerCase().length-3, 3)=='swf') {
            this.to_print[0] = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"  WIDTH='+this.it_width+' HEIGHT='+this.it_height+'>  <PARAM NAME=movie VALUE="'+this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl)+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="'+this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl)+'" quality=high bgcolor=#FFFFFF  WIDTH='+this.it_width+' HEIGHT='+this.it_height+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
            var pic1= new Image();
            pic1.src=this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl);
        } else {
            this.to_print[0] = '<a href="#" onclick="windowsopen(\''+this.it_hiddenurl+'\','+this.it_target+');"><img width="'+this.it_width+'" height="'+this.it_height+'" src="'+this.it_imageurl+'"  id="in-text-img" border="0"></a>';
            this.pic_preload= new Image();
            this.pic_preload.src=this.it_imageurl;
        }
        this.to_print[1] = this.it_width;
        this.to_print[2] = this.it_height;
        this.to_print[3] = this.it_hashview;
        this.to_print[4] = this.it_hiddenurl;
        this.to_print[5] = this.it_target;
        this.to_print[6] = this.it_hashpreview;
        return this.to_print;
    }
}

var in_text_text = {
    tp : '',
    tn : '',
    pic_preload : '',
    it_title : '',
    it_description : '',
    it_url : '',
    it_hiddenurl : '',
    it_imageurl : '',
    it_hashview: '',
    it_hashpreview: '',
    it_height: 0,
    it_width: 0,
    it_target: 1,
    to_print: Array(),
    init : function (it_hashview, it_hashpreview, it_hiddenurl, it_imageurl, it_title, it_url, it_description, it_target, it_width, it_height) {
        this.it_url = it_url;
        this.it_imageurl = it_imageurl;
        this.it_title = it_title;
        this.it_description = it_description;
        this.it_hiddenurl = it_hiddenurl;
        this.it_width = it_width;
        this.it_hashview = it_hashview;
        this.it_hashpreview = it_hashpreview;
        this.it_height = it_height;
        this.it_target = it_target;
        if (it_target==1) {
              this.it_target = '_blank';
        } else {
              this.it_target = '_parent';
        }
        return this._getContent();
    },
    setTemplate: function (template, template_no_image) {
        this.tp=template;
        this.tn=template_no_image;
    },
    _getContent : function () {
        if (this.it_imageurl.toLowerCase()=='') {
            this.to_print[0] = this.tn;
        } else {
            this.to_print[0] = this.tp;
        }
        this.to_print[0] = this.to_print[0].replace(/%title%/gi,this.it_title);
        this.to_print[0] = this.to_print[0].replace(/%description%/gi,this.it_description);
        this.to_print[0] = this.to_print[0].replace(/%url%/gi,this.it_url);
        this.to_print[0] = this.to_print[0].replace(/%imageurl%/gi,this.it_imageurl);
        this.to_print[0] = this.to_print[0].replace(/%hiddenurl%/gi,this.it_hiddenurl);
        this.to_print[0] = this.to_print[0].replace(/%target%/gi,this.it_target);
        this.to_print[0] = this.to_print[0].replace(/%viewurl%/gi,this.it_hashview);
        this.pic_preload= new Image();
        this.pic_preload.src=this.it_imageurl;
        this.to_print[1] = this.it_width;
        this.to_print[2] = this.it_height;
        this.to_print[3] = this.it_hashview;
        this.to_print[4] = this.it_hiddenurl;
        this.to_print[5] = this.it_target;
        this.to_print[6] = this.it_hashpreview;
        return this.to_print;
    }
}

var in_text_video = {
    it_hiddenurl : '',
    it_imageurl : '',
    it_imagealt : '',
    it_hashview: '',
    it_hashpreview: '',
    it_height: 0,
    it_width: 0,
    it_widthban: 0,
    it_heightban: 0,
    it_keyid: 0,
    it_script: '',
    it_logoUrl: '',
    it_target: 1,
    to_print: Array(),
    init : function (it_hashview, it_hashpreview, it_hiddenurl, it_imageurl, it_imagealt, it_target, it_width, it_height, it_widthban, it_heightban, it_keyid, it_script, it_logoUrl) {
        this.it_hiddenurl = it_hiddenurl;
        this.it_imageurl = it_imageurl;
        this.it_imagealt = it_imagealt;
        this.it_width = it_width;
        this.it_hashview = it_hashview;
        this.it_hashpreview = it_hashpreview;
        this.it_height = it_height;
        this.it_widthban = it_widthban;
        this.it_heightban = it_heightban;
        this.it_target = it_target;
        this.it_keyid = it_keyid;
        this.it_script = it_script;
        this.it_logoUrl = it_logoUrl;
        if (it_target==1) {
        //      this.it_target = '_blank';
        } else {
        //      this.it_target = '_parent';
        }
        return this._getContent();
    },
    _getContent : function () {

        if (this.it_imageurl.toLowerCase().substr(this.it_imageurl.toLowerCase().length-3, 3)=='swf') {
            this.to_print[0] = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"  WIDTH='+this.it_width+' HEIGHT='+this.it_height+'>  <PARAM NAME=movie VALUE="'+this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl)+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="'+this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl)+'" quality=high bgcolor=#FFFFFF  WIDTH='+this.it_width+' HEIGHT='+this.it_height+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
            var pic1= new Image();
            pic1.src=this.it_imageurl+'?clickTAG='+in_text_URLencode(this.it_hiddenurl);
        } else {
            this.it_script = this.it_script.replace(/\"/gi,'\'');
            this.it_script = this.it_script.replace(/\'/gi,"\\\'");
            this.to_print[0] = '<a onclick="show_ads(200, \''+this.it_width+'\', \''+this.it_height+'\', \''+this.it_widthban+'\', \''+this.it_heightban+'\', \''+this.it_keyid+'\', \''+this.it_script+'\', \''+this.it_logoUrl+'\');return false;" href="#"><img src="'+this.it_imageurl+'" border="0" id="in-text-img"></a>';
            var pic1= new Image();
            pic1.src=this.it_imageurl;
        }
        this.to_print[1] = '300';//this.it_width;
        this.to_print[2] = '250';//this.it_height;
        this.to_print[3] = this.it_hashview;
        this.to_print[4] = this.it_hiddenurl;
        this.to_print[5] = this.it_target;
        this.to_print[6] = this.it_hashpreview;
        return this.to_print;
    }
}


var keyword_search = {
    kL : new Array(),
    kC : new Array(),
    kV : new Array(),
    kF : new Array(),
    iT : new Array(),
    tp : '',
    tn : '',
    sZ : 0,
    urlCRC : 0,
    iTt : new Array('A','H1','H2','H3','H4','H5','H6','TH','SCRIPT','NOSCRIPT','SELECT','OPTION','IFRAME','TITLE','TEXTAREA','DT','DL','DD','FIELDSET','LEGEND','ACRONYM','ADDRESS','LABEL','NOINTEXT','BR'),
    init: function () {
        for (var i=0; i < this.iTt.length; i +=1) {
            this.iT[this.iTt[i].toLowerCase()]=1;
        }
    },
    vIE: function (){
        return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):999;
    },
    setTemplate: function (template, template_no_image) {
        this.tn=template_no_image;
        this.tp=template;
    },
    addKeyword: function (paramToSplit, keyword, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13) {
        var ittemp;
        var temp;
        var imgUrl=param3.toLowerCase();
        if (paramToSplit==1) {
            this.kL.push(keyword);
            ittemp = in_text_ban.init(param1,param2, param3, param4, param5, param6, param7, param8);
            temp = Array(ittemp[0],ittemp[1],ittemp[2],ittemp[3],ittemp[4],ittemp[5],ittemp[6]);
            this.kC.push(temp);
        }
        if ((paramToSplit==3) && (aws_it_Gf()!=0) && (this.vIE()>=7)) {
            this.kL.push(keyword);
            ittemp = in_text_video.init(param1,param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13);
            temp = Array(ittemp[0],ittemp[1],ittemp[2],ittemp[3],ittemp[4],ittemp[5],ittemp[6]);
            this.kC.push(temp);
        }
        if (paramToSplit==0) {
            this.kL.push(keyword);
            in_text_text.setTemplate(this.tp, this.tn)
            ittemp = in_text_text.init(param1,param2, param3, param4, param5, param6, param7, param8, param9, param10);
            temp = Array(ittemp[0],ittemp[1],ittemp[2],ittemp[3],ittemp[4],ittemp[5],ittemp[6]);
            this.kC.push(temp);
        }
       
    },
    _removeKeyword: function (i) {
        this.kL[i]='';
    },
    trim: function (sString) {
        sString=sString.replace(/^\s*(.*)/, "$1");
        sString=sString.replace(/(.*?)\s*$/, "$1");
        return sString;
    },
    placeKeyword: function (etNode) {
        for (var i=0; i<this.kL.length; i+=1) {
            if (this.kL[i]!='') {
                var pos= etNode.nodeValue.search(eval('/\\b'+this.kL[i]+'\\b/i'));
                if (pos>=0) {
                    c4fAdvertPos = 1;
                    var inserA = document.createElement("A");
                    inserA.innerHTML = etNode.nodeValue.substr(pos, this.kL[i].length);
                    inserA.setAttribute ("class", "in-text_keyword");
                    inserA.className='in-text_keyword';
                    inserA.onmouseout = function (event) {
                        in_text.starttime(this)
                        }
                    //          alert(this.kC[i]);
                    inserA.onmouseover = function (event) {
                        in_text.show(this)
                        };
                    inserA.onclick = function (event) {
                        return false;
                    };
                    inserA.id = 'c4f_obja_'+i
                    inserA.name = 'c4f_obja'+i
                    inserA.setAttribute ("target", this.kC[i][5]);
                    inserA.href = this.kC[i][4];
          
                    var newstartline = document.createTextNode(etNode.nodeValue.substr(0, pos));
                    var newendline = document.createTextNode(etNode.nodeValue.substr(pos+this.kL[i].length));
          
                    etNode.nodeValue = etNode.nodeValue.substr(0, pos);
          
                    insertAfter(etNode.parentNode, inserA, etNode);
                    insertAfter(etNode.parentNode, newendline, inserA);
                    var pic1= new Image();
                    pic1.src=this.kC[i][3];
          
                    //          etNode.parentNode.insertBefore(newstartline, inserA);
                    //          etNode.nodeValue = etNode.nodeValue.substr(pos+this.kL[i].length);
                    //          etNode.parentNode.insertBefore(inserA, etNode);
                    //          etNode.parentNode.insertBefore(newstartline, inserA);
                    this._removeKeyword(i)
                }
            }
        //      alert(this.kL[i]+' '+pos+etNode.nodeValue);
        }
    },
    searchKeyword: function (etNode, level, lost) {
        var t=0;
        //    alert('on chercher les mots clés !')
    
        for (t=0;t<etNode.childNodes.length;t++) {
            var balise = etNode.childNodes[t].nodeName;
            //      if ((balise=='A') && (etNode.childNodes[t].className=='in-text_keyword')) {alert(etNode.childNodes[t].firstChild.nodeValue);}
            if (balise=='#text') {
                var thisNode = this.trim(etNode.childNodes[t].nodeValue).replace(/[\t\s\n\r]/gi," ");
                thisNode = thisNode.replace(/[ ]{2,}/gi," ");
                if (thisNode.length>1) {
                    if (level==1) {
                        this.valideKeyword(etNode.childNodes[t]);
                    } else {
                        this.placeKeyword(etNode.childNodes[t]);
                    }
          
                }
            } else if (((etNode.childNodes[t].childNodes.length>0)
                && (t<etNode.childNodes.length)
                && (this.iT[etNode.childNodes[t].nodeName.toLowerCase()]!=1)
                && (etNode.childNodes[t].className.toLowerCase().indexOf('nointext') == -1)
                && (etNode.childNodes[t].className.toLowerCase().indexOf('nopositext') == -1)
                && (etNode.childNodes[t].className.toLowerCase().indexOf('in-text_keyword') == -1)
                ) || (etNode.childNodes[t].className=='in-text_keyword')) {
                //        alert(etNode.childNodes[t].nodeName);
                this.searchKeyword(etNode.childNodes[t], level);
            }
        }
    },
    valideList: function (keywordList, size, urlCRC, iso, zone_id) {
        // ici il faut spliter la liste de mot clé
        this.kV = keywordList;
        this.sZ = size;
        this.urlCRC = urlCRC;
        this.iso = iso;
        this.zone_id = zone_id
        if (document.getElementById('adwitexpress')) {
            //        alert(document.getElementById('adwitexpress').innerHTML);
            keyword_search.searchKeyword(document.getElementById('adwitexpress'), 1);
        } else {
            //        alert('B');
            keyword_search.searchKeyword(document.body, 1);
        }
        this.sendData();
    },
    valideKeyword: function (etNode) {
        for (var i=0; i<this.kV.length; i+=1) {
            if (this.kV[i]!='') {
                var pos= etNode.nodeValue.search(eval('/\\b'+this.kV[i]+'\\b/i'));
                if (pos>=0) {
                    this.kF.push(this.kV[i]);
                }
            }
        }
    
    },
    sendData: function () {
        var script = document.createElement('script');
        if (document.getElementById('adwitexpress')) {
            var size =document.getElementById('adwitexpress').innerHTML.length;
        } else {
            var size =document.body.innerHTML.length;
        }
        script.src = 'http://'+adwitServer_server_save+'/script/intext_save?zone_id='+this.zone_id+'&key='+adwitServer_client+'&keywords='+in_text_URLencode(this.kF)+'&size='+this.sZ+'&urlCRC='+this.urlCRC+'&iso='+this.iso;
        script.type = 'text/javascript';
        script.id = 'loadScriptLinks4';
        document.documentElement.childNodes[0].appendChild(script);
    }
}

function insertAfter(parent, newElement, referenceElement){
    parent.insertBefore(newElement, referenceElement.nextSibling);
} 
function in_text_URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,' ').replace(/\'/g, ' ').replace(/\&/g, '%26');
}

function windowsopen(surl, starget) {
    if (starget==1) {
        window.open(surl);
    } else {
        document.location=surl;
    }
}

function alreadyload() {
    awx_al=1;
//  alert(awx_al);
}

function aws_checkiso() {
    for (t=0;t<document.getElementsByTagName("meta").length;t++) {
        contents = document.getElementsByTagName("meta")[t].content;
        findit = contents.match(/text\/html/gi);
        if (findit!=null) return contents.match(/[\w-]+$/gi);
    }
    return 0;
}

if (navigator.appName=="Microsoft Internet Explorer") {
    window.attachEvent("onload", alreadyload);
} else {
    window.addEventListener("load", alreadyload, false);
}
AdWitServer_iso = aws_checkiso();

var script = document.createElement('script');
var randomnumber=Math.floor(Math.random()*9999999);
script.src = 'http://'+adwitServer_server+'/script/intext.php?key='+adwitServer_client+'&from='+in_text_URLencode(window.location)+'&iso='+AdWitServer_iso+'&gmt='+in_text._getGmt()+'&rand='+randomnumber;
script.type = 'text/javascript';
script.id = 'loadScriptLinks';
document.documentElement.childNodes[0].appendChild(script);

function aws_makediv() {
    var posiads = document.getElementById('in-text');
    if (posiads) return;
    var bodyRef = document.getElementsByTagName("body").item(0);
    //point 2
    if (bodyRef == null) {
        bodyRef = document.documentElement.childNodes[0];
    }
  
    var aws_posiads = document.createElement("div");
    aws_posiads.setAttribute("id", "in-text");
    aws_posiads.setAttribute("name", "in-text");
    aws_posiads.onmouseout = function (event) {
        in_text.starttime(this)
        }
    aws_posiads.onmouseover = function (event) {
        in_text.stoptimeout(this)
        }
    aws_posiads.className = 'nointext';
    if (bodyRef.firstChild != null) {
        bodyRef.insertBefore(aws_posiads, bodyRef.lastChild);
    } else {
        bodyRef.appendChild(aws_posiads);
    }
}

function show_ads(mytop, width, height, widthban, heightban, bannerId, script, logoUrl) {
    nouveauDiv = document.createElement("div");
    nouveauDiv.innerHTML = "";
    nouveauDiv.id = "glasspane";
    nouveauDiv.className='glasspane';
    document.body.appendChild(nouveauDiv);
    temp = document.getElementById('aws_popunderback').innerHTML;
    temp = temp.replace(/aws_video/gi,script);
    temp = temp.replace(/http:\/\/aws_logourl\//gi,logoUrl);
    temp = temp.replace(/aws_bannerId/gi,bannerId);
    temp = temp.replace(/aws_widthban/gi,widthban);
    temp = temp.replace(/aws_heightban/gi,heightban);
    temp = temp.replace(/aws_width/gi,width);
    temp = temp.replace(/aws_height/gi,height);

    document.getElementById('aws_popunder').innerHTML = temp
    //        document.getElementById('popunder').style.top= mytop+'px';
    document.getElementById('aws_popunder').style.display = 'block';
}

function close_ads() {
    document.getElementById('aws_popunder').style.display = 'none';
    document.getElementById('aws_popunder').innerHTML = '';
    var olddiv = document.getElementById('glasspane');
    document.body.removeChild(olddiv);
}
function aws_it_Gf(){
    return 1;
}

