function switchProductgroup(id) {
	if($('#productgroup'+id).hasClass('active')) {	// Switch off
		$('#productgroup'+id).removeClass('active');
			$.ajax({
				type: "GET",
				url: "ajax.php",
				data: "action=removeProductgroupFromSession&productgroupId="+id
			});
	}else{ // Switch on
		$('#productgroup'+id).addClass('active');
			$.ajax({
				type: "GET",
				url: "ajax.php",
				data: "action=addProductgroupToSession&productgroupId="+id
			});
	}
}

function fillMeasurements(productSelectlistId, measurementSelectlistId) {
	var productId = document.getElementById(productSelectlistId).value;

	$.ajax({
		type: "GET",
		url: "ajax.php",
		data: "action=fillMeasurements&productId="+productId,
		success: function(msg){
			$('#'+measurementSelectlistId).html(msg); // Put in the new options
		}
	});
}

function addFormrow(clickedRowobjectId,productgroupId,rowNumber) {
	// Add one to counter
	totalRows++;
	
	$.ajax({
		type: "GET",
		url: "ajax.php",
		data: "action=addRow&newRowId="+totalRows+"&productgroupId="+productgroupId,
		success: function(msg){
			$('#'+clickedRowobjectId).after(msg);
			
			// Copy product selectlist values of where PLUS was clicked
			$('#product_'+totalRows).html($('#product_'+rowNumber).html());
		}
	});
	document.getElementById('totalRows').value = totalRows;
}

function removeFormrow(clickedRowobjectId) {
	$('#'+clickedRowobjectId).remove();
	$totalRows--;
	document.getElementById('totalRows').value = totalRows;
}
