var http = getHTTPObject(); // We create the HTTP Object
var url='/servlet/getStatus';
var isSearching = false;
var stopRefresh = false;
var statusWidth = 300;
var statusHeight = 150;
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status==404) {
alert("Page not found!");
window.location = 'http://www.google.com';
}
if (http.status==200) {
statusBox = document.getElementById("statusDiv");
statusMsg = http.responseXML.getElementsByTagName("status")[0];
if (statusMsg) {
statusCode = statusMsg.getElementsByTagName("statusCode")[0].firstChild.nodeValue;
if (typeof statusMsg.getElementsByTagName("statusMsg")[0] != 'undefined') {
statusString = statusMsg.getElementsByTagName("statusMsg")[0].firstChild.nodeValue;
} else {
statusString = '';
}
if (statusString.length>100) {
statusString = statusString.substring(0,97)+"...";
}
statusOriginalString = statusMsg.getElementsByTagName("statusOriginalMsg")[0].firstChild.nodeValue;
if (statusOriginalString!="...") {
statusOriginalString="("+statusOriginalString+")";
} else {
statusOriginalString="";
}
statusCompletion = statusMsg.getElementsByTagName("statusCompletion")[0].firstChild.nodeValue;
statusBox.innerHTML="
"+statusString+"
"+statusOriginalString+
"
";
if (statusCompletion==100) {
stopRefresh = true;
setTimeout("reloadPage()",1500);
}
}
isSearching = false;
}
}
}
function reloadPage() {
currentPage = window.location.href;
window.location.href = currentPage;
}
function createStatus() {
pageSize = getPageSize();
var objBody = document.getElementsByTagName("body").item(0);
// create overlay div
var objOverlay = document.createElement("div");
objOverlay.setAttribute('id','boxOverlay');
objOverlay.style.display = 'none';
objOverlay.style.position = 'absolute';
objOverlay.style.width = pageSize[0];
objOverlay.style.height = pageSize[1];
objOverlay.style.top = '0';
objOverlay.style.left = '0';
objOverlay.style.zIndex = '90';
objOverlay.style.backgroundColor = '#000000';
objOverlay.style.opacity = '.25';
objOverlay.style.filter = 'alpha(opacity=25)';
objBody.insertBefore(objOverlay, objBody.firstChild);
objOverlay.style.display = 'block';
objOverlay.style.visibility = 'visible';
statusBox = document.createElement("div");
statusBox.setAttribute('id','statusDiv');
statusBox.style.display="none";
objBody.insertBefore(statusBox, objBody.firstChild);
// width and height are global variables
statusBox.style.zIndex = '100';
statusBox.style.width = statusWidth;
statusBox.style.height = statusHeight;
statusBox.style.backgroundColor="white";
statusBox.style.position = 'absolute';
statusBox.style.padding = 0;
statusBox.style.border = "3px solid #000000";
posX = (pageSize[0]-statusWidth)/2;
posY = (pageSize[1]-statusHeight)/2;
statusBox.style.left=posX;
statusBox.style.top=posY;
statusBox.style.display="block";
if (window.innerHeight) {
window.captureEvents(Event.RESIZE);
}
window.onresize = adaptWindow;
fillData();
}
function adaptWindow() {
objOverlay = document.getElementById('boxOverlay');
pageSize = getPageSize();
objOverlay.style.width = pageSize[0];
objOverlay.style.height = pageSize[1];
statusBox = document.getElementById('statusDiv');
posX = (pageSize[0]-statusWidth)/2;
posY = (pageSize[1]-statusHeight)/2;
statusBox.style.width = statusWidth;
statusBox.style.height = statusHeight;
statusBox.style.left=posX;
statusBox.style.top=posY;
}
// Core code from - quirksmode.org
function getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
function fillData() {
if (!isSearching) {
var urlFinal = url+"?ts="+(new Date()).getTime();
http.open("GET", urlFinal, true);
isSearching = true;
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
if (!stopRefresh) {
setTimeout("fillData()", 1000); // wait (in milliseconds) for next refresh
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
} return xmlhttp;
}