_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:Dl2000/DateFix.js

Nowadays, User:Dl2000/DateFix.js is a topic that has gained great relevance in today's society. Since its emergence, User:Dl2000/DateFix.js has captured the attention of experts, academics, and people of all ages. Whether due to its impact in the social, economic or technological sphere, User:Dl2000/DateFix.js has positioned itself as a topic of general interest that deserves to be analyzed and discussed in depth. In this article, we will explore the different facets of User:Dl2000/DateFix.js, its importance in today's world and the possible future scenarios that could arise from its evolution. Through a detailed analysis, we will address the most relevant aspects of User:Dl2000/DateFix.js to understand its influence on our daily lives and society as a whole.
// <nowiki><pre>
// This script aligns dates, currencies and potentially other formatting e.g. international format
// for many nations per ] or {{A$}} template for Australian dollar.
// PLEASE READ THE DOCUMENTATION at ] (click on the link above) before using.
 
// Feedback and constructive criticism are welcome
// -- disable - some bugs in the general formatting, and much of this was not related
// -- to date fixing e.g. lowercasing "Career" in headings or removing word "Notable" in hdgs

function Dl2_formatgeneral(){
// reserved for any future general formatting
}
 
function Dl2_fix_common_errors() {
 var txt=document.editform.wpTextbox1;
 
// capitalise month names
	txt.value=txt.value.replace(/(\s)jan(|uary|\.)(\s)/g, '$1Jan$2$3');
	txt.value=txt.value.replace(/(\s)feb(|ruary|\.)(\s)/g, '$1Feb$2$3');
	txt.value=txt.value.replace(/(\d\s)mar(|ch|\.)(\s)/g, '$1Mar$2$3');
	txt.value=txt.value.replace(/(\s)mar(|ch|\.)(\s\d)/g, '$1Mar$2$3');
	txt.value=txt.value.replace(/(\s)apr(|il|\.)(\s)/g, '$1Apr$2$3');
	txt.value=txt.value.replace(/(\d\s)may(,|\.)(\s)/g, '$1May$2$3');
	txt.value=txt.value.replace(/(\s)may(|\.)(\s\d)/g, '$1May$2$3');
	txt.value=txt.value.replace(/(\s)jun(|e|\.)(\s)/g, '$1Jun$2$3');
	txt.value=txt.value.replace(/(\s)jul(|y|\.)(\s)/g, '$1Jul$2$3');
	txt.value=txt.value.replace(/(\s)aug(|ust|\.)(\s)/g, '$1Aug$2$3');
	txt.value=txt.value.replace(/(\s)sep(|tember|\.)(\s)/g, '$1Sep$2$3');
	txt.value=txt.value.replace(/(\d{1,2}\s)sept(\s)/g, '$1Sep$2');
	txt.value=txt.value.replace(/(\s)oct(|ober|\.)(\s)/g, '$1Oct$2$3');
	txt.value=txt.value.replace(/(\s)nov(|ember|\.)(\s)/g, '$1Nov$2$3');
	txt.value=txt.value.replace(/(\s)dec(|ember|\.)(\s)/g, '$1Dec$2$3');
 
	txt.value=txt.value.replace(/(\d)(?:-|–|&ndash;)P(resent)/g, '$1 – p$2');
 
//underscore in linked dates - dmy
	txt.value=txt.value.replace(/(\?\d)_(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\]\])/gi, '$1 $2$3');
//underscore in linked dates - mdy
	txt.value=txt.value.replace(/(\?\d\]\])/gi, '$1$2 $3');
 
//remove leading zero from linked date
	txt.value=txt.value.replace(/(\\])/gi, '$1$2 $3$4');
	txt.value=txt.value.replace(/(\\])/gi, '$1$2 $3$4');
 
//rem redundant spaces (and commas) in date formats
	txt.value=txt.value.replace(/(\?\d)+(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\]\])?*,*(\?\]?)/gi, '$1 $2$3 $4');
	txt.value=txt.value.replace(/(\+(?\d|30|31)(\]?\]?)(?:*,*)(\?\]?)/gi, '$1$2 $3$4, $5');
	txt.value=txt.value.replace(/(\+(?\d|30|31)(\]?\]?)+(\?\]?)/gi, '$1$2 $3$4, $5');
 
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(?:, | of )(\d{3,4})/gi, '$1 $2'); //repeat after delinking
 
