////////////////////////////////////////////////////////////////////////
//Capitalise the first letter in a textbox once the value is changed
//Call as follows onChange="Proper(this); return true;"
function Proper(o) {
var s = o.value;
var out = "";
if (s.length > 0) {
var c = true;
// process each character one at a time
for (var i=0; i < s.length; i++) {
var t = s.substring(i,i+1).toUpperCase();
// if not alpha cap next character
cmp = "AÃBCÇDEÉÈËFGHIJKLMNÑOPQRSTUVWXYZ1234567890'";
if ( cmp.indexOf(t) < 0) {
c = true;
}
else {
if (c) {
c = false;
}
else {
t = t.toLowerCase();
}
}
// take special cases like Mc, Mac De and Roman numerals
if ( i > 1 ) {
temp = s.substring(i-2,i).toUpperCase();
if ( temp == "MC" || temp == "DE" && i < 3 ) {
t = t.toUpperCase();
}
cmp = "R IX XI XX II V X S N";
roman = "RWEIVX";
roman2 = "RWIVX E W ";
if ( cmp.indexOf(temp) >= 0 && roman.indexOf(t.toUpperCase()) >= 0 &&
roman2.indexOf(s.substring(i,i+2).toUpperCase() ) >= 0 ) {
t = t.toUpperCase();
}
}
if ( i > 2 ) {
temp = s.substring(i-3,i).toUpperCase();
if ( temp == "MAC" && i < 4 ) {
t = t.toUpperCase();
}
if ( ( temp == " XI" || temp == " VI " || temp == " XX " || temp == "XV" || temp == " RR" ) && (t.toUpperCase() == "I" || t.toUpperCase() == "X" || t.toUpperCase == "R" ) ) {t = t.toUpperCase();
}
} out += t;
}
o.value = out;
} return true;
}