function addUploadFields(id, amount, clas) {
  if (!id) {
    id = 'uploadfilebox';
  }

  var el = $(id);
  var span = el.getElementsByTagName('span')[0];

 
 if ('none' == span.style.display) {
    // Show the file upload box
    span.style.display = 'inline';

  } else {
    // Copy the first file upload box and clear it's value
    var newBox = span.cloneNode(true);
    newBox.getElementsByTagName('input')[0].value = '';
    el.appendChild(newBox);
	
var divs = document.getElementsByTagName('input');
var skaicius=0

		for(var no=0;no<divs.length;no++){
			if(divs[no].className==clas){
			
			skaicius++;
			}	
			
		}	
if (skaicius>=amount) document.getElementById("upload_"+clas).setAttribute('disabled',true);
  }
}



function removeUploadField(element, id, clas, amount) {
  if (!id) {
    id = 'uploadfilebox';
  }
  var el = $(id);
  var span = el.getElementsByTagName('span');
  if (1 == span.length) {
    // Clear and hide the box
   // span[0].style.display='none';
  //  span[0].getElementsByTagName('input')[0].value = '';
    
  } else {
	var divs = document.getElementsByTagName('input');
	var skaicius=0

		for(var no=0;no<divs.length;no++){
			if(divs[no].className==clas){
			
			skaicius++;
			}	
			
		}		  
	  
    el.removeChild(element.parentNode);

		
if (skaicius<=amount) document.getElementById("upload_"+clas).removeAttribute('disabled');
  }
}

