﻿function replace(string, text, by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0, txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0, i) + by;

	if (i + txtLength < strLength)
		newstr += replace(string.substring(i + txtLength, strLength), text, by);

	return newstr;
}

function lzCheck(string, end) {
	var _string = "";
	if (end == -2) {
		_string = "0" + string;
	}
	else if (end == -3) {
		_string = "00" + string;
	}

	return _string.slice(end);
}

function hasPermissionToPathname() {
	try {
		var path = window.location.pathname;
		return true;
	}
	catch (pathaccessexception) {
		//this fails when security level is set to high and so will block access to pathname
		return false;
	}
}

function isInPage(pageNameStartsWith) {
	try {
		// search for com/ in front of name because sometimes the url will contain the pagename fragment
		//  like when clicking the login link the return page will be referenced in the url
		var path = window.location.pathname;

		var pageName = path.substring(path.lastIndexOf('/') + 1);

		return (pageName.toString().toLowerCase().indexOf(pageNameStartsWith.toLowerCase(), 0) != -1);
	} catch (likelyaccessdenied) {
		//this fails when security level is set to high and so will block access to pathname
		return false;
	}
}

function isInPageExact(Path) {
	try {
		var CurrentPath = window.location.href.toString();

		return (CurrentPath.toString().toLowerCase() === Path.toString().toLowerCase());
	} catch (likelyaccessdenied) {
		//this fails when security level is set to high and so will block access to pathname
		return false;
	}
}


function isInURL(TMP_URL_PART) {
	try {
		// search for com/ in front of name because sometimes the url will contain the pagename fragment
		//  like when clicking the login link the return page will be referenced in the url
		var path = window.location.href;


		return (path.toString().toLowerCase().indexOf(TMP_URL_PART.toLowerCase(), 0) != -1);
	} catch (likelyaccessdenied) {
		//this fails when security level is set to high and so will block access to pathname
		return false;
	}
}

function jumpToPageTop(e) {
	UAGENT = navigator.userAgent.toUpperCase();
	if (UAGENT.indexOf("MSIE") >= 0) {
		pos = event.y;
	} else {
		pos = e.pageY;
	}
	pageScroll(pos);
}

function pageScroll(posi) {
	dist = posi / 6;
	nPos = parseInt(posi - dist);
	scrollTo(0, nPos);
	if (nPos > 0) {
		setTimeout("pageScroll(nPos)", 10);
	}
}

function openNewWin(url) {
	var x = window.open(url, 'surveywindow', 'status=0, toolbar=0, scrollbars=1, menubar=0, resizeable=0, width=800,height=550;');

	//x.focus();
}

function reloadparent() {
	try {
		if (window.opener && !window.opener.closed) {
			window.opener.location.reload();
		}
	}
	catch (Error) { }
}

function getText(ref_obj) {
	if (ref_obj !== null) {
		try {
			if (!isIE) { return ref_obj.textContent; }
			else { return ref_obj.innerText; }
		}
		catch (errormsg) {
			eReport(errormsg, "unexpected error when trying to get text property");
			return "";
		}
	}
	else {
		eReport(null, "cannot get text from null object");
		return "";
	}
}

function setVisible(elementID, on) {
	try {
		var element;
		if (document.getElementById) {
			element = document.getElementById(elementID);
		}
		else if (document.all) {
			element = document.all[elementID];
		}
		if (element) {
			if (on) {
				element.style.visibility = "visible";
				element.style.display = "block";
			}
			else {
				element.style.visibility = "hidden";
				element.style.display = "none";			
			}
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "setVisible: error ");
	}
}

function setInnerHTML(elementID, text) {
	try {
		var element;
		if (document.getElementById) {
			element = document.getElementById(elementID);
		}
		else if (document.all) {
			element = document.all[elementID];
		}
		if (element) {
			if (typeof element.textContent != 'undefined') {
				element.textContent = text;
			}
			else if (typeof element.innerHTML != 'undefined') {
				element.innerHTML = text;
			}
			else if (typeof element.removeChild != 'undefined') {
				while (element.hasChildNodes()) {
					element.removeChild(element.lastChild);
				}
				glbLn = 100115;
				element.appendChild(document.createTextNode(text));
			}
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "setInnerText: error ");
	}
}
//sl 180 moveed setInnerHTML
function setInnerHTML(elementId, text, IsAppend) {
	try {
		var element;
		if (document.getElementById) {
			element = document.getElementById(elementId);
		}
		else if (document.all) {
			element = document.all[elementId];
		}
		if (element) {
			if (IsAppend) {
				element.innerHTML += text;
			}
			else {
				element.innerHTML = text;
			}
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "setInnerHTML: error ");
	}
}
function setInnerText(elementId, text) {
	try {
		glbLn = 10090;
		var element;
		if (document.getElementById) {
			glbLn = 10094;
			element = document.getElementById(elementId);
		}
		else if (document.all) {
			glbLn = 10098;
			element = document.all[elementId];
		}
		if (element) {
			if (typeof element.textContent != 'undefined') {
				glbLn = 100103;
				element.textContent = text;
			}
			else if (typeof element.innerText != 'undefined') {
				glbLn = 100107;
				element.innerText = text;
			}
			else if (typeof element.removeChild != 'undefined') {
				glbLn = 100111;
				while (element.hasChildNodes()) {
					element.removeChild(element.lastChild);
				}
				glbLn = 100115;
				element.appendChild(document.createTextNode(text));
			}
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "setInnerText: error ");
	}
}

function cookiesAreEnabled() {
	var RetValue = false;
	try {
		var TMP_Date = new Date();

		//TEST1: check the navigator cookieenabled property and try to create a cookie
		//    var TMP_COOKIE_TEST1 = (navigator.cookieEnabled) ? true : false;

		//    if (typeof navigator.cookieEnabled !== "undefined") {
		//      //create a unique cookie name since a constant name may conflict with past tests
		//      var TMP_TEST1_NAME = "randomname1" + TMP_Date.getTime().toString();
		//      document.cookie = TMP_TEST1_NAME;
		//      TMP_COOKIE_TEST1 = (document.cookie.indexOf(TMP_TEST1_NAME) != -1) ? true : false;
		//    }

		//TEST2: create a cookie with jquery and retrieve it
		var TMP_COOKIE_TEST2 = false;
		try {
			//create a unique cookie name since a constant name may conflict with past tests
			var TMP_TEST2_NAME = "randomname2" + TMP_Date.getTime().toString();

			//clear the test cookie value in case it was previously set
			$.cookie(TMP_TEST2_NAME, null);

			//create or reinitialize the cookie value
			$.cookie(TMP_TEST2_NAME, "TEST");


			if (typeof ($.cookie(TMP_TEST2_NAME)) !== 'undefined') {
				var TMP_COOKIE_VALUE = $.cookie(TMP_TEST2_NAME);
				TMP_COOKIE_TEST2 = (TMP_COOKIE_VALUE === "TEST");

				$.cookie(TMP_TEST2_NAME, null);

			}
			
		}
		catch (cookieaccessexception) {
		}

		RetValue = (TMP_COOKIE_TEST2);

	} catch (cookieexception) {

		RetValue = false;
	}
	return RetValue;
}

//get a cookie safely since sometimes $.cookie calls fail unexpectedly
function getCookie(CookieName) {
	if (glbCookies) {
		try {
			return $.cookie(CookieName);
		} catch (cookieexception) {
			try {
				glbCookies = false;
			} catch (loggingError) { }
		}
	}
	return "";
}