//remove unlinked ordinal date formats
	txt.value=txt.value.replace(/(?:the\s?)?(?\d)(?:th|st|nd|rd|), (?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))()/g, '$1, $2$3 $4 $5');
	txt.value=txt.value.replace(/(?:the\s?)?(?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))()/g, '$1$2 $3$4');
	txt.value=txt.value.replace(/(?:the\s?)?(?\d)(?:th|st|nd|rd|)(?:\sof\s?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\w\d])/g, '$1 $2$3');
	txt.value=txt.value.replace(/(?:the\s?)?(?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))()/g, '$1 $2$3');
	txt.value=txt.value.replace(/(?:the\s?)?(?\d)<sup>(?:th|st|nd|rd|)<\/sup>(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))()/g, '$1 $2$3');
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?(?\d)(?:th|st|nd|rd|),\s(?:the\s)?(?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s)(?:the\s)?(?\d)(?:th|st|nd|rd|)(\|\w\d])/g, '$1 $2, $3$4 $5$6');
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?(?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s)(?:the\s)?(?\d)(?:th|st|nd|rd|)(\|\w\d])/g, '$1 $2$3$4$5');
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?(?\d)(?:th|st|nd|rd)(\|\w\d])/g, '$1 $2$3');
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?(?\d)<sup>(?:th|st|nd|rd)<\/sup>(\|\w\d])/g, '$1 $2$3');
 
//fix 'bda' template redirect
	txt.value=txt.value.replace(/{{bda\|(+)}}/gi, '{{birth date and age|$1}}');
 
//fix 'startdate' template redirect
	txt.value=txt.value.replace(/{{startdate\|(+)}}/gi, '{{start date|$1}}');

