if (location.href.indexOf("/partner/")>-1) location.href=location.href.replace("/partner/","/");
var here=location.href;
if (here.indexOf("\/broadband\/")>=0) {
	var there=here.replace("broadband","internet");
	location.replace(there);
}
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; }
}

// *************** 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}/;
var domainStr = location.hostname;
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="+domainStr+";path=/;";
	document.cookie = cookieData;
}
function GetCookie(name){
	return getCookie(name);
}
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="+domainStr+";expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
// ***** /Global Tracking ***** //

// ********** 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 ********** //
var bc=document.cookie;
var beenThere = bc.indexOf("firstUrl");
if (beenThere == -1) {
	var url = window.location.toString();
	url = url.replace(stripHttpRegExp, "$1");
	setCookie("firstUrl",url ,"8");
}
// ********** /FIRST URL COOKIE ********** //

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

// ********** SOURCE ID & IVR SRC COOKIE SNIFFER ********** //
// get the srcid qs value and validate it, then set the cookie
var strSrcId = getQSItem('srcid');
if(strSrcId && validateSrcIDVal(strSrcId)){
	//alert('set srcid cookie: ' + strSrcId);
	setCookie("srcid", strSrcId, "8");
	setCookie("srcidStore", strSrcId, "8");
}
function validateSrcIDVal(strSrcId){
	if(strSrcId.match(srcIdPattern)){
		return strSrcId;
	}
	return false;
}
// get the ivrSrc qs value and set the cookie
// note that we could have an ap= key instead, so if we do, put that into the ivrSrc cookie
var strSA = getQSItem('sa');
var strAP = getQSItem('ap');
var strIvrSrc = getQSItem('ivr_src');
if (strSA) {
	setCookie("subAgent", strSA, "8");
}
if(strAP){
	strIvrSrc = strAP;
}
if(strIvrSrc){
	setCookie("ivrSrc", strIvrSrc, "8");
	setCookie("ivrSrcStore", strIvrSrc, "8");
}
// ********** /SOURCE ID COOKIE SNIFFER ********** //

// ********** 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 IVR_SRC = getCookie("ivrSrc");
var IVR_SRCStore = getCookie("ivrSrcStore");
var HostingNum = getCookie("hosting_plan");
var HostingName = getCookie("hosting_planName");
var sa = getCookie("subAgent");
// ********** Cookie value checkers ********** //
// if the value of cookie is invalid, expired, null, blank, fubar'd, we need
// to make sure the value isn't "null" and that it is "" instead.

// SRCID
	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");
			}
		}
	}
// IVR_SRC
	if(IVR_SRC == "null" || !IVR_SRC || IVR_SRC == null){
		// now check to see if we have the SrcIDStore available, if so use that
		if(IVR_SRCStore == "null" || !IVR_SRCStore || IVR_SRCStore == null){
			// nevermind, just go with an empty string
			IVR_SRC = "";
		} else {
			// cool we'll just use the var we stored which somehow got overwritten earlier!
			if(IVR_SRCStore == "null" || !IVR_SRCStore || IVR_SRC == null){
				SrcID = "";	// give up, srcid lost or not present
			} else {
				IVR_SRC = IVR_SRCStore;
				setCookie("ivrSrc", IVR_SRCStore, "8");
			}
		}
	}
// SubAgent
	if (sa == "null" || !sa || sa == null) {
		// now check to see if we have the SrcIDStore available, if so use that
		if (saStore == "null" || !saStore || saStore == null) {
			// nevermind, just go with an empty string
			sa = "";
		} else {
			// cool we'll just use the var we stored which somehow got overwritten earlier!
			if(saStore == "null" || !saStore || sa == null){
				saD = "";	// give up, srcid lost or not present
			} else {
				sa = saStore;
				setCookie("sub_agent", saStore, "8");
			}
		}
	}
// ********** /COOKIE VALUES For GLOBAL USE ********** //

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

// ********** QUERYSTRING PARSING OBJ/FUNCTIONS ********** //
function PageQuery(q) {
	if(q.length > 1){
		this.q = q.substring(1, q.length);
	}else{
		this.q = null;
	}

	this.keyValuePairs = new Array();

	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}

	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0].toLowerCase() == s) {
				return this.keyValuePairs[j].split("=")[1];
			}
		}

		return false;
	}

	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0].toLowerCase();
		}

		return a;
	}

	this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
function getQSItem(key){
	key = key.toLowerCase();
	
	if(queryString(key)=='false') {
		return false;
	}else{
		return queryString(key);
	}
}
// ********** 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();
	}
}