//set a cookie safely since sometimes $.cookie calls fail unexpectedly
function setCookie(CookieName, CookieValue) {
	if (glbCookies) {
		try {
			$.cookie(CookieName, CookieValue);
		} catch (cookieexception) {
			try {
				glbCookies = false;
			} catch (loggingError) { }
		}
	}
}
//set a cookie safely since sometimes $.cookie calls fail unexpectedly
function setCookieExpires(CookieName, CookieValue, Timeout) {
	if (glbCookies) {
		try {
			$.cookie(CookieName, CookieValue, { expires: Timeout });
		} catch (cookieexception) {
			try {
				glbCookies = false;
			} catch (loggingError) { }
		}
	}

}

//Browser Support Code
function ajaxIsSupported() {
	var TMP_AJAX_is_supported = false;

	var ajaxRequest;  // The variable that makes Ajax possible!

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		TMP_AJAX_is_supported = true;
	} catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			TMP_AJAX_is_supported = true;
		} catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				TMP_AJAX_is_supported = true;
			} catch (e) {
				// Something went wrong
			}
		}
	}
	return TMP_AJAX_is_supported;
}

function initialize() {
	$('ul#navigationmenu > li').hover(
		function () { $(this).addClass('hover'); },
		function () { $(this).removeClass('hover'); }
	);

	$('ul#navigationmenu > li > ul').hover(
		function () { $(this).parents('li').addClass('hover'); },
		function () { $(this).parents('li').removeClass('hover'); }
	);

	var ps = 1;
	try {
		ps = parseInt(getURLParam("ps"), 10);
	}
	catch (Error) {
	}
	if (ps < 0 || ps > 3) {
		ps = 1;
	}
	try {
		if (isUInt(ps)) {
			if (ps - 1 >= 0) {
				document.getElementsByName('rbState')[ps - 1].checked = true;
			}
		}
	}
	catch (Error) {
		document.getElementsByName('rbState')[0].checked = true;
	}
}

function getURLParam(strParamName) {
	var strHref = window.location.href;
	var strReturn = "";

	//try to isolate if the user's window properties are not accessible or undefined
	if (typeof (window) != 'undefined') {
		if (typeof (window.location) != 'undefined') {
			if (typeof (window.location.href) != 'undefined') {
				if (isNonEmptyString(window.location.href)) {
					strReturn = getURLParamForURL(strParamName, strHref);
				}
				else {
					eReport(ex, "getURLParam: error window.location.href is null or blank");
				}
			}
			else {
				eReport(ex, "getURLParam: error window is undefined");
			}
		}
		else {
			eReport(ex, "getURLParam: error window.location is undefined");
		}
	}
	else {
		eReport(ex, "getURLParam: error window.location.href is undefined");
	}
	return strReturn;
}

function clearDropDown(dropdown) {
	// Set select to the element "selectbox."   
	var select = document.getElementById(dropdown);
	var options = select.getElementsByTagName("option");
	// Loop through the array of options and remove eeach one from the parent's childNode list.   
	for (var i = options.length - 1; i >= 0; i--) {
		if (options[i].value != "Select Year" && options[i].value != "Select Make" && options[i].value != "Select Model")
		{ select.removeChild(options[i]); }
	}
}

function selectDropDown(dropdown, Value) {
	var select = document.getElementById(dropdown);
	var options = select.getElementsByTagName("option");

	for (var i = options.length - 1; i >= 0; i--) {
		if (options[i].value == Value)
		{ select.selectedIndex = i; }
	}
}

function selectDropDownByText(dropdown, text) {
	var select = document.getElementById(dropdown);
	var options = select.getElementsByTagName("option");

	for (var i = options.length - 1; i >= 0; i--) {
		if (options[i].text == text)
		{ select.selectedIndex = i; }
	}
}

String.prototype.startsWith = function (str) { return (this.match("^" + str) == str); }
String.prototype.endsWith = function (str) { return (this.match(str + "$") == str); }
String.prototype.trimall = function (str) {	return this.replace(/^\s*/, "").replace(/\s*$/, ""); }
String.prototype.capitalize = function () { return this.replace(/(^|\s)([a-z])/g, function (m, p1, p2) { return p1 + p2.toUpperCase(); }); };

function recurseToEnable(el, ToEnabled) {
	try {
		el.disabled = !ToEnabled;
	}
	catch (E) {
	}
	if (el.childNodes && el.childNodes.length > 0) {
		for (var x = 0; x < el.childNodes.length; x++) {
			recurseToEnable(el.childNodes[x], ToEnabled);
		}
	}
}

function checkTextAreaMaxLength(textBox, e, length) {
	var mLen = textBox["MaxLength"];
	if (null == mLen) mLen = length;
	var maxLength = parseInt(mLen);
	if (!checkSpecialKeys(e)) {
		if (textBox.value.length > maxLength - 1) {
			if (window.event)//IE
				e.returnValue = false;
			else//Firefox
				e.preventDefault();
		}
	}
}

function checkSpecialKeys(e) { if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40) return false; else return true; }

function getLoginLink() {
	var LoginLinkMessage = "login";
	try {
		if (typeof (location) != 'undefined') {
			if (isExistingObj(location)) {
				if (typeof (location.href) != 'undefined') {
					if (isExistingObj(location.href)) {
						LoginLinkMessage = "<a href='login.aspx?returnurl=" + escape(location.href) + "' >login</a>";
					}
				}
			}
		}
	} catch (hrefError) { }
	return LoginLinkMessage;
}


function display(elementId, value) {
	try {
		var element;
		if (document.getElementById) {
			element = document.getElementById(elementId);
		}
		else if (document.all) {
			element = document.all[elementId];
		}
		if (element) {
			if (value !== null) {
				element.style.display = value;
			}
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "display: error ");
	}
}