//zap redundant templates ('date', 'as of', 'English', '#dateformat:') 
	txt.value=txt.value.replace(/\{\{date\|(+)(?:+)?\}\}/gi, '$1');
	txt.value=txt.value.replace(/{{#dateformat:(+)(?:\|dmy|\|mdy)?}}/gi,'$1'); 
 
}
 
function Dl2_protect_dates_in_titles(){
 var txt=document.editform.wpTextbox1;
 
//permanent protection for dmy dates within images
	txt.value=txt.value.replace(/((?:file|image|img)*{1,30})\s(?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?(\s(?:?\d{3}))?/gi, '$1_$2$3$4_$5$6$7');
	txt.value=txt.value.replace(/(\((?:file|image|img)*?\d)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?(\s(?:?\d{3}))?/gi, '$1$2$3_$4$5_$6$7');
 
	txt.value=txt.value.replace(/(?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?\s(\d{3})(\.jpe?g)/gi, '$1$2$3_$4$5_$6$7');
	txt.value=txt.value.replace(/(?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\.jpe?g)/gi, '$1$2$3_$4$5');
 
//protect dmy date formats within titles of citation templates
	txt.value=txt.value.replace(/(\|*(?:title|work|journal|quote)*=*)((?:?\d)(?:th|st|nd|rd|),?(?:\sof)?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))({0,30}\|)/gi, '$1$2&nbsp;$3$4');
//blockquotes
	txt.value=txt.value.replace(/(<blockquote>+?)((?:?\d)(?:th|st|nd|rd|),?(?:\sof)?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,?\s?\d{3})?(+?<\/blockquote>)/g, '$1$2&nbsp;$3$4$5');

//image gallery
        var rxI = new RegExp("({{mage gallery+?)((?:?\\d)(?:th|st|nd|rd|),?(?:\\sof)?)\\s(Jan(?:uary|\\.|)|Feb(?:ruary|\\.|)|Mar(?:ch|\\.|)|Apr(?:il|\\.|)|May\\.?|Jun(?:e|\\.|)|Jul(?:y|\\.|)|Aug(?:ust|\\.|)|Sep(?:tember|\\.|t\\.|)|Oct(?:ober|\\.|)|Nov(?:ember|\\.|)|Dec(?:ember|\\.|))(,?\\s?\\d{3})?(+?}})", "g");

        // process for possibly multiple image params
        var dfound = txt.value.search(rxI);
        var sanitycount = 12;
        while ((dfound >= 0) && (sanitycount > 0))
        {
            txt.value=txt.value.replace(rxI, '$1$2&nbsp;$3$4$5');
            dfound = txt.value.search(rxI);
            sanitycount = sanitycount - 1;
        }

//permanent protection for mdy dates within images
	txt.value=txt.value.replace(/((?:file|image|img)*{1,60})\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s(?\d|30|31)(th|st|nd|rd|)((.)?\s(?:?\d{3}))?/gi, '$1_$2$3_$4$5$6');
txt.value=txt.value.replace(/((?:file|image|img)*)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s(?\d|30|31)(th|st|nd|rd|)(,)?(\s(?:?\d{3}))?/gi, '$1$2$3_$4$5$6$7'); //re-enabled 13 Aug 2010
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s(?\d|30|31)(th|st|nd|rd|)(,)?\s(\d{3})(\.(?:png|jpe?g))/gi, '$1$2_$3$4$5_$6$7');
	txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s(?\d|30|31)(th|st|nd|rd|)(\.png|\.jpe?g)/gi, '$1$2_$3$4$5');

// infobox image param
	txt.value=txt.value.replace(/(image*=*)(Jan(?:uary|\.)|Feb(?:ruary|\.)|Mar(?:ch|\.)|Apr(?:il|\.)|May\.?|Jun(?:e|\.)|Jul(?:y|\.)|Aug(?:ust|\.)|Sep(?:tember|\.|t\.)|Oct(?:ober|\.)|Nov(?:ember|\.)|Dec(?:ember|\.))\s(.*\.png|.*\.jpe?g)/gi, '$1_$2_$3');

//protect mdy date formats within titles of citation templates
	txt.value=txt.value.replace(/(\|*(?:title|work|journal|quote|chapter)*=+?)()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s((?:?\d)(?:th|st|nd|rd|))(|*?\||*?\})/gi, '$1$2$3$4&nbsp;$5$6');
//blockquotes
	txt.value=txt.value.replace(/(<blockquote>+?)()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s((?:?\d)(?:th|st|nd|rd|),?)\s(\d{3})(+?<\/blockquote>)/g, '$1$2$3$4&nbsp;$5&nbsp;$6$7');

// protect mdy in cquote
	txt.value=txt.value.replace(/(\{\{cquote+?)()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s((?:?\d)(?:th|st|nd|rd|),?)\s(\d{3})(+?\}})/gim, '$1$2$3$4&nbsp;$5&nbsp;$6$7');
}


function Dl2_code_delink_dates() {
 var txt=document.editform.wpTextbox1;
 Dl2_protect_dates ();
 Dl2_fix_common_errors();
//delink ISO8601 dates
	txt.value=txt.value.replace(/\\d{3}-\d-\d)\]\]/gi, '$1');
	txt.value=txt.value.replace(/\\d{3})\]\]-\\d-\d)\]\]/gi, '$1-$2');
	txt.value=txt.value.replace(/(\d{3})-\\d-\d)\]\]/gi, '$1-$2');
	txt.value=txt.value.replace(/\\d{3})\]\]-(\d-\d)/gi, '$1-$2');
 
//delink full dates
	txt.value=txt.value.replace(/\?\d)(?:th|st|nd|rd|)(?:of)?(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(?:\]\] \\d{3})\]\]/gi, '$1 $2 $3');  
 
	txt.value=txt.value.replace(/\?\d)(?:th|st|nd|rd|)(?:\]\],? \\d{3})\]\]/gi, '$1 $2, $3');  
 
//delink single dm or 'dth the m'
	txt.value=txt.value.replace(/(?:the\s)?\?\d)(?:th|st|nd|rd|)(?:of)?(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\]/gi, '$1 $2');  
 
//delink single md or 'm the dth'
	txt.value=txt.value.replace(/\(?:the)?(?\d)(?:th|st|nd|rd|)\]\]()/gi, '$1 $2$3');
 
