//Below are percentage for 24/7 ad server per section and position, 0-100 range
lpathname = document.location.pathname.toLowerCase();

//***************************************
//TOP banner: 468, 728
//***************************************
THIRTEENTH_JUROR_TOP = 50;
CHAT_TOP = 50;
//regular index pages, news, people, trials, message_boards, etc
GENERIC_HEADER_TOP = 50;
NEWS_TOP = 50;
//ONAIR_TOP might not be in used
ONAIR_TOP = 50;
PEOPLE_TOP = 50;
STORE_TOP = 50;
TRIALS_TOP = 50;
VIDEO_TOP = 50;
BOOKSTORE_TOP = 50;
MESSAGEBOARDS_TOP = 50;

//***************************************
//RIGHT BANNER: 120,160
//***************************************
NEWS_RIGHT = 50;

ONAIR_RIGHT = 50;
//special conditions, 100% 24/7 for all forensics section

MESSAGEBOARDS_RIGHT = 50;

//***************************************
//MIDDLE BANNER: 300
//***************************************
//all middle is articles
ARTICLE_MIDDLE = 50;

//multimedia middle is for photogalleries, 13thjuror, etc
MULTIMEDIA_MIDDLE = 50;




//***************************************
//DO NOT EDIT BELOW
//***************************************
function getCookie(name)
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  }
  else begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure)
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function fixDate(date) 
{
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0) date.setTime(date.getTime() - skew);
}

//incAdView - Increase Ad View by BL
//pre: 
//	pos is the position name
//		- top: top banners 468, 728, elbows
//		- middle: middle banners, 300
//		- right: right banners 160, 120
//post:
//	increase cookie counter by 1, save the new values.  
//	use previous expiration time if it exist
function incAdView(pos)
{	
	//assign the variables based on position
	//	topAdCount, middleAdCount, rightAdCount
	//	topAdExpire, middleAdExpire, rightAdExpire
	var countVar = pos+"AdCount";
	var expireVar = pos+"AdExpire";
	
	var tempCookie = getCookie(countVar);	
	//check if cookie value is ok	
	if (tempCookie == null || isNaN(tempCookie)) tempCookie =0;
	//convert to int for computation
	tempCookie = parseInt(tempCookie);
	tempCookie = tempCookie+1;	
	var tempExpire = getCookie(expireVar);
	if (tempExpire == null || tempExpire == "")
	{
		tempExpire = new Date();
		fixDate(tempExpire);
		//set expiration time to 24hrs from now
		tempExpire.setTime(tempExpire.getTime() + 24 * 60 * 60 * 1000);
	}
	else 
	{
		tempExpire = new Date(tempExpire);
		fixDate(tempExpire)
	}
	//set the cookies
	setCookie(countVar, tempCookie, tempExpire, "/");
	setCookie(expireVar, tempExpire, tempExpire, "/");	
}
var topAdCount=getCookie("topAdCount");
var top1AdCount=getCookie("top1AdCount");
var rightAdCount=getCookie("rightAdCount");
var middleAdCount=getCookie("middleAdCount");
if (topAdCount == null || isNaN(topAdCount)) topAdCount =0;
if (top1AdCount == null || isNaN(top1AdCount)) top1AdCount =0;
if (rightAdCount == null || isNaN(rightAdCount)) rightAdCount =0;
if (middleAdCount == null || isNaN(middleAdCount)) middleAdCount =0;

//capping allowed views for advertising.com ads
if (topAdCount >= 2)
{
	THIRTEENTH_JUROR_TOP = 101;
	CHAT_TOP = 101;
	GENERIC_HEADER_TOP = 101;
	NEWS_TOP = 101;
	ONAIR_TOP = 101;
	PEOPLE_TOP = 101;
	STORE_TOP = 101;
	TRIALS_TOP = 101;
	VIDEO_TOP = 101;
	BOOKSTORE_TOP = 101;
}

if (top1AdCount >= 10)
{
	MESSAGEBOARDS_TOP = 101;
}

if (rightAdCount >= 10)
{
	NEWS_RIGHT = 101;
	ONAIR_RIGHT = 101;
	MESSAGEBOARDS_RIGHT = 101;
}

if (middleAdCount >= 10)
{
	ARTICLE_MIDDLE = 101;
	MULTIMEDIA_MIDDLE = 101;	
}