function printStackTrace() {
	var callstack = [];
	var retVal = "";
	var isCallstackPopulated = false;
	try {
		i.dont.exist += 0; //doesn't exist- that's the point
	} catch (e) {
		var lines;
		var i;
		var len;
		if (e.stack) { //Firefox 
			lines = e.stack.split('\n');
			for (i = 0, len = lines.length; i < len; i++) {
				if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
					callstack.push(lines[i]);
				}
			}
			//Remove call to printStackTrace() 
			callstack.shift();
			isCallstackPopulated = true;
			return "";
		}
		else if (window.opera && e.message) { //Opera 
			lines = e.message.split('\n');
			for (i = 0, len = lines.length; i < len; i++) {
				if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
					var entry = lines[i];
					//Append next line also since it has the file info 
					if (lines[i + 1]) {
						entry += ' at ' + lines[i + 1];
						i++;
					}
					callstack.push(entry);
				}
			}
			//Remove call to printStackTrace() 
			callstack.shift();
			isCallstackPopulated = true;
			return "";
		}
	}
	if (!isCallstackPopulated) { //IE and Safari 
		var currentFunction = arguments.callee.caller;
		while (currentFunction) {
			var fn = currentFunction.toString();
			var fname = "";

			if (fn.toString().match(/^function\s*(?:\s+([\w\$]*))?\s*\(/)) {
				if (fn.toString().match(/^function\s*(?:\s+([\w\$]*))?\s*\(/)[1]) {
					fname = fn.toString().match(/^function\s*(?:\s+([\w\$]*))?\s*\(/)[1];
				}
			}
			if (fname !== "eReport") {
				callstack.push(fname);
			}
			currentFunction = currentFunction.caller;
		}
	}
	while (callstack.length > 0) {
		retVal = callstack.pop().toString() + ", " + retVal;
	}
	return retVal;

}

function getArrIndexForValue(Arr, Value, subindex) {
	for (var i = 0; i < Arr.length; i++) {
		if (subindex > -1) {
			if (Arr[i][subindex] === Value) {
				return i;
			}
		}
		else {
			if (Arr[i] === Value) {
				return i;
			}
		}
	}
	return -1;
}

function changeSrc(img_name, img_src, width, height, displayNow) {
	try {
		document.getElementById(img_name).src = img_src;
		if (isUInt(width)) {
			document.getElementById(img_name).width = width;
		}
		if (isUInt(height)) {
			document.getElementById(img_name).height = height;
		}
		if (displayNow) {
			display(img_name, "");
		}
	}
	catch (innertexterror) {
		eReport(innertexterror, "");
	}
}


//validated function to tell if str is non-null and is not a blank string
function isNonEmptyString(str) {
	var RetValue = false;
	if (isExistingObj(str)) {
		if (str !== "") {
			RetValue = true;
		}
	}
	return RetValue;
}

//tell if obj is non-null
function isExistingObj(obj) {
	var RetValue = false;
	if (typeof (obj) !== "undefined" && obj !== null) {
		RetValue = true;
	}
	return RetValue;
}

//pad a number string with zeros on the left
function pad(number, length) {
	var str = '' + number;
	while (str.length < length) {
		str = '0' + str;
	}
	return str;
}

//get an unsigned integer
function isUInt(s) {
	if (!isExistingObj(s)) {
		return false;
	}
	else {
		return (s.toString().trimall().search(/^[0-9]+$/) === 0);
	}
}

//get the URL parameter
function getURLParamForURL(strParamName, strHref) {
	var strReturn = "";
	try {
		if (strHref.indexOf("?") > -1) {
			var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
			var aQueryString = strQueryString.split("&");
			for (var iParam = 0; iParam < aQueryString.length; iParam++) {
				if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
					var aParam = aQueryString[iParam].split("=");
					strReturn = aParam[1];
					strReturn = strReturn.replace("#", "");
					strReturn = strReturn.replace("/", "");
					break;
				}
			}
		}
	} catch (ex) {
		eReport(ex, "getURLParamForURL: error while getting URL parameter");
	}
	return unescape(strReturn);
}

//remove a padding character paddingCharacter from the left side of strNum
function removeLeftPadding(strNum, paddingCharacter) {
	var RetVal = strNum;
	try {
		if (isNonEmptyString(strNum)) {
			RetVal = strNum.toString();
			if (isNonEmptyString(paddingCharacter)) {
				if (paddingCharacter.length === 1) {
					while (RetVal.substr(0, 1) == paddingCharacter && RetVal.length > 1) { RetVal = RetVal.substr(1, 9999); }
				}
			}
		}
	} catch (ex) {
		eReport(ex, "removeLeftPadding: unexpected error");
	}
	return RetVal;
}

function getDDSelectedValue(ddName) {
	if (document.getElementById(ddName)) {
		var ddIndex = document.getElementById(ddName).selectedIndex;
		return document.getElementById(ddName)[ddIndex].value;
	}
	return "";
}
function getDDSelectedText(ddName) {
	if (document.getElementById(ddName)) {
		var ddIndex = document.getElementById(ddName).selectedIndex;
		if (ddIndex > -1) {
			return document.getElementById(ddName)[ddIndex].text;
		}
		else {
			return "";
		}
	}
	return "";
}


function fillNumericDD(obj, min, max, inc, delim, smarts) {
	var index = 0;
	for (i = min; i <= max; i += inc) {
		var val = i;
		if (delim !== "") {
			val += " " + delim;
			if (smarts) {
				if (i !== 1) {
					val += "s";
				}
			}
		}
		obj.options[index] = new Option(val, i);
		index++;
	}
}

function getValue(inText) {
	if (document.getElementById(inText)) {
		return document.getElementById(inText).value;
	}
	return "";
}

function getChecked(ckID) {
	if (document.getElementById(ckID)) {
		return document.getElementById(ckID).checked;
	}
	return false;
}

function setDDSelection(objname, val) {
	for (var i = 0; i < document.getElementById(objname).length; i++) {
		if (document.getElementById(objname).options[i].value == val) {
			document.getElementById(objname).selectedIndex = i
		}
	}
}



function setCheckedValue(radioObj, newValue) {
	if (!radioObj)
		return;
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for (var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if (radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function colorize(objname, colorValue) {
	document.getElementById(objname).style.color = colorValue;
}
//sl 180
function setBackColorStyle(objname, colorValue) {
	document.getElementById(objname).style.backgroundColor = colorValue;
}

function getRadioIndex(objname) {
	return $("input:radio[name='" + objname + "']:checked").val();
}

//#region common to xpressvip applications

function ResultIsSuccess(Result) {
	if (isNonEmptyString(Result)) {
		if (glbAXVersion === 2) {
			return (Result === "1");
		}
		else if (glbAXVersion === 3) {
			return Result.toString().startsWith("Success");
		}
	}
	else {
		return false;
	}
}

function ResultIsFailed(Result) {
	if (isNonEmptyString(Result)) {
		if (glbAXVersion === 2) {
			return (Result === "0" || Result === "-1");
		}
		else if (glbAXVersion === 3) {
			return Result.toString().startsWith("Failed");
		}
	}
	else {
		return false;
	}
}

//sl 180
function AX2GetVariableValuesFromDump(VarName) {
	try {

		//var Dump = glbAX2FeaturesArr[glbAX2FeaturesArrTransport.Dump];
		//var FeatureName = glbAX2FeaturesArr[glbAX2FeaturesArrTransport.Feature];
		if (glbAX2Dump.toString() !== "") {
			if (glbAX2Dump.match(VarName + '====(( \\d*)*)') != null) {
				var FeaturesValues = glbAX2Dump.match(VarName + '====(( \\d*)*)')[1].toString();
				return (FeaturesValues);
			}
		}
	}
	catch (fnError) {
		eReport(fnError, "");
	}
	return "";
}
function AX2GetVariableArrValuesFromDump(VarName) {
	try {
		return AX2GetVariableValuesFromDump(VarName).toString().trim().split(" ").clean();
	}
	catch (fnError) {
		eReport(fnError, "");
	}
	return "";
}
//sl 180
function wsKitDump(glbAX2ID, nvfs_dump, Firmware) {
	try {
		if (isUInt(glbCustomerID)) { glbCustomerID = parseInt(glbCustomerID); } else { glbCustomerID = 0; }

		if (isUInt(glbAX2ID) && isNonEmptyString(nvfs_dump)) {
			DataService.UpdateKitDump(parseInt(glbAX2ID, 10), nvfs_dump, Firmware, glbCustomerID);
		}
		else {
			eReport("", "wsKitDump: invalid parameter; " + glbAX2ID.toString() + "," + nvfs_dump.toString());
		}
	}
	catch (WSERROR) {
		eReport(WSERROR, "wsKitDump: " + glbAX2ID.toString() + "," + nvfs_dump.toString());
	}
}

//sl 180
function AX2GetKitVarsFromKitDetails(KitDetails) {
	var Vars = new Array(11);

	var expected_chars = 0;
	var current_from = 0;
	var current_to = 0;

	current_from += expected_chars; expected_chars = 12; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.platform] = KitDetails.slice(current_from, current_to - 1).trimall();
	glbAX2Platform = Vars[glbAX2KitVarsENum.platform];

	glbAX2NeedsExtraVariables = (Vars[glbAX2KitVarsENum.platform] === "401" || Vars[glbAX2KitVarsENum.platform] === "800");

	current_from += expected_chars; expected_chars = 10; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.port_details] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 50; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.type_details] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 25; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.firmware_name] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 10; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.bootloader_details] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 20; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.glbAX2ID] = KitDetails.slice(current_from, current_to - 1).trimall();

	if (Vars[glbAX2KitVarsENum.glbAX2ID].length === 19) {
		Vars[glbAX2KitVarsENum.glbAX2ID] = Vars[glbAX2KitVarsENum.glbAX2ID].substr(19 - 7, 7);
	}

	current_from += expected_chars; expected_chars = 20; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.firmware_version] = KitDetails.slice(current_from, current_to - 1).trimall();

	//remove platform from front of firmware name since sometimes it is non-standard
	if (Vars[glbAX2KitVarsENum.firmware_name].toString().startsWith(Vars[glbAX2KitVarsENum.platform] + ".")) {
		Vars[glbAX2KitVarsENum.firmware_name] = Vars[glbAX2KitVarsENum.firmware_name].replace(Vars[glbAX2KitVarsENum.platform] + ".", "");
	}

	//remove the firmware version from the firmware name if it was included
	if (Vars[glbAX2KitVarsENum.firmware_name].toString().endsWith(Vars[glbAX2KitVarsENum.firmware_version])) {
		Vars[glbAX2KitVarsENum.firmware_name] = Vars[glbAX2KitVarsENum.firmware_name].replace(Vars[glbAX2KitVarsENum.firmware_version], "").trimall();
	}

	current_from += expected_chars; expected_chars = 513; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.glbAX2D2D] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 50; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.port_conflict] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 30000; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.nvfs_dump] = KitDetails.slice(current_from, current_to - 1).trimall().replace(/\0/g, '0');
	if (Vars[glbAX2KitVarsENum.nvfs_dump] !== "") {
		glbAX2Dump = Vars[glbAX2KitVarsENum.nvfs_dump];
	}

	glbAX2W2W = AX2GetVariableValuesFromDump("W2W");
	glbAX2D2D_TYPE = AX2GetVariableValuesFromDump("D2D_TYPE");

	if (Vars[glbAX2KitVarsENum.nvfs_dump].toString() !== "") {

		if (Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== \d+ \d+ \d+ \d+ \d+/) !== null) {
			var eips_enabled = parseInt(Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== ((?:\d+)) \d+ \d+ \d+ \d+/)[1].toString(), 10);
			var eips_shutdown1 = parseInt(Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== \d+ ((?:\d+)) \d+ \d+ \d+/)[1].toString(), 10);
			var eips_shutdown2 = parseInt(Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== \d+ \d+ ((?:\d+)) \d+ \d+/)[1].toString(), 10);
			var eips_alert1 = parseInt(Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== \d+ \d+ \d+ ((?:\d+)) \d+/)[1].toString(), 10);
			var eips_alert2 = parseInt(Vars[glbAX2KitVarsENum.nvfs_dump].toString().match(/EIPS==== \d+ \d+ \d+ \d+ ((?:\d+))/)[1].toString(), 10);

			Vars[glbAX2KitVarsENum.NVFSDumpEIPSEnabled] = (eips_enabled === 1);
			Vars[glbAX2KitVarsENum.NVFSDumpEIPSShutdown] = parseInt((eips_shutdown1 * 256 + eips_shutdown2) / 60, 10);
			Vars[glbAX2KitVarsENum.NVFSDumpEIPSAlertMinutes] = parseInt((eips_alert1 * 256 + eips_alert2) / 60, 10);
			Vars[glbAX2KitVarsENum.NVFSDumpEIPSAlertSeconds] = parseInt((eips_alert1 * 256 + eips_alert2) % 60, 10);
		}
	}

	current_from += expected_chars; expected_chars = 5000; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.error_details] = KitDetails.slice(current_from, current_to - 1).trimall();

	Vars[glbAX2KitVarsENum.brand] = AX2GetVariableValuesFromDump("BRAND");

	current_from += expected_chars; expected_chars = 30; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.hw_id] = KitDetails.slice(current_from, current_to - 1).trimall();

	current_from += expected_chars; expected_chars = 30; current_to += expected_chars;
	Vars[glbAX2KitVarsENum.nvfs_platform] = KitDetails.slice(current_from, current_to - 1).trimall();

	//todo eventually create nvfs_platform field and get the platform from the table
	if (Vars[glbAX2KitVarsENum.nvfs_platform] !== "") {
		if (Vars[glbAX2KitVarsENum.nvfs_platform] === "CM800") {
			Vars[glbAX2KitVarsENum.platform] = "800";
			glbAX2Platform = Vars[glbAX2KitVarsENum.platform];
		}
		else if (Vars[glbAX2KitVarsENum.nvfs_platform] === "DBALL") {
			Vars[glbAX2KitVarsENum.platform] = "401";
			glbAX2Platform = Vars[glbAX2KitVarsENum.platform];
		}
	}

	current_from += expected_chars; expected_chars = 30; current_to += expected_chars;
	if (KitDetails.slice(current_from, current_to - 1).trimall() !== "") {
		Vars[glbAX2KitVarsENum.firmware_name] = KitDetails.slice(current_from, current_to - 1).trimall();
	}
	//sl 167
	glbKitFirmawreName = Vars[glbAX2KitVarsENum.firmware_name];


	return Vars;
}

