var DartOrd = Math.round(Math.random() * 10000000000000000);		  //Dart ord
if (typeof (DartTile) === 'undefined') {var DartTile = 0;} 				//Dart tile
var DartCharInterdit = '&^@%#`|     ,"*()=.[]';				  					//Liste des charactères interdit par Dart

/*
GetDartSiteName : retourne le Dart.SiteName correspondant au url courant
*/
function GetDartSiteName()
{
	var CurrentSite = (window.location.href).toLowerCase();
	var DartSite = ''; 

	switch (true)  
	{
	   //75e de Radio-Canada
	   case ( CurrentSite.indexOf('.radio-canada.ca/75') > -1 ||  
	   				CurrentSite.indexOf('75.radio-canada.ca') > -1 	):
		      DartSite = 'raca.75.rc.ca' ;
		      break;
		      
		 //Jeunesse     
	   case ( CurrentSite.indexOf('jeunesse') > -1 ):
		      DartSite = 'raca.jeunesse' ;
		      break;
		      		      
		 //Radio-Canada.ca     
	   case ( CurrentSite.indexOf('.radio-canada.ca') > -1 ):
		      DartSite = 'raca.rc.ca' ;
		      break;
		      
		 //tou.tv
	   case ( CurrentSite.indexOf('.tou.tv') > -1 ):
		      DartSite = 'raca.tou.tv' ;
		      break;

		 //tou.mu
	   case ( CurrentSite.indexOf('.tou.mu') > -1 ):
		      DartSite = 'raca.tou.mu' ;
		      break;
		 
		 //RCINet	
	   case ( CurrentSite.indexOf('.rcinet.ca') > -1 ):
		      DartSite = 'raca.rci' ;
		      break;
		 
		 //BandeAPart.fm	
	   case ( CurrentSite.indexOf('.bandeapart.fm') > -1 ):
		      DartSite = 'raca.bap' ;
		      break;
		 
		 //Developpement     
	   case ( CurrentSite.indexOf('-www.radio-canada.ca') > -1 ||
	   				CurrentSite.indexOf('.radio-canada.dev') > -1    ||
	   				CurrentSite.indexOf('.radio-canada.pp') > -1    	):
		      DartSite = 'raca.dev' ;
		      break;

	   default: DartSite = 'raca.rc.ca' ;
		      break;
	}

		return DartSite.toLowerCase(); //Doit être en minuscule

}

/*
GetDartURLCall : retourne le url d'un call de pub vers Dart
*/
function GetDartURLCall(adType, adSize) 
{		
		var Site, Zone, KeyValue, URLCall, Interstitiel;
		
		Site = GetDartSiteName();
		
		Zone = ''; //Pas de Zone avant ère 2
		
		KeyValue = ''; //Pas de Key-Value avant ère 2
	
		//Protection : Si on dépasse les limites de Dart alors on fait quand même le call sans les valeurs problèmatiques
		
		//adType : ne doit pas dépasser 5 caractères et doit être en minuscule
		if(adType.length > 5 ) adType = 'adi';
		adType = adType.toLowerCase();
		
		//SiteName + ZoneName : ne doit pas dépasser 64 caractères
		if((Site.length + Zone.length) > 64 ) Zone = '';
		
		//KeyValue : la longeur total des Keys et les values ne doit pas dépasser 511 caractères (on doit se donner un buffer de 61 chars pour les keyvalue non custom)
		if(KeyValue.length > 450 ) KeyValue = '';
	
		//adsize : ne doit pas dépasser 15 caractères et doit être en minuscule
		if(adSize.length > 15 ) adSize = '1x1';
		adSize = adSize.toLowerCase(); 
				
		DartTile++;
		
		//Si on affiche la première pub alors on met le call pour l'interstitiel
		Interstitiel = (DartTile == 1 ) ? 'dcopt=ist;' : '' ;	
		
		return 'http://ad.ca.doubleclick.net/'+ adType + '/' + Site + '/' + Zone + ';' + Interstitiel + KeyValue + 'sz=' + adSize + ';tile=' + DartTile + ';ord=' + DartOrd + '?';	
		 
}


