/* 	
	weboscope.js					 
	Weboscope version 4.0 copyright Weborama 04-01-2003
	Inclus le module de profiling
*/

var mon_pfl_id = 227356;

//////////////////////////////////////////////////////////////////////
// Debut fonctions profiling
/////////////////////////////////////////////////////////////////////



var mon_pfl_domaine = '';

var WEBO_PFL1='';
var WEBO_PFL2='';
var WEBO_PFL3='';
var WEBO_PFL4='';
var WEBO_PFL5='';

var mon_pfl_cookie = 'wbo_segment_' + mon_pfl_id;

function maj_segment(numero,valeur)
{
	if(parseInt(navigator.appVersion,10)<=3) return -1;
	nb_mois = 12;

	numero = parseInt(numero,10);
	if ((numero < 1) || (numero > 5)) return -2;
	
	var verif_val_I = /^\d+$/;
	if(verif_val_I.test(valeur)) valeur = encode_en_lettre(valeur);
	
	var verif_val_A = /^\w*$/; 
	if(verif_val_A.test(valeur))
	{
	
		var mon_profil_wbo = GetCookie(mon_pfl_cookie);
		tab_segment = new Array('','','','','');

		if(mon_profil_wbo != null)
		{
			tab_segment = mon_profil_wbo.split('|');
			if(tab_segment.length != 5) tab_segment = ('','','','','');
			
			//On vérifie qu une mise ŕ jour est nécessaire.
			if(tab_segment[numero - 1]==valeur) return 1;
			
		}
			
		if(mon_pfl_domaine='')
		{
			mon_pfl_domaine = this.location.host;
			tab_points = new Array();
			tab_points = this.location.host.split('.');
			if(tab_points.length>2) mon_pfl_domaine = mon_pfl_domaine.substring(mon_pfl_domaine.indexOf('.'),mon_pfl_domaine.length);
			if(tab_points.length==2) mon_pfl_domaine = '.' + mon_pfl_domaine;
		}
		

		
		var ma_chaine_profil='';
		for(var i=1; i<=5; i++)
		{
			
			if(i==numero) tab_segment[i-1]=valeur;
			if((tab_segment[i-1]=='') || (tab_segment[i-1]==null)) tab_segment[i-1] = '';
			ma_chaine_profil += tab_segment[i-1];
			
			if(i<5) ma_chaine_profil += '|';
		}
		
		
		expd = new Date();
		expd.setTime(expd.getTime() + (nb_mois * 30 * 24 * 3600 * 1000));
		SetCookie (mon_pfl_cookie,ma_chaine_profil,expd,'/',mon_pfl_domaine);
		return 2;
		
	}
	else return -3;
	
}
function raz_segment()
{
	//destruction du cookie
	expd = new Date();
	expd.setTime(expd.getTime() - (24 * 3600 * 1000));
	SetCookie (mon_pfl_cookie,'||||',expd,'/',mon_pfl_domaine);
}

function recup_param_profil()
{
	var mes_param_pfl = GetCookie(mon_pfl_cookie);
	if(mes_param_pfl == null)
	{
		mes_pfl = new Array('','','','','');
		if(WEBO_PFL1 != '') mes_pfl[0]=WEBO_PFL1;
		if(WEBO_PFL2 != '') mes_pfl[1]=WEBO_PFL2;
		if(WEBO_PFL3 != '') mes_pfl[2]=WEBO_PFL3;
		if(WEBO_PFL4 != '') mes_pfl[3]=WEBO_PFL4;
		if(WEBO_PFL5 != '') mes_pfl[4]=WEBO_PFL5;
		
		mes_param_pfl = '';
		var verif_val_I = /^\d+$/;
		for(var i=1;i<=5;i++)
		{
			if(verif_val_I.test(mes_pfl[i-1])) mes_pfl[i-1] = encode_en_lettre(mes_pfl[i-1]);
			mes_param_pfl += mes_pfl[i-1];
			if(i<5) mes_param_pfl += '|';
		}	
	}
	return mes_param_pfl;
}

function encode_en_lettre(num)
{
	num = parseInt(num,10);
	if(num > 2500) return '';
	var num1 = parseInt(num/52,10);
	var num2 = num % 52;

	num1 += 65;
	if (num1>90) num1+=6;
	
	num2 += 65;
	if (num2>90) num2+=6;
	
	var mon_code52 = String.fromCharCode(num1) + String.fromCharCode(num2);
	return mon_code52;
}

//////////////////////////////////////////////////////////
//fin fonctions profiling
//////////////////////////////////////////////////////////

function webo_zpi(_WEBOZONE,_WEBOPAGE,_WEBOID,_ACC)
{
        var wbs_da=new Date();
        wbs_da=parseInt(wbs_da.getTime()/1000 - 60*wbs_da.getTimezoneOffset());
	var wbs_ref=''+escape(document.referrer);
	var wbs_ta='0x0';
	var wbs_co=0;
	var wbs_nav=navigator.appName;
	var wbs_pfl = escape(recup_param_profil());	

	if (parseInt(navigator.appVersion)>=4)
	{
		wbs_ta=screen.width+"x"+screen.height;
		wbs_co=(wbs_nav!="Netscape")?screen.colorDepth:screen.pixelDepth;
	}
	if((_ACC != null)&&(wbs_nav!="Netscape"))
	{
		var reftmp = 'parent.document.referrer';
		if((_ACC<5)&&(_ACC>0))
		{
			for(_k=_ACC;_k>1;_k--) reftmp = 'parent.' + reftmp;
		}
		var mon_ref = eval(reftmp);

		if(document.referrer == parent.location || document.referrer=='') wbs_ref=''+escape(mon_ref)

	}

	var wbs_arg = ".weborama.fr/fcgi-bin/comptage.fcgi?ID="+_WEBOID;
	if ( location.protocol == 'https:'){
	 	wbs_arg = "https://ssl" + wbs_arg;
	}
	else {
		wbs_arg =  "http://pro" + wbs_arg; 
	}

	wbs_arg+="&ZONE="+_WEBOZONE+"&PAGE="+_WEBOPAGE+"&WEBOPFL="+wbs_pfl;
	wbs_arg+="&ver=2&da2="+wbs_da+"&ta="+wbs_ta+"&co="+wbs_co+"&ref="+wbs_ref;
	var wbs_t= " border='0' height='1' width='1' alt=''>";

	if (parseInt(navigator.appVersion)>=3)
	{
		webo_compteur = new Image(1,1);
		webo_compteur.src=wbs_arg;
	}
	else
	{
		document.write('<IMG SRC="'+wbs_arg+wbs_t);
	}
}

// Compatible
function webossl_zpi(_WEBOZONE,_WEBOPAGE,_WEBOID,_ACC) {
	webo_zpi(_WEBOZONE,_WEBOPAGE,_WEBOID,_ACC);
}

function flash_zpi(_WEBOZONE,_WEBOPAGE,_WEBOID,_ACC) {
	webo_zpi(_WEBOZONE,_WEBOPAGE,_WEBOID,_ACC);
}


webo_ok = 1;
webossl_ok = 1;
weboflash_ok=1;

////////////////////////////////////////////////////////////
//
// Librairie pour les cookies
//

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
	

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name,value,expires,path,domain,secure) 
{
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}



