/* Standard AJAX Funktion */
var http_request = false;

if (window.XMLHttpRequest)
  {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType)
      {
        http_request.overrideMimeType('text/xml');
      }
  }

else if (window.ActiveXObject)
  {
    try
      {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
        try
          {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e) {}
      }
  }

// Ergebnis AJAX verarbeiten und zurückgeben
function insert_result(inner_object, my_script)
  {
    if (http_request)
      {
        http_request.open('GET', my_script);

        http_request.onreadystatechange = function ()
          {
            if (http_request.readyState == 4)
              {
                document.getElementById(inner_object).innerHTML=http_request.responseText;
              }
          };
        http_request.send(null);
      }
  }

// Ergebnis AJAX verarbeiten und zurückgeben
function insert_result_loader(inner_object, my_script, CurrentServer)
  {
    if (http_request)
      {
        document.getElementById(inner_object).innerHTML = '<img src="'+CurrentServer+'/assets/images/ajax-loader-2.gif">';
        http_request.open('GET', my_script);

        http_request.onreadystatechange = function ()
          {
            if (http_request.readyState == 4)
              {
                document.getElementById(inner_object).innerHTML=http_request.responseText;
              }
          };
        http_request.send(null);
      }
  }

/* Alle ankommenden Daten speicher */
var request;

function showDetail(extra)
{
  hide('artikel_zubehoer');
  show('artikel_detail');
  hide('artikel_kraft');

  if(extra == "ja")
  {
    hide('kartei_zubehoer');
    show('kartei_detail');
    hide('kartei_kraft');
  }
}

function showAdditional(extra)
{
  show('artikel_zubehoer');
  hide('artikel_detail');
  hide('artikel_kraft');

  if(extra == "ja")
  {
    hide('kartei_detail');
    show('kartei_zubehoer');
    hide('kartei_kraft');
  }
}

function showKraftstation(extra)
{
  hide('artikel_detail');
  hide('artikel_zubehoer');
  show('artikel_kraft');

  if(extra == "ja")
  {
    hide('kartei_detail');
    hide('kartei_zubehoer');
    show('kartei_kraft');
  }
}

function showPdmDetail(extra)
{
  show('pdm_details');
  hide('pdm_zubehoer');

  if(extra == "ja")
  {
    hide('pdm_kartei_zubehoer');
    show('pdm_kartei_details');
  }
}

function showPdmAdditional(extra)
{
  show('pdm_zubehoer');
  hide('pdm_details');

  if(extra == "ja")
  {
    show('pdm_kartei_zubehoer');
    hide('pdm_kartei_details');


  }
}

function save_bemerkung(bemerkung,CurrentServer)
{
  insert_result('bemerkung',CurrentServer+"/controller/ajax_save_bemerkung.php?bemerkung="+bemerkung);
}

function checkRegister(hinweis,name,value,CurrentServer)
{
  insert_result(hinweis,CurrentServer+"/controller/ajax_user_register.php?"+name+"="+value);
}

function checkbox(element)
{
  document.getElementById(element).checked='checked';
}

function show(element)
{
  document.getElementById(element).style.display='inline';
}

function showBlock(element)
{
  document.getElementById(element).style.display='block';
}

function hide(element)
{
  document.getElementById(element).style.display='none';
}

function checkVoucher(hinweis,value,nummer,summe,CurrentServer)
{
  insert_result_loader(hinweis,CurrentServer+"/controller/ajax_shopcart_voucher.php?code=" + value + "&nummer=" + nummer + "&summe=" + summe, CurrentServer);
}


function validate(nummer,summe,CurrentServer,element_id)
{
  var value = document.getElementById('form_gutschein_' + nummer).value;

  if(value != "")
  {
    document.getElementById(element_id+'_hidden').value = document.getElementById(element_id).value;
    checkVoucher('check_' + nummer, value, nummer, summe, CurrentServer);
  }
}

