//***********************************************
// Author        : Andrew Will
// Modified      : 3/2/2002
// Depencencies  : tcbc.js
//                 vars: - browserName
// Functionality : (1) Opens up a seperate window
//                     with a Bible passage.
//                 (2) Resizes current window and
//                     opens another next to it
//                     with a Bible passage.
//***********************************************

hExtra = 0;
vExtra = 0;
hMultiplier = 0;
vMultiplier = 0;
hMultiplierWin = 0;


function resizeContentWindow() {

	if (screen.availWidth > 1280 || screen.availHeight > 1024) {
		hExtra = screen.availWidth - 1280;
		vExtra = screen.availHeight - 1024;
	}

	top.window.moveTo(hExtra, vExtra);

	// 1280 x 1024 or 1024 x 768 resolution
	if (hExtra == 0) {
		hMultiplier = screen.availWidth;
		vMultiplier = screen.availHeight;
	}
	else {	// bigger resolutions
		hMultiplier = 1280;
		vMultiplier = 1024;
	}

	hMultiplierWin = parseInt(0.52*hMultiplier);

	// IE
	if (browserName == "IE") {
		top.window.resizeTo(hMultiplierWin, vMultiplier);
	}
	// NS
	else if (document.layers || document.getElementById) {
		if (top.window.outerHeight != vMultiplier  ||
				top.window.outerWidth != hMultiplierWin ) {
			top.window.outerHeight = vMultiplier;
			top.window.outerWidth  = hMultiplierWin;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////

function openPassage( /* int */ book,
					  /* int */ chapter ) {

	var url = "/bible/passage.jsp?book=" + book + "&chapter=" + chapter;

	defaultPopUp(url, 650, 550);
}

function defaultPopUp( /* int */ url,
					   /* int */ width,
					   /* int */ height ) {

	var winLeft = (screen.width - width) / 2;
	var winTop  = (screen.height - height) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	var popUpWindow = window.open(url,
			'win'+parseInt(Math.random()*1000),
			'toolbar=0,location=0,scrollbars=1,directories=0,status=1,menubar=0,resizable=1,width='+ width +',height=' + height + ',top=' + winTop + ',left=' + winLeft );	

}

///////////////////////////////////////////////////////////////////////////////

function openBibleStudy( /* String */ passages ) {

// window is too small
//	if (screen.availWidth <= 800 || screen.availHeight <= 600) {
		openBible(passages);
//	}
//	else {
//		resizeContentWindow();
//		openBiblePassage(passages);
//	}
}

function openBiblePassage( /* String */ passages ) {

	// replace all " " with "+"
	while (passages.indexOf(" ") != -1) {
		passages = passages.replace(" ", "+");
	}

	var pUrl = "http://bible.gospelcom.net/bible?passage=" + passages + "&language=english&version=KJV";


	var winLeft = hExtra + hMultiplierWin + 1;
	var winTop  = vExtra;

	var popUpWindow = window.open( pUrl,
			'verseWin',
			'toolbar=0,location=0,scrollbars=1,directories=0,status=1,menubar=0,resizable=1,width='+ (0.45*hMultiplier) +',height=' + (0.9*vMultiplier) + ',top=' + winTop + ',left=' + winLeft );
}

function openBible( /* String */ passages ) {

	// replace all " " with "+"
	while (passages.indexOf(" ") != -1) {
		passages = passages.replace(" ", "+");
	}

	var pUrl = "http://bible.gospelcom.net/bible?passage=" + passages + "&language=english&version=KJV";


	var winLeft = (screen.width - 650) / 2;
	var winTop  = (screen.height - 550) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	var popUpWindow = window.open( pUrl,
			'verse'+parseInt(Math.random()*100),
			'toolbar=0,location=0,scrollbars=1,directories=0,status=1,menubar=0,resizable=1,width='+ 650 +',height=' + 550 + ',top=' + winTop + ',left=' + winLeft );	
}