    var oldXHR = window.XMLHttpRequest;
    function newXHR() {
        var realXHR = new oldXHR();viewloading();realXHR.addEventListener("readystatechange", function() {
			viewloading();
            if(realXHR.readyState==4 && realXHR.status==200){setTimeout("hideloading()", 500);}
            if(realXHR.status == 0 ){hideloading();if(realXHR.responseText == "" && realXHR.readyState == 4){setTimeout("hideloading()", 500);}}
            if(realXHR.status == 502){
				//alert(window.location.href);
				var strUrl = window.location.href;
				var strPort = "/";
				if (strUrl.indexOf(strPort) != -1) {
					var index = strUrl.indexOf(strPort, 10); // from position 10
					//alert(index);
					//alert(strUrl.substring(0,index));
					var homePage = strUrl.substring(0,index);
					window.location.href = homePage.concat("/50x.html");
				}
			}
			if(realXHR.status >= 400){setTimeout("hideloading()", 500);}
			if(realXHR.readyState==4 && realXHR.status==0) {
				hideloading();
			}

        }, false);return realXHR;}
    window.XMLHttpRequest = newXHR;
    function viewloading(){document.getElementById("loading").style.display = 'block';}
    function hideloading(){document.getElementById("loading").style.display = 'none';}
	
	
		/*
		readyState
			0: request not initialized 
			1: server connection established
			2: request received 
			3: processing request 
			4: request finished and response is ready
			
		status	
			200: "OK"
			404: Page not found
			500: Internal Server Error
			400: Bad Request
			
	*/