var filesCount=1;
function addRowClone(tblId)
{
	if ( filesCount >= 10 ) return(alert('Maximum files reached'));
	var tblBody = document.getElementById(tblId).tBodies[0];
	newNode = tblBody.rows[0].cloneNode(true);
	var e = newNode.getElementsByTagName('span');
	e[0].style.display = 'inline';
	var f = newNode.getElementsByTagName('input');
	var first=document.getElementById('firstfile');
	f[0].value = '';
	f[0].id='';
	f[0].name='file_name[]';
	f[1].value = '';
	f[1].id='';
	f[1].name='file[]';
	//e[0].style.display = 'none';
	filesCount++;
	tblBody.appendChild(newNode);
}
function removeCloneRow(node) {
	 document.getElementById('atrForm').removeChild(node);
}
function removeCloneRow2(node) {
	 document.getElementById('atrForm2').removeChild(node);
}
function exec_ajax(file, method)
{
     $.ajax({
        type: method,
        url: file,
        data: null,
        cache: false,
        success: function(html){
        	eval(html);
        }
     });
}

$(function(){
	$("#add-accs").click(function(){
		acc = $("#accessories").val();
		id = $("#acc-parent").val();
		name = $("#acc-opt-" + acc).html();
		
		$.post("/ajax/add_acc", {"item": id, "acc": acc}, function(data){
			$("#acc-added").append('<p id="added-acc-' + data + '">' + name + ' <span class="del-acc" id="del-acc-' + data + '"><b> (изтрий)</b></span></p>');
//			window.location = window.location;
		}, "text");
	
		return false;
	});
	
	$(".del-acc").bind("click", function(){
		id = $(this).attr("id").replace("del-acc-", "");
		
		$.post("/ajax/del_acc", {"id": id}, function(){
			$("#added-acc-" + id).fadeOut().remove();
		});
	});
});


