// /javascript/tools.js
var xmlHttp;
var responseDivHolder;
var responseTextHolder;
//-----------------------------
function showDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="visible";
	document.getElementById(boxid).style.display="block";
}
//-----------------------------
function hideDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="hidden";
	document.getElementById(boxid).style.display="none";
}
//-----------------------------
function toggleHideDiv(boxid){
	// if clicked, show if hidden, hide if visible
	if(!document.getElementById(boxid)) return;
	var boxStyle = document.getElementById(boxid).style; 
	if(boxStyle.visibility == "hidden" || boxStyle.display == "none"){
		boxStyle.visibility ="visible";
		boxStyle.display = "block";
	}
	else{
		boxStyle.visibility ="hidden";
		boxStyle.display = "none";
	}
}
//-----------------------------
function swapOutImage(imageName){
	document.body.style.cursor = 'wait';
	document.getElementById('mainImage').src='/photodatabase/thumbs/' + imageName;
	document.getElementById('mainImage').src='/photodatabase/' + imageName;
	//document.getElementById('mainImage').onload = function { document.body.style.cursor = "default"; }
	document.body.style.cursor = "default";
}
//-----------------------------
function showBurner(burnerFilename){
	document.getElementById('burnerZoomImage').src = "images/loading.gif";
	myBurnerImage = new Image();
	myBurnerImage.src = "burner_images/" + burnerFilename;
	myBurnerImage.onload = function(){ document.getElementById('burnerZoomImage').src = myBurnerImage.src; }
	showDiv('burnerZoom');
	document.getElementById('searchFilterForm').style.display = "none";
	return false;
}
//-----------------------------
function showVirtualPopUp(srcOfPopUp,popUpWidth,popUpHeight){
	hideDiv('virtualPopUp');
	var windowWidth = window.document.body.clientWidth;
	if (srcOfPopUp.length>1){
		document.getElementById('virtualPopUpFrame').src = srcOfPopUp;
		styleForPopUp = document.getElementById('virtualPopUp').style;
		styleForPopUp.background = "#000000";
		styleForPopUp.color = "#ffffff";
		styleForPopUp.width = popUpWidth + 'px';
		styleForPopUp.height = popUpHeight + 'px';
		styleForPopUp.marginLeft = (windowWidth-popUpWidth)/2 + 'px';
		styleForPopUp.position = 'fixed';
	}
	else{
		alert('no source');
	}
}
//-----------------------------
function unHideVirtualPopUp(){
	if(document.getElementById('virtualPopUpFrame').src.length){
		showDiv('virtualPopUp');
	}
	else{
		hideDiv('virtualPopUp');
	}
}
//-----------------------------
function printPage(){
	if (document.getElementById != null){
		var html = '<html>\n<head>\n';
		if (document.getElementsByTagName != null){
			//var headTags = document.getElementsByTagName("head");
			//if (headTags.length > 0) html += headTags[0].innerHTML;
		}
		html += '\n</he' + 'ad>\n<body>\n';
		var contentElem = document.getElementById("content");
		if (contentElem != null){
			html += contentElem.innerHTML;
		}
		else{
			alert("Could not find the content section in the HTML");
			return;
		}
		html += '\n</bo' + 'dy>\n</ht' + 'ml>';
		var printWin = window.open("","printPage");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		printWin.print();
	}
	else{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}

}
//-----------------------------
function deleteImage(imageName,sn){
	if(confirm('Really delete this image?')){
		getResponse('database-application.php?doAction=deleteImage&image=' + imageName + '&sn=' + sn);
	}
}
//------------------------------
function setStatus(theMessage){
	document.getElementById("statusReport").setAttribute("title", theMessage )
}
//------------------------------
function deleteUser(userId){
	// hide userRow(userId)
	hideDiv('userRow' + userId);
	// send delete command to server
	getResponse('database-application.php?doAction=deleteUser&userId=' + userId,"hiddenMessages");
}
//------------------------------

