// Show and hide any element
var state = 'none'; 
function showhide(layer_ref) { 
	if (state == 'block')
		state = 'none'; 
	else
		state = 'block'; 
	
	if (document.all) //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + layer_ref + ".style.display = state"); 
	
	if (document.layers) //IS NETSCAPE 4 or below 
		document.layers[layer_ref].display = state; 
	
	if (document.getElementById &&!document.all)
	{
		hza = document.getElementById(layer_ref); 
		hza.style.display = state; 
	} 
} 

// Add value to a field
function add(harf){
	osnovno.search1.value += harf
}

// Function that opens popup window in desired size and form
function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	if (strType=="console")
		strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") 
		strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") 
		strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	if (strType=="full") 
		strOptions="toolbar,menubar,scrollbars,resizable,location,fullwindow,fullscreen";
	
	window.open(strURL, 'newWin', strOptions);
}

// Function that submits newsletter subscription
function submitnewsletter() {
	if (document.newsletter.email.value == "") {
		alert("Vpišite svojo elektronsko pošto!");
		return false;
	}
	if ((document.newsletter.email.value.length < 5) || (document.newsletter.email.value.indexOf("@") == -1) || (document.newsletter.email.value.indexOf(".") == -1)){
		alert("Elektronska pošta ni v pravi obliki!");
		return false;
	}
	
	return true;
}

// Function that submits simple search
function submitosnovno() {
	if (document.osnovno.search1.value == "") {
		alert("Iskalni niz ne sme biti prazen!");
		return false;
	}
	/*if (document.osnovno.search1.value.length < 1) {
		alert("Iskalni niz je prekratek!");
		return false;
	}*/
	
	if (document.osnovno.field1[1].checked)
	{
		document.osnovno.fotografije.value = "off";
		document.osnovno.rokopisi.value = "off";
		document.osnovno.zemljevidi.value = "off";
		document.osnovno.plakati.value = "off";
		document.osnovno.zvocni_posnetki.value = "off";
	}
	return true;
}

// Function that submits adanced search
function submitnapredno() {
	document.napredno.search1.value = document.napredno.fsearch1.value;
	document.napredno.operator1.value = document.napredno.foperator1.value;
	document.napredno.field1.value = document.napredno.ffield1.value;

	if ((document.napredno.fsearch2.value != "") && (document.napredno.fsearch1.value != "")) {
		document.napredno.search2.value = document.napredno.fsearch2.value;
		document.napredno.operator2.value = document.napredno.foperator2.value;
		document.napredno.field2.value = document.napredno.ffield2.value;
	}
	
	if ((document.napredno.fsearch2.value != "") && (document.napredno.fsearch1.value == "")) {
		document.napredno.search1.value = document.napredno.fsearch2.value;
		document.napredno.operator1.value = document.napredno.foperator2.value;
		document.napredno.field1.value = document.napredno.ffield2.value;
	}

	if ((document.napredno.fsearch3.value != "") && (document.napredno.fsearch2.value != "") && (document.napredno.fsearch1.value != "")) {
		document.napredno.search3.value = document.napredno.fsearch3.value;
		document.napredno.field3.value = document.napredno.ffield3.value;		
	}

	if ((document.napredno.fsearch3.value != "") && (document.napredno.fsearch1.value == "")) {
		document.napredno.search1.value = document.napredno.fsearch3.value;
		document.napredno.field1.value = document.napredno.ffield3.value;
	}
	
	if ((document.napredno.fsearch3.value != "") && (document.napredno.fsearch1.value != "") && (document.napredno.fsearch2.value == "")) {
		document.napredno.search2.value = document.napredno.fsearch3.value;
		document.napredno.field2.value = document.napredno.ffield3.value;
	}
	
	if (document.napredno.search1.value == "") {
		alert("Iskalni niz ne sme biti prazen!");
		return false;
	}
	/*if (document.napredno.search1.value.length < 1) {
		alert("Iskalni niz je prekratek!");
		return false;
	}*/
	return true;
}


