

function addAttach(str){
	var newId = ++document.getElementById('attach').value;
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'attachment_'+(newId));
	newDiv.className='attachment';
	newDiv.innerHTML = '<input type="file" class="attachFile"" style="margin-right: 10px; float: left;" name="attach_'+ newId +'" id="attach_'+ newId +'" />'+
	'<input type="button" class="fElbutton fElbutton1" id="but_'+ newId +'" onclick="removeAttach(\'attachments\', \'attachment_'+(newId) +'\');" value="'+ str +'" />'
	document.getElementById("attachments").appendChild(newDiv);
}


function removeAttach(parId, id){
    var parrent = document.getElementById(parId);
    var toDelete = document.getElementById(id);
    parrent.removeChild(toDelete);
}

function setSavedWidths(){
    var list = document.getElementById("savedAttachments").childNodes;
    var node, 
        maxWidth = document.getElementById("but_1").offsetLeft - document.getElementById("attach_1").offsetLeft;
    for(i=0; i < list.length; i++){
        node = list[i];
        if(node.nodeName == "DIV"){
            for(j=0; j < node.childNodes.length; j++){
                if(node.childNodes[j].nodeName == "DIV"){
                    if(maxWidth < node.childNodes[j].clientWidth +10){
                        maxWidth = node.childNodes[j].clientWidth +10;
                    }
                }
            }
        }
    }
    
    for(i=0; i < list.length; i++){
        node = list[i];
        if(node.nodeName == "DIV"){
            for(j=0; j < node.childNodes.length; j++){
                if(node.childNodes[j].nodeName == "DIV"){
                    node.childNodes[j].style.width = maxWidth+'px';
                }
            }
        }
    }
}
