/*-----------------------------*/
/* Historique des maintenances */
/*-----------------------------*/
/* 2007-08-17	Raynald Bertrand	*/
/* 2007-08-17 Ajout de la variable hp pour gèrer la notion de HOME PAGE */
/* 2007-08-23 Ajout de la variable SwitchLang 								*/
/*			  Ajout l'utilisation de CheckProperties(obj,prop)

/* 2007-09-12 Pejman Ramezanpour: changed sectionlevel(#) to sectionLevel(#) since javascript is case sensitive 
              for the DFP tag, moved ord value to the end where it must be */
/* 2007-09-13 Joe O'Leary:	Added the buildTag function so the ad tags built only use variables that have values.
				fctAdTag was also modified to accomadte this.		*/
/* 2007-09-27 Pejman Ramezanpour: added Affiliate variable to DE tag. also added ChecProperties function for DE tags
*/
/* 2007-10-03 Pejman Ramezanpour: added keyword and makemodel variables to DE tag. added mk and mdl variables to DFP tag.
*/

/*------------------------------*/

// Function for DCOPT Variable
function get_dcopt(mytile){
	if( mytile == 1 ) {
		dcopt =  'ist';  
	}
	else{
		dcopt =  ''; 
	}	    
	return dcopt;
}
// End function get_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] != "") {
			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)
{		
	
//	/**************** SWITCH ********************************/
	var DETag = GetFlagDE(position);	//DETag flag
//	/**************** SWITCH ********************************/
	
	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/,"+");

	SwitchPos = GetPosition(position,objDfp); // from Tag_Section.js
	
	// End of The code that will be use until implementation of DFP

	var tag_options = new Array();

	if (DETag){
		var tag_start = '<script type="text\/javascript" src="http:\/\/ads5.canoe.ca\/js.ng\/site='+objDfp.de_site;
		var tag_end = '"><\/script>';
		var seperator = "&amp;";
		//document.write(? DE Tag using position parameter ')	
								
		//if(objDfp.language == "fr") {
		if(objDfp.SwitchLang == "fr") {
			tag_options["vertical"] = CheckProperties(objDfp,'de_vchannel');
			tag_options["sousvertical"] = CheckProperties(objDfp,'de_subchannel');
			tag_options["position"] = SwitchPos;
			tag_options["Affiliate"] = CheckProperties(objDfp,'de_affiliate');
			tag_options["sujet"] = CheckProperties(objDfp,'de_hchannel');
			tag_options["keyword"] = CheckProperties(objDfp,'de_keyword');
			tag_options["makemodel"] = CheckProperties(objDfp,'de_makemodel');
			tag_options["categorie"] = CheckProperties(objDfp,'de_category');
			tag_options["souscategorie"] = CheckProperties(objDfp,'de_subcategory');
			/* add new tag below */
		     //tag_options["test"] = CheckProperties(objDfp,'de_test');	
		}else{
			tag_options["VChannel"] = CheckProperties(objDfp,'de_vchannel');
			tag_options["SubChannel"] = CheckProperties(objDfp,'de_subchannel');
			tag_options["position"] = SwitchPos;
		    tag_options["Affiliate"] = CheckProperties(objDfp,'de_affiliate'); 	
			tag_options["HChannel"] = CheckProperties(objDfp,'de_hchannel');
			tag_options["keyword"] = CheckProperties(objDfp,'de_keyword');
			tag_options["makemodel"] = CheckProperties(objDfp,'de_makemodel');
			tag_options["category"] = CheckProperties(objDfp,'de_category');
			tag_options["subcategory"] = CheckProperties(objDfp,'de_subcategory');
		    /* add new tag below */
			//tag_options["test"] = CheckProperties(objDfp,'de_test');
		}
		
	} 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;
		tag_options["hp"] = CheckProperties(objDfp,'hp');
		tag_options["mk"] = CheckProperties(objDfp,'mk');
		tag_options["mdl"] = CheckProperties(objDfp,'mdl'); // note l is lower case L
		tag_options["prov"] = CheckProperties(objDfp,'prov');
		tag_options["year"] = CheckProperties(objDfp,'year');	
		tag_options["trim"] = CheckProperties(objDfp,'trim');			
	    /* tag_options["test"] = CheckProperties(objDfp,'test'); */
		//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++;
}


