The Demopædia Encyclopedia on Population is under heavy modernization and maintenance. Outputs could look bizarre, sorry for the temporary inconvenience

Multilingual Demographic Dictionary, second unified edition, English volume

Difference between revisions of "MediaWiki:RefToolbarNoDialogsTextTerm.js"

Multilingual Demographic Dictionary, second unified edition, English vol.
Jump to: navigation, search
(From French demopaedia)
(From French demopaedia)
 
Line 2: Line 2:
 
var wikEdAutoUpdateUrl;
 
var wikEdAutoUpdateUrl;
 
function refbuttons() {
 
function refbuttons() {
   if (mwCustomEditButtons && (document.getElementById('toolbar') || document.getElementById('wikiEditor-ui-toolbar'))/* && wikEdAutoUpdateUrl == null*/) {
+
   if (mw.toolbar && (document.getElementById('toolbar') || document.getElementById('wikiEditor-section-main'))/* && wikEdAutoUpdateUrl == null*/) {
 
     if (document.getElementById('toolbar')) {
 
     if (document.getElementById('toolbar')) {
 
       button = document.createElement('a');
 
       button = document.createElement('a');
Line 8: Line 8:
 
       button.title = "Insert citation";
 
       button.title = "Insert citation";
 
       buttonimage = document.createElement('img');
 
       buttonimage = document.createElement('img');
       buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/0/00/Button_easy_cite_%281%29.png";
+
       buttonimage.src = "//upload.wikimedia.org/wikipedia/commons/0/00/Button_easy_cite_%281%29.png";
 
       buttonimage.alt = "Insert footnote";
 
       buttonimage.alt = "Insert footnote";
 
       button.appendChild(buttonimage);
 
       button.appendChild(buttonimage);
Line 18: Line 18:
 
       button.id = 'reftoolbar-button';
 
       button.id = 'reftoolbar-button';
 
       buttonimage = document.createElement('img');
 
       buttonimage = document.createElement('img');
       buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Curly_Brackets.svg/22px-Curly_Brackets.svg.png";
+
       buttonimage.src = "//upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Curly_Brackets.svg/22px-Curly_Brackets.svg.png";
 
       buttonimage.alt = "Insert citation";
 
       buttonimage.alt = "Insert citation";
 
       button.classname = "tool tool-button";
 
       button.classname = "tool tool-button";
Line 25: Line 25:
 
       buttonimage.style.paddingTop = "5px";
 
       buttonimage.style.paddingTop = "5px";
 
       buttonimage.style.paddingLeft = "3px";
 
       buttonimage.style.paddingLeft = "3px";
       button.appendChild(buttonimage)
+
       button.appendChild(buttonimage);
       document.getElementById('wikiEditor-ui-toolbar').childNodes[0].childNodes[1].appendChild(button);
+
       //document.getElementById('wikiEditor-ui-toolbar').childNodes[0].childNodes[1].appendChild(button);
       //document.getElementById('reftoolbar-button').onclick = easyCiteMain;
+
       ////document.getElementById('reftoolbar-button').onclick = easyCiteMain;
       $j('#reftoolbar-button').live('click', function() { easyCiteMain(); });
+
       //$j('#reftoolbar-button').live('click', function() { easyCiteMain(); });
 +
      $('#wikiEditor-section-main .group-insert').append( button );
 +
      $(button).click( function() { easyCiteMain(); });
 +
 
 
     }
 
     }
 
     if (navigator.userAgent.indexOf('MSIE') == -1) {
 
     if (navigator.userAgent.indexOf('MSIE') == -1) {
Line 58: Line 61:
 
   }
 
   }
 
}
 
}
 
+
 
function addOption(script, text) {
 
function addOption(script, text) {
 
   option = document.createElement('input');
 
   option = document.createElement('input');
Line 66: Line 69:
 
   return option;
 
   return option;
 
}
 
}
 
+
 
function hideInitial() {
 
function hideInitial() {
 
   document.getElementById('citeselect').style.display = 'none';
 
   document.getElementById('citeselect').style.display = 'none';
 
   oldFormHide();
 
   oldFormHide();
 
}
 
}
 
+
 
function oldFormHide() {
 
function oldFormHide() {
 
   if (numforms != 0) {
 
   if (numforms != 0) {
Line 80: Line 83:
 
   }
 
   }
 
}  
 
}  
 
+
 
function easyCiteMain() {
 
function easyCiteMain() {
 
   document.getElementById('citeselect').style.display = '';
 
   document.getElementById('citeselect').style.display = '';
 
}
 
}
 
+
 
var months = ['January', 'February', 'March', 'April', 'May', 'June',
 
var months = ['January', 'February', 'March', 'April', 'May', 'June',
      'July', 'August', 'September', 'October', 'November', 'December'];
+
  'July', 'August', 'September', 'October', 'November', 'December'];
 
var citeGlobalDateFormat = "<date> <monthname> <year>";
 
var citeGlobalDateFormat = "<date> <monthname> <year>";
 
function getTime() {
 
function getTime() {
Line 120: Line 123:
 
   return (datestr);
 
   return (datestr);
 
}
 
}
 
+
 
function citeWeb() {
 
function citeWeb() {
 
   citeNewsWeb("cite web");
 
   citeNewsWeb("cite web");
Line 448: Line 451:
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
 
     '<td width="120"><label for="title">&nbsp;Title: </label></td>'+
 
     '<td width="120"><label for="title">&nbsp;Title: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td></tr>'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
 
     '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
 
     '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
 
     '<tr><td width="120"><label for="work">&nbsp;Work: </label></td>'+
 
     '<tr><td width="120"><label for="work">&nbsp;Work: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="work"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="work"></td>'+
 
     '<td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
 
     '<td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td></tr>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
 
     '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
 
     '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
 
     '<tr><td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
 
     '<tr><td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate" value="'+ newtime +'"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate" value="'+ newtime +'"></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
 
     '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
 
     '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
 
     '</table>'+
 
     '</table>'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
    '</fieldset></div>';
+
'</fieldset></div>';
  document.getElementById('citeselect').innerHTML += form;
+
  document.getElementById('citeselect').innerHTML += form;
 
}
 
}
 
+
 
function citeBook() {
 
function citeBook() {
 
   oldFormHide();
 
   oldFormHide();
Line 488: Line 491:
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
 
     '<td width="120"><label for="others">&nbsp;Others: </label></td>'+
 
     '<td width="120"><label for="others">&nbsp;Others: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="others"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="others"></td></tr>'+
 
     '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
 
     '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
 
     '<td width="120"><label for="editor">&nbsp;Editor: </label></td>'+
 
     '<td width="120"><label for="editor">&nbsp;Editor: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="editor"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="editor"></td></tr>'+
 
     '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
 
     '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
 
     '<tr><td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
 
     '<tr><td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td>'+
 
     '<td width="120"><label for="edition">&nbsp;Edition: </label></td>'+
 
     '<td width="120"><label for="edition">&nbsp;Edition: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="edition"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="edition"></td></tr>'+
 
     '<tr><td width="120"><label for="series">&nbsp;Series: </label></td>'+
 
     '<tr><td width="120"><label for="series">&nbsp;Series: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="series"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="series"></td>'+
 
     '<td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
 
     '<td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td></tr>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
 
     '<td width="120"><label for="chapter">&nbsp;Chapter: </label></td>'+
 
     '<td width="120"><label for="chapter">&nbsp;Chapter: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="chapter"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="chapter"></td></tr>'+
 
     '<tr><td width="120"><label for="isbn">&nbsp;ISBN: </label></td>'+
 
     '<tr><td width="120"><label for="isbn">&nbsp;ISBN: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="isbn"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="isbn"></td>'+
 
     '<td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
 
     '<td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td></tr>'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
 
     '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
 
     '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
 
     '<tr><td width="120"><label for="language">&nbsp;Language: </label></td>'+
 
     '<tr><td width="120"><label for="language">&nbsp;Language: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td>'+
 
     '<td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
 
     '<td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
 
     '</table>'+
 
     '</table>'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
    '</fieldset></div>';
+
'</fieldset></div>';
  document.getElementById('citeselect').innerHTML += form;
+
  document.getElementById('citeselect').innerHTML += form;
 
}
 
}
 
+
 
function citeJournal() {
 
function citeJournal() {
 
   oldFormHide();
 
   oldFormHide();
Line 538: Line 541:
 
   numforms++;
 
   numforms++;
 
   form = '<div id="citediv'+numforms+'">'+
 
   form = '<div id="citediv'+numforms+'">'+
     '<fieldset><legend>Cite book source</legend>'+
+
     '<fieldset><legend>Cite journal source</legend>'+
 
     '<table cellspacing="5">'+
 
     '<table cellspacing="5">'+
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<input type="hidden" value="'+template+'" id="template">'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
 
     '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
 
     '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
 
     '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
 
     '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
 
     '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
 
     '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
 
     '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
 
     '<td width="120"><label for="journal">&nbsp;Journal: </label></td>'+
 
     '<td width="120"><label for="journal">&nbsp;Journal: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="journal"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="journal"></td></tr>'+
 
     '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
 
     '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
 
     '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
 
     '<tr><td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
 
     '<tr><td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td>'+
 
     '<td width="120"><label for="issue">&nbsp;Issue: </label></td>'+
 
     '<td width="120"><label for="issue">&nbsp;Issue: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issue"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issue"></td></tr>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
 
     '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
 
     '<td width="120"><label for="issn">&nbsp;ISSN: </label></td>'+
 
     '<td width="120"><label for="issn">&nbsp;ISSN: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issn"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issn"></td></tr>'+
 
     '<tr><td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
 
     '<tr><td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td>'+
 
     '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
 
     '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
 
     '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
 
     '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
 
     '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
 
     '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
 
     '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
 
     '</table>'+
 
     '</table>'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
 
     '<input type="button" value="Add citation" onClick="addcites()">'+
Line 679: Line 682:
 
    
 
    
 
}
 
}
 
+
 
 
 
 
 
function addcites(template) {
 
function addcites(template) {
 
   cites = document.getElementById('citediv'+numforms).getElementsByTagName('input');
 
   cites = document.getElementById('citediv'+numforms).getElementsByTagName('input');
Line 698: Line 699:
 
     }
 
     }
 
   }
 
   }
   cite = citebegin + citename + citeinner + "numforms=" + numforms + "}}</ref>";
