MediaWiki:Gadget-cite.js

From WikiLectures

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* <pre> */

/* ============== Citation ==========================================
   author:         [[User:Slepi]]
   date:           04/2011, last update 03/2012
   documentation:  [[MediaWiki:Gadget-citation.js/documentation]]
   description:    this script helps to create bibliographical data
   ==================================================================
*/

/* ======================== Texts =========================================== */

baseTextCitace = '<p><span style="float: right;"><a href="#" onclick="return createCitationForm();">Reset</a>&nbsp;•&nbsp;<a href="#" onclick="return closeCitationBox()">Close</a></span></p><h2>Citation</h2>';

/* ======================== auxiliary functions ============================= */

// FUNCTION TO GET COORDINATES OF THE WINDOW
// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getScrollXY() {
  // coordinates
  var scrOfX = 0, scrOfY = 0;

  // Netscape
  if( typeof( window.pageYOffset ) == 'number' ) {
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;

  // DOM
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;

  // IE6
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  // output
  return [ scrOfX, scrOfY ];
}

// FUNCTION PROCESSING CITATIONS AND INSTERTING THEM INTO TEXT
// parameter "formular": form link
// parameter "typ": type of the used source
function zpracovatCitace(formular, typ) {
  // process ISSN
  if(formular.elements["issn"]) {
    if(formular.elements["issn"].value == "")
      formular.elements["issn"].value = "-";
  }

  // process ISBN
  if(formular.elements["isbn"]) {
    if(formular.elements["isbn"].value == "")
      formular.elements["isbn"].value = "-";
  }

  // output beginning
  var output = "{{Cite\n| type = " + typ + "\n";

  // inserting info into the teplate
  var i = 0;
  for(i=0; i<formular.elements.length; i++) {

    // text fields
    if(formular.elements[i] && formular.elements[i].type == "text" && formular.elements[i].value != "") {
      // info by user
      vlozenaInfo = trim(formular.elements[i].value);

      // last character - shouldn't be a period
      viPosledniZnak = vlozenaInfo.charAt(vlozenaInfo.length - 1);
      if(viPosledniZnak == "." || viPosledniZnak == ",") vlozenaInfo = vlozenaInfo.substring(0, vlozenaInfo.length-1);

      // output
      output += "| " + formular.elements[i].id + " = " + vlozenaInfo + "\n";

    // checkbox (e.g. "others")
    } else if (formular.elements[i] && formular.elements[i].type == "checkbox") {
      if(formular.elements[i].checked == true)
        output += "| " + formular.elements[i].id + " = yes\n";
    }
  }

  // end of the template
  output += "}}\n";

  // new citation instead of the strange characters...
  novyOutput = document.getElementById("wpTextbox1").value;
  novyOutput = novyOutput.replace("--//--//--", output);
  document.getElementById("wpTextbox1").value = novyOutput;

  // close gadget
  closeCitationBox();

  return false;
}

// FUNCTION INSERTING CHARACTERS MESS
// parameter "textovePole": ID of the changed textarea
function vlozitTextAreaSpletZnaku(textovePole) {

  pridanyText = "--//--//--";

  // find ID
  if(!document.getElementById(textovePole)) return;
  textovePole = document.getElementById(textovePole);

  // Microsoft Internet Explorer
  if (document.selection) {
    textovePole.focus();

    // insert
    oblastVlozeni = document.selection.createRange();
    oblastVlozeni.text = pridanyText;
  }

  // other browsers
  else if (textovePole.selectionStart || textovePole.selectionStart == 0) {

    // insert and update text
    startText = textovePole.selectionStart;
    endText = textovePole.selectionEnd;
    aktualniText = textovePole.value;
    textovePole.value = aktualniText.substring(0, startText);
    textovePole.value += pridanyText;
    textovePole.value += aktualniText.substring(endText, aktualniText.length);
  }

  // old browsers: add to end
  else {
    textovePole.value += pridanyText;
  }
}

// FUNCTION PROCESSING THE COMPULSORY PARAMETERS OF THE TEMPLATE
// parameter "poleParametru": field with all the compulsory parameters
function classPovinneCitace(poleParametru) {
  for (i in poleParametru) {
    document.getElementById(poleParametru[i]).className += " compulsoryParameterCite";
  }
}

/* =================== Main functions to view form ================ */

