function attachmentChangedPub()
{
   
   var usedFields = 0;
    var fields = new Array();
    for (var i = 0; i < document.compose.elements.length; i++) {
        if (document.compose.elements[i].type == 'file' &&
            document.compose.elements[i].name.substr(0, 13) == 'publication[]') {
            fields[fields.length] = document.compose.elements[i];
        }
    }


    for (var i = 0; i < fields.length; i++) {
        if (fields[i].value.length > 0) {
            usedFields++;
        }
    }

    if (usedFields == fields.length) {
        var lastRow = document.getElementById('attachment_row_pub' + usedFields);
        if (lastRow) {
            var newRow = document.createElement('TR');
            newRow.id = 'attachment_row_pub' + (usedFields + 1);
            var td = document.createElement('TD');
            newRow.appendChild(td);
            td.align = 'left';
            var strong = document.createElement('STRONG');
            td.appendChild(strong);
            strong.appendChild(document.createTextNode('Δημοσίευμα ' + (usedFields + 1) + ' |'));
             td.appendChild(document.createTextNode(' Τίτλος: '));
            
			var titlos = document.createElement('INPUT');
            //titlos.type = 'file';
            td.appendChild(titlos);
            titlos.name = 'pubtitle[]';// + (usedFields + 1);
			td.appendChild(document.createTextNode(' Αρχείο: '));
			var file = document.createElement('INPUT');
            file.type = 'file';
            td.appendChild(file);
            file.name = 'publication[]';// + (usedFields + 1);
			file.onchange = function() { attachmentChangedPub(); };
            file.size = 25;
            file.className = 'fixed';
			/*
            td = document.createElement('TD');
            newRow.appendChild(td);
            td.align = 'left';
            var select = document.createElement('SELECT');
            td.appendChild(select);
            select.name = 'upload_disposition_' + (usedFields + 1);
            select.options[0] = new Option('Attachment', 'attachment', true);
            select.options[1] = new Option('Inline', 'inline');
			*/
            lastRow.parentNode.insertBefore(newRow, lastRow.nextSibling);
			
        }
    }
}

if (document.compose.to && document.compose.to.value == "") {
    document.compose.to.focus();
} else if (document.compose.subject.value == "") {
    document.compose.subject.focus();
} else {
    document.compose.message.focus();
}