+
   cite = citebegin + citename + citeinner + "}}</ref>";
 +
  $("#wpTextbox1").focus();
 
   insertTags(cite, '', '');
 
   insertTags(cite, '', '');
 
   document.getElementById('citediv'+numforms).style.display = 'none';
 
   document.getElementById('citediv'+numforms).style.display = 'none';
 
}
 
}
 
+
 
function getNamedRefs(calls) {
 
function getNamedRefs(calls) {
 
   if (typeof(wikEdUseWikEd) != 'undefined') {
 
   if (typeof(wikEdUseWikEd) != 'undefined') {
Line 716: Line 718:
 
     regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?>/gi //'
 
     regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?>/gi //'
 
   }
 
   }
   var namedrefs = new Array();
+
   var namedrefs = [];
 
   var i=0;
 
   var i=0;
 
   var nr=true;
 
   var nr=true;
Line 736: Line 738:
 
   return namedrefs;
 
   return namedrefs;
 
}
 
}
 
+
 
function citeNamedRef() {
 
function citeNamedRef() {
 
   namedrefs = getNamedRefs(false);
 
   namedrefs = getNamedRefs(false);
Line 753: Line 755:
 
       '<table cellspacing="5">'+
 
       '<table cellspacing="5">'+
 
       '<tr><td><label for="namedrefs">&nbsp;Named references in text</label></td>'+
 
       '<tr><td><label for="namedrefs">&nbsp;Named references in text</label></td>'+
      '<td><select name="namedrefs" id="namedrefs">';
+
            '<td><select name="namedrefs" id="namedrefs">';
 
     for (var i=0;i<namedrefs.length;i++) {
 
     for (var i=0;i<namedrefs.length;i++) {
 
       form+= '<option value="'+namedrefs[i]+'">'+namedrefs[i]+'</option>';
 
       form+= '<option value="'+namedrefs[i]+'">'+namedrefs[i]+'</option>';
Line 761: Line 763:
 
       '<input type="button" value="Add citation" onClick="addnamedcite()">'+
 
       '<input type="button" value="Add citation" onClick="addnamedcite()">'+
 
       '</fieldset></div>';
 
       '</fieldset></div>';
    document.getElementById('citeselect').innerHTML += form;
+
    document.getElementById('citeselect').innerHTML += form;
 
   }
 
   }
 
}
 
}
 
+
 
function addnamedcite() {
 
function addnamedcite() {
 
   name = document.getElementById('citediv'+numforms).getElementsByTagName('select')[0].value;
 
   name = document.getElementById('citediv'+numforms).getElementsByTagName('select')[0].value;
 
   ref = '<ref name="'+name+'" />';
 
   ref = '<ref name="'+name+'" />';
 +
  $("#wpTextbox1").focus();
 
   insertTags(ref, '', '');
 
   insertTags(ref, '', '');
 
   document.getElementById('citediv'+numforms).style.display = 'none';
 
   document.getElementById('citediv'+numforms).style.display = 'none';
 
}
 
}
 
+
 
