var cloned = new Object();
function cloneDiv(toClone) {
	if ($chk(cloned[toClone])) { 
		cloned[toClone]++; 
	} else { 
		cloned[toClone] = 1; 
	}
	var clone = $(toClone).clone().injectBefore(toClone);
	clone.set('id', toClone+'_'+cloned[toClone]);

	if (cloned[toClone] > 1) {
		$$('#'+toClone+'_'+cloned[toClone]+' input.bt_minus').each(function(el) { 
			el.addEvent('click', delDiv); 
			el.setStyle('display', 'inline');
		});
	}

	clone.setStyle('display', 'inline');
	
	$$('#'+toClone+'_'+cloned[toClone]+' input').each( function(item, index){
		if ( ( item.get('name') != 'bt_plus' ) &&
			 ( item.get('name') != 'bt_minus' ) ) {
				
				var newname = item.get('name')+'_'+cloned[toClone];
				var createItem = new Element('input', { 'type':'text','class':item.get('class'),'style':item.get('style'),'name':newname,'size':item.get('size'),'value':item.get('value') });

				if ( newname.match(/counter/) ) {
					createItem.setStyle('display', 'none');
				}

				var newItem = createItem.injectBefore(item);
				item.dispose();

				newItem.set('value', clonedata[newItem.get('name')]);
			}
	} );


}

function delDiv(el) {
	this.getParent().destroy(); 
};

