{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$FILE_SELF}">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.banners.razdel_name}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.banners_edit}
    </div>
</div>
<table border=0 cellspacing=0 cellpadding=0 width="100%">
<form name="edit_banner" enctype="multipart/form-data" method="post" action="{$FILE_SELF}">
{$form.hiddens}
<tr class="table_header">
  <td colspan="2" class="main_header_text" align="left" width="20%">
   {$lang.banners.properties}
  </td>
</tr>
<tr class="even">
  <td class="main_content_text" align="left" width="20%">
   {$lang.banners.name}: 
  </td>
  <td class="main_content_text" align="left">
   <input type="text" name="banner_name" size="40" value="{$one_banner.name}">
  </td>
</tr>
<tr class="odd">
  <td class="main_content_text" align="left">
   {$lang.banners.status}:
  </td>
  <td class="main_content_text" align="left">
   <input type="checkbox" style="margin-left: 0px;" name="status" {if $one_banner.status eq 1}checked="checked"{/if}>
  </td>
</tr>

</tr>
<tr class="even">
  <td class="main_content_text" align="left">
   {$lang.banners.type}:
  </td>
  <td class="main_content_text" align="left">
   <select name="edit" onChange="javascript:ChangeInputType()">
   <option value="image">{$lang.banners.type_image}  </option>
   <option value="html" {if $edit_type eq "html"}selected{/if}>{$lang.banners.type_html}  </option>
   <option value="js_code" {if $edit_type eq "js_code"}selected{/if}>{$lang.banners.type_js_code}  </option>
  </td>
</tr>

{if $edit_type eq "html"}
   <tr class="odd"><td class="main_content_text" align="left">
    {$lang.banners.place_and_size}: 
    </td>
    <td class="main_content_text" align="left"> 
       <select name="place_size_select" onChange="javascript:ChangeBar(options[selectedIndex].value)">
         {foreach from=$posible_sizes item=one_size}
          {$one_size}
         {/foreach}     
     </td>
   </tr>
   <tr class="even"><td class="main_content_text" align="center">
      {$lang.banners.html_code}: 
      </td>
      <td class="main_content_text" align="left"> 
         <textarea cols="120" name="banner_html_code" rows="15" wrap="VIRTUAL">{$one_banner.html_code}</textarea>
      </td>
   </tr>    
{elseif $edit_type eq "js_code"}
    <tr class="odd"><td class="main_content_text" align="left">
    {$lang.banners.place_and_size}: 
    </td>
    <td class="main_content_text" align="left"> 
       <select name="place_size_select" onChange="javascript:ChangeBar(options[selectedIndex].value)">
         {foreach from=$posible_sizes item=one_size}
          {$one_size}
         {/foreach}     
     </td>
   </tr>
   <tr class="even"><td class="main_content_text" align="center">
      {$lang.banners.js_code}: 
      <font color="red">{$lang.banners.note_js}</font>
      </td>
      <td class="main_content_text" align="left"> 
         <textarea cols="120" name="banner_js_code" rows="15" wrap="VIRTUAL">{$one_banner.html_code}</textarea>
      </td>
   </tr>
{else}
<tr class="odd">
  <td class="main_content_text" align="left">
   {$lang.banners.image}: 
  </td>
  <td class="main_content_text" align="left">
   {if $one_banner.img_file_path neq ""}
    <img name="banner_img" src="{$one_banner.img_file_path}" width="{$one_banner.size_x}" height="{$one_banner.size_y}" alt="{$one_banner.alt_text}"></td>
   {/if}
  </td>
