function DOMCall(name) {
    if (document.getElementById)
        return document.getElementById(name);
     else if (document.all)
        return document.all[name];
    else if (document.layers)
        return document.layers[name];
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest(); //Not IE
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP"); //IE
    } else {
        //Display your error message here. 
        //and inform the user they might want to upgrade
        //their browser.
        //alert("Your browser doesn't support the AJAX requests.");
        return null;
    }
}            
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();        

    
//Initiate the asyncronous request.
function loadPhotoSet(s) {
    if (receiveReq != null){
        //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
        if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
            //Setup the connection as a GET call to SayHello.html.
            //True explicity sets the request to asyncronous (default).
            receiveReq.open("GET", 'photos.php?ajax=1&s='+s, true);
            //Set the function that will be called when the XmlHttpRequest objects state changes.
            receiveReq.onreadystatechange = handlePicturePageResult; 
            //Make the actual request.
            receiveReq.send(null);
        }
    } else {
        location.replace("index.php?p=photos&s="+s);
    }
}
function loadVideo(v) {
    if (receiveReq != null){
        //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
        if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
            //Setup the connection as a GET call to SayHello.html.
            //True explicity sets the request to asyncronous (default).
            receiveReq.open("GET", 'video.php?v='+v, true);
            //Set the function that will be called when the XmlHttpRequest objects state changes.
            receiveReq.onreadystatechange = handleSearchResult; 
            //Make the actual request.
            receiveReq.send(null);
        }
    } else {
        location.replace("index.php?v="+v);
    }
}
//Called every time our XmlHttpRequest objects state changes.
function handleSearchResult() {
    //Check to see if the XmlHttpRequests state is finished.
    if (receiveReq.readyState == 4) {
        //Set the contents of our span element to the result of the asyncronous call.
        oObj = DOMCall('content');
        oObj.innerHTML = receiveReq.responseText;
    }
}
//Called every time our XmlHttpRequest objects state changes.
function handlePicturePageResult() {
    //Check to see if the XmlHttpRequests state is finished.
    if (receiveReq.readyState == 4) {
        //Set the contents of our span element to the result of the asyncronous call.
        oObj = DOMCall('contentPictures');
        oObj.innerHTML = receiveReq.responseText;
    }
}