//sl 180 moved functions here
function ResetReserveWait() {
	ResetReserve();
	ResetWait();
}
function ResetReserve() {
	glbAX2ReserveState = glbAX2ReserveStates.none;
}
function ResetWait() {
	glbAX2WaitingState = glbAX2WaitingStates.none;
}

function IsInHomePage() {
	return isInPageExact("http://localhost:59691/XpressKit/") || isInPage("default.aspx") || isInPageExact("http://www.xpresskit.com/") || isInPageExact("http://demo.xpresskit.com/");
}

//#endregion

//#region error handling

function eReport(ErrorObj, ErrorCustomDetails) {
	var EmailMessage = "";

	try {

		var IncidentDate = new Date();

		var Proceed = true;

		//ingore errors if the page is unloading since it can cause
		// unimportant operation cancellation errors
		if (typeof (glbIsPageUnloading) != 'undefined') {
			if (isExistingObj(glbIsPageUnloading)) {
				if (glbIsPageUnloading) {
					Proceed = false;
				}
			}
		}

		if (Proceed) {
			if (typeof (IncidentDate) != 'undefined') {
				if (isExistingObj(IncidentDate)) {
					if (typeof (glbPageLoadedAt) != 'undefined') {
						if (isExistingObj(glbPageLoadedAt)) {
							if (Math.abs((IncidentDate.getTime() - glbPageLoadedAt.getTime()) / 1000) < 3) {
								//ignore if the there is less than 3 seconds between the time the page loaded and the time of the error
								// it is very likely just a problem caused when user pressed back/forward button
								Proceed = false;
							}
						}
					}
				}
			}
		}

		if (typeof (glbTotalErrors) != 'undefined') {
			if (isExistingObj(glbTotalErrors)) {
				if (glbTotalErrors > 0) {
					//only send the first error on the page otherwise may lead to error spewing if we are in a loop
					Proceed = false;
				}
			}
		}

		if (Proceed) {
			var URL = GetHRef();
			var UserAgentStr = GetUserAgent();
			var Globals = GetErrorGlobalsReport();

			if (!glbIsTesting) { if (typeof (glbUser) != 'undefined') { if (isExistingObj(glbUser)) { EmailMessage += "<br>glbUser: " + glbUser; } } }

			if (!glbIsTesting) { if (typeof (glbTotalErrors) != 'undefined') { if (isExistingObj(glbTotalErrors)) { EmailMessage += "<br>glbTotalErrors: " + glbTotalErrors.toString(); glbTotalErrors += 1; } } }

			if (!glbIsTesting) { EmailMessage += "<br>ERROR TIMING... " + GetErrorTimeValues(); }
			EmailMessage += "<br>ERROR DETAILS... " + GetErrorDetailsReport(ErrorObj, ErrorCustomDetails);
			if (!glbIsTesting) { EmailMessage += "<br>SYSTEM... " + GetErrorSystemReport(); }
			if (!glbIsTesting) { EmailMessage += "<br>GLOBALS... " + Globals; }

			//display the appropriate vip4.0 or vip4.2 version depending on which is detected
			if (typeof (glbAXVersion) != 'undefined') {
				if (isExistingObj(glbAXVersion)) {
					if (glbAXVersion.toString() === '2' || glbAXVersion.toString() === '3') {
						EmailMessage += GetErrorGlobalsAX2Report();
					}
					else if (glbAXVersion.toString() === '1') {
						EmailMessage += GetGlobalsAX1Report();
					}
					else {
						EmailMessage += GetErrorGlobalsAX2Report();
						EmailMessage += GetGlobalsAX1Report();
					}
				}
				else {
					EmailMessage += GetErrorGlobalsAX2Report();
					EmailMessage += GetGlobalsAX1Report();
				}
			}
			else {
				EmailMessage += GetErrorGlobalsAX2Report();
				EmailMessage += GetGlobalsAX1Report();
			}

			EmailMessage = "Stack: " + printStackTrace().toString() + EmailMessage;

			//      for (var prop in ERROR_OBJECT) { EmailMessage = " " + prop + " = " + ERROR_OBJECT[prop] + EmailMessage; }

			if (glbIsTesting) {
				alert(EmailMessage.replace(/<br>/g, "\r\n").replace(/&nbsp;/g, " "));
			}
			else {
				DataService.SendErrorEmail(EmailMessage);
				InsertKitWebException2(UserAgentStr);
			}
		}
	}
	catch (reportexception) {
		DataService.SendErrorEmail("error while trying to send email message");

		try {

			if (typeof (ErrorObj) != 'undefined') {
				if (isExistingObj(ErrorObj)) {
					EmailMessage += GeteReport(ErrorObj);
				}
			}

			DataService.SendErrorEmail("error while trying to send email message: " + EmailMessage);
		}
		catch (reportexception2) {
			try {
				DataService.SendErrorEmail("error while trying to send email message");
			}
			catch (reportexception3) {
			}
		}
	}
	return;
}

