function fnSearchMore()
{
  searchValue = document.getElementById( 'fulltext' ).value;
  document.getElementById( 'fulltext' ).value = searchValue.substr( 0, searchValue.length - 1 );
  liveSearchDealerStart( document.getElementById( 'fulltext' ) );
}

function fnFocus( p_strN )
{
  if( p_strN != "" )
  {
    document.getElementById( p_strN ).focus();
  }
}

var objFocus;
var strBackgroundColor;
var strBorderColor;
var windowImage;

function fnHighlight( obj )
{
  if( objFocus )
  {
    objFocus.style.backgroundColor = strBackgroundColor;
    objFocus.style.borderColor     = strBorderColor;
  }
  
  objFocus                  = obj;
  strBackgroundColor        = obj.style.backgroundColor;
  strBorderColor            = obj.style.borderColor;

  if( obj.readOnly == false )
  {  
    obj.style.backgroundColor = '#fffee9';
    if( obj.className != 'form_error' )
    {
      obj.style.borderColor     = '#0000ff';
    }
  }
  return false;
}

function fnPopup( p_strId )
{
  var iWidth  = 600;
  var iHeight = 480;
  var iLeft = ( screen.width - iWidth ) / 2;
  var iTop  = ( screen.height - iHeight ) / 2;
  
  if( windowImage != null )
  {
    windowImage.close();
  }
  
  windowImage = window.open( 'http://cook.kueppersbusch-hausgeraete.de/modRecipe/viewImage?file=' + p_strId, '', 'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',dependent=yes,toolbar=no,location=no,status=no,menubar=no,scrollbar=no,resizeable=no' );
}

function fnCloseImage()
{
  window.close();
}

function fnSalutationChange( obj )
{
  if( obj.value == 'Herrn' )
  {
    document.getElementById( 'tbl_person_salutation_text' ).value = 'Sehr geehrter Herr';
    return false;
  }
  if( obj.value == 'Frau' )
  {
    document.getElementById( 'tbl_person_salutation_text' ).value = 'Sehr geehrte Frau';
    return false;
  }
  if( obj.value == '' )
  {
    document.getElementById( 'tbl_person_salutation_text' ).value = 'Sehr geehrte Damen und Herren';
    return false;
  }
  return false;
}

function fnLinkTo( p_strLink )
{
  self.location.href = p_strLink;
}

function fnSwitchPage( p_iNr, p_strID )
{
  document.getElementById( p_strID ).no_save.value = '1';
  document.getElementById( p_strID ).page.value = p_iNr;

  document.getElementById( p_strID ).submit();
}

function fnFilterSubmit( )
{
  if(document.getElementById( 'filter' ).pdf)
  {
    document.getElementById( 'filter' ).pdf.value = 0;
  }
  document.getElementById( 'filter' ).submit();
}

function fnPDFSubmit( p_iPDF )
{
  document.getElementById( 'filter' ).pdf.value = p_iPDF;
  document.getElementById( 'filter' ).submit();
}

function fnDelete( p_iID, p_strID, p_strName )
{
  document.getElementById( p_strID ).no_save.value = '1';
  document.getElementById( p_strID ).actdel.value = p_iID;
  document.getElementById( p_strID ).submit();
}

function fnAdd( p_strID, p_strName )
{
  document.getElementById( p_strID ).no_save.value = '1';
  document.getElementById( p_strID ).actadd.value = 1;
  document.getElementById( p_strID ).submit();
}

function fnFormHandle( p_strId, p_strValue )
{
  if(document.getElementById(p_strId) )
  {
    document.getElementById(p_strId).value = p_strValue;
    self.document.data.submit();
  }
}

var objTimer     = null;
var searchString;

function liveSearchStart( obj )
{
   searchString = obj;
   if( objTimer )
   {
     window.clearTimeout( objTimer );
   }
   objTimer = window.setTimeout( "doLiveSearch()", 500 );
}

function doLiveSearch()
{
  new Ajax.Updater( 'list', '/index.php/modMain/search', {asynchronous: true, evalScripts: true, parameters: { ffulltext: searchString.value } } );
  return false;
}


var objTimerSearch     = null;
var searchStringDealer;

function liveSearchDealerStart( obj )
{
   searchStringDealer = obj;
   if( objTimerSearch )
   {
     window.clearTimeout( objTimerSearch );
   }
   objTimerSearch = window.setTimeout( "doLiveSearchDealer()", 500 );
}

function doLiveSearchDealer()
{
  new Ajax.Updater( 'result', '/index.php/modDealer/search', { asynchronous: true, evalScripts: true, parameters: { fulltext: searchStringDealer.value } } );
  return false;
}
function fnDeleteIngredient( p_iID )
{
  document.getElementById('delete_ingredient').value = p_iID;
  document.getElementById('frm_recipe').submit();
}

function fnDeleteAppliance( p_iID )
{
  document.getElementById('delete_appliance').value = p_iID;
  document.getElementById('frm_recipe').submit();
}

function fnFocusFirst()
{
  if( document.forms.length > 0 )
  {
    var field = document.forms[0];
    for( i=0; i < field.length; i++ )
    {
      if( ( field.elements[i].type == "text" ) || ( field.elements[i].type == "textarea" ) || ( field.elements[i].type == "password" )  || ( field.elements[i].type == "file" ) || ( field.elements[i].type.toString().charAt(0) == "s" ) )
      {
        if( ( document.forms[0].elements[i].value == '' ) && ( document.forms[0].elements[i].readOnly == false ) )
		{
		  document.forms[0].elements[i].focus();
		  break;
		}
      }
    }
  }
}

function fnCategory( p_gid, p_cid )
{
  // self.location.href = "http://www.kueppersbusch-hausgeraete.de/modProduct/overview/gid/" + p_gid + "/cid/" + p_cid;
  self.location.href = "/index.php/modProduct/overview/gid/" + p_gid + "/cid/" + p_cid;
}

function fnLanguage( obj )
{
  new Ajax.Updater( 'result', '/modLanguage/Switch', { asynchronous: true, evalScripts: true, parameters: { culture: obj.value } } );
  location.reload();
}