function getAllRefs() {
 
function getAllRefs() {
 
   if (typeof(wikEdUseWikEd) != 'undefined') {
 
   if (typeof(wikEdUseWikEd) != 'undefined') {
Line 780: Line 783:
 
   text = document.getElementById('wpTextbox1').value;
 
   text = document.getElementById('wpTextbox1').value;
 
   regex = /< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim //"
 
   regex = /< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim //"
   var allrefs = new Array();
+
   var allrefs = [];
 
   var i=0;
 
   var i=0;
 
   var nr=true;
 
   var nr=true;
Line 799: Line 802:
 
   return allrefs;
 
   return allrefs;
 
}
 
}
 
+
 
function NRcallError(namedrefs, refname) {
 
function NRcallError(namedrefs, refname) {
 
   for (var i=0; i<namedrefs.length; i++) {
 
   for (var i=0; i<namedrefs.length; i++) {
Line 808: Line 811:
 
   return false;
 
   return false;
 
}
 
}
 
+
 
function errorCheck() {
 
function errorCheck() {
 
   var allrefs = getAllRefs();
 
   var allrefs = getAllRefs();
   var allrefscontent = new Array();
+
   var allrefscontent = [];
   var samecontentexclude = new Array();
+
   var samecontentexclude = [];
 
   var sx=0;
 
   var sx=0;
   var templateexclude = new Array();
+
   var templateexclude = [];
 
   var tx=0;
 
   var tx=0;
 
   var skipcheck = false;
 
   var skipcheck = false;
Line 822: Line 825:
 
   }
 
   }
 
   var namedrefs = getNamedRefs(false);
 
   var namedrefs = getNamedRefs(false);
   var errorlist = new Array();
+
   var errorlist = [];
 
   var q=0;
 
   var q=0;
 
   unclosed = document.getElementById('unclosed').checked;
 
   unclosed = document.getElementById('unclosed').checked;
Line 845: Line 848:
 
         if (allrefscontent[i] == allrefscontent[p] && i != p) {
 
         if (allrefscontent[i] == allrefscontent[p] && i != p) {
 
           errorlist[q] = '<tr><td width="75%"><tt>'+allrefscontent[i]+'</tt></td>';
 
           errorlist[q] = '<tr><td width="75%"><tt>'+allrefscontent[i]+'</tt></td>';
           errorlist[q] += '<td width="25%">Multiple refs contain this content, a <a href="http://en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> should be used instead</td></tr>';
+
           errorlist[q] += '<td width="25%">Multiple refs contain this content, a <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> should be used instead</td></tr>';
 
           q++;
 
           q++;
 
           samecontentexclude[sx] = allrefscontent[i]
 
           samecontentexclude[sx] = allrefscontent[i]
Line 853: Line 856:
 
         p++;
 
         p++;
 
       }
 
       }
      skipcheck=false;
+
    skipcheck=false;
 
     }
 
     }
 
     if (templates) {
 
     if (templates) {
Line 864: Line 867:
 
         if (!skipcheck) {
 
         if (!skipcheck) {
 
           errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
 
           errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
           errorlist[q] += '<td width="25%">Does not use a <a href="http://en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a></td></tr>';
+
           errorlist[q] += '<td width="25%">Does not use a <a href="//en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a></td></tr>';
 
           q++;
 
           q++;
 
           templateexclude[tx] = allrefscontent[i];
 
           templateexclude[tx] = allrefscontent[i];
Line 874: Line 877:
 
   }
 
   }
 
   if (repeated) {
 
   if (repeated) {
     var repeatnameexclude = new Array();
+
     var repeatnameexclude = [];
 
     var rx=0;
 
     var rx=0;
 
     for (var k=0; k<namedrefs.length; k++) {
 
     for (var k=0; k<namedrefs.length; k++) {
Line 886: Line 889:
 
         if (namedrefs[k] == namedrefs[z] && k != z) {
 
         if (namedrefs[k] == namedrefs[z] && k != z) {
 
           errorlist[q] = '<tr><td width="75%"><tt>'+namedrefs[k]+'</tt></td>';
 
           errorlist[q] = '<tr><td width="75%"><tt>'+namedrefs[k]+'</tt></td>';
           errorlist[q] += '<td width="25%">Multiple references are given the same <a href="http://en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">name</a></td></tr>';
+
           errorlist[q] += '<td width="25%">Multiple references are given the same <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">name</a></td></tr>';
 
           q++;
 
           q++;
 
           repeatnameexclude[rx] = namedrefs[z];
 
           repeatnameexclude[rx] = namedrefs[z];
Line 894: Line 897:
 
         z++;
 
         z++;
 
       }
 
       }
      skipcheck = false;
+
    skipcheck = false;
 
     }
 
     }
 
   }
 
   }
 
   if (undef) {
 
   if (undef) {
     var undefexclude = new Array();
+
     var undefexclude = [];
 
     var ux=0;
 
     var ux=0;
 
     for (var p=0; p<namedrefcalls.length; p++) {
 
     for (var p=0; p<namedrefcalls.length; p++) {
Line 909: Line 912:
 
         if (!NRcallError(namedrefs, namedrefcalls[p])) {
 
         if (!NRcallError(namedrefs, namedrefcalls[p])) {
 
           errorlist[q] = '<tr><td width="75%"><tt>'+namedrefcalls[p]+'</tt></td>';
 
           errorlist[q] = '<tr><td width="75%"><tt>'+namedrefcalls[p]+'</tt></td>';
           errorlist[q] += '<td width="25%">A <a href="http://en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> is used but not defined</td></tr>';
+
           errorlist[q] += '<td width="25%">A <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> is used but not defined</td></tr>';
 
           q++;
 
           q++;
 
           undefexclude[ux] = namedrefs[p];
 
           undefexclude[ux] = namedrefs[p];
Line 917: Line 920:
 
       skipcheck = false;
 
       skipcheck = false;
 
     }
 
     }
  }
+
}
 
   if (q > 0) {
 
   if (q > 0) {
 
     return errorlist;
 
     return errorlist;
Line 924: Line 927:
 
   }
 
   }
 
}
 
}
 
+
 
function dispErrors() {
 
function dispErrors() {
 
   oldFormHide();
 
   oldFormHide();
Line 932: Line 935:
 
     '<input type="checkbox" id="unclosed" /> Unclosed <tt>&lt;ref&gt;</tt> tags<br/>'+
 
     '<input type="checkbox" id="unclosed" /> Unclosed <tt>&lt;ref&gt;</tt> tags<br/>'+
 
     '<input type="checkbox" id="samecontent" /> References with the same content<br/>'+
 
     '<input type="checkbox" id="samecontent" /> References with the same content<br/>'+
     '<input type="checkbox" id="templates" /> References not using a <a href="http://en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a><br/>'+
+
     '<input type="checkbox" id="templates" /> References not using a <a href="//en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a><br/>'+
 
     '<input type="checkbox" id="repeated" /> Multiple references with the same name<br/>'+
 
     '<input type="checkbox" id="repeated" /> Multiple references with the same name<br/>'+
 
     '<input type="checkbox" id="undef" /> Usage of undefined named references<br/>'+
 
     '<input type="checkbox" id="undef" /> Usage of undefined named references<br/>'+
Line 939: Line 942:
 
   document.getElementById('citeselect').innerHTML += form;
 
   document.getElementById('citeselect').innerHTML += form;
 
}
 
}
 
+
 
function doErrorCheck() {
 
function doErrorCheck() {
 
   var errors = errorCheck();
 
   var errors = errorCheck();
Line 965: Line 968:
 
     form+= '</table>'+
 
     form+= '</table>'+
 
       '</fieldset></div>';
 
       '</fieldset></div>';
    document.getElementById('citeselect').innerHTML += form;
+
    document.getElementById('citeselect').innerHTML += form;
 
   }
 
   }
 
}
 
}
 
+
 
$( refbuttons );
 
$( refbuttons );

Latest revision as of 13:54, 15 June 2017

var numforms = 0;
var wikEdAutoUpdateUrl;
function refbuttons() {
  if (mw.toolbar && (document.getElementById('toolbar') || document.getElementById('wikiEditor-section-main'))/* && wikEdAutoUpdateUrl == null*/) {
    if (document.getElementById('toolbar')) {
      button = document.createElement('a');
      button.href = "javascript:easyCiteMain()";
      button.title = "Insert citation";
      buttonimage = document.createElement('img');
      buttonimage.src = "//upload.wikimedia.org/wikipedia/commons/0/00/Button_easy_cite_%281%29.png";
      buttonimage.alt = "Insert footnote";
      button.appendChild(buttonimage);
      document.getElementById('toolbar').appendChild(button);
    } else {
      button = document.createElement('a');
      button.href = "#";
      button.title = "Insert citation";
      button.id = 'reftoolbar-button';
      buttonimage = document.createElement('img');
      buttonimage.src = "//upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Curly_Brackets.svg/22px-Curly_Brackets.svg.png";
      buttonimage.alt = "Insert citation";
      button.classname = "tool tool-button";
      buttonimage.style.width = "22px";
      buttonimage.style.height = "17px";
      buttonimage.style.paddingTop = "5px";
      buttonimage.style.paddingLeft = "3px";
      button.appendChild(buttonimage);
      //document.getElementById('wikiEditor-ui-toolbar').childNodes[0].childNodes[1].appendChild(button);
      ////document.getElementById('reftoolbar-button').onclick = easyCiteMain;
      //$j('#reftoolbar-button').live('click', function() { easyCiteMain(); });
      $('#wikiEditor-section-main .group-insert').append( button );
      $(button).click( function() { easyCiteMain(); });

    }
    if (navigator.userAgent.indexOf('MSIE') == -1) {
      //alert("NO MSIE");
      citemain = document.createElement('div');
      citemain.style.display = 'none';
      citemain.setAttribute('Id', 'citeselect');
      citemain.appendChild( addOption("citeWeb()", "Cite web") );
      citemain.appendChild( addOption("citeBook()", "Cite book") );
      citemain.appendChild( addOption("citeJournal()", "Cite journal") );
      citemain.appendChild( addOption("citeNews()", "Cite news") );
      citemain.appendChild( addOption("citeNamedRef()", "Named ref") );
      citemain.appendChild( addOption("dispErrors()", "Error check") );
      citemain.appendChild( addOption("hideInitial()", "Cancel") );
      citemain.appendChild( addOption("textTerm()", "TextTerm") );
      document.getElementById('wpTextbox1').parentNode.insertBefore(citemain, document.getElementById('wpTextbox1'));
    }
    else {
      selection = '<div id="citeselect" style="display:none"><input type="button" value="Cite web" onclick="citeWeb()" />'+
	'<input type="button" value="Cite book" onclick="citeBook()" />'+
	'<input type="button" value="Cite journal" onclick="citeJournal()" />'+
	'<input type="button" value="Cite news" onclick="citeNews()" />'+
	'<input type="button" value="Named ref" onclick="citeNamedRef()" />'+
	'<input type="button" value="Error check" onclick="dispErrors()" />'+
	'<input type="button" value="Cancel" onclick="hideInitial()" />'+
	'<input type="button" value="TextTerm" onclick="textTerm()" /></div>';
      document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
    }
  }
}
 
function addOption(script, text) {
  option = document.createElement('input');
  option.setAttribute('type', 'button');
  option.setAttribute('onclick', script);
  option.setAttribute("value", text);
  return option;
}
 
function hideInitial() {
  document.getElementById('citeselect').style.display = 'none';
  oldFormHide();
}
 
function oldFormHide() {
  if (numforms != 0) {
    document.getElementById('citediv'+numforms).style.display = 'none';
  }
  if (document.getElementById('errorform') != null) {
    document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
  }
} 
 
function easyCiteMain() {
  document.getElementById('citeselect').style.display = '';
}
 
var months = ['January', 'February', 'March', 'April', 'May', 'June',
  'July', 'August', 'September', 'October', 'November', 'December'];
var citeGlobalDateFormat = "<date> <monthname> <year>";
function getTime() {
  var datestr = '';
  if (typeof citeUserDateFormat != 'undefined') {
    datestr = citeUserDateFormat;
  } else {
    datestr = citeGlobalDateFormat;
  }
  var DT = new Date();
  var zmonth = '';
  var month = DT.getUTCMonth()+1;
  if (month < 10) {
    zmonth = "0"+month.toString();
  } else {
    zmonth = month.toString();
  }
  month = month.toString();
  var zdate = '';
  var date = DT.getUTCDate()
  if (date < 10) {
    zdate = "0"+date.toString();
  } else {
    zdate = date.toString();
  }
  date = date.toString()
  datestr = datestr.replace('<date>', date);
  datestr = datestr.replace('<month>', month);
  datestr = datestr.replace('<zdate>', zdate);
  datestr = datestr.replace('<zmonth>', zmonth);
  datestr = datestr.replace('<monthname>', months[DT.getUTCMonth()]);
  datestr = datestr.replace('<year>', DT.getUTCFullYear().toString());
  return (datestr);
}
 
function citeWeb() {
  citeNewsWeb("cite web");
}
function citeNews() {
  citeNewsWeb("cite news");
}

function textTerm() {
  textTermf();
} 

var texttermall = new Array();
var texttermcur = new Array();
var textterminput = new Array();
var poffset=null, prange=null, noffset=null, nrange=null;
var section = '';
var subnote = '';

function textTermf() {
  textTermform(null,null);
}

function nexttextterm() {
  //console.log("nexttexterm before noffset :" + noffset + " nrange=" + nrange);
  savetextterms(); // Save if changed
  if(noffset){ // If there is a next
    textTermform(noffset, nrange); // Call with offset !{{TextTerm    }}
  }
}
function previoustextterm() {
  //console.log("previoustexterm before poffset :" + poffset + " prange=" + prange);
  savetextterms();
  if(poffset){ // If there is a next
    textTermform(poffset, prange); // Call with offset !{{TextTerm    }}
  }
}



function texttermfill(subtext) {
  var ref = new Array();
  this.term = '';
  this.note= '';
  this.section= '';
  if(section != '')
    this.section = section;
  this.subnote = '';
  if(subnote != '')
    this.subnote = subnote;
  this.englishentry= '';
  this.indexentry= '';
  this.otherindexentry = '';
  this.otherindexentrytwo = '';
  this.otherindexentrythree = '';
  this.otherindexentryfour = '';
  this.otherindexentryfive = '';

  var j=0;
  var nr=true;
  regexbar= /\|([^|]*)/gm 
  //regexbar =/\|((.)*?)(?=[\||\n])/gm //"|programmes de population|1|933|IndexEntry=programme de population|OtherIndexEntry=population, programme de"
  do {
    ref = regexbar.exec(subtext);
    //console.log(" subtext=" + subtext);
    //console.log(" ref=" + ref);
    if(ref != null){
      switch (j)
      {
      case 0 : this.term = ref[1]; break;
      case 1 : this.note = ref[1]; break;
      case 2 : this.section = ref[1]; break;
      default :
	if(ref[1].match(/^ *?EnglishEntry *?= *?(.*) *?$/))
	  this.englishentry = ref[1].replace(/^ *?EnglishEntry *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?IndexEntry *?= *?(.*) *?$/))
	  this.indexentry = ref[1].replace(/^ *?IndexEntry *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?OtherIndexEntry *?= *?(.*) *?$/))
	  this.otherindexentry = ref[1].replace(/^ *?OtherIndexEntry *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?OtherIndexEntryTwo *?= *?(.*) *?$/))
	  this.otherindexentrytwo = ref[1].replace(/^ *?OtherIndexEntryTwo *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?OtherIndexEntryThree *?= *?(.*) *?$/))
	  this.otherindexentrythree = ref[1].replace(/^ *?OtherIndexEntryThree *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?OtherIndexEntryFour *?= *?(.*) *?$/))
	  this.otherindexentryfour = ref[1].replace(/^ *?OtherIndexEntryFour *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?OtherIndexEntryFive *?= *?(.*) *?$/))
	  this.otherindexentryfive = ref[1].replace(/^ *?OtherIndexEntryFive *?= *?(.*) *?$/,"$1");
	else if(ref[1].match(/^ *?EnglishEntry *?= *?(.*) *?$/))
	  this.englishentry = ref[1].replace(/^ *?EnglishEntry *?= *?(.*) *?$/,"$1");
	else if(j==3){
	    this.subnote = ref[1];
	}else{
	  alert("texttermfill error j=" + j + " ref1= " +ref[1]);
	  //console.log("texttermfill error j=" + j + " ref1= " +ref[1]);
	}
      }
      j++;
    } else {
      nr=false;
    }
  } while (nr==true);
  //console.log("j=" + j + " term=" + this.term + " note=" + this.note + " section=" + this.section +" subnote=" + this.subnote +" indexentry=" + this.indexentry + " otherindexentry=" + this.otherindexentry);
}