function lookup(e,inputString,CurrentServer,text)
{
  e = e || event;

  if(e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
  {
    if(inputString.length <= 2)
    {
      $('#suggestions').hide();
    }
    else
    {
      $.post(CurrentServer+"/controller/ajax_article_search.php", {queryString: ""+inputString+""}, function(data)
      {
        if(data.length >0)
        {
          $('#suggestions').show();
          $('#autoSuggestionsList').html(data);
        }
       });
    }
  }
}

function fill(thisValue)
{
  $('#inputString').val(thisValue);
  $('#suggestions').hide();

  document.getElementById('suche').submit();
}


function searchKdNr(CurrentServer)
{
  insert_result_loader('ergebniss', CurrentServer+"/controller/ajax_search_kdnr.php?kdnr=" + document.getElementById('kundennummer').value, CurrentServer);
}

function checkenter(taste, CurrentServer)
{
  if (taste == 13)
  {
    searchKdNr(CurrentServer);
  }
}

function checkFormIntern()
{
  if(document.getElementById('bearbeiter').value == '')
  {
    document.getElementById('bearbeiter').focus();
    alert('Bitte den Bearbeiter angeben !');
  }

  if(document.getElementById('user_country').value == '')
  {
    document.getElementById('user_country').focus();
    alert('Bitte das Land angeben');
  }
}

function check_voucher_enter(taste)
{
  if (taste == 13 && this.value != '')
  {
    document.getElementById('next_field').focus();
  }
}

function trim (zeichenkette)
{
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

function plusSumme(value)
{
  var aktuell   = parseInt(document.getElementById('summe').value);
  var berechnet = (aktuell + parseInt(value));

  document.getElementById('summe').value = berechnet;

  if(berechnet == document.getElementById('menge').value)
  {
    show('button');hide('summe_span');
  }

  if(berechnet != document.getElementById('menge').value)
  {
    hide('button');show('summe_span');
  }
}

function minusSumme(value)
{
  var aktuell   = parseInt(document.getElementById('summe').value);
  var berechnet = (aktuell - parseInt(value));

  document.getElementById('summe').value = berechnet;

  if(berechnet == document.getElementById('menge').value)
  {
    show('button');hide('summe_span');
  }

  if(berechnet != document.getElementById('menge').value)
  {
    hide('button');show('summe_span');
  }
}

function setMenge(value, menge)
{
  document.getElementById('menge').value = (value * menge);
}

function checkbox_nomail ()
{

  if (document.register.nomail.checked == true)
  {
    document.getElementById('email').value = '';
  }
}

function wirklichLoeschen(bezeichnung, id)
{
  var result = confirm(bezeichnung);

  if(result === true)
  {
    show('delete');
    $.add2cart(id,'delete');
  }

	else
	{
		return false;
	}
}

function confirmed_order(CurrentServer, zahlart)
{
	var payment = zahlart;
  insert_result('hinweis',CurrentServer+"/controller/ajax_shopcart_confirmed.php", CurrentServer);

  window.setTimeout("doPayment('" + payment + "')", 2500);
}

function doPayment(zahlart)
{
  var payment = zahlart;

  if(payment == "finanzierung")
	{
		document.finanzierung.submit();
	}

	if(payment == "sofortueberweisung")
	{
		document.sofortueberweisung.submit();
	}
  
  if(payment == "Kreditkarte")
	{
		document.kreditkarte.submit();
	}
}

function newsletter_checkbox(CurrentServer)
{
  var status = 'off';

  if (document.bestellung.newsletter.checked === true)
  {
    status = "on";
  }

  insert_result('checkbox_newsletter',CurrentServer+"/controller/ajax_newsletter_checkin.php?newsletter="+status, CurrentServer);
}

function order_list(order, path, url, bestseller)
{
  var o = order;
  var p = path;
  var u = url.replace("/bestseller","");
  var b = bestseller;

  if (o != 'bestseller')
  {
    location.href=p + '/' + u + '/order/' + o;
  }

  if (o == 'bestseller')
  {
    location.href=p + '/' + b;
  }
}

//Livesupport JS
function livesupport_Chat_reload(chatid)
{
  $.ajax({
    type: 'GET',
    url: '/controller/ajax_livesupport_chat.php',
    cache: false,
    data: 'chatid='+chatid,
    success: function(data) {
      if(data.substr(0,14) == '<!-- wait1 -->') {
        $('#eingabe').hide();
        $('#chatbox').html(data + msgtext[0] + ' <img alt="wait" src="/assets/images/livesupport/loading.gif" />');
        $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);
      }
      else if(data.substr(0,10) == '<!-- wait2') {
        var regex1 = /^<!-- wait2 \{(.+)\}/;
        var match1 = regex1.exec(data);
        $('#chatbox').html(data + msgtext[1].replace('{TEXT}', match1[1]) + ' <img alt="wait" src="/assets/images/livesupport/loading.gif" />');
        $('#eingabe').hide();
        $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);
      }
      else if(data.substr(0,10) == '<!-- wait3') {
        var regex2 = /^<!-- wait3 \{(.+)\}/;
        var match2 = regex2.exec(data);
        $('#chatbox').html(data + msgtext[2].replace('{TEXT}', match2[1]) + ' <img alt="wait" src="/assets/images/livesupport/loading.gif" />');
        $('#eingabe').hide();
        $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);
      }
      else if(data.substr(0,13) == '<!-- done -->') {
        window.clearInterval(ajaxchattimer);
        window.clearInterval(ajaxtypingtimer);
        $('#eingabe').hide();
        $('#chatbox').append(msgtext[3]);
        $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);
        
        if($('#heartbeat').length > 0) {
          $('#heartbeat').html('');
        }
        if($('#bewertung').length > 0) {
          $('#bewertung').show();
        }
      }
      else {
        $('#chatbox').html(data);
        if(data.substr(0,12) == '<!-- new -->') {
          window.focus();
          $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);
          if($('#eingabe').css('display') == 'block') {
            $('#frage').focus();
          }
        }
        if($('#eingabe').length > 0) {
          $('#eingabe').show();
        }
        if($('#heartbeat').length > 0) {
          var regex3 = /<!-- heartbeat \{(\d+)\}\{(\d+)\} -->$/;
          var match3 = regex3.exec(data);
          var heartbeat = match3[1];
          var now = match3[2];

          if(heartbeat != 0) {
            var style = 'color:#808080;font-size:0.8em;';
            if(now - heartbeat >= 120) {
              style = 'color:#A00;font-size:1em;';
              if(lsTimeout === false) {
                lsTimeout = true;
                window.clearInterval(ajaxchattimer);
                if(confirm('Die Verbindung zum Kunden ist bereits seit 2 Minuten unterbrochen.\n\nMöchtest du das Gespräch jetzt beenden?')) { 
                  livesupport_closechat(chatid);
                  window.location.href = '/livesupport/chat/';
                }
                else {
                  ajaxchattimer = window.setInterval('livesupport_Chat_reload('+chatid+')', 5000);
                }
              }
            }
            $('#heartbeat').html('<span style="'+style+'">Letzte Verbindung zum Kunden vor '+Math.floor((now-heartbeat)/60)+'m'+Math.round((now-heartbeat)%60)+'s</span>');
          }
        }
      }
    }
  });
}

