function focusField(fieldID) 
{
	field = document.getElementById(fieldID);
	field.focus();
}

function selectField(fieldID) 
{
	field = document.getElementById(fieldID);
	field.focus();
	field.select();
}

/* *** */

function centeredPopup(url, width, height) 
{
	var left = (screen.width - width) / 2;
	var top =  (screen.height - height) / 2;
	return window.open(url, "", "width="+width+", height="+height+", left="+left+", top="+top+", scrollbars=no, resizable=yes, status=no");
}
function centeredHTMLImagePopup(title, imageURL, width, height) 
{
	var left = (screen.width - width) / 2;
	var top =  (screen.height - height) / 2;

	popup = window.open("", "", "width="+width+", height="+height+", left="+left+", top="+top+", scrollbars=no, resizable=yes, status=no");

	popup.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">');

	popup.document.write('<html xmlns=\"http://www.w3.org/1999/xhtml\">');

	popup.document.write('<head>');

	popup.document.write('<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />');

	popup.document.write('<title>'+title+'</title>');

	popup.document.write('</head>');

	popup.document.write('<body style=\"padding:0; margin:0;\">');

	popup.document.write('<img src="'+imageURL+'" width="'+width+'" height="'+height+'"/>');

	popup.document.write('</body>');

	popup.document.write('</html>');

	popup.document.close();
	
	popup.focus();
}

function disableAutoComplete()
{
	if (document.getElementsByTagName) 
	{
		var inputElements = document.getElementsByTagName("input");
	
		for (i=0; inputElements[i]; i++) 
		{
			if (inputElements[i].className && (inputElements[i].className.indexOf("disableAutoComplete") != -1)) 
			{
				inputElements[i].setAttribute("autocomplete","off");
			}//if current input element has the disableAutoComplete class set.
		}//loop thru input elements
	}//basic DOM-happiness-check
}

/* *** */

function getProps(obj)
{
    var result = '';

    for (var i in obj)
    {
        if (typeof( obj[i]) == 'function') continue;
        result += i + ' = ' + obj[i] + ' | ';
    }
    
    return result;
}

function displayProps(obj)
{
    var result = '';

    for (var i in obj)
    {
        if (typeof( obj[i]) == 'function') continue;
        result += i + ' = ' + obj[i] + ' | ';
    }

    alert(result);
}

/* *** */

function $id(elemID)
{
    return document.getElementById(elemID);
}

function show(elemID)
{
    $id(elemID).style.display = 'block';
}

function hide(elemID)
{
    $id(elemID).style.display = 'none';
}

function resetSearchForm()
{
    var elements = document.searchform.elements;
    var elementsCount = document.searchform.elements.length;

    for (var i=0; i<elementsCount; i++)
    {
        if (elements[i].type == 'text')
        {
            elements[i].value = elements[i].defaultValue = '';
        }       
    }

    document.searchform.search_published.selectedIndex = document.searchform.search_genre_id.selectedIndex = 0;
}

function populateSearchFields()
{
    document.editform.search_published.value    = document.itemsform.search_published.value  = document.searchform.search_published.value;
    document.editform.search_genre_id.value     = document.itemsform.search_genre_id.value   = document.searchform.search_genre_id.value;
    document.editform.search_artist.value       = document.itemsform.search_artist.value     = document.searchform.search_artist.value;
    document.editform.search_title.value        = document.itemsform.search_title.value      = document.searchform.search_title.value;
    document.editform.search_author.value       = document.itemsform.search_author.value     = document.searchform.search_author.value;
    document.editform.search_editor.value       = document.itemsform.search_editor.value     = document.searchform.search_editor.value;
    document.editform.search_collection.value   = document.itemsform.search_collection.value = document.searchform.search_collection.value;
    document.editform.search_year.value         = document.itemsform.search_year.value       = document.searchform.search_year.value;
    document.editform.search_owner.value        = document.itemsform.search_owner.value      = document.searchform.search_owner.value;
    document.editform.search_place.value        = document.itemsform.search_place.value      = document.searchform.search_place.value;
    document.editform.search_summary.value      = document.itemsform.search_summary.value    = document.searchform.search_summary.value;
    document.editform.current_search_page.value = document.itemsform.current_search_page.value = document.searchform.current_search_page.value;
}

function toggleLineColor(checkInput, ID)
{
    $id('line-'+ID).style.backgroundColor = (checkInput.checked == false) ? '' : '#EEEEEE';
}