/***********************************************************************
 *
 * Copyright (c) 2008-2009 ScanScout, Inc. All Rights Reserved.
 *
 */

// Special code to handle campaigns that require Javascdript (ex: widgets, surveys, etc)
// $Revision: $;
// @author: jburke



if (!self.ScanScout) ScanScout = {};

/******************************************************* START Utility Functions ********************************************/
	function getJsURL(theURL){
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = theURL;

		injectScript(script);
	}
	
	function injectScript(scriptObj){
		var head = document.getElementsByTagName('head').item(0);
		window.setTimeout(function() { head.appendChild(scriptObj) });	
	}
	
	
	function _loadSurveyIFrame(iframeId, iframeUrl) {
		var surveyIframe = document.getElementById(iframeId);
		if (surveyIframe) return;  // Only one is used - the first one.
		surveyIframe = document.createElement('iframe');
		surveyIframe.name = surveyIframe.id = iframeId;
		surveyIframe.style.display = "none";
		surveyIframe.src = iframeUrl;
		document.body.appendChild(surveyIframe);
	}
	/**************************** START Insight Express Utility ****************************/
	function _loadInsightExpressSurveyIFrame(bannerId){
		_loadSurveyIFrame('ss_IXTagFrame', "http://core.insightexpressai.com/adServer/adServerESI.aspx?bannerID=" + bannerId + "&script=true");
	}		
	/**************************** END Insight Express Utility ****************************/
	
		
	/**************************** START QuestionMarket Utility ****************************/
	function _loadQuestionMarketSurvey(surveyId){
		getJsURL('http://amch.questionmarket.com/adsc/' + surveyId + '/randm.js');
	}		
	/**************************** END QuestionMarket Utility ****************************/	
	
	/**************************** START FactorFG Utility ****************************/
	function _loadFactorFGSurvey(urlSuffix, gid){
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.id ="FTG";
		script.src = "http://as1.suitesmart.com/" + urlSuffix + ".js";
		script.GID = gid;
		injectScript(script);
	}		
	/**************************** END FactorFG Utility ****************************/		

/******************************************************* END Utility Functions ********************************************/