function livesupport_Chat_send()
{
  livesupport_boxswitch('cartbox','databox','chatbox');
  
  var frage = $('#frage').val();
  var replace = new Array('\r', '\n', '%0a', '%0d');
  for (var i=0; i<replace.length; i++) {
     frage = frage.replace(replace[i], '');
  }

  if(frage.length > 0)
  {
    livesupport_Chat_post('/controller/ajax_livesupport_chat.php');
  }
  $('#frage').val('').focus();
}

function livesupport_Chat_post(url)
{
  var msg = $('#frage').val().replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
  
  $.ajax({
    type: 'POST',
    url: url,
    cache: false,
    /*timeout: 10000,*/
    data: 'task=add&frage='+msg+'&chatid='+$('#chatid').val(),
    beforeSend: function() {
      $('#frage').css({'background-image':'url(/assets/images/livesupport/loading.gif)', 'background-repeat':'no-repeat', 'background-position':'center'});
    },
    success: function(data) {
      $('#chatbox').html(data);
      $('#chatbox').scrollTop(document.getElementById('chatbox').scrollHeight);    
      $('#frage').val('').css({'background-image':'none'}).focus();
    } /*,
    error: function() { 
      var width = $('#frage').width() - 40;
      var top   = $('#frage').position().top + $('#frage').height() - 20;
      var left  = $('#frage').position().left + Math.floor(($('#frage').width() - width) / 2);
      var html  = '<div id="error" style="top:'+top+'px;left:'+left+'px;width:'+width+'px;"><img src="/assets/icons/error.png" alt="error" /> Senden fehlgeschlagen, bitte erneut versuchen! <img src="/assets/icons/error.png" alt="error" /></div>';
      
      $(html).insertAfter('#frage').fadeOut(10000, function() { $(this).remove(); });
      $('#frage').css({'background-image':'none'}).val(msg).focus();
    }*/
  });
}

