var currentTab= null;

$(function() {
  $(".sandbox-result-content").each(function() {
    $(this).contents().find("html").html("<html><body><p>Loading...</p></body></html>");
  });
  
  $(".sandbox-doc").keyup(function() {
    makeRequest();
  });
  $(".parameter").click(function() {
    makeRequest();
  });
  $("#sandbox-tabs").tabs({
    selected: 0,
    show: function(event, ui) {
      currentTab= ui.panel;
      makeRequest();
    }
  });
  
  $("#sandboxParameters").removeAttr("class");
  $("#sandboxParameters>h3").removeAttr("class");
  $("#sandboxParameters>div").removeAttr("class");
  $("#sandboxParameters").accordion({
    autoHeight: false,
    collapsible: true
  });
});

function makeRequest() {
  $(".sandbox-result-content").each(function() {
    $(this).contents().find("html").html("<html><body><p>Loading...</p></body></html>");
  });
  $("#sandbox-form").attr("target", $(currentTab).attr("id"));
  $("#outputType").val($(".sandbox-tab-outputType", currentTab).val());

  $("#sandbox-form").submit();
}