/******************************************************* START Surveys ********************************************/
	


	var surveyCampaignPubs = "|208|427|508|510|511|513|533|553|565|595|596|597|603|611|618|625|631|632|634|641|642|643|644|645|646|647|648|649|650|651|654|655|656|657|659|660|661|662|663|664|665|671|672|673|675|684|686|699|702|705|706|707|711|712|713|718|719|720|730|737|739|743|744|745|749|750|752|753|754|755|757|763|764|769|794|795|796|797|837|840|841|842|843|844|847|853|854|855|861|863|864|865|866|867|868|869|870|878|879|880|884|885|886|887|888|889|900|906|909|910|911|919|930|936|937|938|943|944|947|956|957|963|970|971|972|973|974|989|11002|11003|13002|13003|13004|14019|16002|17003|17005|17006|17007|17008|17009|17010|17011|17012|17013|17014|17015|17016|17017|17018|17019|17020|17021|17022|17023|17024|17025|17026|17027|17028|17029|17030|17031|17032|17033|17034|17035|17036|17037|17038|17039|17040|17041|17042|17043|17044|17045|17046|17047|17048|17049|17050|17051|17052|17053|17054|17055|17056|17057|17058|17059|17060|17061|17062|17063|17064|17065|17066|17067|17068|17069|17070|17071|17072|17073|17074|17075|17076|17077|17078|17079|17080|17081|17082|17083|17084|17085|17086|17087|17088|17089|17090|17091|17092|17093|17094|17095|17096|17097|17098|17099|17100|17101|17102|17103|17104|17105|17106|17107|17108|17109|17110|17111|17112|17113|17114|17115|17116|17117|17118|17119|17120|17121|17122|17123|17124|17125|17126|17127|17128|17129|17130|17131|17132|17133|17134|17135|17136|17137|17138|17139|17140|17141|17142|17143|17144|17145|17146|17147|17148|17149|17150|17151|17152|17153|17154|17155|17156|17157|17158|17159|17160|17161|17162|17163|17164|17165|17166|17167|17168|17169|17170|17171|17172|17173|17174|17175|17176|17177|17178|17179|17180|17181|17182|17183|17184|17185|17186|17187|17188|17189|17190|17191|17192|17193|17194|17195|17196|17197|17198|17199|17200|17201|17202|17203|17204|17205|17206|17207|17208|17209|17210|17211|17212|17213|17214|17215|17216|17217|17218|17219|17220|17221|17222|17223|17224|17225|17226|17227|17228|17229|17230|17231|17232|17233|17234|17235|17236|17237|17238|17239|17240|17241|17242|17243|17244|17245|17246|17247|17248|17249|17250|17251|17252|17253|17254|17255|17256|17257|17258|17259|17260|17261|17262|17263|17264|17265|17266|17267|17268|17269|17270|17271|17272|17273|17274|17275|17276|17277|17278|17279|17280|17281|17282|17283|17284|17285|17286|17287|17288|17289|17290|17291|17292|17293|17294|17295|17296|17297|17298|17299|17300|17301|17302|17303|17304|17305|17306|17307|17308|17309|17310|17311|17312|17313|17314|17315|17316|17317|17318|17319|17320|17321|17322|17323|17324|17325|17326|17327|17328|17329|17330|17331|17332|17333|17334|17335|17336|17337|17338|17339|17340|17341|17342|17343|17344|17345|17346|17347|17348|17349|17350|17351|17352|17353|17354|17355|17356|17357|17358|17359|17360|17361|17362|17363|17364|17365|17366|17367|17368|17369|17370|17371|17372|17373|17374|17375|17376|17377|17378|17379|17380|17381|17382|17383|17384|17385|17386|17387|17388|17389|17390|17391|17392|17393|17394|17395|17396|17397|17398|17399|17401|17402|17403|17404|17405|17406|17407|17408|17409|17410|17411|17412|17413|17414|17415|17416|17417|17418|17419|17420|17421|17422|17423|17424|17425|17426|17427|17428|17429|17430|17431|17432|17433|17434|17435|17436|17437|17438|17439|17440|17441|17442|17443|17444|17445|17446|17447|17448|17449|17450|17451|17452|17453|17454|17455|17456|17457|17458|17459|17460|17461|17462|17463|17464|17465|17466|17467|17468|17469|17470|17471|17472|17473|17474|17475|17476|17477|17478|17479|17480|17481|18001|18002|18003|18004|18005|18006|20002|20003|20004|20005|26002|27002|27003|27004|27005|30002|30003|30004|30005|30006|30007|30008|31003|36032|38001|39004|39005|40004|40005|40006|40007|40008|41002|41003|41004|42002|43002|47002|49002|49003|52001|56002|56015|56018|56021|56022|56028|56033|56034|56035|56040|56043|56044|56045|56048|56049|56052|56057|56058|56061|56062|56066|56069|56070|56077|56081|56084|56086|56088|56089|56117|56120|56122|56123|56124|56125|56126|56127|56128|56129|56130|56186|56187|56191|56205|56207|56209|56210|56211|56215|56216|56217|56218|56219|56220|56221|56222|56223|56224|56227|56228|56229|56230|56231|56232|56233|56234|56235|56236|56237|56238|56239|56240|56241|56242|56247|56248|56249|56250|56251|56254|56255|56262|56266|56267|56270|56277|56278|56279|56280|56281|56282|56283|56284|56285|56286|56290|56291|56292|56293|56294|56295|56298|56299|56301|56302|56303|56311|56319|56320|56323|56332|56333|56334|56337|56338|56339|56340|56342|56344|56347|56348|56352|56362|56365|56366|56367|56369|56382|56394|56395|56396|56397|56398|56399|56400|56401|56402|56403|56404|56405|56406|56407|56409|56415|56416|56417|56418|56419|56420|56421|56422|56423|56424|56425|56426|56427|56428|56429|56430|56431|56432|56433|56434|56435|56436|56437|56438|56439|56440|56441|56442|56443|56444|56445|56446|56447|56448|56449|56450|56451|56452|56453|56454|56455|56456|56457|56459|56463|56464|56465|56466|56467|56468|56469|56470|56471|56472|56473|56474|56475|56476|56477|56485|56486|56487|56491|56492|56499|56500|56501|56506|56509|56510|56511|56517|56518|56519|56520|56521|56522|56523|56524|56525|56526|56527|56529|56535|56548|56551|56552|56553|56556|56561|56565|56567|56568|56569|56571|56572|56573|56574|56575|56576|56577|56578|56579|56580|56581|56582|56583|56584|56585|56588|56589|56592|56593|56597|56601|56603|56605|56607|56608|56609|56613|56614|56615|56616|56617|56618|56619|56620|56621|56622|56623|56625|56626|56628|56632|56636|56639|56643|56645|56646|56647|56648|56650|56653|56654|56655|56656|56658|56659|56660|56661|56662|56663|56664|56665|56666|56667|56668|56669|56670|56672|56673|56674|56675|56676|56677|56678|56679|56680|56681|56682|56683|56684|56685|56686|56687|56688|56689|56691|56954|56949|56950|56948|56945|56942|56941|56933|56921|56885";
	var surveyCampaignIds = ["1247519","1247531","1247532","1247533","1247534","1247535","1247536","1247537","1247538","1247539","1247540","1247541"]; 


	ScanScout.runCampaignFunctionality = function(publisherId, campaignId, adPosition){
		if (surveyCampaignPubs.indexOf("|" + publisherId + "|") > -1){
			ss_campaignDebug('surveyCampaignIds: ' + surveyCampaignIds);
			ss_campaignDebug('surveyCampaignIds.length: ' + surveyCampaignIds.length);
			for (var i = 0; i < surveyCampaignIds.length; i++){
			  var _currentCampaignId = surveyCampaignIds[i];
			  ss_campaignDebug('surveyCampaignIds[' + i + ']' + surveyCampaignIds[i]);
			  if (_currentCampaignId == campaignId){
				ScanScout.callTestCampaignSurvey(_currentCampaignId, adPosition);
			  } else {
			 	ss_campaignDebug('this campaign is not ' + _currentCampaignId + ' so call control');
				ScanScout.callControlCampaignSurvey(_currentCampaignId, adPosition);
			  }
			}

		}
	}
	ScanScout.callTestCampaignSurvey = function(campaignId, adPosition){	//Only call test function if the current campaign is a survey campaign
		//if (adPosition == 1){  //for now, just run these on the first ad in the schedule
			ss_campaignDebug('call _callSsCampaignTestSurvey_' + campaignId);
			try {
				if(navigator.appName.indexOf("Microsoft") != -1) {
					window['_callSsCampaignTestSurvey_' + campaignId](adPosition);
				} else {
					document['_callSsCampaignTestSurvey_' + campaignId](adPosition);
				}	
			} catch (error){
				ss_campaignDebug('callTestCampaignSurvey: ' + error.message)
			}
		//}
	};
	ScanScout.callControlCampaignSurvey = function(campaignId, adPosition){
		if (adPosition == 1){  //for now, just run these on the first ad in the schedule
			ss_campaignDebug('call _callSsCampaignControlSurvey_' + campaignId);
			try {
				if(navigator.appName.indexOf("Microsoft") != -1) {
					window['_callSsCampaignControlSurvey_' + campaignId](adPosition);
				} else {
					document['_callSsCampaignControlSurvey_' + campaignId](adPosition);
				}							
			} catch (error){
				ss_campaignDebug('callControlCampaignSurvey: ' + error.message)
			}
		}
	}
	


	/********** Start HR Block Campaigns *******/

	var _hasCalledTestSurvey_1247519= false;
	function _callSsCampaignTestSurvey_1247519(adPosition){
		if (!_hasCalledTestSurvey_1247519){
			_loadQuestionMarketSurvey('d677941/16/695022');
			_hasCalledTestSurvey_1247519 = true;
		}
	}
	
	
	var _hasCalledTestSurvey_1247531= false;
	function _callSsCampaignTestSurvey_1247531(adPosition){
		if (!_hasCalledTestSurvey_1247531){
			_loadQuestionMarketSurvey('d677941/16/694941');
			_hasCalledTestSurvey_1247531 = true;
		} 
	}
	

	var _hasCalledTestSurvey_1247532= false;
	function _callSsCampaignTestSurvey_1247532(adPosition){
		if (!_hasCalledTestSurvey_1247532){
			_loadQuestionMarketSurvey('d677941/16/694941');
			_hasCalledTestSurvey_1247532 = true;
		}
	}
	


	var _hasCalledTestSurvey_1247533= false;
	function _callSsCampaignTestSurvey_1247533(adPosition){
		if (!_hasCalledTestSurvey_1247533){
			_loadQuestionMarketSurvey('d677941/16/694941');
			_hasCalledTestSurvey_1247533 = true;
		}
	}
	


	var _hasCalledTestSurvey_1247534= false;
	function _callSsCampaignTestSurvey_1247534(adPosition){
		if (!_hasCalledTestSurvey_1247534){
			_loadQuestionMarketSurvey('d677941/16/694941');
			_hasCalledTestSurvey_1247534 = true;
		}
	}
	


	var _hasCalledTestSurvey_1247535= false;
	function _callSsCampaignTestSurvey_1247535(adPosition){
		if (!_hasCalledTestSurvey_1247535){
			_loadQuestionMarketSurvey('d677941/16/695022');
			_hasCalledTestSurvey_1247535 = true;
		}
	}



	var _hasCalledTestSurvey_1247536= false;
	function _callSsCampaignTestSurvey_1247536(adPosition){
		if (!_hasCalledTestSurvey_1247536){
			_loadQuestionMarketSurvey('d677941/16/695022');
			_hasCalledTestSurvey_1247536 = true;
		}
	}
	

	var _hasCalledTestSurvey_1247537= false;
	function _callSsCampaignTestSurvey_1247537(adPosition){
		if (!_hasCalledTestSurvey_1247537){
			_loadQuestionMarketSurvey('d677941/16/695022');
			_hasCalledTestSurvey_1247537 = true;
		}
	}



	var _hasCalledTestSurvey_1247538= false;
	function _callSsCampaignTestSurvey_1247538(adPosition){
		if (!_hasCalledTestSurvey_1247538){
			_loadQuestionMarketSurvey('d677941/16/695021');
			_hasCalledTestSurvey_1247538 = true;
		}
	}
	
	
	var _hasCalledTestSurvey_1247539= false;
	function _callSsCampaignTestSurvey_1247539(adPosition){
		if (!_hasCalledTestSurvey_1247539){
			_loadQuestionMarketSurvey('d677941/16/695021');
			_hasCalledTestSurvey_1247539 = true;
		}
	}
	

	var _hasCalledTestSurvey_1247540= false;
	function _callSsCampaignTestSurvey_1247540(adPosition){
		if (!_hasCalledTestSurvey_1247540){
			_loadQuestionMarketSurvey('d677941/16/695021');
			_hasCalledTestSurvey_1247540 = true;
		}
	}	


	var _hasCalledTestSurvey_1247541= false;
	function _callSsCampaignTestSurvey_1247541(adPosition){
		if (!_hasCalledTestSurvey_1247541){
			_loadQuestionMarketSurvey('d677941/16/695021');
			_hasCalledTestSurvey_1247541 = true;
		}
	}		
	/********** End HR Block Campaigns *******/

	
	
	

