﻿// Copyright Basement.nl, 2009

function btnNewClick()
{
  if (confirm("are you sure you want to clear the test?"))
  {
    document.frmMain.list_plain.value = "";
  }
  document.frmMain.list_plain.focus();
}

function btnOpenClick()
{
  document.frmMain.action = "open.php";
  document.frmMain.submit();
}

function btnSaveClick()
{
  var LOldAction = document.frmMain.action;
  document.frmMain.action = "action/process_save_to_teach.php";
  document.frmMain.submit();
  // Restore action
  document.frmMain.action = LOldAction;
}

function btnOpenInWrtsClick()
{
  var LOldAction = document.frmMain.action;
  document.frmMain.action = "action/process_save_to_wrts.php";
  document.frmMain.target = "_blank";
  document.frmMain.submit();
  // Restore action
  document.frmMain.target = "_self";
  document.frmMain.action = LOldAction;
}

function btnHelpClick()
{
  document.frmMain.action = "help.php";
  document.frmMain.submit();
}

function btnPrintClick()
{
  window.open("", "LWinPrint", "width=600,height=300,scrollbars=1,resizable=1");
  var LOldAction = document.frmMain.action;
  document.frmMain.action = "print.php";
  document.frmMain.target = "LWinPrint";
  document.frmMain.submit();
  // Restore action
  document.frmMain.target = "_self";
  document.frmMain.action = LOldAction;
}

function btnSymbolClick()
{
  alert("symbols only work in the edit window");
}

function btnTestClick()
{
  var InputText = document.frmMain.list_plain.value;
  InputText = InputText.replace(/^\s*|\s*$/g,"");
  if (InputText === "")
  {
    alert("you didn't enter any questions.");
    document.frmMain.list_plain.focus();
  }
  else if (InputText.indexOf("=") == -1)
  {
    alert("use the symbol '=' to separate questions from their answers.");
    document.frmMain.list_plain.focus();
  }
  else
  {
    document.frmMain.submit();
  }
}

function AjaxCallback(AResponseText)
{
  var LResponseArray = [];
  if (AResponseText !== "")
  {
    LResponseArray = AResponseText.split("|");
    // waardering 4.0 (aantal stemmen: 3) --> je stem is gewijzigd|3|3.0
    document.getElementById("idVote").innerHTML = "rank " + LResponseArray[2] + " (votes: " + LResponseArray[1] + ")";
    document.getElementById("idVoteResult").innerHTML = LResponseArray[0];
  }
}

function btnVoteClick(AListID, AVote)
{
  AjaxRequest("action/process_vote.php?chapter=" + encodeURIComponent(AListID) + "&vote=" + encodeURIComponent(AVote), null, AjaxCallback);
}

function btnUpdateClick()
{
  if (confirm("save the changes?"))
  {
    document.frmMain.action = "action/process_list_update.php";
    document.frmMain.submit();
  }
}

function btnDeleteClick()
{
  if (confirm("are you sure you want to delete this test?"))
  {
    document.frmMain.action = "action/process_list_delete.php";
    document.frmMain.submit();
  }
}

function EditableContentClick(AClear, ADiv, AName, AType, AClass)
{
  var AContent = "";
  
  document.getElementById(ADiv).onclick = null;
  document.getElementById(ADiv).className = "";
  
  if (AClear === false)
  {
    AContent = document.getElementById(ADiv).innerHTML;
  }

  if (AType == "input")
  {
    document.getElementById(ADiv).innerHTML = '<input class="' + AClass + '" name="' + AName + '" value="' + AContent + '" size="100" maxlength="100" type="text">';
  }
  else
  {
    document.getElementById(ADiv).innerHTML = '<textarea class="' + AClass + '" name="' + AName + '">' + AContent + '</textarea>';
  }

  document.getElementsByName(AName)[0].select();
  document.getElementsByName(AName)[0].focus();
}

