﻿var dwin;
function debug( msg, end ){
	if( ! dwin ){
		if( end ){
			return;
		}
		dwin = window.open( 'about:blank' , 'debug_window', 'scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,dependant=yes,alwaysRaised=yes,location=yes'); 
	}
	dwin.document.writeln( msg + "<br>" );
	if( end ){
		dwin.document.close();
	}
} 



//	var ol_fullhtml=1;

//var ol_fgcolor = "#FFFFE1";
var ol_fgcolor = "#FFDA40";
//var ol_fgcolor = "#FFE74E";
var ol_bgcolor = "#FFBD1E";
var ol_textcolor = "#000000";
var ol_capcolor = "#FFFFFF";

var ol_width = "-1";
var ol_close = "x";


var search_on = false;
var read_on = false;





function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser./nThis browser is not supported,');
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
}
is = new Browser();

function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
	}
	return null
}
function deleteCookie(name) {
	saveCookie(name,"",-1)
}


function getlayer( id ){
    if (is.dom || is.opera) {
	  tmp = document.getElementById(id);
      return tmp.style;
    }else
    if (is.ns4) {
	  return eval( 'document.' + id );
    }else
    if (is.ie) {
	  return eval( id + '.style' );
    }else
		return false;
}

function show( id ){
	l = getlayer( id );
	if(l){
	    l.visibility = is.ns4 ? "show" : "visible";
		l.display = 'block';
	}
}

function hide( id ){
	l = getlayer( id );
	if(l){
	    l.visibility = is.ns4 ? "hide" : "hidden";
		l.display = 'none';
	}
}


var active_panel = false;

function panel_toggle( id ){
	if( active_panel == id ){
		hide( active_panel );
		active_panel = false;
	}else{
		if( active_panel != false ){
			hide( active_panel );
		}
		show( id );
		active_panel = id;
	}
	return true;
}

function panel_show( id ){
	if( active_panel == id ){
		return true;
	}
	if( active_panel != false ) {
		hide( active_panel );
	}
	show( id );
	active_panel = id;
	return true;
}


function panel_close( id ){
	if( active_panel == id || ( id == 'all' && active_panel!=false) ){
		hide( active_panel );
		active_panel = false;
	}
	return true;
}

function refill_selectbox( caller, target_id, selected_id ) {
	if( ! is.dom ) {
		return false;
	}
//	alert( target_id );

	var knyga = caller.options[caller.selectedIndex].value;
	var target = document.getElementById( target_id );
//	while (target.options.length) target.options[0] = null;
	if( is.ns6 ){
		while (target.options.length>0) 
			target.remove(0);
	}else{
		while (target.options.length>0) 
			target.options.remove(0);
	}

	var data = search_sritis_data[ caller.selectedIndex ];
	for (i = 0; i < data.length-1; i++) {
//		var tmp = document.createElement("OPTION");
		var tmp = new Option( data[i][0], data[i][1] );
		//alert(data[0][0] +" "+ data[0][1]);
		//alert(data[1][0] +" "+ data[1][1]);
		if( data[i][1]==selected_id )
			tmp.selected = true;
			
		if( is.ns6 ) {
		    target.add(tmp, target.options[target.options.length] );
		}else{
//		    target.options.add(tmp,data[i][1], target.options[target.options.length]);
		    target.options.add(tmp);
		}
		//alert(data[i][0]);
//		tmp.innerText = data[i];
//		tmp.value = i;
	}
	//alert("viskas");
    return true;
}



function startup(selected_id) {
	if( is.dom ){
		refill_selectbox( document.getElementById( 'search_document_select' ), 'search_set_select', selected_id );
	}
	return true;
}




/*function print() {
//    window.alert( 'Spausdinimo funkcija dar neveikia.' );
	return window.print();
}
*/

var qs_array = [ 
'/index.aspx?cmp=find&str=QUERY&doc=BiblijaRKK1998',		// 1 
'/index.aspx?cmp=find&str=QUERY&doc=BiblijaRKE1999',		// 2
'',
'',
'http://www.lcn.lt/cgi-bin/webglimpse/opt/webglimpse/index/bzinios?query=QUERY&errors=0&age=&maxfiles=50&maxlines=30&maxchars=10000&cache=yes'	// 5
];


function quick_search(o) {
//	window.alert( o.elements.sritis.value );
	i = parseInt( o.elements.sritis.value );

	if( isNaN(i) || (i < 1) ){
//		window.alert( 'Pasirinkite paieškos sritį' );
		i = 1;
//	    return false;
	}
	
	q = o.elements.q.value;

	if( q.length < 1 ){
		window.alert( 'Įveskite paieškos žodį' );
	    return false;
	}

	url = new String( qs_array[i-1] );

	if( url.length <1 ){
		window.alert( 'Ši paieškos sritis dar neveikia' );
	    return false;
	}

	if( i == 5 ) { // bzinios
		o.acceptCharset = 'Windows-1257';
	}

	rexp = /QUERY/g;
	url2 = url.replace( rexp, o.elements.q.value );
	
//	window.alert( url2 );

	window.location = url2;
	return false;
}
