/*
* tf1.js : permet d afficher les publicites publisher une fois la page chargee
* Last update : 2010-10-01
*/

/* main library */
document.write('<scr'+'ipt type="text/javascript" src="http://cstatic.weborama.fr/js/adperf_publisher.js"></scr'+'ipt>');

var weboramaAds = window['weboramaAds'] || (function () {
    var secteurs = Array(), ids = Array(), urls = Array(), secteurs_matching = Array();
    
    /*** Init ***/
    secteurs_matching.push([1, 9]); /* Boissons */
    secteurs_matching.push([2, 2]); /* Alimentation */
    secteurs_matching.push([4, 18]); /* Habillement - accessoires textiles */
    secteurs_matching.push([7, 5]); /* Appareils mégers */
    secteurs_matching.push([8, 3]); /* Ameublement - dération */
    secteurs_matching.push([9, 16]); /* Entretien */
    secteurs_matching.push([10, 19]); /* Toilette - Beauté/
    secteurs_matching.push([11, 7]); /* Automobile - Transport */
    secteurs_matching.push([12, 30]); /* Voyage - Tourisme */
    secteurs_matching.push([13, 14]); /* Energie */
    secteurs_matching.push([15, 15]); /* Enseignement - Formation */
    secteurs_matching.push([16, 13]); /* Edition */
    secteurs_matching.push([17, 12]); /* Distribution - VAD */
    secteurs_matching.push([18, 17]); /* Ets Financiers - Assurances, Services */
    secteurs_matching.push([19, 1]); /* Jardinage - Bricolage - Agriculture */
    secteurs_matching.push([20, 28]); /* Services */
    secteurs_matching.push([21, 20]); /* Immobilier */
    secteurs_matching.push([23, 10]); /* Corporate */
    secteurs_matching.push([26, 27]); /* Pharmacie - Medecine */
    secteurs_matching.push([30, 6]); /* Audiovisuel - Photo - Ciné */
    secteurs_matching.push([32, 11]); /* Culture et loisirs */
    secteurs_matching.push([33, 22]); /* Information méa */
    secteurs_matching.push([49, 29]); /* Técommunication */
    secteurs_matching.push([50, 22, 23]); /* Informatique (dont bureautique - imprimantes) */
    secteurs_matching.push([55, 10]); /* BTP */
    secteurs_matching.push([70, 21]); /* Industrie */

    /*** Private ***/
    convert_to_weborama = function(id) {
        var i, data;

	if (secteurs_matching instanceof Array) {
           for (i = 0; i < secteurs_matching.length; i++) {
		data = secteurs_matching[i];		
		if (data instanceof Array && data.length >= 2 && data[0] === id) {
			return data.slice(1).join(',');
	        }
           }
        }

	return 0;
    };

    /*** API ***/
    return {

	    addSecteur: function (id) {
		var i, wid;
		
		wid = convert_to_weborama(id);
		if (wid === 0) {return false;}

		for (i = 0; i < secteurs.length; ++i) {
			if (secteurs[i] === wid) return false;
		}
		secteurs.push(wid);
		return true;
	    },  

    	    addId: function (e) { ids.push(e); },
    	    addUrl: function (e) { urls.push(e); },

	    /* mise a jour des iframe avec requete weborama */
	    display : function () {	
		// 1 - recuperation des secteurs d'activite a exclure
		var sec = secteurs.join(','), util_js, base_url, k, iframe, url;	

		// 2 - ecriture des codes .js	
		util_js = 'http://cstatic.weborama.fr/publisher/iframe.html?JS=';
		base_url = 'http://aimfar.solution.weborama.fr/fcgi-bin/diff.fcgi?';

		if ( ids instanceof Array && urls instanceof Array ) {
			for (k = 0; k < ids.length; ++k) {
				iframe = document.getElementById(ids[k]);
				if (urls[k] !== undefined) {
					url = base_url+urls[k]+'&nsa='+sec;
					if (iframe) iframe.src=util_js+escape(url);
				}
			}	  	
		}
		return true;
	    },
        };
	
}());

