
/*
-----------------------------------------------------------------------------------------------
--------		COPYRIGHT  ©  2005 Kontera Technologies, Inc. ALL RIGHTS RESERVED       -------							
-----------------------------------------------------------------------------------------------

###################################################################################################
#########									Variable Declaration						  #########							
###################################################################################################
*/
var osMac = false
if (navigator.platform.toLowerCase().indexOf('mac') != -1)	osMac = true;

//Harmless defines (can or should run once per tag)
// START : Global variables area
var iPageSize = 2000;
var iGetLimit = 2080;
var iMaxURL = 250;
var bIE = (navigator.appName.indexOf("Microsoft") != -1);
var sScriptPath = "http://kona.kontera.com/";
var teUrl = "http://te.kontera.com:7070/ListingTransform/ListingTransform";
var KonaVersion ="DC Ver 1.4_39 Date:02_03_2005";
var hideTO;		// used for the timeout event of the layer (for canceltimeout purpose)
var sGetScriptName = "KonaGet.js?";
var sSendScriptName = "KonaSend.js?";
var dTemp = new Date();
var sUnique = "u=" + dTemp.getTime();
var aMinArticleElemSize = [100,70,50];
var GET_KEY_MODE   = 0; // collecting data  to create a key to the page.
var GET_HTML_MODE  = 1; // collecting  page content data  to send to core server.
var DO_MARKUP_MODE = 2  // doing markup of AdLink in the document.
var FILTER_TAGS_REGULAR		  = 0;  //  regular filtering by publisherID/TagName/AttributeName/AttributeValue
var FILTER_TAGS_BY_GROUPS	  = 1;  //  filtering by groups (ie -B H1 H2 H3)
var FILTER_TAGS_BY_EXPRESSION = 2;  //  filtering by expression (ie -,to filter all font tags with size  >= 2) ,use :filterTagsForAdLinks("","FONT","size"," >= 2",FILTER_TAGS_BY_EXPRESSION); 
var MIN_ELEMENT_FOR_ADLINK = 20;
var MINIMUM_TEXT_IN_PAGE  = 0;
var wordsCounterStart =1;
var wordsCounterEnd =0;
var TEXT_NODE = 3;
var iMaxChunk = 4;
var isBoldActive ="1";
var visetedNodeArray = new Array();
var dcAdlinkHighlights = new Array();
var filterTagsForAdLinksArray = new Array();
var BROAD_MATCH = "90";

// START: define Tags to filterd as adLink.
// we will insert the most common tags first for better performance.
	filterTagsForAdLinksArray[0] = new filterTagsForAdLinks("","B strong","",""				 ,FILTER_TAGS_BY_GROUPS); 
	filterTagsForAdLinksArray[1] = new filterTagsForAdLinks("","H1 H2 H3","",""			 ,FILTER_TAGS_BY_GROUPS); 
	filterTagsForAdLinksArray[2] = new filterTagsForAdLinks("","FONT","size"," > 2"		 ,FILTER_TAGS_BY_EXPRESSION); 
	filterTagsForAdLinksArray[3] = new filterTagsForAdLinks("","","className","storyHEADLINE",FILTER_TAGS_REGULAR); 
	filterTagsForAdLinksArray[4] = new filterTagsForAdLinks("","","className","inside-head"	 ,FILTER_TAGS_REGULAR);
	filterTagsForAdLinksArray[5] = new filterTagsForAdLinks("","","className","storyheadline",FILTER_TAGS_REGULAR); 
	filterTagsForAdLinksArray[6] = new filterTagsForAdLinks("67","span","className","style5",FILTER_TAGS_REGULAR);
// END: define Tags to filterd as adLink.

//  
var GameLinkPublishers = ['42','43','44','49','53','54','77'];
// list of publishers that have a distinct adlink layer behavior
	
var UNKNOWN = 0;
var LOADING = 1;
var LOADED  = 2;
var DISABLED =  -1;
var currentTagId;
var LoadDynamicAdLinkDataEvent = false;
var alGotFactor = false;
var NOT_MARKED = 0;
var MARKED = 1;
var NOT_VALID = 2;
var adlinkMarked = false;
var dcAdlinksActive = "1"; //global param since , we need to send this param each time we do sendPageKey , we cant take it from one of the Tag;
var AUTO_FETCH = "0";
var FETCH_BY_DEMAEND="1";
var topKAdLinks = 6;			// the number of dynamic adLink for auto data fetch from the Te 
var maxAdlinksOnPage = 6;		// default max adLink on page 
var adLinksOnPageCounter = 0;   // 
var hideLayer = true;
var lastIndexToBedynamicLoad = -1;
var currentAdLinkIndexToShow = -1;
var teTimeOut = 1500;				// te time out per request 
var teAoutoFetchTimeOut = 4500;		// te time out for init load of auto  fetch
var teLoadDataTimeOut = 2500;       // te dynamic load request time out ,(when doing mous over on a singel adLink with no data)
var mouseOverWhileLoad = false;
var isSsendPageKey = false;
var requestCounter =0;
var TM		= "TM";
var TM_AL	= "TM(AL)";
var PU		= "PU";
var ADL		= "ADL";
var generalIndex = -1; //to sync all params that cames from array.
// END : Global variables area

//Custom meta tags
var aCustMeta = [];
var sCaption = "ADVERTISEMENT";
var windowStatusBarCaptionOnAdLinkMouseOver = "DynamiContext AdLink";
var cookie_name = "dc_PP_cap";
//End per publisher

//Global variables (can run every tag - used by first tag only)
var sKey = "";
var sDocText = "";
var iChunkNumber = 0;
var iLastDocSize = 0;
var iLastNodeNumber = 0;
var iCurrMU = 0;

//Updated by KonaGetInline.js (can run every tag)
var iKonaResultCode = 2; //{0=DoSearch, 1=Found, 2=NotFound}
var aKonaResults = []; //aKonaResults[i]="resultType|Width|Height|Border|URL|BackColor"
var aURLParams = []; //params inside the URL that will be replaced

// -------------------------   def params valuse   ---------------------------------------------------------- 
var DC_AL_NUMBER_DEF				= "1";
var DC_AL_COLOR_DEF					= "Orange";
//var DC_BG_COLOR_DEF					= "WHITE";
var DC_AL_LY_SHOWCAPTION_DEF	    = "yes";
var DC_AL_LY_CAPTION_TEXT_DEF	    = "Advertisement";
var DC_AL_LY_CAPTION_FONT_COLOR_DEF = "#AFAFAF";
var DC_AL_LY_BORDER_COLOR_DEF	    = "BLACK";
var DC_AL_LY_BG_COLOR_DEF			= "#FFFFF0";
var DC_AL_LY_FONT_TYPE_DEF			= "Arial";
var DC_AL_LY_ONMOUSEOVER_COLOR_DEF  = "#FFFFE0";
var DC_AL_LY_OPEN_TIME_DEF			= "500";
var DC_AL_LY_TITLE_ACTIVE_DEF	    = "yes";
var DC_AL_LY_TITLE_FONT_COLOR_DEF   = "#00008B";
var DC_AL_LY_TITLE_BOLOD_DEF	    = "no";
var DC_AL_LY_TITLE_FONT_SIZE_DEF    = "12";
var DC_AL_LY_DESC_ACTIVE_DEF	    = "yes";
var DC_AL_LY_DESC_FONT_SIZE_DEF     = "11";
var DC_AL_LY_URL_ACTIVE_DEF			= "yes";
var DC_AL_LY_URL_FONT_COLOR_DEF	    = "#00008B";
var DC_AL_LY_URL_FONT_BOLD_DEF	    = "no";
var DC_AL_LY_URL_FONT_SIZE_DEF	    = "10";
var DC_AL_LY_EXPLAIN_ACTIVE_DEF	    = "yes";
var DC_AL_LY_EXPLAIN_TEXT_DEF	    = 'what\'s this?';
var DC_AL_LY_EXPLAIN_URL_DEF	    = "http://dc.kontera.com";
var DC_RON_DEF					    = "SPORT";
var DC_ADLINKS_ACTIVE_DEF			= "1";
var DC_ADULT_DEF					= "0";
var DC_PP_WIDHT_DEF					= "500";
var DC_PP_HEIGHT_DEF				= "600";
var DC_PP_CAP_DEF					= "3";
var DC_PP_UNDER_DEF					= "0";
var DC_AD_INDEX						= "0";
// -------------------------   def params valuse   ---------------------------------------------------------- 




/*
###################################################################################################
#########									CLASSES										  #########							
###################################################################################################
*/
// next struct holds  the media propertyies , if the user allready defines them in the tag the value 
//for those variables will be taken from the Tag , other wise a defualt value will be set.
function InfoUnit(
	  iUnitID,
	  dc_width,
	  dc_height,
	  dc_Keywords,
	  dc_OutBorder,
	  dc_InBorder,
	  dc_external_border,
	  dc_internal_border,
	  dc_bg_color1,
	  dc_bg_color2,
	  dc_AdLinkColor,
	  dcAL_number,
	  dcAL_color,
	  dcAL_bgColor,
	  dcAL_LY_showCaption,
	  dcAL_LY_captionTxt,
	  dcAL_LY_captionFontColor,
	  dcAL_LY_borderColor,
	  dcAL_LY_bgColor,
	  dcAL_LY_FontType,
	  dcAL_onMouseOvercolor,
	  dcAL_LY_openTime,
	  dcAL_LY_titleActive,
	  dcAL_LY_titleFontColor,
	  dcAL_LY_titleBold,
	  dcAL_LY_titleFontSize,
	  dcAL_LY_descActive,
	  dcAL_LY_descFontColor,
	  dcAL_LY_descFontSize,
	  dcAL_LY_urlActive,
	  dcAL_LY_urlFontColor,
	  dcAL_LY_urlFontBold,
	  dcAL_LY_urlFontSize,
	  dcAL_explainActive,
	  dcAL_explainText,
	  dcAL_explainURL,
	  dc_numberAds,
	  dc_sm_type,
	  dc_default,
	  dc_bg_img,
	  dc_align,
	  dc_caption_text,
	  dc_show_caption,
	  dc_caption_font,
	  dc_caption_font_size,
	  dc_caption_font_color,
	  dc_caption_font_bgColor,
	  dc_show_title,
	  dc_title_font,
	  dc_title_font_size,
	  dc_title_font_bold,
	  dc_title_font_color,
	  dc_show_description,
	  dc_description_font,
	  dc_description_font_size,
	  dc_description_font_bold,
	  dc_description_font_color,
	  dc_show_url,
	  dc_url_font,
	  dc_url_font_size,
	  dc_url_font_bold,
	  dc_url_font_color,
	  dc_titLinesNumberFactor,
	  dc_descLinesNumberFactor,
	  dc_descCharsFactor,
	  dc_titCharsFactor,
	  dc_caption_position,
	  dc_adlinks_active,
	  dc_ron,
	  dc_adult,
	  dc_PP_cap,
	  dc_PP_width,
	  dc_PP_height,
	  dc_PP_under,
	  dc_adprod,
	  dc_adIndex)
{
this.iUnitID				 = iUnitID;
this.dc_width				  = dc_width ;
this.dc_height				  = dc_height ;
this.dc_Keywords			  = dc_Keywords
this.dc_OutBorder		      = dc_OutBorder
this.dc_InBorder			  = dc_InBorder      
this.dc_external_border		  = dc_external_border
this.dc_internal_border		  = dc_internal_border
this.dc_bg_color1			  = dc_bg_color1
this.dc_bg_color2	          = dc_bg_color2
this.dc_AdLinkColor		   	  = dc_AdLinkColor;
this.dcAL_number			  = dcAL_number; 
this.dcAL_color				  = dcAL_color;				 
this.dcAL_bgColor			  = dcAL_bgColor;			
this.dcAL_LY_showCaption	  = dcAL_LY_showCaption;
this.dcAL_LY_captionTxt		  = dcAL_LY_captionTxt;
this.dcAL_LY_captionFontColor = dcAL_LY_captionFontColor;
this.dcAL_LY_borderColor	  = dcAL_LY_borderColor;
this.dcAL_LY_bgColor		  = dcAL_LY_bgColor;
this.dcAL_LY_FontType		  = dcAL_LY_FontType;
this.dcAL_onMouseOvercolor	  = dcAL_onMouseOvercolor;
this.dcAL_LY_openTime		  = dcAL_LY_openTime;
this.dcAL_LY_titleActive	  = dcAL_LY_titleActive;
this.dcAL_LY_titleFontColor	  = dcAL_LY_titleFontColor;
this.dcAL_LY_titleBold		  = dcAL_LY_titleBold;
this.dcAL_LY_titleFontSize	  = dcAL_LY_titleFontSize;
this.dcAL_LY_descActive		  = dcAL_LY_descActive;
this.dcAL_LY_descFontColor	  = dcAL_LY_descFontColor;
this.dcAL_LY_descFontSize	  = dcAL_LY_descFontSize;
this.dcAL_LY_urlActive		  = dcAL_LY_urlActive;
this.dcAL_LY_urlFontColor	  = dcAL_LY_urlFontColor;
this.dcAL_LY_urlFontBold	  = dcAL_LY_urlFontBold;
this.dcAL_LY_urlFontSize	  = dcAL_LY_urlFontSize;
this.dcAL_explainActive		  = dcAL_explainActive;
this.dcAL_explainText		  = dcAL_explainText;
this.dcAL_explainURL          = dcAL_explainURL;
this.dc_numberAds                = dc_numberAds;
this.dc_sm_type					 = dc_sm_type;
this.dc_default				     = dc_default;
this.dc_bg_img					 = dc_bg_img;
this.dc_align					 = dc_align;
this.dc_show_caption			 = dc_show_caption;
this.dc_caption_text		  	 = dc_caption_text;
this.dc_caption_font			 = dc_caption_font;
this.dc_caption_font_size        = dc_caption_font_size;
this.dc_caption_font_color       = dc_caption_font_color;
this.dc_caption_font_bgColor     = dc_caption_font_bgColor;
this.dc_show_title				 = dc_show_title;
this.dc_title_font				 = dc_title_font;
this.dc_title_font_size			 = dc_title_font_size;
this.dc_title_font_bold			 = dc_title_font_bold;
this.dc_title_font_color		 = dc_title_font_color;
this.dc_show_description		 = dc_show_description;
this.dc_description_font		 = dc_description_font;
this.dc_description_font_size	 = dc_description_font_size;
this.dc_description_font_bold	 = dc_description_font_bold;
this.dc_description_font_color	 = dc_description_font_color;
this.dc_show_url				 = dc_show_url;
this.dc_url_font				 = dc_url_font;
this.dc_url_font_size			 = dc_url_font_size;
this.dc_url_font_bold			 = dc_url_font_bold;
this.dc_url_font_color			 = dc_url_font_color;
this.dc_titLinesNumberFactor	 = dc_titLinesNumberFactor;
this.dc_descLinesNumberFactor 	 = dc_descLinesNumberFactor;
this.dc_descCharsFactor  	     = dc_descCharsFactor;
this.dc_titCharsFactor			 = dc_titCharsFactor;
this.dc_caption_position		 = dc_caption_position;
this.dc_adlinks_active			 = dc_adlinks_active; 
this.dc_ron						 = dc_ron;
this.dc_adult					 = dc_adult;
this.dc_PP_cap					 = dc_PP_cap;		
this.dc_PP_width				 = dc_PP_width;	
this.dc_PP_height				 = dc_PP_height
this.dc_PP_under				 = dc_PP_under;
this.dc_adprod					 = dc_adprod;
this.dc_adIndex					 = dc_adIndex; 
}
//----------------------Additional Params For Generic TextMatch-----------------------

