var searchindex = "0:0";

mas_books_by = new Array
(
    "title",	"названию",
    "author",	"автору"
);

mas_journals_by = new Array
(
    "title",	"названию"
);

function onload_searchindex (strType, strSelectby)
{
    var oType = document.getElementById("searchindex_type");
    var selby = document.getElementById("searchindex_selectby");
    
    for ( i = 0; i < oType.options.length; i++)
    {
	if ( oType.options(i).value == strType )
	{
	    oType.options(i).selected = true;
	    fint = i;
	}
    }
    
    switch (strType)
    {
	case "book":	mas_cur = mas_books_by;		break;
	case "journal":	mas_cur = mas_journals_by;	break;
    }
    
    for (i = 0; i < mas_cur.length; i = i + 2)
    {
	var oOption = document.createElement("OPTION");
	selby.options.add(oOption);
	oOption.value = mas_cur[i];
	oOption.innerText = mas_cur[i + 1];
	if ( oOption.value == strSelectby )
	{
	    oOption.selected = true;
	    sint = i / 2;
	}
    }    

    searchindex = fint + ":" + sint;
    document.getElementById(searchindex).style.display = 'block';
}

function onchange_searchindex ()
{
    var fint  = document.getElementById("searchindex_type").selectedIndex;
    var selby = document.getElementById("searchindex_selectby");
    var sint  = selby.selectedIndex;

    document.getElementById(searchindex).style.display = 'none';
    searchindex = fint + ":" + sint;
    document.getElementById(searchindex).style.display = 'block';

    selby.innerHTML = "";
    switch (fint)
    {
	case 0:	mas_cur = mas_books_by;		break;
	case 1:	mas_cur = mas_journals_by;	break;
    }

    for (i = selby.options.length - 1; i >= 0; i--)
    {
	selby.options.remove(i);
    }

    sint = (sint < mas_cur.length / 2) ? sint : 0;
    for (i = 0; i < mas_cur.length; i = i + 2)
    {
	var oOption = document.createElement("OPTION");
	selby.options.add(oOption);
	oOption.value = mas_cur[i];
	oOption.innerText = mas_cur[i + 1];
	if ( (i / 2) == sint )
	{ oOption.selected = true; }
    }
    
//    alert (selby.outerHTML);
}

function onclick_searchindex (obj)
{
    document.getElementById('index').value = obj;
    document.getElementById('searchindex').submit();
}


function toggle(obj, display)
{
    var t = document.getElementById(obj);
    t.style.display = display;
}
			 



var authors = -1;
var list_indexes = new Array ("titles", "authors", "years");
var list_searchs = new Array ("books", "journals");

function show_index (obj)
{
    for (i = 0; i < list_indexes.length; i++)
    {
	document.getElementById(list_indexes[i]).style.display = 'none';
	var alink = document.getElementById("a_" + list_indexes[i]);
	if (alink != null) { alink.className = ''; }
    }
    document.getElementById(obj).style.display = 'block';
    document.getElementById("a_" + obj).className = 'selected';
}

function add_author (obj)
{
    if ( authors == -1 ) authors = obj + 1;

    var parent = document.getElementById('authors_list');
    var row = parent.insertRow ();
    var cell = row.insertCell ();
    cell.insertAdjacentHTML("BeforeEnd","<input type=text name=author_family" + authors + ">");
    cell = row.insertCell ();
    cell.insertAdjacentHTML("BeforeEnd","<input type=text name=author_name" + authors + ">");
    cell = row.insertCell ();
    cell.insertAdjacentHTML("BeforeEnd","<input type=text name=author_midname" + authors + ">");
    
    authors++;
    alert (parent.innerHTML);
}

function show_search (obj)
{
    for (i = 0; i < list_searchs.length; i++)
    {
	document.getElementById(list_searchs[i]).style.display = 'none';
    }
    document.getElementById(list_searchs[obj.selectedIndex]).style.display = 'block';
}

function toggle(obj)
{
    var t = document.getElementById(obj);
    t.style.display = t.style.display == 'block' ? 'none' : 'block';
}

function sel_l (obj)
{
    var par = obj.parentElement;
    var leng = par.children.length;
    str = par.children(1).style.display;
    str = (str == "inline") ? "none" : "inline";
    for (var i = 1;i < leng;i++)
    {
	par.children(i).style.display = str;
    }
}

function ch_col (obj)
{
    str = obj.style.color;
    str = (str == 'red') ? '#003399' : 'red';
    obj.style.color = str;
}

