function createRequestObject() 
{
 var req;
 if(window.XMLHttpRequest)
 {
  // Firefox, Safari, Opera...
  req = new XMLHttpRequest();
 }
 else if(window.ActiveXObject) 
 {
  // Internet Explorer 5+
  req = new ActiveXObject("Microsoft.XMLHTTP");
 } 
 else 
 {
  // There is an error creating the object,
  // just as an old browser is being used.
  alert('There was a problem creating the XMLHttpRequest object');
 }
 return req;
}

// Make the XMLHttpRequest object
var http = createRequestObject();


function sendRequestPost(id, url, variable, div) 
{
 // Open PHP script for requests
 globaldiv = div;
 http.open('post', url);
 http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 http.onreadystatechange = handleResponsePost;
 http.send(variable+'='+id);
}


function handleResponsePost() 
{
 if (http.readyState == 4 && http.status == 200)
 {
  // Text returned from PHP script
  var response = http.responseText;
  if(response) 
  {
   // Update ajaxTest2 content
   document.getElementById(globaldiv).innerHTML = response;
  }
 }
}






function displayimage(id)
{
  sendRequestPost(id, "camgallery/imageprocess.php", "id", "imagebox")
}


function preloadimage(id)
{
getmargins()
imageheight = 300
topmargin = (windowheight - imageheight) / 2
imagetopmargin = scroll + topmargin;
document.getElementById("imagebox").style.top = imagetopmargin-50+"px";

imagetopmargin = scroll + topmargin;  sendRequestPost(id, "camgallery/imageload.php", "id", "imagebox")  
}




function resizeimage()
{

getmargins()
 
imagewidth = document.getElementById("imagereplace").width
imageheight = document.getElementById("imagereplace").height
leftmargin = imagewidth / -2
topmargin = (windowheight - imageheight) / 2
imagetopmargin = scroll + topmargin;

document.getElementById("imagebox").style.width = imagewidth+76+"px";
document.getElementById("center").style.width = imagewidth+20+"px";
document.getElementById("caption").style.width = imagewidth+10+"px";
document.getElementById("imagebox").style.top = imagetopmargin-50+"px";
document.getElementById("imagebox").style.marginLeft = leftmargin-28+"px";

document.getElementById("imagebox").style.visibility = "visible";
document.getElementById("imagereplace").style.visibility = "visible";

  
}  

function getmargins()
{
scroll = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scroll = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scroll = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scroll = document.documentElement.scrollTop;
  }
  
windowheight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    windowheight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowheight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    windowheight = document.body.clientHeight;
  } 

}


function hideimage()
{

getmargins();

imageheight = 300
topmargin = (windowheight - imageheight) / 2
imagetopmargin = scroll + topmargin;

document.getElementById("imagebox").style.width = "378px";
document.getElementById("center").style.width = "322px";
document.getElementById("imagebox").style.top = imagetopmargin-50+"px";
document.getElementById("imagebox").style.marginLeft = "-175px";
document.getElementById("imagebox").innerHTML = "";

}