var href = document.location.href;
var loc = document.location.href;
var iseyeblaster = false;
var ispopup = false;
var last_popup = null;
function getCookieValue(nm) {var c=document.cookie; var x=c.indexOf(nm+'='); if(x == -1) return null; var y=x+nm.length; var z=c.indexOf(';',y); if(z == -1) z=c.length; var v=c.substring(y,z); if(v.charAt(0) == '=') v=v.substring(1,v.length); return v;}
function getCookieDomain() {var ds = ''; if(href.indexOf('.netzero.net') != -1) ds='; domain=.netzero.net'; if(href.indexOf('.juno.com') != -1) ds='; domain=.juno.com'; if(href.indexOf('.mybluelight.com') != -1) ds='; domain=.mybluelight.com'; return ds;}
function setCookieValue(n,v,days) {expire=';expires=Tue, 24 Jul 2022 01:01:01 GMT'; if (arguments.length>2) {msecs=(days*24*60*60*1000)+(new Date()).getTime();then=new Date(msecs);expire=';expires='+then.toGMTString(); } var ds=getCookieDomain(); document.cookie=n+'='+v+expire+';path=/'+ds;}
function setHostCookie(n,v,days) {expire=';expires=Tue, 24 Jul 2022 01:01:01 GMT'; if (arguments.length>2) {msecs=(days*24*60*60*1000)+(new Date()).getTime();then=new Date(msecs);expire=';expires='+then.toGMTString();} var str = n+'='+v+expire+';path=/'; document.cookie=str;}
function areCookiesEnabled() {setCookieValue('c_check','enabled'); var c=getCookieValue('c_check'); if(c!=null && c.indexOf('enabled') != -1) return true; alert('You must enable cookies to use this site!'); document.location='/s/common?r=cookies'; return false;}
function getURLValue(n) {if(loc.indexOf(n+'=') != -1) {v=loc.substring(loc.indexOf(n+'=')+n.length+1,loc.length); if(v.indexOf('&') != -1) v=v.substring(0,v.indexOf('&')); return v;} return '';}
function isEmpty(i) {return ((i == null)||(i.length==0));}
function setfocus(win) {if(parseInt(navigator.appVersion) >= 4) {if(arguments.length > 0) {win.window.focus();} else {window.focus();}}}
function popup(url,target,widthorsettings,height) {
 var win = null;
 if(arguments.length > 2) {
  var settings = widthorsettings;
  if (arguments.length == 4) settings='scrollbars=yes,resizable=yes,status=no,toolbar=no,location=no,menu=no,width='+widthorsettings+',height='+height;
  win=window.open(url,target,settings); 
 }
 if(arguments.length == 2) {
  win=window.open(url,target); 
 }
 if(arguments.length == 1) {
  win=window.open(url); 
 } 
 if(win != null) {
   last_popup=win;
   ispopup=true;
   setfocus(win);    
 }
}
function popnoscroll(uri,target,width,height) {popup(uri,target,'resizable=no,status=no,toolbar=no,location=no,menu=no,width='+width+',height='+height);}
function PopUp(mypage, myname, w, h, scroll) {var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2; winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'; popup(mypage, myname, winprops);}
function popunder(uri,target) {var p='resizable=yes,status=no,toolbar=no,menu=no,location=no,scrollbars=yes,height='+(screen.height-150)+',width='+(screen.width-10)+',left=0,top=100';B=window.open(uri,target,p);B.blur();setfocus();}
function image() { alert("NOTICE\! These images are for demonstration only\. Please open the appropriate program on your computer and use these images as a reference\.") }
// showing or hiding layer popup, mask, and iframe while changing source of iframe
function popLayer(pop,visi,width,height,maskWidth,maskHeight,maskColor,left,top){

	/* attempt to resolve with a var set in the jsp as a fail-safe when unswapped value is passed in */
	var test = pop.match(/\${[^\.]+\.([^\}]+)}/)
	if(test && test.length){
		//alert('['+window.accountServer+']['+test[1]+']['+eval('window.'+test[1])+']');
		pop = pop.replace(/\${[^\.]+\.([^\}]+)}/,eval('window.'+test[1]));
	}
	
	if(document.layers){
		document.popIframe.src=pop;
		document.transBack.style.visibility=visi;
		document.transBack.style.width=maskWidth;
		document.transBack.style.height=maskHeight;
		document.transBack.style.background=maskColor;
		document.popL.style.visibility=visi;
		document.popIframe.style.width=width+"px";
		document.popIframe.style.height=height+"px";
		document.popL.style.width=width+"px";
		document.popL.style.height=height+"px";
		document.popL.style.left=left;
		document.popL.style.top=top;
	}
	if(document.getElementById){
		document.getElementById("popIframe").src=pop;
		document.getElementById("transBack").style.visibility=visi;
		document.getElementById("transBack").style.width=maskWidth;
		document.getElementById("transBack").style.height=maskHeight;
		document.getElementById("transBack").style.background=maskColor;
		document.getElementById("popL").style.visibility=visi;
		document.getElementById("popIframe").style.width=width+"px";
		document.getElementById("popIframe").style.height=height+"px";
		document.getElementById("popL").style.width=width+"px";
		document.getElementById("popL").style.height=height+"px";
		document.getElementById("popL").style.left=left;
		document.getElementById("popL").style.top=top;
	}
	
	isDrlsOverlay = true;
} 
function rights(server) { var page = 'http://' + server + '/start/landing.do?page=www/popup/yourprivacyrights'; popup (page ,'privacy','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=440,height=460');}
var errImg = (Image ? new Image(1, 1) : undefined);
function myErrorHandler(errorMessage,url,line) {
 var url = '/s/javascript?r=javascript-error&message=' + escape('suppressed at  ' + line + ' ' + errorMessage + ' ' + url);
 if (errImg) errImg.src = url;
 return true;
}
if(!window.onerror) {
	if(!location.host.match(/local/)) window.onerror = myErrorHandler; //apply when customer facing
}

