if (document.images) {
  pic1= new Image();
  pic1.src="http://www.adwit.net/intext/templates/images/in-text_top.png";
  pic2= new Image();
  pic2.src="http://www.adwit.net/intext/templates/images/in-text_logo.png";
  pic3= new Image();
  pic3.src="http://www.adwit.net/intext/templates/images/in-text_close.png";
  pic4= new Image();
  pic4.src="http://www.adwit.net/intext/templates/images/in-text_tlc.png";
  pic5= new Image();
  pic5.src="http://www.adwit.net/intext/templates/images/in-text_trc.png";
  pic6= new Image();
  pic6.src="http://www.adwit.net/intext/templates/images/in-text_l.png";
  pic7= new Image();
  pic7.src="http://www.adwit.net/intext/templates/images/in-text_r.png";
  pic8= new Image();
  pic8.src="http://www.adwit.net/intext/templates/images/in-text_blc.png";
  pic9= new Image();
  pic9.src="http://www.adwit.net/intext/templates/images/in-text_brc.png";
  pic10= new Image();
  pic10.src="http://www.adwit.net/intext/templates/images/in-text-b.png";
  pic11= new Image();
  pic11.src="http://www.adwit.net/intext/templates/images/in-text_r.png";
}

var awx_al = 0;

var in_text = {
  actifTimeOut: '',
  actifTimeOutName: '',
  kC: '', 
  _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 = {
  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();
  },
  _getContent : function () {
    if (this.it_imageurl.toLowerCase().substr(this.it_imageurl.toLowerCase().length-10, 10)=='=ghost.gif') {
      this.to_print[0] = '<div id="in-text_inner"><div id="in-text_tl"></div><div id="in-text_tr" onclick="document.getElementById(\'in-text\').style.visibility=\'hidden\';"></div><div id="in-text_bl"><div id="in-text_tlc"></div><div id="in-text_l"></div></div><div id="in-text_content" onclick="windowsopen(\''+this.it_hiddenurl+'\','+this.it_target+');"><div id="in-text_title2">'+this.it_title+'</div><div id="in-text_text2">'+this.it_description+'</div><div id="in-text_url2">'+this.it_url+'</div><div id="in-text_btn2"><img src="http://www.adwit.net//intext/templates/images/savoir_plus.png" width="104" height="21" border="0"></div></div><div id="in-text_br"><div id="in-text_trc"></div><div id="in-text_r"></div></div><div id="in-text_blc"></div><div id="in-text_bc"></div><div id="in-text_brc"></div></div>';
    } else {
      this.to_print[0] = '<div id="in-text_inner"><div id="in-text_tl"></div><div id="in-text_tr" onclick="document.getElementById(\'in-text\').style.visibility=\'hidden\';"></div><div id="in-text_bl"><div id="in-text_tlc"></div><div id="in-text_l"></div></div><div id="in-text_content" onclick="windowsopen(\''+this.it_hiddenurl+'\','+this.it_target+');"><div id="in-text_logo"><img src="'+this.it_imageurl+'" width="120" height="120" border="0"></div><div id="in-text_title">'+this.it_title+'</div><div id="in-text_text">'+this.it_description+'</div><div id="in-text_url">'+this.it_url+'</div><div id="in-text_btn"><img src="http://www.adwit.net//intext/templates/images/savoir_plus.png" width="104" height="21" border="0"></div></div><div id="in-text_br"><div id="in-text_trc"></div><div id="in-text_r"></div></div><div id="in-text_blc"></div><div id="in-text_bc"></div><div id="in-text_brc"></div></div>';
    }
    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(),
  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;
  },
  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);
      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) {
  // ici il faut spliter la liste de mot clé
    this.kV = keywordList;
    this.sZ = size;
    this.urlCRC = urlCRC;
    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://www.adwit.net/script/intext-save.php?key='+awsXpress_zone+'&keywords='+in_text_URLencode(this.kF)+'&size='+this.sZ+'&urlCRC='+this.urlCRC;
    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://www.adwit.net/script/intext.php?key='+awsXpress_zone+'&from='+in_text_URLencode(window.location)+'&iso='+AdWitServer_iso+'&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;
}
