function fnValidateLessonPlan() {
	var himsValidator = [new hims_ctl_val('ctl00_CP_ClassDropDownList', "Class", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_DivisionDropDownList', "Division", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_SubjectDropDownList', "Subject", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_TopicDropDownList', "Topic", "T", "", "", "", 20)];
	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 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': false,
//			'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': false,
//			'auto': true
//		});
//	}
//}

var reader = new FileReader();
reader.onload = function (e) {
}
function readURL(input) {
    if (input.files && input.files[0]) {
        reader.readAsDataURL(input.files[0]);
        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()) {
        LoadingMessage('Uploading', '<b>Please Wait</b>');
        $("#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: '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;
                }
                $("#ctl00_CP_UploadSuccessMessage").text("Uploaded Successfully");
                /*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_UploadSuccessMessage").text("Uploaded Successfully");
                }, 100);
            },
            error: function (response, status, e) {
                window.setTimeout(function () {
                    CloseLoadingpopup();
                }, 100);
            }
        })
        return false;
    }
}
function isFile(file) {
    var video = /\.(xls|)$/i;
    var CSV = /\.(csv|)$/i;
    if (video.test(file) || CSV.test(file))
        return true;
    else
        return false;
}
function ValidateImageDetails() {
    var fields;
    fields = "";
    var file = document.getElementById('flUpload').value;
    //if (isFile(document.getElementById('flUpload').value) == false || document.getElementById('flUpload').value == null) {
    //    fields = fields + "\n-- Invalid file --";
    //}
    if (fields != "") {
        fields = "Please fill in the following details:\n------------------------------------" + fields;
        alert(fields);
        return false;
    }
    else {
        return true;
    }
}

function GetBalanceLeave(obj) {
    var row = obj.parentNode.parentNode;
    //var GridView = document.getElementById('<%= this.LeaveBalanceGridView.ClientID %>');
    var LastYearBalanceLeave = 0;
    var CurrentBalanceLeave = 0;
    var BalanceLeave = 0;
    
    //for (var i = 1; i < table.rows.length; i++)
    //{
    //    if (isNaN(parseFloat(table.rows[i].cells[6].childNodes[1].value)))
    //    {
    //        table.rows[i].cells[6].childNodes[1].value = 0.00;
    //    }
    //    if (isNaN(parseFloat(table.rows[i].cells[7].childNodes[1].value))) {
    //        table.rows[i].cells[7].childNodes[1].value = 0.00;
    //    }
    //LastYearBalanceLeave = parseFloat(GridView.rows[row].cells[6].childNodes[1].value);
    //CurrentBalanceLeave = parseFloat(GridView.rows[row].cells[7].childNodes[1].value);
    //}
    if (row.cells[6].getElementsByTagName("input")[0].value == "")
    {
        row.cells[6].getElementsByTagName("input")[0].value = 0.00;
    }
    if (row.cells[7].getElementsByTagName("input")[0].value == "")
    {
        row.cells[7].getElementsByTagName("input")[0].value = 0.00;
    }
    LastYearBalanceLeave = row.cells[6].getElementsByTagName("input")[0].value;
    CurrentBalanceLeave = row.cells[7].getElementsByTagName("input")[0].value;
        
    BalanceLeave = parseFloat(LastYearBalanceLeave) + parseFloat(CurrentBalanceLeave);
    row.cells[9].getElementsByTagName("input")[0].value = parseFloat(BalanceLeave);
}