// JavaScript Document
// Author:			Digital dialects (www.digitaldialects.co.za)
// Date Created:	27 July 2004
// Last Updated:	29 August 2005
// Description:		Opens a window to display an image of an unknown resolution.
var imageFile = '';
var imageWidth = 0;
var imageHeight = 0;
var imageName = '';
var textCellHeight = 0;
var windowHeight = 0;
var imageWindow;
var windowOpen = false;
var hBuffer = 35;
var wBuffer = 10;

function openImage(imageFile, imageWidth, imageHeight, imageDescription, windowName) {
	
	if(document.all) {
	imageHeight = parseInt(imageHeight) + hBuffer;
	imageWidth = parseInt(imageWidth) + wBuffer;
	}
	//windowHeight = imageHeight  + textCellHeight;
	left = (imageWidth - 168)/2;
	upper = (imageHeight - 30)/2;
	
	var xLeft = (screen.width / 2) - (imageWidth / 2)
	var yTop = (screen.height / 2) - (imageHeight / 2)
	//infoWindow = window.open('', 'DDBC', 'width='+imageWidth+',height='+imageHeight+',toolbar=no,location=no,status=no,menubar=no,resizable=0,top='+yTop+',left='+xLeft+'');
	//infoWindow.document.location = imageFile;
	
	imageWindow = window.open('', 'DDBC', 'width=0,height=0,resizable=0,top=0,left=0,status=no,top=0,left='+xLeft+'');
	//imageWindow = window.open('', 'DDBC', 'resizable=0,top=0,left=0,status=no');
	imageWindow.resizeTo(imageWidth, imageHeight);
	imageWindow.innerWidth = imageWidth;
	imageWindow.innerHeight = imageHeight;
	imageWindow.focus();
	
	imageWindow.document.open();
	imageWindow.document.writeln('<html>');
	imageWindow.document.writeln('<head>');
	imageWindow.document.write('<title>');
	imageWindow.document.write(imageDescription); // + ' - ' + (imageWidth - wBuffer) + 'x' + (imageHeight - hBuffer) + ' - ' + windowName);
	imageWindow.document.writeln('</title>');
	imageWindow.document.writeln('<meta http-equiv="pragma" content="no-cache">');
	imageWindow.document.writeln('</head>');
	imageWindow.document.writeln('<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" bgcolor="">');
	imageWindow.document.writeln('<div id="loader" style="position:absolute;left:' + left + 'px; top:' + upper + 'px;z-index:1">');
	imageWindow.document.writeln('Please wait for the picture.');
  	imageWindow.document.writeln('</div >');
	imageWindow.document.writeln('<table align="center" border="0" cellpadding="0" cellspacing="0">');
	imageWindow.document.writeln('<tr>');
	imageWindow.document.writeln('<td>');
	imageWindow.document.writeln('<div id="image" style="position:absolute;left:0px;top:0px;z-index:2">');
	imageWindow.document.writeln('<img alt="' + imageFile + '" title="' + imageDescription + '" src="' + imageFile + '">');
	imageWindow.document.writeln('</div >');
	imageWindow.document.writeln('</td>');
	imageWindow.document.writeln('</tr>');
	imageWindow.document.writeln('</table>');
	imageWindow.document.writeln('</body>');
	imageWindow.document.writeln('</html>');
	imageWindow.document.close();
}

function openWin(page, winName, xWidth, yHeight) {

	var xLeft = (screen.width / 2) - (xWidth / 2)
	var yTop = (screen.height / 2) - (yHeight / 2)
	if(screen.height < yHeight)
	{
		yHeight = screen.height - 60;
	}
	
	//infoWindow = window.open('', winName, 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=0,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
	//infoWindow = window.open('', 'DDBC', 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,resizable=0,top=0,left=0');
	//infoWindow.document.location = page;
	//infoWindow.focus();
	window.open(page,winName,'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
}

function openWinMid(page, winName, xWidth, yHeight) {

	var xLeft = (screen.width / 2) - (xWidth / 2)
	var yTop = (screen.height / 2) - (yHeight / 2)
	if(screen.height < yHeight)
	{
		yHeight = screen.height - 60;
	}
	
	//infoWindow = window.open('', winName, 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=0,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
	//infoWindow = window.open('', 'DDBC', 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,resizable=0,top=0,left=0');
	//infoWindow.document.location = page;
	//infoWindow.focus();
	window.open(page,winName,'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,screenX='+yTop+',top='+yTop+',screenY='+xLeft+',left='+xLeft+'');
}

function SizeToFit()
       {
        window.setTimeout(
            function()
            {
            if (document.body.scrollHeight > screen.height)
            {
				switch(screen.height)
				{
				case 600:
				window.resizeTo((document.body.scrollWidth + 20), 565);
				break;
				case 768:
				window.resizeTo((document.body.scrollWidth + 20), 733);
				break;
				default:
				window.resizeTo((document.body.scrollWidth + 20), (document.body.scrollHeight + 67));
				}
			} else
			{
			if (navigator.appVersion.indexOf('MSIE 7.0') > 0) {
			window.resizeTo((document.body.scrollWidth + 20), (document.body.scrollHeight + 87));
			}
			else {
			window.resizeTo((document.body.scrollWidth + 20), (document.body.scrollHeight + 67));
			}
			}
			}, 400);
       }

function openSermon(page, winName, xWidth, yHeight) {
	var xLeft = (screen.width / 2) - (xWidth / 2)
	var yTop = (screen.height / 2) - (yHeight / 2)
	//infoWindow = window.open('', winName, 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=0,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
	//infoWindow = window.open('', 'DDBC', 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,resizable=0,top=0,left=0');
	//infoWindow.document.location = page;
	//infoWindow.focus();
	window.open(page,winName,'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
}

function openToolWin(page, winName, xWidth, yHeight) {
	var xLeft = (screen.width / 2) - (xWidth / 2)
	var yTop = (screen.height / 2) - (yHeight / 2)
	if(screen.height < 1024)
	{
		yHeight = screen.height - 60;
	}
	//infoWindow = window.open('', winName, 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=0,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
	//infoWindow = window.open('', 'DDBC', 'width='+xWidth+',height='+yHeight+',toolbar=no,location=no,status=no,menubar=no,resizable=0,top=0,left=0');
	//infoWindow.document.location = page;
	//infoWindow.focus();
	window.open(page,winName,'width='+xWidth+',height='+yHeight+',toolbar=yes,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,screenX=0,top=0,screenY='+xLeft+',left='+xLeft+'');
}

function thankYou(sermonNum, sermonType) {
	window.location ='sermonConfirm.aspx?sNum=' + sermonNum + '&sType=' + sermonType + '&reqPage=2';
	}