// ************************ NEW PARAMS1.4  *****************************





//--------------------------------------------------------------------------------------------------------

function Links(elementNumber, elementOffset, highlighttext,wordNumber)
{
this.elementNumber = elementNumber;
this.elementOffset = elementOffset;
this.highlighttext = highlighttext;
this.wordNumber = wordNumber;
this.dcAdlinkInfo = [];
this.LinkArray = [];
this.status = UNKNOWN; 
this.LoadByDemandAdLinkData = LoadByDemandAdLinkData;
this.marked					= NOT_MARKED;
}
//--------------------------------------------------------------------------------------------------------
function LinkInfo(keyword,title,description,landingUrl,encodedRedirect,imageUrl)
{
this.keyword		 = keyword;
this.title			 = title;
this.description	 = description;
this.landingUrl		 = landingUrl;
this.encodedRedirect = encodedRedirect;
this.imageUrl		 = imageUrl;
}
//--------------------------------------------------------------------------------------------------------
function filterTagsForAdLinks(publisherId,tagName,attributeName,attributeValue,type)
{
	this.publisherId	= publisherId; 
	this.tagName	    = tagName;
	this.attributeName  = attributeName;
	this.attributeValue = attributeValue;
	this.type			= type;
}
//--------------------------------------------------------------------------------------------------------

/*
###################################################################################################
#########									EVENTS										  #########							
###################################################################################################
*/

//--------------------------------------------------------------------------------------------------------
function OnClick(e,index,aElement,iLinkID,adLinkObj)
{
if ( dcAdlinkHighlights[iLinkID].status!=LOADED) 
{
	aElement.removeAttribute("href");
	return false; 
}
if(!e)
	var e = window.event;
	if (typeof(adLinkObj)=='undefined')
		aElement = document.getElementById("AdLinkLayerClick");
	else 
		aElement  = adLinkObj;
		

var AdLinkInfoArray = dcAdlinkHighlights[iLinkID].dcAdlinkInfo;
if (isInGameLinkPublishersGroup())
	aElement.href=getURL(AdLinkInfoArray[index].encodedRedirect);

if(AdLinkInfoArray.length == 0)
	return;
else 
{
	aElement.href=AdLinkInfoArray[index].encodedRedirect;
	if (typeof(adLinkObj)!='undefined')	
		return;
	else 
	{	
		if (bIE)
			aElement.click();
		else 
		{
 			window.open(AdLinkInfoArray[index].encodedRedirect);
 			var oLayer = document.getElementById('kLinkTitle');
		    oLayer.style.visibility = 'hidden';
	 	}
		
    }		
}

}

function KonakeyDown()
{
   if (event.keyCode == 86 )window.status = KonaVersion;
}
//--------------------------------------------------------------------------------------------------------

/*
###################################################################################################
#########									Methods										  #########							
###################################################################################################
//---------------------------------------------------------------------------------------------------------------*/
/*
* isInGameLinkPublishersGroup : return's true if the current publisherID is a member of the GAMELINK group.
*
*/
function isInGameLinkPublishersGroup()
{		
		var isInGroup = false;
		for (i=0;i<GameLinkPublishers.length;i++ )
		{
			if (GameLinkPublishers[i] == dc_PublisherID)
			{	
				isInGroup = true
				break;
			}
		}
		return isInGroup; 
}
//---------------------------------------------------------------------------------------------------------------
/*
*
*
*
*/
function doCookie() 
{
	if(document.cookie) 
	{
		index = document.cookie.indexOf(cookie_name);
	} 
	else 
	{
		index = -1;
	}

	var expireDate = new Date;
	expireDate.setDate(expireDate.getDate()+1)
	expireDate.setHours(00,00,01);
	var expires = expireDate.toGMTString();
	if (index == -1) 
	{
		
		
		document.cookie=cookie_name+"=1; expires=" + expires;
	} 
	else 
	{
		countbegin = (document.cookie.indexOf("=", index) + 1);
		countend = document.cookie.indexOf(";", index);
		if (countend == -1)
		{
			countend = document.cookie.length;
		}
		count = eval(document.cookie.substring(countbegin, countend)) + 1;

		document.cookie=cookie_name+"="+count+"; expires=" + expires;
	}
}
//---------------------------------------------------------------------------------------------------------------
function getPopCount() 
{
	if(document.cookie) 
	{
		index = document.cookie.indexOf(cookie_name);
		if (index != -1) 
		{
			countbegin = (document.cookie.indexOf("=", index) + 1);
			countend = document.cookie.indexOf(";", index);
			if (countend == -1) 
			{
				countend = document.cookie.length;
			}
			count = document.cookie.substring(countbegin, countend);
			return count;
		}
	}
	return 0;
	
}


/**
update the adLiks status , if the dcAdlinkInfo.length > 0 , it means that this adLink data has been loaded
*/
function updateAdLinksStatus()
{
if (typeof(dcAdlinkHighlights)!='undefined' )
{
	var i;
	for (i=0;i<dcAdlinkHighlights.length;i++)
	{
		if (dcAdlinkHighlights[i].dcAdlinkInfo.length > 0)
		{
			dcAdlinkHighlights[i].status = LOADED;
		}
	}
}
}
//--------------------------------------------------------------------------------------------------------
// this function preform dynamic request to the TE inorder to get adLink Data
// param - key			: the word for which we want Data
// param - adLinkIndex   : the index of the adLink in  dcAdlinkHighlights Array.
// if key == undefined ,it means to go and do autofetch for topKAdLinks adLink.
function LoadDynamicAdLinkData(key,adLinkIndex,iTagNum)
{

	if (typeof(iTagNum) == 'undefined')
	{
		iTagNum = 0 ;
	}
	var dynamicFactorCounter = 0;
	var scriptURL = teUrl+"&keywords=";
	var i =0,index=0;
	var teRequestTimeOut = 0;
	if (typeof(key)=='undefined' || key==null) // auto fetch for the topKAdLinks
	{
		teRequestTimeOut = teAoutoFetchTimeOut;
		index = adLinkIndex;
		while (i<topKAdLinks && index<dcAdlinkHighlights.length)
		{
				scriptURL+=dcAdlinkHighlights[index].highlighttext;
				dcAdlinkHighlights[index].status = LOADING;
				i++;
				index++;
				if (i<topKAdLinks && index<dcAdlinkHighlights.length)
					scriptURL+="%2B";

		}
	}
	else
	{
		scriptURL+=key;
		teRequestTimeOut = teTimeOut;
		dynamicFactorCounter = 500;
	}
	scriptURL+="&keywords";
	scriptURL+="&index="+adLinkIndex;
	scriptURL+="&resultNum="+aInfoUnits[currentTagId].dcAL_number+"&time="+teRequestTimeOut+"&tag="+Number(iTagNum+requestCounter+dynamicFactorCounter);
	requestCounter++;
	// auto fetch type - 0
	if (!osMac) 
	{		
		var s=document.createElement('script');
		s.setAttribute('type','text/javascript');
		s.setAttribute('src', scriptURL);
		document.getElementById("konasapn0").appendChild(s);

	
	} 
	else 
	{
		// THIS WILL SUPPORT ONLY MAC
		var tHtml = '<SCRIPT language="JavaScript" src="'+scriptURL+'"></SCRIPT>'
		document.getElementById("konasapn0").innerHTML = tHtml;
	}
	
}
//--------------------------------------------------------------------------------------------------------

function LoadByDemandAdLinkData(index)
{
LoadDynamicAdLinkData(this.highlighttext,index);

}

//--------------------------------------------------------------------------------------------------------
/**
* puts doc body as first element in array
*/
function getRootElems()
{
	//For demo only
	if (typeof(KonterDynamicContextDemoState)!='undefined')
	{
		aRootElems[0] = document.getElementById("KonaBeginBody");
		if(!aRootElems[0])
			aRootElems[0] = document.body;
	}
	// NOT!! DEMO ,Real Process
	else
	{
		aRootElems[0] = document.getElementById("KonaBody"); // to support a pre-defined analisys area in the page.
		if(!aRootElems[0])
			aRootElems[0] = document.body;
	}
	

}
//--------------------------------------------------------------------------------------------------------

//Util functions (can run every tag)
function errorHandler()
{
return true;
}

//--------------------------------------------------------------------------------------------------------
//If Debug comment out next line
//window.onerror = errorHandler;
//--------------------------------------------------------------------------------------------------------
function DebugPrintout(sText, bBold, bForce)
{
var oAnchor = document.getElementById("KonaDemoIframe");
if(!oAnchor)
	oAnchor = document.body;
else
{
	if(oAnchor.role && !bForce)
		if(oAnchor.role == "guest")
			return;
}
var oDebug = document.createElement("P");
oDebug.style.margin = 0;
if(bBold == "B")
	oDebug.style.fontWeight = "bold";
oDebug.innerText = sText;
oAnchor.appendChild(oDebug);
}

//--------------------------------------------------------------------------------------------------------

/**
* gets relevant data when running in debug mode
*/
function DebugGetTerms(sResultLine)
{
try 
  {
	var aCurResultData = sResultLine.split("|");
	var aKeywords = (aCurResultData[5]+"&").match(/terms=(.*\?)&/g);
	if(!aKeywords)
		aKeywords = (aCurResultData[5]+"&").match(/k=(.*\?)&/g);
	if(!aKeywords)
		return "";
	var sKeywords = "";
	for(var i = 0; i < aKeywords.length; i++)
		if(aKeywords[i] != "")
		{
			var aTemp = aKeywords[i].split("=");
			aTemp = aTemp[1].split("&");
			if(sKeywords != "")
				sKeywords += ", "
			sKeywords += aTemp[0];
		}
   }
   catch (e) {}
   return sKeywords;
}

//--------------------------------------------------------------------------------------------------------

/*
* escapes the url
*/
function urlEncode(sText)
{
return escape(sText.replace(/[\240\s]+/g, "+"));
}

//--------------------------------------------------------------------------------------------------------