// FUNCTION CREATING CITE BUTTON TO THE TOOLBAR
function createCitationButton() {

  // end when not editing
  if(wgAction == "view" || !document.getElementById("wpTextbox1")) return;

  // older browsers not supported
  if (!window.XMLHttpRequest) return;

  // add CSS style
  importStylesheet("MediaWiki:Gadget-cite.css");

  // create div for overlay
  overlayDiv = document.createElement("div");
  overlayDiv.className = "overlay_div_cit";
  overlayDiv.id = "overlay_div_cit";

  // position and scrolling fixation
  kam = getScrollXY();
  overlayDiv.style.top = kam[0];
  overlayDiv.style.position = "fixed";

  // add div to the page
  document.body.appendChild(overlayDiv);

  // block with text
  contentDiv = document.createElement("div");
  contentDiv.className = "content_div_cit";
  contentDiv.id = "content_div_cit";

  // position of the block
  contentDiv.style.top = 20 + kam[0];
  contentDiv.style.position = "fixed";

  // add block to the page
  document.body.appendChild(contentDiv);
}

// FUNCTION CLOSING CITATION AFTER CLICKING TO "CLOSE"
function closeCitationBox() {
  document.getElementById('overlay_div_cit').style.display = 'none';
  document.getElementById('content_div_cit').style.display = 'none';
  document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace('--//--//--', '');
  document.forms['editform'].elements['wpTextbox1'].focus();

  return false;
}

// FUNCTION CREATING A FORM ROW
// parameter "popis": description (label) of the field)
// parameter "parametr": parameter of the template Cite
// parameter "typ": type of entry (text, checkbox, etc.)
function createCitationFormRow(popis, parametr, typ) {

  // default entry type: text
  if(!typ) typ =  "text";

  // create row
  output = '<div><p><label for="' + parametr + '">' + popis + ':&nbsp;</label><input type="' + typ + '" name="' + parametr + '" id="' + parametr +'" onChange="fieldChanged(\'' + parametr + '\');" /></p></div>';

  // output
  return output;
}

// FUNCTION RETURNING ROW FOR EXACT PARAMETER OF THE TEMPLATE CITE
// parameter "parametr": template Cite parameter
function createCitationInput(parametr){
  // array of rows
  output = {

  // authors
  "corporation" : createCitationFormRow("Name of corporation", "corporation"),
  "surname1" : createCitationFormRow("Surname of the first author", "surname1"),
  "name1" : createCitationFormRow("Name of the first author", "name1"),
  "surname2" : createCitationFormRow("Surname of the second author", "surname2"),
  "name2" : createCitationFormRow("Name of the second author", "name2"),
  "surname3" : createCitationFormRow("Surname of the third author", "surname3"),
  "name3" : createCitationFormRow("Name of the third author", "name3"),
  "others" : createCitationFormRow("Others", "others", "checkbox"),
  "author_of_collection" : createCitationFormRow("Author of the collection", "author_of_collection"),
  "responsibility" : createCitationFormRow("Author(s)", "responsibility"),
  "institution" : createCitationFormRow("Institution", "institution"),
  "institute" : createCitationFormRow("Institute", "institute"),
  "surname" : createCitationFormRow("Surname of the pedagogue", "surname"),// surname for lecture
  "name" : createCitationFormRow("Name of the pedagogue", "name"),// name for lecture

  // titles
  "title" : createCitationFormRow("Title", "title"),
  "article" : createCitationFormRow("Title of the article", "article"),
  "source_name" : createCitationFormRow("Title", "source_name"),
  "subtitle" : createCitationFormRow("Subtitle", "subtitle"),
  "journal" : createCitationFormRow("Journal", "journal"),
  "serial_publication" : createCitationFormRow("Title of the serial publication", "serial_publication"),
  "label" : createCitationFormRow("Label of the document", "label"),
  "collection" : createCitationFormRow("Title of the collection", "collection"),
  "document" : createCitationFormRow("Title of the document", "document"),
  "topic" : createCitationFormRow("Lecture topic", "topic"),

  // descriptions and publishers
  "url" : createCitationFormRow("Available from WWW", "url"),
  "edition" : createCitationFormRow("Edition", "edition"),
  "location" : createCitationFormRow("Location (city)", "location"),
  "country" : createCitationFormRow("Country", "country"),
  "publisher" : createCitationFormRow("Publisher", "publisher"),
  "year" : createCitationFormRow("Year", "year"),
  "date_of_revision" : createCitationFormRow("Last revision date", "date_of_revision"),
  "cited" : createCitationFormRow("Date of citation", "cited"),
  "the_year" : createCitationFormRow("Volume (year)", "the_year"),
  "number" : createCitationFormRow("Issue number", "number"),
  "range" : createCitationFormRow("Number of pages", "range"),
  "series" : createCitationFormRow("Series", "series"),
  "volume" : createCitationFormRow("Volume", "volume"),
  "chapter" : createCitationFormRow("Chapter number", "chapter"),
  "name_of_chapter" : createCitationFormRow("Title of the chapter", "name_of_chapter"),
  "pages" : createCitationFormRow("Cited pages", "pages"),
  "notes" : createCitationFormRow("Notes", "notes"),
  "isbn" : createCitationFormRow("ISBN", "isbn"),
  "issn" : createCitationFormRow("ISSN", "issn"),
  "pmid" : createCitationFormRow("PMID", "pmid"),
  "doi" : createCitationFormRow("DOI", "doi"),
  "subject" : createCitationFormRow("Lecture subject", "subject"),
  "specialization": createCitationFormRow("Subject specialization", "specialization"),
  "faculty" : createCitationFormRow("Faculty", "faculty"),
  "university" : createCitationFormRow("University or school", "university"),
  "date" : createCitationFormRow("Date of the lecture", "date") // date for lecture
  };

  // output
  return output[parametr];
}

