﻿//DOMCall Function
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);
}


function checkFileExt(ctrl) {
    //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 = new Array(".7z", ".aiff", ".asf", ".avi", ".bmp", ".csv", ".doc", ".fla", ".flv", ".gif", ".gz", ".gzip", ".jpeg", ".jpg", ".mid", ".mov", ".mp3", ".mp4", ".mpc", ".mpeg", ".mpg", ".ods", ".odt", ".pdf", ".png", ".ppt", ".pxd", ".qt", ".ram", ".rar", ".rm", ".rmi", ".rmvb", ".rtf", ".sdc", ".sitd", ".swf", ".sxc", ".sxw", ".tar", ".tgz", ".tif", ".tiff", ".txt", ".vsd", ".wav", ".wma", ".wmv", ".xls", ".xml", ".zip");
    var allowSubmit = false;
    //if our control contains no file then alert the user
//    if (file.indexOf("\\") == -1) {
//        alert("You must select a file before hitting the Submit button");
//        return false; ;
//    }

        //get the file type
        type = file.slice(file.indexOf("\\") + 1);
        var ext = file.slice(file.lastIndexOf(".")).toLowerCase();
        //loop through our array of extensions
        if (ext == '') {
            allowSubmit = true;
                   }
            else {
                    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) {
        //let the user know they selected a wrong file extension
        alert("Only files with extensions " + (validExtensions.join("  ").toUpperCase()) + " are allowed");
        return false;
    }
    else {
        return true
    }
    return allowSubmit;
}

