var lk_lang = location.href.search(/\/en\//) == -1 ? 'de' : 'en'

function lk_txt_update( p_id, q_id )
{
  var lk_id = document.getElementById('sel_lk')?document.getElementById('sel_lk')[ document.getElementById('sel_lk').selectedIndex ].value:0
  xajax_fx_lk_txt_update( lk_id, p_id, q_id, lk_lang )
}

function lk_delete()
{
  var lk_id = document.getElementById('sel_lk')[ document.getElementById('sel_lk').selectedIndex ].value
  xajax_fx_lk_delete( lk_id, lk_lang )
}

function lk_add( q_id )
{
  var name = document.getElementById('lk_name').value
  document.getElementById('lk_name').value=''
  xajax_fx_lk_add( name, q_id, lk_lang )
}

function lk_add_all( q_id )
{
  xajax_fx_lk_add_all( q_id, lk_lang )
  
  for( i=1; i<a_pict_on_page.length; i++ )
    lk_icon_change( a_pict_on_page[i], 2 , 0 )
}

function lk_change()
{
  var lk_id = document.getElementById('sel_lk')[ document.getElementById('sel_lk').selectedIndex ].value
  var name = document.getElementById('lk_cname').value
  xajax_fx_lk_change( lk_id, name, lk_lang )
}

function lk_sort( a )
{
  var lk_id = document.getElementById('sel_lk')[ document.getElementById('sel_lk').selectedIndex ].value
  xajax_fx_lk_sort( lk_id, a )
}

function check_lk_neu(lang)
{
  if (document.getElementById('lk_name').value=='' ) {
    alert(lk_lang=='en' ? 'Please enter the name first!' : 'Bitte geben Sie zunächst den Name ein!')
    return false
  }
  return true
}

function lk_icon_change( p_id, icon, status )
{
  // icon     0 : toogle
  //          1 : icon_lk
  //          2 : icon_lk2
  // status   0 : off
  //          1 : on
  var e = document.getElementsByName('icon_lk_'+p_id)
  if ( !e[0] || typeof(e[0])=='undefined' ) e = document.getElementsByName('icon_lk2_'+p_id)
  if ( !e[0] || typeof(e[0])=='undefined' ) return

  var icon_name = 'icon_lk' + (icon == 2 || !icon && e[0].name.replace(/_\d+$/,'') == 'icon_lk' ? '2' : '')
  var title = 'zur Bildauswahl hinzufügen'
  if (lk_lang == 'de' && icon_name == 'icon_lk2') {
    title = 'von Auswahl entfernen';
  } else if (lk_lang == 'en') {
    title = icon_name == 'icon_lk2' ? 'remove from selektion' : 'Add to image selection';
  }

  if ( status ) {
    e[0].src = gif_name[ icon_name ].on.src
  } else {
    e[0].src = gif_name[ icon_name ].off.src
  }

  e[0].title = title;
  e[0].alt   = title;
  e[0].name  = icon_name + '_' + p_id
}

function lk_icon_change_all()
{
  var i=0
  for( i=1; i<a_pict_on_page.length; i++ )
    lk_icon_change( a_pict_on_page[i], pict_in_lk.indexOf( ' ' + a_pict_on_page[i] + ' ' )==-1?1:2 , 0 )
}

function addOption(selectId,txt,val)
{
  // safari dont like it
  //var objOption = new Option(txt,val)
  //document.getElementById(selectId).options.add(objOption)
  //document.getElementById(selectId).selectedIndex=document.getElementById(selectId).length-1
  document.getElementById(selectId).options[document.getElementById(selectId).length] = new Option(txt,val)
  document.getElementById(selectId).selectedIndex=document.getElementById(selectId).length-1
}

function lk_download(format)
{
  var lk_id = document.getElementById('sel_lk')[ document.getElementById('sel_lk').selectedIndex ].value;
  xajax_fx_lk_download(lk_id, format);
}

function lkmail_download(hash, format)
{
  xajax_fx_lkmail_download(hash, format);
}