//Month+day_number "]th" -> "March 7"
	txt.value=txt.value.replace(/\?\d)\]\](?:th|st|nd|rd)/gi, '$1');
 
//month+day+year piped pseudo-ISO dates
	txt.value=txt.value.replace(/\?\d|30|31)\|?\d-?\d\]\]-(?:\\d\d\d)(\|\d{2,4})?(?:\]\])?/gi, '$1$2, $3');
	txt.value=txt.value.replace(/\\d\s(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))\|?\d-?\d\]\]-(?:\\d{3})(\]\])?/gi, '$1 $2');
 
//month+day piped
	txt.value=txt.value.replace(/(?:the\s)?\(?:of)?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\|(]{1,30})\]\]/gi, '$1');
 
 //']Xyyyy ' to 'month day, year'
	txt.value=txt.value.replace(/\\].(\d{3,4})/gi, '$1 $2, $3'); 
 //']Xyyyy' to 'day month year'
	txt.value=txt.value.replace(/\\].(\d{3,4})/gi, '$1 $2 $3'); 
 
// century
	txt.value=txt.value.replace(/\\]/gi, '$1$2$3');
	txt.value=txt.value.replace(/\(?:century|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|(]{1,30})\]\]/gi, '$1');
	txt.value=txt.value.replace(/\)(century|centuries)(\sAD|\sBC|\sCE|\sBCE|)\]\]/gi, '$1$2$3');
	txt.value=txt.value.replace(/\(?:century|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|(]{1,30})\]\]/gi, '$1');
 
// months
	txt.value=txt.value.replace(/\\]/gi, '$1');
	txt.value=txt.value.replace(/\]{1,30})\]\]/gi, '$1');
 
// decades and years -- disabling for now due to potential inappropriate delinks
	// txt.value=txt.value.replace(/\\]/g, '$1s');
	// txt.value=txt.value.replace(/\]{1,30})\]\]/g, '$1');
	// txt.value=txt.value.replace(/\\]/gi, '$1$2 $3');
	// txt.value=txt.value.replace(/\?)(AD|BC|CE|BCE|)\]\]/gi, '$1$2');
	// txt.value=txt.value.replace(/\?)(\d{1,4})\]\]/gi, '$3$2$1');
	// txt.value=txt.value.replace(/\]{1,30})\]\]/gi, '$1');
	// txt.value=txt.value.replace(/\]{1,30})\]\]/gi, '$1');
	// txt.value=txt.value.replace(/\{3,10})\]\]/g, '$1'); -- disabled - would delink things like ]
 
//month+year
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
	txt.value=txt.value.replace(/\]+\|((?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s\d{3,4})\]\]/gi, '$1');
	txt.value=txt.value.replace(/\\]/gi, '$1');
	txt.value=txt.value.replace(/\]{1,30})\]\]/gi, '$1');
 
//removed piped years when in full date
	txt.value=txt.value.replace(/(\\],?\s?\]{1,32}\|(\d{1,4}\]\])/gi, '$1$2');
	txt.value=txt.value.replace(/(\\],?\s?\]{1,32}\|(\d{1,4}\]\])/gi, '$1$2');
 
//Identify surprise or 'Easter egg' diversions linking months to year articles.
	txt.value=txt.value.replace(/\]+\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\]/gi, '$1');
 
// month and day piped
	txt.value=txt.value.replace(/(\d{4,4}-)\\d{1,2}(?:th|st|nd|rd|)\|(\d-)(\d)\]\]/gi, '$10$20$3');
	txt.value=txt.value.replace(/(\d{4,4}-)\\d{1,2}(?:th|st|nd|rd|)\|(\d\d-)(\d)\]\]/gi, '$1$20$3');
	txt.value=txt.value.replace(/(\d{4,4}-)\\d{1,2}(?:th|st|nd|rd|)\|(\d-)(\d\d)\]\]/gi, '$10$2$3');
	txt.value=txt.value.replace(/\\d{1,2}(?:th|st|nd|rd|)\|(]{1,30})\]\]/gi, '$1');
	txt.value=txt.value.replace(/\(?:of)?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\|(]{1,30})\]\]/gi, '$1');
	txt.value=txt.value.replace(/\\]/gi, '$1');
 
