/// future generix loader
//----------------------------------------------------
//----------------------------------------------------
function CheckProperties(obj,prop) {		
if (typeof(obj[prop]) == "undefined") { 
return "";						
} 
else {
return obj[prop];
}
}
//----------------------------------------------------
//----------------------------------------------------
function SearchString( textToSearch, stringToFind) {
var text = textToSearch.toString() ;
var maReg = new RegExp( stringToFind, "gi") ;
if ( text.search( maReg ) == -1 )
return 0;
else
return 1;
}
//-----------------------------------------
//-----------------------------------------
function showProperties(obj,lstprop) {
var props = [];
for (var prop in obj) {
if (SearchString(lstprop,prop) || lstprop == '')
{				
if (prop == 'm' || prop == 't' || prop == 'n' || prop == 'co' || prop == 'u' || prop == 'un' || prop == 'oun' )
{
} else {
props.push('<br>'+prop+' : '+obj[prop]);
}
}
}
document.write(props.join(', '));
}
//------------------------------------
//------------------------------------
function IsNumeric(VarStr) {
var RegExp = /^(\d*)$/;
var result = VarStr.match(RegExp);
return result;
}
//---------------------------------------
//---------------------------------------
function debugDumpVar (obj,hidecode,lbl,filter) {	
var url_racine_param = document.location.href.toLowerCase().split("?");
if (url_racine_param.length > 1)
{
var list_param=url_racine_param[1].split('&')
for (i = 0; i <= list_param.length; i++) {
var par = list_param[i];
if (par == hidecode)
{
//---------------------------------------------------
//---------------------------------------------------					
document.write('<hr><strong>Dump variable -> '+lbl+' ['+filter+']:</strong><br>');
showProperties(obj,filter);
document.write('<br><br>Fin...');
}
}
}	
}
//----------------------------------------------
//----------------------------------------------
function qs(TheKey) {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
if (TheKey == key) {
return val;
}		
}
}
}
//---------------------------------------------
//- Function : ObjArrNbr(n,m,q,t)
//-					m -> Numérique, fin de la séquence
//-					q -> Numérique, Quantité de nombre désiré
//-					t -> String, type de tri désiré 
//-						 a : Ascendant
//-						 d : Descendant
//-						 r : Random
//- Ex. MyArr = new ObjArray(1,10,5,'r');
//- 
//---------------------------------------------
function ObjArrNbr(n,m,q,t) {
this.GlbArray = new  Array();
this.n = n;	//Séquence de départ
this.m = m; //Séquence de fin
this.q = q; //Quantité de nombre désiré (not used)
this.t = t; //Type de tri désiré (a,d,r)
//- Tri l'objet GlbArray random
this.SortRand = function(a, b) {
return (Math.round(Math.random()) - 0.5); 
}
//- Tri l'objet GlbArray Ascendant
this.SortAsc = function (a, b){ 
return (a-b); 
}
//- Tri l'objet GlbArray Descendant
this.SortDesc = function (a, b){ 
return (b-a); 
}
//- Popule l'objet GlbArray
this.BuildArr = function() {
for (x=this.n; x<=this.m; x++) {
this.GlbArray.push(x);
}
switch (this.t)
{
case 'a':
this.GlbArray.sort(this.SortAsc);
break;
case 'd':
this.GlbArray.sort(this.SortDesc);
break;
case 'r':
this.GlbArray.sort(this.SortRand);
break;
default:
break;
}
}	
} 
//---------------------------------------------
//- Function : ConcatWB(ConcatString, delimit)
//- 
//---------------------------------------------
function ConcatWB (ConcatString, delimit) {
if (!ConcatString == '')
{
return delimit + ConcatString;
} else {
return '';
}	
}
//---------------------------------------------
//- Functions : crawlerForFlashInfo et popupFlashInfoWindow
//- 
//---------------------------------------------
function crawlerForFlashInfo(){
for (var i=0; i<document.getElementById('flashinfobody').getElementsByTagName('a').length; ++i) {
var link = document.getElementById('flashinfobody').getElementsByTagName('a')[i];
if ( link.rel == 'flashinfo') {
link.onclick = function(){ return popupFlashInfoWindow('argent',this.href,950,690); }
}
}
}
function popupFlashInfoWindow(popupName,url,popupWidth,popupHeight){
win = window.open(url, popupName,"width=" + popupWidth + ",height=" + popupHeight + ",resizable=no,scrollbars=no,toolbar=no,status=no,location=no,directories=no");
//bug de NN4 quand focus trop vite, attend 0,25 sec
setTimeout('win.focus();',250);
return false;
}
function get_keyword(name){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";  
var regex = new RegExp( regexS );  
var results = regex.exec( window.location.href );  
if( results == null )    
return "";  
else    
return results[1];
}
function GetFlagDE( Posi )
{
var ActifDE = false; // TRUE: Tag DE, FALSE: Tag DFP
var ExceptionDE = 
{
button : 1,
advertorial : 1
}
return ( ExceptionDE[ Posi ] ) ? true : ActifDE; //DETag flag
}
function GetPosition( Pos, Obj ) 
{
var NameTranslation = 
{
fr : 	
{
skyscraper:	'bouton_7',
special1:	'special1',
special2:	'special2',
superbanner:    'bandeau',
bigbox:		'boite',
button:		'bouton_4',
popup:		'popup',
advertorial:    'publireportage',
banner:		'bandeau_1',
doublebox:	'doubleboite'
},
en : 	
{
skyscraper:	'button_7',
special1:	'special1',
special2:	'special2',
superbanner:	'superbanner',
bigbox:		'boite',
button:		'button_4',
popup:		'popup',
advertorial:	'publireportage',
banner:		'banner',
doublebox:	'doublebox'
}
}
return NameTranslation[ Obj.language ][ Pos ];
}
function GetDim( Posi )
{		
var tab = new Array;
tab[ "superbanner" ]	="728x90";
tab[ "bigbox" ]		="300x250";
tab[ "skyscraper" ]	="120x600,160x600";
tab[ "popup" ]		="500x500";
tab[ "banner" ]		="468x60";
tab[ "button" ]		="160x60";
tab[ "advertorial" ]	="306x140";
tab[ "special1" ]	="175x40";
tab[ "special2" ]	="175x40";
return tab[ Posi ];
}
//-----------------------------
//-----------------------------
function DfpVariables(){
this.mainsection = 'lcvtt';
this.sujet = '';
this.affiliate = '';
this.sectionLevel2 = 'forum';
this.sectionLevel3 = '';
this.language = 'fr';
this.division = 'aff';
this.hp="";
this.SwitchLang = this.language; // For some site fr and en are process the same way so hardcode this variable
this.networkid = 'can';
this.tile = 1;
this.rand_num = Math.floor(Math.random()*8999999999)+1000000000;
this.prov = '';
//etc..
this.de_site       = '';     // site
this.de_vchannel   = '';        // vertical
this.de_category   = '';             // categorie
this.de_subchannel = '';             // sous-vertical
this.de_hchannel   = '';      // sous-catégorie
this.dfpSwitch	= {
skyscraper:		0,
superbanner:	0,
bigbox:			0,
catfish: 		1,
special:		1,
special1:		1,
special2:		1,
button:			1,
popup:			1,
advertorial:	1,
banner:			1,
doublebox:		1
}
}
var MyGenericTagVar = new DfpVariables();
var _dcopt_data           = new Array();    // internal data
var _dcopt_html           = new Array();    // external html
var _dcopt_data_functions = new Array();    // internal functions
var CanoeAdCallVideo = 'http://ad.doubleclick.net/pfadx/can.'+MyGenericTagVar.language+'.'+MyGenericTagVar.division+'.'+MyGenericTagVar.mainsection;
//this section check all section level to return a value if there's  one.
if(MyGenericTagVar.sectionLevel2){
CanoeAdCallVideo = CanoeAdCallVideo + '/bcplayer-'+MyGenericTagVar.sectionLevel2 + ';';
}
if(MyGenericTagVar.sectionLevel3){
CanoeAdCallVideo = CanoeAdCallVideo + 'subz1=' + MyGenericTagVar.sectionLevel3 + ';';
}
if(MyGenericTagVar.sectionLevel4){
CanoeAdCallVideo = CanoeAdCallVideo + 'subz2=' + MyGenericTagVar.sectionLevel4 + ';';
}
if(MyGenericTagVar.sectionLevel5){
CanoeAdCallVideo = CanoeAdCallVideo + 'subz3=' + MyGenericTagVar.sectionLevel5 + ';';
}
if(MyGenericTagVar.dfpSpekey != null){
for (var itemKey in MyGenericTagVar.dfpSpeKey) {
var CanoeAdCallVideo = CanoeAdCallVideo + itemKey + '=' + MyGenericTagVar.dfpSpeKey[itemKey] + ';';
}
}
var CanoeAdCallBigbox = 'http://ad.doubleclick.net/adi/can.'+MyGenericTagVar.language+'.'+MyGenericTagVar.division+'.'+MyGenericTagVar.mainsection;
//this section check all section level to return a value if there's  one.
if(MyGenericTagVar.sectionLevel2){
CanoeAdCallBigbox = CanoeAdCallBigbox + '/bcplayer-'+MyGenericTagVar.sectionLevel2 + ';';
}
if(MyGenericTagVar.sectionLevel3){
CanoeAdCallBigbox = CanoeAdCallBigbox + 'subz1=' + MyGenericTagVar.sectionLevel3 + ';';
}
if(MyGenericTagVar.sectionLevel4){
CanoeAdCallBigbox = CanoeAdCallBigbox + 'subz2=' + MyGenericTagVar.sectionLevel4 + ';';
}
if(MyGenericTagVar.sectionLevel5){
CanoeAdCallBigbox = CanoeAdCallBigbox + 'subz3=' + MyGenericTagVar.sectionLevel5 + ';';
}
if(MyGenericTagVar.dfpSpekey != null){
for (var itemKey in MyGenericTagVar.dfpSpeKey) {
var CanoeAdCallBigbox = CanoeAdCallBigbox + itemKey + '=' + MyGenericTagVar.dfpSpeKey[itemKey] + ';';
}
}
function fctDcopt() {
var params = (arguments.length) ? arguments[0] : {};
//----------------------
for (var type in _dcopt_html) {
if ( typeof(_dcopt_html[type]) == "function" ) continue;
var html = _dcopt_html[type];
//----------------------
var div = document.createElement('div');
div.setAttribute('id', 'dcopt_'+type);
document.body.appendChild(div);
//----------------------
if (typeof(_dcopt_data_functions[type]) == 'function') {
_dcopt_data_functions[type](params);
}
//----------------------
document.getElementById('dcopt_'+type).innerHTML = html;
}
return false;
}
function get_dcopt(mytile){
if( mytile == 1 ) {
dcopt =  'ist';  
}
else{
dcopt =  ''; 
}	    
return dcopt;
}
function buildTag(tag_start,tag_end,tag_options,seperator) {
var ad_tag = tag_start;
for (var i in tag_options) {
if(tag_options[i] != "" && ( typeof(tag_options[i]) == 'string' || typeof(tag_options[i]) == 'number')  ) {
if (ad_tag != "") ad_tag += seperator;
ad_tag = ad_tag + i + "=" + tag_options[i];
}
}
ad_tag =  ad_tag + tag_end;
return ad_tag;
}
function fctAdTag(position,objDfp,posId)
{				
var size = GetDim(position); // Size Variable
var my_dcopt =get_dcopt(objDfp.tile); // DCOPT Variable
var my_keyword = get_keyword( 'q' );// motcle variable in LaToile
my_keyword = my_keyword.replace(/%20/,"+");
var tag_options = new Array();
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
if ( objDfp.dfpSwitch != null && objDfp.dfpSwitch[position] ) {
return;
} else {			
var tag_start = '<script type="text\/javascript" src="http:\/\/ad.doubleclick.net\/adj\/'+objDfp.networkid+'.'+objDfp.language+'.'+objDfp.division+'.'+objDfp.mainsection+'\/'+objDfp.sectionLevel2;
var tag_end = '?"><\/script>';
var seperator = ";";
tag_options["subz1"] = CheckProperties(objDfp,'sectionLevel3');
tag_options["subz2"] = CheckProperties(objDfp,'sectionLevel4');
tag_options["subz3"] = CheckProperties(objDfp,'sectionLevel5');
tag_options["kw"] = CheckProperties(objDfp,'my_keyword');
tag_options["tile"] = CheckProperties(objDfp,'tile');
tag_options["sz"] = size;
tag_options["dcopt"] = my_dcopt;
tag_options["pos"] = posId;
//---------------------------------//
//-- optional: add special keys  --//
//---------------------------------//
if (objDfp.dfpSpeKey != null) {			
for (var itemKey in objDfp.dfpSpeKey) {
tag_options[itemKey] = objDfp.dfpSpeKey[itemKey];					
}
}
if (CheckProperties(objDfp,'ForceHP') != "") { 
tag_options["hp"] = CheckProperties(objDfp,'ForceHp');
} else {
if (( CheckProperties(objDfp,'sectionLevel2') != '' 
&& CheckProperties(objDfp,'sectionLevel2') != 'accueil' 
&& CheckProperties(objDfp,'sectionLevel2') != 'home'
)
|| 
( CheckProperties(objDfp,'sectionLevel3') != '' 
&& CheckProperties(objDfp,'sectionLevel3') != 'accueil'
&& CheckProperties(objDfp,'sectionLevel3') != 'home' 
)
){
tag_options["hp"] = 1;
}			
}
tag_options["mk"] = CheckProperties(objDfp,'mk');
tag_options["mdl"] = CheckProperties(objDfp,'mdl'); // note l is lower case L
tag_options["prov"] = CheckProperties(objDfp,'prov');
//ord must always be the last item in the array
tag_options["ord"] = CheckProperties(objDfp,'rand_num');
document.write(buildTag(tag_start,tag_end,tag_options,seperator));
}
objDfp.tile++;
}
var canoeCatfish = {};	
canoeCatfish._css      = '';
canoeCatfish._link     = '';
canoeCatfish._swf      = '';
canoeCatfish._height   = 0;
canoeCatfish._position = 0;
canoeCatfish._opened   = false;
canoeCatfish._interval = 0;
canoeCatfish._generateHTML = function() {
var cssNode   = document.createElement('link');
cssNode.type  = 'text/css';
cssNode.rel   = 'stylesheet';
cssNode.href  = canoeCatfish._css;
cssNode.media = 'screen';
document.getElementsByTagName("head")[0].appendChild(cssNode);
var content = '';
if (canoeCatfish._swf) {
content = ''+
'swf: '+canoeCatfish._swf+
'';
} else {
content = ''+
'<div id="catfishInner">'+
'	<div id="catfishTop"></div>'+
'	<a href="'+ canoeCatfish._link +'" id="catfishLink" target="_blank"></a>'+
'	<a href="#" onclick="return canoeCatfish.close();" id="catfishClose">close</a>'+
'</div>'+
'';
}
return '<div id="catfish">'+content+'</div>';
};
canoeCatfish._open = function() {
canoeCatfish._position = -canoeCatfish._height;
canoeCatfish._interval = setInterval('canoeCatfish._do_open()',10);
};
canoeCatfish._do_open = function() {
canoeCatfish._position += 10;	
if (canoeCatfish._position >= 0) {
canoeCatfish._position = 0;
canoeCatfish._opened = true;
clearInterval(canoeCatfish._interval);
}
document.getElementById('catfish').style.bottom = canoeCatfish._position+'px';
};
canoeCatfish._do_close = function() {
canoeCatfish._position -= 10;	
if (canoeCatfish._position <= -canoeCatfish._height) {
canoeCatfish._position = -canoeCatfish._height;
canoeCatfish._opened = false;
clearInterval(canoeCatfish._interval);
}
document.getElementById('catfish').style.bottom = canoeCatfish._position+'px';
};
canoeCatfish.isOpened = function() {
return canoeCatfish._opened;
};
canoeCatfish.setCss = function(css) {
canoeCatfish._css = css;
};
canoeCatfish.setLink = function(link) {
canoeCatfish._link = link;
};
canoeCatfish.setHeight = function(height) {
canoeCatfish._height = height;
};
canoeCatfish.setSwf = function(swf) {
canoeCatfish._swf = swf;
};
canoeCatfish.getHTML = function() {
return canoeCatfish._generateHTML();
};
canoeCatfish.appendToDcopt = function() {
_dcopt_html['catfish'] = canoeCatfish._generateHTML();
};
canoeCatfish.open = function(timeout) {
setTimeout('canoeCatfish._open()',(timeout) ? timeout : 0);
return false;
};
canoeCatfish.close = function() {
canoeCatfish._position = 0;
canoeCatfish._interval = setInterval('canoeCatfish._do_close()',10);
return false;
};
canoeCatfish.openOnLoad = function(timeout) {
timeout = (timeout) ? timeout : 0;
if (window.addEventListener){
eval("window.addEventListener('load', function() { canoeCatfish.open("+timeout+"); }, false);");
} else if (window.attachEvent){
eval("window.attachEvent('onload', function() { canoeCatfish.open("+timeout+"); });");
}
return false;
};

