function prev_(elem){
	do {
			elem = elem.previousSibling;
	} while (elem && elem.nodeType != 1);
	return elem;
}


// Получение следующего смежного элемента в DOM
function next_(elem){
       do {
               elem = elem.nextSibling;
       } while (elem && elem.nodeType != 1);       return elem;
}

function add(id, id_q)
{
s=document.getElementById('files'+id+id_q);
n=document.getElementById('num'+id+id_q);
m=document.getElementById('names'+id+id_q);

namesub=document.createElement('input');

namesub.setAttribute('type','text');
namesub.setAttribute('name','name_'+id+id_q+''+n.getAttribute('value'));
namesub.setAttribute('id','name_'+id+id_q+''+n.getAttribute('value'));
namesub.setAttribute('value','Дополнительная');
namesub.setAttribute('disabled', '');

input=document.createElement('input');
input.setAttribute('type','file');
input.setAttribute('name','file_'+id+id_q+'['+n.getAttribute('value')+']');
input.setAttribute('id','file_'+id+id_q+''+n.getAttribute('value')+'');


s.appendChild(input);
m.appendChild(namesub);
s.appendChild(document.createElement('br'));
m.appendChild(document.createElement('br'));
n.setAttribute('value',parseInt(n.getAttribute('value'))+1);
}

function delete_oP(id)
{
s=document.getElementById('files'+id);
n=document.getElementById('num'+id);
m=document.getElementById('names'+id);

if((parseInt(n.getAttribute('value'))) > 1)
{
    p=document.getElementById('file_'+id+''+(parseInt(n.getAttribute('value'))-1));
    k=document.getElementById('name_'+id+''+(parseInt(n.getAttribute('value'))-1));
    n.setAttribute('value',parseInt(n.getAttribute('value'))-1);
    s.removeChild(p);
    m.removeChild(k);
}
}

function add_express()
{
s=document.getElementById('files');
n=document.getElementById('num');

input=document.createElement('input');

input.setAttribute('type','file');
input.setAttribute('name','file_order_'+n.getAttribute('value'));
input.setAttribute('id','file_order_'+n.getAttribute('value'));


s.appendChild(input);
//s.appendChild(document.createElement('br'));

n.setAttribute('value',parseInt(n.getAttribute('value'))+1);
}

function delete_express()
{
s=document.getElementById('files');
n=document.getElementById('num');



if((parseInt(n.getAttribute('value'))) > 1)
{
    p=document.getElementById('file_'+(parseInt(n.getAttribute('value'))-1));
    n.setAttribute('value',parseInt(n.getAttribute('value'))-1);
	//var brElem = next_(p);
//	s.remiveChild(brElem);
    s.removeChild(p);
}
}
