{capture name="title"} - {l}Submit Link{/l}{/capture}
{capture assign="in_page_title"}{l}Submit Link{/l}{/capture}
{capture assign="description"}{l}Submit a new link to the directory{/l}{/capture}

{include file="header.tpl"}
{include file="top_bar.tpl"}

{include file="validation.tpl" form_id="submitForm" validators=$validators}

{strip}
{if $smarty.const.DISABLE_SUBMIT == 1 && $is_admin neq 1} 
    <table width="96%" border="0" align="center" cellpadding="4" cellspacing="4" class="sp_area">
        <tr>      
            <td>         
                <h2>{l}Closed{/l}</h2>      
           </td>   
        </tr>   
        <tr>      
            <td>         
	            {l}We are sorry but link submissions are closed.{/l}<br />
				{$disablereason}
            </td>   
        </tr> 
     </table> 
     <br /> 
{else}

{if ($confirmed)}
   <table border="0" class="formPage">
   <tr><td colspan="2" class="msg">
   {l}The link's email address has been confirmed.{/l}<br />
   {l}The link will be listed as soon as it is approved by a site administrator.{/l}
   </td></tr>
   </table>
{/if}

{if $smarty.const.REQUIRE_REGISTERED_USER == 1 and empty($regular_user_details.ID)}
    <table border="0" class="formPage">
       <tr>
          <td>
             <h3>{l}Information{/l}</h3>
          </td>
       </tr>
       <tr>
          <td>
             {l}You must be logged in to submit a new link.{/l}
             <br />
             {l}No account yet?{/l} <a href="{$smarty.const.DOC_ROOT}/profile.php?mode=register" title="{l}Register new user{/l}">{l}Create one{/l}</a>
          </td>
       </tr>
    </table>
{else}
    <form method="post" action="" class="cmxform" id="submitForm" name="submitForm" enctype="multipart/form-data">
    <table border="0" class="formPage">
    {if $error}
       <tr><td colspan="2" class="err">
          {l}An error has occured {foreach name=errorList from=$error_list key=errorKey item=errorItem}
					{if $errorKey == 'DO_MATH'}
						{if is_array($errorItem)}
							{$errorItem.remote}
						{else}
							{$errorItem}
						{/if}
					{/if}
				{/foreach}.{/l}
       </td></tr>
    {/if}
    
    {if $double_review and !$posted}
    <tr><td colspan="2" class="err">
       {$double_review}
    </td></tr>
    {/if}
    
    {if $posted}
       <tr><td colspan="2" class="msg">
       {l}Link submitted{/l}{if $waiting_approval eq 1}{l} and awaiting approval{/l}{/if}.<br />
       {l}Submit another link.{/l}
       </td></tr>
    {/if}
    
    {if $needs_confirmation}
        <tr><td colspan="2" class="msg">
       {l}The email address you provided needs to be confirmed before the link is listed.{/l}<br />
       {l}Please check your email for the confirmation link.{/l}
       </td></tr>
    {/if}


<tr>
	<td colspan="2">
            <div class="fields">
		<div class="fields_c">
			<h3>{l}Available Link Types{/l}:</h3>
			<table border="0" cellspacing="10" cellpadding="0">
				{foreach from=$link_types item=link_type name=link_types key=link_type_id}
		      	<tr>
		      		<td>
		      			<input type="radio" name="LINK_TYPE" value="{$link_type_id}" {if $link_type_id == $linktypeid}checked{/if}/>
		      		</td>
		      		<td>
		      			{l}{$link_type.NAME}{/l}&nbsp;-&nbsp;
		      			{if $link_type.PRICE > 0}
		      				{$smarty.const.HTML_CURRENCY_CODE}{$link_type.PRICE} / {$payment_um[$link_type.PAY_UM]}
		      			{else}
		      				free
		      			{/if}
		      			<p class="small">{l}{$link_type.DESCRIPTION}{/l}</p>
		      		</td>
				</tr>
				{/foreach}
			</table>
      	</div>
      	<div class="fields_b"></div>
	</div>
	</td>
</tr>


<tr>
   <td class="label underlined" align='left' colspan="2">
		{l}Fields marked with a {/l}<span class='req'>*</span>{l} are required.{/l}
   </td>
</tr>

