var compteurSlide = 0;
var tabSlide      = new Array();
var objectLnk     = null;
function C_handlerEvenement(self){
if(self.xmlhttp.readyState == 4) {
reponse = self.xmlhttp.responseText;
var r = reponse.parseJSON();
if(r['actif'] == '1')
afficherPromo(r);
}
}
function ClientPromo(){
this.parent = ClientService;
this.parent();
this.handlerEvenement = C_handlerEvenement;
}
function imageUrl(img, url) {
this.img = img; 
this.url = url;
}
function lancerPromo(){
var url = document.getElementsByTagName('base')[0].href;
client = new ClientPromo();
client.setUrl(url+'/achatFichiers/server_ajax.php?service=getPromo');
client.executer();
}
function afficherPromo(p_infos){
var bib = new Bibliotheque();
var nomCookie = 'cpt_promo';
var cookie = bib.getCookie(nomCookie);
if(cookie == "")
cookie = 1;
else
cookie = eval(cookie) + 1;
bib.setCookie(nomCookie, cookie);
if(cookie <= p_infos['nbAffichagePromo']){ 
var left = (screen.width - eval(p_infos['largeurPromo']))/2;
var top = (screen.height - eval(p_infos['hauteurPromo']))/2;
var promo = window.open(p_infos['URLPromo'],"promo",
"width="+p_infos['largeurPromo']+
",height="+p_infos['hauteurPromo']+
",left="+left+",top="+top+",location=no,menubar=no,status=no,toolbar=no");
promo.focus();
}
}
function slideStart(param) {
compteurSlide = 0;
tabSlide      = param.split(';');
objectLnk     = document.getElementById('pub_autres');
slideElement();
}
function slideElement() {
tabElementSlide = tabSlide[compteurSlide].split('!');
delaySlide      = parseInt(tabElementSlide[0]);
elementSlide    = tabElementSlide[1];
ajoutElement(elementSlide);
compteurSlide   = (compteurSlide + 1) % tabSlide.length;
setTimeout("slideElement()", delaySlide);
}
function ajoutElement(listAffichage) {
divPub = objectLnk;
if (divPub) {
supprimerNoeudsElement(divPub);
framesAffichage = listAffichage.split(',');
nbFrames        = framesAffichage.length;
for (i=0; i<nbFrames; i++) {
frame  = framesAffichage[i].split('|');
src    = frame[0];
ext    = src.substring(src.lastIndexOf('.')+1, src.length);
css    = frame[1];
width  = frame[2];
height = frame[3];
url    = frame[4];
if (ext == 'swf') {
ajouterFlash(divPub, src, css, width, height)
} else {
ajouterLienImage(divPub, src, css, width, height, url);
}
}
}
}
function supprimerNoeudsElement(noeud) {
if ((noeud != undefined) && (noeud != null)) {
while (noeud.hasChildNodes()) {
noeud.removeChild(noeud.firstChild);
}
}
}
function ajouterLienImage(objConteneur, src, style, width, height, url) {
if (url != '') {
objLnk           = document.createElement('a');
objLnk.href      = url;
objLnk.target    = "_blank;";
objLnk.className = style;
objConteneur.appendChild(objLnk);
objImg           = document.createElement('img');
objImg.src       = src;
objImg.border    = 0;
objImg.width     = width;
objImg.height    = height;
objLnk.appendChild(objImg);
} else {
objImg           = document.createElement('img');
objImg.src       = src;
objImg.className = style;
objImg.border    = 0;
objImg.width     = width;
objImg.height    = height;
objConteneur.appendChild(objImg);
}
}
function ajouterFlash(objConteneur, src, style, width, height) {
objDiv           = document.createElement('div');
objDiv.className = style;
objConteneur.appendChild(objDiv);
objFlash         = document.createElement('embed');
objFlash.src     = src;
objFlash.target  = "_blank;";
objFlash.width   = width;
objFlash.height  = height;
objFlash.quality = 'high';
objFlash.scale   = 'exactfit';
objFlash.wmode   = 'opaque';
objDiv.appendChild(objFlash);
}
