﻿function checkFileExt(ctrl, extensions)
{
    //set the name of our form
    var form = document.form1;
    //retrieve our control
    var file = DOMCall(ctrl).value;
    var type = "";
    
    // Create an array of acceptable files
    var validExtensions = extensions.split(',');
    var allowSubmit = false;
    //if our control contains no file then alert the user
    if (file.indexOf("\\") == -1) {
        return true; // Return true if no file is supplied
    }
    else {
        //get the file type
        type = file.slice(file.indexOf("\\") + 1);
        var ext = file.slice(file.lastIndexOf(".")).toLowerCase();
        //loop through our array of extensions
        for (var i = 0; i < validExtensions.length; i++) {
            //check to see if it's the proper extension
            if (validExtensions[i] == ext) {
                //it's the proper extension
                allowSubmit = true;
            }
        }
    }
    //now check the final bool value
    if (allowSubmit == false) {
        return false;
    }
    else {
        return true
    }
    return allowSubmit;
}

function DOMCall(name) {
    //Checks the DOM features available
    if (document.layers) //checks document.layers
        return document.layers[name];
    else if (document.all) //checks document.all
        return document.all[name];
    else if (document.getElementById) //checks getElementById
        return document.getElementById(name);
}