{foreach from=$submit_items item=item name=submit_items}
{* special submit items *}
{if $item.FIELD_NAME == 'TITLE'}
	<tr>
		<td class="label">{if $valid.rules.TITLE.required==true}<span class='req'>*</span>{/if}{l}Title{/l}:</td>
		<td class="field">
			<input type="text" id="TITLE" name="TITLE" value="{$data.TITLE|escape|trim}" maxlength="{$smarty.const.TITLE_MAX_LENGTH}" class="text" />
            {if $SEO_URL != ''}
            	<a class="admin_action" href="{if !$smarty.const.ENABLE_REWRITE}
                                                {$smarty.const.DOC_ROOT}/detail.php?id={$ID}
                                             {else}
                                                {$smarty.const.DOC_ROOT}/{$SEO_URL}{/if}" title="{l}Preview Link on the Front End{/l}" target="_blank">
            		<img src="{$smarty.const.TEMPLATE_ROOT}/images/outbox.png"/>
            	</a>
            {/if}
         </td>
      </tr>
{elseif $item.FIELD_NAME == 'CATEGORY_ID'}
	<tr>
		<td class="label">{if $valid.rules.CATEGORY_ID.required==true}<span class='req'>*</span>{/if}{l}Category{/l}:</td>
		<td class="field">
			{* Load category selection *}
			{include file="category_select.tpl" selected=$data.CATEGORY_ID selected_parent=$data.PARENT_ID}
			{if $link_type_details.MULTIPLE_CATEGORIES != ''}
                        {foreach from=$add_categs item=categ name=additional}
				{if $smarty.foreach.additional.index < $link_type_details.MULTIPLE_CATEGORIES}
                                <div>
					{include file="category_select.tpl" selected=$categ.CATEGORY_ID  selected_parent=$categ.CATEGORY_ID additional_categs=true}&nbsp;
					<a href="#" onclick="removeCateg(this); return false;">{l}remove{/l}</a>
					<div style="float: none; clear: both; height: 8px;"></div>
				</div>
                                {/if}
			{/foreach}
                        {/if}
			<div id="categ" style="display: none;">
				<br />
				{include file="category_select.tpl" selected=$data.CATEGORY_ID selected_parent=$data.PARENT_ID additional_categs=true}&nbsp;
			</div>
			<a href="" class="formDelCateg" id="fileDelCateg" onclick="removeCateg(this); return false;" style="display: none">{l}remove{/l}</a>
  			<div class="clear"></div>
  			<br />
   			<a onclick="plusCateg();return false;" href="" id="plusCategLink" class="formSmall" style="border-width: 0;">+ {l}additional categ{/l}</a>
		</td>
      </tr>
      {elseif $item.FIELD_NAME == 'OWNER_NAME'}
	<tr>
		<td class="label">{if $valid.rules.OWNER_NAME.required==true}<span class='req'>*</span>{/if}{l}Owner Name{/l}:</td>
		<td class="field">
			<input type="text" id="OWNER_NAME" name="OWNER_NAME" value="{$data.OWNER_NAME|escape|trim}" maxlength="{$smarty.const.USER_NAME_MAX_LENGTH}" class="text" />
		</td>
	</tr>
{elseif $item.FIELD_NAME == 'OWNER_EMAIL'}
	<tr>
		<td class="label">{if $valid.rules.OWNER_EMAIL.required==true}<span class='req'>*</span>{/if}{l}Owner Email{/l}:</td>
		<td class="field">
			<input type="text" id="OWNER_EMAIL" name="OWNER_EMAIL" value="{$data.OWNER_EMAIL|escape|trim}" maxlength="255" class="text" />
                        <p class="small">
                            <span style="display: block; margin: 2px; float: left;">
                                <input type="checkbox" name="OWNER_NEWSLETTER_ALLOW" checked="checked" />
                            </span>
                            &nbsp;
                            <span style="display: block; float: left; margin: 2px 0 0 0;">Allow site administrator to send me newsletters. </span>
                        <div style="clear: both;"></div>
                        </p>
		</td>
	</tr>
{elseif $item.FIELD_NAME == 'META_KEYWORDS'}
	{if $smarty.const.ENABLE_META_TAGS eq 1}
	<tr>
		<td class="label">{l}META Keywords{/l}:</td>
		<td class="field">
			<input type="text" id="META_KEYWORDS" name="META_KEYWORDS" value="{$data.META_KEYWORDS|escape|trim}" class="text" />
			<p class="msg notice info">{l}Separate keywords by comma.{/l}</p>
		</td>
	</tr>
	{/if}
{elseif $item.FIELD_NAME == 'META_DESCRIPTION'}
	{if $smarty.const.ENABLE_META_TAGS eq 1}
	<tr>
		<td class="label">{l}META Description{/l}:</td>
		<td class="smallDesc">
			<textarea id="META_DESCRIPTION" name="META_DESCRIPTION" rows="3" cols="30" class="text" {formtool_count_chars name="META_DESCRIPTION" limit=$smarty.const.META_DESCRIPTION_MAX_LENGTH alert=true}>{$data.META_DESCRIPTION|trim|escape}</textarea>
			<p class="limitDesc">{l}Limit{/l}: <input type="text" name="META_DESCRIPTION_limit" class="limit_field" readonly="readonly" value="{$MetaDescriptionLimit}" /></p>
		</td>
	</tr>
	{/if}
	