function InsertKitWebException2(useragent) {
	var tmpuseragent = (typeof (useragent) == 'undefined') ? "undef" : (useragent === null) ? "null" : useragent.toString();
	var tmpglbIsTesting = (typeof (glbIsTesting) == 'undefined') ? "undef" : (glbIsTesting === null) ? "null" : glbIsTesting.toString();
	var tmpglbIsLogging = (typeof (glbIsLogging) == 'undefined') ? "undef" : (glbIsLogging === null) ? "null" : glbIsLogging.toString();
	var tmpglbLogPath = (typeof (glbLogPath) == 'undefined') ? "undef" : (glbLogPath === null) ? "null" : glbLogPath.toString();
	var tmpglbIsIE = (typeof (glbIsIE) == 'undefined') ? "undef" : (glbIsIE === null) ? "null" : glbIsIE.toString();
	var tmpglbTotalErrors = (typeof (glbTotalErrors) == 'undefined') ? "undef" : (glbTotalErrors === null) ? "null" : glbTotalErrors.toString();
	var tmpglbAXVersion = (typeof (glbAXVersion) == 'undefined') ? "undef" : (glbAXVersion === null) ? "null" : glbAXVersion.toString();
	var tmpglbIsVirginPage = (typeof (glbIsVirginPage) == 'undefined') ? "undef" : (glbIsVirginPage === null) ? "null" : glbIsVirginPage.toString();
	var tmpglbAXDetectReturnValue = (typeof (glbAXDetectReturnValue) == 'undefined') ? "undef" : (glbAXDetectReturnValue === null) ? "null" : glbAXDetectReturnValue.toString();
	var tmpglbAXFlashResults = (typeof (glbAXFlashResults) == 'undefined') ? "undef" : (glbAXFlashResults === null) ? "null" : glbAXFlashResults.toString();
	var tmpglbAXD2DReadReturnValue = (typeof (glbAXD2DReadReturnValue) == 'undefined') ? "undef" : (glbAXD2DReadReturnValue === null) ? "null" : glbAXD2DReadReturnValue.toString();
	var tmpglbHasFocus = (typeof (glbHasFocus) == 'undefined') ? "undef" : (glbHasFocus === null) ? "null" : glbHasFocus.toString();
	var tmpglbCookies = (typeof (glbCookies) == 'undefined') ? "undef" : (glbCookies === null) ? "null" : glbCookies.toString();
	var tmpglbAJAX = (typeof (glbAJAX) == 'undefined') ? "undef" : (glbAJAX === null) ? "null" : glbAJAX.toString();
	var tmpglbPreviousPlatformID = (typeof (glbPreviousPlatformID) == 'undefined') ? "undef" : (glbPreviousPlatformID === null) ? "null" : glbPreviousPlatformID.toString();
	var tmpglbPreviousFirmware = (typeof (glbPreviousFirmware) == 'undefined') ? "undef" : (glbPreviousFirmware === null) ? "null" : glbPreviousFirmware.toString();
	var tmpglbLn = (typeof (glbLn) == 'undefined') ? "undef" : (glbLn === null) ? "null" : glbLn.toString();
	var tmpglbHasPathAccess = (typeof (glbHasPathAccess) == 'undefined') ? "undef" : (glbHasPathAccess === null) ? "null" : glbHasPathAccess.toString();
	var tmpglbPageLoadedAt = (typeof (glbPageLoadedAt) == 'undefined') ? "undef" : (glbPageLoadedAt === null) ? "null" : glbPageLoadedAt.toString();
	var tmpglbFlashingStartedAt = (typeof (glbFlashingStartedAt) == 'undefined') ? "undef" : (glbFlashingStartedAt === null) ? "null" : glbFlashingStartedAt.toString();
	var tmpglbIsPageUnloading = (typeof (glbIsPageUnloading) == 'undefined') ? "undef" : (glbIsPageUnloading === null) ? "null" : glbIsPageUnloading.toString();
	var tmpglbAX1IsFlashing = (typeof (glbAX1IsFlashing) == 'undefined') ? "undef" : (glbAX1IsFlashing === null) ? "null" : glbAX1IsFlashing.toString();
	var tmpglbAX1FlashingIsFinished = (typeof (glbAX1FlashingIsFinished) == 'undefined') ? "undef" : (glbAX1FlashingIsFinished === null) ? "null" : glbAX1FlashingIsFinished.toString();
	var tmpglbRunSearch = (typeof (glbRunSearch) == 'undefined') ? "undef" : (glbRunSearch === null) ? "null" : glbRunSearch.toString();
	var tmpglbAX1URL = (typeof (glbAX1URL) == 'undefined') ? "undef" : (glbAX1URL === null) ? "null" : glbAX1URL.toString();
	var tmpglbAX1DownloadSec = (typeof (glbAX1DownloadSec) == 'undefined') ? "undef" : (glbAX1DownloadSec === null) ? "null" : glbAX1DownloadSec.toString();
	var tmpglbAX2TooltipObj = (typeof (glbAX2TooltipObj) == 'undefined') ? "undef" : (glbAX2TooltipObj === null) ? "null" : glbAX2TooltipObj.toString();
	var tmpglbAX2InitializingDisplay = (typeof (glbAX2InitializingDisplay) == 'undefined') ? "undef" : (glbAX2InitializingDisplay === null) ? "null" : glbAX2InitializingDisplay.toString();

	var tmpglbAX2WaitingState = (typeof (glbAX2WaitingState) == 'undefined') ? "undef" : (glbAX2WaitingState === null) ? "null" : glbAX2WaitingState.toString();
	var tmpglbAX2ReserveState = (typeof (glbAX2ReserveState) == 'undefined') ? "undef" : (glbAX2ReserveState === null) ? "null" : glbAX2ReserveState.toString();

	var tmpglbAX2ID = (typeof (glbAX2ID) == 'undefined') ? "undef" : (glbAX2ID === null) ? "null" : glbAX2ID.toString();
	var tmpglbAX2URL = (typeof (glbAX2URL) == 'undefined') ? "undef" : (glbAX2URL === null) ? "null" : glbAX2URL.toString();
	var tmpglbAX2DownloadSec = (typeof (glbAX2DownloadSec) == 'undefined') ? "undef" : (glbAX2DownloadSec === null) ? "null" : glbAX2DownloadSec.toString();
	//TODO REMOVE VARIABLE FROM LOG  var tmpglbRunSearch = (typeof (glbRunSearch) == 'undefined') ? "undef" : glbRunSearch.toString();
	var tmpglbAX2D2D = (typeof (glbAX2D2D) == 'undefined') ? "undef" : (glbAX2D2D === null) ? "null" : glbAX2D2D.toString();
	var tmpglbAX2NeedsExtraiables = (typeof (glbAX2NeedsExtraiables) == 'undefined') ? "undef" : (glbAX2NeedsExtraiables === null) ? "null" : glbAX2NeedsExtraiables.toString();
	var tmpglbAX2D2DAfterChanges = (typeof (glbAX2D2DAfterChanges) == 'undefined') ? "undef" : (glbAX2D2DAfterChanges === null) ? "null" : glbAX2D2DAfterChanges.toString();
	var tmpglbAX2DatabaseD2DSummary = (typeof (glbAX2DatabaseD2DSummary) == 'undefined') ? "undef" : (glbAX2DatabaseD2DSummary === null) ? "null" : glbAX2DatabaseD2DSummary.toString();
	var tmpglbAX2D2DResults = (typeof (glbAX2D2DResults) == 'undefined') ? "undef" : (glbAX2D2DResults === null) ? "null" : glbAX2D2DResults.toString();
	var tmpglbAX2W2W = (typeof (glbAX2W2W) == 'undefined') ? "undef" : (glbAX2W2W === null) ? "null" : glbAX2W2W.toString();
	var tmpglbAX2W2WAfterChanges = (typeof (glbAX2W2WAfterChanges) == 'undefined') ? "undef" : (glbAX2W2WAfterChanges === null) ? "null" : glbAX2W2WAfterChanges.toString();
	var tmpglbAX2W2WResults = (typeof (glbAX2W2WResults) == 'undefined') ? "undef" : (glbAX2W2WResults === null) ? "null" : glbAX2W2WResults.toString();
	var tmpglbAX2D2DWrite = (typeof (glbAX2D2DWrite) == 'undefined') ? "undef" : (glbAX2D2DWrite === null) ? "null" : glbAX2D2DWrite.toString();
	var tmpglbAX2VehicleWrite = (typeof (glbAX2VehicleWrite) == 'undefined') ? "undef" : (glbAX2VehicleWrite === null) ? "null" : glbAX2VehicleWrite.toString();
	var tmpglbAX2VehicleResults = (typeof (glbAX2VehicleResults) == 'undefined') ? "undef" : (glbAX2VehicleResults === null) ? "null" : glbAX2VehicleResults.toString();
	var tmpglbUser = (typeof (glbUser) == 'undefined') ? "undef" : (glbUser === null) ? "null" : glbUser.toString();

	DataService.InsertKitWebException2(tmpuseragent, tmpglbIsTesting, tmpglbIsLogging, tmpglbLogPath, tmpglbIsIE, tmpglbTotalErrors, tmpglbAXVersion, tmpglbIsVirginPage,
	tmpglbAXDetectReturnValue, tmpglbAXFlashResults, tmpglbAXD2DReadReturnValue,
	tmpglbHasFocus,
	tmpglbCookies,
	tmpglbAJAX,
	tmpglbPreviousPlatformID,
	tmpglbPreviousFirmware,
	tmpglbLn,
	tmpglbHasPathAccess,
	tmpglbPageLoadedAt,
	tmpglbFlashingStartedAt,
	tmpglbIsPageUnloading,
	tmpglbAX1IsFlashing,
	tmpglbAX1FlashingIsFinished,
	tmpglbRunSearch,
	tmpglbAX1URL,
	tmpglbAX1DownloadSec,
	tmpglbAX2TooltipObj,
	tmpglbAX2InitializingDisplay,
	tmpglbAX2WaitingState,
	tmpglbAX2ReserveState,
	tmpglbAX2ID,
	tmpglbAX2URL,
	tmpglbAX2DownloadSec,
	tmpglbRunSearch,
	tmpglbAX2D2D,
	tmpglbAX2NeedsExtraiables,
	tmpglbAX2D2DAfterChanges,
	tmpglbAX2DatabaseD2DSummary,
	tmpglbAX2D2DResults,
	tmpglbAX2W2W,
	tmpglbAX2W2WAfterChanges,
	tmpglbAX2W2WResults,
	tmpglbAX2D2DWrite,
	tmpglbAX2VehicleWrite,
	tmpglbAX2VehicleResults,
	tmpglbUser);
}