function check_chat_enter(e)
{
  e = e || event;
  if (e.keyCode === 13 && !e.ctrlKey)
  {
    livesupport_Chat_send();
    return false;
  }
  else if(e.keyCode === 13 && e.ctrlKey)
  {
    document.chat.frage.value += '\n';
    return true;
  }
  return true;
}

function livesupport_boxswitch(hide1,hide2,show) {
  if(document.getElementById(hide1) && document.getElementById(hide2) && document.getElementById(show))
  {
    hide(hide1);
    hide(hide2);
    showBlock(show);
  }
}

function livesupport_closechat(id) {
  if(http_request)
  {
    http_request.open('GET', '/controller/ajax_livesupport_chat.php?task=closechat&chatid='+id, false);
    http_request.send(null);
  }
}

function livesupport_Chat_accept(id) {
  if(http_request)
  {
    http_request.open('GET', '/controller/ajax_livesupport_chat.php?task=chatstatus&chatid='+id, false);
    http_request.send(null);

    var res = http_request.responseText;

    if(res.substr(0,4) == 'leer')
    {
      window.location.href = '/livesupport/chat/'+id;
      window.name = id;
    }
    else
    {
      if(confirm('Das Gespräch wurde bereits von '+res+' angenommen.\n\nMöchtest Du dem Gespräch hinzugefügt werden?'))
      {
        window.location.href = '/livesupport/chat/'+id;
        window.name = id;
      }
      else
        return false;
    }
  }
}

function livesupport_checkForm()
{
  if(document.getElementById('emailabsenden'))
  {
      if(document.getElementsByName('name')[0].value.length < 1 || document.getElementsByName('frage')[0].value.length < 1 || document.getElementsByName('email')[0].value.length < 1)
      {
          alert(msgtext[5]);
          return false;
      }
  }
  else if(document.getElementsByName('name')[0].value.length < 1 || document.getElementsByName('frage')[0].value.length < 1)
  {
    alert(msgtext[4]);
    return false;
  }
  return true;
}

function livesupport_internStatus(ziel)
{
  if(http_request)
  {
    http_request.open('GET', '/controller/ajax_livesupport_chat.php?task=checkintern&ziel='+ziel, false);
    http_request.send(null);

    if(http_request.responseText.substr(0,4) == 'true')
    {
        alert('Du hast bereits eine Anfrage an '+ziel+' gesendet!');
        return false;
    }
  }
  return true;
}

function livesupport_shopcartModify(chatid, cartid, action)
{
  if(http_request)
  {
    if(action == 'refresh')
    {
      var anzahl = document.getElementById('slot'+cartid).value;
      http_request.open('GET', '/controller/ajax_livesupport_customerinfo.php?task=refresh&id='+cartid+'&anzahl='+anzahl, false);
      http_request.send(null);
    }
    else if(action == 'delete')
    {
      http_request.open('GET', '/controller/ajax_livesupport_customerinfo.php?task=delete&id='+cartid, false);
      http_request.send(null);
    }
    livesupport_shopcartReload(chatid);
  }
}

function addOpenSearch(CurrentServer)
{
  var url = CurrentServer + "/sport-tiedje.xml";
  window.external.AddSearchProvider(url);
}

function livesupport_shopcartReload(chatid)
{
  if(http_request)
  {
    window.clearInterval(ajaxchattimer);
    
    http_request.open('GET', '/controller/ajax_livesupport_customerinfo.php?get=cart&chatid='+chatid, false);
    http_request.send(null);
    document.getElementById('cartbox').innerHTML=http_request.responseText;
    
    ajaxchattimer = window.setInterval('livesupport_Chat_reload('+chatid+')', 5000);
  }
}

function livesupport_checkVoucher(chatid, element_id, code, summe)
{
  if(http_request)
  { 
    http_request.open('GET', '/controller/ajax_shopcart_voucher.php?code=' + code + '&summe=' + summe, false);
    http_request.send(null);
    
    if(http_request.responseText.indexOf('success.gif') != -1)
    {
      livesupport_shopcartReload(chatid);    
    }
    else
    {
      document.getElementById(element_id).innerHTML=http_request.responseText;
    }
  }
}

function livesupport_PlusMinus(sprache)
{
  if(document.getElementById('resPlus_ID_'+sprache))
  {
    if(document.getElementById('resBlock_ID_'+sprache).style.display == 'none')
    {
      document.getElementById('resPlus_ID_'+sprache).src='/assets/icons/minus.png';
      showBlock('resBlock_ID_'+sprache);
    }
    else
    {
      document.getElementById('resPlus_ID_'+sprache).src='/assets/icons/plus.png';
      hide('resBlock_ID_'+sprache);
    }
  }
}