/******************************************************* END Surveys ********************************************/


/******************************************************* START ScanScoutLogger ********************************************/
if (!self.ScanScoutLogger) ScanScoutLogger = {};

ScanScoutLogger.logMsg = function(logEntry)
// Display log entry in popup.
{
	var now = new Date();
	var theTime = ScanScoutLogger.sprintf("%d:%'02d:%'02d:%'03d", now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());

	logEntry = theTime + ' | ' + logEntry;
	var debugElement = ScanScoutLogger.getElement('ss_debug');
	if (debugElement && debugElement.style.display != 'none')
	{
		debugElement.value = logEntry + '\n' + debugElement.value;
	}
	else if (ScanScoutLogger.debugging)
	{
		// Accumulate it for later, truncated to 5K chars.
		// TODO: append to array instead.
		ScanScoutLogger.initialLog = (ScanScoutLogger.initialLog || '').substring(0, 5000);
		ScanScoutLogger.initialLog = logEntry + '\n' + (ScanScoutLogger.initialLog || '');
	}
};

ScanScoutLogger.getElement = function (idOrName)
// Get an element identified by id or name attribute.
{
	var element = document.getElementById(idOrName);
	if (element) return element;
	var elements = document.getElementsByName(idOrName);
	if (elements && elements.length > 0) return elements[0];
};

