/*************************************************************************
 *
 * cvs:			$Date: 2004/02/10 12:29:12 $Author: jonah $Revision: 1.7 $
 * file:		search.js	
 * purpose:		JS function for book serach include file.
 * programmer:	jonas.ahnlund (JA)
 * develop inc:	flowinteractive
 *
 * history:		2003.05.28	created (JA).
 *
 ************************************************************************/
var	gSelected = 'btitle',
	gOnImg = null,
	gOffImg = null;

/************************************************
** FUNCTION:	preloadImages();
************************************************/
function preloadImages()
{	
	gOffImg = new Image();
	gOnImg = new Image();
	
	gOnImg.src = 'img/search_radio_on.gif';
	gOffImg.src = 'img/search_radio_off.gif';
}

/************************************************
** FUNCTION:	changeSearchRadio( rname );
************************************************/
function changeSearchRadio( rname, type )
{
    var theForm = document.forms[ 'search_form' ];

	if( rname != gSelected )
	{
		document.images[ gSelected ].src = gOffImg.src;
		document.images[ rname ].src = gOnImg.src;
		gSelected = rname;
	}

	if( theForm )
	    theForm.search_type.value = type;
}

/*************************************************
** FUNCTION:	validateSearch();
**************************************************/
function validateSearch()
{
	var theForm = document.forms[ 'search_form' ];
	if( theForm )
	{
	    // TODO

	    theForm.submit();
	}
}

/*************************************************
** FUNCTION:    focusizeSearch();
*************************************************/
function focusizeSearch()
{
    var theForm = document.forms[ 'search_form' ];
	if( theForm )
	{
	    theForm.search_query.focus();
	}
}

/**************************************************
** FUNCTION:    postImageArchiveSearch( _query, type, index );
**************************************************/
function postImageArchiveSearch( _query, type, index )
{
    var theForm = document.forms[ 'selection_form' ];
    var current_index = 0;

    if( theForm )
    {
    	if(type == "char") {
    		theForm.query.value = '';
	        theForm.category_char.value = _query;
	    }
        current_index = ( parseInt( theForm.from.value ) + index );
        theForm.from.value = ( current_index < 0 ) ? 0 : current_index;

        //alert( "browsing archive images from index: " + theForm.from.value );

        theForm.submit();
    }
}

/****************************************************************
** FUNCTION:    resetIndexCounter();
*****************************************************************/
function resetIndexCounter()
{
    var theForm = document.forms[ 'selection_form' ];
    var current_index = 0;

    if( theForm )
        theForm.from.value = 0;
}

/****************************************************
** FUNCTION:    postIsbnSearch();
****************************************************/
function postIsbnSearch()
{
	var theForm = document.forms[ 'selection_form' ];

	if( theForm )
	{
		if( trim( theForm.query.value ).length > 0 )
			theForm.submit();
	}
}

preloadImages();