{stored_object name=$blah|cat:'u':$user->id type="newcomp" from="newcomp" assign="newcomp"}

{if $smarty.request.confirmReset}{stored_object name=$blah|cat:'u':$user->id type="signup" destroy="true"}{/if}

{include_php file="shared_handle:newcomp.createInvitation"}

<h1 class="pageHead2">Create a Competition: Step 2</h1>

<h2>Create Your Invitation Letter:</h2>

<form name="compStartForm" method="post">
<input type="hidden" name="pg" value="{toc_next}">
<input type="hidden" name="no_expire" value="true">
<input type="hidden" name="newcomp[letterType]" value="">

<script language="JavaScript">

var examples = Array();
{foreach from=$examples key="key" item="example"}
examples[{$key}] = '{eval var=$example.body|addslashes|replace:"\r":""|replace:"\n":"\\n"}';
{/foreach}

{literal}

function toggleType(type) {
	if (type == 'customLetter') {
		document.getElementById('customLetter').style.display = 'block';
		document.getElementById('madlib').style.display = 'none';
	} else {
		document.getElementById('customLetter').style.display = 'none';
		document.getElementById('madlib').style.display = 'block';
	}
}

function setExample(key) {
	toggleType('customLetter');
	var ta = document.getElementById('customLetterElement');

	if (!ta.value || confirm('Are you sure you want to overwrite your custom letter with this example?')) {
		ta.value = examples[key];
	}
}
{/literal}

</script>


<table align="center">
<tr>
	<td><div>
		<u>Examples:</u>
		<div style="margin-left:15px;">
			{foreach from=$examples key="key" item="example"}
				<a href="javascript://" onclick="setExample({$key});">{$example.title}</a><br />
			{foreachelse}
				Sorry, there are no examples for this combination of competition type and invitation letter type.
			{/foreach}
		</div>
	</div></td>
	<td align="center">
		<h2>{$newcomp.invitationType|niceText} Letter</h2>
		
		<table style="border:1px solid #CCCCCC;">
		<tr>
			<td><div>
				<a href="javascript://" onclick="toggleType('madlib');">Use a MadLib!</a>
				&nbsp; | &nbsp; 
				<a href="javascript://" onclick="toggleType('customLetter');">Create My Own</a>
			</div></td>
		</tr>
		<tr>
			<td>
				<div id="madlib" style="display:none;">
					TEXT!...</div>

				<div id="customLetter" style="display:block;">
					<textarea id="customLetterElement" name="newcomp[customLetter]" rows="20" cols="40" class="textarea"></textarea></div>
			</td>
		</tr>
		</table>
	</td>
	<td>
	</td>
</tr>
</table>

</form>