// remove below after next search server push
function logPageViewData(server,application, page, serverTime, startTime) {
 var img = '<img src='+server+'/s/pv?s=999999&a='+application+'&p='+page+'&d='+gl_domain+'&srt=0&crt=0& width=1 height=1 border=0>';
 document.write(img);
}

// function to show login box in an overlay (extending + reusing startpage opverlay code)
function eow_login(){
		document.getElementById("transBack").style.visibility='visible';
		document.getElementById("transBack").style.width='100%';
		document.getElementById("transBack").style.background='#C4DEFF';
		document.getElementById("transBack").style.height=getPageSize()+15;
		document.getElementById("eow-overlay").style.visibility='visible';
		// recalculate height after some dynamic Ads have loaded
		var cumulativeLoad = window.onload;
		window.onload=function() { 
		//Call cumulativeLoad if its != null
		if(cumulativeLoad!=null) { cumulativeLoad(); } 
		eow_login();
		}
}

function eow_overlay_check(ecf){
	// check for overlay cookie
	var cookiejar4r = new cookiejar('CJAR_4');  
	overlayCount=cookiejar4r.getCookie('eow_overlay_count');  
	if(!overlayCount) {overlayCount=0;}
	overlayCount=parseInt(overlayCount);
	if(overlayCount < 2 || ecf == 'eow_overlay_sp') {
	// display 
	eow_login();
	// increment
	overlayCount +=1;
	// reset cookie
	var cookiejar4w = new cookiejar('CJAR_4');  
	cookiejar4w.setCookie("eow_overlay_count",overlayCount);    
	cookiejar4w.write();  
	}
}

function getPageSize(){
	var yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
  return yScroll;
}

/**
 * BANDWIDTH DETECTION SCRIPT
 * ADDED ON 3/29/2007
 */
CONNECTION_TYPE_COOKIE_NAME = "CT";
EXPIRATION_INTERVAL = 7;
COOKIE_PATH = "/";


destination_url = "";
cookie_domain = "";
_throughput = 0;
_connection_type = ""; 		
_semaphoreCT = false;
_semaphoreRDB = false;
		
function callback(throughput, connection_type) {
	_throughput = throughput;
	_connection_type = connection_type;
	run();
}