// Functions for handling selection of databases
function switch_all_checkbox()
{		
	for (var i = 0; i < document.napredno.elements.length; i++) {
		if ((document.napredno.elements[i].type == 'checkbox') && (document.napredno.elements[i] != document.napredno.katnuk))
			document.napredno.elements[i].checked = document.napredno.select_all.checked;
	}
}

// (De)Select all
function check_all_checkbox()
{
	var checkedEl = 0;
	
	for (var i = 0; i < document.napredno.elements.length; i++) {
		if ((document.napredno.elements[i].type == 'checkbox') && (document.napredno.elements[i].checked == false))
			document.napredno.select_all.checked = false;
		else
			checkedEl++;
	}

	if ((checkedEl == document.napredno.elements.length - 2) && (document.napredno.katnuk.checked == false))
		document.napredno.select_all.checked = true;
}

// If fulltext search is selected, we need to disable some collections
function check_full_text_search_checkbox()
{
	if ((document.napredno.ffield1.value == "fulltext") || (document.napredno.ffield2.value == "fulltext") || (document.napredno.ffield3.value == "fulltext"))
	{
		// document.napredno.katnuk.checked = false; document.napredno.katnuk.disabled = true;
		document.napredno.rokopisi.checked = false; document.napredno.rokopisi.disabled = true;
		document.napredno.fotografije.checked = false; document.napredno.fotografije.disabled = true;
		document.napredno.zvocni_posnetki.checked = false; document.napredno.zvocni_posnetki.disabled = true;
		document.napredno.zemljevidi.checked = false; document.napredno.zemljevidi.disabled = true;
		document.napredno.plakati.checked = false; document.napredno.plakati.disabled = true;
		document.napredno.select_all.checked = false; document.napredno.select_all.disabled = true;
	} else if (document.napredno.select_all.disabled == true) {
		// document.napredno.katnuk.disabled = false;
		document.napredno.rokopisi.disabled = false;
		document.napredno.fotografije.disabled = false;
		document.napredno.zvocni_posnetki.disabled = false;
		document.napredno.zemljevidi.disabled = false;
		document.napredno.plakati.disabled = false;
		document.napredno.select_all.disabled = false;
	}
}

// Function that submits poll
function submit_anketa(spol)
{
	var checked = 0;
	for (var i=0; i < document.anketa.odgovor.length; i++)
	{
		if (document.anketa.odgovor[i].checked)
		{
			checked = true;
			break;
		}
	}

	if (checked)
	{
		document.anketa.spol.value = spol;
		document.anketa.submit();
	}
}

// Functions that submits form in result page
function do_post_form(database)
{
//	if (database == "katnuk")
//		document.forms.form.action = "results_katnuk.asp"
	document.form.database.value=database;
	document.form.displayed.value='0';
	document.forms.form.submit();
}
function do_post_form_sort(database,sort)
{
	//if (database == "katnuk")
	//	document.forms.form.action = "results_katnuk.asp"
	document.form.database.value=database;
	document.form.displayed.value='0';
	document.form.sort.value=sort;
	document.forms.form.submit();
}

function do_post_form_from(database, displayed)
{
	//if (database == "katnuk")
	//	document.forms.form.action = "results_katnuk.asp"
	document.form.database.value=database;
	document.form.displayed.value=displayed;
	document.forms.form.submit();
}

// Function that toggles divs' visibility
function toggle( what, no ) 
{
	var i;
	var divs;
	if (what == '') {
		divs = no;			
		for(i=1;i<=divs;i++) {
			document.getElementById('div'+i).style.visibility = 'hidden';
			document.getElementById('div'+i).style.display = 'none';
		}
	} else {
		if (document.getElementById(what).style.visibility == 'visible') {
		    document.getElementById(what).style.visibility = 'hidden';
	        document.getElementById(what).style.display = 'none';
	    } else {
		    document.getElementById(what).style.visibility = 'visible';
	        document.getElementById(what).style.display = 'block';
	    }
    }
}