ScanScoutLogger.init = function (e)
{
	// Append a new DIV to the body. 
	var debugWrapper = document.createElement('div');
	debugWrapper.id = 'ss_debug_wrapper';
	debugWrapper.style.position = 'absolute';
	debugWrapper.style.top = '100px';
	debugWrapper.style.left = '100px';
	debugWrapper.style.width = '900px';
	debugWrapper.style.border = '2px outset';
	debugWrapper.style.backgroundColor = 'lightblue'; 
	debugWrapper.style.padding = '2px';
	debugWrapper.style.fontSize = 'small';

	var body = document.getElementsByTagName('body').item(0);
	body.appendChild(debugWrapper);

	var debugHTML =
		'<div id="ss_debug_titlebar" style="padding:2px" title="Drag slowly"><nobr>' +
		'ScanScout Debugger' +
		'&nbsp;&nbsp;&nbsp;' +
		'<button onClick="ScanScoutLogger.toggleShowDebug(); return false;" title="Hide or Show the log">Hide/Show</button>' +
		'<button onClick="ScanScoutLogger.clearDebug(); return false;" title="Clear the log">Clear</button>' +
		'&nbsp;&nbsp;&nbsp;' +

		'</nobr></div>' +
		'<textarea id="ss_debug" cols=120 rows=20 style="width:100%">' + 
		(ScanScoutLogger.initialLog || '') + 
		'</textarea>';
	debugWrapper.innerHTML = debugHTML;

	var debugTitlebar = document.getElementById('ss_debug_titlebar');
	debugTitlebar.style.cursor = 'move';
	debugTitlebar.onmousedown = ScanScoutLogger.debugDragStart;
	debugTitlebar.onmousemove=ScanScoutLogger.debugDrag;
	debugTitlebar.onmouseup=ScanScoutLogger.debugDragEnd;

}

