/*********************************************
 * Helper functions for the display of a 
 * roadblock advertisement.
 *********************************************
*/
var RBContainer, RBBackground, RBAd;
var RBIntID = 0;

ff = false; v3 = false; op = false; ie4  = false; ie5 = false; nn4 = false; nn6 = false; isMac = false; aol = false;
if(document.images){
	if(navigator.userAgent.indexOf("Opera") != -1)op = true;
	else if(navigator.userAgent.indexOf("AOL") != -1) aol = true;
	else if(navigator.userAgent.indexOf("Firefox") != -1) ff = true;
	else {
		if (document.all && !document.getElementById) ie4 = true;
		if (document.layers) nn4 = true;
		if (document.all && document.getElementById) ie5 = true;
		if (document.addEventListener) nn6 = true;
	}
}
else v3 = true;	

if(navigator.userAgent.indexOf("Mac") != -1) { isMac = true; }


// Browser compatible element getter
function GetDocumentElementById(id)
{
	if (document.all)
		return document.all[id];
	if (document.getElementById(id))
		return document.getElementById(id);
	return null;
}

function HandleRBContainer()
{
	var dsoctop = 0;
	var dsoclft = 0;
	if (document.documentElement) {
		dsoctop = document.documentElement.scrollTop;
		dsoclft = document.documentElement.scrollLeft;
	}
	else {
		dsoctop = document.all ? document.body.scrollTop 
			+ (ff || (ie5 && !isMac) ? document.body.parentElement.scrollTop : 0): pageYOffset;
		dsoclft = document.all ? document.body.scrollLeft 
			+ (ff || (ie5 && !isMac) ? document.body.parentElement.scrollLeft : 0): pageXOffset;
	}

	var cliWidth = 0;
	var cliHeight = 0;
	if (op || aol) {
		cliHeight = window.innerHeight;
		cliWidth = window.innerWidth;
	}
	else {
		cliHeight = document.documentElement.clientHeight;
		cliWidth = document.documentElement.clientWidth;
	}
	
	//alert(cliWidth + " x " + cliHeight);
		
	var flt = RBContainer.style;

	flt.height = cliHeight + 'px';
	flt.width = cliWidth + 'px';
	flt.top = dsoctop + 'px';
	flt.left = dsoclft + 'px';
	//alert("End");
	//flt.display = 'block';
	
	if (ie5 && !isMac){
		var DivRef = RBContainer;
		var IfrRef = document.getElementById('DivShim');
		IfrRef.style.top = flt.top;
		IfrRef.style.left = flt.left;
		
		IfrRef.style.width = flt.width;
		IfrRef.style.height = flt.height;
//			IfrRef.style.top = DivRef.style.top;
		//IfrRef.style.left = DivRef.style.left;
		IfrRef.style.display = "block";
		//IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	}
}

function clickAndHide(url)
{
	//alert(url);
	var i = new Image();
	i.src = url;
	reveal();
}

function revealAds() {
	var e = document.getElementById('container');
	e.style.display="block";
}

function reveal()
{
	if (RBIntID != 0) clearInterval(RBIntID);
	RBIntID = 0;
	RBContainer.style.display = 'none';
	if (ie5 && !isMac)
		GetDocumentElementById('DivShim').style.display = "none";
	revealAds();
}

function ShowRoadblock()
{
	
	RBContainer = GetDocumentElementById('roadblockcontainer');
	RBBackground = GetDocumentElementById('roadblockbackground');
	RBAd = GetDocumentElementById('roadblock');

	
	// comment out these 2 lines if you comment the lines beneath.
	RBContainer.style.display = 'block';
	RBIntID = setInterval("HandleRBContainer()", 25);
	
	/* uncomment this if you want to surpress it for a given number of hours
	if (readCookie('roadblock') != 'served')
	{
		RBContainer.style.display = 'block';
		RBIntID = setInterval("HandleRBContainer()", 25);
		writeCookie("roadblock", "served", 12); // change the hours here
	}
	else
	{
		reveal();
	}
	*/
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}


function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function startCount() {
	dispCount = document.getElementById("showCount");
	dispCount.style.display = 'inline';
	countdown();
}

var clock = 11; /*sets total timer count */
function countdown () {
	clock = clock - 1;
	d = document.getElementById("rc");
	d.innerHTML = clock;
	if (clock == 0) {
		reveal();
	}
	x = setTimeout("countdown()",1000);
}
if (index == -1 && introLive == "true" ) {
	document.write ('<script type="text/javascript">\n');
	document.write ('<!--\n');
	document.write ('ShowRoadblock();\n');
	document.write ('//-->\n');
	document.write ('</script>\n');
	document.write ('<p class="close">Sponsored Introduction <span id="showCount"><a href="javascript:void(0);" onclick="clickAndHide();return false;">Continue on to Modern Bulk Transporter</a> (or wait <span id="rc">10</span> seconds) <a class="xButton" href="javascript:void(0);" onclick="clickAndHide();return false;">&times;</a></span></p>\n');

	document.write ('<div class="introstitialAd">\n');
	document.write ('<script type="text/javascript">\n');
	document.write ('var a = Math.random();\n');
	document.write ('var zzzzadslotzzzz= a * 100000;\n');
	document.write ('document.write(');
	document.write ("'");
	document.write ('<scr');
	document.write ("'");
	document.write (' + ');
	document.write ("'");
	document.write ('ipt src=http://ad.doubleclick.net/adj/');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write ('.iclick.com/adtarget;subss=');
	document.write ("'");
	document.write (' + subss + ');
	document.write ("'");
	document.write (';subs=');
	document.write ("'");
	document.write (' + subs + ');
	document.write ("'");
	document.write (';area=');
	document.write ("'");
	document.write (' + area + ');
	document.write ("'");
	document.write (';site=');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write (';kw=;sz=');
	document.write ("'");
	document.write (' + adSize + ');
	document.write ("'");
	document.write (';pos=introstitial;spon=');
	document.write ("'");
	document.write (' + clientNumber + ');
	document.write ("'");
	document.write (';ord=');
	document.write ("'");
	document.write (' + zzzzadslotzzzz + ');
	document.write ("'");
	document.write ('></scr');
	document.write ("'");
	document.write (' + ');
	document.write ("'");
	document.write ('ipt>');
	document.write ("'");
	document.write (');\n');
	document.write ('</script>\n');
	document.write ('<script type="text/javascript">\n');
	document.write ('if ((!document.images && navigator.userAgent.indexOf(');
	document.write ("'");
	document.write ('Mozilla/2.');
	document.write ("'");
	document.write (') >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {\n');
	document.write ('document.write(');
	document.write ("'");
	document.write ('<a href="http://ad.doubleclick.net/jump/');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write ('.iclick.com/adtarget;subss=');
	document.write ("'");
	document.write (' + subss + ');
	document.write ("'");
	document.write (';subs=');
	document.write ("'");
	document.write (' + subs + ');
	document.write ("'");
	document.write (';area=');
	document.write ("'");
	document.write (' + area + ');
	document.write ("'");
	document.write (';site=');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write (';kw=;sz=');
	document.write ("'");
	document.write (' + adSize + ');
	document.write ("'");
	document.write (';pos=introstitial;spon=');
	document.write ("'");
	document.write (' + clientNumber + ');
	document.write ("'");
	document.write (';ord=');
	document.write ("'");
	document.write ('+zzzzadslotzzzz+');
	document.write ("'");
	document.write ('">');
	document.write ("'");
	document.write (');\n');
	document.write ('document.write(');
	document.write ("'");
	document.write ('<img src="http://ad.doubleclick.net/ad/');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write ('.iclick.com/adtarget;subss=');
	document.write ("'");
	document.write (' + subss + ');
	document.write ("'");
	document.write (';subs=');
	document.write ("'");
	document.write (' + subs + ');
	document.write ("'");
	document.write (';area=');
	document.write ("'");
	document.write (' + area + ');
	document.write ("'");
	document.write (';site=');
	document.write ("'");
	document.write (' + siteName + ');
	document.write ("'");
	document.write (';kw=;sz=');
	document.write ("'");
	document.write (' + adSize + ');
	document.write ("'");
	document.write (';pos=introstitial;spon=');
	document.write ("'");
	document.write (' + clientNumber + ');
	document.write ("'");
	document.write (';ord=');
	document.write ("'");
	document.write ('+zzzzadslotzzzz+');
	document.write ("'");
	document.write ('" border="0" alt="" /></a>');
	document.write ("'");
	document.write (');\n');
	document.write ('}\n');
	document.write ('</script>\n');
	document.write ('</div>\n');

	addLoadEvent(startCount); 
}
