// JavaScript Document

/*
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];}
}

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; }
}

function rightSize(w, h) {
	if(!isNaN(w) && !isNaN(h)){
		self.resizeTo(w,h);
		self.moveTo(80,80);
		
		window.focus();
	}
}
*/
// *************** CB's Remote Window Controller *************** //
function remoteWindow(theLink, bringForward){
	// bringForward = flag to focus opener window
	// theLink = new href for opener window
	
	if(window.opener){
		// if we have an opener window...
		window.opener.location.href = theLink;
		if(bringForward){
			window.opener.focus();
		}
	}else{
		window.location.href = theLink;
	}
}
function popRemoteWinNoFeatures(theLink, theName){
window.open(theLink,theName,"alwaysRaised=1,dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1 resizable=1");
}
// *************** /CB's Remote Window Controller *************** //

/*
// *************** 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) {
	newWin=window.open(fileName,windowName,"alwaysLowered=1,z-lock,dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,screenX=20,screenY=20,width="+theWidth+",height="+theHeight);
	newWin.blur();
}

function glossary(entry) {
	 var theFileName = "/support/glossary/definition.shtml?"+ 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;
}

// ************************************** //
// ********** Tracking Cookies ********** //

// ***** Global Tracking ***** //

var stripHttpRegExp = /https?:\/\/(.*)/;
var srcIdPattern = /\d{3}-\d{10}/;

function setCookie(cookieName, cookieValue, numOfWeeks) {
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (numOfWeeks * 604800000));	//# milliseconds in a week
	var cookieData = cookieName+"="+escape(cookieValue)+";expires="+expDate.toGMTString()+";domain=covad.com;path=/;";
	document.cookie = cookieData;
}

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 "";
			//changed to "" from null
	  	} else {
	    	begin += 2;
		}
		
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	  
	var info = unescape(dc.substring(begin + prefix.length, end));
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name) {
	if (getCookie(name)) {
		document.cookie = name + "=;path=/;domain=covad.com;expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
// ***** /Global Tracking ***** //

// ********** SOURCE ID COOKIE SNIFFER ********** //
// re-written 7/12/04 CB

function getSrcId() {
	// helper function to retrieve srcid value from querystring
	
	var strTheQs, intSrcIdPos, intSrcIdEndPos, strThisSrcId;
	strTheQs = location.search.toLowerCase();		// get the querystring from the URL
	
	// if we have a querystring to deal with then...
	if (strTheQs){
		intSrcIdPos = strTheQs.indexOf('srcid=');		// find the last char position of srcid=
		
		if (intSrcIdPos != -1){
			// ladies and gents we have a srcid key, see if there's a worthwhile value...
			// but first, add 6 to the starting position (to exclude the srcid= string)
			intSrcIdPos += 6;
			intSrcIdEndPos = intSrcIdPos + 14;									// compute the last position of the srcid
			strThisSrcId = strTheQs.substring(intSrcIdPos, intSrcIdEndPos);		// extract the srcid string
			
			// if the strSrcId var is a viable srcid, it will be returned
			if (strThisSrcId.match(srcIdPattern)){
				return strThisSrcId;
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}

// now if we have a srcid cookie already set, and a new srcid in the querystring, overwrite the
// first srcid cookie.  if we do not have a cookie set already, just write the cookie.
var strSrcId = getSrcId();

// if the srcid in the QS is valid, set the cookie regardless if this is the first or Nth srcid
// (i.e. any previous srcid cookies will be overwritten)
if (strSrcId){
	// ok we have a valid srcid!  Set the cookie and let the user be on their way
	setCookie("srcid", strSrcId, "8");
	setCookie("srcidStore", strSrcId, "8");
	
	/*** DEBUGGING STEPS BELOW, NOT FOR PRODUCTION ENVIRON ***
	//alert("valid src found! cookie set.\n\nsrcid: " + strSrcId);
		
	// validate the cookie was set
	if(!getCookie("srcid")){
		//alert("hmm, cookie wasn't set!! wth is going on here??\n\nsrcid: " + strSrcId);
	}else{
		//alert("cookie validated, all is well!\n\nsrcid: " + strSrcId);
	}
} else {
	//alert("invalid src id value, cookie not set!\n\nsrcid: " + strSrcId);
*** END DEBUGGING STEPS ***/
}