var sas_tmstp=Math.round(Math.random()*10000000000);
var sas_masterflag=1;

function getSmartFormat(_sas_formatid) {
	_sas_formatid = _sas_formatid*1;
	var _o;
	switch (_sas_formatid) {
		case 1841 : _o = {'_w':728, '_h':90, 'isJs':false}; break;
		case 1839 : _o = {'_w':300, '_h':250, 'isJs':false}; break;
		case 1846 : _o = {'_w':424, '_h':60, 'isJs':false}; break;
		case 1840 : _o = {'_w':160, '_h':600, 'isJs':false}; break;
		case 1847 : _o = {'_w':1000, '_h':70, 'isJs':false}; break;
		case 2639 : _o = {'_w':300, '_h':600, 'isJs':false}; break;
		case 3508 : _o = {'_w':104, '_h':60, 'isJs':false}; break;
		case 3542 : _o = {'_w':104, '_h':60, 'isJs':false}; break;
		default : return ""; break;
	}
	_o._smartSize = _o._w + "x" + _o._h;
	return _o;
};

function SmartAdServer_iframe(sas_pageid,sas_formatid,sas_target) {
	if (sas_formatid == 1847) {SmartAdServer_noiframe(sas_pageid,sas_formatid,sas_target);return false;}
	
	document.write(getPubSmart(sas_pageid,sas_formatid,sas_target));
};
function getSmartAdServer_iframe(sas_pageid,sas_formatid,sas_target) {return getPubSmart(sas_pageid,sas_formatid,sas_target);}

function getPubSmart(sas_pageid,sas_formatid,sas_target) {
	var _oPubInfo = getSmartFormat(sas_formatid);
	sas_master = (sas_masterflag==1) ? 'M' : 'S';
	sas_masterflag=0;
	
	var _sReturn = "";
	
	if (_oPubInfo._smartSize == "728x90") _sReturn += '<div class="srcPubBg">';
	
	_sReturn += '	<div class="srcPub srcPub'+_oPubInfo._smartSize+'">';
	_sReturn += '		<iframe src="'+ GetDartURLCall('adi', _oPubInfo._smartSize) +'" width="' + _oPubInfo._w + '" height="' + _oPubInfo._h + '" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>';
	_sReturn += '	</div>';
	
	if (_oPubInfo._smartSize == "728x90") _sReturn += '</div>';
	
	return _sReturn;
};
function SmartAdServer_noiframe(sas_pageid,sas_formatid,sas_target) {
	sas_master = (sas_masterflag==1) ? 'M' : 'S';
	sas_masterflag=0;
	var _oPubInfo = getSmartFormat(sas_formatid);
	document.write('<SCR'+'IPT SRC="'+ GetDartURLCall('adj', _oPubInfo._smartSize) +'"></SCR'+'IPT>');
};


///	LEGACY : lien texte
function SmartAdServer_liensTextes(sas_pageid,sas_formatid,sas_target) {return "";}
function getSmartAdServer_liensTextes(sas_pageid,sas_formatid,sas_target) {return "";}
function getLiensTextes(sas_pageid,sas_formatid,sas_target) {return "";};
function srcPubLiensTextes(_o) {return "";};


///	LEGACY : premiere implantation de DART
var isFromRss = document.location.toString().toLowerCase().indexOf("ref=rss") != -1;
function getPub(DARTSite, DARTZone, DARTWidth, DARTHeight, DARTTile) {return "";}
function getPubInnerHTML(DARTSite, DARTZone, DARTWidth, DARTHeight, DARTTile) {return "";}
function getPubTxt(arrObjPub) {return "";}
function classPub(DARTSite, DARTZone, txt) {return "";}
function pubRequest(param) {return "";}
