/* 
Full-text bibliographical research tool (PHP) v0.2 - April 2006
Creative Commons License, Emanuel@Towfigh.net & Hoerster@Muenster.de: Use as you like -- no warranty whatsoever
if you apply improvements please let us know
*/

// the welcome() function is in charge of showing our welcome splashscreen
function welcome() {
        document.body.style.overflow = (document.body.style.overflow == "auto")? "auto" : "hidden";
	el = document.getElementById("overlay");
	el.style.display = el.style.display? "" : "block";
	el = document.getElementById("welcome");
	el.style.display = el.style.display? "" : "block";
}

// the popup function shows the IE error warning on the screen
function popup (Adresse) {
  var centerX=(screen.width-300)/2; 
  var centerY=(screen.height-350)/2;
  Fenster1 = window.open(Adresse, 'Info', 'width=300,height=350,top='+centerY+',screenY='+centerY+',left='+centerX+',screenX='+centerX+',dependent=yes,location=no,menubar=no,status=no,toolbar=no');
  Fenster1.focus();
}

// the toggleLayer function is in charge for showing/hiding the different selections on the right hand side of
// the search screen
function toggleLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
		myimage = whichLayer + "_myimage";
		image2 = document.getElementById(myimage);
		image2.src = (style2.display == "block") ? "tpl/active/img/toggle_close.gif" : "tpl/active/img/toggle_open.gif";
	}
	else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		myimage = whichLayer + "_myimage";
		image2 = document.all[myimage];
		image2.src = (style2.display == "block") ? "tpl/active/img/toggle_close.gif" : "tpl/active/img/toggle_open.gif";
	}
	else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		myimage = whichLayer + "_myimage";
		image2 = document.layers[myimage];
		image2.src = (style2.display == "block") ? "tpl/active/img/toggle_close.gif" : "tpl/active/img/toggle_open.gif";
	}
}

function hideLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = "";
		myimage = whichLayer + "_myimage";
		image2 = document.getElementById(myimage);
		image2.src = "tpl/active/img/toggle_open.gif";
	}
	else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = "";
		myimage = whichLayer + "_myimage";
		image2 = document.all[myimage];
		image2.src = "tpl/active/img/toggle_open.gif";
	}
	else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = "";
		myimage = whichLayer + "_myimage";
		image2 = document.layers[myimage];
		image2.src = "tpl/active/img/toggle_open.gif";
	}
}

// this is the function that takes care of the checking and unchecking of the documents that can
// be excluded from the search by selection of a checkbox on the right side of the search screen
function chk_level1(master,group) {
	var allpagetags = new Array();
	var allpagetags = document.getElementsByTagName("input");
    for (i=0;i<allpagetags.length;i++) {
	    if (allpagetags[i].className==group) { 
	        allpagetags[i].checked = (master.checked == 1) ? 1 : 0;
	        allpagetags[i].disabled = (master.checked == 1) ? 0 : 1;
 		} 
    }
//    if (master.checked == 0) hideLayer(master.value); 
}
function chk_level2(master,groupname) {
	hld = document.getElementsByName(groupname);
    for (i=0;i<=hld.length-1;i++) {
        hld[i].checked = (master.checked == 1) ? 1 : 0;
        hld[i].disabled = (master.checked == 1) ? 0 : 1;
    }
//    if (master.checked == 0) hideLayer(master.value); 
}

// this function is in charge of actually taking out those documents that were unchecked by the user
// in the selection shown on the right side of the search screen
function skip_files(box) {
	formArray = new Array()
	j = document.forms[0].length;
	for (i=0; i<j; i++){
//		if((document.skipfiles.elements[i].checked == false) && (document.skipfiles.elements[i].name != "Level1") && (document.skipfiles.elements[i].name != "Level2")) { formArray[i] = document.skipfiles.elements[i].value; }
		if((document.skipfiles.elements[i].checked == false) && (document.skipfiles.elements[i].disabled == false)) { formArray.splice(0,0,document.skipfiles.elements[i].value); }
	}
	var output_string = formArray.join(":");
	if ( output_string.length > 512 ) {
		alert("Error!\nThe number of deselected documents is far too great ("+output_string.length+" characters). Sorry.");
	}
	else parent.document.searchform.s.value = output_string;
}

// the resize functions take care of the size of the iframes and divs
// so that you have the feeling of a one-page screen with the controls remaining where they are
// and yet use the whole screen
// unfortunately, browsers treat the resizing differently :-(
function resize_iframe( who , howmuch ) {
	//resize an iframe according to the size of the window
        var FFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
        var FFExtra=parseFloat(FFVersion)>=0.1? 15 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
        who2 = "coord_" + who;
        who2 = document.getElementById(who2);
	if (who2.offsetParent) {
		pos = who2.offsetTop
		while (who2= who2.offsetParent) {
			pos += who2.offsetTop
		}
	}
	document.getElementById(who).height = document.body.offsetHeight - pos - FFExtra + "px";
}
function resize_div( who , howmuch ) {
	//resize a div according to the size of the window
	document.getElementById(who).style.height = document.body.offsetHeight - document.getElementById(who).offsetTop + "px";
}

// in RESULTS, these functions make the moves between the anchors
function move(anchor) {
	document.getElementById('current_anchor').value = parseInt(anchor);
	window.location="#phrase-" + anchor;
}
function prev() {
if (document.getElementById('current_anchor').value > 0) {
	anchor = parseInt(document.getElementById('current_anchor').value) - 1;
	document.getElementById('current_anchor').value = anchor;
	window.location="#phrase-" + anchor;
	}
}
function next() {
if (parseInt(document.getElementById('current_anchor').value) + 1 < document.getElementById('max_anchor').value ) {
	anchor = parseInt(document.getElementById('current_anchor').value) + 1;
	document.getElementById('current_anchor').value = anchor;
	window.location="#phrase-" + anchor;
	}
}