﻿        var ShowErr = function(id) {
            if($("#" + id).attr("type") == "text")
            {
                $("#" + id).attr("style", "border:1px #C82D4B solid;");
            }
            $("#f" + id.replace("ctl00_ContentPlaceHolder1_", "")).attr("style", "color:#C82D4B");
        }
        var HideErr = function(id) {
            if($("#" + id).attr("type") == "text")
            {
                 $("#" + id).attr("style", "");
            }
            $("#f" + id.replace("ctl00_ContentPlaceHolder1_", "")).attr("style", "");
        }

        var timerId;
        $(function() {
            timerId = setInterval("checkRadUploadCount()", 5);
            
        });
        var count = 0;
        function checkRadUploadCount() {
            if ($("input[type=file]").length == 5) {
                $("input[type=file]").each(function() {
                    $(this).change(function() {
                        var fullFileName = $(this).val();
                        var fileName;
                        if (fullFileName.lastIndexOf("\\") > 0) {
                            fileName = fullFileName.substring(fullFileName.lastIndexOf("\\") + 1);
                        }
                        else {
                            fileName = fullFileName;
                        }
                        $("#" + $(this).attr("id").replace("_Radupload1file0", "_txtWeek")).html(fileName);

                        $("#" + $(this).attr("id").replace("Radupload1file0", "btnRemove")).attr("class", "RemoveBtn");

                    });
                });
                clearInterval(timerId);
            }
            count++;
            if (count > 200) {
                clearInterval(timerId);
            }
            if ($('.RadUploadSelectButton').length == 5) {
                $('.RadUploadSelectButton').each(function() {
                    $(this).val("");
                });
            }
        }

        // remove selected file in HTMLInputElement and reset lblName's text
        function removeSelectedFile(obj) {
            var btnId = obj.id;
            var upFileId = btnId.replace("btnRemove", "Radupload1file0");
            var lblFileNameId = btnId.replace("btnRemove", "txtweek");
            var lblFileName = document.getElementById(lblFileNameId);
            lblFileName.innerHTML = "No file selected (max. 1 MB)";
            
            var upFile = document.getElementById(upFileId);
            if (upFile == null) return;
            var tempSpan = document.createElement("span");
            var tempSpanId = btnId.replace("btnRemove", "tempSpan");
            tempSpan.id = tempSpanId;
            upFile.parentNode.insertBefore(tempSpan, upFile);
            var tempForm = document.createElement("form");
            tempForm.appendChild(upFile);
            document.getElementsByTagName("body")[0].appendChild(tempForm);
            tempForm.reset();
            upFile.setAttribute("title", "");
            upFile.setAttribute("alt", "");
            tempSpan.parentNode.insertBefore(upFile, tempSpan);
            tempSpan.parentNode.removeChild(tempSpan);
            tempSpan = null;
            tempForm.parentNode.removeChild(tempForm);
            hideRemoveBtn(btnId);
        }
        // hide remove button
        function hideRemoveBtn(btnId) {
            $("#"+btnId).attr("class","RemoveBtnHide");
        }