function textTermform(offset,range){

  // We search for TextTerm in wptexbox1 from cursor position (offset) and if selected (range)
  // If called by a previous or next, they are not null {{TextTerm<-......>}}
  // if outside of a TextTerm template, we will fill with the term with the selection
  // in any case we compute the previous nextstart and previus end and next offset not real.
  // if inside a TextTerm we fill the form
  // if saveterm is necessary, we save and exit.
  // if previous or next, we save if necessary and we call textTermform with a new offset >0 (next) or <0 (previous) and range
  // 
  var textarea= document.getElementById('wpTextbox1');
  if ('selectionStart' in textarea) {
    if (offset == null){ // range should be null too
      offset = textarea.selectionStart;
      range = textarea.selectionEnd - textarea.selectionStart;

      var lstxtterm = textarea.value.substring(0,textarea.selectionEnd). lastIndexOf("{{TextTerm") ; // Just before the string. No regex
      var lstcltxtterm = textarea.value.substring(0,textarea.selectionStart). lastIndexOf("}}") ; //might be for another purpose than TextTerm
      // Looking for the section
      section = '';
      var psectione = textarea.value.substring(0,textarea.selectionEnd). lastIndexOf("===") ; // Just before the string. No regex
      if(psectione != -1){
	var psections = textarea.value.substring(0,psectione). lastIndexOf("===") ; // Just before the string. No regex
	if(psections != -1){
	  section =  textarea.value.substring(psections,psectione+3).match(/^=== *?(\d{3}) *?===$/)[1];
	}
      }
      //console.log(" section |" + section);
      //textarea.value.substring(0,textarea.selectionStart). search(new RegExp("((({{TextTerm[^}]+)[^{]+)+)");
      
      if ( (-1 == lstxtterm) || ((-1 < lstxtterm) && (lstxtterm < lstcltxtterm)) ) { // @{{TextTerm ...@}}...(...).. 
	// {{Refnumber }} ....! 
	// alert("We are after outside a previous TextTerm or no TextTerm before:" + textarea.value.substring(0,textarea.selectionStart ));
	texttermcur = new texttermfill("|" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
	//console.log(" We want to fill with the selection=" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
	// On se retrouve avec du texte à ajouter et le curseur inchangé à textarea.selectionStart   
      } else if ( (lstxtterm > lstcltxtterm) && (lstcltxtterm > -1) ) { // @}}... @{{TextTerm ... (...).. 
	//alert("We are within a TextTerm or no closing }}:" + textarea.value.substring(lstcltxtterm, lstxtterm));
	
	// ( textarea.value.substring(lstxtterm, textarea.selectionStart). search(new RegExp("}}")) == -1) {
	var endtxterm= textarea.value.substring(textarea.selectionStart, textarea.length). search("}}");
	if( endtxterm == -1)
	  error(" Error no closing TextTerm; should be fixed:" + textarea.value.substring(textarea.selectionStart, textarea.length));
	else{
	  endtxterm = endtxterm + textarea.selectionStart +2 ; // }} included
	  // Looking for @{{TextTerm....}}@
	  // alert("We are within textterm  " + lstxtterm + " to " + endtxterm + " soit:" + textarea.value.substring(lstxtterm,endtxterm) );
	  //console.log(" Replacing with form result:" + textarea.value.substring(lstxtterm+"{{TextTerm".length,endtxterm-"}}".length));
	  texttermcur = new texttermfill(textarea.value.substring(lstxtterm+"{{TextTerm".length,endtxterm-"}}".length) );
	  // On devrait remplacer {{TextTerm ...}} par la forme, soit de lstxtterm endtxtterm
	  // On se fout de la sélection originale et la repositionne sur toute l'étendue du textterm.
	  // alert("After null before textarea.selectionStart is" + textarea.selectionStart + " end=" +  textarea.selectionEnd);
	  // alert(" selection is:" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
	  textarea.selectionStart = lstxtterm;
	  textarea.selectionEnd = endtxterm;
	  // alert("After null textarea.selectionStart is" + textarea.selectionStart + " end=" +  textarea.selectionEnd);
	  // alert(" selection is now:" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
	} //en endtxtterm
      } // end  @}}... @{{TextTerm ... (...).. 
    }else{ // coming from a previous or next
      // alert("After Next textarea.selectionStart is" + textarea.selectionStart + " end=" +  textarea.selectionEnd);
      // alert(" After next selection is:" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
      // alert("Coming from a previous or next modifing selectionStart start is an offsetstart =" + offset + " and range=" + range)
  // Previous
  //                                selectionStart selectionEnd
  //                                         >                <
  // ^....@{{TextTerm....#}}.................@{{TextTerm ...}}!
  //       !<-range-------->! 
  //                       #<-offset--------->! 
  // Next
  //  selectionStart selectionEnd
  //      >                 <
  // ^....@{{TextTerm....#}}.................@{{TextTerm ...}}!
  //                                         !<--range------->! 
  //                       #<-offset--------->! 
      // alert(" Before textarea.selectionStart=" + textarea.selectionStart + " textarea.selectionEnd=" + textarea.selectionEnd);
      //alert(" Before is:" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
      textarea.selectionStart = (offset > 0 ? textarea.selectionEnd + offset : textarea.selectionStart + offset -range);
      textarea.selectionEnd = textarea.selectionStart + range;
        // Looking for the section
      section = '';
      var psectione = textarea.value.substring(0,textarea.selectionEnd). lastIndexOf("===") ; // Just before the string. No regex
      if(psectione != -1){
	var psections = textarea.value.substring(0,psectione). lastIndexOf("===") ; // Just before the string. No regex
	if(psections != -1){
	  section =  textarea.value.substring(psections,psectione+3).match(/^=== *?(\d{3}) *?===$/)[1];
	}
      }
      //console.log(" section Other |" + section);

      // alert(" After is:" + textarea.value.substring(textarea.selectionStart,textarea.selectionEnd));
      // alert(" After textarea.selectionStart=" + textarea.selectionStart + " textarea.selectionEnd=" + textarea.selectionEnd);
      //console.log("textterm cur is:" + textarea.value.substring(textarea.selectionStart+"{{TextTerm".length,textarea.selectionEnd-"}}".length));
      texttermcur = new texttermfill(textarea.value.substring(textarea.selectionStart+"{{TextTerm".length,textarea.selectionEnd-"}}".length) );
    }
  }else{
    alert("No selectionStart Internet Explorer < 9?");
  }  
  // Looking for previous and next
  // Previous
  // ^....@{{TextTerm....#}}.................@{{TextTerm ...}}!
  //                        poffset
  //       <   prange      ><
  //       ><              ><
  //     pstart          pend
  //       !<--------offsetpstart------------>! 
  //                       #<-offsetpsend---->! 

  var pstart = textarea.value.substring(0,textarea.selectionStart). lastIndexOf("{{TextTerm"); 
  if ( pstart == -1) { // No previous
    // alert( "NO previous : " + textarea.value.substring(0,textarea.selectionStart));
    poffset = null;
    prange = null;
  }else{
    // alert( "Previous pstart=" + pstart + " selectionStart=" + textarea.selectionStart + " pstart:selectionStart=" + textarea.value.substring(pstart,textarea.selectionStart));
    var pend = textarea.value.substring(pstart,textarea.selectionStart). search("}}") ; // Regex ?
    // alert( "Previous pstart=" + pstart + " pend= " + pend + " selectionStart=" + textarea.selectionStart + " pstart:selectionStart=" + textarea.value.substring(pstart,textarea.selectionStart));
    if ( pend == -1) { // Strange no ending
      stop( "NO ending }} in previous : " + textarea.value.substring(0,textarea.selectionStart));
    }else{
      prange = pend + 2; // }} included
      poffset = pstart + prange - textarea.selectionStart;  // should be negative
      // alert( " prange =" + prange + " poffset=" + poffset);
    }
  }
  // Next
  // ^....@{{TextTerm....#}}.................@{{TextTerm ...}}!
  //                       !<--------offsetnend-------------->! 
  //                       #<-offsetnstart--->! 
  //                                      noffset
  //                                         ><   nrange     >
  //                       #<-offsetnstart--->! 
  var nstart = textarea.value.substring(textarea.selectionEnd,textarea.length). search("{{TextTerm") 
  if ( nstart == -1) { // No next
    // alert( "NO next TextTerm : " +  textarea.value.substring(textarea.selectionEnd,textarea.length));
    noffset = null;
    nrange = null;
  }else{
    var nend = textarea.value.substring(textarea.selectionEnd + nstart,textarea.length). search("}}") ;
    if ( nend == -1) { // Strange no ending
      stop( "NO ending }} in previous : " + textarea.value.substring(textarea.selectionEnd,textarea.length)) ;
    }else{
      noffset = nstart ;
      nrange = nend +2 ;// }}
    }
  }


  // We do have offset or null, as well formfilled with a selection.

  oldFormHide();
  template = "TextTerm";
  var legend;
  if (template == "TextTerm") {
    legend = "TextTerm source";
  } else {
    legend = "Cite news source";
  }
  newtime = getTime();

  numforms++;
  form = '<div id="citediv'+numforms+'">'+
    '<fieldset><legend>'+legend+'</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+template+'" id="template">'+
    '<tr><td><label for="term">&nbsp;*Term or expression: </label></td>'+
    '<td colspan="3"><input type="text" tabindex=1 style="width:100%" id="term" value= "' +
    texttermcur.term + '"></tr>'+
    '<tr><td width="100"><label for="note">&nbsp;*Note number (1, 2 etc .): </label></td>'+
    '<td width="40"><input type="text" tabindex=1 style="width:10%" id="note" value= "' +
    texttermcur.note + '"></td>'+
    '<td width="100"><label for="subnote">&nbsp;Subnote (2): </label></td>'+
    '<td width="40"><input type="text" tabindex=1 style="width:10%" id="subnote" value= "' +
    texttermcur.subnote + '"></td></tr>'+
    '<tr><td width="300"><label for="section">&nbsp;Section (102, 933 etc.): </label></td>'+
    '<td width="40"><input type="text" tabindex=1 style="width:10%" id="section" value= "' +
    texttermcur.section + '"></td>'+
    '<td width="120"><label for="indexentry">&nbsp;IndexEntry: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="indexentry" value= "' +
    texttermcur.indexentry + '"></td></tr>'+
    '<tr><td width="120"><label for="otherindexentry">&nbsp;OtherIndexEntry: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="otherindexentry" value= "' +
    texttermcur.otherindexentry + '"></td>'+
    '<td width="120"><label for="otherindexentrytwo">&nbsp;OtherIndexEntryTwo: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="otherindexentrytwo" value= "' +
    texttermcur.otherindexentrytwo + '"></td></tr>'+
    '<tr><td width="120"><label for="otherindexentrythree">&nbsp;OtherIndexEntryThree: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="otherindexentrythree" value= "' +
    texttermcur.otherindexentrythree + '"></td>'+
    '<td width="120"><label for="otherindexentryfour">&nbsp;OtherIndexEntryFour: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="otherindexentryfour" value= "' +
    texttermcur.otherindexentryfour + '"></td></tr>'+
    '<tr><td width="120"><label for="otherindexentryfive">&nbsp;OtherIndexEntryFive: </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="otherindexentryfive" value= "' +
    texttermcur.otherindexentryfive + '"></td>'+
    '<td width="120"><label for="englishentry">&nbsp;EnglishEntry (for Chinese and Japanese): </label></td>'+
    '<td width="400"><input type="text" tabindex=1 style="width:100%" id="englishentry" value= "' +
    texttermcur.englishentry + '"></td></tr>'+
    '</table>'+
    '<input type="button" id="previous" value="(save &) previous TextTerm" onClick="previoustextterm()">'+
    '<input type="button" value="(save &) exit" onClick="savetextterms()">'+
    '<input type="button" id="next" value="(save &) next TextTerm" onClick="nexttextterm()">'+
    '</fieldset></div>';
  document.getElementById('citeselect').innerHTML += form;
}


function citeNewsWeb(templatename) {
  oldFormHide();
  template = templatename;
  var legend;
  if (template == "cite web") {
    legend = "Cite web source";
  } else {
    legend = "Cite news source";
  }
  newtime = getTime();
  numforms++;
  form = '<div id="citediv'+numforms+'">'+
    '<fieldset><legend>'+legend+'</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+template+'" id="template">'+
    '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
    '<td width="120"><label for="title">&nbsp;Title: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td></tr>'+
    '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
    '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
    '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
    '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
    '<tr><td width="120"><label for="work">&nbsp;Work: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="work"></td>'+
    '<td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td></tr>'+
    '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
    '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
    '<tr><td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate" value="'+ newtime +'"></td>'+
    '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
    '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
    '</table>'+
    '<input type="button" value="Add citation" onClick="addcites()">'+
 '</fieldset></div>';
   document.getElementById('citeselect').innerHTML += form;
}
 
function citeBook() {
  oldFormHide();
  template = "cite book";
  numforms++;
  form = '<div id="citediv'+numforms+'">'+
    '<fieldset><legend>Cite book source</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+template+'" id="template">'+
    '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
    '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
    '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
    '<td width="120"><label for="others">&nbsp;Others: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="others"></td></tr>'+
    '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
    '<td width="120"><label for="editor">&nbsp;Editor: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="editor"></td></tr>'+
    '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
    '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
    '<tr><td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td>'+
    '<td width="120"><label for="edition">&nbsp;Edition: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="edition"></td></tr>'+
    '<tr><td width="120"><label for="series">&nbsp;Series: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="series"></td>'+
    '<td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td></tr>'+
    '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
    '<td width="120"><label for="chapter">&nbsp;Chapter: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="chapter"></td></tr>'+
    '<tr><td width="120"><label for="isbn">&nbsp;ISBN: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="isbn"></td>'+
    '<td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td></tr>'+
    '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
    '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
    '<tr><td width="120"><label for="language">&nbsp;Language: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td>'+
    '<td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
    '</table>'+
    '<input type="button" value="Add citation" onClick="addcites()">'+
 '</fieldset></div>';
   document.getElementById('citeselect').innerHTML += form;
}
 
function citeJournal() {
  oldFormHide();
  template = "cite journal";
  numforms++;
  form = '<div id="citediv'+numforms+'">'+
    '<fieldset><legend>Cite journal source</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+template+'" id="template">'+
    '<tr><td width="120"><label for="last">&nbsp;Last name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
    '<td width="120"><label for="first">&nbsp;First name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
    '<tr><td width="120"><label for="coauthors">&nbsp;Coauthors: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
    '<td width="120"><label for="date">&nbsp;Publication date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td></tr>'+
    '<tr><td width="120"><label for="title">&nbsp;Title: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
    '<td width="120"><label for="journal">&nbsp;Journal: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="journal"></td></tr>'+
    '<tr><td width="120"><label for="publisher">&nbsp;Publisher: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
    '<td width="120"><label for="location">&nbsp;Location: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
    '<tr><td width="120"><label for="volume">&nbsp;Volume: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td>'+
    '<td width="120"><label for="issue">&nbsp;Issue: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issue"></td></tr>'+
    '<tr><td width="120"><label for="pages">&nbsp;Pages: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
    '<td width="120"><label for="issn">&nbsp;ISSN: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="issn"></td></tr>'+
    '<tr><td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td>'+
    '<td width="120"><label for="language">&nbsp;Language: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td></tr>'+
    '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
    '<td width="120"><label for="accessdate">&nbsp;Access date: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
    '<tr><td width="120"><label for="refname">&nbsp;Reference name: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
    '</table>'+
    '<input type="button" value="Add citation" onClick="addcites()">'+
    '</fieldset></div>';
  document.getElementById('citeselect').innerHTML += form;
}

function saveinput(terminput) {
  //  terminput = document.getElementById('citediv'+numforms).getElementsByTagName('input');
  this.term = '';
  this.note= '';
  this.section = '';
  this.indexentry= '';
  this.otherindexentry = '';
  this.otherindexentrytwo = '';
  this.otherindexentrythree = '';
  this.otherindexentryfour = '';
  this.otherindexentryfive = '';
  this.englishentry = '';

  for (var i=0; i<terminput.length-1; i++) {
    if (terminput[i].id == "template" ){
      ;
    }else if (terminput[i].id == "term" ){
      this.term = terminput[i].value;
    }else if(terminput[i].id == "note"){
      this.note = terminput[i].value;
    }else if(terminput[i].id == "section"){
      this.section = terminput[i].value;
    }else if(terminput[i].id == "subnote"){
      this.subnote = terminput[i].value;
    }else if(terminput[i].id == "indexentry"){
      this.indexentry = terminput[i].value;
    }else if(terminput[i].id == "otherindexentry"){
      this.otherindexentry = terminput[i].value;
    }else if(terminput[i].id == "otherindexentrytwo"){
      this.otherindexentrytwo = terminput[i].value;
    }else if(terminput[i].id == "otherindexentrythree"){
      this.otherindexentrythree = terminput[i].value;
    }else if(terminput[i].id == "otherindexentryfour"){
      this.otherindexentryfour = terminput[i].value;
    }else if(terminput[i].id == "otherindexentryfive"){
      this.otherindexentryfive = terminput[i].value;
    }else if(terminput[i].id == "englishentry"){
      this.englishentry = terminput[i].value;
    }else{
      ;;//alert(" SaveInput terminput[i].id = " + terminput[i].id + " terminput[i].value =" + terminput[i].value);
    }

  }
}

function savetextterms(template) {
  var txtterminput = document.getElementById('citediv'+numforms).getElementsByTagName('input');
  textterminput = new saveinput(txtterminput);
  //alert("texttermcur=" + texttermcur);
  //alert("textterminput=" + textterminput);
  // Testing
  var different = false;
  if((textterminput.term != texttermcur.term) || (textterminput.note != texttermcur.note) ||
     (textterminput.section != texttermcur.section) ||
     (textterminput.subnote != texttermcur.subnote) ||
     (textterminput.indexentry != texttermcur.indexentry) ||
     (textterminput.otherindexentry != texttermcur.otherindexentry) || 
     (textterminput.otherindexentrytwo != texttermcur.otherindexentrytwo) ||
     (textterminput.otherindexentrythree != texttermcur.otherindexentrythree) ||
     (textterminput.otherindexentryfour != texttermcur.otherindexentryfour) ||
     (textterminput.otherindexentryfive != texttermcur.otherindexentryfive) ||
     (textterminput.englishentry != texttermcur.englishentry) )
    different = true;

  if (different){
    // alert(" They are different, have to save" );
    var texttermchain="{{TextTerm";
    texttermchain += '|' + (textterminput.term ? textterminput.term : '');
    texttermchain += '|' + (textterminput.note ? textterminput.note : '');
    texttermchain += (textterminput.section ? '|' + textterminput.section : '');
    texttermchain += (textterminput.subnote ? '|' + textterminput.subnote : '');
    texttermchain += (textterminput.indexentry ? '|IndexEntry='+ textterminput.indexentry : '');
    texttermchain += (textterminput.otherindexentry ? '|OtherIndexEntry='+ textterminput.otherindexentry : '');
    texttermchain += (textterminput.otherindexentrytwo ? '|OtherIndexEntryTwo='+ textterminput.otherindexentrytwo : '');
    texttermchain += (textterminput.otherindexentrythree ? '|OtherIndexEntryThree='+ textterminput.otherindexentrythree : '');
    texttermchain += (textterminput.otherindexentryfour ? '|OtherIndexEntryFour='+ textterminput.otherindexentryfour : '');
    texttermchain += (textterminput.otherindexentryfive ? '|OtherIndexEntryFive='+ textterminput.otherindexentryfive : '');
    texttermchain += (textterminput.englishentry ? '|EnglishEntry='+ textterminput.englishentry : '');
    texttermchain += "}}";
    
    var textarea= document.getElementById('wpTextbox1');
    var savepos= textarea.selectionStart;
    if ('selectionStart' in textarea) {
      textarea.value=textarea.value.substring(0,textarea.selectionStart) + texttermchain + textarea.value.substring(textarea.selectionEnd, textarea.length); 
      //insertTags(texttermchain, '', '');
      textarea.selectionStart = savepos;
      textarea.selectionEnd = savepos + texttermchain.length;
    }
    else{
      alert("No selectionStart firefox");
    }
  }
  else{
    ;//alert(" They are similar, don't save" );
  }
  document.getElementById('citediv'+numforms).style.display = 'none';
  
}
 
function addcites(template) {
  cites = document.getElementById('citediv'+numforms).getElementsByTagName('input');
  var citebegin = '<ref';
  var citename = '';
  var citeinner = '';
  for (var i=0; i<cites.length-1; i++) {
    if (cites[i].value != '' && cites[i].id != "refname" && cites[i].id != "template") {
      citeinner += "|" + cites[i].id + "=" + cites[i].value;
    }
    else if (cites[i].value != '' && cites[i].id == "refname" && cites[i].id != "template") {
      citebegin += ' name="' + cites[i].value + '"';
    }
    else if (cites[i].value != '' && cites[i].id != "refname" && cites[i].id == "template") {
      citename = '>{{' + cites[i].value;
    }
  }
  cite = citebegin + citename + citeinner + "}}</ref>";
  $("#wpTextbox1").focus();
  insertTags(cite, '', '');
  document.getElementById('citediv'+numforms).style.display = 'none';
}
 
function getNamedRefs(calls) {
  if (typeof(wikEdUseWikEd) != 'undefined') {
    if (wikEdUseWikEd == true) {
      WikEdUpdateTextarea();
    }
  }
  text = document.getElementById('wpTextbox1').value;
  var regex;
  if (calls) {
    regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?\/ *?>/gi //'
  } else {
    regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)) *?>/gi //'
  }
  var namedrefs = [];
  var i=0;
  var nr=true;
  do {
    ref = regex.exec(text);
    if(ref != null){
      if (ref[5]) {
        namedrefs[i] = ref[5];
      } else if (ref[3]) {
        namedrefs[i] = ref[3];
      } else {
        namedrefs[i] = ref[6];
      }
      i++;
    } else {
      nr=false;
    }
  } while (nr==true);
  return namedrefs;
}
 