// ********** /SOURCE ID COOKIE SNIFFER ********** //

// ********** SESSION ID (MPUID) COOKIE SNIFFER ********** //
var bc=document.cookie;
var beenThere = bc.indexOf("mpuid");
if (beenThere == -1) {
	var bc=document.cookie;
	var prefix = "session_id";
	var begin = bc.indexOf(prefix);
	
	if (begin == -1) {
		begin = bc.indexOf(prefix);
	
		if (begin != 0) {};
	} else {
		begin += 2;
	}
	
	var end = bc.indexOf(";", begin);
	if (end == -1)
		end = bc.length;
	
	var ssidval = unescape(bc.substring(begin + prefix.length, end));
	setCookie("mpuid",ssidval ,".003");
}
// ********** /SESSION ID (MPUID) COOKIE SNIFFER ********** //

// ********** FIRST URL COOKIE ********** //
// *** EDITED 030106 AB MAX 100 CHAR!!!
var bc=document.cookie;
var beenThere = bc.indexOf("firstUrl");
if (beenThere == -1) {
	var url = window.location.toString();
	var urlLocation=url.split("?")[0];
	//if ((urlLocation=url.split("?")[0])!=-1) var qMark="?";
	var qString=url.indexOf("SrcID");
	var scrIDString=url.slice(qString,(qString+20));
	url = urlLocation + "?" + scrIDString;
	//url = url.slice(0,urlLength);
	//alert ("Cookie value is " + url);
	url = url.replace(stripHttpRegExp, "$1");
	setCookie("firstUrl",url ,"8");
}
// ********** /FIRST URL COOKIE ********** //

// ********** Referrer COOKIE ********** //
var bc=document.cookie;
var referringUrl = bc.indexOf("referrer");
if (referringUrl == -1) {
	var referredBy = document.referrer.toString();;
	referredBy = referredBy.replace(stripHttpRegExp, "$1");
	setCookie("referrer",referredBy,"8");
}
// ********** /Referrer COOKIE ********** //

// ********** KeyWord COOKIE ********** //
if (location.href.indexOf("kw")!=-1) {
var keyWordVal=location.href.split("kw=")[1].split("&")[0].replace(/%20/g," ");
setCookie("keyword",keyWordVal,"8");
}
// ********** /KeyWord COOKIE ********** //

// ********** COOKIE VALUES For GLOBAL USE ********** //
var MPUID = getCookie("mpuid");
var FirstURL = getCookie("firstUrl");
var SrcID = getCookie("srcid");
var SrcIDStore = getCookie("srcidStore");
var SessionID = getCookie("session_id");
var ReferringURL = getCookie("referrer");
var KeyWord = getCookie("keyword");

// if the srcid cookie is invalid, expired, null, blank, fubar'd, we need
// to make sure the value isn't "null" and that it is "" instead.
if(SrcID == "null" || !SrcID || SrcID == null){
	// now check to see if we have the SrcIDStore available, if so use that
	if(SrcIDStore == "null" || !SrcIDStore || SrcIDStore == null){
		// nevermind, just go with an empty string
		SrcID = "";
	} else {
		// cool we'll just use the var we stored which somehow got overwritten earlier!
		if(SrcIDStore == "null" || !SrcIDStore || SrcID == null){
			SrcID = "";	// give up, srcid lost or not present
		} else {
			SrcID = SrcIDStore;
			setCookie("srcid", SrcIDStore, "8");
		}
	}
}
// ********** /COOKIE VALUES For GLOBAL USE ********** //

// ********** /Tracking Cookies ********** //
// *************************************** //
