function fnValidateResultDetail1() {
	var himsValidator = [new hims_ctl_val('ctl00_CP_TitleTextBox', "Name", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_DivisionDropDownList', "Division", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_ExamDatePickerControl' + '_DateTextbox', "Exam Date", "T", "", "", "", 10)];
	if (fnDoValidate(himsValidator))
		return true;
	else
		return false;
}
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}
function uppercase() {
	key = window.event.keyCode;
	if ((key > 0x60) && (key < 0x7B))
		window.event.keyCode = key - 0x20;
}
//function cpageLoad() {
//	var browser=navigator.userAgent.toLowerCase();
//	if(browser.indexOf('firefox')>=0){		
//		$("#ctl00_CP_FileUpload1").fileUpload({
//			'uploader' : '../../../UserControls/MultiFileUpload/uploader.swf',
//			'cancelImg': '../../../Images/cancel.png',
//			'script': '../../../UserControls/MultiFileUpload/Upload.ashx?ASPSESSID=' + $('#ctl00_CP_hdnSessionid').val(),
//			'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
//			'multi': true,
//			'auto': true
//		});
//	}
//	else {
//		$("#ctl00_CP_FileUpload1").fileUpload({
//			'uploader': '../../../UserControls/MultiFileUpload/uploader.swf',
//			'cancelImg': '../../../Images/cancel.png',
//			'script': '../../../UserControls/MultiFileUpload/Upload.ashx',
//			'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
//			'multi': true,
//			'auto': true
//		});
//	}
//}
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;
        if ($('#ctl00_CP_UploadConfigurationHiddenField').val() == "Azure") {
            ajaxFileUploadAzure();
        }
        else {
            ajaxFileUpload();
        }
    }
}
function OpenFileUpload() {
    $('#flUpload').click();
}
function LoadingMessage(msg1, msg2) {
    $('#dvTestLoadingmsg').show();
    $('#spn1msg').html(msg1);
    $('#spn2msg').html(msg2);
    $('.hls-bg').show();
}
function CloseLoadingpopup() {
    $('#dvTestLoadingmsg').hide();
    $('.hls-bg').hide();
}
function ajaxFileUpload() {
    if (ValidateImageDetails()) {
        if (ValidateImageSize()) {
            LoadingMessage('Uploading', '<b>Please Wait</b>');
            $("#loading").ajaxStart(function () {
                $(this).show();
            }).ajaxComplete(function () {
                $(this).hide();
            });
            $.ajaxFileUpload({
                url: ($('#ctl00_CP_UploadTypeIdHiddenField').val() == '2') ? '/UserControls/MultiFileUpload/common-file-upload.ashx?ScreenId=31182' : '/UserControls/MultiFileUpload/common-file-upload.ashx?ScreenId=20179',
                //url: '/UserControls/MultiFileUpload/common-file-upload.ashx?ScreenId=20179',

                secureuri: false,
                fileElementId: 'flUpload',
                dataType: 'text',
                contentType: "application/json; charset=utf-8",
                data: { name: 'logan', id: 'id', hdn: '1' },
                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;
                    }
                    /*var str = response;
                    str = str.replace('<pre style="word-wrap: break-word; white-space: pre-wrap;">','');
                    str = str.replace('</pre>','');				
                    $('#hdnFileName').val(str);*/
                    window.setTimeout(function () {
                        CloseLoadingpopup();
                        $("#ctl00_CP_Label2").text("Uploaded Successfully");
                    }, 100);
                },
                error: function (response, status, e) {
                    window.setTimeout(function () {
                        CloseLoadingpopup();
                    }, 100);
                }
            })
            return false;
        }
    }
}
function ajaxFileUploadAzure() {
    if (ValidateImageDetails()) {
        if (ValidateImageSize()) {            
                LoadingMessage('Uploading', '<b>Please Wait</b>');
                $("#loading").ajaxStart(function () {
                    $(this).show();
                }).ajaxComplete(function () {
                    $(this).hide();
                });
                var ScreenTypeId;
                if ($('#ctl00_CP_UploadTypeIdHiddenField').val() == '2') {
                    ScreenTypeId = 35;
                }
                else
                {
                    ScreenTypeId = 16;
                }
                //var ScreenTypeId = 16;
                var UserSourceTypeId = $('#ctl00_CP_UserSourceTypeHiddenField').val();
                var UserSourceId = $('#ctl00_CP_UserSourceIdHiddenField').val();
                var DocumentId = 0;
                if ($('#ctl00_CP_IdHiddenField').val() != '')
                    DocumentId = $('#ctl00_CP_IdHiddenField').val();
                var DocumentName = filename;
                var GUID = 0;
                if ($('#ctl00_CP_GUIDHiddenField').val() != '')
                    GUID = $('#ctl00_CP_GUIDHiddenField').val();
                $.ajaxFileUpload({
                    url: '/UserControls/MultiFileUpload/DocumentUpload.ashx?ScreenTypeId=' + ScreenTypeId + '&UserSourceTypeId=' + UserSourceTypeId + '&UserSourceId=' + UserSourceId + '&DocumentId=' + DocumentId + '&DocumentName=' + DocumentName + '&GUID=' + GUID,
                    secureuri: false,
                    fileElementId: 'flUpload',
                    dataType: 'text',
                    contentType: "application/json; charset=utf-8",
                    data: { name: 'logan', id: 'id', hdn: '1' },
                    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;
                        }
                        /*var str = response;
                        str = str.replace('<pre style="word-wrap: break-word; white-space: pre-wrap;">','');
                        str = str.replace('</pre>','');				
                        $('#hdnFileName').val(str);*/
                        window.setTimeout(function () {
                            CloseLoadingpopup();

                            $("#ctl00_CP_Label2").text("Uploaded Successfully");

                        }, 100);
                    },
                    error: function (response, status, e) {
                        window.setTimeout(function () {
                            CloseLoadingpopup();
                        }, 100);
                    }
                })
                return false;
            }
        }
    }
function isFile(file) {
    var count = document.getElementById('flUpload').files;
    var fileValu = document.getElementById('flUpload');
    var count_file = 0;
    for (var i = 0; i < count.length; i++) {
        var t = fileValu.files[i].name.split('.').pop();
        if (t.toLowerCase() == "pdf") {
            count_file = count_file + 1;
        }
        else
        {
            filename = fileValu.files[i].name;
            return false;
        }
    }

    //if ((/\.(pdf|)$/i).test(file))
    //    return true;
    //else
    //    return false;
}
function ValidateImageDetails() {
    var fields;
    fields = "";
    var file = document.getElementById('flUpload').value;
    var iSize = ($("#flUpload")[0].files[0].size / 1024);
    iSize = (Math.round((iSize / 1024) * 100) / 100);
    //Added new validation for mantis : 30188
    if (isFile(document.getElementById('flUpload').value) == false || document.getElementById('flUpload').value == null) {
        fields = fields + "\n Invalid file ";
    }
    //else if (iSize > 1) {
    //    alert('File should be less than 1 MB');
    //    return false;
    //}
    if (fields != "") {
        fields = "Please fill in the following details:\n------------------------------------" + fields + filename;
        alert(fields);
        return false;
    }
    else {
        return true;
    }
}
function ValidateImageSize() {
    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 ($('#ctl00_CP_AttachmentSizeHiddenField').val() != '') {
        if (iSize > $('#ctl00_CP_AttachmentSizeHiddenField').val()) {
            alert('File should be less than ' + $('#ctl00_CP_AttachmentSizeHiddenField').val() + ' KB');
            return false;
        }

        else {
            return true;
        }
    }
    else {
        return true;
    }
}

