{include file="header.tpl"}

<script type="text/javascript">
userAccounts = Array();
{section name=p loop=$paysystems}
userAccounts['{$paysystems[p].name}'] = '{$paysystems[p].account}';
{/section}

{literal}
function setDefAccount() {
  obj = document.refback.paysystem;
  objd = document.refback.psaccount;
  if (!obj) return;
  i = obj.selectedIndex; o = obj.options;
  n = o[i].value;
  if (userAccounts[n]) objd.value = userAccounts[n];
}
function checkRefBack()
{
  if (document.refback.email) {
    status = checkEmail(document.refback.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!');

      document.refback.email.focus();
      return false;
    }
  }

  if (!document.refback.username.value) {
    alert('Please enter you Program Username');
    document.refback.username.focus();
    return false;
  }

  if (!document.refback.amount.value) {
    alert('Please enter you Invested Amount');
    document.refback.amount.focus();
    return false;
  }

  if (!document.refback.account.value) {
    alert('Please enter you Payment System ID');
    document.refback.account.focus();
    return false;
  }

  return true;
}

{/literal}
var rcb = {$jsrcb};
var add_rcb_percent = {$add_rcb_percent|number_format:2};
var add_rcb_percent_next = {$add_rcb_percent_next|number_format:2};
{literal}

function calcRCB() {
  inv = parseFloat(document.getElementById('inv_amount').value);
  fst_amount = re_amount = 0.00;
  rrcb = {ref:0,fst_rcb:0,re_rcb:0,fst_bonus:0,re_bonus:0};
  if (!isNaN(inv)) {
    for (i in rcb) {
      r = rcb[i];
      if (r.min <= inv && (r.max == 0 || r.max >= inv)) {
        rrcb = r; break;
      }
    }
    if (rrcb) {
      fst_amount = inv * (rrcb.ref/100) * ((rrcb.fst_rcb+add_rcb_percent)/100) + rrcb.fst_bonus;
      re_amount = inv * (rrcb.ref/100) * ((rrcb.re_rcb+add_rcb_percent_next)/100) + rrcb.re_bonus;
    }
  }
  document.getElementById('fst_amount_quote').innerHTML = fst_amount.toFixed(2);
  document.getElementById('re_amount_quote').innerHTML = re_amount.toFixed(2);
}
{/literal}
</script>

{include file="program_details.tpl"}

{if $rcb}
<h3>{t}RCB Rates{/t}</h3>
{include file="rcb_table.tpl" rcbs=$rcb}
{/if}

<h3>{t}Referral Commission Back{/t}</h3>

{if $frm.display == 'sent'}
<div class="ok">{t}Thank you. Your request has been sent to administrator. You will receive commission back after admininstrator approve the request.{/t}</div>
{else}

{if $errors}
<ul class="error">
{if $errors.turing}<li> {t}Invalid turing image provided{/t}</li>{/if}
{if $errors.email}<li> {t}Please enter your E-mail address{/t}</li>{/if}
{if $errors.invalid_email}<li> {t}Please enter a valid E-mail address{/t}</li>{/if}
{if $errors.username}<li> {t}Please enter your program username{/t}</li>{/if}
{if $errors.account}<li> {t}Please enter your payment system account{/t}</li>{/if}
{if $errors.request_exists}{t}Request for this program and username already exists. Please be patient and wait till admin process your previus request{/t}{/if}
</ul>
{/if}

{if !$userinfo.logged}
<div class="message">{t signup_link="?a=signup"|encurl login_link="?a=login"|encurl}You can <a href="%signup_link">signup</a> and <a href="%login_link">login</a> into our site to track your refbacks{/t} {if $settings.registered_rcb_percent > 0}{t rcb=$settings.registered_rcb_percent|escape:html} and receive additional %rcb% RCB{/t}{/if}</div>
{/if}
<form method="post" onsubmit="return checkRefBack()" name="refback" action="">
<input type=hidden name=a value=refback>
<input type=hidden name=action value=send>
<input type=hidden name=lid value={$listing.id}>
<table class="form">
{if !$userinfo.logged}
<tr>
 <th>{t}Your E-mail:{/t}</th>
 <td><input type="text" name="email" value="{$frm.email|default:$userinfo.email|escape:html}"></td>
</tr>
{/if}
<tr>
 <th>{t}Program Username:{/t}</th>
 <td><input type="text" name="username" value="{$frm.username|default:$userinfo.username|escape:html}"></td>
</tr>
<tr>
 <th>{t}Invested Amount:{/t}</th>
 <td><input type="text" name="amount" value="{$frm.amount|escape:html}" id="inv_amount" onkeyup="calcRCB()" onmouseover="calcRCB()" onblur="calcRCB()"></td>
</tr>
<tr>
 <th>{t}RCB Quote{/t}</th>
 <td>
  {t}1st Deposit{/t}: $<span id="fst_amount_quote">0.00</span><br>
  {t}Re-Deposit{/t}: $<span id="re_amount_quote">0.00</span>
 </td>
</tr>
<tr>
 <th>{t}Deposit Payment System{/t}</th>
 <td>
   <select name="paysystem" onchange="setDefAccount()">
{section name=p loop=$paysystems}
   <option value="{$paysystems[p].name}" {if $paysystems[p].selected}selected{/if}>{$paysystems[p].name}</option>
{/section}
   </select>
 </td>
</tr>
<tr>
 <th>{t}Your Payment System ID{/t}</th>
 <td><input type="text" name="psaccount" value="{$frm.psaccount|escape:html}"></td>
</tr>
<tr>
 <th>{t}Your Comments{/t}</th>
 <td><textarea name="comments" cols=27 rows=4>{$frm.comments|escape:html}</textarea></td>
</tr>
{if $settings.use_turing}
<tr>
  <th><img src="{"?a=turing&`$sesname`=`$sesid`&r=`$rand`"|encurl}" alt="turing code"></th>
  <td><input type=text name="turing" maxlength=6 size=6></td>
</tr>
{/if}
<tr>
 <th></th>
 <td><input type="submit" value="{t}Submit{/t}" class=sbmt></td>
</tr>
</form>
</table>

{/if}

{if $rcbs}
<div class="details">
<h3>{t program=$listing.name|escape:html}RCB Requests for %program{/t} | {t}RCB Deposit:{/t} ${$totals.inv} | {t}RCB Paid:{/t} ${$totals.rcb}</h3>
<table class="list">
<tr>
 <th>{t}Date{/t}</th>
 <th>{t}User{/t}</th>
 <th>{t}Deposit/RCB{/t}</th>
 <th>{t}Account{/t}</th>
 <th>{t}Status{/t}</th>
</tr>
{foreach from=$rcbs item=r}
<tr class="{cycle values="row1,row2"}">
 <td>{$r.date}</td>
 <td>{$r.username}</td>
 <td>${$r.inv_amount|number_format:2}{if $r.rcb_amount}/${$r.rcb_amount|number_format:2}{/if}</td>
 <td><img src="{"`$theme`images/`$r.paysystem`.gif"|encurl}" alt="{$r.paysystem}"> {$r.psaccount}</td>
 <td>{if $r.status == 1}<b class="profit">{t}Paid{/t}</b>{elseif $r.status == 2}<b class="declined">{t}Declined{/t}</b>{else}<b class="spend">{t}Pending{/t}</b>{/if}</td>
</tr>
{/foreach}
</table>
</div>
{/if}

<script>
setDefAccount();
</script>

{include file="footer.tpl"}