function clearText(thefield)
{
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

$(document).ready(function() {

  //PRODUCT Uitgebreide informatie show/hide
  $('#uitgebreid-container').hide();

  $('a#uitgebreid-toggle').click(function() {
    $('#uitgebreid-container').toggle(100);
    return false;
  });

  //PRODUCT Therapeutische informatie show/hide
  $('#therapeutisch-container').hide();

  $('a#therapeutisch-toggle').click(function() {
    $('#therapeutisch-container').toggle(100);
    return false;
  });

  //Login pop-up genereren
  $("#LoginLink, #LoginLink2").colorbox({}, function() {

    $('[name=username]').focus();

    $('#LoginNowLink').click(function() { doLogin($('[name=username]').val(), $('[name=password]').val(), $('input:checkbox:checked').val()); });

    $('[name=username],[name=password]').bind('keypress', function(e) {
      var code = (e.keyCode ? e.keyCode : e.which);
      if (code == 13) {
        doLogin($('[name=username]').val(), $('[name=password]').val(), $('input:checkbox:checked').val());
      }
    });

  });

  //Login pop-up genereren
  $("#PopupLink").colorbox({ iframe: true, innerHeight: '485px', innerWidth: '958px' }, function () {
  });

  //Delete functie
  $(".deleteLink").click(function() {
    id = $(this).attr('href')

    $.ajax({
      url: "include/inc_functies_ajax.asp",
      data: "f=delete&object=" + $("#deleteWhat").val() + "&id=" + id,
      cache: false,
      success: function() {
        $('#' + id).find("td").css("background-color", "#bf2e1b");
        $('#' + id).find("td").fadeOut(500, function() { $(this).parent().remove(); });
        $('#' + id).fadeOut(500, function() {
          $(this).css("display", "none");
          window.location.reload(true);
        });
      }
    });
  });

  $('.deleteLink').confirm({
    msg: "",
    timeout: 5000,
    dialogShow: 'fadeIn',
    dialogSpeed: 'slow',
    buttons: {
      ok: 'Ja',
      cancel: 'Nee',
      wrapper: "<span class='deletechoice'></span>",
      separator: " / "
    }
  });

  //Inloggen
  function doLogin(sU, sP, sS) {
    $.ajax({
      url: "/include/inc_functies_ajax.asp",
      type: "POST",
      data: "f=dologin&u=" + sU + "&p=" + sP + "&s=" + sS,
      dataType: 'jsonp',
      cache: false,
      success: function(rv) {
        //Login succesvol
        if (rv == "1") {
          location.reload();
        }
        else if (rv == "2") {
          location = "/mijn-gegevens";
        }
        else if (rv == "3") {
          location = "/niet-goedgekeurd";
        }
        //Login niet succesvol
        else {
          $('[name=username]').css("background-color", "#ffc5c5");
          $('[name=password]').css("background-color", "#ffc5c5");
        }

      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(xhr.responseText);
      }
    });

  }

});