function citeNamedRef() {
  namedrefs = getNamedRefs(false);
  if (namedrefs == '') {
    oldFormHide();
    numforms++;
    out = '<div id="citediv'+numforms+'"><fieldset>'+
      '<legend>References in text</legend>There are no named refs (<tt>&lt;ref name="Name"&gt;</tt>) in the text</fieldset></div>';
    document.getElementById('citeselect').innerHTML += out;
  }
  else {
    oldFormHide();
    numforms++;
    form = '<div id="citediv'+numforms+'">'+
      '<fieldset><legend>References in article</legend>'+
      '<table cellspacing="5">'+
      '<tr><td><label for="namedrefs">&nbsp;Named references in text</label></td>'+
            '<td><select name="namedrefs" id="namedrefs">';
    for (var i=0;i<namedrefs.length;i++) {
      form+= '<option value="'+namedrefs[i]+'">'+namedrefs[i]+'</option>';
    }
    form+= '</select>'+
      '</td></tr></table>'+
      '<input type="button" value="Add citation" onClick="addnamedcite()">'+
      '</fieldset></div>';
     document.getElementById('citeselect').innerHTML += form;
  }
}
 
function addnamedcite() {
  name = document.getElementById('citediv'+numforms).getElementsByTagName('select')[0].value;
  ref = '<ref name="'+name+'" />';
  $("#wpTextbox1").focus();
  insertTags(ref, '', '');
  document.getElementById('citediv'+numforms).style.display = 'none';
}
 