{elseif $item.FIELD_NAME eq 'RECPR_URL'}		
	<tr>
		<td class="label">{if $valid.rules[$item.FIELD_NAME].required==true}<span class='req'>*</span>{/if}{l}{$item.NAME}{/l}:</td>
		<td class="field">
        	<input type="text" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" value="" size="40" maxlength="255" class="text" />
        	<br />
        	{if $smarty.const.SAME_DOMAIN_RECPR == 1}
				<p class="small">{l}We require the Reciprocal to be on the same domain as the link you are submitting.{/l}</p>
        	{/if}
        	<p class="small">{l}To validate the reciprocal link please include the{/l}<br />{l}following HTML code in the page at the URL{/l}<br />{l}specified above, before submiting this form{/l}:</p>
        	<textarea name="RECPR_TEXT" rows="2" readonly="readonly" cols="50" class="text">&lt;a href="{$smarty.const.DEFAULT_RECPR_URL}"&gt;{$smarty.const.DEFAULT_RECPR_TITLE}&lt;/a&gt;</textarea>
		</td>
	</tr>
{* /special submit items *}
{else}
<tr>
	   	<td class="label">{if $valid.rules[$item.FIELD_NAME].required==true}<span class='req'>*</span>{/if}{l}{$item.NAME}{/l}:</td>
	   	<td class="field">
			{if $item.TYPE eq 'STR'}
				<input type="text" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" value="{$data[$item.FIELD_NAME]|escape|trim}" size="40" class="text" />
			{elseif $item.TYPE eq 'TXT'}
				{include file="rte.tpl" NAME=$item.FIELD_NAME VALUE=$data[$item.FIELD_NAME]}
			{elseif $item.TYPE eq 'BOOL'}
				{html_options options=$yes_no selected=$data[$item.FIELD_NAME] name=$item.FIELD_NAME id=$item.FIELD_NAME}
			{elseif $item.TYPE eq 'DROPDOWN'}
				{html_options2 options=$item.OPTIONS selected=$data[$item.FIELD_NAME] name=$item.FIELD_NAME id=$item.FIELD_NAME}
			{elseif $item.TYPE eq 'CAT'}
				{html_options options=$categsNormal selected=$data[$item.FIELD_NAME] name=$item.FIELD_NAME id=$item.FIELD_NAME}
			{elseif $item.TYPE eq 'FILE'}
				<input type="file" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" class="text"/><br />
				{l}Allowed files{/l}: .pdf, .xls, .xlsx, .doc, .docx, .zip, .rar, .txt, .rtf, .csv. {l}Files of other types will not be uploaded at all{/l}.
				<br/>
				{if $data[$item.FIELD_NAME] neq ''}
				{l}Current{/l}: <br/><a href="{$smarty.const.SITE_URL}uploads/{$data[$item.FIELD_NAME]}" target="_blank">{$data[$item.FIELD_NAME]}</a>
					&nbsp;<input type="checkbox" name="MARK_REMOVE_{$item.FIELD_NAME}" value="1"/>&nbsp;{l}Mark for removal{/l}
				{/if}
				 {elseif $item.TYPE eq 'VIDEO'}
                            <input type="file" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" class="text"/><br/>
                            {l}Allowed files{/l}: .avi, .mpg, .wmv, .mov {l}Files of other types will not be uploaded at all{/l}.
                            <br />
                            {if $data[$item.FIELD_NAME] neq ''}
                                {l}Current{/l}: <br/><img src="{$smarty.const.SITE_URL}uploads/thumb/{$data[$item.FIELD_NAME]}.jpg"/> <a href="{$smarty.const.DOC_ROOT}/rm_si.php?id={$item.ID}&lid={$data.ID}">{l}Remove{/l}</a>
                            {/if}
			{elseif $item.TYPE eq 'IMAGE'}
				<input type="file" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" class="text"/><br/>
				{l}Allowed files{/l}: .gif, .png, .jpg, .jpeg. {l}Files of other types will not be uploaded at all{/l}.
				<br />
				{if $data[$item.FIELD_NAME] neq ''}
					{l}Current{/l}: <br/>
					<a href="{$smarty.const.SITE_URL}uploads/{$data[$item.FIELD_NAME]}?detail=1&TB_iframe=true&height=400&width=400" onclick="return showThickbox(this);" class="thickbox">
					<img src="{$smarty.const.SITE_URL}uploads/thumb/{$data[$item.FIELD_NAME]}"/></a>
					&nbsp;<input type="checkbox" name="MARK_REMOVE_{$item.FIELD_NAME}" value="1"/>&nbsp;{l}Mark for removal{/l}
				{/if}
			{elseif $item.TYPE eq 'IMAGEGROUP'}
                                {php}
                                        // assign a uniqid to this field so we can find the files on submit
                                        $this->assign('imagegroupid',uniqid());
                                {/php}
                                <input type="hidden" name="{$item.FIELD_NAME}" id="{$item.FIELD_NAME}" value="{$imagegroupid}"/>
                                {literal}
                                        <div id="file-uploader">
                                                <noscript>
                                                        <p>Please enable JavaScript to use file uploader.</p>
                                                        <!-- or put a simple form for upload here -->
                                                </noscript>
                                        </div>
                                        <script src="javascripts/fileuploader.js" type="text/javascript"></script>
                                             <script>
					     curr_count = 0;
                                                function createUploader(){
                                                    var uploader = new qq.FileUploader({
                                                        element: document.getElementById('file-uploader'),
                                                        action: 'uploadimg.php',
							onSubmit: function(id, fileName, responseJSON){
													curr_count = curr_count+1;
													if(curr_count>=parseInt("{/literal}{$link_types[$linktypeid].COUNT_IMAGES}{literal}"))
													 jQuery(".qq-upload-button").hide();
													       },
                                                        params: {
                                {/literal}
                                                                imagegroupid: "{$imagegroupid}"
                                {literal}
                                                        }
                                                    });
                                                }
                                                window.onload = createUploader;
                                          </script>

                                {/literal}
			{/if}
    
			{if $item.DESCRIPTION}
				<br /><p class="small">{$item.DESCRIPTION}</p>
			{/if}
		</td>
	</tr>
{/if}
{/foreach}    