ScanScoutLogger.toggleShowDebug = function ()
{
	var log = document.getElementById('ss_debug');
	var display = log.style.display;
	log.style.display = (display == 'none' ? 'block' : 'none');
}


ScanScoutLogger.clearDebug = function ()
{
	document.getElementById('ss_debug').value = '';
}

ScanScoutLogger.debugDragStart = function (e)
{
	ScanScoutLogger.debugDrag.dragging = true;
	if (document.body.attachEvent)
		document.body.attachEvent("move", ScanScoutLogger.debugDrag)
	else
		document.body.addEventListener("move", ScanScoutLogger.debugDrag, false);

	e = e || window.event;	
	ScanScoutLogger.getMouseXY(e);

	var debugWrapper = document.getElementById('ss_debug_wrapper');
	if (!debugWrapper) return;
	
	debugWrapper.style.top;
	ScanScoutLogger.debugDrag.xOffset = ScanScoutLogger.debugDrag.x - debugWrapper.offsetLeft;
	ScanScoutLogger.debugDrag.yOffset = ScanScoutLogger.debugDrag.y - debugWrapper.offsetTop;
}

ScanScoutLogger.getMouseXY = function (e)
{
  	// grab the x-y pos.s if browser is NS
	ScanScoutLogger.debugDrag.x = e.pageX;
	ScanScoutLogger.debugDrag.y = e.pageY;
	if (ScanScoutLogger.getBrowserType() == 0)
 	{ 
		// grab the x-y pos.s if browser is IE
		ScanScoutLogger.debugDrag.x = e.clientX + document.body.scrollLeft;
		ScanScoutLogger.debugDrag.y = e.clientY + document.body.scrollTop;
 	}
}