// FORM FOR CITATION
function createCitationForm() {

  // character mess for further template
  if(document.getElementById('wpTextbox1').value.indexOf('--//--//--') == -1) vlozitTextAreaSpletZnaku("wpTextbox1");
  document.getElementById('wpTextbox1').blur();

  overlayDiv = document.getElementById("overlay_div_cit");
  contentDiv = document.getElementById("content_div_cit");

  // show div overlay_div_cit
  overlayDiv.style.display = "block";

  // show div overlay_div_cit
  contentDiv.style.display = "block";
  contentDiv.style.fontSize = "small";

  // text
  contentDiv.innerHTML = baseTextCitace;
  contentDiv.innerHTML += "<p>This tool helps you create proper citation of used literature. After filling in the form the template Cite will be generated and inserted into the article. Please, choose which source would you like to cite:</p>";

  // basic menu
  contentDiv.innerHTML +=
    "<h4>Books and collections</h4>" +
    "<ul>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('book');\">" +
    "book</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('chapter');\">" +
    "chapter of a book (the same author)</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('collection');\">" +
    "chapter of a book (other author), collection</a></li>" +
    "</ul>" +
    "<h4>Articles, publications and periodicals</h4>" +
    "<ul>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('article');\">" +
    "article</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('academic_publication');\">" +
    "academic publication</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('serial_publication');\">" +
    "serial publication</a></li>" +
    "</ul>" +
    "<h4>Electronic sources</h4>" +
    "<ul>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('web');\">" +
    "webpage or website</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('cd');\">" +
    "CD, DVD and others</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('db');\">" +
    "database</a></li>" +
    "</ul>" +
    "<h4>Official publications</h4>" +
    "<ul>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('company_publication');\">" +
    "company publication</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('legislative_publication');\">" +
    "legislative material, laws, etc.</a></li>" +
    "<li>" +
    "<a href=\"#\" onclick=\"return createCitationTypeForm('standard');\">" +
    "standard, patent</a></li>" +
    "</ul>" +
    "<h4>Others</h4>" +
    "<ul>" +
    "<li>" +
    "<a href=\"#\"# onclick=\"return createCitationTypeForm('lecture');\">" +
    "lecture at the university</a></li>" +
    "</ul>";

  // field for automatic generating from PMID
  contentDiv.innerHTML +=
    "<h4>Quick citations</h4>" +
    "<h5>PMID</h5>" +
    '<form onsubmit="return false;" id="formPMID">' +
    '<p>Here you can generate a citation using only PMID of the article in the PubMed database!</p>' +
    '<label for="pmid">PMID:</label>&nbsp;<input type="text" id="pmid" name="pmid" />&nbsp;' +
    '<input type="button" onclick="zpracovatPMID(document.forms[\'formPMID\'].elements[\'pmid\'].value)" value="Get citation from PMID" />&nbsp;<span id="pmid_wait"><img src="' + wgServer + '/skins/common/images/ajax-loader.gif" width="20" height="20" />&nbsp;Please wait&hellip;</span>' +
    '</form><br />';
    document.getElementById("pmid_wait").style.visibility= "hidden";
    document.getElementById("wp_wait").style.visibility= "hidden";
  return false;
}