{if $link_type_details.DEEP_LINKS > 0}
	<tr>
		<td class="label required"><label>{l}Deep Links{/l}:</label></td>
		<td class="smallDesc">
			<table id="additional_links" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td align="center">{l}Titles{/l}</td>
					<td align="center">{l}URLs{/l}</td>
				</tr>
				
				{section name=i start=0 loop=$link_type_details.DEEP_LINKS}
				<tr>
					<td><input type="text" name="ADD_LINK_TITLE[]" class="text" style="width: 130px;" value="{$add_links[i].TITLE}" /></td>
					<td><input type="text" name="ADD_LINK_URL[]"   class="text" style="width: 130px;" value="{$add_links[i].URL}" /></td>
				</tr>
				{/section}
			</table>
			
			<div class="clear"></div>
		</td>
	</tr>
{/if}

{if $remove_link}
<tr>
    <td class="label">{l}Mark for removal{/l}:</td>
    <td class="field">
        <input type="checkbox" id="MARK_REMOVE" name="MARK_REMOVE" /><span class="small">{l}Use with caution{/l}</span>
    </td>
</tr>
{/if}
{if $smarty.const.VISUAL_CONFIRM eq 2}
<tr>
		<td class="label"<span class='req'>*</span>{l}DO THE MATH{/l}:</td>
		<td class="field">
			<span style="color: red;">
				{foreach name=errorList from=$error_list key=errorKey item=errorItem}
					{if $errorKey == 'DO_MATH'}
						{if is_array($errorItem)}
							{$errorItem.remote}<br/>
						{else}
							{$errorItem}<br/>
						{/if}
					{/if}
				{/foreach}
			</span>
			<font style="font-weight: bold; font-size: 14pt; color: red; margin-right: 10px;">{$DO_MATH_N1} + {$DO_MATH_N2} = </font><input type="text" id="DO_MATH" name="DO_MATH" value='{$DO_MATH}' class="text" style="width: 60px;"/>
		<br/>
		<br/>
		</td>
	</tr>
	{/if}
{if $smarty.const.VISUAL_CONFIRM eq 1}
    {if $dont_show_captch neq 1}
    <tr id="{$item.NAME}">
        <td class="label"><span class='req'>*</span>{l}Enter the code shown{/l}:</td>
        <td class="field">
            <input id="IMAGEHASH" name="IMAGEHASH" type="hidden" value="{$imagehash}" />
            <input class="required text" id="CAPTCHA" name="CAPTCHA" type="text" value="" size="{$smarty.const.CAPTCHA_PHRASE_LENGTH}" maxlength="{$smarty.const.CAPTCHA_PHRASE_LENGTH}" class="text" />
            <label for="CAPTCHA" id="captcha_validation" style="float: none; color: red; padding-left: .5em; "></label>
            <div style="clear: both;"></div>
            <p class="small">{l}This helps prevent automated registrations.{/l}</p>
            <img src="{$smarty.const.DOC_ROOT}/captcha.php?imagehash={$imagehash}" class="captcha" alt="{l}Visual Confirmation Security Code{/l}" title="{l}Visual Confirmation Security Code{/l}" />
        </td>
    </tr>
    {/if}
{/if}