ScanScoutLogger.debugDrag = function (e)
{
	if (!ScanScoutLogger.debugDrag.dragging) return;
	e = e || window.event;	
	ScanScoutLogger.getMouseXY(e);
	
	var debugWrapper = document.getElementById('ss_debug_wrapper');
	if (!debugWrapper) return;
	
	debugWrapper.style.left = (ScanScoutLogger.debugDrag.x - ScanScoutLogger.debugDrag.xOffset) + 'px';
	debugWrapper.style.top = (ScanScoutLogger.debugDrag.y - ScanScoutLogger.debugDrag.yOffset) + 'px';
};
ScanScoutLogger.debugDrag.dragging = false;

ScanScoutLogger.debugDragEnd = function ()
{
	ScanScoutLogger.debugDrag.dragging = false;
	if (document.body.detachEvent)
		document.body.detachEvent("move", ScanScoutLogger.debugDrag)
	else
		document.body.removeEventListener("move", ScanScoutLogger.debugDrag, true);
};



ScanScoutLogger.getBrowserType = function()
// Return browser type:  MSIE: 0,  Firefox: 1,  Opera: 2,  Others: 3
{
	var ua = window.navigator.userAgent;
	if (ua.indexOf("MSIE") >=0) {
		return 0;
	} else if (ua.indexOf("Firefox/") >=0) {
		return 1;
	} else if (ua.indexOf("Opera/") >=0) {
		return 2;
	} else {
		return 3;	// Other
	}
}


ScanScoutLogger.str_repeat = function (i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); };

ScanScoutLogger.sprintf = function () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? ScanScoutLogger.str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
};

/******************************************************* END ScanScoutLogger ********************************************/







/****************************************************START Debugging**********************************************/

var _ssDebugging = false;
var _ssDebugCounter = 1;
function ss_campaignDebug(msg){
	if (_ssDebugging){
		try {
			document.getElementById("adData").innerHTML = ('<hr/><h3>Message#' + (_ssDebugCounter++) + ': ' + msg + '</h3>') + document.getElementById("adData").innerHTML;
			return;
		} catch (error){alert('error in ss_campaignDebug: ' + error);}
	}
}

function getUseDebugging(){
	try { 
	  if (ss_developmentMode == true)  {
		return true;
	  } else {
	 	return false
	  }
	} catch (e){
		return false;
	}
}

function testShowDebugging(){
    	if (getUseDebugging()){
    		clearDebugging();
    		_innerTestShowDebugging();
    	}
 }

