
function imageRestore() { 
  var i,x,a=document.sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function loadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=loadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function objLoc(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if (!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=objLoc(n,d.layers[i].document);
  if (!x && d.getElementById) x=d.getElementById(n); return x;
}

function imageOver() {
  var i,j=0,x,a=imageOver.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=objLoc(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// reload NS 4 i window ifs resized
function nsReload(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=nsReload; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
nsReload(true);


function LayerSwap() { //v6.0
  var i,p,v,obj,args=LayerSwap.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=objLoc(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


// *************** DS's POPUP SCRIPT *************** //
function popWin(fileName,windowName,theWidth,theHeight) {
window.open(fileName,windowName,"alwaysRaised=1,dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1 resizable=1,left=20,top=20,width="+theWidth+",height="+theHeight);
 }

// *************** DS's POPUP SCRIPT *************** //
function popWin2(fileName,windowName,theWidth,theHeight) {
window.open(fileName,windowName,"alwaysRaised=1,dependent=1,toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=20,top=20,width="+theWidth+",height="+theHeight);
      }

function popWin3(fileName,windowName,theWidth,theHeight) {
window.open(fileName,windowName,"alwaysRaised=1,dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,left=20,top=20,width="+theWidth+",height="+theHeight);
      }
function popWin4(fileName,windowName,theWidth,theHeight) {
window.open(fileName,windowName,"alwaysLowered=1,dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,left=20,top=20,width="+theWidth+",height="+theHeight);
      }

function glossary(entry) {
	 var theFileName = "/support/glossary/definition.shtml?tw="+ entry;
	 var newWindow = window.open(theFileName,
		"glossaryPopup",
"width=334,height=215,screenX=10,screenY=10,directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,copyhistory=no"); 
}	  

function gotoURL() {
  var Current = document.toswitch.isplist.selectedIndex;
  window.location.href = document.toswitch.isplist.options[Current].value;
  return false;
}


// *************** ROI Campign Code - START *************** //
function roiHit(roiImageUrl) {
	var roiImage = new Image();

	if(roiImageUrl.match(/.+\?.+/)) {
		roiImageUrl += "&";
	} else {
		roiImageUrl += "?";
	}
	roiImageUrl += "mpuid=" + cookieData.getSessionId();	// seesion id to keep duplicate vists from being logged

	roiImage.src = roiImageUrl;

	// DEBUG
	//alert("DEBUG - ROI Tag URL to hit for this page:\n" + roiImageUrl);
	if(document.getElementById('roiTest')) {
		var roiTestDiv = document.getElementById('roiTest');
		roiTestDiv.innerHTML = '<font color="#FFFFFF">' + roiImageUrl + 
		'</font>' + '<img src="' + roiImageUrl + '" width="1" height="1" border="0">'; // added the image tag for further debugging
	}
}
// *************** ROI Campign Code - END *************** //


// === COVAD DOMAIN SNIFF ==//
// =============== SOC.GR SCRIPT =============== //
// looks at the pages domains and returns the appropriate domain for setting a cookie
function CookieDomain() {
	function IsDomainIp() {
		var isIpTest = true;
		var domainArr = new Array();
		domainArr = document.domain.split(".");
	
		for(i=0; i<domainArr.length; i++) {
			if(isNaN(domainArr[i])) {
				isIpTest = false;
				break;
			}
		}
	
		return isIpTest;
	}

	if(!IsDomainIp()) {
		var currDomainArr = document.domain.split(".");
		var currDomainArrLen = currDomainArr.length;
		var currDomainType = currDomainArr[currDomainArrLen-1];
		var currDomainName = currDomainArr[currDomainArrLen-2];
		var currDomain = "." + currDomainName + "." + currDomainType;
	} else {
		var currDomain = document.domain;
	}

	// alert("Cookie Domain: " + currDomain);
	return currDomain;
}


if(CookieDomain() == ".covad.com") {
	// parse the query string for any attributes
	function parseQueryString (str) {
		str = str ? str : location.search;
		var query = str.charAt(0) == '?' ? str.substring(1) : str;
		var args = new Object();
	
		if(query) {
			var fields = query.split('&');
			for(var f = 0; f < fields.length; f++) {
				var field = fields[f].split('=');
				if(field[1]) {	// there is a chance that this field is null or no value was provided for the key
					args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
				} else {
					args[unescape(field[0].replace(/\+/g, ' '))] = "";
				}
			}
		}
		return args;
	}


	function SetCookie (name, value) {
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : "/";
		var domain = (argc > 4) ? argv[4] : cookieDomain;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}


	function DeleteCookie (name) {
		alert (name);
		var argv = DeleteCookie.arguments;
		var argc = DeleteCookie.arguments.length;
		var path = (argc > 1) ? argv[3] : null;
		var domain = (argc > 2) ? argv[4] : null;
		var cval = GetCookie(name);
		var exp = new Date();
		exp.setTime (exp.getTime() - 100);
	
		document.cookie =	name + "=" + cval + 
			"; expires=" + exp.toGMTString() +
			((path == null) ? "; path=/" : ("; path=" + path)) +
			((domain == null) ? "; domain=.covad.com" : ("; domain=" + domain));
	}


	function getCookieVal(offset) {
	   var endstr = document.cookie.indexOf (";", offset);
	   if (endstr == -1) endstr = document.cookie.length;
	   return unescape (document.cookie.substring(offset, endstr));
	}


	function GetCookie(name) {
	   var arg = name+"=";
	   var alen = arg.length;
	   var clen = document.cookie.length;
	   var i = 0;
	   while (i < clen) {
	      var j = i + alen;
	      if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
	      i = document.cookie.indexOf(" ", i) + 1;
	      if (i == 0) break;
	   }
	   return null;
	}


	function cookieExpDays(days) {
		var expDays = 0;
		expDays = new Date((new Date()).getTime() + days * 24 * 60 * 60 * 1000);
		return expDays;
	}

	function cookieExpHours(hours) {
		var expHours = 0;
		expHours = new Date((new Date()).getTime() + hours * 60 * 60 * 1000);
		return expHours;
	}

	function cookieExpMinutes(minutes) {
		var expMin = 0;
		expMin = new Date((new Date()).getTime() + minutes * 60 * 1000);
		return expMin;
	}


	function CookieData() {
		this._ut = null;
		this._bid = null;
		this._rc = null;
		this._srcId = "";	// leads db needs this as a blank or a string
		this._ivrSrc = null;
		this._sa = null;
		this._sessionId = null;
		this._firstUrl = null;
		this._httpReferrer = null;
		// HANDLE OLD VARIABLES PRIOR TO CBS LAUNCH 12/12/03
		this._t = null;
		this._s = null;

		this.getUt = function (e) { return this._ut; }
		this.getBid = function (e) { return this._bid; }
		this.getRc = function (e) { return this._rc; }
		this.getSrcId = function (e) { return this._srcId; }
		this.getIvrSrc = function (e) { return this._ivrSrc; }
		this.getSa = function (e) { return this._sa; }
		this.getSessionId = function (e) { return this._sessionId; }
		this.getFirstUrl = function (e) { return this._firstUrl; }
		this.getHttpReferrer = function (e) { return this._httpReferrer; }
		// HANDLE OLD VARIABLES PRIOR TO CBS LAUNCH 12/12/03
		this.getT = function (e) { return this._t; }
		this.getS = function (e) { return this._s; }
	}
	CookieData.prototype.setUt = function(_ut) { this._ut = _ut; }
	CookieData.prototype.setBid = function(_bid) { this._bid = _bid; }
	CookieData.prototype.setRc = function(_rc) { this._rc = _rc; }
	CookieData.prototype.setSrcId = function(_srcId) { this._srcId = _srcId; }
	CookieData.prototype.setIvrSrc = function(_ivrSrc) { this._ivrSrc = _ivrSrc; }
	CookieData.prototype.setSa = function(_sa) { this._sa = _sa; }
	CookieData.prototype.setSessionId = function(_sessionId) { this._sessionId = _sessionId; }
	CookieData.prototype.setFirstUrl = function(_firstUrl) { this._firstUrl = _firstUrl; }
	CookieData.prototype.setHttpReferrer = function(_httpReferrer) { this._httpReferrer = _httpReferrer; }
	// HANDLE OLD VARIABLES PRIOR TO CBS LAUNCH 12/12/03
	CookieData.prototype.setT = function(_t) { this._t = _t; }
	CookieData.prototype.setS = function(_s) { this._s = _s; }


	// script / cookie action logic
	// NOTE: if any new url params are added, please be sure to adjust CookieData and it's prototypes accordingly!
	// t and s are old variables. Once the new CBS app is running, these should be removed from here and CookieData()
	var cookieParams = new Array();
	cookieParams = [
		"ut", "bid", "rc", "srcId", "ivrSrc", 
		"sa", "firstUrl", "httpReferrer",
		"t", "s"
	]


	// set any new cookie values here
	// must be done prior to GetCookies
	var cookieDomain = CookieDomain();
	var cookieData = new CookieData();
	var urlParams = new Array();
	urlParams = parseQueryString();	// get all the params from the URL

	// assign values if values were passed in the URL
	for(i=0; i<cookieParams.length; i++) {
		eval("var " + cookieParams[i] + " = null;");
		if(	cookieParams[i] != "firstUrl" || 
			cookieParams[i] != "httpReferrer" ||
			cookieParams[i] != "srcId") { // these are handled differently
			eval("if(urlParams['" + cookieParams[i] + "']) { SetCookie('" + cookieParams[i] + "', urlParams['" + cookieParams[i] + "']); }");
		}
	}


	// special cases or multiple key/value mappings to existing cookie variables
	var srcIdCleaned = "";
	var srcIdRegExp = new RegExp("^.+-(.*-.*)$", ""); // strip WSS code from SrcID
	if(urlParams['SrcId']) { srcIdCleaned = urlParams['SrcID'].replace(srcIdRegExp, "$1"); }
	if(urlParams['SrcID']) { srcIdCleaned = urlParams['SrcID'].replace(srcIdRegExp, "$1"); }
	if(srcIdCleaned  && !GetCookie('srcId')) { SetCookie('srcId', srcIdCleaned, cookieExpDays(30)); }

	if(urlParams['IVR_SRC']) { SetCookie('ivrSrc', urlParams['IVR_SRC']); }
	if(urlParams['ap']) { SetCookie('ivrSrc', urlParams['ap']); }
	if(GetCookie('session_id')) { cookieData.setSessionId(GetCookie('session_id')); }

	if(!GetCookie('firstUrl')) {
		var stripHttpRegExp = /https?:\/\/(.*)/;
		var url = window.location.toString();
		url = url.replace(stripHttpRegExp, "$1");

		SetCookie('firstUrl', url);
		cookieData.setFirstUrl(GetCookie('firstUrl'));
	}

	if(!GetCookie('httpReferrer') && document.referrer != "") {
		var stripHttpRegExp = /https?:\/\/(.*)/;
		var url = document.referrer.toString();
		url = url.replace(stripHttpRegExp, "$1");

		SetCookie('httpReferrer', url);
		cookieData.setHttpReferrer(GetCookie('httpReferrer'));
	}


	// get cookie variables based on cookieParams array
	for(i=0; i<cookieParams.length; i++) {
		var tempKey = cookieParams[i];
		var tempVal = GetCookie(tempKey);
		// alert("Key: " + tempKey + "\nValue: " + tempVal);  // DEBUG

		// first char needs to be capital
		if(tempKey.length > 1) {
			tempKey = tempKey.substring(0,1).toUpperCase() + tempKey.substring(1, tempKey.length);
		} else {
			tempKey = tempKey.toUpperCase();
		}

		// set cookie values into cookieData object
		eval("if(tempVal) { cookieData.set" + tempKey + "(tempVal); }");
		
		// eval("if(GetCookie('" + cookieParams[i] + "')) { " + cookieParams[i] + " = GetCookie('" + cookieParams[i] + "'); }");
	}


} else {


	// code required for old IMS system
	// *************** COOKIE SUPPORT  *************** 
	function Cookie(document, name, hours, path, domain, secure)
	{
	    this.$document = document;
	    this.$name = name;
	    if (hours)
	        this.$expiration = new Date((new Date()).getTime() + hours*3600000*30);
	    else this.$expiration = null;
	    if (path) this.$path = path; else this.$path = null;
	    if (domain) this.$domain = domain; else this.$domain = null;
	    if (secure) this.$secure = true; else this.$secure = false;
	}
	
	function _Cookie_store()
	{
	    var cookieval = "";
	    for(var prop in this) {
	        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
	            continue;
	        if (cookieval != "") cookieval += '&';
	        cookieval += prop + ':' + escape(this[prop]);
	    }
	    var cookie = this.$name + '=' + cookieval;
	    if (this.$expiration)
	        cookie += '; expires=' + this.$expiration.toGMTString();
	    if (this.$path) cookie += '; path=' + this.$path;
	    if (this.$domain) cookie += '; domain=' + this.$domain;
	    if (this.$secure) cookie += '; secure';
	    this.$document.cookie = cookie;
	}
	
	function _Cookie_load()
	{
	    var allcookies = this.$document.cookie;
	    if (allcookies == "") return false;
	    var start = allcookies.indexOf(this.$name + '=');
	    if (start == -1) return false; 
	    start += this.$name.length + 1;
	    var end = allcookies.indexOf(';', start);
	    if (end == -1) end = allcookies.length;
	    var cookieval = allcookies.substring(start, end);
	    var a = cookieval.split('&');
	    for(var i=0; i < a.length; i++)
	        a[i] = a[i].split(':');
	    for(var i = 0; i < a.length; i++) {
	        this[a[i][0]] = unescape(a[i][1]);
	    }
	    return true;
	}
	
	function _Cookie_remove()
	{
	    var cookie;
	    cookie = this.$name + '=';
	    if (this.$path) cookie += '; path=' + this.$path;
	    if (this.$domain) cookie += '; domain=' + this.$domain;
	    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	    this.$document.cookie = cookie;
	}
	
	new Cookie();
	Cookie.prototype.store = _Cookie_store;
	Cookie.prototype.load = _Cookie_load;
	Cookie.prototype.remove = _Cookie_remove;
	var COOKIE_NAME = "o_q";
	var EXPIRY_TIME = 24;
	var COOKIE_PATH = "/";
	var COOKIE_DOMAIN = ".covad.com";
	var FIRSTURLDEFAULT = "http://www.covad.com";
	var SHORTSOURCEIDREGEXP = /SrcID=([^&]*)&?/;
	var NEWSOURCE = /SRCID=([^&]*)&?/;
	var LASTSOURCE = /srcid=([^&]*)&?/;
	var SOURCEIDREGEXP = /sourceid=([^&]*)&?/;
	var covadVisitorData = new Cookie(document, COOKIE_NAME, EXPIRY_TIME, COOKIE_PATH, COOKIE_DOMAIN);
	covadVisitorData.load();
	if (covadVisitorData.firsturl == null)
	{
	    covadVisitorData.firsturl = location.href;
	}
	
	if (covadVisitorData.firsturl != null)
	{
		covadVisitorData.urlcache = location.href;
		var urlresultshort = document.URL.match(SHORTSOURCEIDREGEXP);
		var urlresult = document.URL.match(SOURCEIDREGEXP);
		var urlresultnew = document.URL.match(NEWSOURCE);
		var urlresultlast = document.URL.match(LASTSOURCE);
		if ((urlresult != null) && (urlresult[1] != null))
		{
			covadVisitorData.sourceid = urlresult[1];
			covadVisitorData.firsturl = covadVisitorData.urlcache;
		}
		else if ((urlresultshort != null) && (urlresultshort[1] != null))
		{
			covadVisitorData.sourceid = urlresultshort[1];
			covadVisitorData.firsturl = covadVisitorData.urlcache;
		}
		else if ((urlresultnew != null) && (urlresultnew[1] != null))
		{
			covadVisitorData.sourceid = urlresultnew[1];
			covadVisitorData.firsturl = covadVisitorData.urlcache;
		}
		else if ((urlresultlast != null) && (urlresultlast[1] != null))
		{
			covadVisitorData.sourceid = urlresultlast[1];
			covadVisitorData.firsturl = covadVisitorData.urlcache;
		}
	    covadVisitorData.SrcID = covadVisitorData.sourceid;
	}
	
	
	if (covadVisitorData.referrer == null)
	{
	    covadVisitorData.referrer = document.referrer;
	}
	
	if (covadVisitorData.sourceid == null)
	{
		var resultShort = document.URL.match(SHORTSOURCEIDREGEXP);
	    var result = document.URL.match(SOURCEIDREGEXP);
		var resultnew = document.URL.match(NEWSOURCE);
		var resultlast = document.URL.match(LASTSOURCE);
	    if ((result != null) && (result[1] != null))
		{
	       covadVisitorData.sourceid = result[1];
	    }
	    else if ((resultShort != null) && (resultShort[1] != null))
		{
	       covadVisitorData.sourceid = resultShort[1];
	    }
		else if ((resultnew != null) && (resultnew[1] != null))
		{
			covadVisitorData.sourceid = resultnew[1];
		}
		else if ((resultlast != null) && (resultlast[1] != null))
		{
			covadVisitorData.sourceid = resultlast[1];
		}
	    else
		{
	        covadVisitorData.sourceid = 0;
	    }
	    covadVisitorData.SrcID = covadVisitorData.sourceid;
	} 
	
	covadVisitorData.store();
	
	// *************** WIDEN THE DOMAIN OF THE SESSION COOKIE *********//
	function getApacheSessionIdCookie() {
		var sessionId = new Cookie(document, "session_id", null, "/", "");
		sessionId.load();
		return sessionId;
	}
	function isCookieContent(aCookie, aField) {
		return (aField.charAt(0) != '$' && 
			(aCookie[each].constructor != Function))
	}
	function widenSessionIdDomain() {
		var sessionId = getApacheSessionIdCookie(); 
		var hasContent = false;
		for (each in sessionId) {
			if (isCookieContent(sessionId, each))
				hasContent = true;
		};
		if (hasContent) {
			sessionId.$domain = ".covad.com";
			for (each in sessionId) {
				if (isCookieContent(sessionId, each))
					sessionId[each] = "";
			};
		getApacheSessionIdCookie().remove();
		sessionId.store();
		}
	}
	
	widenSessionIdDomain();
}

// ** Browser **

// PLATFORM
var isMac = (navigator.appVersion.indexOf("Mac") != -1);
var isWin = (navigator.appVersion.indexOf("Win") != -1);
// BROWSER
var isAbsIE4 = (navigator.appVersion.indexOf("MSIE 4.0") != -1);
var isIE4 = (navigator.appVersion.indexOf("MSIE 4") != -1);
var isIE5 = (navigator.appVersion.indexOf("MSIE 5") != -1);
var isIE6 = (navigator.appVersion.indexOf("MSIE 6") != -1);
var isNN6 = ((window.navigator.appName.indexOf("Netscape") != -1) && (navigator.appVersion.indexOf("5.") != -1));
var isNN4 = ((window.navigator.appName.indexOf("Netscape") != -1) && (navigator.appVersion.indexOf("4.") != -1));
var isNN = (window.navigator.appName.indexOf("Netscape") != -1);

// =============== END SOC.GR SCRIPT =============== //

