var MyGenericTagVar  = new GenericTagVar();
//check to see if a page is homepage or not
var theurl=document.location.href;
var mainurl=theurl.indexOf("home.html");
var mainurl2=theurl.charAt(theurl.length -1);
var mainurl3=theurl.indexOf("home.php");
    if ((mainurl!=-1) || (mainurl2=="/") || (mainurl3!=-1)){
        var pageha="1";
          }
     else {
        var pageha="0";
          }

// Function for LaToile Quebec ( KeyWord Variable)
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];
}
// End function get_keyword

// Function for DCOPT Variable
function get_dcopt(mytile){
	if( mytile == 1 ) {
		dcopt =  'ist';  
	}
	else{
		dcopt =  ''; 
	}	    
	return dcopt;
}
// End function get_dcopt


function fctAdTag(position,obj,posId)
{		
	
//	/**************** SWITCH ********************************/
	var DETag = GetFlagDE();	//DETag flag
//	/**************** SWITCH ********************************/
	
	var size = GetDim(position); // Size Variable
	var my_dcopt =get_dcopt(obj.tile); // DCOPT Variable

	var my_keyword = get_keyword( 'q' );// motcle variable in LaToile
	my_keyword = my_keyword.replace(/%20/,"+");

	SwitchPos = GetPosition(position,obj);

	if (position == "button_4" || position == 'advertorial') {
		var DETag=true;
	}
	
	// End of The code that will be use until implementation of DFP
		
	if (DETag){
		//document.write(? DE Tag using position parameter ')	
		
		if(obj.language == "fr") {
			document.write('<script type="text\/javascript" src="http:\/\/ads5.canoe.ca\/js.ng\/site='+obj.de_site+'&amp;vertical='+obj.de_vchannel+'&amp;sousvertical='+obj.de_subchannel+'&amp;position='+SwitchPos+'&amp;sujet='+obj.sujet+'&amp;categorie='+obj.de_category+'"><\/script>');
		}else{
			document.write('<script type="text\/javascript" src="http:\/\/ads5.canoe.ca\/js.ng\/site='+obj.de_site+'&amp;VChannel='+obj.de_vchannel+'&amp;SubChannel='+obj.de_subchannel+'&amp;position='+SwitchPos+'&amp;HChannel='+obj.de_hchannel+'&amp;category='+obj.de_category+'"><\/script>');
		}

	}
	else {
	 // check to see if this is a sectionLevel4 or higher to treat the targeted homepages. if yes, set hp=0 which means it won't be a targeted homepage, if not use hp as variable populated by the value of 'pageha'.
       if (obj.sectionLevel4==''){
		   document.write('<script type="text\/javascript" src="http:\/\/ad.doubleclick.net\/adj\/'+obj.networkid+'.'+obj.language+'.'+obj.division+'.'+obj.mainSection+'\/'+obj.sectionLevel2+';subz1='+obj.sectionLevel3+';kw='+my_keyword+';tile='+obj.tile+';sz='+size+';dcopt='+my_dcopt+';pos='+posId+';hp='+pageha+';ord='+obj.rand_num+'?"><\/script>');
	       }
	       else {
		   document.write('<script type="text\/javascript" src="http:\/\/ad.doubleclick.net\/adj\/'+obj.networkid+'.'+obj.language+'.'+obj.division+'.'+obj.mainSection+'\/'+obj.sectionLevel2+';subz1='+obj.sectionLevel3+';kw='+my_keyword+';tile='+obj.tile+';sz='+size+';dcopt='+my_dcopt+';pos='+posId+';hp=0;ord='+obj.rand_num+'?"><\/script>');
		   }
	}

	obj.tile++;
}