<tr id="AGREERULES">
    <td class="label"><span class='req'>*</span><a href="{$smarty.const.DOC_ROOT}/rules.php" title="Submission Rules" target='_blank'>{l}Submission Rules Agreement{/l}</a>:</td>
    <td class="field">
        <input type="checkbox" id="AGREERULES" name="AGREERULES"{if $AGREERULES eq 'on'} checked="checked"{/if} /> {l}I AGREE with the {/l}<a href="{$smarty.const.DOC_ROOT}/rules.php" title="Submission Rules" target='_blank'>{l}submission rules{/l}</a>
    </td>
</tr>
<tr>
    <td colspan="2" class="buttons">
    {if !$review_link and !$remove_link}
       <input type="submit" name="continue" value="{l}Continue{/l}" onclick="this.value='Please Wait'"  class="btn" />
    {else}
       <input type="hidden" name="id" value="{$data.ID}"/>
       <input type="submit" name="edit" value="{l}Continue{/l}" class="btn" />
    {/if}
    </td>
</tr>
</table>
<input type="hidden" name="formSubmitted" value="1" />
</form>
{/if}
{/if}

{literal}

<script type="text/javascript">

jQuery(function($) {
	$(document).ready(function(){
		$("input[name=LINK_TYPE]").change(function(){
			//update_form(); // albert: seems useless, we are making a refresh when the user changes the link type
			var lt = getUrlVars()["LINK_TYPE"];
			if (lt) {
				var url = location.href.replace("LINK_TYPE="+lt, "LINK_TYPE=" + this.value);
			} else {
				if (location.href.search(/\?/) == -1) {
					var url = location.href + "?LINK_TYPE="+this.value;
				} else {
					var url = location.href + "&LINK_TYPE="+this.value;
				}
			}
			location.href= url;
		});
		
		function getUrlVars()
		{
		    var vars = [], hash;
		    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		    for(var i = 0; i < hashes.length; i++)
		    {
		        hash = hashes[i].split('=');
		        vars.push(hash[0]);
		        vars[hash[0]] = hash[1];
		    }
		    return vars;
		}

	
		$("#addCateg").click(function(){
			var categs_count = $("#multiple_categs").children().size();
			var link_type	  = $('input[name=LINK_TYPE]:checked').val();
			if (categs_count < multiple_categs[link_type]) {
				$("#add_categ").clone(true).insertAfter("#add_categ");
				categs_count++;
			}
			if (categs_count == multiple_categs[link_type])
				$(this).hide();
			
		});

		$("#removeCateg").click(function(){
			if ($("#addCateg").is(":hidden"))
				$("#addCateg").show();
			if ($("#multiple_categs").children().size() > 1)
				$(this).parent().remove();
		});


		$("#submitForm").submit(function() {
			$('#categ').remove();
			return true;
		});

	});
});

var maxCats = {/literal}{if $link_type_details.MULTIPLE_CATEGORIES == ''}1{else}{$link_type_details.MULTIPLE_CATEGORIES}{/if}{literal};
var numCats = {/literal}1 + {$add_categs|@count}{literal};
if (numCats >= maxCats) {
	$('plusCategLink').style.display = 'none'; 
}

function plusCateg()
{
	var div = $('categ');
	var newDiv = div.cloneNode(true);
	newDiv.id = ''
	newDiv.style.display = 'block';

	//newDiv.find('*.smallText').val("");

	var delLink = $('fileDelCateg');
	var a = delLink.cloneNode(true);
	a.id = '';
	a.style.display = "inline";
	newDiv.appendChild(a);
	delLink.parentNode.insertBefore(newDiv, delLink);

	numCats++;
	if (numCats >= maxCats) {
		$('plusCategLink').style.display = 'none'; 
	} 
}

function removeCateg(elem)
{
	elem.parentNode.remove(elem.previousSibling);
	
	numCats--;
	if (numCats < maxCats) {
		$('plusCategLink').style.display = 'block'; 
	} 
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}


</script>

{/literal}


{include file="footer.tpl"}
{/strip}