function clearEmptyAd(adTag){
	adContainer = document.getElementById(adTag);
	if(adContainer){
		for(i=0; i < adContainer.childNodes.length; i++){
			if(adContainer.childNodes[i].nodeName.toLowerCase() == "a"){
				addLink = adContainer.childNodes[i];
				if(addLink.childNodes[1] && addLink.childNodes[1].nodeName.toLowerCase() == "img"){
					if(addLink.childNodes[1].src.indexOf("grey.gif") != -1){
						adContainer.style.display = "none";
						break;
					}
				}
			}
		}
	}
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

/**
 * @author anderkj
 */
rdb = Get_Cookie("RDB");
publisher = null;
version = null;
zip = null;
zipExt = null;
countryCode = null;
subscriber = null;
incomeHigh = null;
incomeLow = null;
age = null;
gender = null;
keyVals = "";
if(rdb && rdb != "undefined"){
	publisher = rdb.substring(0,2);
	version = rdb.substring(2,4);
	zip = parseInt(rdb.substring(4,10),16);
	zipExt = parseInt(rdb.substring(10,14),16);
	countryCode = parseInt(rdb.substring(14,18),16);
	subscriber = rdb.substring(20,22);
	incomeHigh = rdb.substring(22,24);
	incomeLow = rdb.substring(24,26);
	age = parseInt(rdb.substring(26,28),16);
	if(rdb.substring(18,20) == "01"){
		gender = "male";
	}else{
		gender = "female";
	}
}
if("$keyValues" == ""){
	var keyVals = "zip=" + zip + ";" + "gndr=" + gender;
}else{
	var keyVals = ";zip=" + zip + ";" + "gndr=" + gender;
}

var seg_age = null;
if(age >= 18 && age <= 24){
	seg_age = "18-24";
}else if(age >= 25 && age <= 34){
	seg_age = "25-34";
}else if(age >= 35 && age <= 44){
	seg_age = "35-44";	
}else if(age >= 45 && age <= 54){
	seg_age = "45-54";
}else if(age >= 55 && age <= 64){
	seg_age = "55-64";
}else if(age > 64){
	seg_age = "65";
}
if(seg_age){
	keyVals += ";sage=" + seg_age ;
}

//Generate a page wide random number that dart will use in tags.
ord=Math.floor(Math.random()*10000000000000000);  //moved to top template.

