
<!-- JavaScript code by Mark A. Agius // Code hidden from non-JavaScript web browsers

/*
==================================================================
 ScriptFile.js will return a Roman number from a decimal number.
 Used on http://members.aol.com:/MarkAgius website upto October 2008.
 Minor edit on  6/04/2010, moved to my markagius.co.uk website and
 renamed file ScriptFile.js as romanscript.js
==================================================================
 FILE NAME       ;   ScriptFile.js
 DESIGNER/AUTHOR ;   Mark A. Agius, (c)1998-2000
 DATE AND VERSION;   14/06/1998-28/02/1999, version 0.00a
 NOTES           ;   This js file (ScriptFile.js) has been converted from some
                     JavaScript/JSScript code in a HTMP web page. This JavaScript
                     was in turn converted from an old Acorn BBC basic program,
                     which I wrote in March 1995.  I have also used the BBC basic code in my
                     !Base_X application, which you can download from my programs page at;
                     http://members.aol.com:/MarkAgius/WebPages/Programs.htm
 HTML CODE       ;   To use this file from your HTML web page use the following code;
 ¦  
 ¦  Copyright; Mr. M. Agius, &copy; 
 ¦  <NOSCRIPT><!-- Browser dosn't suport script -->
 ¦  <!-- 1962 -->
 ¦  MCMLXII
 ¦  </NOSCRIPT>
 ¦  
 ¦  <SCRIPT SRC="ScriptFile.js"></SCRIPT>
 ¦  <SCRIPT LANGUAGE="JavaScript"><!--
 ¦  the_R_year = roman_number(1962,"")
 ¦  document.write(the_R_year)
 ¦  if (this_year!=1962){
 ¦    the_R_year = roman_number("*","")
 ¦    document.write(" - "+the_R_year)
 ¦  }
 ¦  //--></SCRIPT>
 ¦  1962 - 2000
 ¦  


==================================================================
*/
version = "0.01"
date    = "26/06/2000"

var this_year=new Date();
var this_year=this_year.getFullYear();

//--------------------------------------------------

function roman_number(number,flag){
  number=number+""
  if (number.toUpperCase().substring(0,7)=="VERSION"){
    output="<NOBR><FONT COLOR=\"Red\"><BR>JavaScript code by <B>Mark A. Agius</B> (c) ";
    versionYear=date.substring(date.lastIndexOf("/")+1)
    if (versionYear!=this_year){output=output+roman_number(versionYear,"*")+" - "}
    output=output+roman_number("THISYEAR","*")+"<BR>Version "+version+" ("+date+")</FONT></NOBR>";number="#"
  }
  if (number.toUpperCase().substring(0,4)=="HELP"){
    output="<NOBR><FONT COLOR=\"Green\"><BR><B><U>Help syntax;</U></B><BR>"
    output=output+" roman_number(\"Help\") = displays this help message.<BR>"
    output=output+" roman_number(\"Version\") = displays version number of code.<BR>"
    output=output+" roman_number() = displays current year in Roman numerals with 'ad' at the end.<BR>"
    output=output+" roman_number(\"*\") = displays current year in Roman numerals with 'ad' at the end.<BR>"
    output=output+" roman_number(\"ThisYear\") = displays current year in Roman numerals with 'ad' at the end.<BR>"
    output=output+" roman_number(\"ThisYear\",\"*\") = displays current year in Roman numerals only.<BR>"
    output=output+" roman_number(\"*\",\"*\") = displays current year in Roman numerals only.<BR>"
    output=output+" roman_number(<I>&lt;number&gt;</I>) = displays <I>&lt;number&gt;</I> in  Roman numerals with 'ad' or 'bc' at the end.<BR>"
    output=output+" roman_number(<I>&lt;number&gt;</I>,\"*\") = displays <I>&lt;number&gt;</I> in  Roman numerals only.<BR>"
    output=output+" var this_year = the current year. <SMALL><I>(Eg. "+this_year+")</I></SMALL><BR>"
    output=output+"</FONT></NOBR>"
    number="#"
  }

  // If number is not set then set number to 'ThisYear'
  if (isNaN(number)){if (number!="#"){number="ThisYear"}}
  // If number = "*" then set number to 'ThisYear'
  if (number=="*"){number="ThisYear"}
  // - If string 'flag' = '*' then don't display 'bc' or 'ad' -
  display_ad_bc=true
  if (flag>""){
    if(flag=="*"){display_ad_bc=false}
  }
  if (number!="#"){
    // - If number is 'Undefined', null, NaN or number="ThisYear" then set number to current year -
    if (number.toUpperCase()=="THISYEAR"){
      // - Get current date (and time) -
      date_now=new Date()
      // - Get year from string -
      // Doesn't work on Netscape // number=date_now.getFullYear()
      number=date_now.getYear()
      // - Ugh years from 1900 to 1999 only display the last two digits -
      // -- Netscape returns '100' and not '0' for the year 2000 with ..getYear(), so next few lines modulate number by 100 first.
      if (number<=999){number=number%100;}
      if (number<=80){number=number+2000;}
      // -- End of added code for Netscape.
      if (number<100){number=1900+number}
    }
    // - Set the 'bc' or 'ad' flag, 'bc' = Before Christ and 'ad' = Anno Domini (After Christ) -
    if (number>=0){bc_ad="ad"} else {bc_ad="bc"}
    if (number==0){bc_ad=""}
    // - If string 'flag' = '*' then don't display 'bc' or 'ad' -
    if (!display_ad_bc) {bc_ad=""} else {bc_ad="<SMALL><I>"+bc_ad+"</I></SMALL>"}
    // - Turn negative numbers into positive numbers -
    number=Math.abs(number)
    // - Convert the number into Roman numerals -
    // - ====================================== -
    // - Can't handel numbers bigger than 999999 -
    if (number>999999) return number+bc_ad+" is out of range! {-999999(bc) to +999999(ad) only}"
   number=number % 1000000
    roman=""
    Num=1000000;A=13
    repeat=true
    while(repeat){
      S=number/Num ; S=S-(S%1)
      if (S==9){roman=roman+get_Roman_Numeral(A,1)+get_Roman_Numeral(A+2,1)}
        else {if (S>4){roman=roman+get_Roman_Numeral(A+1,1)+get_Roman_Numeral(A,S-5)}
                else {if (S==4){roman=roman+get_Roman_Numeral(A,1)+get_Roman_Numeral(A+1,1)}
                        else {roman=roman+get_Roman_Numeral(A,S)}
                     }
             }
      number=number % Num
      Num=Num/10
      A=A-2
      if (roman.length>100){roman=roman.substring(0,100)+"...";A=-1}
      if (A<0){repeat=false}
    }
    if (roman==""){roman="-"}
    output=roman+bc_ad
  }
  return output
}

  //--------------------------------------------------

function get_Roman_Numeral(Num,Len){
  R_Numerals="?IVXLCDMvxlcdm¤*#~"
  Char=R_Numerals.substring(Num,Num+1)
  Roman_char=""
  while (Len>0){
    Roman_char=Roman_char+Char
    Len=Len-1
  }
  return Roman_char
}

//--------------------------------------------------

// -- End of JavaScript hidden code. -->
