var ok_filetypes = new Array('jpg', 'jpeg', 'jfif', 'jpg', 'tiff', 'tif', 'psd', 'pict', 'pct', 'gif', 'png', 'art', 'avi', 'avs', 'bmp', 'cgm', 'cin', 'crw', 'cur', 'cut', 'dcm', 'dicom', 'dcr', 'dcx', 'dib', 'djvu', 'dng', 'dot', 'dpx', 'emf', 'epdf', 'epi', 'eps', 'eps2', 'eps3', 'epsf', 'epsi', 'ept', 'exr', 'fax', 'fig', 'fits', 'fpx', 'gplt', 'hpgl', 'ico', 'jbig', 'jng', 'jp2', 'jpc', 'mat', 'miff', 'mng', 'mpeg', 'mpg', 'm2v', 'mp4', 'm4v', 'mrw', 'mtv', 'mvg', 'nef', 'orf', 'otb', 'p7', 'palm', 'pam', 'pbm', 'pcd', 'pcds', 'pcl', 'pcx', 'pdb', 'pdf', 'pef', 'pfa', 'pfb', 'pfm', 'pgm', 'picon', 'pix', 'png8', 'png24', 'png32', 'pnm', 'ppm', 'ps', 'ps3', 'ptif', 'pwp', 'rad', 'raf', 'rla', 'rle', 'sct', 'sfw', 'sgi', 'sun', 'svg', 'tga', 'tim', 'txt', 'uil', 'vicar', 'viff', 'wbmp', 'wmf', 'wpg', 'xbm', 'xcf', 'xpm', 'xwd', 'x3f', 'tgz', 'gz', 'rar', 'sea', 'sit', 'zip', 'cr2', 'pp2', 'pz2', 'hr2', 'hd2', 'fc2', 'pz3', 'obj', 'uvs', 'uvw', 'mtl', 'crz', 'ppz', 'pzz', 'hdz', 'hrz', 'deltas', 'cm2', 'cmz', 'lt2', 'ltz', 'fcz', 'zbr', 'flv', 'mov', 'qt', 'dmg', 'pkg', 'mpkg', 'tar', 'wmv');

var big_imagetypes = new Array('tiff', 'tif', 'psd', 'pict', 'pct', 'art', 'avs', 'bmp', 'cgm', 'cin', 'crw', 'cut', 'dcm', 'dicom', 'dcr', 'dcx', 'dib', 'djvu', 'dng', 'dot', 'dpx', 'emf', 'epdf', 'epi', 'eps', 'eps2', 'eps3', 'epsf', 'epsi', 'ept', 'exr', 'fax', 'fig', 'fits', 'fpx', 'gplt', 'hpgl', 'mat', 'miff', 'mng', 'mrw', 'mtv', 'mvg', 'nef', 'orf', 'otb', 'p7', 'palm', 'pam', 'pbm', 'pcd', 'pcds', 'pcl', 'pcx', 'pdb', 'pdf', 'pef', 'pfa', 'pfb', 'pfm', 'pgm', 'picon', 'pix', 'pnm', 'ppm', 'ps', 'ps3', 'ptif', 'pwp', 'rad', 'raf', 'rla', 'rle', 'sct', 'sfw', 'sgi', 'sun', 'svg', 'tga', 'tim', 'uil', 'vicar', 'viff', 'wbmp', 'wmf', 'wpg', 'xbm', 'xcf', 'xpm', 'xwd', 'x3f');

var big_filetypes = new Array('cr2', 'pp2', 'pz2', 'hr2', 'hd2', 'fc2', 'pz3', 'obj', 'uvs', 'uvw', 'mtl', 'crz', 'ppz', 'pzz', 'hdz', 'hrz', 'deltas', 'cm2', 'cmz', 'lt2', 'ltz', 'fcz', 'zbr', 'dmg', 'pkg', 'mpkg', 'zip', 'sit', 'sea', 'rar', 'tgz', 'gz', 'tar');

var big_movietypes = new Array('avi', 'mpeg', 'mpg', 'mp4', 'mp2', 'm4v', 'flv', 'mov', 'qt', 'wmv');

function validate_post() {
    var subject = document.getElementById('post_subject_I').value;
    var body = document.getElementById('post_body_I').value;

    if (!subject) {
        alert("Post must have a subject");
        return false;
    }
    if (subject.length < 4) {
        alert("Post subject is too short. 4 Character minimum.");
        return false;
    }

    if (!body) {
        alert("No blank posts, please");
        return false;
    }
    if (body.length < 8) {

        if (confirm("Post is too short. Are you trying to bookmark this thread?")) {
            add_bookmark();
        }

        return false;
    }

    return true;
}

function add_bookmark() {
    alert("add_bookmark. Stub");
}

function checkAttachment(id) {
// var bugs = document.getElementById('debugger');

    var file = document.getElementById(id);

    if (!file) return false;
    if (!file.value) return false;

    var filetype = file.value.match(/\.([^\/\\\.]+)$/)[1];
    if (!filetype) {
        if (confirm("This file has no extension.\nShould I treat it as a text file?")) return true;
        else {
            file.value = '';
            return false;
        }
    }

// bugs.innerHTML += "Got filetype " + filetype + "<br/>\n";

    for (i in ok_filetypes) {
// bugs.innerHTML += "Checking [" + filetype.toLowerCase() + "] against [" + ok_filetypes[i] + "]<br/>\n";
        if (filetype.toLowerCase() == ok_filetypes[i]) {
            for (j in big_imagetypes) {
                if (filetype.toLowerCase() == big_imagetypes[j]) {
                    if (confirm("This file may be a large image.\n" +
                                "It may take a long time to upload and " +
                                "will be converted to an appropriate " + 
                                "network format. Is this OK?")) return true;
                    file.value = '';
                    return false;
                }
            }
            for (j in big_movietypes) {
                if (filetype.toLowerCase() == big_movietypes[j]) {
                    if (filetype.toLowerCase() == 'm4v') {
                        if (confirm("This file is a movie.\n" +
                                "It may take a long time to upload and " +
                                "will be converted to Shockwave Flash Video. " +
                                "Is this OK?\n\nPlease note that iTunes movies " +
                                "and TV shows cannot be read by the system or " +
                                "converted due to DRM, not to mention massive " + 
                                "size!")) return true;
                        file.value = '';
                        return false;
                    }
                    if (confirm("This file is a movie.\n" +
                                "It may take a long time to upload and " +
                                "will be converted to Shockwave Flash Video. " +
                                "Is this OK?")) return true;
                    file.value = '';
                    return false;
                }
            }
            for (j in big_filetypes) {
                if (filetype.toLowerCase() == big_filetypes[j]) {
                    if (confirm("This file may be large.\n" +
                                "It may take a long time to upload. " +
                                "Continue?")) return true;
                    file.value = '';
                    return false;
                }
            }

            return true;
        }
    }

    alert("The filetype of this file is not supported in attachments");
    file.value = '';

    return false;
}

function subscribe_to_thread(thread_id) {

    var callback = function (response) {
        document.getElementById('subscribe_button').innerHTML = '';
        document.getElementById('subscribed_marker').innerHTML = '<img src="/images/icons/subscribe.png" alt="Subscribed" title="You are subscribed to this thread"/>';
    };

    asynch_call_rpc('/forum/subscribe.ez', 'subscribe', callback, {'thread' : thread_id});

}

