function fnValidateStudentGatePass() {
    var himsValidator = [
                       new hims_ctl_val('ctl00_CP_OrgDropDownList', "Organization", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_StudentIdNoTextBox', "ID No", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_RelationshipDropDownList', "Relationship", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_VisitorNameTextBox', "Visitor Name", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_ReasonOfGatePassTextBox', "Reason Of Gate Pass", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_EntryModeStatusDropDownList', "Entry Mode Status", "T", "", "", "", 20),
                       new hims_ctl_val('ctl00_CP_GatePassDateDatePickerControl' + '_DateTextbox', "Gate Pass Date", "T", "", "", "", 10)
    ];
    if (fnDoValidate(himsValidator)) {
        $("#MessageBoxDiv").hide();
        return true;
    }
    else {
        $("#MessageBoxDiv").show();
        return false;
    }
}

//Add for upload photo by Hemali mantis IS : 0027599
var reader = new FileReader();
var filename = '';
reader.onload = function (e) { }

function readURL(input) {
    if (input.files && input.files[0]) {
        reader.readAsDataURL(input.files[0]);
        filename = input.files[0].name;
        ajaxFileUpload();
    }
}

function OpenFileUpload() {
    $('#flUpload').click();
}

function ValidateAttachmentImageDetails() {
    var fields;
    fields = "";
    var file = document.getElementById('flUpload').value;
    var iSize = ($("#flUpload")[0].files[0].size / 1024);
    iSize = (Math.round((iSize / 1024) * 100) / 100);
    if (isAttachmentFile(document.getElementById('flUpload').value) == false || document.getElementById('flUpload').value == null) {
        fields = fields + "\n Invalid file ";
        alert(fields);
        return false;
    }
    else {
        return true;
    }
}

function ValidateAttachmentImageSize() {
    var fields = "";
    var file = document.getElementById('flUpload').value;
    var iSize = ($("#flUpload")[0].files[0].size / 1024);
    if ($('#ctl00_CP_FileAttachmentSizeHiddenField').val() != '') {
        if (iSize > $('#ctl00_CP_FileAttachmentSizeHiddenField').val()) {
            alert('File should be less than ' + $('#ctl00_CP_FileAttachmentSizeHiddenField').val() + ' KB');
            return false;
        }
        else
            return true;
    }
    else
        return true;
}

function isAttachmentFile(file) {
    var jpg = /\.(jpg|)$/i;
    var png = /\.(png|)$/i;
    var jpeg = /\.(jpeg|)$/i;
    var doc = /\.(.doc|)$/i;
    var pdf = /\.(.pdf|)$/i;
    if ((/\.(jpg|jpeg|png|pdf|)$/i).test(file.toLowerCase())) {
        return true;
    }
    else {
        return false;
    } gradeanalysis
}

function CloseLoadingpopup() {
    $('#dvMainLoadingmsg').hide();
}

function ajaxFileUpload() {
    if (ValidateAttachmentImageDetails()) {
        if (ValidateAttachmentImageSize()) {
            $("#loading").ajaxStart(function () {
                $(this).show();
            }).ajaxComplete(function () {
                $(this).hide();
            });
            $.ajaxFileUpload({
                url: '/UserControls/MultiFileUpload/common-file-upload.ashx',
                secureuri: false,
                fileElementId: 'flUpload',
                dataType: 'text',
                contentType: "application/json; charset=utf-8",
                data: { name: 'logan', id: 'id', hdn: '2' },
                success: function (response, status) {
                    if (response == "-007") {
                        alert('Cannot upload file as the used space exceeds allocated space')
                        return
                    }
                    if (response == "-008") {
                        alert('Invalid Extention');
                        return;
                    }
                    if (response == "-009") {
                        alert('Cannot include / or .. in a filename')
                        return;
                    }
                    window.setTimeout(function () {
                        CloseLoadingpopup();
                        $("#ctl00_CP_Label2").text("Uploaded Successfully");
                        $("#ctl00_CP_RefreshButtonHiddenField").val("Browse");
                    }, 100);
                },
                error: function (response, status, e) {
                    window.setTimeout(function () {
                        CloseLoadingpopup();
                    }, 100);
                }
            })
            return false;
        }
    }
}