<?php /* Smarty version 2.6.2, created on 2012-10-23 00:29:19
         compiled from buy_ads.tpl */ ?>
<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'encurl', 'buy_ads.tpl', 148, false),array('modifier', 'intval', 'buy_ads.tpl', 178, false),array('modifier', 'default', 'buy_ads.tpl', 211, false),array('modifier', 'escape', 'buy_ads.tpl', 228, false),)), $this); ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "header.tpl", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

<script type="text/javascript">
discounts = [
<?php if (isset($this->_sections['i'])) unset($this->_sections['i']);
$this->_sections['i']['loop'] = is_array($_loop=$this->_tpl_vars['discounts']) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$this->_sections['i']['name'] = 'i';
$this->_sections['i']['show'] = true;
$this->_sections['i']['max'] = $this->_sections['i']['loop'];
$this->_sections['i']['step'] = 1;
$this->_sections['i']['start'] = $this->_sections['i']['step'] > 0 ? 0 : $this->_sections['i']['loop']-1;
if ($this->_sections['i']['show']) {
    $this->_sections['i']['total'] = $this->_sections['i']['loop'];
    if ($this->_sections['i']['total'] == 0)
        $this->_sections['i']['show'] = false;
} else
    $this->_sections['i']['total'] = 0;
if ($this->_sections['i']['show']):

            for ($this->_sections['i']['index'] = $this->_sections['i']['start'], $this->_sections['i']['iteration'] = 1;
                 $this->_sections['i']['iteration'] <= $this->_sections['i']['total'];
                 $this->_sections['i']['index'] += $this->_sections['i']['step'], $this->_sections['i']['iteration']++):
$this->_sections['i']['rownum'] = $this->_sections['i']['iteration'];
$this->_sections['i']['index_prev'] = $this->_sections['i']['index'] - $this->_sections['i']['step'];
$this->_sections['i']['index_next'] = $this->_sections['i']['index'] + $this->_sections['i']['step'];
$this->_sections['i']['first']      = ($this->_sections['i']['iteration'] == 1);
$this->_sections['i']['last']       = ($this->_sections['i']['iteration'] == $this->_sections['i']['total']);
 echo '{'; ?>
"from":<?php echo $this->_tpl_vars['discounts'][$this->_sections['i']['index']]['from']; ?>
, "to":<?php echo $this->_tpl_vars['discounts'][$this->_sections['i']['index']]['to']; ?>
, "discount":<?php echo $this->_tpl_vars['discounts'][$this->_sections['i']['index']]['discount'];  echo '}';  if (! $this->_sections['i']['last']): ?>,<?php endif;  endfor; endif; ?>
];
<?php echo '
function chng_type(id) {
  mnu = document.getElementById(\'menu\');
  for (i = 1; i < 200; i++) {
    obj = document.getElementById(\'at_li_\'+i);
    if (obj) obj.className = \'\';
    obj = document.getElementById(\'form_\'+i);
    if (obj) obj.style.display = \'none\';
  }
  obj = document.getElementById(\'at_li_\'+id);
  obj.className = \'active\';
  obj = document.getElementById(\'form_\'+id);
  obj.style.display = \'\';

  calc_price();
}

function chng_price(price, tid) {
  mnu = document.getElementById(\'menu_\'+tid);
  for (i = 0; i < mnu.children.length; i++) {
    mnu.children[i].className = \'\';
  }
  obj = document.getElementById(\'pr_li_\'+tid+\'_\'+price);
  obj.className = \'active\';

  calc_price();
}

function calc_price() {
  type = _get_type();
  price = _calc_price(type);
  weeks = parseInt(document.getElementById(\'weeks_\'+type).value);
  discount = _get_discount(weeks);
  if (discount > 0) price = price * ((100-discount)/100);

  obj = document.getElementById(\'tprice_\'+type);
  if (obj) obj.innerHTML = price < 0 ? 0 : price;

  obj = document.getElementById(\'discount_\'+type);
  if (obj) obj.innerHTML = discount;
}

function _get_type() {
  type = 0;
  mnu = document.getElementById(\'menu\');
  inpts = mnu.getElementsByTagName(\'input\');
  for (i = 0; i < inpts.length; i++) {
    if (inpts[i].checked) {
      type = inpts[i].value; break;
    }
  }
  return type;
}
function _calc_price(type) {
  price = 0;

  mnu = document.getElementById(\'menu_\'+type);
  if (!mnu) {
    obj = document.getElementById(\'price_\'+type);
    if (obj) price = obj.innerHTML;
  } else {
    inpts = mnu.getElementsByTagName(\'input\');
    for (i = 0; i < inpts.length; i++) {
      if (inpts[i].checked) {
        price = inpts[i].value; break;
      }
    }
  }
  if (price == 0) return -1;

  weeks = parseInt(document.getElementById(\'weeks_\'+type).value);
  if (isNaN(weeks) || weeks < 1) return -2;

  return weeks * price;
}

function _get_discount(weeks) {
  discount = 0;
  for (i in discounts) {
    if (discounts[i].from <= weeks && (discounts[i].to >= weeks || discounts[i].to == 0)) {
      discount = discounts[i].discount;
    }
  }
  return discount;
}

function checkAds() {
  type = _get_type();
  if (!type) {
    alert(\'Please, select ads zone.\');
    return false;
  }
  price = _calc_price(type);
  if (price == -1) {
    alert(\'Please, choose ad place\');
    return false;
  }
  if (price == -2) {
    alert(\'Please, enter weeks period\');
    return false;
  }

  f = document.forms[\'ads_\'+type];                                                     
  if (f.url && !f.url.value.match(/^https?:\\/\\//)) {
     alert(\'Please, enter full destination URL\');
     return false;
  }

  if (f.banner_url && f.banner_url.value != \'\' && !f.banner_url.value.match(/^https?:\\/\\//)) {
     alert(\'Please, enter your banner full URL (starts with http://)\');
     return false;
  }

  if (f.banner_url && f.banner_url.value != \'\' && !f.banner_url.value.match(/^https?:\\/\\//)) {
     alert(\'Please, enter your banner full URL (starts with http://)\');
     return false;
  }

  if (f.email && f.email.value != \'\') {
    status = checkEmail(f.email.value);

    if (status > 0) {
      if (status == 1)
  	    alert(\'Please, enter your E-Mail address!\');
      if (status == 2)
  	    alert(\'Please, enter a valid E-Mail address!\');
      return false;
    }
  }

  return true;
}
</script>
'; ?>


<h3>Advertising</h3>
<div class="buy_ads">

<div class="menu_wrap clearfix">
<img src="<?php echo ((is_array($_tmp=($this->_tpl_vars['theme'])."images/buy_ads.png")) ? $this->_run_mod_handler('encurl', true, $_tmp) : smarty_modifier_encurl($_tmp)); ?>
" width="150">
<ul class="menu" id="menu">
<?php if (count($_from = (array)$this->_tpl_vars['bads'])):
    foreach ($_from as $this->_tpl_vars['tid'] => $this->_tpl_vars['atype']):
?>
 <li id="at_li_<?php echo $this->_tpl_vars['tid']; ?>
"><input type="radio" name="tid" value="<?php echo $this->_tpl_vars['tid']; ?>
" id="at_rd_<?php echo $this->_tpl_vars['tid']; ?>
" onclick="chng_type('<?php echo $this->_tpl_vars['tid']; ?>
')"><label for="at_rd_<?php echo $this->_tpl_vars['tid']; ?>
"><b><?php echo $this->_tpl_vars['tid']; ?>
</b>. <?php echo $this->_tpl_vars['atype']['name']; ?>
</label></li>
<?php endforeach; unset($_from); endif; ?>
</ul>
</div>

<?php if ($this->_tpl_vars['errors']): ?>
<ul class="error">
<?php if ($this->_tpl_vars['errors']['invalid_type']): ?><li> Please, choose correct ads type</li><?php endif;  if ($this->_tpl_vars['errors']['no_available_places']): ?><li> No avaliable places for this ads type</li><?php endif;  if ($this->_tpl_vars['errors']['invalid_period']): ?><li> Please, choose correct period</li><?php endif;  if ($this->_tpl_vars['errors']['invalid_listing']): ?><li> Please, select Program</li><?php endif; ?>
</ul>
<?php endif; ?>

<?php if (count($_from = (array)$this->_tpl_vars['bads'])):
    foreach ($_from as $this->_tpl_vars['tid'] => $this->_tpl_vars['atype']):
?>
<div class="<?php echo $this->_tpl_vars['atype']['type']; ?>
" id="form_<?php echo $this->_tpl_vars['tid']; ?>
" style="display: none;">
<h3 id="title_<?php echo $this->_tpl_vars['tid']; ?>
">Buy <?php echo $this->_tpl_vars['atype']['name']; ?>
</h3>
<?php if ($this->_tpl_vars['atype']['exp_date']): ?>
<div class="message">Sorry, all ad places are currently busy.<br>The closest one will be avaliable on <b><?php echo $this->_tpl_vars['atype']['exp_date']; ?>
</b> for <b>$<?php echo $this->_tpl_vars['atype']['exp_price']; ?>
</b>/week.</div>
<?php else: ?> <form name="ads_<?php echo $this->_tpl_vars['tid']; ?>
" method="post" onsubmit="return checkAds()" action="">
<input type="hidden" name="a" value="buy_ads">
<input type="hidden" name="action" value="preview">
<input type="hidden" name="tid" value="<?php echo $this->_tpl_vars['tid']; ?>
">
<table class="form">
<tr>
 <th>Available:</th>
 <td><?php if ($this->_tpl_vars['atype']['max_ads'] > 0): ?><b><?php echo ((is_array($_tmp=$this->_tpl_vars['atype']['available'])) ? $this->_run_mod_handler('intval', true, $_tmp) : intval($_tmp)); ?>
</b> of <b><?php echo $this->_tpl_vars['atype']['max_ads']; ?>
</b><?php else: ?><b>Unlimited</b><?php endif; ?> ad places</td>
</tr>
<?php if ($this->_tpl_vars['atype']['type'] == 'rotating'): ?>
<tr>
 <th>Price:</th>
 <td><b>$<span id="price_<?php echo $this->_tpl_vars['tid']; ?>
"><?php echo $this->_tpl_vars['atype']['price']; ?>
</span></b>/week</td>
</tr>
<?php else: ?>
<tr>
 <th>Ad Place:</th>
 <td>
<ul class="menu" id="menu_<?php echo $this->_tpl_vars['tid']; ?>
">
<?php if (count($_from = (array)$this->_tpl_vars['atype']['ads'])):
    foreach ($_from as $this->_tpl_vars['price'] => $this->_tpl_vars['p']):
?>
 <li id="pr_li_<?php echo $this->_tpl_vars['tid']; ?>
_<?php echo $this->_tpl_vars['price']; ?>
">
<?php if ($this->_tpl_vars['p']['type'] == 'default'): ?>
  <input type="radio" name="price" value="<?php echo $this->_tpl_vars['price']; ?>
" id="pr_rd_<?php echo $this->_tpl_vars['tid']; ?>
_<?php echo $this->_tpl_vars['price']; ?>
" <?php if ($this->_tpl_vars['price'] == $this->_tpl_vars['frm']['price']): ?>checked<?php endif; ?> onclick="chng_price('<?php echo $this->_tpl_vars['price']; ?>
', '<?php echo $this->_tpl_vars['tid']; ?>
')">
  <label for="pr_rd_<?php echo $this->_tpl_vars['tid']; ?>
_<?php echo $this->_tpl_vars['price']; ?>
">
   Available now for <b>$<?php echo $this->_tpl_vars['p']['price']; ?>
</b>/week
  </label>
<?php else: ?>
  <label for="pr_rd_<?php echo $this->_tpl_vars['tid']; ?>
_<?php echo $this->_tpl_vars['price']; ?>
">
   Available on <b><?php echo $this->_tpl_vars['p']['exp_date']; ?>
</b> for <b>$<?php echo $this->_tpl_vars['p']['price']; ?>
</b>/week
  </label>
<?php endif; ?>
 </li>
<?php endforeach; unset($_from); endif; ?>
</ul>
 </td>
</tr>
<?php endif; ?>

<tr>
 <th>Period:</th>
 <td><input type="text" name="period" value="<?php echo ((is_array($_tmp=((is_array($_tmp=$this->_tpl_vars['frm']['period'])) ? $this->_run_mod_handler('intval', true, $_tmp) : intval($_tmp)))) ? $this->_run_mod_handler('default', true, $_tmp, 1) : smarty_modifier_default($_tmp, 1)); ?>
" style="width: 50px;" id="weeks_<?php echo $this->_tpl_vars['tid']; ?>
" onkeyup="calc_price()"> weeks</td>
</tr>
<?php if ($this->_tpl_vars['discounts']): ?>
<tr>
 <th>Discount:</th>
 <td><b id="discount_<?php echo $this->_tpl_vars['tid']; ?>
">0</b>%</td>
</tr>
<?php endif; ?>


<?php if ($this->_tpl_vars['atype']['type'] == 'listings'): ?>

<tr>
 <th>Program:</th>
 <td>
  <select name="listing_id">
<?php if (count($_from = (array)$this->_tpl_vars['blistings'])):
    foreach ($_from as $this->_tpl_vars['l']):
?>
<option value="<?php echo $this->_tpl_vars['l']['id']; ?>
"><?php echo ((is_array($_tmp=$this->_tpl_vars['l']['name'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
</option>
<?php endforeach; unset($_from); endif; ?>
  </select>
 </td>
</tr>

<?php else: ?> 
<tr>
 <th>Destination URL:</th>
 <td><input type="text" name="url" value="<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['url'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
"></td>
</tr>
<tr>
 <th>Banner URL:</th>
 <td><input type="text" name="banner_url" value="<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['banner_url'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
"></td>
</tr>
<tr>
 <th>Titile:</th>
 <td><input type="text" name="title" maxlength=80 value="<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['title'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
"></td>
</tr>
<tr>
 <th>Text:</th>
 <td><input type="text" name="text" maxlength=120 value="<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['text'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
"></td>
</tr>

<?php endif; ?>  
<tr>
 <th>Contact E-Mail:</th>
 <td><input type="text" name="email" value="<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['email'])) ? $this->_run_mod_handler('escape', true, $_tmp, 'html') : smarty_modifier_escape($_tmp, 'html')); ?>
"></td>
</tr>
<tr>
 <th>Total Price:</th>
 <td><b>$<span id="tprice_<?php echo $this->_tpl_vars['tid']; ?>
"></span></b></td>
</tr>
<tr>
 <th></th>
 <td><input type=submit value="Preview"></td>
</tr>
</table>
</form>
<?php endif; ?> </div>

<?php endforeach; unset($_from); endif; ?>

</div> 
<?php if ($this->_tpl_vars['frm']['tid']): ?>
<script type="text/javascript">
tid = parseInt('<?php echo ((is_array($_tmp=$this->_tpl_vars['frm']['tid'])) ? $this->_run_mod_handler('intval', true, $_tmp) : intval($_tmp)); ?>
');
<?php echo '
if (obj = document.getElementById(\'at_rd_\'+tid)) {
 obj.checked = true;
 chng_type(tid);
}
'; ?>

</script>
<?php endif;  $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "footer.tpl", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>