function gr_ads_set_cookie(name,value,seconds)
{
	var expires = "";
	if (seconds)
	{
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function gr_ads_get_cookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function gr_ads_runpixel(url)
{
	var img = new Image();
	img.src = url;
}

function gr_ads_adc_url(size, random, site_code, site_zone, iframe, return_type)
{
	if (size == '300x250,300x600A')
	{
		size = '300x250A|300x600A';
	}
	
	//ni = no interstitial
	var ni = true;
	if (size == '0x0MN')
	{
		ni = false;
	}
	
	var url = 'http://gr.burstnet.com/gr/display/v=4.0S/sz=' + size + '/' + random + 
				'/hosturl=' + site_code + ';' + site_zone + '/ehosturl/' +
					(ni ? 'NI/' : '') +
					(iframe ? '' : 'NF/') + 
					'RETURN-CODE/' + 
					(return_type == 'js' ? 'JS' : 'TXT') + '/';
					
	return url;
}

function gr_ads_dws(url)
{	
	document.write(unescape("%3Cscript src='" + url + "' type='text/javascript'%3E%3C/script%3E"));
}

function gr_ads_parse_custom(custom)
{
	var params = {};
	var parts = custom.split(";");
	
	for(var index in parts)
	{
		var part = parts[index].split('=');
		params[part[0]] = unescape(part[1]);
	}
	
	return params;
}

if (typeof(gr_ads_ord) == 'undefined')
{
	gr_ads_ord = Math.round(Math.random() * 1000000000000000); 
}

if (typeof(gr_ads_zone) == 'undefined')
{
	gr_ads_zone = 'missing-zone';
}

if (typeof(gr_ads_size) == 'undeinfed')
{
	gr_ads_size = '0x0';
}

if (typeof(gr_ads_int_run) == 'undefined')
{
	gr_ads_int_run = false;
}

if (typeof(gr_ads_tile) == 'undefined')
{
	var gr_ads_tile = 1;
}
else
{
	gr_ads_tile++;
}

if (typeof(gr_i_l_m) == 'undefined')
{
	gr_i_l_m = 240;
}

var gr_ads_site_code = 'bscreview';

var gr_ads_current_url = false;
	
try {
	gr_ads_current_url = location.href;
}
catch(e)
{
	gr_ads_current_url = '';
}

if (typeof(gr_ads_iframe) == 'undefined')
{
	gr_ads_iframe = top.location!= self.location;		
}

if (typeof vauPresent == 'undefined' || (gr_ads_size != '300x250' && gr_ads_size != '300x250,300x600'))
{	
	if (typeof(gr_ads_zone) != 'undefined' && typeof(gr_ads_size) != 'undefined')
	{		
		var url = false;
		
		if (gr_ads_current_url.match(/gr_ads_custom=([^&]+)/)) 
		{
			var custom = gr_ads_parse_custom(unescape(RegExp.$1));
			if (custom.adurl)
			{
				url = custom.adurl;
			}
			
			if (custom.runevent)
			{
				gr_ads_runpixel(custom.runevent);
			}

		}
		else {
			url = gr_ads_adc_url(gr_ads_size + 'A', gr_ads_ord, gr_ads_site_code, gr_ads_zone, gr_ads_iframe, 'js');
		} 
		
		//set the cookie that locks out interstitials for N hours
		if (gr_ads_current_url.match(/gr_i_ni/) || gr_ads_zone == 'interstitial') {
			gr_ads_set_cookie('gr_ads_i_ni_' + gr_ads_site_code, 1, 60 * gr_i_l_m);
		}
		
		if (gr_ads_int_run == false && gr_ads_size != '640x480' && gr_ads_size != '1x1')
		{
			if (!gr_ads_current_url.match(/gr_i_ni/) && gr_ads_get_cookie('gr_ads_i_ni_' + gr_ads_site_code) == null)
			{
				gr_ads_int_run = true;
				gr_ads_dws(
					gr_ads_adc_url('0x0MN', gr_ads_ord, gr_ads_site_code, gr_ads_zone, gr_ads_iframe, 'js')
					);
			}
		}
		
		gr_ads_dws(
			url
		);
	}
	else {
		//try Firefox console
		if (typeof(console) != 'undefined' && typeof(console.log) != 'undefined') {
			try {
				console.log("Zone or size undefined.");
			} 
			catch (e) {
			}
		}
	}
}

if (gr_ads_size != '1x1')
{
	if (typeof gr_ads_qc == "undefined" || gr_ads_qc == false) {
		//quantcast STARTS HERE
		_qoptions = {
			qacct: "p-f6YcX3NVRrf9A"
		};
		
		var gr_ads_qc = true;
		var _q_sc = document.createElement('script');
		_q_sc.src = 'http://edge.quantserve.com/quant.js';
		var _q_head = document.getElementsByTagName("head")[0];
		_q_head.appendChild(_q_sc);
	}
	
	/* comScore tag */
	if (typeof gr_ads_comscore == "undefined" || gr_ads_comscore == false) {
		var gr_ads_comscore = true;
		var __cs_c1 = 2;
		var __cs_c2 = "6035244";
		var __cs_c3 = "6035244";
		var __cs_c4 = escape(document.location.href);
		var __cs_c5 = "";
		var __cs_c6 = "";
		var __cs_c15 = "";
		
		var __cs_params = ["c1=", __cs_c1, "&c2=", __cs_c2, "&c3=", __cs_c3, "&c4=", __cs_c4, "&c5=", __cs_c5, "&c6=", __cs_c6, "&c15=", __cs_c15].join('');
		
		var _s_sc = document.createElement('script');
		_s_sc.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js?" + __cs_params;
		document.getElementsByTagName('head')[0].appendChild(_s_sc);
	}
}