// spaces and commas - mdy birth and death date ranges
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31),? (\d{1,3}|?\d{3})(?:**)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31),? (\d{1,3}|?\d{3})()/gi, '$1$2 $3, $4 – $5 $6, $7$8');
//dmy birth and death date ranges)
	txt.value=txt.value.replace(/()(?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? (\d{1,3}|?\d{3})(?:\s?\s?)(?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? (\d{1,3}|?\d{3})()/gi, '$1$2 $3 $4 – $5 $6 $7$8');
 
}
 
function Dl2_delink_ISO_to_dmy() {
    var txt = document.editform.wpTextbox1;
 
// disable in-citation temporarily
//    txt.value = yyyymmdd_to_dmy(txt.value);  // adapted from User:Plastikspork/datetools.js

	txt.value=txt.value.replace(/()(\d{3}-\d\d-\d\d)(<\s?\/ref.*?>)/g, '$1$2 $3');

//code to convert ref ISO-dates in citation templates for certain cases

// -(\d)([^
// -0(\d)([^

// replace date=<ISO8601> within refs
	txt.value=txt.value.replace(/(<\s?ref.*?>+)(\|\s?date\s?=)(\d{3})-(0|1)-(\d)()(*?<\s?\/ref.*?>)/gm, 
            function(zz, start1, start2, yyyy, mm, dd, end1, end2)
            {
                return (start1 + start2 + dd + ' ' + Dl2_Monthname(mm) + ' ' + yyyy + end1 + end2);
            } );

    Dl2_remove_leading_zeros_from_nonlinked_dates ();   
 
}
 
var linkmap=;
function Dl2_protect_dates(){
 var txt=document.editform.wpTextbox1;
	txt.value=txt.value.replace(/Image:+/gi, function(img){
        linkmap.push(img);
        return "\x02"+(linkmap.length-1)+"\x03";
    });
//protect certain dates 
	txt.value=txt.value.replace(/(\[\[4)(AD)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(March )((?:8|14) Alliance)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(movement 2) (June)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(6th\sof\s)(October City)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(19th\sof\s)(April movement)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(\\])/gi, '$1 in France|May 1968$2');
	txt.value=txt.value.replace(/(\\])/gi, '$1♫$2'); //June 1, 1974 is the name of an album
	txt.value=txt.value.replace(/(\'\'June )(1, 1974\'\')/gi, '$1♫$2'); 
	txt.value=txt.value.replace(/(\\])/gi, '$1:$2');

	Dl2_protect_dates_in_titles();
}
 
function Dl2_unprotect_dates(){
 var txt=document.editform.wpTextbox1;
 
//unprotect certain dates
	txt.value=txt.value.replace(/(\[\[4)♫(AD)/gi, '$1♫$2');
	txt.value=txt.value.replace(/(\[\[(?:8|14))♫(March Alliance)/gi, '$1$2');
	txt.value=txt.value.replace(/(movement 2)♫(June)/gi, '$1 $2');
	txt.value=txt.value.replace(/(6th\sof\s)♫(October City)/gi, '$1$2');
	txt.value=txt.value.replace(/(19th\sof\s)♫(April movement)/gi, '$1$2');
	txt.value=txt.value.replace(/(June )♫(1, 1974)/gi, '$1$2');
	txt.value=txt.value.replace(/(\w)♫(\w)/g, '$1$2');	//2010-10-06 quick patch to remove any spurious protection markers
	txt.value=txt.value.replace(/\x02(+)\x03/g, function(x, n){
        return linkmap;
    });
}
 
function Dl2_remove_leading_zeros_from_nonlinked_dates () {
 var txt=document.editform.wpTextbox1;
//remove leading zero from nonlinked date
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s0(\d)(?:th|st|nd|rd|),?\s(\d{3})(|\b)/gi, '$1$2 $3, $4$5');
	txt.value=txt.value.replace(/()0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{3})(|\b)/gi, '$1$2 $3 $4$5');
 
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s0(\d)(?:th|st|nd|rd|)(|\b)/gi, '$1$2 $3$4');
	txt.value=txt.value.replace(/()0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(|\b)/gi, '$1$2 $3$4');
 
}

// Tag only
function Dl2_Monthname(monthcode) {
    var myMonths = new Array("0", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    return myMonths; // the , 10 avoids the jscript cootie where "08" is translated to "0"
}

function Dl2_Monthcode(monthname) {
    var myMonths = ;

    var mthcode = myMonths.indexOf(monthname.toLowerCase()) + 1;

    return mthcode;
}

function Dl2_CurrMY() {
// current month-year
    var currentDate = new Date();
    var currmonth = currentDate.getMonth();
    var curryear  = currentDate.getFullYear();
    var myMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var curryyyymm = myMonths + ' ' + curryear;

    return curryyyymm;
}

function Dl2_IntlTag1() {
    var txt=document.editform.wpTextbox1;
    Dl2_IntlTag(txt);
}

function Dl2_IntlTag(txta){
// leave an existing tag alone
    var rxpd1 = new RegExp("{{Use dmy dates(\\|*)?}}", "gi");
    var ddfound = txta.value.search(rxpd1);
    if (ddfound >= 0)
    {
        return;
    }

// current month-year
    var curryyyymm = Dl2_CurrMY();

// insert or update 'dmy' template
    txta.value=txta.value.replace(/{{(use (dmy|mdy) dates|dmy|mdy)(\|*)?}}/gi, '{{Use dmy dates|date='+curryyyymm+'}}');

    var rxpdd = new RegExp("{{Use dmy dates\\|date="+curryyyymm+"}}", "gi");
    var dflagfound = txta.value.search(rxpdd);
    if (dflagfound == -1)
    {
        txta.value='{{Use dmy dates|date='+curryyyymm+'}}\r\n'+txta.value;
    }
}
 
function Dl2_BDA() {
  var txt=document.editform.wpTextbox1;

  var case1handled = 0;

  // case 1: birth_date = dd MMM yyyy
	txt.value=txt.value.replace(/(birth_date*=*)(?)*(+)*()(*\(age.*\))?/gi,
            function(zz, start1, dd, mmm, yyyy, end1)
            {
                var newbda;
                var andage = '';
                if (parseInt(yyyy) > 1920)
                {
                    andage = ' and age';
                }
                newbda =  (start1 + '{{birth date' + andage + '|' + yyyy + '|' + Dl2_Monthcode(mmm) + '|' + dd + '|df=y}}' );
                case1handled = 1;
                return newbda;
            } );

  // case 2: existing {{birth date| - but only if not handled in case 1, and then only for sensible years
  if (case1handled == 0)
  {
    txt.value=txt.value.replace(/{{birth date\|(19)\|/gi, '{{birth date and age|$1|');
  }

  var txtsumm=document.editform.wpSummary;
  var summary = "bda";
  if (txtsumm.value.indexOf(summary) == -1) {
    if (txtsumm.value.match(/?\s*$/)) {
      txtsumm.value += " | ";
    }
    txtsumm.value += summary;
  }
  document.forms.editform.wpMinoredit.checked = true;

  document.editform.wpDiff.click();
}

function Dl2_dates_to_dmy(){
 var txt=document.editform.wpTextbox1;

    Dl2_IntlTag(txt);

    Dl2_code_delink_dates();
//repeat protect dates because 'unprotect dates' function is within 'delink dates' function
    Dl2_protect_dates();
 
//change start and end templates
	txt.value=txt.value.replace(/({{(start\sdate|end\sdate)*\|)df=ye?s?\|(*df=ye?s?)/gi, '$1$2');
 
//change deprecated birth and death templates
	txt.value=txt.value.replace(/({{(?:Birth|Death|release|film date|start date|end date)*)\|mf=ye?s?/gi, '$1');
	txt.value=txt.value.replace(/({{(?:Birth|Death|release|film date|start date|end date)*\|)/gi, '$1df=yes|');
	txt.value=txt.value.replace(/({{(?:Birth|Death|release|film date|start date|end date)*\|)df=ye?s?\|(*df=ye?s?)/gi, '$1$2');
 
// dts - format=dmy in this case
        // per {{dts}} doc, remove the obsolete link=off param
	txt.value=txt.value.replace(/({{dts*)(\|link=off)/gi, '$1');
        // clean up existing format...
	txt.value=txt.value.replace(/({{dts*)(\|format=(dmy|mdy))/gi, '$1');
        // then ensure format=dmy is applied if year is first (bugfix courtesy Ohconfucius)
        // txt.value=txt.value.replace(/({{dts*\|)/gi, '$1format=dmy|'); - false pos when date not yr first
        txt.value=txt.value.replace(/(\{\{dts*\|)(?=\d{4})/gi, '$1format=dmy|');

//convert mdy-mdy to dmy-dmy (birth and death date ranges)
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31), (?\d{0,3})(?:\s?\s?)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31), (?\d{0,3})()/g, '$1$3 $2 $4 – $6 $5 $7$8');
 
//convert md-mdy date ranges to dm-dmy
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|)((?:,\s?\d(?:th|st|nd|rd|)){0,6}),?(\/|\s?\s?|\s(?:and|to|&)\s)(?\d|30|31)(?:th|st|nd|rd|),?\s(?:of\s)?(\d{3,4})/g, '$1$3$4$5$6 $2 $7');
//test code	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|)((?:,?\s?\d(?:th|st|nd|rd|)){0,6}),? (?\d|30|31)(?:th|st|nd|rd|),?\s(?:of\s)?(\d{3,4})/g, '$1$3$4, $5 $2$6');
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|)((?:,\s?\d(?:th|st|nd|rd|)){0,6}), (?\d|30|31)(?:th|st|nd|rd|)(|\b)/g, '$1$3$4, $5 $2$6');
 
//convert md,d,d, date ranges to d,d,dm  (multiple, separated by commas)
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d)(?:th|st|nd|rd|)((?:,?\s(?\d|30|31)(?:th|st|nd|rd|)){0,6}),?(\/|\s?\s?|\s(?:and|to|&)\s)(?\d|30|31)(?:th|st|nd|rd|)(|\b)/g, '$1$3$4$5$6 $2$7');
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))((?:\s?\d(?:th|st|nd|rd|),?){1,6})(\s(?:and|to|&)\s)(?\d|30|31)(?:th|st|nd|rd|)(|\b)/g, '$1$3$4$5 $2$6');
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d)(?:th|st|nd|rd|)((?:,?\s?\d(?:th|st|nd|rd|)){1,6})(|\b)/g, '$1$3$4 $2$5');
//convert md date ranges to dm  (simple, separated by hyphens and dashes  or 'to')
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d)(?:th|st|nd|rd|)(\s?\s?|\sto\s)(?\d|30|31)(?:th|st|nd|rd|)(|\b)/g, '$1$3 $4$5 $2$6');
 
//'md, md,' to 'dm, dm,'
	txt.value=txt.value.replace(/()( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))( ?\d|30|31),( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))( ?\d|30|31)()/g, '$1$3$2,$5$4,$6'); 
 
//convert simple mdy dates to dmy
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|),?\s(\d{1,4}\s?(?:AD|BC|CE|BCE))/g, '$1$3 $2 $4');
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|),?\s(\d{3})(|\b)/g, '$1$3 $2 $4$5');
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|)(|\b)/g, '$1$3 $2$4');
//Repeat line to capture some instances that get missed first time 
//(needed because the date component 'September 19, 1881' within the string 'March 4-September 19, 1881' is blocked from conversion by the '4')
	txt.value=txt.value.replace(/()(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?\d|30|31)(?:th|st|nd|rd|),?\s(\d{1,4})(|\b)/g, '$1$3 $2 $4$5');
 