function GetErrorDetailsReport(ErrorObj, ErrorCustomDetails) {
	var EmailMessage = "";

	try {

		if (typeof (ErrorCustomDetails) != 'undefined') {
			if (isNonEmptyString(ErrorCustomDetails)) {
				EmailMessage += "<br>&nbsp;ErrorCustomDetails: " + ErrorCustomDetails.toString();
			}
		}

		if (typeof (ErrorObj) != 'undefined') {
			if (isExistingObj(ErrorObj)) {
				EmailMessage += GeteReport(ErrorObj);
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetErrorSystemReport: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetUserAgent() {
	var EmailMessage = "";

	try {
		if (typeof (ua) != 'undefined') {
			if (isExistingObj(ua)) {
				EmailMessage += ua;
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetUserAgent: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetHRef() {

	var EmailMessage = "";

	try {

		if (typeof (location) != 'undefined') {
			if (isExistingObj(location)) {

				if (typeof (location.href) != 'undefined') {
					if (isExistingObj(location.href)) {
						EmailMessage += "<br>&nbsp;location.href: " + location.href.toString();
					}
				}
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetHRef: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetErrorSystemReport() {

	var EmailMessage = "";

	try {

		if (typeof (BrowserDetect) != 'undefined') {
			if (isExistingObj(BrowserDetect)) {

				if (typeof (BrowserDetect.browser) != 'undefined') {
					if (isExistingObj(BrowserDetect.browser)) {
						EmailMessage += "<br>&nbsp;BROWSER/OS: " + BrowserDetect.browser;
					}
				}

				if (typeof (BrowserDetect.version) != 'undefined') {
					if (isExistingObj(BrowserDetect.version)) {
						EmailMessage += " " + BrowserDetect.version;
					}
				}

				if (typeof (osversion) != 'undefined') {
					if (isExistingObj(osversion)) {
						EmailMessage += " on " + osversion;
					}
				}
			}
		}

		EmailMessage += "<br>&nbsp;USER AGENT:" + GetUserAgent();

		EmailMessage += "<br>&nbsp;HREF:" + GetHRef();

		if (typeof (document.referrer) != 'undefined') {
			if (isExistingObj(document.referrer)) {
				EmailMessage += "<br>&nbsp;REFERING URL:" + document.referrer;
			}
		}

	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetErrorSystemReport: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetErrorTimeValues() {

	var EmailMessage = "";

	try {

		var IncidentDate = new Date();

		if (typeof (IncidentDate) != 'undefined') {
			if (isExistingObj(IncidentDate)) {
				EmailMessage += "<br>&nbsp;WHEN: " + IncidentDate.getDay() + "/" + IncidentDate.getMonth() + "/" + IncidentDate.getYear() + " " + IncidentDate.getHours() + ":" + IncidentDate.getMinutes() + ":" + IncidentDate.getSeconds();
			}
		}

		if (typeof (glbPageLoadedAt) != 'undefined') {
			if (isExistingObj(glbPageLoadedAt)) {
				EmailMessage += "<br>&nbsp;glbPageLoadedAt: " + glbPageLoadedAt.getDay() + "/" + glbPageLoadedAt.getMonth() + "/" + glbPageLoadedAt.getYear() + " " + glbPageLoadedAt.getHours() + ":" + glbPageLoadedAt.getMinutes() + ":" + glbPageLoadedAt.getSeconds();
			}
		}

		if (typeof (IncidentDate) != 'undefined') {
			if (isExistingObj(IncidentDate)) {
				if (typeof (glbPageLoadedAt) != 'undefined') {
					if (isExistingObj(glbPageLoadedAt)) {
						EmailMessage += "<br>&nbsp;SECONDS SINCE PAGE LOADED: " + Math.abs((IncidentDate.getTime() - glbPageLoadedAt.getTime()) / 1000);
					}
				}
			}
		}

		if (typeof (glbFlashingStartedAt) != 'undefined') {
			if (isExistingObj(glbFlashingStartedAt)) {
				EmailMessage += "<br>&nbsp;glbFlashingStartedAt: " + glbFlashingStartedAt.getDay() + "/" + glbFlashingStartedAt.getMonth() + "/" + glbFlashingStartedAt.getYear() + " " + glbFlashingStartedAt.getHours() + ":" + glbFlashingStartedAt.getMinutes() + ":" + glbFlashingStartedAt.getSeconds();
			}
		}

		if (typeof (IncidentDate) != 'undefined') {
			if (isExistingObj(IncidentDate)) {
				if (typeof (glbFlashingStartedAt) != 'undefined') {
					if (isExistingObj(glbFlashingStartedAt)) {
						EmailMessage += "<br>&nbsp;SECONDS SINCE FLASH STARTED: " + Math.abs((IncidentDate.getTime() - glbFlashingStartedAt.getTime()) / 1000);
					}
				}
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetErrorTimeValues: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetErrorGlobalsReport() {

	var EmailMessage = "";

	try {

		if (typeof (glbHasPathAccess) != 'undefined') {
			if (isExistingObj(glbHasPathAccess)) {
				EmailMessage += "<br>&nbsp;glbHasPathAccess: " + glbHasPathAccess.toString();
			}
		}

		if (typeof (glbLn) != 'undefined') {
			if (isExistingObj(glbLn)) {
				EmailMessage += "<br>&nbsp;glbLn: " + glbLn.toString();
			}
		}

		if (typeof (glbIsTesting) != 'undefined') {
			if (isExistingObj(glbIsTesting)) {
				EmailMessage += "<br>&nbsp;glbIsTesting: " + glbIsTesting.toString();
			}
		}

		if (typeof (glbHasFocus) != 'undefined') {
			if (isExistingObj(glbHasFocus)) {
				EmailMessage += "<br>&nbsp;glbHasFocus: " + glbHasFocus.toString();
			}
		}
		if (typeof (glbIsVirginPage) != 'undefined') {
			if (isExistingObj(glbIsVirginPage)) {
				EmailMessage += "<br>&nbsp;glbIsVirginPage: " + glbIsVirginPage.toString();
			}
		}
		if (typeof (glbIsIE) != 'undefined') {
			if (isExistingObj(glbIsIE)) {
				EmailMessage += "<br>&nbsp;glbIsIE: " + glbIsIE.toString();
			}
		}
		if (typeof (glbIsLogging) != 'undefined') {
			if (isExistingObj(glbIsLogging)) {
				EmailMessage += "<br>&nbsp;glbIsLogging: " + glbIsLogging.toString();
			}
		}

		if (typeof (glbLogPath) != 'undefined') {
			if (isExistingObj(glbLogPath)) {
				EmailMessage += "<br>&nbsp;glbLogPath: " + glbLogPath.toString();
			}
		}

		if (typeof (glbAXVersion) != 'undefined') {
			if (isExistingObj(glbAXVersion)) {
				EmailMessage += "<br>&nbsp;glbAXVersion: " + glbAXVersion.toString();
			}
		}

		if (typeof (glbAXFlashResults) != 'undefined') {
			if (isNonEmptyString(glbAXFlashResults)) {
				EmailMessage += "<br>&nbsp;glbAXFlashResults: " + glbAXFlashResults.toString();
			}
		}

		if (typeof (glbAXD2DReadReturnValue) != 'undefined') {
			if (isNonEmptyString(glbAXD2DReadReturnValue)) {
				EmailMessage += "<br>&nbsp;glbAXD2DReadReturnValue: " + glbAXD2DReadReturnValue.toString();
			}
		}

		if (typeof (glbAX2D2DResults) != 'undefined') {
			if (isNonEmptyString(glbAX2D2DResults)) {
				EmailMessage += "<br>&nbsp;glbAX2D2DResults: " + glbAX2D2DResults.toString();
			}
		}

		if (typeof (glbCookies) != 'undefined') {
			if (isNonEmptyString(glbCookies)) {
				EmailMessage += "<br>&nbsp;glbCookies: " + glbCookies.toString();
			}
		}

		if (typeof (glbPreviousPlatformID) != 'undefined') {
			if (isNonEmptyString(glbPreviousPlatformID)) {
				EmailMessage += "<br>&nbsp;glbPreviousPlatformID: " + glbPreviousPlatformID.toString();
			}
		}

		if (typeof (glbPreviousFirmware) != 'undefined') {
			if (isNonEmptyString(glbPreviousFirmware)) {
				EmailMessage += "<br>&nbsp;glbPreviousFirmware: " + glbPreviousFirmware.toString();
			}
		}

		if (typeof (glbAXDetectReturnValue) != 'undefined') {
			if (isNonEmptyString(glbAXDetectReturnValue)) {
				EmailMessage += "<br>&nbsp;glbAXDetectReturnValue: " + glbAXDetectReturnValue.toString();
			}
		}

		if (typeof (glbRunSearch) != 'undefined') {
			if (isExistingObj(glbRunSearch)) {
				EmailMessage += "<br>&nbsp;glbRunSearch: " + glbRunSearch.toString();
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetErrorGlobalsReport: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetGlobalsAX1Report() {

	var EmailMessage = "";

	try {

		EmailMessage += "<br>GLOBALS FOR VIP4.0... ";

		if (typeof (glbAX1IsFlashing) != 'undefined') {
			if (isExistingObj(glbAX1IsFlashing)) {
				EmailMessage += "<br>&nbsp;glbAX1IsFlashing: " + glbAX1IsFlashing.toString();
			}
		}
		if (typeof (glbAX1FlashingIsFinished) != 'undefined') {
			if (isExistingObj(glbAX1FlashingIsFinished)) {
				EmailMessage += "<br>&nbsp;glbAX1FlashingIsFinished: " + glbAX1FlashingIsFinished.toString();
			}
		}

		if (typeof (TMP_URL) != 'undefined') {
			if (isExistingObj(TMP_URL)) {
				EmailMessage += "<br>&nbsp;TMP_URL: " + TMP_URL.toString();
			}
		}
		if (typeof (glbAX1DownloadSec) != 'undefined') {
			if (isExistingObj(glbAX1DownloadSec)) {
				EmailMessage += "<br>&nbsp;glbAX1DownloadSec: " + glbAX1DownloadSec.toString();
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetGlobalsAX1Report: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GetErrorGlobalsAX2Report() {

	var EmailMessage = "";

	try {
		EmailMessage += "<br>GLOBALS FOR VIP4.2... ";

		if (typeof (glbAX2InitializingDisplay) != 'undefined') {
			if (isExistingObj(glbAX2InitializingDisplay)) {
				EmailMessage += "<br>&nbsp;glbAX2InitializingDisplay: " + glbAX2InitializingDisplay.toString();
			}
		}

		if (typeof (glbAX2WaitingState) != 'undefined') {
			if (isExistingObj(glbAX2WaitingState)) {
				EmailMessage += "<br>&nbsp;glbAX2WaitingState: " + glbAX2WaitingState.toString();
			}
		}

		if (typeof (glbAX2ReserveState) != 'undefined') {
			if (isExistingObj(glbAX2ReserveState)) {
				EmailMessage += "<br>&nbsp;glbAX2ReserveState: " + glbAX2ReserveState.toString();
			}
		}

		if (typeof (glbAX2ID) != 'undefined') {
			if (isExistingObj(glbAX2ID)) {
				EmailMessage += "<br>&nbsp;glbAX2ID: " + glbAX2ID.toString();
			}
		}
		if (typeof (glbAX2D2D) != 'undefined') {
			if (isExistingObj(glbAX2D2D)) {
				EmailMessage += "<br>&nbsp;glbAX2D2D: " + glbAX2D2D.toString();
			}
		}

		if (typeof (glbAX2URL) != 'undefined') {
			if (isExistingObj(glbAX2URL)) {
				EmailMessage += "<br>&nbsp;glbAX2URL: " + glbAX2URL.toString();
			}
		}

		if (typeof (glbAX2DownloadSec) != 'undefined') {
			if (isExistingObj(glbAX2DownloadSec)) {
				EmailMessage += "<br>&nbsp;glbAX2DownloadSec: " + glbAX2DownloadSec.toString();
			}
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GetErrorGlobalsAX2Report: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}

function GeteReport(ErrorObj) {

	var EmailMessage = "";

	try {
		if (typeof (ErrorObj.popStackFrame) != 'undefined') {
			if (typeof (ErrorObj.popStackFrame()) != 'undefined') {
				EmailMessage += "<br>&nbsp;popStackFrame: " + ErrorObj.popStackFrame();
			} 
		}

		if (typeof (ErrorObj.get_message) != 'undefined') {
			if (typeof (ErrorObj.get_message()) != 'undefined') {
				EmailMessage += "<br>&nbsp;get_message: " + ErrorObj.get_message();
			} 
		}

		if (typeof (ErrorObj.get_statusCode) != 'undefined') {
			if (typeof (ErrorObj.get_statusCode()) != 'undefined') {
				EmailMessage += "<br>&nbsp;get_statusCode: " + ErrorObj.get_statusCode();
			} 
		}

		if (typeof (ErrorObj.get_timedOut) != 'undefined') {
			if (typeof (ErrorObj.get_timedOut()) != 'undefined') {
				EmailMessage += "<br>&nbsp;get_timedOut: " + ErrorObj.get_timedOut();
			} 
		}

		if (typeof (ErrorObj.get_stackTrace) != 'undefined') {
			if (typeof (ErrorObj.get_stackTrace()) != 'undefined') {
				EmailMessage += "<br>&nbsp;get_stackTrace: " + ErrorObj.get_stackTrace();
			} 
		}

		if (typeof (ErrorObj.get_exceptionType) != 'undefined') {
			if (typeof (ErrorObj.get_exceptionType()) != 'undefined') {
				EmailMessage += "<br>&nbsp;get_exceptionType: " + ErrorObj.get_exceptionType();
			} 
		}

		if (typeof (ErrorObj._exceptionType) != 'undefined') {
			EmailMessage += "<br>&nbsp;_exceptionType: " + ErrorObj._exceptionType;
		}
		if (typeof (ErrorObj._message) != 'undefined') {
			EmailMessage += "<br>&nbsp;_message: " + ErrorObj._message;
		}
		if (typeof (ErrorObj._stackTrace) != 'undefined') {
			EmailMessage += "<br>&nbsp;_stackTrace: " + ErrorObj._stackTrace;
		}
		if (typeof (ErrorObj._stackCode) != 'undefined') {
			EmailMessage += "<br>&nbsp;_stackCode: " + ErrorObj._stackCode;
		}
		if (typeof (ErrorObj._timedOut) != 'undefined') {
			EmailMessage += "<br>&nbsp;_timedOut: " + ErrorObj._timedOut;
		}

		if (typeof (ErrorObj.description) != 'undefined') {
			EmailMessage += "<br>&nbsp;description: " + ErrorObj.description;
		}
		if (typeof (ErrorObj.message) != 'undefined') {
			EmailMessage += "<br>&nbsp;message: " + ErrorObj.message;
		}
		if (typeof (ErrorObj.Message) != 'undefined') {
			EmailMessage += "<br>&nbsp;Message: " + ErrorObj.Message;
		}
		if (typeof (ErrorObj.name) != 'undefined') {
			EmailMessage += "<br>&nbsp;name: " + ErrorObj.name;
		}
		if (typeof (ErrorObj.number) != 'undefined') {
			EmailMessage += "<br>&nbsp;number: " + ErrorObj.number;
		}
	}
	catch (reportexception) {
		EmailMessage += "<br>&nbsp;GeteReport: CAUGHT EXCEPTION ";
	}

	return EmailMessage;
}
//#endregion

function printIframe(id) { var iframe = document.frames ? document.frames[id] : document.getElementById(id); var ifWin = iframe.contentWindow || iframe; ifWin.focus(); ifWin.printPage(); return false; }

Array.prototype.clean = function (deleteValue) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == deleteValue) {
			this.splice(i, 1);
			i--;
		}
	}
	return this;
}


