/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
        var request_o; //declare the variable to hold the object.
        var browser = navigator.appName; //find the browser name
        if(browser == "Microsoft Internet Explorer"){
                /* Create the object using MSIE's method */
                request_o = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
                /* Create the object using other browser's method */
                request_o = new XMLHttpRequest();
        }
        return request_o; //return the object
}

/* You can get more specific with version information by using
        parseInt(navigator.appVersion)
        Which will extract an integer value containing the version
        of the browser being used.
*/

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject();
var counter=1;
var piccounter=2;


function RefreshBox() {
        /* Create the request. The first argument to the open function is the method (POST/GET),
                and the second argument is the url...
                document contains references to all items on the page
                We can reference document.form_category_select.select_category_select and we will
                be referencing the dropdown list. The selectedIndex property will give us the
                index of the selected item.
        */
        url = 'getnewcontent.php?counter=' + counter;
        http.open('get', url);
        /* Define a function to call once a response has been received. This will be our
                handleNumSent function that we define below. */
        http.onreadystatechange = function() {
          if(http.readyState == 4){ //Finished loading the response
                /* We have got the response from the server-side script,
                        let's see just what it was. using the responseText property of
                        the XMLHttpRequest object. */
                var response = http.responseText;
                var response_array=response.split(":");
             
                if ( document.getElementById('docbox') ) {
                  document.getElementById('docbox').innerHTML = response_array[0];
                  /* update the picture */
                  /*document.getElementById('docimage').innerHTML = '<img src="http://www.ratemyhospital.ie/images/doc_box_pic1_0' + piccounter + '.gif">';*/
                  url = '"http://www.ratemyhospital.ie/images/doc_box_pic1_0' + piccounter + '.gif"';
                  document.getElementById('docimage').style.backgroundImage = 'url(' + url + ')';

                }
               
                func="RefreshBox()";
                counter++;
                piccounter++;
                if ( counter > 11 ) {
                  counter = 0;
                }
                if ( piccounter > 5 ) {
                  piccounter = 1;
                }
                window.setTimeout( func, 5000 );
           }
        }
          
        /* Send the data. We use something other than null when we are sending using the POST
                method. */
        http.send(null);
}




function init() {
  func="RefreshBox()";
  window.setTimeout( func, 10000 );
}



// some function already defined in events.js

var http3 = createRequestObject(); 

/* Function called to get the activity categories list */
function getLocalHospitals(){
          http3.open('get', '/hospital/get_local_hospitals.php');
          /* Define a function to call once a response has been received. This will be our
                  showLocalHospitals function that we define below. */
          http3.onreadystatechange = refreshLocalHospitals;
          /* Send the data. We use something other than null when we are sending using the POST
                  method. */
          try {
            http3.send(null);
          } catch(e) {}
}

function refreshLocalHospitals(){
        /* Make sure that the transaction has finished. The XMLHttpRequest object
                has a property called readyState with several states:
                0: Uninitialized
                1: Loading
                2: Loaded
                3: Interactive
                4: Finished */
        if(http3.readyState == 4){ //Finished loading the response
                /* We have got the response from the server-side script,
                        let's see just what it was. using the responseText property of
                        the XMLHttpRequest object. */
                var response = http3.responseText;
                /* And now we want to change the product_categories <div> content.
                        we do this using an ability to get/change the content of a page element
                        that we can find: innerHTML. */
                document.getElementById('local_hospitals').innerHTML = response;
        }
}



function showLocalHospitals(e) {
     if (browser.isIE) {
       x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
       y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
     }
     if (browser.isNS) {
       x = e.clientX + window.scrollX;
       y = e.clientY + window.scrollY;
     }
     x += 10;
     document.getElementById('local_hospitals').style.visibility = "visible";
     document.getElementById('local_hospitals').style.left = x + "px";
     document.getElementById('local_hospitals').style.top = y + "px";
     getLocalHospitals();
     /* close the popup after a number of seconds 
     window.setTimeout("hideLocalHospitals()", 10000); */

}

function hideLocalHospitals() {
    document.getElementById('local_hospitals').style.visibility = "hidden";

}

