﻿function doAttachmentUpload(ProblemID, Self, txtID) {
    if (!Self.IsUploading) {
        var _UploadTable = document.getElementById('trFicsNewDialogTable' + ProblemID);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + ProblemID);
        var _DivProgress = document.getElementById('divFicsNewDialogProgress' + ProblemID);

        document.getElementById('divFicsUploadProgress' + ProblemID).style.display = 'block';
        _ifrPhoto.contentWindow.document.getElementById('AttachmentUpload').submit();
        _UploadTable.style.display = 'none';
        _DivProgress.style.display = 'block';
        Self.IsUploading = true;
        return false;
    } else {
        //var _uploadTextBox = document.getElementById(txtID);
        //_uploadTextBox.value = htmlentities(_uploadTextBox.value, 'ENT_COMPAT');
        return true;
    }
}

function CreateUploadButtons(ProblemID, MyIndex) {
    var _ifrPhoto = document.getElementById('ifrFicsAttach' + ProblemID);
    var Mybtn = _ifrPhoto.contentWindow.document.createElement('input');
    Mybtn.type = 'file';
    Mybtn.ProblemID = ProblemID;
    Mybtn.onchange = uploadChange;
    Mybtn.MyIndex = MyIndex + 1;
    Mybtn.name = 'FicsFile' + Mybtn.MyIndex;
    Mybtn.id = 'FicsFile' + Mybtn.MyIndex;

    var MyDeleter = _ifrPhoto.contentWindow.document.createElement('input');
    MyDeleter.type = 'button';
    MyDeleter.style.display = 'none';
    MyDeleter.value = 'Slet';
    MyDeleter.ProblemID = ProblemID;
    MyDeleter.onclick = function(event) {
        var _Parent = this.parentNode;
        while (_Parent.hasChildNodes()) {
            _Parent.removeChild(_Parent.childNodes.item(0));
        }
        _Parent.parentNode.removeChild(_Parent);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        var _divFrame = document.getElementById('divFicsUploadFrame' + this.ProblemID);
        var _divFiles = _ifrPhoto.contentWindow.document.getElementById('divFiles');
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        _divFrame.style.height = _divFiles.offsetHeight + 'px';
        _ifrPhoto.style.height = _divFiles.offsetHeight + 'px';
        return false;
    }
    Mybtn.Deleter = MyDeleter;

    var MyDiv = _ifrPhoto.contentWindow.document.createElement('div');
    MyDiv.innerHTML = '&nbsp;';
    MyDiv.style.cssFloat = 'left';
    MyDiv.style.styleFloat = 'left';
    MyDiv.style.display = 'none';
    Mybtn.StatusDisplay = MyDiv;

    var MyParentDiv = _ifrPhoto.contentWindow.document.createElement('div');
    MyParentDiv.appendChild(Mybtn);
    MyParentDiv.appendChild(MyDiv);
    MyParentDiv.appendChild(MyDeleter);
    MyParentDiv.style.clear = 'both';


    _ifrPhoto.contentWindow.document.getElementById('divFiles').appendChild(MyParentDiv);
}


function initAttachUpload(ProblemID) {
    CreateUploadButtons(ProblemID, 1);         
}

function uploadChange(event) {
    if (this.value.trim() != '') {
        this.style.display = 'none';
        this.StatusDisplay.innerHTML = ExtractFileName(this.value);
        this.StatusDisplay.style.display = 'block';
        this.Deleter.style.display = 'block';
        CreateUploadButtons(this.ProblemID, this.MyIndex + 1);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        var _divFrame = document.getElementById('divFicsUploadFrame' + this.ProblemID);
        var _divFiles = _ifrPhoto.contentWindow.document.getElementById('divFiles');
        _divFrame.style.height = _divFiles.offsetHeight + 'px';
        _ifrPhoto.style.height = _divFiles.offsetHeight + 'px';
    }
}


function attachUploadComplete(message, isError, ProblemID, CliID) {
    if (document.getElementById('divFicsUploadProgress' + ProblemID).style.display != 'none') {
        document.getElementById('divFicsUploadProgress' + ProblemID).style.display = 'none';

        var _divFrame = document.getElementById('divFicsUploadFrame' + ProblemID);
        var _divUploadMessage = document.getElementById('divFicsUploadMessage' + ProblemID);
        var _divUploadProgress = document.getElementById('divFicsUploadProgress' + ProblemID);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + ProblemID);

        _divUploadProgress.style.display = 'none';
        _divUploadMessage.style.display = 'none';
        _divFrame.style.display = '';

        if (message.length) {
            var color = (isError) ? '#ff0000' : '#008000';

            _divUploadMessage.innerHTML = '<span style=\"color:' + color + '\;font-weight:bold">' + message + '</span>';
            _divUploadMessage.style.display = '';

            if (isError) {
                _ifrPhoto.contentWindow.document.getElementById('FicsFilAttachment1').focus();
            }
            document.getElementById(CliID).click();
        }
    }
}









