/*
	JavaScript used by the backendPages theme
	$Id: backendPages.js,v 2.01 2006/06/23 16:51:05 brpavioni Exp $
*/

var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var DEBUG_ALERTS_ON = false;

/* Catch any error messages passed back from 
dslhelp.windstream.net or www.windstream.net/dslhelp. 
These error messages will be displayed to the customer. */
var errorList = {
	"1.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while clearing the browser's history."
	},
	"2.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while setting browser's home page."
	},
	"3.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An internal error occurred. Please try again later."
	},
	"4.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An attempt to send your information to an Internet Service Representative has failed."
	},
	"5.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An attempt to initiate a remote control session has failed."
	},
	"6.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while setting the browser's history life."
	},
	"7.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while setting Windows Auto Update Settings."
	},
	"8.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while performing a traceroute."
	},
	"9.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while emptying your recycle bin."
	},
	"10.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred while setting your router's firewall level."
	},
	"11.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred during the installation of the necessary ActiveX components.<br />Please ensure you have ActiveX enabled and you agree to install the controls. ActiveX can be enabled in your browser's Internet options."
	},
	"12.00.00.00" : {
		'errorComponent' : "LWP",
		'text'					 : "An error occurred during the installation of the necessary ActiveX components.<br />Please ensure you have ActiveX enabled and you agree to install the controls. ActiveX can be enabled in your browser's Internet options."
	},


	//chorusEnablement (install DSL check up center) errors
	"1.00.00.01" : {
		'errorComponent' : "chorusEnablement",
		'text'					 : "An error occurred while installing Microsoft Java Virtual Machine."
	},
	"2.00.00.01" : {
		'errorComponent' : "chorusEnablement",
		'text'					 : "An error occurred while installing the Windstream Broadband Check-up Center."
	},
	"3.00.00.01" : {
		'errorComponent' : "chorusEnablement",
		'text'					 : "An error occurred while launching the Windstream Broadband Check-up Center."
	},
	"4.00.00.01" : {
		'errorComponent' : "chorusEnablement",
		'text'					 : "An error occurred while registering the Windstream Broadband Check-up Center."
	},


	//getOptimalSettings errors
	"1.00.00.02" : {
		'errorComponent' : "getOptimalSettings",
		'text'					 : "An error occurred while creating an optimal settings record."
	},
	"2.00.00.02" : {
		'errorComponent' : "getOptimalSettings",
		'text'					 : "An error occurred while gathering an optimal settings record."
	},


	//deleteTemp Files errors
	"1.00.00.03" : {
		'errorComponent' : "DeleteTemporaryFiles",
		'text'					 : "An error occurred while deleting temporary Internet files."
	},
	"2.00.00.03" : {
		'errorComponent' : "DeleteTemporaryFiles",
		'text'					 : "An error occurred while deleting temporary system files."
	},
	"3.00.00.03" : {
		'errorComponent' : "DeleteTemporaryFiles",
		'text'					 : "An error occurred while deleting temporary user files."
	}
};