</tr>

   <tr class="even"><td class="main_content_text" align="left">
     {$lang.banners.image_path}:
     </td>
     <td class="main_content_text" align="left">
     <input type="text" name="img_file_path" size="40" value="{$one_banner.short_img_file_path}">
     </td>
   </tr>
   <tr class="odd"><td class="main_content_text" align="left">
     {$lang.banners.upload_image}:
     </td>
     <td class="main_content_text" align="left">
     <input name="file" type="file" value="{$site_root}/uploades/banners/{$one_banner.short_img_file_path}">
     {$lang.banners.allowed_formats}
     </td>

   </tr>
   <tr class="even"><td class="main_content_text" align="left">
    {$lang.banners.place_and_size}: 
    </td>
    <td class="main_content_text" align="left"> 
       <select name="place_size_select" onChange="javascript:ChangeBar(options[selectedIndex].value)">
         {foreach from=$posible_sizes item=one_size}
          {$one_size}
         {/foreach}     
     </td>
   </tr>
   <tr class="odd"><td class="main_content_text" align="left">
    {$lang.banners.link}:
    </td>
    <td class="main_content_text" align="left">
    <input type="text" name="banner_url" size="40" value="{$one_banner.banner_url}">
    </td>
   </tr>
   <tr class="even"><td class="main_content_text" align="left">
    {$lang.banners.alttext}:
    </td>
    <td class="main_content_text" align="left">
    <input type="text" name="alt_text" size="40" value="{$one_banner.alt_text}">
    </td>
   </tr>
   <tr class="odd"><td class="main_content_text" align="left">
    {if $one_banner.stop_after_views neq -1}
    <input type="checkbox" name="stop_after_views_checked" checked="checked" style="margin-left: 0px;" onclick="javascript:SetStatusStopByView(checked)">
    {$lang.banners.stop_after_views}:
    <td class="main_content_text" align="left">
    <input type="text" name="stop_after_views" size="40" value="{$one_banner.stop_after_views}">
    {else}
    <input type="checkbox" name="stop_after_views_checked" style="margin-left: 0px;" onclick="javascript:SetStatusStopByView(checked)">
    {$lang.banners.stop_after_views}:
    <td class="main_content_text" align="left">
    <input type="text" name="stop_after_views" size="40" value="1" disabled="disabled">
    {/if}
    </td>
   </td></tr>
   <tr class="even"><td class="main_content_text" align="left">
    {if $one_banner.stop_after_hits neq -1}  
    <input type="checkbox" style="margin-left: 0px;" name="stop_after_hits_checked" checked="checked" onclick="javascript:SetStatusStopByHits(stop_after_hits_checked.checked)">
    {$lang.banners.stop_after_hits}:
    <td class="main_content_text" align="left">
    <input type="text" name="stop_after_hits" size="40" value="{$one_banner.stop_after_hits}">
    {else}
    <input type="checkbox" style="margin-left: 0px;" name="stop_after_hits_checked" onclick="javascript:SetStatusStopByHits(checked)">
    {$lang.banners.stop_after_hits}:
    <td class="main_content_text" align="left">
    <input type="text" name="stop_after_hits" size="40" value="1" disabled="disabled">
    {/if}
    </td>
   </td></tr>
   <tr class="odd"><td class="main_content_text" align="left">
    {if $one_banner.stop_after_date neq "0000-00-00"}  
    <input type="checkbox" style="margin-left: 0px;" name="stop_after_date_checked" checked="checked" onclick="javascript:SetStatusStopByHits(stop_after_hits_checked.checked)">
    {$lang.banners.stop_after_date}:
    <td class="main_content_text" align="left">
    {else}
    <input type="checkbox" style="margin-left: 0px;" name="stop_after_date_checked" onclick="javascript:SetStatusStopByDate(checked)">
    {$lang.banners.stop_after_date}:
    <td class="main_content_text" align="left">
    {/if}
      <select name="b_day" {if $one_banner.stop_after_date eq "0000-00-00"}disabled{/if}> 
          {section name=d loop=$day}
            <option value="{$day[d].value}" {if $day[d].sel}selected{/if}>{$day[d].value}</option>
        {/section}
        </select>&nbsp;
    <select name="b_month" {if $one_banner.stop_after_date eq "0000-00-00"}disabled{/if}>
        {section name=m loop=$month}
          <option value="{$month[m].value}" {if $month[m].sel}selected{/if}>{$month[m].name}</option>
        {/section}
        </select>&nbsp;
    <select name="b_year" {if $one_banner.stop_after_date eq "0000-00-00"}disabled{/if}>
        {section name=y loop=$year}
          <option value="{$year[y].value}" {if $year[y].sel}selected{/if}>{$year[y].value}</option>
        {/section}
        </select>&nbsp;
    </td>
   </td></tr>
   <tr class="even"><td class="main_content_text" align="left">
    {$lang.banners.open_new_window}:    
    </td>
    <td>
    <input type="checkbox" style="margin-left: 0px;" name="open_in_new_window" {if $one_banner.open_in_new_window eq 1} checked="checked" {/if}>
   </td></tr>
{/if}
<tr><td colspan="2">{$lang.banners.edit_comment}</td></tr>

