// ----------------- ERROR HANDLING CODE ----------
	if (window.location.href.indexOf("localhost") == -1)
		window.onerror = javascriptErrorHandler	
	function javascriptErrorHandler(msg, url, linenumber) {
	   

		var referer = "";
		if (document.referrer) referer = document.referrer;
		
		var errorUrl = '/ErrorHandler/JSErrorHandler.aspx?'
			+ 'message=' + escape(msg) 
			+ '&URL=' + escape(url) 
			+ '&LineNumber=' + linenumber 
			+ '&referer=' + escape(referer);
			
		re = new RegExp(/[\?\&]id=(\d*)/gi)
		var foundId = re.exec(referer);
		
		if (foundId && foundId.length == 2)
		    errorUrl += "&id=" + foundId[1];
		
		SE_HttpRequest = SE_GetXmlHttp();
		if (SE_HttpRequest)
		{
			SE_HttpRequest.open('GET', errorUrl, true);
			SE_HttpRequest.send(null);
		}		
		SE_OpenAdBlockerWarning();				
		SE_Error_HandleSpecialCases(msg);
		return false;
	}

	_SE_HasPopopBlocker = null;
	_SE_AdBlockTestPage = "/Common/ErrorHandler/PopupTest.aspx";
	
	function SE_HasPopupBlocker()
	{
		if (_SE_HasPopopBlocker == null)
		{
			if (window.SymRealWinOpen)
				_SE_HasPopopBlocker = "yes";				
			else 
			{
				var winTest = window.open(_SE_AdBlockTestPage, "PopupTest", "left=4000,top=4000,width=1,height=1,status=0,directories=0,location=0,scrollbars=0,resizable=0,menubar=0,toolbar=0");
				if (!winTest || !winTest.close)
					_SE_HasPopopBlocker = "yes";	
				else
				{
					winTest.close();
					var winTest1 = window.open(_SE_AdBlockTestPage, "PopupTest", "left=4000,top=4000,width=1,height=1,status=0,directories=0,location=0,scrollbars=0,resizable=0,menubar=0,toolbar=0");
					if (!winTest1)	
						_SE_HasPopopBlocker = "yes";	
					else
					{
						winTest1.close()
						_SE_HasPopopBlocker =  "no";
					}
				}
			}
		}
		return _SE_HasPopopBlocker;
	}

	_SE_HasAdBlocker = null;
	function SE_HasAdBlocker()
	{
		if (_SE_HasAdBlocker == null)
		{
			adTestHtml = SE_GetHttpText(_SE_AdBlockTestPage) 
			if (adTestHtml.indexOf("banner/clear.gif") != -1)
				_SE_HasAdBlocker = "no";
			else
				_SE_HasAdBlocker= "yes";
		}
		return _SE_HasAdBlocker;
	}

	function SE_OpenAdBlockerWarning()
	{
		// this can end up in a infinite loop unless we skip it when called from SE_HasAdBlocker()
		if (_SE_HasAdBlocker == "yes") 
		{
			if (SE_GetCookie('HideAdBlockerWarning') != "yes")
			{
				var divAlert = document.getElementById("divSE_AdBlockerWarning");
				if (divAlert == null) 
				{
					divAlert = document.createElement("div");
				}
				divAlert.id = "divSE_AdBlockerWarning";
				divParent = document.getElementById("adBlockerWarning");
				if (divParent)
					divParent.appendChild(divAlert);
				else
					document.body.appendChild(divAlert);
				divAlert.style.position = "absolute";
				divAlert.style.left = "100px";
				divAlert.style.top = "100px";
				divAlert.style.zIndex = "1000";
				
				divAlert.innerHTML = SE_AdBlockerWarning(divAlert)
					+ "<p><input type='checkbox' id='chkAdBlockerWarning' name='chkAdBlockerWarning' value='no'  onclick=SE_CloseAdBlockerWarning()> "
					+ "<span class='note'>Do not show again</span>"
					+ "<div align='right'><a href='javascript:SE_CloseAdBlockerWarning()'>close</a></div>"
			}
			else
			{
				setTimeout('window.status = "Warning: There is an error on this page that may be caused by Ad Blocking software."', 500);
			}
		}
	}

	function SE_CloseAdBlockerWarning()
	{
		var expireTime = new Date();
		
		if(document.getElementById("chkAdBlockerWarning").checked)
		{
			expireTime.setTime(expireTime.getTime() + (1000 * 60 * 60 * 24 * 365));
			SE_SetCookie('HideAdBlockerWarning','yes',expireTime); 
		}
		divAlert = document.getElementById("divSE_AdBlockerWarning");
		divAlert.style.display = "none";
	}


	function SE_AdBlockerWarning(divAlert)
	{	
		if (divAlert)
		{
			divAlert.style.display = "block";
			divAlert.style.width = 400;
			divAlert.style.background = "#FFFFCC";
			
			divAlert.style.border = "black 1px solid";
			divAlert.style.padding = "10px";
			divAlert.style.color = "#000000";
		
			window.onerror = noError;
			
			return "<p align=center style=\"font-weight: bold;color:red;\">This page is experiencing a difficulty "
				+ "that may be caused by Ad Blocking software</p>"
				+ "We are unable to access a file or javascript program that is necessary to load this page or "
				+ "to perform the action you requested. This behavior is "
				+ "frequently caused by Ad Blocker software (such as Norton Internet Security). To make this page work, please "
				+ "disable Ad Blocking on this site.";
				
		}
	}	
	
	function SE_Error_HandleSpecialCases(msg)
	{
	    if (msg)
	    {
	        if (msg.indexOf("VELatLong") >= 0)
	        {
	            if (navigator.userAgent.toLowerCase().indexOf("msie") >= 0 && 
		            navigator.userAgent.match(/MSIE (\d)\./)[1] == '6') 
		                alert("We are having difficulty displaying some mapping features.\n\n"
		                    + "This sometimes happens when using back level of Microsoft Internet Explorer 6.0.\n\n"
		                    + "To resolve the problem you can \n"
		                    + " - continue without mapping features, \n"
		                    + " - upgrade to the latest release of MSIE 6.0, \n"
		                    + " - upgrade to newer version of MSIE or, \n"
		                    + " - use a different kind browser.");
	        }
	     }
	     
	}
	
	function noError ()
	{
		return true;
	}
	
	var COOKIE_PASSING_PROBLEM = 	"cookiePassingProblem"
	var SE_CookiesPassingProblem = "none";//SE_GetCookie(COOKIE_PASSING_PROBLEM); -- Brian Shamblen: Had to comment this code out because it was causing issues in production for people with popup blockers.
	if (SE_CookiesPassingProblem == "") SE_CookiesPassingProblem = "none";
	var SE_CookieTestTries = 0;
	
	function SE_CheckPopupCookies()
	{
		return SE_PopupCookiePassingProblem();
	}
	
	function SE_PopupCookiePassingProblem()
	{
		if (navigator.userAgent.toLowerCase().indexOf("msie") >= 0 && 
		    navigator.userAgent.match(/MSIE (\d)\./)[1] > 6) 
		        return "none";
		if ((SE_CookieTestTries == 0) && (!opener)) 
		{
			SE_CookieTestTries++;
			var testerWin = window.open(_SE_AdBlockTestPage, "PopupTest", "left=4000,top=4000,width=1,height=1,status=0,directories=0,location=0,scrollbars=0,resizable=0,menubar=0,toolbar=0");
			if (SE_UserAgent("gecko")) SE_Wait(100);
			var fAccessDenied = true;
			try
			{
				// even referring to the window will throw an error with certain popup/ad blockers
				var winTest = testerWin;
				fAccessDenied = false;
			}
			catch (e){}
			
			try
			{
				fAccessDenied = (fAccessDenied || (!testerWin) || (!testerWin.document));
			}
			catch(e)
			{
				fAccessDenied = true;
			}
			if (fAccessDenied)
			{
				SE_CookiesPassingProblem = "A popup blocker is preventing popup windows that are required to run this site.";
				SE_SetCookie(COOKIE_PASSING_PROBLEM, SE_CookiesPassingProblem)
				return SE_CookiesPassingProblem;
			}
			else
			{
				var passesCookiesToPopups = false;
				try
				{
					passesCookiesToPopups =
					(
						(
							SE_GetDocumentCookie(document, "ASP.NET_SessionId") &&
							(
								SE_GetDocumentCookie(testerWin.document, "ASP.NET_SessionId") == SE_GetDocumentCookie(document, "ASP.NET_SessionId")
							)
						)
						|| (testerWin.document.cookie == document.cookie)
					);
				} catch(e){}
				testerWin.close();
				testerWin = null;
				if (passesCookiesToPopups)
				{
					SE_CookiesPassingProblem = "none"
					SE_SetCookie(COOKIE_PASSING_PROBLEM, "none")
				}
				else
				{
					SE_CookiesPassingProblem = "This browser cannot pass cookies to a popup window.";
					SE_SetCookie(COOKIE_PASSING_PROBLEM, SE_CookiesPassingProblem)
				}
			}
		}
		return SE_CookiesPassingProblem;
	}	
	
    function SE_TestPopupCookiePassing(formName, divMsgBlocker, divMsgNewWindow, hdnExecuteCodeBehindClick)
	{
		// SEMI_HACK to work around Microsoft bug
		// this method is used during login or site entry to ensure that popups will retain the cookies of the opener
		// this will not be true in IE6 if the user has opened the browser from a Windows Explorer screen or shortcut
		divMsgBlocker.style.display = "none";
		divMsgNewWindow.style.display = "none";
		if(!opener)
		{
			if (SE_PopupCookiePassingProblem() != "none")
			{
				document.getElementById(formName).target="SE_Popup";
				// this will bypass the code-behind button click event 
				// so we need to pass an argument to the code behind to tell it to manually execute the click event
				hdnExecuteCodeBehindClick.value = true;
				var wOpened = window.open("", "SE_Popup", 'width=1,height=1,left=0,top=0,scrollbars=no')
				if (wOpened)
					divMsgNewWindow.style.display = "block";					
				else
					divMsgBlocker.style.display = "block";
				document.getElementById(formName).submit();
				return false;
			}
		}
		return true;
	}
	
	// ----------------- END ERROR HANDLING CODE ----------
	
	
	// -- helper functions that probably should be somewhere else
	
	var SE_HttpRequest = null;
	function SE_GetXmlHttp()
	{
		if (!SE_HttpRequest)
		{
			var xmlHttp = null;
			try{xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
			catch(e)
			{
				try	{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
				catch(exc)
				{xmlHttp = null;}
			}
			if(!xmlHttp && typeof XMLHttpRequest != "undefined")
				xmlHttp = new XMLHttpRequest();
			SE_HttpRequest = xmlHttp;
			return xmlHttp;
		}
		else
			return SE_HttpRequest;
	}
		
	function SE_GetHttpText(url)
	{
		// synchronous request
		SE_HttpRequest = SE_GetXmlHttp();
		if (SE_HttpRequest)
		{
		SE_HttpRequest.open('GET', url, false);
		SE_HttpRequest.send(null);
		return SE_HttpRequest.responseText;
		}
	}
	
	function SE_UserAgent(userAgentText)
	{
		var _userAgent = navigator.userAgent.toLowerCase();
		if (userAgentText == "msie")
			return (_userAgent.indexOf(userAgentText) != -1) && (_userAgent.indexOf('opera') == -1) ;
		else
			return _userAgent.indexOf(userAgentText) != -1;
	}
	
	function SE_GetCookie(name)
	{
		return SE_GetDocumentCookie(document, name)
	}
	function SE_GetDocumentCookie(doc, name)
	{
		var cookieName = name + "=";
		var objCookie = doc.cookie;
		var cookieStart;
		var cookieEnd;
		if(objCookie.length > 0)
		{
			cookieStart = objCookie.indexOf(cookieName);
			if(cookieStart != -1)
			{
				cookieStart += cookieName.length;
				cookieEnd = objCookie.indexOf(";",cookieStart);
				if(cookieEnd == -1)
				{
					cookieEnd = objCookie.length;
				}
				return unescape(objCookie.substring(cookieStart,cookieEnd));
			}
		}
		return null;
	}
	
	function SE_SetCookie(name, value, expires)
	{
		document.cookie = name + "=" + escape(value) + "; path=/" + 
		((expires == null) ? "" : "; expires=" + expires.toGMTString());
	}
	
	function SE_Wait(iMilliseconds)
	{
		var	dStart = new Date();
		while((new Date()) - dStart < iMilliseconds)
		{}
	}