//Month+day_number " 7th March" -> "7 March"
	txt.value=txt.value.replace(/()(?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{1,4})(|\b)/g, '$1$2 $3 $4$5');
	txt.value=txt.value.replace(/()(?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(|\b)/g, '$1$2 $3$4');
 
 Dl2_remove_leading_zeros_from_nonlinked_dates ();
//remove comma in International date format
	txt.value=txt.value.replace(/(?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),?\s?(\d{3,4})()/g, '$1 $2 $3$4');
 
 Dl2_unprotect_dates();
 
}
 
function Dl2_MOSNUM_edit_summary(nation){
// Add a tag to the summary box
 var txt=document.editform.wpSummary;
    var summary = "unify formatting per ], script-assisted (" + nation + " subject)";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/?\s*$/)) {
			txt.value += ", ";
		}
		txt.value += summary;
	}
//	document.forms.editform.wpMinoredit.checked = true;
	document.editform.wpDiff.click();
}
 
function Dl2_ADollar() {
  var txt=document.editform.wpTextbox1;

  txt.value=txt.value.replace(/{{AUD\|(+)}}/, '{{A\$|$1}}');
  txt.value=txt.value.replace(/\\]/gi, '{{A\$}}');
  txt.value=txt.value.replace(/AU\$/gi, 'A\$');
}

