// Looks for questionable characters in this string.
// Returns an array of characters from this string
// which are classified as questionable.
// Returns an empty array if there are no such characters.
function find_questionable_characters(str)
{
    var ok = "\t\r\n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var set = [];
    for(var i = 0; i < str.length; i++)
        if( -1 == ok.indexOf( str.charAt(i) ) )
            set[ str.charAt(i) ] = 1;

    var uniq = [];
    for( ch in set )
        if( set[ch] == 1 )
            uniq.push(ch);

    return uniq;
}

function confirm_questionable_characters( fields )
{
    var num_warnings = 0;
    var warnings  = "Some of the content you entered contains characters that\n";
        warnings += "are displayed differently among different carriers or phones.\n";
        warnings += "We recommend that you eliminate these characters.  Specifically,\n\n"

    for(var j=0; j<fields.length; j++)
    {
        var str = $(fields[j].dom).value;
        var found = find_questionable_characters(str);

        if( str != "NO_VALUE_SET" && found.length > 0 )
        {
            num_warnings++;

            warnings += "- The field '" + fields[j].name + "' contains: "
            for(var i = 0; i < found.length; i++)
            {
                if( i > 0 && i == found.length - 1 )
                    warnings += ", and "
                else if( i > 0 )
                    warnings += ", "
                warnings += found[i];
            }
            warnings += "\n\n";
        }
    }

    if( num_warnings > 0 )
        return confirm(warnings + "Do you want to ignore these warnings and continue anyway?");
    else
        return true;
}
