{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};
{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)/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>RCB Rates</h3>
{include file="rcb_table.tpl" rcbs=$rcb}
{/if}

<h3>Referral Commission Back</h3>

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

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

{if !$userinfo.logged}
<div class="message">You can <a href="{"?a=signup"|encurl}">signup</a> and <a href="{"?a=login"|encurl}">login</a> into our site to {if $settings.registered_rcb_percent > 0} receive additional {$settings.registered_rcb_percent|escape:html}% RCB and{/if} track your refbacks.</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>Your E-mail</th>
 <td><input type="text" name="email" value="{$frm.email|default:$userinfo.email|escape:html}"></td>
</tr>
{/if}
<tr>
 <th>Program Username</th>
 <td><input type="text" name="username" value="{$frm.username|default:$userinfo.username|escape:html}"></td>
</tr>
<tr>
 <th>Invested Amount</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>RCB Quote</th>
 <td>
  1st deposit: $<span id="fst_amount_quote">0.00</span><br>
  Re-Deposit: $<span id="re_amount_quote">0.00</span>
 </td>
</tr>
<tr>
 <th>Deposit Payment System</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>Your Payment System ID</th>
 <td><input type="text" name="psaccount" value="{$frm.psaccount|escape:html}"></td>
</tr>
<tr>
 <th>Your Comments</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="Submit" class=sbmt></td>
</tr>
</form>
</table>

{/if}

{if $rcbs}
<div class="details">
<h3>RCB Requests for {$listing.name|escape:html}</h3>
<table class="list">
<tr>
 <th>Date</th>
 <th>User</th>
 <th>Deposit/RCB</th>
 <th>Account</th>
 <th>Status</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">Paid</b>{else}<b class="spend">Pending</b>{/if}</td>
</tr>
{/foreach}
</table>
</div>
{/if}

<script>
setDefAccount();
</script>

{include file="footer.tpl"}