﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

;if (window.jQuery) (function($) {


    $.fn.Accept = function() {
        if (this.length == 0) return this;

        this.each(function() {

            var el = $(this);
            acceptVal = String(el.attr('accept') || '');

            if (acceptVal.length > 1) {
                acceptVal = acceptVal.replace(/\W+/g, '|').replace(/^\W|\W$/g, '');
                var acceptRegex = new RegExp('\\.(' + (acceptVal ? acceptVal : '') + ')$', 'gi');

                el.change(function() {
                    $(this).blur();

                    file = String(this.value || '');
                    if (!file.match(acceptRegex)) {
                        this.value = null;
                        alert('You cannot select a $ext file.\nPlease select again...'.replace('$ext', String(file.match(/\.\w{1,4}$/gi))));
                    }
                });

            }

        });

    }

    $(function() {
        $("input[type=file]").Accept();
    });


})(jQuery);