// FUNCTION FOR PROCESSING PMID
var xmlPMID;

function zpracovatPMID(formularX) {
  document.getElementById("pmid_wait").style.visibility= "visible";
  pmid = formularX;
  exptest = /^\d+$/;

  if (exptest.test(pmid) == true) {
    var urlPMID = "http://www.wikilectures.eu/extensions/citace/pmid_en.php?pmid=" + pmid;
    getXMLHttpRequest("xmlPMID", urlPMID, "zpracovatPMIDRequest");
    return false;
  } else {
    document.getElementById("pmid_wait").style.visibility= "hidden";
    window.alert("This is not a valid PMID. Please, check it or try it again.");
    document.forms["formPMID"].elements["pmid"].value = "";
    return false;
  }

}

// FUNCTION CREATING CITATION FORM PMID
function zpracovatPMIDRequest() {
   if (xmlPMID.readyState==4) {// 4 = "loaded"
    if (xmlPMID.status==200) {// 200 = OK
      var output = xmlPMID.responseText; // srver response

      if (output.indexOf("{{") == -1) {
        document.getElementById("pmid_wait").style.visibility= "hidden";
        window.alert("This is not a valid PMID. Please, check it or try it again.");
        document.forms["formPMID"].elements["pmid"].value = "";
        return false;
      }

      // insert into article
      novyOutput = document.getElementById("wpTextbox1").value;
      novyOutput = novyOutput.replace("--//--//--", output);
      document.getElementById("wpTextbox1").value = novyOutput;

      // close gadget
      document.getElementById("pmid_wait").style.visibility= "hidden";
      closeCitationBox();
      return false;

    } else {
      return false;
    }
  }
}

