{include file="$gentemplates/$header_tpl"}
<h2>{$lang.banners.pages}</h2>

{*if $form.error}<p class="error_msg">* {$form.error}</p>{/if*}


<form name="edit_resols" enctype="multipart/form-data" method="post" action="{$file_name}">
	{$form.hiddens}
	<dl>
		<dt style="width:100%;">
			<div style="margin-bottom: 20px;">			
			<dl style="margin: 5px 0;">
				{foreach name=a from=$areas item=item}
				<dt align="{$default_left}" style="width:8%">
					{$item.price} {$settings.site_unit_costunit}
				</dt>
				<dt style="width:3%">
					<input type="checkbox" id="ar{$smarty.foreach.a.iteration}" name="area[]" value="{$item.id}" {if $item.checked eq 1} checked="checked" {/if} onclick="javascript: CalcForm();" style="position:relative;"/>
				</dt>
				<dt style="width:36%; margin-{$default_right}: 20px; text-align:left;">
					{$item.description}
					<input type="hidden" id="pr{$smarty.foreach.a.iteration}" value="{$item.price}" />
				</dt>
				{if $smarty.foreach.a.last && $smarty.foreach.a.iteration is div by 1}
				<dt class="main_content_text" align="{$default_left}" style="width:50%" colspan="3"></dt>
				{/if}
				{if $smarty.foreach.a.iteration is div by 2 }
				</dl><dl style="margin: 5px 0;">
				{/if}
				{/foreach}
				<input type="hidden" id="count" value="{$smarty.foreach.a.iteration}" />
			</dl>
			</div>
		</dt>
	</dl>
	<dl style="margin-bottom: 20px;">
		<dt>
			<div>
			<dl>
				<dt>{$lang.banners.count_account}: <b>{$curr_count} {$settings.site_unit_costunit}</b></dt>
			</dl>
			<dl>
				<dt>{$lang.banners.count}: <b><span id="curr_count">0</span> {$settings.site_unit_costunit}</b></dt>
			</dl>
			<dl>
				<dt>{$lang.banners.total_pages}: <b><span id="pages">0</span></b></dt>
			</dl>
			<dl>
				<dt>{$lang.banners.for_period}: <b>{$settings.banner_period_amount} {$settings.banner_period}</b></dt>
			</dl>
			<dl><dt>&nbsp;</dt></dl>
			<dl>
				<dt>{$lang.banners.renew_account}: <a href="{$form.account_link}">{$lang.section.account}</a></dt>
			</dl>
			</div>
		</dt>
	</dl>
	<dl>
		<dt><input id="submit_butt" type="submit" value="{$lang.banners.activate_link}" ></dt>
	</dl>
</form>
<script>
{literal}

count = document.getElementById('count').value;
account = ownParseFloat(document.getElementById('id_account').value);
disableExtraAreas(0);

function CalcForm(){
	summ = 0;
	count_pages = 0;
	for(i=1;i<=count;i++){
		if (document.getElementById('ar'+i).checked){
			checked=1;
			count_pages++;
			summ = ownParseFloat(parseFloat(summ) + parseFloat(document.getElementById('pr'+i).value));
		}
	}
	disableExtraAreas(summ);
	document.getElementById('curr_count').innerHTML = summ;
	document.getElementById('pages').innerHTML = count_pages;
	if (count_pages>0) document.getElementById('submit_butt').disabled = false;
	else document.getElementById('submit_butt').disabled = true;
}

function disableExtraAreas(summ){
	for(i=1;i<=count;i++){
		new_summ = summ + ownParseFloat(document.getElementById('pr'+i).value);
		if (new_summ>account){
			if (document.getElementById('ar'+i).checked==false)
				document.getElementById('ar'+i).disabled=true;
		}else{
			document.getElementById('ar'+i).disabled=false;
		}
	}
}

function CheckMyForm(){
	butt = document.getElementById('submit_butt');
	if (CheckForm()) butt.disabled = false;
	else butt.disabled = true;
}

function ownParseFloat(value){
	return Math.round(parseFloat(value)*100)/100;
}

{/literal}
</script>
{include file="$gentemplates/$footer_tpl"}