// type - the full word of the English variant type to be tagged to
function Dl2_EngTag(type) {
    var txt=document.editform.wpTextbox1;

    // If there's an existing tag, prompt to override
    langvars = new Array("American", "Australian", "British (Oxford)", "British", "Canadian", "Indian", "Irish", "Pakistani" );
    var curryyyymm = Dl2_CurrMY();

    for (i = 0; i < langvars.length; i++)
    {
        var rxTemp = new RegExp('{{*(?:se+' + langvars + '+English|ngvarB)*(?:|\\|*date*=*)*}}', 'gi');
        if ((langvars != type) && (txt.value.search(rxTemp) >= 0))
        {
            if (confirm(langvars + ' English tag already exists - override?'))
            {
                var newtag='{{Use ' + type + ' English|date='+curryyyymm+'}}';
                txt.value=txt.value.replace(rxTemp, newtag);
            }
            else
            {
                return;
            }
        }
    }

    // add tag if not already present (or changed above)
    var rxpdd = new RegExp("{{Use " + type + " English", "gi");
    var dflagfound = txt.value.search(rxpdd);
    if (dflagfound == -1)
    {
        txt.value='{{Use ' + type + ' English|date='+curryyyymm+'}}\r\n'+txt.value;
    }
}
 
function Dl2_all_dates_to_dmy(nation) {
  Dl2_formatgeneral();
  Dl2_dates_to_dmy();
  Dl2_delink_ISO_to_dmy();
  Dl2_MOSNUM_edit_summary(nation);
}

