
/*
 * This will act as a reference for the current request.
 */
var currentRequest;

/*
 * data buffer
 */
var data;

/*
 * This function will be used to inject the scraped value of a page
 */
function injectPage(url, sourceDiv) {
}


/*
 * This function resolves an XMLHttpRequest object irrespective of browser.
 */
function getRequest(){

   if (window.XMLHttpRequest) {
      //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
      return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      return new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      return null;
   }

}


/*
 * This performs the actual functionality to create a request
 */
function makeRequest(url, contentType, method, dataToSend) {
   currentRequest = getRequest();
   if (contentType == null || contentType == "")
      contentType = "text/html";
   if (method == null || method == "")
      method = "GET";
   //open the request
   currentRequest.open(method, url);
   currentRequest.setRequestHeader('content-type', contentType);

   //set the handler
   currentRequest.onreadystatechange = defaultHandler;

   //send data if the request is not a GET
   if (method != 'GET' && (dataToSend != null || dataToSend != ""))
      currentRequest.send(dataToSend);
   else
      currentRequest.send(null);

}

/*
 * Performs a GET to look up a URL
 */
function getHTML(url) {
   makeRequest(url, null, null, null);
}


/*
 * Performs a GET to look up a URL
 */
function postHTML(url, postData) {
   makeRequest(url,  null, "POST", postData);
}

/*
 * Performs a GET to look up a URL
 */
function getXML(url) {
   makeRequest(url,"text/xml", null, null);
}


/*
 * Performs a GET to look up a URL
 */
function postXML(url, postData) {
   makeRequest(url, "text/xml", "POST", postData);
}




/*
 * Default handler
 */
function defaultHandler() {

   if (currentRequest.readyState == 0) {

   } else if (currentRequest.readyState == 1) {
      try {
         stillBusy();
      } catch (e) {
         alert(e.name+" -> "+e.message+" you probably do not have the stillBusy() function defined");
      }
   } else if (currentRequest.readyState == 2) {
      try {
         onComplete("done");
      } catch (e) {
         alert(e.name+" -> "+e.message+" you probably do not have the onComplete(data) function defined");
      }
   }



//   if (currentRequest.status == 200 && currentRequest.readyState == 4) {
   if (currentRequest.readyState == 4) {
      var data = currentRequest.responseText;
      try {
         //gotData
         gotData(data);
      } catch (e) {
         alert(e.name+" -> "+e.message+" you probably do not have the gotData(data) function defined");
      }
   }

}


      function gotData(data) {
         divVal = document.getElementById("insertDiv");
         divVal.innerHTML = data;
         fadeWidth = 629;
         fadingNow = false;
         document.getElementById("fading").style.width = ""+fadeWidth+"px";
         setTimeout("makeVisible()", 12000);  // in case the < img > tag onload event is not triggered
      }


function makeVisible() {
      if (fadeWidth != 0 && !(fadingNow)) {
         fadingNow = true; 
         //document.getElementById("fading").innerHTML = '<img src="/images/loaded.gif" border="0" style="width:629px; height: 292px; ">';
         document.getElementById("fading").style.display = 'block';
         document.getElementById("progress").innerHTML = "";
         document.getElementById("insertDiv").style.display = 'block';
         setTimeout("fadeAway()", 100);
      }
}

function fadeAway() {
         fadeWidth = fadeWidth - 30; 
         if (fadeWidth > 0) {
            document.getElementById("fading").style.width = ""+fadeWidth+"px";
            setTimeout("fadeAway()", 10);
         } else {
            fadeWidth = 0;
            document.getElementById("fading").style.width = ""+fadeWidth+"px";
            document.getElementById("fading").style.display = 'none';
         }
}


      function stillBusy(){
//         document.getElementById("progress").innerHTML = "Loading...";
      }

      function onComplete(info){
         //document.getElementById("progress").innerHTML = "finished!";
         //document.getElementById("progress").innerHTML = "";
      }

      function load(url) {
         
         document.getElementById("insertDiv").innerHTML = "";
         document.getElementById("fading").style.display = 'none';
         document.getElementById("insertDiv").style.display = 'none';
//         document.getElementById("progress").innerHTML = "";
         document.getElementById("progress").innerHTML = '<img src="/images/loading.gif" width="32" height="32" border="0" style="margin: 130px 0 0 300px; ">';
         remoteURLFile = "getLargeImage.pl";
         getHTML(url);
      }

function arbFunction() {
   alert("Some Arb function");
}