/*
*
*/
function fixPuncs(sText)
{
var sRetText;
//space puncs at the end of word
sRetText = sText.replace(/(\w)([\,:\.\?!\)"'])([\240\s])/g, "$1+$2$3");
//spcae puncs at the end of line
sRetText = sRetText.replace(/(\w)([\,:\.\?!\)"'])$/g, "$1+$2");
//space " or ( at the beginind of the word
sRetText = sRetText.replace(/([\240\s])(["\(])(\w)/g, "$1$2+$3");
//space " or ( at the beginind of the line
sRetText = sRetText.replace(/^(["\(])(\w)/g, "$1+$2");
//space , or : between words without space
sRetText = sRetText.replace(/(\w)([\,:])(\w)/g, "$1+$2+$3");
return sRetText;
}
//--------------------------------------------------------------------------------------------------------

/*
* removes white spaces
*/
function trim(sText)
{
return sText.replace(/^[\240\s]+/g, "").replace(/[\240\s]+$/g, "");
}
//--------------------------------------------------------------------------------------------------------

/*
* opens the url arg in a new window
*/
function redir(sUrl)
{
window.open(sUrl, "_new");
}

//--------------------------------------------------------------------------------------------------------

/*
* gets page meta data 
*/
function getMetaTags()
{
var oMeta = document.getElementsByTagName("META");
var sMeta = "";
var sCust = "";
for(var i = 0; i < oMeta.length; i++)
{
	var sName = oMeta[i].name;
	if(sName.toLowerCase() == "keywords")
		sMeta += "&m1=" + urlEncode(fixPuncs(oMeta[i].content.substr(0, 500)));
	if(sName.toLowerCase() == "description")
		sMeta += "&m2=" + urlEncode(fixPuncs(oMeta[i].content.substr(0, 500)));
	for(var j = 0; j < aCustMeta.length; j++)
	{
		if(sName.toLowerCase() == aCustMeta[j])
			sCust += sName + "=" + fixPuncs(oMeta[i].content.substr(0, 500)) + ";";
	}
}
if(sCust != "")
	sMeta += "&m3=" + urlEncode(sCust);
return sMeta;
}

//--------------------------------------------------------------------------------------------------------

/*
* handles the meta data keywords
*/
function getKwdMetaOnly()
{
var oMeta = document.getElementsByTagName("META");
var sMeta = "";
for(var i = 0; i < oMeta.length; i++)
{
	var sName = oMeta[i].name;
	if(sName.toLowerCase() == "keywords")
		sMeta = "&m1=" + urlEncode(fixPuncs(oMeta[i].content.substr(0, 100)));
}
return sMeta;
}

//--------------------------------------------------------------------------------------------------------

/*
*
*/
function getURL(url)
{
	//redir(aAdLinkData[0].destinationUrl); //one result
	var redir=url+'&yargs=js_url='+js_url;
	if(typeof(this["js_ref_id"]) != "undefined")
			redir+='&ref='+js_ref_id;
	if(typeof(this["js_src_id"]) != "undefined")
			redir+='&src='+js_src_id;
	return redir;
}
//--------------------------------------------------------------------------------------------------------
function OptionallyGetUrl()
{
if(document.referrer == '')//Send URL if referrer is not available only in first request
	return "&l=" + urlEncode(document.location.href.substring(0, iMaxURL));
else
	{return "";}
}
/*
* displays the adlink layer
*/
//--------------------------------------------------------------------------------------------------------
function adLinkDataExsit(index)
{
	for (i=0;i<dcAdlinkHighlights.length;i++)
	{
		if (dcAdlinkHighlights[index].highlighttext == dcAdlinkHighlights[i].highlighttext)
			{
				if (dcAdlinkHighlights[i].status == LOADED)
				{
					dcAdlinkHighlights[index].dcAdlinkInfo =  dcAdlinkHighlights[i].dcAdlinkInfo;
					dcAdlinkHighlights[index].status = LOADED; 
					return true;
				}
			}
	}
	return false;
}
//--------------------------------------------------------------------------------------------------------
function showTitle(e, obj, adlinkID ,divId) {

		
		// checking adLlink status before showing the layer
		updateAdLinksStatus();
		if (dcAdlinkHighlights[adlinkID].status != LOADED)
		{
			mouseOverWhileLoad = true;
			lastIndexToBedynamicLoad = adlinkID;
			if (dcAdlinkHighlights[adlinkID].status == UNKNOWN)
			{
				if (!adLinkDataExsit(adlinkID))
				{
					dcAdlinkHighlights[adlinkID].status = LOADING;
					dcAdlinkHighlights[adlinkID].LoadByDemandAdLinkData(adlinkID);
				}
				else 
					mouseOverWhileLoad = false;
				
			}
			
		}
		else 
		{
			mouseOverWhileLoad = false;
		}
		currentAdLinkIndexToShow =adlinkID;
		mouseIsOverLayer = true;
		window.status = windowStatusBarCaptionOnAdLinkMouseOver;
		var moveByPx = 140;
		var divElement = null;
		if (divId!="")
		{
			 divElement = document.getElementById(divId);
		}
		var Yposition,Xposition,Yevent,Xevent;
		if (bIE)
		{
			Yevent = window.event.y;
			Xevent = window.event.x;
		}
		else
		{
			Yevent = e.pageY - getScrollTop();
			Xevent = e.pageX - getScrollLeft();
		}
		if (divElement ==null)
			{
				Yposition =Yevent+getScrollTop();
				
			}
			else
			{
				var positionType ="";
				if (bIE)
					positionType  = divElement.currentStyle.position;
				else
					positionType  = divElement.style.position 
					
				if (positionType == "absolute")
				{	 
					Yposition = divElement.offsetTop + obj.offsetTop;
					Xposition = divElement.offsetLeft + obj.offsetLeft ;	
				}
				else 
					Yposition =Yevent+getScrollTop();
			}

		if (Xevent< moveByPx)  // title will be hidden (left), so resetting
			Xposition = 0;
		else
		{ 
			if ((Xevent+moveByPx+40) > document.body.offsetWidth && document.body.offsetWidth!= 0) // title will be hidden (right), so resetting
				Xposition = document.body.offsetWidth-320;
			 else
			       Xposition = Xevent+document.body.scrollLeft-moveByPx;
		}

		if (Xposition < 50) 
				Xposition = 50;
		if (dc_PublisherID == 196)
		{
			var xyObj = createLayerXYpositions(obj);
			Yposition = xyObj.top-15;
			Xposition = xyObj.left - moveByPx;

		}
		
		showListings(adlinkID, Yposition+15, Xposition);	
	

	}
//-----------------------------------------------------------------------------------------------
function createLayerXYpositions(o)
{
	var XY =new positions(0,0,0,0);
	if(!o)return XY;
	var x=0,y=0,p=o;
	while(p)
	{
	  x+=p.offsetLeft;
	  y+=p.offsetTop;
	  p=p.offsetParent;
	}
	XY.left=x;
	XY.top=y+o.offsetHeight
	XY.right=x+o.offsetWidth;
	XY.bottom=y+o.offsetHeight;
	return XY;
};
//-----------------------------------------------------------------------------------------------
function positions(x,y,w,h)
{
	this.left	=x;
	this.right	=x+w;
	this.top	=y;
	this.bottom =y+h;
};
//--------------------------------------------------------------------------------------------------------
// The following functions handle hiding the layer (for IE and NS)
//--------------------------------------------------------------------------------------------------------

function hideTitle(e, elmnt) {
if (document.all) {
	if (!(kLinkTitle.contains(window.event.toElement))) {
		mouseIsOverLayer = false;
		if ( dcAdlinkHighlights[currentAdLinkIndexToShow].status == LOADED && !mouseOverWhileLoad)
		{
			hideTO = window.setTimeout('hidekLinkTitle()', aInfoUnits[currentTagId].dcAL_LY_openTime );
		}
	}
} else {
		if (checkMouseLeave(elmnt, e)) 
		{
			if ( dcAdlinkHighlights[currentAdLinkIndexToShow].status == LOADED && !mouseOverWhileLoad)
			{
				hideTO = window.setTimeout('document.getElementById(\'kLinkTitle\').style.visibility = \'hidden\'; document.getElementById(\'kLinkTitle\').style.display = \'none\';', aInfoUnits[currentTagId].dcAL_LY_openTime );
			}
		}
}
}

function hidekLinkTitle()
{
if (!mouseIsOverLayer)
	document.all.kLinkTitle.style.display = 'none';
}

function checkIfMouseOverLayer() {

if (!mouseIsOverLayer && dcAdlinkHighlights[currentAdLinkIndexToShow].status == LOADED && !mouseOverWhileLoad) {
	if (document.all) {
		document.all.kLinkTitle.style.display = 'none';
	} else {
		var oLayer = document.getElementById('kLinkTitle');
		oLayer.style.visibility = 'hidden';
		oLayer.style.display = 'none';
	}
}
}



function containsDOM (container, containee) {
var isParent = false;
do {
if ((isParent = container == containee))
  break;
containee = containee.parentNode;
}
while (containee != null);
return isParent;
}


function checkMouseLeave (element, evt) {
if (element.contains && evt.toElement) {
return !element.contains(evt.toElement);
}
else if (evt.relatedTarget) {
return !containsDOM(element, evt.relatedTarget);
}
}

var prgressBarNumber = "";
//--------------------------------------------------------------------------------------------------------
// this function returns the innerHTML value for the adLink(located at the adlinkID index of dcAdlinkHighlights) 
// Layer object to be display
function getAdLinkDesc(adlinkID)
{
var newListing ="";
if (dcAdlinkHighlights[adlinkID].status != LOADED )
{
	prgressBarNumber = 0;
	newListing =  '<DIV style="align:left;border-bottom: 1px black solid; padding-top: 5px; padding-bottom: 5px;" onmouseover=" mouseOverWhileLoad=true;this.style.backgroundColor=\''+aInfoUnits[currentTagId].dcAL_onMouseOvercolor+'\';" onmouseout="mouseOverWhileLoad=false;this.style.backgroundColor=\'\';">';
	newListing+="<pre>";
	newListing+= " <font style=color:"+ dcAdlinkHighlights[adlinkID].dcAL_LY_descFontColor+"><center><FONT color='"+aInfoUnits[currentTagId].dcAL_LY_titleFontColor+"'> Loading </FONT> </center>";
	newListing+="</pre>";
	newListing += '</DIV>';
	prgressBarNumber  =newListing; 
	dcAdlinkHighlights[adlinkID].status = LOADING;
	
}
else
{ 
 var aLinkInfo = dcAdlinkHighlights[adlinkID].dcAdlinkInfo;
	for (j=0;j<aLinkInfo.length && j<aInfoUnits[currentTagId].dcAL_number;j++) {
		newListing += '<DIV style="text-align:left;border-bottom: 1px black solid; padding-top: 5px; padding-bottom: 5px;" onmouseover="this.style.backgroundColor='+"'"+aInfoUnits[currentTagId].dcAL_onMouseOvercolor+'\';\" onmouseout="this.style.backgroundColor=\'\';" onclick="OnClick(event,'+j+',this,'+adlinkID+');">';
		if (aInfoUnits[currentTagId].dcAL_LY_titleActive.toLowerCase() == 'yes') {
			// Showing listing title
			if (isInGameLinkPublishersGroup() && ( aLinkInfo[j].title == "" || aLinkInfo[j].title == null))
				aLinkInfo[j].title = aLinkInfo[j].keyword;
			if (aLinkInfo[j].title+'' != 'undefined' && aLinkInfo[j].title+'' != '') {
				var attr = 'font-size: ' +aInfoUnits[currentTagId].dcAL_LY_titleFontSize+';';
				if (aInfoUnits[currentTagId].dcAL_LY_titleBold.toLowerCase() == 'yes') attr += ' font-weight: bold;';
				else 
					attr += ' font-weight: normal;';

				newListing += '<A  href="#" onclick=\'this.removeAttribute("href")\' class="ADLINK_LAYER" ><FONT color="'+aInfoUnits[currentTagId].dcAL_LY_titleFontColor+'" style="'+attr+'">'+aLinkInfo[j].title+'</FONT></A>';
			}
		}

		if (aInfoUnits[currentTagId].dcAL_LY_descActive.toLowerCase() == 'yes') {
			// Showing listing description
			if (aLinkInfo[j].description+'' != 'undefined' && aLinkInfo[j].description+'' != '') {
				var attr = 'font-weight:normal;font-size: ' +aInfoUnits[currentTagId].dcAL_LY_descFontSize+'; color: '+aInfoUnits[currentTagId].dcAL_LY_descFontColor+';';
				var adLinkImage ="";
				if (dc_adLinkImageActive == 'yes' && aLinkInfo[j].imageUrl!="" && aLinkInfo[j].imageUrl!=null && aLinkInfo[j].imageUrl!="null")
				{

					adLinkImage ="<td valign='top'><INPUT width='80' hieght='40' TYPE=\"image\" SRC=\" "+aLinkInfo[j].imageUrl +"\"></td>";
					newListing += '<table><tr><td><DIV style="margin-top: 5px;" style="'+attr+'"> <FONT style="'+attr+'">' + aLinkInfo[j].description + '</FONT> </DIV></td>'+adLinkImage+'</tr></table>';
				}
				else
					newListing += '<DIV style="margin-top: 5px;" style="'+attr+'"> <FONT style="'+attr+'">' + aLinkInfo[j].description + '</FONT> </DIV>';
			}
		}

		if (aInfoUnits[currentTagId].dcAL_LY_urlActive.toLowerCase() == 'yes') {
			
			// handeling the gameLink publisher's
			if (isInGameLinkPublishersGroup() && ( aLinkInfo[j].landingUrl == '' ||  aLinkInfo[j].landingUrl.length < 2 || aLinkInfo[j].landingUrl == null) )
			{
				aLinkInfo[j].landingUrl = js_url;
			}
			// Showing listing URL
			if (aLinkInfo[j].landingUrl+'' != 'undefined' && aLinkInfo[j].landingUrl+'' != '') {
				var attr = 'font-size: ' +aInfoUnits[currentTagId].dcAL_LY_urlFontSize+'; color: '+aInfoUnits[currentTagId].dcAL_LY_urlFontColor+';';
				if (aInfoUnits[currentTagId].dcAL_LY_urlFontBold.toLowerCase() == 'yes') 
					attr += ' font-weight: bold;';
				else
					attr += ' font-weight: normal;';
				newListing += '<DIV style="margin-top: 5px;"><A href="#" onclick=\'this.removeAttribute("href")\' href="#" style="text-decoration: none; '+attr+'">';
				newListing += "<font style='"+attr +"';> "+aLinkInfo[j].landingUrl+"</font></A></DIV>";
			}
		}
		newListing += '</DIV>';
}

}
return newListing;
}

//--------------------------------------------------------------------------------------------------------


// This function is being called from showLayer and is drawing the layer actual listings

function showListings(adlinkID,	Yposition, Xposition) {

var aLinkInfo = dcAdlinkHighlights[adlinkID].dcAdlinkInfo;


var newListing = "";
if (document.all) document.all.kLinkTitleText.innerHTML = '';
else document.getElementById('kLinkTitleText').innerHTML = '';


newListing = getAdLinkDesc(adlinkID);
	if (document.all) {
		// -----------------------
		// IE
		// -----------------------
		if (dcAdlinkHighlights[adlinkID].status == DISABLED )
			return;
		document.all.kLinkTitle.all.kLinkTitleText.innerHTML += newListing;			
		document.all.kLinkTitle.style.backgroundColor = aInfoUnits[currentTagId].dcAL_LY_bgColor;
		document.all.kLinkTitle.style.left = Xposition
		document.all.kLinkTitle.style.top = Yposition;
		document.all.kLinkTitle.style.display = '';
		document.all.kLinkTitle.style.zIndex = 100;
		document.all.kLinkTitle.style.visibility = 'visible';

	} else {
		// -----------------------
		// NETSCAPE	
		// -----------------------


		var oLayer = document.getElementById('kLinkTitle');
		var oLayerTxt = document.getElementById('kLinkTitleText');

		oLayer.style.top = Yposition + "px";
		oLayer.style.left = Xposition + "px";


		oLayerTxt.innerHTML += newListing;
		oLayer.style.display = '';
		oLayer.style.zIndex = 100;
		oLayer.style.visibility = 'visible';
	}
	if (dcAdlinkHighlights[adlinkID].status == LOADING)
 		updateAdLinkLayer(adlinkID,Yposition, Xposition);

}

/**
//--------------------------------------------------------------------------------------------------------------------
*/
function removeAdLink(index)
{
		var adLinkText  = dcAdlinkHighlights[index].highlighttext;
		oLayer = document.getElementById('kLinkTitle');
		oLayer.style.visibility = 'hidden';
		oLayer.style.display = 'none';
		for (i =0 ;i < dcAdlinkHighlights.length;i++)
		{
			if (dcAdlinkHighlights[i].highlighttext == adLinkText && dcAdlinkHighlights[i].dcAdlinkInfo.length == 0)
			{
				var oNewNode = document.createElement("SPAN");
				dcAdlinkHighlights[i].status =  DISABLED;
				oNewNode.innerHTML = dcAdlinkHighlights[i].highlighttext;
				var obj = document.getElementById("KonaLink"+i);
				if (obj)
				{ 
					if (bIE)
						obj.replaceNode(oNewNode);	
					else	
					 obj.parentNode.replaceChild(oNewNode,obj);
				}
			}
		}
}

/**
//--------------------------------------------------------------------------------------------------------------------
*/
var tecounter = 0;
var statusBarStr="Loading";
// this function trigered upon the - by demand request , and  creates singel thread for each request.
// which check's every 200 Mill's if this adLink object status has changed , meaning got Data form the TE.
function updateAdLinkLayer(index,y,x)
{
if (typeof(dcAdlinkHighlights[index].dcAdlinkInfo) != 'undefined' && dcAdlinkHighlights[index].dcAdlinkInfo.length > 0)
{
	dcAdlinkHighlights[index].status = LOADED;
	var obj = document.getElementById('kLinkTitleText');
	// if lastIndexToBedynamicLoad != currentAdLinkIndexToShow there was no change in the mouse since the last by demand load
	if (lastIndexToBedynamicLoad == currentAdLinkIndexToShow) 
		showListings(index,y+1,x);	

	mouseIsOverLayer = false;
	window.status = "Dynamic Context Loaded!";
	statusBarStr="Loading";
	setTimeout("checkIfMouseOverLayer()",aInfoUnits[currentTagId].dcAL_LY_openTime );
}
else // checks if the Dynamic Data has arrived yet
{
	tecounter+=200;
	var functionName =  "updateAdLinkLayer("+index+","+y+","+x+")";
	mouseIsOverLayer = true;
	statusBarStr +="."; 
	window.status = statusBarStr;

if (tecounter > teLoadDataTimeOut)
{
		tecounter = 0;
		removeAdLink(index);
}
else
	setTimeout(functionName,200);

}
}
/*
//--------------------------------------------------------------------------------------------------------
// to be used in the future.
function findAlnternativeAdLinkData(adLinkId)
{
var index =0;
for (i=0;i<dcAdlinkHighlights.length;i++)
{
	if (typeof(dcAdlinkHighlights[i].dcAdlinkInfo) != 'undefined' && dcAdlinkHighlights[i].dcAdlinkInfo.length > 0)
	{
		dcAdlinkHighlights[adLinkId].dcAdlinkInfo[0] = dcAdlinkHighlights[i].dcAdlinkInfo[0];
		return true;// alternative found.
	}
}
return false; //no alternative found.
}
*/
//--------------------------------------------------------------------------------------------------------
/**
* returns top scroll position
*/
function getScrollTop() {
var s = 0;
if (window.getSelection) {  // Moz 
return document.body.scrollTop; 
}
if (document.documentElement && document.documentElement.scrollTop) {
s = document.documentElement.scrollTop;
}
else if (document.body && document.body.scrollTop) {
s = document.body.scrollTop;
}
return s;
}
//--------------------------------------------------------------------------------------------------------

/**
* returns left scroll position
*/
function getScrollLeft() 
{
 if (window.getSelection) {  // Moz 
 return document.body.scrollLeft; 
 }
var s = 0;
if (document.documentElement && document.documentElement.scrollLeft) 
{
	s = document.documentElement.scrollLeft;
}
else 
	if (document.body && document.body.scrollLeft) 
	{
		s = document.body.scrollLeft;
	}
return s;
}
//--------------------------------------------------------------------------------------------------------
function resizeKey(theKey) 
{ 
	var newKey=""; var getKeyNum=parseInt(theKey.length / 100)+1; 
	for (var i=0;i<theKey.length;++i) 
	{ 
		if (i%getKeyNum == 0)//take every getKeyNum 
		{ 
			newKey+=theKey.charAt(i); 
		} 
	} 
	return newKey; 
} 
//--------------------------------------------------------------------------------------------------------
//walkTheTree multi purpose function
//iMode {0=GetKey, 1=GetHtml, 2=Markup}
function walkTheTree(iMode)
{
var iNodeNumber = 0;
var iWordNumber = 0;
var oThisPara;
var oLastPara;
var bFirstPara = true;
var bInLink = false;
var iMinArticleElemSize = aMinArticleElemSize[0];
switch(iMode)
{
	case GET_KEY_MODE:
		for(var i = 0; i < aRootElems.length; i++)
		{
			sKey += traverse(aRootElems[i]);
		}
		sKey=resizeKey(sKey);
		// if in demo state than use random key to prevent cacheing.
		if (typeof(KonterDynamicContextDemoState)!='undefined' )
		{	
			if (dc_PublisherID == BROAD_MATCH)
			{
				sKey+="broad";
			}
			else
				sKey+="topical";

		}
		break;
	
	case GET_HTML_MODE:
		for(var j = 0; j < aMinArticleElemSize.length && sDocText.length < aMinArticleElemSize[j]*2; j++)
		{
			iMinArticleElemSize = aMinArticleElemSize[j];
			sDocText = "";
			for(var i = 0; i < aRootElems.length; i++)
			{
				sDocText += traverse(aRootElems[i]);
			}
		}
		break;
	case DO_MARKUP_MODE:
		for(var i = 0; i < aRootElems.length; i++)
		{
			traverse(aRootElems[i]);
		}
		break;
}

//--------------------------------------------------------------------------------------------------------
// handeling the replace of the adLink word for browser other than IE. 
function doMarkOtherBrowsers(sNewHtml,sOldHtml,sEscKeyword,sLink)
{
	var words = sEscKeyword.split(" ");
	if (words.length == 2)
	{
		 reMark = new RegExp("((\\b))("+words[0]+"(\\s)*"+words[1]+"(?!<\/A #DC#>)\\b)","i");
		 sNewHtml = sNewHtml.replace(reMark, sLink);
	}
	else 
	if (words.length == 3)
	{
		 reMark = new RegExp("((\\b))("+words[0]+"(\\s)*"+words[1]+"(\\s)*"+words[2]+"(?!<\/A #DC#>)\\b)","i");
		 sNewHtml = sNewHtml.replace(reMark, sLink);
	}
	return sNewHtml;
}
//--------------------------------------------------------------------------------------------------------
// this is a sub function to the doMark function ,it finds if the adLink word to heighLighted is in a div , if so
// it returns the div referance
// 
function getDivId(oNode)
{
	var tempHtmlNode = oNode;
	var divElementId="";
	var maxNods = 100;
	var nodsCounter =0;
	while(tempHtmlNode.parentNode.tagName!="BODY" && tempHtmlNode.tagName!="DIV" &&  nodsCounter< maxNods)
	{
		if (tempHtmlNode!=null)
			tempHtmlNode = tempHtmlNode.parentNode;
		nodsCounter++;
	}
	if (tempHtmlNode.tagName=="DIV") 
	{
		if (tempHtmlNode.id == "" || typeof(tempHtmlNode)=='undefined')
		tempHtmlNode.id = Math.round(Math.random()*100000);
		divElementId = tempHtmlNode.id;
	}
	return divElementId;
}

//--------------------------------------------------------------------------------------------------------
function toFilterAdLinkTag(tagNode,tagName)
{
	var	attributeValue ="";
	var fontWeight="";
	if (dc_isBoldActive =='no')
	{
		startIndex = 0;
		if (bIE)
		 fontWeight = tagNode.currentStyle.fontWeight;
		else
			 fontWeight = tagNode.currentStyle.fontWeight;	 
		if (GoodDecimal(fontWeight))
		{
			if (Number(fontWeight)>=700 ) return true;
		}
	}
	else
		startIndex = 1;	
	
	
	for (i=startIndex;i<filterTagsForAdLinksArray.length;i++)
	{
		if (filterTagsForAdLinksArray[i].publisherId == dc_PublisherID || filterTagsForAdLinksArray[i].publisherId == "")
		{
			if (filterTagsForAdLinksArray[i].type == FILTER_TAGS_REGULAR)
			{
			
				if (filterTagsForAdLinksArray[i].tagName.toLowerCase() == tagName.toLowerCase() || filterTagsForAdLinksArray[i].tagName == "")
				{
					if(bIE)	
							attributeValue = tagNode.getAttribute(filterTagsForAdLinksArray[i].attributeName);
					else
							attributeValue = eval("tagNode."+filterTagsForAdLinksArray[i].attributeName)

					if (attributeValue == filterTagsForAdLinksArray[i].attributeValue || (filterTagsForAdLinksArray[i].attributeValue == "" && filterTagsForAdLinksArray[i].tagName.toLowerCase() == tagName.toLowerCase() ))
					{
						return true;
					}

				}
			}
			else
			{	
				switch(filterTagsForAdLinksArray[i].type)
				{
					case FILTER_TAGS_BY_GROUPS:
						// check if the tagName is in a goup of tags
						if (filterTagsForAdLinksArray[i].tagName.toLowerCase().indexOf(tagName.toLowerCase())!=-1)
						{
							return true;
						}
						break;
					case FILTER_TAGS_BY_EXPRESSION:
						// check for expretions
						if (filterTagsForAdLinksArray[i].tagName.toLowerCase() == tagName.toLowerCase())
						{
							if(bIE)	
								attributeValue = tagNode.getAttribute(filterTagsForAdLinksArray[i].attributeName);
							else
								attributeValue = eval("tagNode."+filterTagsForAdLinksArray[i].attributeName)

							if (attributeValue!= "" && attributeValue!=null  &&  attributeValue.match(/\b\d+\b/)!=null)
							{
								if (eval(attributeValue+" "+filterTagsForAdLinksArray[i].attributeValue))
									return true;
							}
							
						}
						break;		
				}
			}

		}
	}
	return false;
}
//------------------------------------------------------------------------------------

function CJL_getCurrentStyle(elem, prop)
{
   if( elem.currentStyle )
   {  
      var ar = prop.match(/\w[^-]*/g);
      var s = ar[0];
      
      for(var i = 1; i < ar.length; ++i)		   
      {
         s += ar[i].replace(/\w/, ar[i].charAt(0).toUpperCase());
      }
           
      return elem.currentStyle[s]
   }
   else if( document.defaultView.getComputedStyle )
   {
      return document.defaultView.getComputedStyle(elem, null).getPropertyValue(prop);
   }
}
//------------------------------------------------------------------------------------
function getStyleAttribute(obj,attributeType,simpleAttribute)
{
        var attributValue ="";
	 if (bIE)
	{
		 var style = obj.currentStyle;
        	if ( typeof(style) != 'undefined')
				attributValue = eval("style."+attributeType);
	}
	else	  
	   attributValue  =  CJL_getCurrentStyle(obj, attributeType)
	   	
		
        return attributValue;
}
//------------------------------------------------------------------------------------
function GoodDecimal(S)
{ 
	return /^[-+]?\d*$/.test(S) 
}
	//------------------------------------------------------------------------------------
function getFontSizeStr(fontSize)
{
	if ( fontSize.indexOf("%")!=-1 )
		return  fontSizeStr="";
	if (  GoodDecimal(fontSize)  )
	 {
		 fontSizeStr = "size="+fontSize;
	 }
	else 
	 fontSizeStr ="style='font-size: "+fontSize+"'";
	
	return fontSizeStr;
}
//------------------------------------------------------------------------------------
function isMinimumElementNumber(sNewHtml,oNode)
{

	var isBelowMinimum = false;
	if (dc_isFilterMinimumElementsActive == 'no')
		return isBelowMinimum;
	if ( sNewHtml.length < MIN_ELEMENT_FOR_ADLINK )
	{
		if ( oNode.previousSibling != null)
		{
			if (oNode.previousSibling.tagName != 'BR') 
				isBelowMinimum = true;	
			else 	
				isBelowMinimum = false;
		}
		else 
			isBelowMinimum = true;	
	}
	 return isBelowMinimum;
	     
}
//------------------------------------------------------------------------------------
function adLinkWrapper(adlink,index)
{
	this.adlink = adlink
	this.index	= index;
}
//------------------------------------------------------------------------------------
function getAdLinksForNodeNumber()
{

	var tempArray = new Array();
	for (var i=0;i<dcAdlinkHighlights.length;i++)
	{
		
		if (dcAdlinkHighlights[i].marked == NOT_MARKED && adLinkInRange(dcAdlinkHighlights[i]))
			tempArray[tempArray.length] =new adLinkWrapper(dcAdlinkHighlights[i],i);
	}
	tempArray.sort(function(a,b){return (b.adlink.highlighttext.length - a.adlink.highlighttext.length)});
	return tempArray
}
function getNextLinkIndexForNextNodeRange()
{
	
}
//------------------------------------------------------------------------------------
/**
* creates the adlinks (the words in text with the adlink tag)
*/
function doMark(oNode)
{

	var currentadLinksForNodeArray = getAdLinksForNodeNumber();
	var isBold=0;
	var currentadLinksForNodeIndex =0;
	var numberOfAdLinkForCurrentNode = 0;
	var adLinksCandidateArray = new Array();
	var nodeTagName = oNode.parentNode.tagName;
	if ( toFilterAdLinkTag(oNode.parentNode,nodeTagName) )
	{
		iCurrMU = iCurrMU +currentadLinksForNodeArray.length;
		for (var j=0;j<currentadLinksForNodeArray.length;j++)
			currentadLinksForNodeArray[j].adlink.marked = NOT_VALID;
		return;
	}
		
	var fontAtrributeName     = "";
	var fontSizeAtrributeName = "";
	var fontWeight	     = "";


	  if (bIE)
	  {
           fontAtrributeName     = "fontFamily";
	    fontSizeAtrributeName = "fontSize";
	    fontWeight	      ="fontWeight"
	   
	  }
	 else
	 {
           fontAtrributeName     = "font-family";
	    fontSizeAtrributeName = "font-size";
	    fontWeight	      ="font-weight"

	 }
	var fontWeight = getStyleAttribute(oNode.parentNode,fontWeight,true);
	 if (GoodDecimal(fontWeight))
		fontWeight= Number(fontWeight);
	else
		fontWeight = Number(400);	
	
	
	var fontType = getStyleAttribute(oNode.parentNode,fontAtrributeName,true);
	var fontSize = getStyleAttribute(oNode.parentNode,fontSizeAtrributeName,true);
	
	fontSizeStr =  getFontSizeStr(fontSize);
	var parentStyle ="";
	if (fontSizeStr.indexOf("style")!=-1)
		{
			parentStyle = "style='font-weight:"+fontWeight +";font-family:"+fontType+";font-size:"+fontSize+";"; 
			fontSizeStr  ="";
		}
	else
		parentStyle = "style='font-weight:"+fontWeight +";font-family:"+fontType+";"; 

	
	var sOldHtml = oNode.nodeValue;
	var sNewHtml = sOldHtml;
	// Assuming the results arrive in order: Element number [Asc], Word number [Des]
	while( (  maxAdlinksOnPage > adLinksOnPageCounter ) &&  (currentadLinksForNodeIndex < currentadLinksForNodeArray.length))
	{  
		
	    // if it's a bold element or element with small number of words ignore it.
		if (isMinimumElementNumber(sNewHtml,oNode))
		{
			currentadLinksForNodeArray[currentadLinksForNodeIndex].adlink.marked = NOT_VALID;
			++currentadLinksForNodeIndex;
			continue;
		}
		
		var divElementId = getDivId(oNode);
		var rePrefix = "";
		var sLink = linkTemplate.replace(/<1>/g, currentadLinksForNodeArray[currentadLinksForNodeIndex].index).replace(/<2>/g, "$3");
		sLink = sLink.replace(/<3>/g, "#DC#");//marking the repleaced link ,so next word/link to be replaced  will ignore it.
		sLink = sLink.replace(/<4>/g, "'"+divElementId+"'");
		if (typeof(fontType)!='undefined' && fontType!=null && fontType!='' && typeof(fontSize)!='undefined' && fontSize!=null && fontSize!='')
		{
		  sLink = sLink.replace(/#FS#/g, parentStyle+"  "+fontSizeStr);		   
		}

		rePrefix = "(\\S+[\\240\\s]+){" + currentadLinksForNodeArray[currentadLinksForNodeIndex].adlink.elementOffset + "}";
		var sEscKeyword = currentadLinksForNodeArray[currentadLinksForNodeIndex].adlink.highlighttext.replace(/(\*|\^|\$|\+|\?|\.|\(|\)|\||\{|\}|\,|\[|\]|\\|\/)/g, '\\$1');
		
		var reMark;
		{
			try 
			{ 
				reMark =new RegExp("((\\b))("+sEscKeyword+"(?!<\/font><\/A><\!-- #DC#)\\b)","i");
	
			} 
			catch (e) 
			{
				reMark =new RegExp("(\\b)("+sEscKeyword+")?!(<\/font><\/A><\!-- #DC#>)\\b)","i");
			}
			var sEscKeywordOp1 ="";
			var sEscKeywordOp2 ="";
			var beforeSize = sNewHtml.length;
			var tempAdLink = 'KONTERA:'+adLinksCandidateArray.length+':';
			adLinksCandidateArray[adLinksCandidateArray.length] = sLink.replace('$3',sEscKeyword);
			sNewHtml = sNewHtml.replace(reMark, tempAdLink);
			
			currentadLinksForNodeArray[currentadLinksForNodeIndex].adlink.marked = MARKED;
			numberOfAdLinkForCurrentNode++;
			sOldHtml = sNewHtml;
			var afterSize = sNewHtml.length;
			if (!bIE)
			{
				if (afterSize == beforeSize)
					sNewHtml = doMarkOtherBrowsers(sNewHtml,sOldHtml,sEscKeyword,sLink);
			}
		}

		
		iCurrMU = currentadLinksForNodeArray[currentadLinksForNodeIndex].index+1;
		currentadLinksForNodeIndex++;
		adLinksOnPageCounter++;
			

	}

	
	var tempIndex =0;
	while ( tempIndex < dcAdlinkHighlights.length && !dcAdlinkHighlights[tempIndex].marked == NOT_MARKED )
	{
		tempIndex++;
	}
	iCurrMU = tempIndex;
	if (numberOfAdLinkForCurrentNode == 0 || sNewHtml.length < MIN_ELEMENT_FOR_ADLINK) return;
	for (j=0;j<adLinksCandidateArray.length;j++)
		sNewHtml = sNewHtml.replace('KONTERA:'+j+':',adLinksCandidateArray[j]);
	var oNewNode = document.createElement("SPAN");
	oNewNode.style.fontFamily = fontType;
		
	if ( !GoodDecimal(fontSize) )
			oNewNode.style.fontSize	  = fontSize;

	if (nodeTagName.toLowerCase() =="pre" )
		oNewNode.innerHTML = "<pre> "+sNewHtml+" </pre>";
	else 
		oNewNode.innerHTML = sNewHtml;
	try {		
			if (document.getElementById("debugta")!=null)
			{
				document.all.debugta.value = oNewNode.innerHTML;
			}

			if(bIE)
				oNode.replaceNode(oNewNode); // does not work on Netscape
			else
				oNode.parentNode.replaceChild(oNewNode,oNode);
		 }
		 catch (e) {
		 oNode.parentNode.innerHTML = oNewNode.innerHTML;
		 }

}

//--------------------------------------------------------------------------------------------------------

/*
* checks if the adlink is in the current element
*/
function adLinkInRange(link)
{
if (typeof(link.wordNumber)=='undefined')
return false;
var adLinkLoacation = Number(link.wordNumber);
if ((adLinkLoacation >= wordsCounterStart  && adLinkLoacation <= wordsCounterEnd) || (  link.elementNumber == iNodeNumber ))
	return true;
else 
	return false;
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function isFiterdNodeForAdLink(oNode,mode)
{
		if (mode!=DO_MARKUP_MODE) return false;
		if(oNode.tagName!="TD") return false;
		if(oNode.tagName=="META") return true;
		if (typeof(oNode.DC_FILTER)!='undefined')
		{ 
			if (oNode.DC_FILTER)
				return true;
			else 
				return false
		}
		else 
			return false;
}
//--------------------------------------------------------------------------
function countWordsNew(msg)
{
var words  = urlEncode(fixPuncs(msg)).split("+");
var counter = 0;
for (i=0;i<words.length;i++)
if (unescape(words[i]).length > 1) counter++;
return counter;
}
//--------------------------------------------------------------------------
function markAdLinkInNode(oNode)
{
		if (wasVisted(oNode)) return "";
		var msg	 = oNode.nodeValue;
		var n =countWordsNew(msg);
		if (n ==0 ) return "";
		wordsCounterStart = wordsCounterEnd+1;
		wordsCounterEnd +=n; 
		if (iCurrMU  < dcAdlinkHighlights.length)
		{
			if (typeof(dcAdlinkHighlights[iCurrMU].wordNumber)!='undefined')
			{
				if (adLinkInRange(dcAdlinkHighlights[iCurrMU])&& dcAdlinkHighlights[iCurrMU].marked == NOT_MARKED)
				{
					doMark(oNode);
				}
			}
			else
				if(dcAdlinkHighlights[iCurrMU].elementNumber == iNodeNumber && dcAdlinkHighlights[iCurrMU].marked == NOT_MARKED)
				{
					doMark(oNode);
				}
		}
}

//--------------------------------------------------------------------------------------------------------
function wasVisted(oNode)
{
var i=0;
while(visetedNodeArray[i] !=oNode && i<visetedNodeArray.length)
{
	i++;
}
if (i<visetedNodeArray.length)
{	
	return true;
}
else
{

	visetedNodeArray[visetedNodeArray.length]=oNode;
	
	return false;
}
}
//--------------------------------------------------------------------------------------------------------

function doWork(iMode, oNode)
{
	var sRetText = "";
	switch(iMode)
	{
	case GET_KEY_MODE:
		var aWords = oNode.nodeValue.split(/[\240\s]/);
		for(var i=0; i<aWords.length; i++)
		{
			if(iWordNumber % 10 == 0)
			{
				if(aWords[i].match(/\d+/g)==null)
					sRetText += aWords[i];
				else
					iWordNumber--;
			}
			iWordNumber++;
		}
		break;
	case GET_HTML_MODE:
		if (wasVisted(oNode)) return "";
		//Bold
		var isBold = 0;
		var nodeTagName = oNode.parentNode.tagName;
			if(toFilterAdLinkTag(oNode.parentNode,nodeTagName))
				isBold = 1;

		if(!bFirstPara)
		{
			
			//Paragraph
			if(oThisPara != oLastPara)
			{
				if(isBold)
					sRetText += " _  B ";//Paragraph terminator and Bold opener double space intentional
				else
					sRetText += " _ ";//Paragraph terminator
				oLastPara = oThisPara;
			}
			else
				if(isBold)
					sRetText += " B ";//Bold opener
				else
					sRetText += " @ ";//Line terminator
		}
		else
			if (isBold == 1)
				sRetText += " B ";
				
		bFirstPara = false;
		var sNodeText = oNode.nodeValue;
		sRetText += fixPuncs(sNodeText);
		break;
	case DO_MARKUP_MODE:	
		markAdLinkInNode(oNode);
		break;
	}
	return sRetText;
}
//--------------------------------------------------------------------------------------------------------

/**
* checks if it time to exit the recursion process
*/
function checkExitCond(iMode)
{
	switch(iMode)
	{
	case GET_KEY_MODE:
		if(iWordNumber > 1000)
			return true;
		break;
	case GET_HTML_MODE:
		if(sDocText.length > iMaxChunk * iPageSize)
			return true;
		break;
	case DO_MARKUP_MODE:
		if(iCurrMU >= dcAdlinkHighlights.length)
			return true;
		break;
	}
	return false;
}

//--------------------------------------------------------------------------------------------------------

/*
* checks if the element is valid
*/
function skipNode(sText)
{
	if(trim(sText).length < 2)
		return true;
	if(sText.search(/(copyright|\xA9) *200[345]/i) != -1)
		return true;
	if(sText.search(/All rights reserved/i) != -1)
		return true;
	if(sText.search(/are registered trademarks/i) != -1)
		return true;
	return false;
}

//--------------------------------------------------------------------------------------------------------

/**
* recursion on the DOM tree
*/
function traverse(oNode)
{
	if (oNode.id =='konteraElements')
		return "";
	
	if ( isFiterdNodeForAdLink(oNode,iMode) ) return "";
	var sCurrentText = "";
	if (checkExitCond(iMode)) return "";
	
	var sParentName = oNode.parentNode.nodeName;
	if(iMode == GET_HTML_MODE) { //Do the paragraph stuff
		if(oNode.nodeName == "TD" || oNode.nodeName == "P") {
			oThisPara = oNode;
			if(oLastPara == null) oLastPara = oNode;
		}
	}

	if (oNode.nodeName=="A")//going into link
		bInLink = true;
	if(oNode.nodeName=="TABLE")//going out of link
		bInLink = false;
		
	if (oNode.nodeType == TEXT_NODE && !bInLink && sParentName!="SELECT"  && sParentName!="SCRIPT" && sParentName!="NOSCRIPT" )
	{
		if(!skipNode(oNode.nodeValue) )//Skip empty or restricted nodes
		{				
			sCurrentText = doWork(iMode, oNode);
			iNodeNumber++;
		}
	}

	if (oNode.childNodes != null && oNode.nodeName!="SELECT" )
		for (var i=0; i < oNode.childNodes.length; i++)
			sCurrentText += traverse(oNode.childNodes[i]);
			

	if(oNode.nodeName=="A")//going out of link
		bInLink = false;
	if(iMode == GET_HTML_MODE && oNode.nodeName == "TD" && sCurrentText.length && sCurrentText.length < iMinArticleElemSize)
	{    
	   //return the line/para data only	
		oNode.DC_FILTER = true;
		sCurrentText = sCurrentText.replace(/_\s[^B@_]+\sB\s/, "_  B  B "); 
		var aElems = sCurrentText.match(/^[_@B]\s|\s[_@B]\s|\s[_@B]$/g);
		if(aElems)
		{
			var val = aElems.join("");
			return val;
		}
		else
			{
		    	return "";
			}
	}
	else
	{
		return sCurrentText;
	}
		
}

}

//--------------------------------------------------------------------------------------------------------

function iframeUrlManipolation(sURL,sKeyword)
{
var url;
url=sURL+"&";
url=url.replace(/&terms=[^&]*/g,"");
url=url.replace(/&keywords=[^&]*/g,"");
url=url.replace(/&sId=[^&]*/g,"");
return  url+"keywords="+sKeyword;
}

//--------------------------------------------------------------------------------------------------------

/**
* adds a new iframe to the page acoording to the args
*/
function DoIFrame(iTagNum, iWidth, iHeight, iBorder, sURL, sBackColor)
{
sURL = sURL.replace(/'/g, "%27");

// the publisher insert in tag his own keywords
if (aInfoUnits[iTagNum].dc_Keywords!=null && aInfoUnits[iTagNum].dc_Keywords!= '')
	sURL = iframeUrlManipolation(sURL,aInfoUnits[iTagNum].dc_Keywords);
var iBorder = 0;
var sIFrame = "<IFRAME frameborder='no'  id=KonaIFrame" + iTagNum + " scrolling=no src='";
sIFrame = sIFrame + sURL + "' width=";
sIFrame = sIFrame + iWidth + "px height=";
sIFrame = sIFrame + iHeight + "px frameBorder=";
sIFrame = sIFrame + iBorder + "px style='background-color:";
sIFrame = sIFrame + sBackColor + "' marginWidth=0 marginHeight=0 vspace=0 hspace=0 ";
sIFrame = sIFrame + "allowTransparency='true'></IFRAME>";
var oSpan = document.createElement("SPAN");
document.getElementById("konasapn" + iTagNum).appendChild(oSpan);
oSpan.innerHTML = sIFrame;
}

//--------------------------------------------------------------------------------------------------------

/**
* adds a new image to the page acoording to the args
*/
function DoImage(iTagNum, iWidth, iHeight, sImgURL, sOnClickURL)
{ 
sImgURL = sImgURL.replace(/'/g, "%27");
sOnClickURL = sOnClickURL.replace(/'/g, "%27");
var sImage = "<A href='";
sImage = sImage + sOnClickURL + "' target='_top'>";
sImage = sImage + "<IMG border=0 width=";
sImage = sImage + iWidth + "px height=";
sImage = sImage + iHeight + "px alt='Click here to visit our sponsor' src='";
sImage = sImage + sImgURL + "'></A>";
var oSpan = document.createElement("SPAN");
document.getElementById("konasapn" + iTagNum).appendChild(oSpan);
oSpan.innerHTML = sImage;
}

//--------------------------------------------------------------------------------------------------------

/**
* adds a new scripts (used in konaGet and konaSend
*/
function DoScript(iTagNum, sURL)
{
sURL = sURL.replace(/'/g, "%27");
var sScript = "<SCRIPT LANGUAGE='JavaScript' SRC='";
sScript = sScript + sURL + "'>";
sScript = sScript + "</SCR" + "IPT>";
var oSpan = document.createElement("SPAN");
document.getElementById("konasapn" + iTagNum).appendChild(oSpan);
oSpan.innerHTML = sScript;
}

//--------------------------------------------------------------------------------------------------------
function DoPopUp(iTagNum,aCurResultData)
{
	var cap = getPopCount();
	if ( cap >= aInfoUnits[iTagNum].dc_PP_cap) return;
	var TeUrl=aCurResultData[5]+"&dc_pp_information_Unit="+aInfoUnits[iTagNum].iUnitID;
	sFeatures = "height="+ aInfoUnits[iTagNum].dc_PP_height+",width="+aInfoUnits[iTagNum].dc_PP_width+",status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no";
	var oSpan = document.createElement("SPAN");
	document.getElementById("konasapn" + iTagNum).appendChild(oSpan);
	var win = window.open(TeUrl,"_blanc",sFeatures);
	if (aInfoUnits[iTagNum].dc_PP_under == 1)
	{
		win.blur();
		window.focus();
	}
	doCookie();
}
//--------------------------------------------------------------------------------------------------------

function showAdlinks(iTagNum)
{

  if(  dcAdlinkHighlights.length > 0)
  {
	if (adlinkMarked) 
		return;
	adlinkMarked = true;

	// sort adLinks by location in the DOM
    dcAdlinkHighlights.sort(function(a,b){return (a.wordNumber - b.wordNumber)});
   
    // START Auto adLink Data Fetch Process , For TopK adLinks.
	updateAdLinksStatus();
	if (!LoadDynamicAdLinkDataEvent)
		{   // fetch dynamic data starting from the 0 index 
			LoadDynamicAdLinkDataEvent = true;
			LoadDynamicAdLinkData(null,0,iTagNum); 
		}	
    // END Auto adLink Data Fetch Process , For TopK adLinks.
	
	// START Process Of Doing HighLight for page adLinks. 
	visetedNodeArray = new Array();
	walkTheTree(GET_HTML_MODE);// mark nodes we visit.
	visetedNodeArray = new Array();
	walkTheTree(DO_MARKUP_MODE);
	// END Process Of Doing HighLight for page adLinks. 
   }

}
//--------------------------------------------------------------------------------------------------------
// createing the view param part of the TE url request 
function createViewParamQueryForIFream(iTagNum)
{
 // here we put all the params that we want to pass to the TE.
var params =['dc_numberAds','dc_bg_color1','dc_bg_color2','dc_description_font_color','dc_InBorder','dc_OutBorder',
			 'dc_external_border','dc_internal_border','dc_sm_type','dc_default','dc_bg_img','dc_align','dc_show_caption','dc_caption_text',
			 'dc_caption_font','dc_caption_font_size','dc_caption_font_color','dc_caption_font_bgColor','dc_show_title','dc_title_font','dc_title_font_size',
			 'dc_title_font_bold','dc_title_font_color','dc_show_description','dc_description_font','dc_description_font_size',
			 'dc_description_font_bold','dc_description_font_color','dc_show_url','dc_url_font','dc_url_font_size','dc_url_font_bold',
			 'dc_url_font_color','dc_titLinesNumberFactor','dc_descLinesNumberFactor','dc_descCharsFactor','dc_titCharsFactor','dc_caption_position','dc_adIndex'];
var results ="";
for (i=0;i<params.length;i++)
	{
		var paramValue = eval('aInfoUnits['+iTagNum+'].'+params[i]);
		if (paramValue!="")
			results+= "&"+params[i] + "=" + escape(paramValue);
	}
	return results;
}
//--------------------------------------------------------------------------------------------------------------------------
/** 
* adds a new iframe for search match
*/
function IFrameForSearchMatch(iTagNum,aCurResultData)
{
	var sURL = aCurResultData[5];
	//Visual properties from the tag
	sURL+=createViewParamQueryForIFream(iTagNum);
	
	if(aInfoUnits[iTagNum].dc_width != "")
	{
		sURL = sURL + "&dc_width=" + aInfoUnits[iTagNum].dc_width;
		aCurResultData[1] = aInfoUnits[iTagNum].dc_width;
	}
	else 
		if (aCurResultData[1]!= '0')//check if the te return Width value!=0 , then use it
			sURL = sURL + "&dc_width=" + aCurResultData[1];
		else 
			{ 	
			   sURL = sURL + "&dc_width=" + def_dc_Width;
			   aInfoUnits[iTagNum].dc_width = def_dc_Width;
			   aCurResultData[1] = def_dc_Width;

			}

	if(aInfoUnits[iTagNum].dc_height != "")
	{
		sURL = sURL + "&dc_height=" + aInfoUnits[iTagNum].dc_height;
		aCurResultData[2]=aInfoUnits[iTagNum].dc_height;
	}
	else 
		if (aCurResultData[2]!= '0')//check if the te return Height value!=0 , then use it
			sURL = sURL + "&dc_height=" + aCurResultData[2];
		 else 
			{
			   sURL = sURL + "&dc_height=" + def_dc_Height;
			   aInfoUnits[iTagNum].dc_height = def_dc_Height;
			   aCurResultData[2] = def_dc_Height;
			}
				
	DoIFrame(iTagNum, aCurResultData[1], aCurResultData[2], aCurResultData[3], sURL, aCurResultData[4]);	
}

//--------------------------------------------------------------------------------------------------------

function ProcessResults(iTagNum, iKonaResultCode)
{

// safe side check that the data arrived from the reaction is valid.	
if ( typeof(aKonaResults) == 'undefined' || typeof(aKonaResults[iTagNum]) == 'undefined')
	return;
//Parse result
var aCurResultData = aKonaResults[iTagNum].split("|");
//resultType|Width|Height|Border|BackColor|URL|URL2

// if in tag 0 we got adlink & TM we need to incress the adLink TagNumber , to report 0:TM ,1:AdLink	
if (aCurResultData[0]!= 'L' && iTagNum == 0 && maxAdlinksOnPage > 0 && !alGotFactor)
{ 
	requestCounter++;
	alGotFactor = true;
}	
//Do the Creative only onces	
var childsNum = document.getElementById("konasapn" + iTagNum).childNodes.length;
if(childsNum  > 2 && iKonaResultCode == 1 || childsNum  > 1 && iKonaResultCode == 0)
	return;

//do switch on the results and call proper function for editing
switch(aCurResultData[0])
{
	case "S": //IFrame for search match
		IFrameForSearchMatch(iTagNum,aCurResultData);
		break;
	case "D": //IFrame for DirectAdvertiser search match
		IFrameForSearchMatch(iTagNum,aCurResultData);
		break;
	case "I": //Image banner
		var sImgURLTemplate = aCurResultData[5];
		var sOnClickURLTemplate = aCurResultData[6];
		for(var i = 1; i <= aURLParams.length; i++)
		{
			var re = new RegExp("<" + i + ">","g");
			sImgURLTemplate = sImgURLTemplate.replace(re, aURLParams[i]);
			sOnClickURLTemplate = sOnClickURLTemplate.replace(re, aURLParams[i]);
		}
		if(dc_width != 0 && dc_height != 0)
			DoImage(iTagNum, dc_width, dc_height, sImgURLTemplate, sOnClickURLTemplate);
		else			DoImage(iTagNum, aCurResultData[1], aCurResultData[2], sImgURLTemplate, sOnClickURLTemplate);
		break;
	case "H": //IFrame banner
		var sURLTemplate = aCurResultData[5];
		for(var i = 1; i <= aURLParams.length; i++)
		{
			var re = new RegExp("<" + i + ">","g");
			sURLTemplate = sURLTemplate.replace(re, aURLParams[i]);
		}
		if(dc_width != 0 && dc_height != 0)
			DoIFrame(iTagNum, dc_Width, dc_height, aCurResultData[3], sURLTemplate, aCurResultData[4]);
		else
			DoIFrame(iTagNum, aCurResultData[1], aCurResultData[2], aCurResultData[3], sURLTemplate, aCurResultData[4]);		
		break;
	case "X": //script
		var sURLTemplate = aCurResultData[5];
		DoScript(iTagNum, sURLTemplate);		
		break;

	case "P":
		DoPopUp(iTagNum,aCurResultData);
		break;
	
	case "U":
		DoPopUp(iTagNum,aCurResultData);
		break;	
	}
}//--------------------------------------------------------------------------------------------------------
function addEvent(obj, evType, fn)
{ 
if (obj.addEventListener)
{ 
obj.addEventListener(evType, fn, true); 
return true; 
} 
else 
 if (obj.attachEvent)
 { 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
} 
else  
 return false; 
}
//--------------------------------------------------------------------------------------------------------

//The event handler for returning from server
function onKonaReturn(iTagNumFromServer)
{
iTagNumFromServer = parseInt(iTagNumFromServer)
currentTagId = iTagNumFromServer;
if (osMac && document.readyState != 'complete') {
	window.setTimeout('onKonaReturn('+iTagNumFromServer+')',100);
	return;
}

if (iKonaResultCode == 0)  {

	ProcessResults(iTagNumFromServer, iKonaResultCode);
	var sLastChunk = "";
	//Get the text from the document
	if(sDocText == "")
		walkTheTree(GET_HTML_MODE)
	if(sDocText.length < MINIMUM_TEXT_IN_PAGE || iChunkNumber >= iMaxChunk)
		return;

	if((iChunkNumber == iMaxChunk - 1) || (sDocText.length < (iChunkNumber + 1) * iPageSize))
		sLastChunk = "&ls=1";
	//QueryString {p=Publisher, k=Key, c=Chunk, o=OffsetChars, e=ElementOffset, i=InfoUnit, n=TagNum, t=Title, m1-3=MetaTags, l=URL, h=HTML}
 
	var sQuery = sUnique + "&p=" + dc_PublisherID + "&k=" + urlEncode(sKey) + "&c=" + iChunkNumber + sLastChunk;
	sQuery = sQuery + "&o=" + iLastDocSize + "&e=" + iLastNodeNumber + "&i=" + aInfoUnits[iTagNumFromServer].iUnitID + "&n=" + iTagNumFromServer+"&al="+ dcAdlinksActive+"&bAl="+isBoldActive;
	
	if(iChunkNumber == 0)//Only in first request
	{
		var metaData ="&m1=&m2=";
		if (dc_PublisherID != 7)
		{
			metaData =   getMetaTags();
		}
		var title = document.title;
		if (title==null)
		{
			title ="";
		}
		sQuery = sQuery + "&t=" + urlEncode(fixPuncs(title)) + metaData;
		sQuery = sQuery + OptionallyGetUrl();
	}
	sQuery = sQuery + "&h=";
	
	var sDocTemp = urlEncode(sDocText);
	var iThisDocSize = iGetLimit - sScriptPath.length - sSendScriptName.length - sQuery.length;
	if (sDocTemp!= "")
	{
		while (sDocTemp.charAt(iLastDocSize + iThisDocSize) !="+" && iThisDocSize >=0)
		{
			iThisDocSize--;
		}
		sDocTemp = sDocTemp.substring(iLastDocSize, iLastDocSize + iThisDocSize);
	}
	//var aElems = sDocTemp.match(/^[_@]\+|\+[_@]\+|\+[_@]$/g);
	
   sDocTemp=sDocTemp.replace(/B\+B/g,"B++B");
   var sCountTemp=sDocTemp.replace(/_\+B[\+$]/g,"_+");//don't count _+B as 2 elements
   var aElems = sCountTemp.match(/[_@]\+|^B\+|\+[_@B]\+|\+[_@B]$/g);

	
	sQuery = sQuery + sDocTemp;
	iLastDocSize += iThisDocSize;
	if(aElems != null)
		iLastNodeNumber += aElems.length;
	var oScript = document.createElement("SCRIPT");
	oScript.setAttribute("language", "JavaScript");
	oScript.setAttribute("src", sScriptPath + sSendScriptName + sQuery);
	document.getElementById("konasapn" + iTagNumFromServer).appendChild(oScript);
	
	iChunkNumber++;
	//For Debug
	/*DebugPrintout("Ad Query String (light):", "B", true);
	DebugPrintout("Terms= " + DebugGetTerms(aKonaResults[iTagNumFromServer]), "R", true);
	DebugPrintout("\r", "R", true);
	DebugPrintout("Data sent to Analysis Engine:", "B");
	DebugPrintout("Key= " + sKey);
	DebugPrintout("Title= " + document.title);
	DebugPrintout("Meta Tags= " + unescape(getMetaTags().replace(/\+/g, " ").replace(/&m1=/, "Keywords=").replace(/&m2=/, "Description=")));
	DebugPrintout("HTML= " + unescape(sDocTemp.replace(/\+/g, " ")));
	DebugPrintout("\r");*/
	//End Debug
	//break;

} else if (iKonaResultCode == 1) {

	ProcessResults(iTagNumFromServer, iKonaResultCode);
	showAdlinks(iTagNumFromServer);
	
	//For Debug
	/*DebugPrintout("Ad Query String:", "B", true);
	DebugPrintout("Terms= " + DebugGetTerms(aKonaResults[iTagNumFromServer]), "R", true);
	DebugPrintout("\r", "R", true);
	if(iTagNumFromServer == 0 && dcAdlinkHighlights[0] != "")
	{
		DebugPrintout("Links (line, offset, keyword):", "B");
		for(var i = 0; i < dcAdlinkHighlights.length; i++)
		{
			var sText = dcAdlinkHighlights[i].elementNumber + ", ";
			sText = sText + dcAdlinkHighlights[i].elementOffset + ", ";
			sText = sText + dcAdlinkHighlights[i].highlighttext;
			DebugPrintout("Link" + i + "= " + sText);
		}	
		DebugPrintout("\r");
	}*/
	//End Debug
	//break;


} else if (iKonaResultCode == 2) {
	//alert("No Results - Should not get here!!! iKonaResultCode: 2");
	//break;
}
return;
}

  
//-------------------------------------------------------------------------------------------------------

function getProductLocation(productType)
{

	for (i=0; i<iTagNumber; i++)
	{
		if (aInfoUnits[i].dc_adprod == productType)
			return i;
	}		
	// product is not in the list.
	return -1; 
	
}

//--------------------------------------------------------------------------------------------------------
function removeAdLinkTag(productType)
{
	var AL_index	= getProductLocation(ADL);
	var TM_AL_index = getProductLocation(TM_AL);
	
		if (AL_index!=-1 && TM_AL_index != -1)
		{
				// set to ignore tag call
				aInfoUnits[AL_index].dc_adprod ="IGNORE";
				
				// move AL param to the TM(AL) TAG
				aInfoUnits[TM_AL_index].dcAL_number					=  aInfoUnits[AL_index].dcAL_number;
				aInfoUnits[TM_AL_index].dcAL_color					=  aInfoUnits[AL_index].dcAL_color;
				aInfoUnits[TM_AL_index].dcAL_bgColor				=  aInfoUnits[AL_index].dcAL_bgColor;
				aInfoUnits[TM_AL_index].dcAL_LY_showCaption			=  aInfoUnits[AL_index].dcAL_LY_showCaption;
				aInfoUnits[TM_AL_index].dcAL_LY_captionTxt			=  aInfoUnits[AL_index].dcAL_LY_captionTxt;
				aInfoUnits[TM_AL_index].dcAL_LY_captionFontColor	=  aInfoUnits[AL_index].dcAL_LY_captionFontColor;
				aInfoUnits[TM_AL_index].dcAL_LY_borderColor			=  aInfoUnits[AL_index].dcAL_LY_borderColor;
				aInfoUnits[TM_AL_index].dcAL_LY_bgColor				=  aInfoUnits[AL_index].dcAL_LY_bgColor;
				aInfoUnits[TM_AL_index].dcAL_LY_FontType			=  aInfoUnits[AL_index].dcAL_LY_FontType;
				aInfoUnits[TM_AL_index].dcAL_onMouseOvercolor		=  aInfoUnits[AL_index].dcAL_onMouseOvercolor;
				aInfoUnits[TM_AL_index].dcAL_LY_openTime			=  aInfoUnits[AL_index].dcAL_LY_openTime;
				aInfoUnits[TM_AL_index].dcAL_LY_titleActive			=  aInfoUnits[AL_index].dcAL_LY_titleActive;
				aInfoUnits[TM_AL_index].dcAL_LY_titleFontColor		=  aInfoUnits[AL_index].dcAL_LY_titleFontColor;
				aInfoUnits[TM_AL_index].dcAL_LY_titleBold			=  aInfoUnits[AL_index].dcAL_LY_titleBold;
				aInfoUnits[TM_AL_index].dcAL_LY_titleFontSize		=  aInfoUnits[AL_index].dcAL_LY_titleFontSize;
				aInfoUnits[TM_AL_index].dcAL_LY_descActive			=  aInfoUnits[AL_index].dcAL_LY_descActive;
				aInfoUnits[TM_AL_index].dcAL_LY_descFontColor		=  aInfoUnits[AL_index].dcAL_LY_descFontColor;
				aInfoUnits[TM_AL_index].dcAL_LY_descFontSize		=  aInfoUnits[AL_index].dcAL_LY_descFontSize;
				aInfoUnits[TM_AL_index].dcAL_LY_urlActive			=  aInfoUnits[AL_index].dcAL_LY_urlActive;
				aInfoUnits[TM_AL_index].dcAL_LY_urlFontColor		=  aInfoUnits[AL_index].dcAL_LY_urlFontColor;
				aInfoUnits[TM_AL_index].dcAL_LY_urlFontBold			=  aInfoUnits[AL_index].dcAL_LY_urlFontBold;
				aInfoUnits[TM_AL_index].dcAL_LY_urlFontSize			=  aInfoUnits[AL_index].dcAL_LY_urlFontSize;
				aInfoUnits[TM_AL_index].dcAL_explainActive			=  aInfoUnits[AL_index].dcAL_explainActive;
				aInfoUnits[TM_AL_index].dcAL_explainText			=  aInfoUnits[AL_index].dcAL_explainText;
				aInfoUnits[TM_AL_index].dcAL_explainURL				=  aInfoUnits[AL_index].dcAL_explainURL;
		}
}

//--------------------------------------------------------------------------------------------------------
function setTagPositionFirst(tagType)
{
	var tagType_index = getProductLocation(tagType); 
	if (tagType_index != -1)
	{
		var temp  = aInfoUnits[0];
		aInfoUnits[0] = aInfoUnits[tagType_index];
		aInfoUnits[tagType_index] = temp;
		
	}
}
//--------------------------------------------------------------------------------------------------------
function rearangeTags()
{
	var products="";
	for(var x = 0; x < iTagNumber; x++)
	{
		 products+="|"+aInfoUnits[x].dc_adprod+"|";
	}
	
	if (products.indexOf(ADL)!= -1 && products.indexOf(TM_AL)!= -1 && products.indexOf(PU)== -1)
	{
		removeAdLinkTag()
	}
	
	if (products.indexOf(PU)!= -1 && products.indexOf(TM_AL)!= -1  ) 
	{
		setTagPositionFirst(TM_AL);
	}
	
	if (products.indexOf(PU)!= -1 && products.indexOf(TM)!= -1 )
	{
		 setTagPositionFirst(TM);
	}
	
	if ( (products.indexOf(PU)!= -1 && products.indexOf(ADL)!= -1 ) || (products.indexOf(PU)!= -1 && products.indexOf(TM_AL)!= -1 && products.indexOf(ADL)!= -1) )
	{
		setTagPositionFirst(ADL);
	}
	
	var tempArray = new Array();
	for (i=0;i<aInfoUnits.length;i++ )
	{
		if (aInfoUnits[i].dc_adprod != "IGNORE")
		{
			tempArray[tempArray.length] = aInfoUnits[i]

		}
	}
	aInfoUnits = tempArray;
	iTagNumber = aInfoUnits.length;
	
	
}
//--------------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------------

function getAndSendPageKey()
{
if (isSsendPageKey) return;
isSsendPageKey = true;
if(bIE)
	if(document.readyState != "complete" && !isSsendPageKey) return 0;

if(aRootElems[0] == "") getRootElems();


//Get the page key
walkTheTree(GET_KEY_MODE);

//Put KonaGet tag
var sQuery = sUnique + "&p=" + dc_PublisherID + "&k=" + urlEncode(sKey)+"&al="+dcAdlinksActive;
sQuery = sQuery + OptionallyGetUrl();
var title = document.title;
if (title != null && title.length > 100 )
{
	title = title.substring(0,100);
}
else title ="";
var t = urlEncode(fixPuncs(title));
var m = getKwdMetaOnly();
var h = "";
if(t == "" || m == "")
	if(bIE)
		h = "&m2=" + urlEncode(fixPuncs(aRootElems[0].innerText.substr(0, 100)));
	else
	{
		var range = document.createRange();
		range.selectNodeContents(aRootElems[0]);
		h = "&m2=" + urlEncode(fixPuncs(range.toString().substr(0, 100)));
	}
sQuery = sQuery + "&t=" + t + m + h;
rearangeTags();
if (dc_PublisherID != 168 )
{
for(var x = 0; x < iTagNumber; x++)
{
	

	var sPerTagQuery = sQuery + "&i=" + aInfoUnits[x].iUnitID + "&n=" + x;
	var scriptURL = sScriptPath +''+ sGetScriptName +''+ sPerTagQuery;
	if (!osMac) {		
		var s=document.createElement('script');
		s.setAttribute('type','text/javascript');
		s.setAttribute('src', scriptURL);
		document.getElementById("konasapn" + x).appendChild(s);
	} else {
	
		// THIS WILL SUPPORT ONLY MAC
		var tHtml = '<SCRIPT language="JavaScript" src="'+scriptURL+'"></SCRIPT>'
		document.getElementById("konasapn" + x).innerHTML = tHtml;
	}
	

		
	/* 
	//For Debug
	DebugPrintout("Data sent to Reaction Engine:", "B");
	DebugPrintout("Key= " + sKey);
	DebugPrintout("Title= " + document.title.substr(0, 100));
	DebugPrintout("Meta Keywords= " + unescape(getKwdMetaOnly().replace(/\+/g, " ").replace(/&m1=/, "")));
	if(h != "")
		DebugPrintout("Document beginning (as Meta Desc.)= " + unescape(urlEncode(aRootElems[0].innerText.substr(0, 100)).replace(/\+/g, " ")));
	DebugPrintout("\r");
	//End Debug 
	*/
}
}

}

//--------------------------------------------------------------------------------------------------------
function  validateNumeric( strValue ) {
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

//--------------------------------------------------------------------------------------------------------

function selectRandomValue(tagParam,toEscape,tolower)
{
	var res;
	if (typeof(toEscape) == 'undefined')
		toEscape = false;
	if (typeof(tolower) == 'undefined')
		tolower = true;
	if (typeof(tagParam)=="object")
	{
		
		var index = Math.floor(Math.random()*tagParam.length);
		if (index == tagParam.length )
			index = tagParam.length - 1;
		if (generalIndex == -1)
		{
			generalIndex = index;
			
		}
		index = generalIndex;
		if (index > tagParam.length )
			index = 0;

		res =  tagParam[index];
	}
	else 
	{
		res = tagParam;
	}
	
	if (!validateNumeric(res) && tolower) // check if it's not a number
		res = res.toLowerCase();
	if (toEscape)
		res =  escape(res);
	return res;	
}
//--------------------------------------------------------------------------------------------------------
function support_1_3_Ver_Params()
{

	if ( aInfoUnits[iTagNumber].dc_sm_type == "")
	{
	if( Number(aInfoUnits[iTagNumber].dc_width) > Number(aInfoUnits[iTagNumber].dc_height))	
		aInfoUnits[iTagNumber].dc_sm_type ="horizontal";
	else 	
		aInfoUnits[iTagNumber].dc_sm_type ="vertical";
	}
	
}
//--------------------------------------------------------------------------------------------------------
function support_1_3_Ver_ParamsNameing()
{
	if(typeof(this["dc_Width"]) != "undefined")
	{
	  eval("this['dc_width'] = dc_Width");
	}
	if(typeof(this["dc_Height"]) != "undefined")
	{
	  eval("this['dc_height'] = dc_Height");
	}
	
	if(typeof(this["dc_BorderColor"]) != "undefined")
	{
	  eval("this['dc_external_border'] = dc_BorderColor");
	  eval("this['dc_OutBorder'] = 'yes' ");
	  eval("this['dc_internal_border'] = dc_BorderColor");
	  eval("this['dc_InBorder'] = 'yes' ");
	  
	}
	if(typeof(this["dc_BackgroundColor1"]) != "undefined")
	{
	  eval("this['dc_bg_color1'] = dc_BackgroundColor1");
	}
	if(typeof(this["dc_BackgroundColor2"]) != "undefined")
	{
	  eval("this['dc_bg_color2'] = dc_BackgroundColor2");
	}
	if(typeof(this["dc_TitleColor"]) != "undefined")
	{
	  eval("this['dc_title_font_color'] = dc_TitleColor");
	}
	
	if(typeof(this["dc_TextColor"]) != "undefined")
	{
	  eval("this['dc_description_font_color'] = dc_TextColor");
	}
	if(typeof(this["dc_URLColor"]) != "undefined")
	{
	  eval("this['dc_url_font_color'] = dc_URLColor");
	}
	
	
	
}

/*
#################################################################################################################
#######																									  #######	
#######        The Script begins here, THIS IS WHERE IT ALL BEGINS										  #######
#######                    Things that can run every tag												  #######
#######																									  #######
#################################################################################################################*/

//Global variables (should run only in the first tag)
if(typeof(this["aRootElems"]) == "undefined")
eval("var aRootElems = ['']");
if(typeof(this["iTagNumber"]) == "undefined")
eval("var iTagNumber = 0");
if(typeof(this["aInfoUnits"]) == "undefined")
eval("var aInfoUnits = ['']");
if(typeof(this["dcAdlinkHighlights"]) == "undefined")
eval("var dcAdlinkHighlights = ['']");


//Per Publisher stuff (can run every tag)
//Use publisher ID from tag if available
if(typeof(this["dc_PublisherID"]) == "undefined")
{
if(typeof(this["iKonaPublisherID"]) == "undefined") //  supporting publisher parm variable for  ver 1.2 
eval("var dc_PublisherID = 4");
else eval("var dc_PublisherID = iKonaPublisherID");
}
if(typeof(this["dc_PartnerID"]) != "undefined")
{
	 eval("var dc_PublisherID = dc_PartnerID");
}


if (dc_PublisherID == 158 || dc_PublisherID == 159 || dc_PublisherID == 160   )
{
	sScriptPath="http://208.185.211.88/";	
}


if(typeof(this["dc_isBoldActive"]) == "undefined")
{
	 eval("var dc_isBoldActive =  'yes'");
}
if(typeof(this["dc_isFilterMinimumElementsActive"]) == "undefined")
{
	 eval("var dc_isFilterMinimumElementsActive =  'yes'");
}
if(typeof(this["js_url"]) == "undefined")
        eval("var js_url = 'www.gamelink.com'");

if(typeof(this["dc_adLinkImageActive"]) == "undefined")
        eval("var dc_adLinkImageActive = 'no'");

if (dc_isBoldActive=='no')
	isBoldActive = "0";
	
//Information unit stuff - should be defined in a different Tag before this one
//Select the default info unit in case it is not available
if(typeof(this["dc_UnitID"]) == "undefined")
{
if(typeof(this["iKonaUnitID"]) == "undefined") //  supporting publisher parm variable for  ver 1.2 
eval("var dc_UnitID = 0");
else 	eval("var dc_UnitID = iKonaUnitID"); 
}


if(iTagNumber == 0)
{
if(bIE && !osMac)
{
	document.attachEvent("onreadystatechange", getAndSendPageKey);
	setTimeout("getAndSendPageKey()",3000);
}
else
{
	window.onload = getAndSendPageKey;
}
}
// START - spport 1.2 params in ver 1.3

if (typeof(this["sKonaBGColor1"])!="undefined")			 eval("var dc_bg_color1 = sKonaBGColor1");
if (typeof(this["sKonaBGColor2"])!="undefined")			 eval("var dc_bg_color2 = sKonaBGColor2");
if (typeof(this["sKonaTitleColor"])!="undefined")	     eval("var dc_TitleColor = sKonaTitleColor");
if (typeof(this["sKonaTextColor"])!="undefined")		 eval("var dc_TextColor = sKonaTextColor");
if (typeof(this["sKonaURLColor"])!="undefined")			 eval("var dc_URLColor = sKonaURLColor");
if (typeof(this["sKonaURLVisitedColor"])!="undefined")	 eval("var dc_URLVisitedColor = sKonaURLVisitedColor");
// END - spport 1.2 params in ver 1.3

support_1_3_Ver_ParamsNameing();

//save info unit data				  
aInfoUnits[iTagNumber] = new InfoUnit(dc_UnitID,
(typeof(this["dc_width"])						!= "undefined")?                  selectRandomValue(dc_width)				: "",
(typeof(this["dc_height"])					!= "undefined")?			      selectRandomValue(dc_height)					: "",
(typeof(this["dc_Keywords"])					!= "undefined")?               selectRandomValue(dc_Keywords)				: "",
(typeof(this["dc_OutBorder"])					!= "undefined")?              selectRandomValue(dc_OutBorder)				: "",
(typeof(this["dc_InBorder"])					!= "undefined")?               selectRandomValue(dc_InBorder)				: "",
(typeof(this["dc_external_border"])			!= "undefined")?        selectRandomValue(dc_external_border)					: "",
(typeof(this["dc_internal_border"])			!= "undefined")?	      selectRandomValue(dc_internal_border)					: "",
(typeof(this["dc_bg_color1"])					!= "undefined")?			  selectRandomValue(dc_bg_color1)				: "",
(typeof(this["dc_bg_color2"])					!= "undefined")?			  selectRandomValue(dc_bg_color2)				: "",
(typeof(this["dc_AdLinkColor"])				!= "undefined")?            selectRandomValue(dc_AdLinkColor)					: DC_AL_COLOR_DEF,
(typeof(this["dcAL_number"])					!= "undefined")?               selectRandomValue(dcAL_number)				: DC_AL_NUMBER_DEF,
(typeof(this["dcAL_color"])					!= "undefined")?                selectRandomValue(dcAL_color)					: DC_AL_COLOR_DEF,
(typeof(this["dcAL_bgColor"])					!= "undefined")?              selectRandomValue(dcAL_bgColor)				: "",
(typeof(this["dcAL_LY_showCaption"])			!= "undefined")?       selectRandomValue(dcAL_LY_showCaption)				: DC_AL_LY_SHOWCAPTION_DEF,
(typeof(this["dcAL_LY_captionTxt"])			!= "undefined")?        selectRandomValue(dcAL_LY_captionTxt,false,false)		: DC_AL_LY_CAPTION_TEXT_DEF,
(typeof(this["dcAL_LY_captionFontColor"])		!= "undefined")?  selectRandomValue(dcAL_LY_captionFontColor)				: DC_AL_LY_CAPTION_FONT_COLOR_DEF,
(typeof(this["dcAL_LY_borderColor"])			!= "undefined")?       selectRandomValue(dcAL_LY_borderColor)				: DC_AL_LY_BORDER_COLOR_DEF,
(typeof(this["dcAL_LY_bgColor"])				!= "undefined")?           selectRandomValue(dcAL_LY_bgColor)				: DC_AL_LY_BG_COLOR_DEF,
(typeof(this["dcAL_LY_FontType"])				!= "undefined")?          selectRandomValue(dcAL_LY_FontType)				: DC_AL_LY_FONT_TYPE_DEF,
(typeof(this["dcAL_onMouseOvercolor"])			!= "undefined")?      selectRandomValue(dcAL_onMouseOvercolor)				: DC_AL_LY_ONMOUSEOVER_COLOR_DEF,
(typeof(this["dcAL_LY_openTime"])				!= "undefined")?          selectRandomValue(dcAL_LY_openTime)				: DC_AL_LY_OPEN_TIME_DEF,
(typeof(this["dcAL_LY_titleActive"])			!= "undefined")?       selectRandomValue(dcAL_LY_titleActive)				: DC_AL_LY_TITLE_ACTIVE_DEF,
(typeof(this["dcAL_LY_titleFontColor"])		!= "undefined")?    selectRandomValue(dcAL_LY_titleFontColor)					: DC_AL_LY_TITLE_FONT_COLOR_DEF,
(typeof(this["dcAL_LY_titleBold"])			!= "undefined")?         selectRandomValue(dcAL_LY_titleBold)					: DC_AL_LY_TITLE_BOLOD_DEF,
(typeof(this["dcAL_LY_titleFontSize"])		!= "undefined")?     selectRandomValue(dcAL_LY_titleFontSize)					: DC_AL_LY_TITLE_FONT_SIZE_DEF,
(typeof(this["dcAL_LY_descActive"])			!= "undefined")?        selectRandomValue(dcAL_LY_descActive)					: DC_AL_LY_DESC_ACTIVE_DEF,
(typeof(this["dcAL_LY_descFontColor"])		!= "undefined")?     selectRandomValue(dcAL_LY_descFontColor)					: DC_AL_LY_BORDER_COLOR_DEF,
(typeof(this["dcAL_LY_descFontSize"])			!= "undefined")?      selectRandomValue(dcAL_LY_descFontSize)				: DC_AL_LY_DESC_FONT_SIZE_DEF,
(typeof(this["dcAL_LY_urlActive"])			!= "undefined")?         selectRandomValue(dcAL_LY_urlActive)					: DC_AL_LY_URL_ACTIVE_DEF,
(typeof(this["dcAL_LY_urlFontColor"])			!= "undefined")?      selectRandomValue(dcAL_LY_urlFontColor)				: DC_AL_LY_URL_FONT_COLOR_DEF,
(typeof(this["dcAL_LY_urlFontBold"])			!= "undefined")?       selectRandomValue(dcAL_LY_urlFontBold)				: DC_AL_LY_URL_FONT_BOLD_DEF,
(typeof(this["dcAL_LY_urlFontSize"])			!= "undefined")?       selectRandomValue(dcAL_LY_urlFontSize)				: DC_AL_LY_URL_FONT_SIZE_DEF,
(typeof(this["dcAL_explainActive"])			!= "undefined")?        selectRandomValue(dcAL_explainActive)					: DC_AL_LY_EXPLAIN_ACTIVE_DEF,
(typeof(this["dcAL_explainText"])				!= "undefined")?          selectRandomValue(dcAL_explainText,false,false)	: DC_AL_LY_EXPLAIN_TEXT_DEF,
(typeof(this["dcAL_explainURL"])				!= "undefined")?           selectRandomValue(dcAL_explainURL)				: DC_AL_LY_EXPLAIN_URL_DEF,
(typeof(this["dc_numberAds"])					!= "undefined")?			  selectRandomValue(dc_numberAds)				: "",
(typeof(this["dc_sm_type"])					!= "undefined")?			  selectRandomValue(dc_sm_type)						: "",
(typeof(this["dc_default"])					!= "undefined")?			  selectRandomValue(dc_default)						: "",
(typeof(this["dc_bg_img"])					!= "undefined")?				  selectRandomValue(dc_bg_img)					: "",
(typeof(this["dc_align"])						!= "undefined")?				  selectRandomValue(dc_align)				: "",
(typeof(this["dc_caption_text"])				!= "undefined")?           selectRandomValue(dc_caption_text,false,false)				: "",
(typeof(this["dc_show_caption"])					!= "undefined")?				  selectRandomValue(dc_show_caption)	: "",
(typeof(this["dc_caption_font"])				!= "undefined")?           selectRandomValue(dc_caption_font)				: "",
(typeof(this["dc_caption_font_size"])			!= "undefined")?      selectRandomValue(dc_caption_font_size)				: "",
(typeof(this["dc_caption_font_color"])		!= "undefined")?     selectRandomValue(dc_caption_font_color)					: "",
(typeof(this["dc_caption_font_bgColor"])		!= "undefined")?     selectRandomValue(dc_caption_font_bgColor)				: "",
(typeof(this["dc_show_title"])				!= "undefined")?			  selectRandomValue(dc_show_title)					: "",
(typeof(this["dc_title_font"])				!= "undefined")?			  selectRandomValue(dc_title_font)					: "",
(typeof(this["dc_title_font_size"])			!= "undefined")?        selectRandomValue(dc_title_font_size)					: "",
(typeof(this["dc_title_font_bold"])			!= "undefined")?        selectRandomValue(dc_title_font_bold)					: "",
(typeof(this["dc_title_font_color"])			!= "undefined")?       selectRandomValue(dc_title_font_color)				: "",
(typeof(this["dc_show_description"])			!= "undefined")?       selectRandomValue(dc_show_description)				: "",
(typeof(this["dc_description_font"])			!= "undefined")?       selectRandomValue(dc_description_font)				: "",
(typeof(this["dc_description_font_size"])		!= "undefined")?  selectRandomValue(dc_description_font_size)				: DC_AL_LY_DESC_FONT_SIZE_DEF,
(typeof(this["dc_description_font_bold"])		!= "undefined")?  selectRandomValue(dc_description_font_bold)				: "",
(typeof(this["dc_description_font_color"])		!= "undefined")? selectRandomValue(dc_description_font_color)				: "",
(typeof(this["dc_show_url"])					!= "undefined")?				  selectRandomValue(dc_show_url)			: "",
(typeof(this["dc_url_font"])					!= "undefined")?				  selectRandomValue(dc_url_font)			: "",
(typeof(this["dc_url_font_size"])				!= "undefined")?          selectRandomValue(dc_url_font_size)				: "",
(typeof(this["dc_url_font_bold"])				!= "undefined")?          selectRandomValue(dc_url_font_bold)				: "",
(typeof(this["dc_url_font_color"])				!= "undefined")?         selectRandomValue(dc_url_font_color)				: "",
(typeof(this["dc_titLinesNumberFactor"])		!= "undefined")?         selectRandomValue(dc_titLinesNumberFactor)			: "",
(typeof(this["dc_descLinesNumberFactor"])		!= "undefined")?         selectRandomValue(dc_descLinesNumberFactor)		: "",
(typeof(this["dc_descCharsFactor"])				!= "undefined")?         selectRandomValue(dc_descCharsFactor)				: "",
(typeof(this["dc_titCharsFactor"])				!= "undefined")?         selectRandomValue(dc_titCharsFactor)				: "",
(typeof(this["dc_caption_position"])			!= "undefined")?         selectRandomValue(dc_caption_position)				: "",
(typeof(this["dc_adlinks_active"])				!= "undefined")?         selectRandomValue(dc_adlinks_active)				: DC_ADLINKS_ACTIVE_DEF,
(typeof(this["dc_ron"])						    != "undefined")?         selectRandomValue(dc_ron)						    : DC_RON_DEF,
(typeof(this["dc_adult"])						!= "undefined")?         selectRandomValue(dc_adult)						: DC_ADULT_DEF,
(typeof(this["dc_PP_cap"])						!= "undefined")?         selectRandomValue(dc_PP_cap)						: DC_PP_CAP_DEF,
(typeof(this["dc_PP_width"])					!= "undefined")?         selectRandomValue(dc_PP_width)						: DC_PP_WIDHT_DEF,
(typeof(this["dc_PP_height"])					!= "undefined")?         selectRandomValue(dc_PP_height)					: DC_PP_HEIGHT_DEF,
(typeof(this["dc_PP_under"])					!= "undefined")?         selectRandomValue(dc_PP_under)						: DC_PP_UNDER_DEF,
(typeof(this["dc_adprod"])						!= "undefined")?         selectRandomValue(dc_adprod,false,false )			: "",
(typeof(this["dc_adIndex"])						!= "undefined")?         selectRandomValue(dc_adIndex,false,false )			: DC_AD_INDEX);



support_1_3_Ver_Params();	 
// will not be override by next Tag def  value  "0" is the strong value	 
if (aInfoUnits[iTagNumber].dc_adlinks_active == "0" )
	dcAdlinksActive	 = "0"; 
aInfoUnits[iTagNumber].dc_adprod = unescape(aInfoUnits[iTagNumber].dc_adprod );

var AdLinkColor;
AdLinkColor = unescape(aInfoUnits[iTagNumber].dc_AdLinkColor);

//erase data for next IU
var linkTemplate = "<A href=# style='text-decoration: underline;' #FS2# class=\"kLink1\" onMouseOver=\"window.clearTimeout(hideTO);showTitle(event, this, <1>,<4>);\" target='_new' id=\"KonaLink<1>\" onclick=\"OnClick(event,0,this,<1>,this)\" oncontextmenu=\"return false;\" onmouseout=\" mouseIsOverLayer = false; mouseOverWhileLoad = false; hideTO = window.setTimeout('checkIfMouseOverLayer()',"+aInfoUnits[iTagNumber].dcAL_LY_openTime+");\"><font #FS# color='"+AdLinkColor+"'#DC#><2></font></A><!-- <3> -->";
var def_dc_Width = 500; 
var def_dc_Height = 500;
var def_AdLinkColor ="#FF6633"
dc_width = "";		   // Ad unit width
dc_height = "";		   //Ad unit height
dc_caption_text = "";   //Caption on top/side of ad.
dc_Keywords= "";	   //Explicit topic instead of analysis topics
dc_OutBorder = "";	   //Does ad have external border? Yes/no
dc_InBorder  = "";	   //Does ad have internal border? Yes/no
dc_external_border= "";			//External border color
dc_internal_border= "";			//Internal border color
dc_bg_color1= "";		//Background color
dc_bg_color2= "";		//Alternate background color. If empty, uses color 1
dc_TitleColor= "";			    //title color
dc_DescriptionColor= "";		//description color
dc_URLColor= "";			    //landing page url color


//style for markups and layer
var mouseIsOverLayer = false;

if(bIE) var cursorType = 'hand';
else var cursorType = 'pointer';

if (!document.getElementById('kLinkTitle')) {   

document.writeln("<SPAN id='konteraElements'>");
document.writeln("<A href=#  target='_new' id=\"AdLinkLayerClick\"></A>"); 
document.writeln("<DIV onmouseover=\"mouseIsOverLayer = true;\" onmouseout=\" mouseOverWhileLoad=false; hideTitle(event, this);\" class=\"kLinkTitle\" id=\"kLinkTitle\" style=\"cursor:"+cursorType+"; position: absolute; visibility: hidden; display: none;\">");
document.writeln("<DIV id=\"kLinkTitleText\" ></DIV>");

if (aInfoUnits[iTagNumber].dcAL_LY_showCaption.toLowerCase() == 'yes')
	document.writeln("<DIV onmouseover=\"mouseIsOverLayer = true;\" onmouseout=\" mouseOverWhileLoad=false; hideTitle(event, this);\" align=\"center\" class=\"sponsor\" id=\"layerCaption\" style=\"cursor:"+cursorType+"; position: absolute; width: 290px; margin-top: 5px;font-weight:normal\">"+aInfoUnits[iTagNumber].dcAL_LY_captionTxt+"</DIV>");

if (aInfoUnits[iTagNumber].dcAL_explainActive.toLowerCase() == 'yes' && !isInGameLinkPublishersGroup() )
	document.writeln("<DIV style=\"position: absolute; width: 290px; text-align: right; margin-top: 5px;\"><A style='font-weight:normal' target='_new' href=\""+aInfoUnits[iTagNumber].dcAL_explainURL+"/PublisherExplanation/Explanation?pid="+dc_PublisherID+"\" class=\"whatsthis\">"+aInfoUnits[iTagNumber].dcAL_explainText+"</A></DIV>");

// this div is a spacer (since the caption and the help layer are absolute, they need a bg)
if (aInfoUnits[iTagNumber].dcAL_explainActive.toLowerCase() == 'yes' || aInfoUnits[iTagNumber].dcAL_LY_showCaption.toLowerCase() == 'yes')
	document.writeln("<DIV align=\"center\" class=\"sponsor\" style=\"height: 18px;\"></DIV>");


document.writeln("</DIV>");

document.writeln("</SPAN>");
}   







var adLinkStyle=" <STYLE type=\"text/css\">"+

"A.ADLINK_LAYER {"+
	"text-decoration: none;"+
	"}"+
"A.ADLINK_LAYER:hover {"+
	"text-decoration: underline;"+
	"color:"+aInfoUnits[iTagNumber].dcAL_LY_titleFontColor+

	"}"+	
	"A.kLink1 {"+
	"color:"+AdLinkColor+";"+	
		"border-bottom: none;"+
		"border-bottom: 1px "+AdLinkColor+" dotted;"+
		"border-bottom-style:dotted;"+
		"text-decoration: underline;"+				
		"cursor: "+cursorType+";"+	
		"font-family: "+aInfoUnits[iTagNumber].dcAL_LY_FontType+";"+	

			"}"+

	"A.kLink1:visited {"+
		"color:"+AdLinkColor+";"+	
		"border-bottom: none;"+
		"border-bottom: 1px "+AdLinkColor+" dotted;"+
		"text-decoration: underline;"+				
		"cursor: "+cursorType+";"+	
		"font-family: "+aInfoUnits[iTagNumber].dcAL_LY_FontType+";"+

		
	"}"+

	"A.kLink1:hover {"+
		"color:"+AdLinkColor+";"+	
		"border-bottom: 1px "+AdLinkColor+" solid;"+
		"text-decoration: underline;"+				
		"cursor: "+cursorType+";"+		
		"font-family: "+aInfoUnits[iTagNumber].dcAL_LY_FontType+";"+	
		"background-color:"+unescape(aInfoUnits[iTagNumber].dcAL_bgColor)+
		
	
				
	"}"+
	"A.whatsthis {"+
		"font-family: MS Sans Serif, Verdana;"+
		"font-size: 8pt;"+
		"color: #AFAFAF;"+
		"text-decoration: none;"+				
		"cursor: "+cursorType+";"+				
		
	"}"+

	"A.whatsthis:visited {"+
		"font-family: MS Sans Serif, Verdana;"+
		"font-size: 8pt;"+
		"color: #AFAFAF;"+
		"text-decoration: none;"+				
		"cursor: "+cursorType+";"+				
		
	"}"+

	"A.whatsthis:hover {"+
		"font-family: MS Sans Serif, Verdana;"+
		"font-size: 8pt;"+
		"color: blue;"+
		"text-decoration: underline;"+				
		"cursor: "+cursorType+";"+				
	"}"+
	"DIV.kLinkTitle {"+
		"position: absolute;"+
		"font-family: "+aInfoUnits[iTagNumber].dcAL_LY_FontType+";"+
		"font-size: 9pt;"+
		"padding: 2px;"+
		"background-color: "+aInfoUnits[iTagNumber].dcAL_LY_bgColor+";"+
		"border: 1px "+aInfoUnits[iTagNumber].dcAL_LY_borderColor+" solid;"+
		"width: 300px;"+
		"filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=3, OffY=3, Color='#afafaf', Positive='true')"+
	"}"+
	".sponsor {"+
		"font-family: MS Sans Serif, Verdana;"+
		"color: "+aInfoUnits[iTagNumber].dcAL_LY_captionFontColor+";"+
		"font-size: 9pt;"+
		"cursor: default;"+
	"}"+
"</STYLE>";

	document.writeln(adLinkStyle);


document.writeln("<STYLE type=\"text/css\"> .KonaLayer{position:absolute;background-color:white;width=300px} </STYLE>");

//Add an anchore so we can append to it
document.writeln("<SPAN ID=konasapn" + iTagNumber + "></SPAN>");
document.onkeydown = KonakeyDown;
//increase for next tag
iTagNumber++;
/*
-----------------------------------------------------------------------------------------------
--------		COPYRIGHT  ©  2005 Kontera Technologies, Inc. ALL RIGHTS RESERVED       -------							
-----------------------------------------------------------------------------------------------
*/