/*
function initAttachUpload(ProblemID) {
    var _ifrPhoto = document.getElementById('ifrFicsAttach' + ProblemID);
    var Mybtn = _ifrPhoto.contentWindow.document.createElement('input');
    Mybtn.type = 'file';
    Mybtn.ProblemID = ProblemID;
    Mybtn.onchange = uploadChange;
    Mybtn.MyIndex = 1;
    Mybtn.name = 'nameFicsFile' + Mybtn.MyIndex;
    Mybtn.id = 'id_FicsFile' + Mybtn.MyIndex;


    var MyDeleter = _ifrPhoto.contentWindow.document.createElement('input');
    MyDeleter.type = 'button';
    MyDeleter.style.display = 'none';
    MyDeleter.value = 'Slet';
    MyDeleter.style.cssFloat = 'left';
    MyDeleter.style.styleFloat = 'left';
    MyDeleter.ProblemID = ProblemID;
    MyDeleter.onclick = function(event) {
    var _Parent = this.parentNode;
    while (_Parent.hasChildNodes()) {
    _Parent.removeChild(_Parent.childNodes.item(0));
    }
    _Parent.parentNode.removeChild(_Parent);
    var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
    var _divFrame = document.getElementById('divFicsUploadFrame' + this.ProblemID);
    var _divFiles = _ifrPhoto.contentWindow.document.getElementById('divFiles');
    var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
    _divFrame.style.height = _divFiles.offsetHeight + 'px';
    _ifrPhoto.style.height = _divFiles.offsetHeight + 'px';        
    return false;        
    }
    Mybtn.Deleter = MyDeleter;

    var MyDiv = _ifrPhoto.contentWindow.document.createElement('div');
    MyDiv.innerHTML = '&nbsp;';
    MyDiv.style.cssFloat = 'left';
    MyDiv.style.styleFloat = 'left';   
    MyDiv.style.display = 'none';
    Mybtn.StatusDisplay = MyDiv;
    
    var MyParentDiv = _ifrPhoto.contentWindow.document.createElement('div');
    MyParentDiv.appendChild(Mybtn);
    MyParentDiv.appendChild(MyDiv);
    MyParentDiv.appendChild(MyDeleter);
    MyParentDiv.style.clear = 'both';    
    
    _ifrPhoto.contentWindow.document.getElementById('divFiles').appendChild(MyParentDiv);
}

function uploadChange(event) {
    if (this.value.trim() != '') {
        this.style.display = 'none';
        this.StatusDisplay.innerHTML = ExtractFileName(this.value);
        this.StatusDisplay.style.display = 'block';
        this.Deleter.style.display = 'block';
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        var Mybtn = _ifrPhoto.contentWindow.document.createElement('input');        
        Mybtn.type = 'file';
        Mybtn.ProblemID = this.ProblemID;
        Mybtn.onchange = uploadChange;
        Mybtn.MyIndex = this.MyIndex + 1;
        Mybtn.name = 'FicsFile' + Mybtn.MyIndex;
        Mybtn.id = 'FicsFile' + Mybtn.MyIndex;

        var MyDeleter = _ifrPhoto.contentWindow.document.createElement('input');
        MyDeleter.type = 'button';
        MyDeleter.style.display = 'none';
        MyDeleter.value = 'Slet';
        MyDeleter.ProblemID = this.ProblemID;
        MyDeleter.onclick = function(event) {
        var _Parent = this.parentNode;
        while (_Parent.hasChildNodes()) {
        _Parent.removeChild(_Parent.childNodes.item(0));
        }
        _Parent.parentNode.removeChild(_Parent);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        var _divFrame = document.getElementById('divFicsUploadFrame' + this.ProblemID);
        var _divFiles = _ifrPhoto.contentWindow.document.getElementById('divFiles');
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        _divFrame.style.height = _divFiles.offsetHeight + 'px';
        _ifrPhoto.style.height = _divFiles.offsetHeight + 'px';
        return false;
        }
        Mybtn.Deleter = MyDeleter;
        
        var MyDiv = _ifrPhoto.contentWindow.document.createElement('div');
        MyDiv.innerHTML = '&nbsp;';
        MyDiv.style.cssFloat = 'left';
        MyDiv.style.styleFloat = 'left';           
        MyDiv.style.display = 'none';
        Mybtn.StatusDisplay = MyDiv;

        var MyParentDiv = _ifrPhoto.contentWindow.document.createElement('div');
        MyParentDiv.appendChild(Mybtn);
        MyParentDiv.appendChild(MyDiv);
        MyParentDiv.appendChild(MyDeleter);
        MyParentDiv.style.clear = 'both';          
        
        
        _ifrPhoto.contentWindow.document.getElementById('divFiles').appendChild(MyParentDiv);
        var _ifrPhoto = document.getElementById('ifrFicsAttach' + this.ProblemID);
        var _divFrame = document.getElementById('divFicsUploadFrame' + this.ProblemID);
        var _divFiles = _ifrPhoto.contentWindow.document.getElementById('divFiles');
        _divFrame.style.height = _divFiles.offsetHeight + 'px';
        _ifrPhoto.style.height = _divFiles.offsetHeight + 'px';
    }
}
*/