function Dl2_Australianate() {
  Dl2_ADollar();
  Dl2_EngTag("Australian");
  Dl2_all_dates_to_dmy("AUS");
}

function Dl2_NewZealandate() {
  Dl2_all_dates_to_dmy("NZL");
}

function Dl2_UKanate() {
  Dl2_EngTag("British");
  Dl2_all_dates_to_dmy("UK");
}

function Dl2_IntlDate() {
  Dl2_all_dates_to_dmy("international");
}

function Dl2_AusNZate() {
  Dl2_EngTag("Australian");
  Dl2_all_dates_to_dmy("AUS/NZL");
}

function Dl2_IEanate() {
  Dl2_all_dates_to_dmy("IRL");
}

function Dl2_ZAanate() {
  Dl2_all_dates_to_dmy("ZAF");
}
 
function Dl2_Indianate() {
  Dl2_all_dates_to_dmy("IND");
}
 
$(function () {
 if(document.forms.editform) {
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_Australianate()', 'Australianate', 'ca-unitfixer', 'Format for Australia', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_NewZealandate()', 'New Zealandate', 'ca-unitfixer', 'Format for New Zealand', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_AusNZate()', 'AUS/NZ', 'ca-unitfixer', 'Format for Australia/New Zealand', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_UKanate()', 'UKanate', 'ca-unitfixer', 'Format for UK', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_IEanate()', 'Irelandate', 'ca-unitfixer', 'Format for Ireland', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_ZAanate()', 'South Africanate', 'ca-unitfixer', 'Format for South Africa', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_Indianate()', 'Indianate', 'ca-unitfixer', 'Format for India', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_IntlDate()', 'International dates', 'ca-unitfixer', 'International date formatting', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_IntlTag1()', 'Intl tag', 'ca-unitfixer', 'International dmy date tag', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Dl2_BDA()', 'BDA', 'ca-unitfixer', 'Add age to infobox birth dates', '', '');

  }
});
// </pre></nowiki>