jQuery(document).ready(function() {	

	function do_zebra(){
		jQuery('.form-table tr:nth-child(4n+3)').css({"background" : "#F1F1F1"});
		jQuery('.form-table tr:nth-child(4n+4)').css({"background" : "#F1F1F1"});		
	}
	do_zebra();
	jQuery('input#condition-add-new').parent().parent().css({"background" : "white"});
  jQuery('#condition-add-new').click(function(){  	
	//count rows in a .form-table minus last row with the button
	var sets = jQuery('.form-table tr input[id$="-code"]').length;			
	
	var rows = '<tr valign="top"><th scrope="row"> <label for="">Name %n:</label> </th> <td> <input size="30" type="text" id="condition-%id-name" name="atw[condition][%id][name]"/> </td> </tr> <tr valign="top"> <th scrope="row"> <label for="">Code %n:</label> </th> <td> <input size="60" type="text" id="condition-%id-code" name="atw[condition][%id][code]"/> </td> </tr>';

	//jQuery(this).parent().parent().before('<tr lign="top">' + row1.replace('[0]', '['+sets+']') + '</tr>' + '<tr lign="top">' + row2.replace('[0]', '['+sets+']') + '</tr>');
	jQuery(this).parent().parent().before(rows.replace(/%id/gi, sets).replace(/%n/gi, sets+1));
	do_zebra();
  });  
});