<tr class="odd">
  <td class="main_content_text" align="left" valign="top">
    {$lang.banners.show_for}:
  </td>
  <td>
	  <table>
		  <tr>
			  <td style="padding-left: 0px;">
				  {$lang.banners.usertype}:
			  </td>
			  <td>
				  <select name="id_user_type">
					  <option value="0"></option>
						{foreach item=item from=$user_types name=user_type}
							<option type="radio" name="im" value="{$item.id}" {if $id_user_type && $item.id eq $id_user_type}selected{/if} id="user_type_{$smarty.foreach.user_type.iteration}" >
									{$item.name}
							</option>
						{/foreach}
				  </select>
			  </td>
		  </tr>
		  <tr>
			  <td style="padding-left: 0px;">
					{$lang.country.country}:
			  </td>
			  <td>
				<select name="id_country" style="width: 195px;" onchange="ChangeLocation(this);">
					<option value="0"></option>
					{foreach item=item from=$country}<option value="{$item.id}" {if $item.sel}selected{/if}>{$item.value}</option>{/foreach}
				</select>
			  </td>
		  </tr>
		  <tr>
			  <td style="padding-left: 0px;">
					{$lang.country.region}:
			  </td>
			  <td id="region_div" >
				  <select name="region" style="width: 195px;" onchange="ChangeLocation(this);">
					  <option value="0"></option>
						{foreach item=item from=$region}<option value="{$item.id}" {if $item.sel}selected{/if}>{$item.value}</option>{/foreach}
				  </select>
			  </td>
		  </tr>
		  <tr>
			  <td style="padding-left: 0px;">
					{$lang.country.city}:
			  </td>
			  <td id="city_div">
				  <select name="city" style="width: 195px;">
					  <option value="0"></option>
						{foreach item=item from=$city}<option value="{$item.id}" {if $item.sel}selected{/if}>{$item.value}</option>{/foreach}
				  </select>
			  </td>
		  </tr>
		  <tr>
			  <td style="padding-left: 0px;">
					{$lang.banners.age_min}:
			  </td>
			  <td >
				<select name="age_min" >
					<option value="0"></option>
					{foreach item=item from=$age_min}<option value="{$item}" {if $min_age_sel eq $item}selected{/if}>{$item}</option>{/foreach}
				</select>
			  </td>
		  </tr>
		  <tr>
			  <td style="padding-left: 0px;">
					{$lang.banners.age_max}:
			  </td>
			  <td >
				<select name="age_max" >
					<option value="0"></option>
					{foreach item=item from=$age_max}<option value="{$item}" {if $max_age_sel eq $item}selected{/if}>{$item}</option>{/foreach}
				</select>
			  </td>
		  </tr>
	  </table>
  </td>
</tr>

<tr class="even">
  <td class="main_content_text" align="left" valign="top">
    {$lang.banners.for_groups}:
  </td>
  <td>
    {foreach name=g from=$one_banner.groups item=item}
    <input type="checkbox" style="margin-left: 0px;margin-top:5px;margin-bottom:5px;" name="groups[]" value="{$item.id}" {if $is_add_mode}checked=checked{else}{$item.checked}{/if} /> {$item.name}<br />
    {/foreach}
  </td>
</tr>
<tr><td colspan="2" >
<table border=0 cellspacing=0 cellpadding=0 width="100%">
<tr class="table_header">
  <td colspan="2" class="main_header_text" align="left">
   {$lang.banners.banners_arrea}
  </td>
</tr>
{foreach from=$one_banner.areas item=tow_areas name=nam}
<tr {if $smarty.foreach.nam.iteration mod 2 eq 1}class="even"{else}class="odd"{/if}>
  <td class="main_content_text" align="left" width="50%">
   <input type="checkbox" style="margin-left: 0px;" class="area_all" name="area_{$tow_areas[0].id}" {if $tow_areas[0].checked eq 1} checked="checked" {/if} {if $tow_areas[0].enabled neq 1}disabled="disabled"{/if}>
   {* $tow_areas[0].description *}

   {assign var=tmp value=$tow_areas[0].description}
   {if $lang.banners[$tmp]}
	{$lang.banners[$tmp]}
   {else}
	{$tmp}
   {/if}
  </td>
  {if $tow_areas[1].id eq -1}
  <td class="main_content_text" align="left">
  </td>
  {else}
  <td class="main_content_text" align="left">
   <input type="checkbox" style="margin-left: 0px;" class="area_all" name="area_{$tow_areas[1].id}" {if $tow_areas[1].checked eq 1} checked="checked" {/if} {if $tow_areas[1].enabled neq 1}disabled="disabled"{/if}>
   {* $tow_areas[1].description *}
   
   {assign var=tmp value=$tow_areas[1].description}
   {if $lang.banners[$tmp]}
	{$lang.banners[$tmp]}
   {else}
	{$tmp}
   {/if}
  </td>
  {/if}
