var xmlHttp;
var top;
var left;
var width;
var height;

function repopulate(url) {
	if (document.getElementById('newdiva')) {
		xmlHttp = GetXmlHttpObject();
		xmlHttp.onreadystatechange = fillDiv;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		document.getElementById('photoname').innerHTML = "Loading...";
		document.getElementById('photofile').innerHTML = "<div style='padding-top: 160px;'><img src='/images/loading.gif'></div>";
	}
}






function calldivbox(url) {
	if (document.getElementById('newdiva')) {
		closeDiv();
	}
	var winheight = 0;
	var winwidth = 0;
	if (typeof (window.innerHeight) == 'number') {
		winheight = window.innerHeight;
		winwidth = window.innerWidth;
	} else if (document.documentElement.clientHeight) {
		winheight = document.documentElement.clientHeight;
		winwidth = document.documentElement.clientWidth
	} else{
		winheight = document.body.clientHeight;
		winwidth = document.body.clientWidth;
	}
	var posx = 0;
	var posy = 0;
	if (typeof (window.pageXOffset) =='number') {
		posx = window.pageXOffset;
		posy = window.pageYOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		posx = document.body.scrollLeft;
		posy = document.body.scrollTop;
	} else{
		posx = document.documentElement.scrollLeft;
		posy = document.documentElement.scrollTop;
	}
	top = (winheight-700)/2 + posy;
	left = (winwidth-770)/2 + posx;
	if (left<0) {
		left = 0;
	}
	height = 700;
	width = 770;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	xmlHttp.onreadystatechange = fillDiv;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	var backleft = left-10;
	var backtop = top-10;
	var backwidth = width+20;
	var backheight = height+20;
	
	// 'contents' contains the contents of the popup div before it is populated by the script called by 'url'.
	// It should generally be a loading screen.
	var contents = "<div style='margin: 5px;'><div style='font-family: arial; font-size: 12pt; font-weight: bold; height: 30px; overflow: hidden;'><div style='float: right; margin-top: 4px;'><span id='closebutton' class='button' onclick='closeDiv()'>&nbsp;</span></div></div><div style='padding-top: 7px;'></div></div></div>";
	
	// The div 'bodyenclose' encloses the entire site, as the name suggests. This line dims the screen.
	// If you remove this, you must also remove it from closeDiv().
	document.getElementById('bodyenclose').style.cssText = 'opacity: .5; filter: alpha(opacity=50); height: 100%; width: 100%;';
	
	// 'backdiv' provides a translucent border around the popup.
	// If you remove it, you must also remove it from closeDiv().
//	var backdiv = document.createElement("div");
//	backdiv.style.cssText = 'width: ' + backwidth + '; height: ' + backheight + '; background-color: #000099; position: absolute; top: ' + backtop + '; left: ' + backleft + '; opacity: .50; filter: alpha(opacity=50); float: left;';
//	backdiv.setAttribute('id', 'newdivb');
//	document.body.appendChild(backdiv);
	
	// 'newdiv' is the actual popup.
	var newdiv = document.createElement("div");
	newdiv.innerHTML = contents;
	newdiv.style.cssText = 'border: 1px solid #000000; position: absolute; top: ' + top + "; left: " + left + "; width: " + width + "; height: " + height + "; opacity: 1; filter: alpha(opacity=100); z-index: 1000; background-color: white;";
	newdiv.setAttribute('id', 'newdiva');
	document.body.appendChild(newdiv);
}





function fillDiv() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById('newdiva').innerHTML = xmlHttp.responseText;
	} 
}





function closeDiv() {
	var div1 = document.getElementById("newdiva");
//	var div2 = document.getElementById("newdivb");
	document.body.removeChild(div1);
//	document.body.removeChild(div2);
	document.getElementById('bodyenclose').style.cssText = '';
}





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;
}