function livesupport_insertResource(target_id, source_id)
{
  var t = parent.document.getElementById(target_id);
  var s = document.getElementById(source_id);
  
  if(t != null && s != null)
  {
    t.value += s.innerHTML;

    var len = t.value.length;

    if(t.setSelectionRange)
    {
      t.setSelectionRange(len,len);
      t.focus();
    }
    else if(t.createTextRange)
    {
      var rn = t.createTextRange();
      rn.moveStart('character',len);
      rn.select();
    }
  }
}

function livesupport_newAjax()
{
  var ajax = false;

  if(window.XMLHttpRequest)
  {
    ajax = new XMLHttpRequest();
    if (ajax.overrideMimeType)
    {
      ajax.overrideMimeType('text/xml');
    }
  }
  else if(window.ActiveXObject)
  {
    try
    {
      ajax = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {}
    }
  }
  return ajax;
}

function livesupport_typingTimer(chatid, who)
{
  if(who == '')
    who = 'kunde';
  
  if(isTyping === false)
  {
    lsTypingUpdate_ajax.open('GET', '/controller/ajax_livesupport_chat.php?typing=update&status=1&chatid='+chatid+'&who='+who, true);
    lsTypingUpdate_ajax.send(null);
    isTyping = true;
  }
  
  if (typingTimeout != undefined) 
    clearTimeout(typingTimeout);

  typingTimeout = setTimeout( function() {   
    lsTypingUpdate_ajax.open('GET', '/controller/ajax_livesupport_chat.php?typing=update&status=0&chatid='+chatid+'&who='+who, true);
    lsTypingUpdate_ajax.send(null);
    isTyping = false;
  }, 750);
}

function livesupport_typingStatus(chatid, who)
{
  if(who == '')
    who = 'kunde';
  
  if(lsTypingStatus_ajax)
  {
    lsTypingStatus_ajax.open('GET', '/controller/ajax_livesupport_chat.php?typing=read&who='+who+'&chatid='+chatid, true);
    lsTypingStatus_ajax.onreadystatechange = function ()
    {
      if (lsTypingStatus_ajax.readyState == 4)
      {
        if(lsTypingStatus_ajax.responseText == '1')
          document.getElementById('typingstatus').innerHTML = '<img src="/assets/images/livesupport/typing.gif" alt="typing" /> ' + msgtext[6] + '...';
        else
          document.getElementById('typingstatus').innerHTML = '';
      }
    }
    lsTypingStatus_ajax.send(null);
  }
}

function mobile_klappBox(element)
{
  if(document.getElementById(element).style.display=='none')
  {    
    document.getElementById(element+'_plus').src='/assets/icons/minus.png';
    showBlock(element);
  }
  else
  {
    document.getElementById(element+'_plus').src='/assets/icons/plus.png';
    hide(element);
  }
}

function livesupport_hoverStarIn(id) {
  var r = id.substring(1,2);
  var s = id.substring(6,7);

  $('#info'+r+'').html($('#'+id+'').attr('rel'));
  if($('#'+id+'').attr('src') == '/assets/images/livesupport/star-white.png') {
    for(var i=1; i<=s; i++) {
      $('#r'+r+'star'+i+'').attr('src', '/assets/images/livesupport/star-gold.png');
    }
  }
  else {
    for(var i=5; i>s; i--) {
      if($('#r'+r+'star'+i+'').attr('src') == '/assets/images/livesupport/star-gold.png') {
        $('#r'+r+'star'+i+'').attr('src', '/assets/images/livesupport/star-white.png');
      }
    }
  }
}

function livesupport_hoverStarOut(id) {
  var r = id.substring(1,2);

  if($('#rating'+r+'').val() != 0) {
    $('#info'+r+'').html($('#r'+r+'star'+$('#rating'+r+'').val()+'').attr('rel'));

    for(var i=5; i>1; i--) {
      $('#r'+r+'star'+i+'').attr('src', '/assets/images/livesupport/star-white.png');
    }

    for(var i=1; i<=$('#rating'+r+'').val(); i++) {
      $('#r'+r+'star'+i+'').attr('src', '/assets/images/livesupport/star-gold.png');
    }
  }
  else {
    $('#info'+r+'').html('');
    for(var i=5; i>=1; i--) {
      $('#r'+r+'star'+i+'').attr('src', '/assets/images/livesupport/star-white.png');
    }
  }
}