function do_Onload() {
	// Create Internet Explorer Boolean Variable Checks
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie7    = (is_ie && (agt.indexOf("msie 7.")!=-1));
	var supportedBrowser = is_ie && !is_ie3 && !is_ie4 && !is_ie5;



	// *** OS PLATFORM ***
	var is_win   = ((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1));
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	//        Win32, so you can't distinguish between Win95 and WinNT.
	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	var is_win16 = ((agt.indexOf("win16")!=-1) ||
						 (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
						 (agt.indexOf("windows 16-bit")!=-1) );

	var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
									(agt.indexOf("windows 16-bit")!=-1));

	var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
	var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));
	var is_winxp = ((agt.indexOf("windows nt 5.1")!=-1));

	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	var is_win32 = (is_win95 || is_winnt || is_win98 ||
									((is_major >= 4) && (navigator.platform == "Win32")) ||
									(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
	var supportedOS = is_win98 || is_win2k || is_winme || is_winxp;
	/* END OS PLATFORM */



	var hide_DCUC_links = function() {
		var tags = document.getElementsByTagName('span');
		for(var i in tags) {
			if(tags[i].className == 'spc_DCUC')	tags[i].style.display = 'none';
		}

		var alertWording = new String("To install the Broadband Check Up Center, please use the Microsoft Internet Explorer web browser.").replace(/('|")/g, "\\$1");

		document.getElementById('a_dcuc_link').href = "javascript: void(alert('" + alertWording + "'))";
		document.getElementById('img_dcuc_link').href = "javascript: void(alert('" + alertWording + "'))";
	};

	//it's not IE5.5 or higher and/or windows 98,2k,xp,me
	if(!(supportedBrowser && supportedOS)) {
		hide_DCUC_links();
		document.getElementById('error_table').style.display = '';
		document.getElementById('error_img').src = '/dslhelp/img/warning.gif';
		document.getElementById('error_text').innerHTML = 'This site is best viewed with Internet Explorer 5.5 or higher.';

	// If we have IE 7
	//} //else if(is_ie7) {
		//hide_DCUC_links();
		//document.getElementById('error_table').style.display = '';
		//document.getElementById('error_img').src = '/dslhelp/img/warning.gif';
		//document.getElementById('error_text').innerHTML = 'The Broadband Check Up Center is not yet available for use with Internet Explorer 7.';

	// Otherwise, check for errors
	} else {
		var urlString = parent.location.search;
		var cancelled = urlString.indexOf("cancel=true") != -1;

		var errorText = null;
		var foundEror = urlString.indexOf("errorCode=");
		if(foundEror != -1) {
			var error_spt = urlString.substring(foundEror + 10, urlString.length);
			if(error_spt != "2.00.00.03" && error_spt != "3.00.00.03") {
				if(errorList[error_spt]) {
					errorText = errorList[error_spt].text;
				} // if
			} // if

			if(error_spt != "") {
				var pingme = jsError();
				document.getElementById('error_table').style.display = '';
				document.getElementById('error_img').src = '/dslhelp/img/error.gif';
				if(pingme != '') {
					document.getElementById('error_text').innerHTML = pingme;
				} else {
					document.getElementById('error_text').innerHTML = errorText;
				} // if
			} // if
		} // if
	} // if
}











/* Build the Elements for the speed test chart */
sChart = new Object()
sChart.title = "Broadband Downstream Bandwidth Test";
sChart.titles = new Array("Broadband Lite","Broadband Tier 1","Broadband Ultra","Extreme","Yours");
sChart.field1 = new Array(256,1500,3000,6000);
sChart.field2 = new Array("128","384","384","384");
sChart.fields = new Array("yellow.gif","blue.gif","green.gif","red.gif");

/* Build the Elements for the images to display */

currChart = new Object()
currChart.coloVal = "red.gif";
currChart.direction = "horizontal";
currChart.info = sChart






/* Start Cookie Error Check
Added 04/12/2005 Brett Pavioni */
function getCookie(name) {
	var cname = name + "=";
	var dc = document.cookie;

	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1)  {
				end = dc.length;
			} // end if
			return dc.substring(begin, end);
		} // end if
	} // end if
	return null;
}

function jsError() {
	var today = new Date();
	var dateToExpire = today.getTime() + 1800000;
	var myCookie = getCookie('errorCookie');
	if(myCookie == null) {
		var twoPart = new Array(dateToExpire, 0);
	} else {
		var twoPart = new String(myCookie).split("-");
		twoPart[1] = parseInt(twoPart[1]);
	} // end if
	if(twoPart[1] >= 2) {
		if(parseInt(twoPart[0]) < today.getTime()) {
			today.setTime((today.getTime()-6000000));
			document.cookie = "errorCookie=deleteMe-0;expires="+today.toGMTString();
		} else {
			 return "We apologize for the inconvenience, however, the server may be busy at this time. Please try again later.";
		} // end if
	} else {
		today.setTime(dateToExpire);
		twoPart[1] = new String((parseInt(twoPart[1]) + 1));
		document.cookie = "errorCookie="+dateToExpire+"-"+twoPart[1]+";expires="+today.toGMTString();
	} // if
	return "";
} // if
/* End Cookie Error Check */





/* Utility functions for DSL Checkup Center start */

/* Install Check-up Center Navigation */
/* Added 04/12/2005 Nick Trower */
function Nav_HandleOnClick(arg){
	if (arg == 'cancel') {
		document.location.href = 'http://dslhelp.windstream.net';
	}
	if (arg == 'next') {
		updateURL("chorusEnablement");
	}
}

function displayImage(img){
	document.getElementById('viewImage').style.visibility = "visible";
	if(img == 'ethernet'){
		document.getElementById('viewImage').innerHTML = "<img src='/dslhelp/flow/install/img/5100_eth.jpg' alt='Ethernet Configuration Setup'>";
	} else{
		document.getElementById('viewImage').innerHTML = "<img src='/dslhelp/flow/install/img/5100_usb.jpg' alt='USB Configuration Setup'>";
	}
}

function showRouter(){
	document.getElementById('routerPics').innerHTML = "<img src='/dslhelp/flow/install/img/ar7.gif' alt='AR7 Router'>&nbsp;<img src='/dslhelp/flow/install/img/ar5.gif' alt='AR5 Router'>";
}

function updateURL(action) {
	window.location.href = "/alltel/portal/customersupport/?hrefURL=/dslhelp/iframenoscroll.html&action="+ action;
}

function DbgAlert(strString) {
	if(DEBUG_ALERTS_ON)
		alert("checking ret values::" + strString);
}

function QueryString(a) { 
 var url = (new String(document.location.href).split("?"))[1]; 
 if(url) { 
  var e = url.split("&"); 
  for(var i = 0; i <= e.length; i++) { 
   if(e[i]) { 
    var g = e[i].split("="); 
    if(g[0] == a) { 
     return unescape(g[1]); 
    } // end if 
   } // end if 
  } // end for 
 } // end if 
 return null; 
} 
var error = QueryString('error');

/* Utility functions for DSL Checkup Center end */