function insert_rows()
{
	    
	// get user inputs from page
	scriptIn = script_in.value;
	rowInsertAbove = row_insert_above.value * 1;
	rowsInsertCount = rows_insert_count.value * 1;
	
    /***
    * Validate user input
    */
			
	// warn user if script in is blank
	if(scriptIn.length == 0)
	{
		window.alert("Paste the script you want to insert rows in into the Script in box.");
		return;
	}
	// warn user if insert row above input is blank
	if(rowInsertAbove == "")
	{
			window.alert("Insert above row is blank.");
			return;
	}
	// warn user if insert row above input is not a number
	if(isNaN(rowInsertAbove))
	{
			window.alert("Insert above row must be a number.");
		 	return;
	}
	// warn user if rows insert is blank
	if(rowsInsertCount == "")
	{
			window.alert("Number of rows to insert is blank.");
			return;
	}
	// warn user if insert row above input is not a number
	if(isNaN(rowsInsertCount))
	{
			window.alert("Number of rows to insert must be a number.");
		 	return;
	}
	scriptOut = scriptIn;

	// count rows in form script
	rowInsertAboveExists = true;
	for(rowIndex = 1; rowInsertAboveExists; rowIndex++)
	{
		//Create regular expression object.
		rowSearchText = new RegExp("R" + rowIndex + "=","i");

		// If row exist
		if (scriptIn.search(rowSearchText) != -1)
		{
			rowCount = rowIndex;
		}
		// If row does not exist
		else
		{
			rowInsertAboveExists = false;
		}
	}
	// warn user inser above row above does not exist in form script
	if(rowInsertAbove > rowCount)
	{
		window.alert("Cannot insert above row " + rowInsertAbove + " because form only has " + rowCount + " rows.");
		return;
	}

	// renumber rows on form
	//rowsInsertCount = rows_insert_input.value;
	for(rowIndex = rowCount; rowIndex >= rowInsertAbove; rowIndex--)
	{
		rowReplaceText = new RegExp("R" + rowIndex + "=","i");
		replace_text = "R" + (rowIndex + (rowsInsertCount * 1)) + "=";
		scriptOut = scriptOut.replace(rowReplaceText, replace_text);
	}
	
	// insert blank row(s)
	rowsBlankText = "";
	rowIndex = rowInsertAbove;
	for(rowIndex; rowIndex <= (rowInsertAbove + rowsInsertCount - 1); rowIndex++)
	{
		rowsBlankText += "R" + rowIndex + "=Blank\n";
	}
	rowsBlankText += "R" + (rowInsertAbove + rowsInsertCount) + "=";
	rowReplaceText = new RegExp("R" + (rowInsertAbove + rowsInsertCount) + "=","i");
	scriptOut = scriptOut.replace(rowReplaceText, rowsBlankText);

	script_out.innerText = scriptOut;
}
/*
* Displays alert box containing text. Use for debugging
*/
function d(variable, value)
{
	window.alert(variable + " = " + value);
}