function livesupport_clickStar(id) {
  $('#rating'+id.substring(1,2)+'').val(id.substring(6,7));
}

function livesupport_checkRating() {
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  
  if(($('#emailverlauf').attr('checked') === true || $('#newsletter').attr('checked') === true) && ($('#email').val() == '' || !filter.test($('#email').val())))
  {
    $('#mailerror').show();
    $('#email').css('border', '1px dotted #cc0033');

    return false;
  }
 
  $('#bewertung').hide();
  
  return true;
}

function kasse_form_klick_close_rechnungsanschrift () {
  $('#abweichende_rechnungsanschrift :input[name!="liefer_country"]').each(function(){$(this).val('');});
  $('#abweichende_rechnungsanschrift').hide();
  $('#wk_title_rechnungsanschrift').hide();
  $('#link_rechnungsanschrift').show();
  $('#wk_title_lieferanschrift_alt').hide();
  $('#wk_title_lieferrechnungsanschrift').show();
  $('#auswahl_lieferland').show();  
  $('#auswahl_land').hide();  
}
function kasse_form_klick_rechnungsanschrift () {
  $('#abweichende_rechnungsanschrift').show();
  $('#link_rechnungsanschrift').hide();
  $('#wk_title_lieferanschrift_alt').show();
  $('#wk_title_lieferrechnungsanschrift').hide();
  $('#wk_title_rechnungsanschrift').show();
  
  if($('#feld_firma').css('display') != 'none') {
    $('#feld_liefer_firma').show();
  }
  
  $('#anrede2').val($('#anrede').val());
  $('#liefer_firma').val($('#firma').val());
  $('#liefer_name').val($('#name').val());
  $('#liefer_strasse').val($('#strasse').val());
  $('#liefer_plz').val($('#plz').val());
  $('#liefer_ort').val($('#ort').val());
  $('#liefer_telefon').val($('#telefon').val());
  $('#hinweis_versandkosten').hide();
  $('#auswahl_lieferland').hide();  
  $('#auswahl_land').show();  
}

function uncheckBoxes(id) {
  $('input[name="zahlart"]:radio').each(function(){
      $(this).attr('checked', false);
      
      if($.isFunction($(this).checkboxradio)) {
        $(this).checkboxradio('refresh');
      }
  });
  $('#'+id+'').attr('checked', 'checked');
  
  if($.isFunction($('#'+id+'').checkboxradio)) {
    $('#'+id+'').checkboxradio('refresh');
  }
}

function scrollArticlePic(direction) {
  var aPics = $('#bilder_swipe div[class="bild_div"]');
  
  if(direction == 'fwd') {
    for(var i=0; i<=aPics.length; i++)
    {
      if($(aPics[i]).css('display') != 'none' && i < aPics.length-1) {
        if(i >= aPics.length-2) {
          $('#next').attr('src', '/assets/images/mobile/next_off.png');
        }
        $('#prev').attr('src', '/assets/images/mobile/prev_on.png');
        
        $(aPics[i]).hide();
        $(aPics[i+1]).show();
        break;
      }
    }
  }
  else {
    for(var k=aPics.length-1; k>=0; k--)
    {
      if($(aPics[k]).css('display') != 'none' && k > 0) {
        if(k == 1) {
          $('#prev').attr('src', '/assets/images/mobile/prev_off.png');
        }
        $('#next').attr('src', '/assets/images/mobile/next_on.png');
        
        $(aPics[k]).hide();
        $(aPics[k-1]).show();
        break;
      }
    }
  }
}

function getSetSummeMobile(value, addsub) {
  var berechnet;
  var aktuell = parseInt($('#summe').val());
  if(addsub == '+') {
    berechnet = (aktuell + parseInt(value));
  }
  else {
    berechnet = (aktuell - parseInt(value));
  }

  $('#summe').val(berechnet);

  if(berechnet == $('#menge').val()) {
    $('#button').button('enable');
    $('#summe_span').hide();
  }
  else {
    $('#button').button('disable');
    $('#summe_span').show();
  }
}

function changeRechnungsland () {  
  if($('#wk_title_rechnungsanschrift').css('display') == 'none') {
    $('#hinweis_versandkosten').show();
  }
  if($('#wk_title_rechnungsanschrift').css('display') != 'none') {
    $('#hinweis_versandkosten_abweich_liefer').show();
  }
}