</tr>
{/foreach}
</table>
</td></tr><tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><a href="#" onclick="javascript: checkuncheckAll(1);">{$lang.button.checkall}</a>/<a href="#" onclick="javascript: checkuncheckAll(0);">{$lang.button.uncheckall}</a></td></tr>
<tr><td colspan="2" style="padding-top:15px;"><table>
<tr>
  <td class="main_content_text" align="right" width="100%">
  <a class="admin_button_major" onclick="SubmitMyForm();">{$lang.button.save}<span>&nbsp;</span></a>
{*  <a class="admin_button_cancel"  onclick="javascript:document.location='{$FILE_SELF}';">{$lang.button.vip_cancel}<span>&nbsp;</span></a>*}
  </td> 
</tr>
</table></tr></td>
</form>
</table>
<script>
{literal}
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode; // ���������� ������ ��������
};
function CheckFormAll(){
	var count = document.getElementsByClassName('area_all').length;
	for(i=0;i<count;i++){
		if (document.getElementsByClassName('area_all')[i].checked) return true;
	}
	return false;
}
 
function checkuncheckAll(ch){
	var count = document.getElementsByClassName('area_all').length;
	for(i=0;i<count;i++){
		if (document.getElementsByClassName('area_all')[i].disabled==false){
			switch (ch){
				case 0: document.getElementsByClassName('area_all')[i].checked=false; break;
				case 1:	document.getElementsByClassName('area_all')[i].checked=true; break;
			}
		}
	}
}
{/literal}
</script>
<script>
{literal}

function ChangeLocation(obj){
    if($(obj).attr('name') == 'id_country'){
	     SelectRegion($(obj).val(), document.getElementById('region_div'), document.getElementById('city_div'));
		 return 1;
    }
    if($(obj).attr('name') == 'region'){
	     SelectCity($(obj).val(), document.getElementById('city_div'));
		 return 1;
    }

}


function CheckForm()
{
  
  if (!document.forms[0].banner_name.value)
     {
      {/literal} 
      alert("{$lang.banners.enter_name|escape:javascript}.");
      {literal} 
      return 0;
     }
{/literal} 
  {if $edit_type eq "html" || $edit_type eq "js_code"}
{literal} 

{/literal} 
  {else}
{literal} 
  if (document.forms[0].stop_after_views_checked.checked)
     {
       if ((parseInt(document.forms[0].stop_after_views.value))<=0) 
          {
            {/literal} 
            alert("{$lang.banners.invalid_stop_after_views|escape:javascript}.");
            {literal} 
            return 0;
          }
     }
  if (document.forms[0].stop_after_views_checked.checked)
     {
       if ((parseInt(document.forms[0].stop_after_hits.value))<=0) 
          {
            {/literal} 
            alert("{$lang.banners.invalid_stop_after_hits|escape:javascript}.");
            {literal} 
            return 0;
          }
     }
{/literal}
  {/if}
{literal} 
  return 1;
}
function SubmitMyForm() 
{
  if (CheckForm()==1)
     {
       document.forms[0].submit();
     }
}  
function SetStatusStopByView(stat) 
{
  if (stat) 
     {
       document.forms[0].stop_after_views.disabled = false;
     }
     else
     {
       document.forms[0].stop_after_views.disabled = true;
     }
}  
function SetStatusStopByHits(stat) 
{
  if (stat) 
     {
       document.forms[0].stop_after_hits.disabled = false;
     }
     else
     {
       document.forms[0].stop_after_hits.disabled = true;
     }
}  
function SetStatusStopByDate(stat)
{
  if (stat) 
     {
       document.forms[0].b_day.disabled = false;
       document.forms[0].b_month.disabled = false;
       document.forms[0].b_year.disabled = false;

     }
     else
     {
       document.forms[0].b_day.disabled = true;
       document.forms[0].b_month.disabled = true;
       document.forms[0].b_year.disabled = true;
     }
};

function ChangeInputType()
{
{/literal}
  {if $is_add_mode eq "1"}
{literal} 
  document.forms[0].sel.value="add";
  document.forms[0].submit();
{/literal}
  {else}
{literal}
  document.forms[0].sel.value="edit";
  document.forms[0].submit();
{/literal}
  {/if}
{literal}
}

{/literal}
{$javascript}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}