function analyse_logic()
{
    // get logic from form
	logicIn = logic_text_in.value;
	
	// warn user if script in is blank
	if(logicIn.length == 0)
	{
		window.alert("Paste the logic you want to analyse into the 'Logic to analyse' box.");
		return;
	}	
	// replace newlines
	logicIn = logicIn.replace(/&\r\n/g, "");
	logicIn = logicIn.replace(/\r\n/g, ";");
	
	// start logic out
	logicOut = "Target\tMethod\tCategory\tFormula\r\n";
	
	// separate methods in logic
	methods = logicIn.split("[METHOD=");
	methodsCount = methods.length
	for(method_index = 1; method_index < methodsCount; method_index++)
	{
		method = methods[method_index];
		method_label = method.substr(0,method.search(/,/));

		// separate categories in method
		categories = method.split("[CATEGORY= ");
		categoriesCount = categories.length
		for(categories_index = 1; categories_index < categoriesCount; categories_index++)
		{
			category = categories[categories_index]; //debug("Category: " + category);
			// get category labels
			category_labels = category.substr(0, category.search(/]/));
			//debug("Category Labels: " + category_labels);
			category_labels = category_labels.split(", ");
			// get category logic lines
			logic_lines = category.substr(category.search(/;/) + 1);
			//debug("Category Logic Lines: " + logic_lines);
			
			logic_lines = logic_lines.split(";");
			logicLinesCount  = logic_lines.length
			for(logic_lines_index = 0; logic_lines_index < logicLinesCount; logic_lines_index++)
			{
				logic_line = logic_lines[logic_lines_index];
				logic_target = logic_line.substr(0, logic_line.search(/=/));
				//debug(logic_target + "," + logic_line);
				categoryLabelsCount = category_labels.length
				for(cat_lab_index = 0; cat_lab_index < categoryLabelsCount; cat_lab_index++)
				{
					category_label = category_labels[cat_lab_index];
					if(logic_line.length > 0)
					{
						logicOut += logic_target + "\t" + method_label + "\t" + category_label + "\t" + logic_line + "\r\n";
						window.status = "Parsing: " + method_label + "-" + category_label;
					}
				}
			}
		}
	}
	window.status = "Copying to logic_text_out";
	logic_text_out.innerText = logicOut;
	window.alert("Finished analysing formulas.");
	window.status = "Done";
}
