var gPrevSearchType = 0;
function ChangeSearchType( pSearchType )
{
  document.getElementById( 'search_type_' + gPrevSearchType ).style.display = 'none';
  gPrevSearchType = pSearchType;
  document.getElementById( 'search_type_' + pSearchType ).style.display = 'block';
}
function SubmitForm( pEvent )
{
  var loEvent = null;
  if( !pEvent )
    loEvent = window.event;
  else
    loEvent = pEvent;

  var loKeyCode = null;
  if( loEvent.keyCode )
    loKeyCode = loEvent.keyCode;
  else if( typeof( loEvent.which ) != 'undefined' )
    loKeyCode = loEvent.which;
  else
    return;

  if( loKeyCode == 13 )
    document.getElementById( 'search_type_' + gPrevSearchType ).submit();
  else
    return;
}

var gPrevLink = null;
var gNextLink = null;
var gLoadingSearchForm = false;

var gSearchType = 'google';

var gSearchFields = new Array();
gSearchFields[ 'google' ] = 'q';
gSearchFields[ 'telefon' ] = 'q';
gSearchFields[ 'prisguide' ] = 'siteSearchQuery';
gSearchFields[ 'filter' ] = 'q';

var extraopts = new Array();
extraopts[ 'google' ] = '<table><tr><td><input type="radio" name="u" value="verden" checked="checked"/></td><td>Verden</td><td><input type="radio" name="u" value="norge"/></td><td>Norge</td><td><a href="JavaScript:void( 0 );" onclick="JavaScript:getSearchForm( gNextLink, \'google\', true );">Avansert søk</a></td></tr></table>';
extraopts[ 'telefon' ] = '';
extraopts[ 'prisguide' ] = '';
extraopts[ 'filter' ] = '';

function getSearchForm( pLink, pType, pAdvanced )
{     
  if( gLoadingSearchForm )
    return;

  if( pLink == null )
    pLink = document.getElementById( 'search_form_active_link' );
  
  if( gPrevLink == null )
    gPrevLink = document.getElementById( 'search_form_active_link' );
	  
  gNextLink = pLink; 
  gLoadingSearchForm = true;

  var loValue = '';
  if( gSearchType == 'reise' )
  {
    if( gPrevSearchType != 2 ) 
	  eval( 'loValue = document.forms.search_type_' + gPrevSearchType + '.dest.value' );
  }
  else
    loValue = document.forms.search_form[ gSearchFields[ gSearchType ] ].value;
  
  gPrevSearchType = 0;
  
  var loAdvanced = '';
  if( pAdvanced )
    loAdvanced = '&adv='; 
	
  request( 'http://www.start.no/includes/fpmodules/search_box/search_box_new.php', 'type=' + pType + '&value=' + loValue + loAdvanced, true );
  
  gSearchType = pType;
}

function setSearchTab()
{
  gPrevLink.className = 'link';
  gNextLink.className = 'active_link';
  gPrevLink = gNextLink;
  setExtraOpt( gSearchType );  
  gLoadingSearchForm = false;
}
function resetSearchTab()
{
  gLoadingSearchForm = false;
  gPrevSearchType = 0;
}

function setExtraOpt( pType )
{
	if( document.getElementById( 'search_extraopt' ) )
	  document.getElementById( 'search_extraopt' ).innerHTML = extraopts[ pType ];
}