function getAllRefs() {
  if (typeof(wikEdUseWikEd) != 'undefined') {
    if (wikEdUseWikEd == true) {
      WikEdUpdateTextarea();
    }
  }
  text = document.getElementById('wpTextbox1').value;
  regex = /< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim //"
  var allrefs = [];
  var i=0;
  var nr=true;
  do {
    ref = regex.exec(text);
    if(ref != null){
      if (ref[0].search(/[^\s]{150}/) != -1) {
        ref[0] = ref[0].replace(/\|([^\s])/g, "| $1");
      }
      ref[0] = ref[0].replace(/</g, "&lt;");
      ref[0] = ref[0].replace(/>/g, "&gt;");
      allrefs[i] = ref[0];
      i++;
    } else {
      nr=false;
    }
  } while (nr==true);
  return allrefs;
}
 
function NRcallError(namedrefs, refname) {
  for (var i=0; i<namedrefs.length; i++) {
    if (namedrefs[i] == refname) {
      return true;
    }
  }
  return false;
}
 
function errorCheck() {
  var allrefs = getAllRefs();
  var allrefscontent = [];
  var samecontentexclude = [];
  var sx=0;
  var templateexclude = [];
  var tx=0;
  var skipcheck = false;
  var namedrefcalls = getNamedRefs(true);
  for (var i=0; i<allrefs.length; i++) {
    allrefscontent[i] = allrefs[i].replace(/&lt; *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^'"\s]*?[^\/]\b)))? *?&gt;((.|\n)*?)&lt; *?\/? *?ref *?&gt;/gim, "$8");  //"
  }
  var namedrefs = getNamedRefs(false);
  var errorlist = [];
  var q=0;
  unclosed = document.getElementById('unclosed').checked;
  samecontent = document.getElementById('samecontent').checked;
  templates = document.getElementById('templates').checked;
  repeated = document.getElementById('repeated').checked;
  undef = document.getElementById('undef').checked;
  for (var i=0; i<allrefs.length; i++) {
    if (allrefs[i].search(/&lt; *?\/ *?ref *?&gt;/) == -1 && unclosed) {
      errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
      errorlist[q] += '<td width="25%">Unclosed <tt>&lt;ref&gt;</tt> tag</td></tr>';
      q++;
    }
    if (samecontent) {
      for (var d=0; d<samecontentexclude.length; d++) {
        if (allrefscontent[i] == samecontentexclude[d]) {
          skipcheck = true;
        }
      }
      var p=0;
      while (p<allrefs.length && !skipcheck) {
        if (allrefscontent[i] == allrefscontent[p] && i != p) {
          errorlist[q] = '<tr><td width="75%"><tt>'+allrefscontent[i]+'</tt></td>';
          errorlist[q] += '<td width="25%">Multiple refs contain this content, a <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> should be used instead</td></tr>';
          q++;
          samecontentexclude[sx] = allrefscontent[i]
          sx++;
          break;
        }
        p++;
      }
     skipcheck=false;
    }
    if (templates) {
      if (allrefscontent[i].search(/\{\{cite/i) == -1 && allrefscontent[i].search(/\{\{citation/i) == -1 && allrefscontent[i].search(/\{\{Comic (book|strip) reference/i) == -1 && allrefscontent[i].search(/\{\{Editorial cartoon reference/i) == -1 && allrefscontent[i].search(/\{\{harv/i) == -1) {
        for (var x=0; x<templateexclude.length; x++) {
          if (allrefscontent[i] == templateexclude[x]) {
            skipcheck = true;
          }
        }
        if (!skipcheck) {
          errorlist[q] = '<tr><td width="75%"><tt>'+allrefs[i]+'</tt></td>';
          errorlist[q] += '<td width="25%">Does not use a <a href="//en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a></td></tr>';
          q++;
          templateexclude[tx] = allrefscontent[i];
          tx++;
        }
        skipcheck = false;
      }
    }
  }
  if (repeated) {
    var repeatnameexclude = [];
    var rx=0;
    for (var k=0; k<namedrefs.length; k++) {
      for (var d=0; d<repeatnameexclude.length; d++) {
        if (namedrefs[k] == repeatnameexclude[d]) {
          skipcheck = true;
        }
      }
      var z=0;
      while (z<namedrefs.length && !skipcheck) {
        if (namedrefs[k] == namedrefs[z] && k != z) {
          errorlist[q] = '<tr><td width="75%"><tt>'+namedrefs[k]+'</tt></td>';
          errorlist[q] += '<td width="25%">Multiple references are given the same <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">name</a></td></tr>';
          q++;
          repeatnameexclude[rx] = namedrefs[z];
          rx++;
          break;
        }
        z++;
      }
     skipcheck = false;
    }
  }
  if (undef) {
    var undefexclude = [];
    var ux=0;
    for (var p=0; p<namedrefcalls.length; p++) {
      for (var d=0; d<undefexclude.length; d++) {
        if (allrefscontent[i] == undefexclude[d]) {
          skipcheck = true;
        }
      }
      if (!skipcheck) {
        if (!NRcallError(namedrefs, namedrefcalls[p])) {
          errorlist[q] = '<tr><td width="75%"><tt>'+namedrefcalls[p]+'</tt></td>';
          errorlist[q] += '<td width="25%">A <a href="//en.wikipedia.org/wiki/Wikipedia:Footnotes#Naming_a_ref_tag_so_it_can_be_used_more_than_once">named reference</a> is used but not defined</td></tr>';
          q++;
          undefexclude[ux] = namedrefs[p];
          ux++;
        }
      }
      skipcheck = false;
    }
 }
  if (q > 0) {
    return errorlist;
  } else {
    return 0;
  }
}
 
function dispErrors() {
  oldFormHide();
  form = '<div id="errorform"><fieldset>'+
    '<legend>Error checking</legend>'+
    '<b>Check for:</b><br/>'+
    '<input type="checkbox" id="unclosed" /> Unclosed <tt>&lt;ref&gt;</tt> tags<br/>'+
    '<input type="checkbox" id="samecontent" /> References with the same content<br/>'+
    '<input type="checkbox" id="templates" /> References not using a <a href="//en.wikipedia.org/wiki/Wikipedia:Citation_templates">citation template</a><br/>'+
    '<input type="checkbox" id="repeated" /> Multiple references with the same name<br/>'+
    '<input type="checkbox" id="undef" /> Usage of undefined named references<br/>'+
    '<input type="button" id="errorchecksubmit" value="Check for selected errors" onclick="doErrorCheck()"/>'+
    '</fieldset></div>';
  document.getElementById('citeselect').innerHTML += form;
}
 
function doErrorCheck() {
  var errors = errorCheck();
  document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
  if (errors == 0) {
    if (numforms != 0) {
      document.getElementById('citediv'+numforms).style.display = 'none';
    }
    numforms++;
    out = '<div id="citediv'+numforms+'"><fieldset>'+
      '<legend>Error checking</legend>No errors found.</fieldset></div>';
    document.getElementById('citeselect').innerHTML += out;
  }
  else {
    if (numforms != 0) {
      document.getElementById('citediv'+numforms).style.display = 'none';
    }
    numforms++;
    form = '<div id="citediv'+numforms+'">'+
      '<fieldset><legend>Error checking</legend>'+
      '<table border="1px">';
    for (var i=0; i<errors.length; i++) {
      form+=errors[i];
    }
    form+= '</table>'+
      '</fieldset></div>';
     document.getElementById('citeselect').innerHTML += form;
  }
}
 
$( refbuttons );