function ss_flashDebugging(msg){
	try {
		document.getElementById("ss_flashDebugging").innerHTML = ('<hr/><h3>' + msg + '</h3>') + document.getElementById("ss_flashDebugging").innerHTML;
		return;
	} catch (error){}
}
 
 function _innerTestShowDebugging(){
     	try {
     		var debugCell = document.getElementById("debugCell");
     		var debugDivClearButton = document.createElement("input");
     		debugDivClearButton.setAttribute("type", "button");
     		debugDivClearButton.setAttribute("onClick", "document.getElementById('ss_flashDebugging').innerHTML = '';");
     		debugDivClearButton.setAttribute("value", "Clear Debugging");
     		debugCell.appendChild(debugDivClearButton);
 
     		var debugDiv = document.createElement("div");
 		debugDiv.setAttribute("style", "width: 300px; height: 500px; overflow:auto; padding:4px; border:solid 1px #CCCCCC; font-size: x-small; font-family: Arial; background: #dadada;");
     		debugDiv.setAttribute("id", "ss_flashDebugging");
     		debugCell.appendChild(debugDiv);
    	} catch (e){alert("errror: " + e.message);} 
 
 }
 
 function clearDebugging(){ 
 	try {
 		var debugCell = document.getElementById("debugCell");
 		debugCell.innerHTML = ''; 	
 	} catch (e){
 	}
 }
 /****************************************************END Debugging**********************************************/
 
 /****************************************************Start Domain Detection*************************************/ 
 ScanScout.completeFlg = 0;
 ScanScout.browser = "";
 ScanScout.flashUrl = "http://media.scanscout.com/ads/ssAdvUsrSeg.swf";
 
 ScanScout.loaded = 0;
 
 ScanScout.initPage = function() {
 	//Create a div
 	var e = document.createElement("div");
 	e.id = "ss_DomDecDiv";
 	e.style.position = 'absolute'
 	e.style.top = window.window.pageYOffset || document.body.scrollTop || 0;;
 	e.style.left= window.window.pageXOffset || document.body.scrollLeft || 0;;
    	document.body.appendChild(e); 
    	
    	if (navigator.appName.indexOf("Microsoft") != -1) ScanScout.browser = "IE";
 }
 
 ScanScout.startUserSeg = function (pubId){
 	if (ScanScout.loaded == 0) ScanScout.initPage();

 	var e = document.getElementById('ss_DomDecDiv');

 	var flashElement = document.getElementById('ssFlashEmb');
 	if (flashElement) e.removeChild(flashElement);

	if (pubId == null) pubId = "0";
 	
 	var flashEmbed = "";
 	var flashVars = "pubId=" + pubId; 
 	if (ScanScout.browser == "IE") flashEmbed = ScanScout.buildObject("ssFlashEmb", ScanScout.flashUrl, 1,1, flashVars);
 	else flashEmbed = ScanScout.buildEmbed("ssFlashEmb", ScanScout.flashUrl, 1,1, flashVars);
 	e.innerHTML = flashEmbed;
 	
 	ScanScout.loaded=1;
 }
 
 ScanScout.isUserSegComplete = function() {
 	return ScanScout.completeFlg;
 }
 
 
 
 ScanScout.buildObject = function (id, url, width, height, vars)
 {
 	var obj = '<object id="'+ id +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="border: 0px solid red" width="'+ width +'" height="'+ height +'">';
 	obj += '<param name="movie" value="'+ url +'" />';
 	obj += '<param name="allowScriptAccess" value="always" />';
 	obj += '<param name="wmode" value="transparent" />';
 	obj += '<param name="scale" value="noscale" />';
 	obj += '<param name="salign" value="tl" />';
 	obj += '<param name="flashvars" value="'+ vars +'" />';
 	obj += "</object>";
 	return obj;	
 }
 
 ScanScout.buildEmbed = function (id, url, width, height, vars)
 {
 	var embed = '<embed id="'+id+'" name="'+id+'"' +
 		' src="' + url + '"' +
 		' type="application/x-shockwave-flash"' +
 		' pluginsPage="http://www.macromedia.com/go/getflashplayer"' +
 		' allowScriptAccess="always"' +
 		' wmode="transparent"' +
 		' scale="noscale" salign="tl"' +
 		' width="' + width + '"' +
 		' height="' + height + '"' +
 		' style="border: 0px solid red"' +
 		' flashVars="' + vars + '"' +
 		'></embed>';
 		
 	return embed;	
 }
 /****************************************************END Debugging**********************************************/
