// Script for the BNC index page (top page with navigation and containig the bottom iframe)

var lastSearch = new Array();
lastSearch.q1 = ''
lastSearch.op2 = 'en'
lastSearch.q2 = ''
lastSearch.op3 = 'en'
lastSearch.q3 = ''
lastSearch.rgn = 'all'
lastSearch.book = 'all'
lastSearch.field = 'images'



// onLoad event handler
function doLoad() {
	if (typeof(bncjsloaded) != 'undefined') {
		resizeBottomFrame()
		window.onresize = resizeBottomFrame
	}
}

function doOnClickAdvancedSearch(a) {
	var href = a.getAttribute('href')
	if (lastSearch.q1 != '') {
		href += ';q1=' + encodeURIComponent(lastSearch.q1);
	}
	bottomFrame.rightFrame.location = href;
}

function doResizeIFrames() {
	var iFrameHeight = getWindowHeight()
	if (iFrameHeight > 0) {
		var frame = document.getElementById('idTopFrame')
		if (frame != null) {
			frame.style.height = iFrameHeight + 'px';
		}
		// See resizeBottomFrame
		// - document.body.offsetTop - bottomFrame.offsetTop
		iFrameHeight -= 159
		if (iFrameHeight < 48) { iFrameHeight = 48 }
		frame = document.getElementById('idBottomFrame')
		if (frame != null) {
			frame.style.height = iFrameHeight + 'px';
		}
	}
}


function doSubmitQuickSearch(form) {
	var q1 = trim(form.q1.value)
	lastSearch.q1 = q1;
	if ((q1 == '') || (q1 == '*')) {
		alert('Geef een term op om naar te zoeken')
		return false
	}
	return true 
}

// Wrapper for executing js function from menu
function execMenuItem() {
	return false
}

function loadMenu(page, bookCode) {
	if ((typeof(bookCode) != 'undefined') && (bookCode != '')) {
		//src="/b/bnc/js/menu/menudata/" + bookCode + ".js"
		// bijbelboek order is important
		_maxm("ajax:/b/bnc/js/menu/menudata/bijbelboek.js")
	} else {
		_maxm("ajax:/b/bnc/js/menu/menudata/" + page + ".js")
	}
}

// Called by main window onload and onresize event handlers
// to set the height of the bottomFrame
function resizeBottomFrame() {
	var bottomFrame = document.getElementById('idBottomFrame')
	if (bottomFrame != null) {
		var frameHeight = getWindowHeight() - document.body.offsetTop - bottomFrame.offsetTop
		if (frameHeight > 0) {
			bottomFrame.style.height = frameHeight + 'px'
		}
	}
}

function saveSearch(lastSearch, q1, op2, q2, op3, q3, rgn, book) {
	if ((op2 != 'of') && (op2 != 'niet')) { op2 = 'en' }
	if ((op3 != 'of') && (op3 != 'niet')) { op3 = 'en' }
	if (rgn == '') { rgn = 'all' }
	if (book == '') { book = 'all' }
	lastSearch.q1 = q1
	lastSearch.op2 = op2
	lastSearch.q2 = q2
	lastSearch.op3 = op3
	lastSearch.q3 = q3
	lastSearch.rgn = rgn
	lastSearch.book = book
}

function setTitle(page, bookOrRD) {
	var titleDiv = document.getElementById('idDivTitle')
	if (titleDiv != null) {
		var pageDir = imageDir + page + '/'
		var titleImg
		if (((page == 'rodedraden') || (page == 'webquests')) && (bookOrRD != '')) {
			titleImg = pageDir + bookOrRD + '_title.jpg'
		} else {
			if (bookOrRD != '') {
				titleImg = pageDir + bookOrRD + '/title.jpg'
			} else {
				titleImg = pageDir + '/title.jpg'
			}
		}
		titleDiv.style.background = "url('" + titleImg + "')"
	}
}

