var hD="0123456789ABCDEF";
function d2h(d) {
var h = hD.substr(d&15,1);
while(d>15) {d>>=4;h=hD.substr(d&15,1)+h;}
return h;
}
function convertWeirdWordChars(name, text) {
    dirtyCharacters = false;
    
    convertedText = "";
 
    for (j = 0; text != null && j < text.length; ++j) {
         //if (text.charCodeAt(j) >= 256) {
         //    alert("Char " + j + " of " + text + " is " + d2h(text.charCodeAt(j)));
         //}
         switch (text.charAt(j)) {
             // Various dashes and hyphens
             case "\u2013": 
                 convertedText = convertedText + "-"; break;
             case "\u2014": 
                 convertedText = convertedText + "--"; break;
             case "\u2015": 
                 convertedText = convertedText + "---"; break;
             case "\u2017": 
                 convertedText = convertedText + "_"; break;
 
             // Various single quote characters
             case "\u2018": 
             case "\u2019": 
             case "\u201A": 
             case "\u201B": 
                 convertedText = convertedText + "'"; break;
 
             // Various double quote characters
             case "\u201C": 
             case "\u201D": 
             case "\u201E": 
                 convertedText = convertedText + "\""; break;
 
             // Daggers and Bullets
             case "\u2020": 
             case "\u2021": 
             case "\u2022": 
             case "\uF0B7":
                 convertedText = convertedText + "*"; break;
 
             // Ellipsis
             case "\u2026": 
                 convertedText = convertedText + "..."; break;
 
             // Euro
             case "\u20AC": 
                 convertedText = convertedText + "EURO"; break;
 
             default: 
                 if (text.charCodeAt(j) < 256) {
                     convertedText = convertedText + text.charAt(j); 
                 } else {
                     if (dirtyCharacters == false) {
                         alert("Unrecognised characters found - please preview carefully\n\n"
                             + "\"" + text + "\"");
                         dirtyCharacters = true;
                     }
                     convertedText = convertedText + "?"; 
                 }
                 break;
         }
 
    }

    return convertedText;
};
 
function convertFormWordChars(form) {
    for (i = 0; i < form.elements.length; ++i) {
        form.elements[i].value = convertWeirdWordChars(form.elements[i].name, form.elements[i].value);
    }
    return true;
}
 
 
function showPasteWarning() {
    alert("Using Copy and Paste to enter text here can cause some punctuation marks to be incorrectly converted. Please preview this text carefully on the preview page and correct any discrepancies.");
};