// FUNCTION CREATING CERTAIN FORM FOR EVERY TYPE OF SOURCE
// parameter "typ": type of used source
function createCitationTypeForm(typ) {

  // citation box
  contentDiv = document.getElementById("content_div_cit");

  // beginning of citation
  output = '<h3>Type of citation: ' + typ.replace("_", " ") + '</h3>';

  // help
  output += '<p>Please, fill in fields of this form. Always provide authors of the source. All compulsory fields have red border. After clicking on <b>Create citation</b> the citation template will be generated and insrted into article on the place of the cursor.<br /><small>If you chose wrong type of source, you can restart this form clicking on <b>Restart</b> at the top. Link <b>Close</b> will close this window and return you to article edit page.</small></p>';

  // beginning of the form
  // chapter = book, serial_publication = article
  output += '<form onsubmit="return zpracovatCitace(this, \'' + (typ == "chapter" ? "book" : (typ == "serial_publication" ? "article" : typ)) + '\');">';

  // authors
  switch(typ) {
  case "book" :
  case "chapter" :
  case "collection" :
  case "article" :
  case "serial_publication" :
  case "web" :
  case "cd" :
  case "company_publication" :
  case "academic_publication" :
    output += '<div><fieldset><legend>Authors</legend>';
    output += '<div id="citKorporaceForm">';
    output += createCitationInput("corporation");
    output += '</div>';
    output += createCitationInput("surname1");
    output += createCitationInput("name1");
    output += '<div id="citDalsiAutoriForm">';
    output += createCitationInput("surname2");
    output += createCitationInput("name2");
    output += createCitationInput("surname3");
    output += createCitationInput("name3");
    output += '</div>';
    output += createCitationInput("others");
    output += '<div id="citOdkaz1AutoriForm"><a href="#" onclick="return false;">&rarr;&nbsp;more authors and other options</a></div>';
    output += '<div id="citOdkaz2AutoriForm"><a href="#" onclick="return false;">&larr;&nbsp;one author, hide options</a></div>';
    output += '</fieldset></div>';
    break;
  default :
    break;
  }


  // other parameters
  switch(typ) {

    // book types
    case "collection" :
      output += '<div><fieldset><legend>Title of the publication or chapter</legend>';
      output += createCitationInput("title");
      output += createCitationInput("subtitle");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Collection or book information</legend>';
      output += createCitationInput("collection");
      output += createCitationInput("author_of_collection");
      output += '<div class="prefsectiontip">Recommended: "SURNAME, Name". Inicials please write without punctuation.</div>';
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Availability</legend>';
      output += createCitationInput("url");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Edition</legend>';
      output += createCitationInput("edition");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Publisher details and description</legend>';
      output += createCitationInput("location");
      output += createCitationInput("publisher");
      output += createCitationInput("year");
      output += createCitationInput("range");
      output += createCitationInput("series");
      output += createCitationInput("volume");
      output += createCitationInput("pages");
      output += createCitationInput("notes");
      output += createCitationInput("isbn");
      output += '</fieldset></div>';
      break;
    case "chapter" :
    case "company_publication" :
      output += '<div><fieldset><legend>Information about chapter</legend>';
      output += createCitationInput("chapter");
      output += createCitationInput("name_of_chapter");
      output += '</fieldset></div>';
    case "book" :
      output += '<div><fieldset><legend>Title</legend>';
      output += createCitationInput("title");
      output += createCitationInput("subtitle");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Availability</legend>';
      output += createCitationInput("url");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Edition</legend>';
      output += createCitationInput("edition");
      output += '</fieldset></div>';
      output += '<div><fieldset><legend>Publisher details and description</legend>';
      output += createCitationInput("location");
      output += createCitationInput("publisher");
      output += createCitationInput("year");
      output += createCitationInput("range");
      output += createCitationInput("series");
      output += createCitationInput("volume");
      output += createCitationInput("pages");
      output += createCitationInput("notes");
      output += createCitationInput("isbn");
      output += '</fieldset></div>';
      break;

    // article types
    case "serial_publication" :
      output += '<div><fieldset><legend>Publication</legend>';
      output += createCitationInput("serial_publication");
      output += '</fieldset></div>';
    case "article" :
      output += '<div><fieldset><legend>Article/publication</legend>';
      output += createCitationInput("article");
      output += '</fieldset></div>';
      if (typ == "article") {
        output += '<div><fieldset><legend>Journal information</legend>';
        output += createCitationInput("journal");
      } else if (typ == "serial_publication") {
        output += '<div><fieldset><legend>Details</legend>';
      }
      output += createCitationInput("url");
      output += createCitationInput("year");
      output += createCitationInput("the_year");
      output += createCitationInput("volume");
      output += createCitationInput("number");
      output += createCitationInput("pages");
      output += createCitationInput("notes");
      output += createCitationInput("issn");
      output += '</fieldset></div>';
      break;

    // electronic sources
    case "db" :
      output += '<div><fieldset><legend>Authors and responsibility</legend>';
      output += createCitationInput("responsibility");
      output += '</fieldset></div>';
    case "web" :
      output += '<div><fieldset><legend>Availability</legend>';
      output += createCitationInput("url");
      output += '</fieldset></div>';
    case "cd" :
      output += '<div><fieldset><legend>Source details</legend>';
      output += createCitationInput("source_name");
      output += createCitationInput("subtitle");
      output += createCitationInput("publisher");
      output += createCitationInput("year");
      output += createCitationInput("date_of_revision");
      output += createCitationInput("cited");
      output += '</fieldset></div>';
      break;

    // legislative document
    case "legislative_publication" :
      output += '<div><fieldset><legend>Legislative publication details</legend>';
      output += createCitationInput("country");
      output += createCitationInput("institution");
      output += createCitationInput("document");
      output += createCitationInput("collection");
      output += createCitationInput("year");
      output += createCitationInput("notes");
      output += createCitationInput("pages");
      output += createCitationInput("url");
      output += '</fieldset></div>';
      break;

    // standard
    case "standard" :
      output += '<div><fieldset><legend>Standard</legend>';
      output += createCitationInput("label");
      output += createCitationInput("source_name");
      output += createCitationInput("location");
      output += createCitationInput("institution");
      output += createCitationInput("year");
      output += createCitationInput("notes");
      output += createCitationInput("pages");
      output += createCitationInput("url");
      output += '</fieldset></div>';
      break;

    // academic literature
    case "academic_publication" :
      output += '<div><fieldset><legend>Academic publication details</legend>';
      output += createCitationInput("source_name");
      output += createCitationInput("subtitle");
      output += createCitationInput("location");
      output += createCitationInput("institute");
      output += createCitationInput("year");
      output += createCitationInput("url");
      output += createCitationInput("pages");
      output += createCitationInput("notes");
      output += '</fieldset></div>';
      break;

    case "lecture":
      output += '<div><fieldset><legend>University lectures</legend>';
      output += createCitationInput("surname");
      output += createCitationInput("name");
      output += createCitationInput("topic");
      output += createCitationInput("subject");
      output += createCitationInput("specialization");
      output += createCitationInput("faculty");
      output += createCitationInput("university");
      output += createCitationInput("location");
      output += createCitationInput("date");
      output += createCitationInput("url");
      output += createCitationInput("notes");
      output += '</fieldset></div>';
      break;
  }

  if (typ == "article") {
    output += "<div><fieldset><legend>Other identificators</legend>";
    output += createCitationInput("pmid");
    output += '<div class="prefsectiontip">PMID number in PubMed database.</div>';
    output += createCitationInput("doi");
    output += '<div class="prefsectiontip">DOI identificator.</div>';
    output += "</fieldset></div>";
  }

  // button for submitting the form
  output += '<input type="submit" value="Create citation" />&nbsp;';
  output += '<input type="reset" value="Reset form" /></form>';
  output += '<p>&nbsp;</p>';

  // output
  contentDiv.innerHTML = baseTextCitace + output;

  // compulsory parameters
  polePovinnychParametru = new Array();
  switch (typ) {
    case "book":
    case "chapter":
      polePovinnychParametru = ["title", "edition", "year", "isbn"];
      break;
    case "collection":
      polePovinnychParametru = ["title", "edition", "author_of_collection", "year"];
      break;
    case "article":
      polePovinnychParametru = ["article", "journal", "pages", "year", "the_year", "volume", "issn"];
      break;
    case "serial_publication":
      polePovinnychParametru = ["article", "journal", "serial_publication", "pages", "year", "volume", "the_year", "issn"];
      break;
    case "web":
      polePovinnychParametru = ["source_name", "cited", "url"];
      break;
    case "cd":
      polePovinnychParametru = ["cited", "source_name"];
      break;
    case "db":
      polePovinnychParametru = ["source_name", "responsibility", "cited", "url"];
      break;
    case "company_publication":
      polePovinnychParametru = ["title", "publisher", "year"];
      break;
    case "legislative_publication":
      polePovinnychParametru = ["country", "document", "year"];
      break;
    case "standard":
      polePovinnychParametru = ["label", "source_name", "year"];
      break;
    case "academic_publication":
      polePovinnychParametru = ["source_name", "location", "year"];
      break;
    case "lecture":
      polePovinnychParametru = ["surname", "topic", "subject", "specialization", "faculty", "university", "location", "date"];
      break;
  }

  // classes for compulsory parameters
  classPovinneCitace(polePovinnychParametru);

  // fill in the date
  if(document.getElementById("cited")) {

    datumCitace = document.getElementById("cited");

    dnesni_datum = new Date();

    vyplneni_rok = dnesni_datum.getFullYear();
    vyplneni_mesic = (dnesni_datum.getMonth() + 1);
    if (vyplneni_mesic < 10) vyplneni_mesic = "0" + vyplneni_mesic;
    vyplneni_den = dnesni_datum.getDate();
    if (vyplneni_den < 10) vyplneni_den = "0" + vyplneni_den;
    vyplneni_data = vyplneni_rok + "-" + vyplneni_mesic + "-" + vyplneni_den;

    datumCitace.value = vyplneni_data;
    datumCitace.onclick = function() {
      document.getElementById("cited").value = "";
      document.getElementById("cited").onclick = null;
    }
  }

  // authors
  // jQuery animation
  $j(document).ready(function(){
    $j("#citOdkaz1AutoriForm").click(
      function(){
        $j("#citKorporaceForm").slideToggle();
        $j("#citDalsiAutoriForm").slideToggle();
        $j("#citOdkaz1AutoriForm").slideToggle();
        $j("#citOdkaz2AutoriForm").slideToggle();
      }
    );
    $j("#citOdkaz2AutoriForm").click(
      function(){
        $j("#citKorporaceForm").slideToggle();
        $j("#citDalsiAutoriForm").slideToggle();
        $j("#citOdkaz1AutoriForm").slideToggle();
        $j("#citOdkaz2AutoriForm").slideToggle();
      }
    );
  });

  // end
  return false;
}

// start this!
$(createCitationButton);

if ( typeof $j != 'undefined' && typeof $j.fn.wikiEditor != 'undefined' ) {$j( function() {
    $j( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'advanced',
      'group': 'insert',
      'tools': {'citation': {
          label: 'Create citation',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Text_document_with_page_number_icon.svg/22px-Text_document_with_page_number_icon.svg.png?uselang=cs',
          action: {type: 'callback',
            execute: function(context){createCitationForm();}
          }
        }
      }
    });
  });
}

/* </pre> */