var xmlHttp;
var contentHandler = new TagHandler(null);

function nextPicturePage(albumID, page, locationID, backLink) {
    page = page+1;

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("This website uses AJAX. Javscript must be enabled!");
        return;
    }

    xmlHttp.open('POST', 'php/changePhotoPage.php', true);
    xmlHttp.onreadystatechange=stateChanged;
    contentHandler.tagName = 'albumPane';
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('albumID=' + albumID + '&page=' + page + '&locationID=' + locationID + '&backLink=' + backLink);
}

function previousPicturePage(albumID, page, locationID, backLink) {
   
    page = page-1;

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("This website uses AJAX. Javscript must be enabled!");
        return;
    }

    xmlHttp.open('POST', 'php/changePhotoPage.php', true);
    xmlHttp.onreadystatechange=stateChanged;
    contentHandler.tagName = 'albumPane';
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('albumID=' + albumID + '&page=' + page + '&locationID=' + locationID + '&backLink=' + backLink);
}

function goToPicturePage(albumID, page, locationID, backLink) {
   
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("This website uses AJAX. Javscript must be enabled!");
        return;
    }

    xmlHttp.open('POST', 'php/changePhotoPage.php', true);
    xmlHttp.onreadystatechange=stateChanged;
    contentHandler.tagName = 'albumPane';
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('albumID=' + albumID + '&page=' + page + '&locationID=' + locationID + '&backLink=' + backLink);
}

function deletePicture(photoID, albumID, page) {
    
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("This website uses AJAX. Javscript must be enabled!");
        return;
    }

    xmlHttp.open('POST', 'php/deletePhoto.php', true);
    xmlHttp.onreadystatechange=stateChanged;
    contentHandler.tagName = 'albumPane';
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send('photoID=' + photoID + '&albumID=' + albumID + '&page=' + page);
}

function TagHandler(tagName)
{
   var tagName;
   return tagName;
}

function stateChanged() { 

    if (xmlHttp.readyState==4) { 
        document.getElementById(contentHandler.tagName).innerHTML=xmlHttp.responseText;
    }
}

function GetXmlHttpObject() {

    var xmlHttp=null;

    try {
    // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