function set_domain_cookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );

  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }

  var expires_date = new Date( today.getTime() + (expires));

  document.cookie = name + "=" +escape( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  ( ( path ) ? ";path=" + path : "" ) +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ( ( secure ) ? ";secure" : "" );
}

function run() {
	set_untd_cookie();

  if(location.href.match("netzero.net") != null) 
    cookie_domain = "netzero.net";
  else if (location.href.match("juno.com") != null) 
    cookie_domain = "juno.com";
  else if (location.href.match("mybluelight.com") != null) 
    cookie_domain = "mybluelight.com";

  set_domain_cookie(CONNECTION_TYPE_COOKIE_NAME, _connection_type, EXPIRATION_INTERVAL, COOKIE_PATH, cookie_domain, false);
  
}
		
function set_untd_cookie() {
    var RDB_URL = window.location.protocol+'//track.untd.com/s/oasrdb?pid=SDS&profile='+_connection_type;
	exec(RDB_URL);
}

function exec(URL) {
	setTimeout("send_http_request('"+URL+"')", 10);
}
		
function send_http_request(requestURL) {
  var imgObj = (Image ? new Image() : undefined);
  if (imgObj != undefined) {
    imgObj.src = requestURL + "&ts=" + (new Date()).getTime();
    if (!imgObj.complete)
      pause(1000);
  }
}		
		
function pause(millis) {
	var date = new Date();
	var curDate = null;

	do { var curDate = new Date(); }
	while(curDate-date < millis);
	return;
}
//    0 - dialup
//    1 - broadband
//   -2 - unknown		
var BandwidthChecker = {
	startTime: null,
	inProgress: false,
	downloadTimes: [],
	sizeInBytes: 3111,
	noOfTimes: 0,
	standardDownloadTime : 650,
	repeat : 3,
	connTypes: ["0", "1"],
	differenceMargin : 25,
	downloadURL: "http://webmail.netzero.net/images/headers/hdr_lg_new_accl_n.gif",
	imgObj: null,
	kbps: 0,
	cType: null,
	checkBandwidth: function() {
		this.inProgress = true;
		imgObj = new Image();
		imgObj.onload = this.downloaded;
		imgObj.onerror = function() {
			callback(0, -2);
		}
		this.startTime = new Date();
		imgObj.src = this.downloadURL + "?ts=" +  (new Date()).getTime();
	},
	downloaded: function() {
		BandwidthChecker.noOfTimes += 1;
		BandwidthChecker.downloadTimes[BandwidthChecker.noOfTimes-1] = (new Date())-BandwidthChecker.startTime;
		if(BandwidthChecker.noOfTimes<BandwidthChecker.repeat) {
			BandwidthChecker.checkBandwidth();
		} else {
			BandwidthChecker.returnBandWidth();
			this.inProgress = false;
			callback(BandwidthChecker.getConnectionSpeed(), BandwidthChecker.getConnectionType());
		}
	},
	returnBandWidth: function() {
		this.downloadTimes = this.downloadTimes.sort(this.sortAscending);
		nearestNumber	= (this.downloadTimes[1] - this.downloadTimes[0])<=(this.downloadTimes[2] - this.downloadTimes[1]) ? Math.floor((this.downloadTimes[1] + this.downloadTimes[0])/2) : Math.floor((this.downloadTimes[1] + this.downloadTimes[2])/2);
		elapsedTime     =  nearestNumber / 1000;
		sizeInKBits     = (this.sizeInBytes  * 8)/1024;
		kbps       = (sizeInKBits/elapsedTime) * 0.93 ; 		this.kbps       = Math.round(kbps, 2);
		cType           = "";
		this.cType = (nearestNumber>=(this.standardDownloadTime-((this.differenceMargin/100)*this.standardDownloadTime)))?this.connTypes[0]:this.connTypes[1];
	},
	sortAscending: function(a, b) {
		return (a-b);
	},
	getConnectionType: function() {
		return this.cType;
	},
	getConnectionSpeed: function() {
		return this.kbps;
	}
}
/**
 * END OF BANDWIDTH DETECTION SCRIPT
 */
