var pageURL=location.href;
if (pageURL.indexOf("gc=y")>=0) {
docURI=pageURL.split(".com")[1];
location.replace("http://www.getcovad.com" + docURI);
}
var here=location.href;
if (here.indexOf("\/voip\/")>=0) {
	var there=here.replace("voip","phone_internet");
	location.replace(there);
} else if (here.indexOf("\/broadband\/")>=0) {
	var there=here.replace("broadband","internet");
	location.replace(there);
}
// *************** 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 *************** //

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 ********** //

// ********** Select Hosting COOKIE ********** //
// Host Cookie set on Host/BB Pod Pg
// setCookie("hosting_plan",planNum,"8");
function addHost2Order(planNum,planName) {
	if (HostingName!="") {
		var addIt = confirm ("Replace " + HostingName + " with " + planName + "?");
	} else {
		var addIt = confirm ("Add " + planName + " to your Broadband order?");
	}
		if (addIt) {
		setCookie("hosting_plan",planNum,"8");
		setCookie("hosting_planName",planName,"8");
		alert (planName + " will be added to your Broadband order.")
		location.reload();
	} else {
		alert (planName + " will not be added to your Broadband order.")
	}
}
function clearHost () {
var deleteIt =  confirm ("Remove " + HostingName + " from your Broadband order?");
if (deleteIt) {
	deleteCookie ("hosting_plan");
	deleteCookie ("hosting_planName");
	location.reload();
	}
}
// ********** /Select Hosting 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");
var HostingNum = getCookie("hosting_plan");
var HostingName = getCookie("hosting_planName");

// 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 ********** //
// *************************************** //
