<?php
/**
 * ChainPay Payment Page v1.0.3
 * FULLY SELF-CONTAINED — no wp_head/wp_footer = zero theme CSS conflicts.
 * All CSS, JS and QRCode library are inline. Nothing external loaded.
 */
defined( 'ABSPATH' ) || exit;

/* ── Validate & load all data BEFORE any HTML output ─────── */
$cp_oid   = isset( $_GET['order_id'] )  ? absint( $_GET['order_id'] )                      : 0;
$cp_okey  = isset( $_GET['order_key'] ) ? sanitize_text_field( wp_unslash( $_GET['order_key'] ) ) : '';
$cp_order = $cp_oid ? wc_get_order( $cp_oid ) : null;

if ( ! $cp_order || ! hash_equals( $cp_order->get_order_key(), $cp_okey ) ) {
    wp_die( esc_html__( 'Invalid payment link.', 'chainpay' ), 'ChainPay', array( 'response' => 404 ) );
}

/* ── Settings ─────────────────────────────────────────────── */
$cp_timeout    = (int)    get_option( 'chainpay_invoice_timeout', 15 );
$cp_show_qr    = 'yes' === get_option( 'chainpay_show_qr',    'yes' );
$cp_show_timer = 'yes' === get_option( 'chainpay_show_timer', 'yes' );
$cp_show_rate  = 'yes' === get_option( 'chainpay_show_rate',  'yes' );
$cp_show_fee   = 'yes' === get_option( 'chainpay_show_fee',   'yes' );

/* ── JS config built server-side ──────────────────────────── */
$cp_coins    = ChainPay_Price_Feed::get_routed_coins();
$cp_all      = ChainPay_Coin_Registry::all();
$cp_free     = array_keys( ChainPay_Coin_Registry::free_coins() );
$cp_has_lic  = ChainPay_License::is_active();
$cp_first    = ! empty( $cp_coins ) ? (string) array_keys( $cp_coins )[0] : 'BTC';
$cp_store    = get_bloginfo( 'name' );
$cp_order_no = $cp_order->get_order_number();

$cp_cfg = wp_json_encode( array(
    'ajax_url'    => admin_url( 'admin-ajax.php' ),
    'nonce'       => wp_create_nonce( 'chainpay_nonce' ),
    'order_id'    => $cp_oid,
    'order_key'   => $cp_okey,
    'coins'       => $cp_coins,
    'all_coins'   => $cp_all,
    'free_coins'  => $cp_free,
    'has_license' => $cp_has_lic,
    'first_coin'  => $cp_first,
    'license_url' => 'https://chainpay.store/pricing',
    'store_name'  => $cp_store,
    'timeout_min' => $cp_timeout,
    'show_qr'     => $cp_show_qr,
    'show_timer'  => $cp_show_timer,
    'show_rate'   => $cp_show_rate,
    'show_fee'    => $cp_show_fee,
) );

/* ── HTTP headers ─────────────────────────────────────────── */
header( 'Content-Type: text/html; charset=UTF-8' );
header( 'X-Frame-Options: SAMEORIGIN' );
header( 'X-Content-Type-Options: nosniff' );
header( 'Cache-Control: no-cache, no-store, must-revalidate' );
?><!DOCTYPE html>
<html lang="<?php echo esc_attr( get_locale() ); ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="robots" content="noindex,nofollow">
<meta name="theme-color" content="#0b1020">
<title><?php echo esc_html( $cp_store ); ?> — Pay with Crypto</title>
<style>
/* ── HARD RESET — overrides ANY theme CSS that may have loaded ── */
*,*::before,*::after{all:unset;box-sizing:border-box !important;}
html{height:100%;-webkit-text-size-adjust:100%;font-size:16px;}
body{
  display:flex !important;
  min-height:100vh !important;
  width:100% !important;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif !important;
  font-size:15px !important;
  line-height:1.5 !important;
  color:#111 !important;
  background:#0b1020 !important;
  align-items:center !important;
  justify-content:center !important;
  padding:16px !important;
  -webkit-font-smoothing:antialiased;
  box-sizing:border-box !important;
  position:relative !important;
}

/* Background */
body::before{
  content:'';position:fixed;inset:0;z-index:0;
  background:
    radial-gradient(ellipse 800px 500px at 80% 0%,rgba(255,107,43,.13) 0%,transparent 70%),
    radial-gradient(ellipse 600px 400px at 10% 90%,rgba(37,99,235,.09) 0%,transparent 70%),
    linear-gradient(145deg,#080d1a 0%,#0f1628 60%,#080d1a 100%);
}

/* ── CARD ──────────────────────────────────────────────────── */
.cp-card{
  position:relative;z-index:1;
  width:100%;max-width:400px;
  background:#fff;
  border-radius:20px;
  overflow:hidden;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.07),
    0 32px 64px rgba(0,0,0,.6),
    0 8px 24px rgba(0,0,0,.3);
}

/* ── STATUS BAR ────────────────────────────────────────────── */
.cp-sb{
  display:flex;align-items:center;gap:10px;
  padding:11px 16px;min-height:44px;
  background:#14213d;
  transition:background .35s;
}
.cp-sb.s-detected {background:#1a3060;}
.cp-sb.s-confirmed{background:#0a3020;}
.cp-sb.s-expired  {background:#2d1010;}

.cp-spin{
  width:14px;height:14px;flex-shrink:0;
  border:2px solid rgba(255,255,255,.15);
  border-top-color:#4ade80;border-radius:50%;
  animation:cp-rotate .75s linear infinite;
}
.cp-spin.off{opacity:0;pointer-events:none;}
@keyframes cp-rotate{to{transform:rotate(360deg);}}

.cp-sb-msg{flex:1;font-size:12px;font-weight:700;color:#fff;letter-spacing:.1px;}
.cp-sb-tmr{font-family:'Courier New',Courier,monospace;font-size:13px;font-weight:700;color:#4ade80;}
.cp-sb-tmr.warn{color:#fbbf24;}
.cp-sb-tmr.crit{color:#f87171;animation:cp-blink 1s step-end infinite;}
@keyframes cp-blink{50%{opacity:.3;}}

/* ── MERCHANT ROW ──────────────────────────────────────────── */
.cp-merch{
  display:flex;align-items:center;justify-content:space-between;
  padding:13px 16px 11px;
  border-bottom:1px solid #f0f0f0;background:#fff;
}
.cp-store{font-size:13px;font-weight:800;color:#111;display:block;margin-bottom:1px;}
.cp-onum {font-size:11px;color:#bbb;display:block;}
.cp-amt-box{text-align:right;}
.cp-amt{font-size:17px;font-weight:900;color:#111;font-family:'Courier New',Courier,monospace;line-height:1.2;display:block;}
.cp-rate{font-size:10px;color:#bbb;display:block;margin-top:2px;}

/* ── COIN SELECTOR ─────────────────────────────────────────── */
.cp-csel{
  display:flex;align-items:center;gap:10px;
  padding:11px 16px;border-bottom:1px solid #f0f0f0;
  cursor:pointer;background:#fff;
  transition:background .12s;
  user-select:none;-webkit-tap-highlight-color:transparent;
}
.cp-csel:hover{background:#fafafa;}
.cp-csel:active{background:#f5f5f5;}
.cp-cdot{
  width:32px;height:32px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-size:15px;font-weight:900;color:#fff;
}
.cp-cinfo{flex:1;min-width:0;}
.cp-cname{font-size:13px;font-weight:700;color:#111;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.cp-cnet {font-size:10px;color:#bbb;display:block;margin-top:1px;}
.cp-csel-r{display:flex;align-items:center;gap:6px;flex-shrink:0;}
.cp-cchg{font-size:11px;color:#bbb;}
.cp-carr{font-size:14px;color:#ccc;transition:transform .2s;display:inline-block;}

/* ── STATE OVERLAYS ────────────────────────────────────────── */
.cp-state{
  display:none;flex-direction:column;align-items:center;
  justify-content:center;padding:40px 20px;text-align:center;
}
.cp-state.show{display:flex;}
.cp-state-ico  {font-size:52px;line-height:1;display:block;margin-bottom:14px;}
.cp-state-title{font-size:18px;font-weight:800;color:#111;display:block;margin-bottom:8px;}
.cp-state-sub  {font-size:13px;color:#888;line-height:1.6;display:block;}

/* ── TABS ──────────────────────────────────────────────────── */
.cp-tabs{
  display:flex;padding:0 16px;
  border-bottom:1px solid #f0f0f0;background:#fff;
}
.cp-tab{
  flex:1;padding:11px 0;
  font-size:12px;font-weight:800;
  background:none;border:none;border-bottom:2px solid transparent;
  color:#bbb;cursor:pointer;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  transition:all .15s;margin-bottom:-1px;
  outline:none;-webkit-tap-highlight-color:transparent;
}
.cp-tab.on{color:#111;border-bottom-color:#4ade80;}
.cp-tab:hover:not(.on){color:#555;}

/* ── PANES ─────────────────────────────────────────────────── */
.cp-pane{display:none;padding:16px;}
.cp-pane.on{display:block;}

/* ── QR ────────────────────────────────────────────────────── */
.cp-qr-box{
  position:relative;width:180px;height:180px;
  margin:0 auto 14px;
  background:#fff;padding:7px;
  border-radius:14px;border:1.5px solid #efefef;
  display:flex;align-items:center;justify-content:center;
}
#cp-qr-canvas{width:166px;height:166px;display:flex;align-items:center;justify-content:center;}
#cp-qr-canvas canvas{width:100% !important;height:100% !important;display:block !important;}
#cp-qr-canvas img  {width:100% !important;height:100% !important;display:block !important;}
.cp-qr-lbl{font-size:11px;color:#bbb;text-align:center;padding:16px 0;}
.cp-qr-coin{
  position:absolute;bottom:4px;right:4px;
  width:34px;height:34px;border-radius:50%;
  border:3px solid #fff;
  display:flex;align-items:center;justify-content:center;
  font-size:14px;font-weight:900;color:#fff;
  box-shadow:0 2px 8px rgba(0,0,0,.2);
}
.cp-wallet{
  display:flex;align-items:center;justify-content:center;gap:7px;
  width:100%;padding:12px;border-radius:12px;
  background:#4ade80;color:#052e16;
  font-size:13px;font-weight:800;
  text-decoration:none;border:none;cursor:pointer;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  transition:background .15s,transform .15s;
  box-shadow:0 4px 14px rgba(74,222,128,.3);
  outline:none;
}
.cp-wallet:hover{background:#22c55e;transform:translateY(-1px);}
.cp-wallet:active{transform:none;}

/* ── COPY PANE ─────────────────────────────────────────────── */
.cp-ci{margin-bottom:12px;}
.cp-cl{font-size:9px;font-weight:800;text-transform:uppercase;letter-spacing:.8px;color:#bbb;display:block;margin-bottom:4px;}
.cp-crow{
  display:flex;align-items:center;gap:7px;
  background:#f8f8f8;border:1px solid #eee;
  border-radius:9px;padding:9px 11px;
}
.cp-cv{
  flex:1;font-family:'Courier New',Courier,monospace;font-size:11px;
  color:#111;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  display:block;
}
.cp-cb{
  flex-shrink:0;
  background:#e8f5e9;color:#2e7d32;
  border:none;border-radius:6px;
  padding:4px 10px;font-size:10px;font-weight:800;
  cursor:pointer;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  transition:all .12s;outline:none;
  -webkit-tap-highlight-color:transparent;
}
.cp-cb:hover,.cp-cb.done{background:#2e7d32;color:#fff;}
.cp-sep{
  display:flex;align-items:center;gap:8px;
  margin:4px 0;color:#e0e0e0;font-size:11px;
}
.cp-sep::before,.cp-sep::after{content:'';flex:1;height:1px;background:#f0f0f0;display:block;}

/* ── FOOTER ────────────────────────────────────────────────── */
.cp-foot{
  border-top:1px solid #f5f5f5;
  padding:9px 16px 12px;text-align:center;background:#fff;
}
.cp-fee{font-size:10px;color:#bbb;display:flex;align-items:center;justify-content:center;gap:4px;}
.cp-fee-val{font-weight:700;color:#999;}
.cp-pow{font-size:9px;color:#ddd;margin-top:5px;display:block;}
.cp-pow a{color:inherit;text-decoration:none;}
.cp-pow a:hover{color:#aaa;text-decoration:underline;}

/* ── COIN BOTTOM SHEET ─────────────────────────────────────── */
.cp-sheet-bg{
  position:fixed;inset:0;z-index:9000;
  background:rgba(0,0,0,0);pointer-events:none;
  transition:background .25s;
}
.cp-sheet-bg.open{background:rgba(0,0,0,.55);pointer-events:all;}
.cp-sheet{
  position:fixed;bottom:0;left:0;right:0;z-index:9001;
  background:#fff;border-radius:22px 22px 0 0;
  max-height:78vh;overflow-y:auto;
  transform:translateY(100%);
  transition:transform .3s cubic-bezier(.32,.72,0,1);
  overscroll-behavior:contain;
}
.cp-sheet.open{transform:translateY(0);}
.cp-sh-handle{width:36px;height:4px;background:#e0e0e0;border-radius:2px;margin:10px auto 0;display:block;}
.cp-sh-hd{font-size:13px;font-weight:800;color:#111;display:block;padding:12px 16px 10px;border-bottom:1px solid #f0f0f0;}
.cp-sh-row{
  display:flex;align-items:center;gap:12px;padding:12px 16px;
  cursor:pointer;transition:background .1s;
  -webkit-tap-highlight-color:transparent;
}
.cp-sh-row:hover{background:#fafafa;}
.cp-sh-row.sel{background:#f0fdf4;}
.cp-sh-row.lkd{opacity:.65;}
.cp-sh-dot{
  width:36px;height:36px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:16px;font-weight:900;color:#fff;flex-shrink:0;
}
.cp-sh-info{flex:1;min-width:0;}
.cp-sh-name{font-size:13px;font-weight:700;color:#111;display:block;}
.cp-sh-sym {font-size:10px;color:#bbb;display:block;margin-top:1px;}
.cp-sh-lkd{
  background:#fff7ed;color:#c2410c;
  border-radius:20px;padding:3px 9px;font-size:10px;font-weight:800;
}
.cp-sh-chk{color:#4ade80;font-size:14px;font-weight:900;}

/* ── LICENSE MODAL ─────────────────────────────────────────── */
.cp-modal-bg{
  position:fixed;inset:0;z-index:9500;
  background:rgba(0,0,0,0);pointer-events:none;
  display:flex;align-items:center;justify-content:center;padding:20px;
  transition:background .2s;
}
.cp-modal-bg.open{background:rgba(0,0,0,.65);pointer-events:all;}
.cp-modal{
  background:#fff;border-radius:20px;max-width:300px;width:100%;
  padding:26px 22px;text-align:center;
  transform:scale(.9) translateY(20px);opacity:0;
  transition:transform .25s,opacity .25s;
}
.cp-modal-bg.open .cp-modal{transform:scale(1) translateY(0);opacity:1;}
.cp-modal-ico  {font-size:42px;display:block;margin-bottom:10px;line-height:1;}
.cp-modal-title{font-size:17px;font-weight:800;color:#111;display:block;margin-bottom:6px;}
.cp-modal-desc {font-size:13px;color:#666;line-height:1.6;display:block;margin-bottom:16px;}
.cp-modal-cta{
  display:block;background:#f7931a;color:#fff;
  border-radius:10px;padding:11px;font-size:13px;font-weight:800;
  text-decoration:none;margin-bottom:8px;transition:background .15s;
}
.cp-modal-cta:hover{background:#e07d0f;color:#fff;}
.cp-modal-skip{
  display:block;background:none;border:none;color:#bbb;font-size:12px;
  cursor:pointer;width:100%;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  outline:none;
}
.cp-modal-skip:hover{color:#555;}

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media(max-width:440px){
  body{padding:0 !important;align-items:flex-end !important;}
  .cp-card{border-radius:18px 18px 0 0;max-width:100%;}
}
</style>
</head>
<body>

<div class="cp-card" id="cpCard">

  <!-- STATUS BAR -->
  <div class="cp-sb" id="cpSb">
    <div class="cp-spin" id="cpSpin"></div>
    <div class="cp-sb-msg" id="cpMsg">Awaiting Payment&hellip;</div>
    <?php if ( $cp_show_timer ) : ?>
    <div class="cp-sb-tmr" id="cpTmr"><?php echo esc_html( sprintf( '%02d:00', $cp_timeout ) ); ?></div>
    <?php endif; ?>
  </div>

  <!-- MERCHANT ROW -->
  <div class="cp-merch">
    <div>
      <span class="cp-store"><?php echo esc_html( $cp_store ); ?></span>
      <span class="cp-onum">Order #<?php echo esc_html( $cp_order_no ); ?></span>
    </div>
    <div class="cp-amt-box">
      <span class="cp-amt" id="cpAmt">&mdash;</span>
      <?php if ( $cp_show_rate ) : ?><span class="cp-rate" id="cpRate"></span><?php endif; ?>
    </div>
  </div>

  <!-- COIN SELECTOR -->
  <div class="cp-csel" id="cpCsel" role="button" tabindex="0" onclick="cpOpenSheet()" onkeydown="if(event.key==='Enter')cpOpenSheet()">
    <div class="cp-cdot" id="cpCdot" style="background:#f7931a;">&#8383;</div>
    <div class="cp-cinfo">
      <span class="cp-cname" id="cpCname">Loading&hellip;</span>
      <span class="cp-cnet"  id="cpCnet"></span>
    </div>
    <div class="cp-csel-r">
      <span class="cp-cchg">Change</span>
      <span class="cp-carr" id="cpCarr">&#8964;</span>
    </div>
  </div>

  <!-- CONFIRMED STATE -->
  <div class="cp-state" id="cpStOk">
    <span class="cp-state-ico">&#9989;</span>
    <span class="cp-state-title">Payment Confirmed!</span>
    <span class="cp-state-sub">Your order is being processed.<br>Redirecting you&hellip;</span>
  </div>

  <!-- EXPIRED STATE -->
  <div class="cp-state" id="cpStExp">
    <span class="cp-state-ico">&#9203;</span>
    <span class="cp-state-title">Invoice Expired</span>
    <span class="cp-state-sub">This payment window has closed.<br>Please place a new order.</span>
  </div>

  <!-- MAIN CONTENT -->
  <div id="cpMain">

    <?php if ( $cp_show_qr ) : ?>
    <div class="cp-tabs">
      <button class="cp-tab on" onclick="cpTab('scan',this)">&#128247; Scan QR</button>
      <button class="cp-tab"   onclick="cpTab('copy',this)">&#128203; Copy</button>
    </div>
    <?php endif; ?>

    <!-- SCAN PANE -->
    <?php if ( $cp_show_qr ) : ?>
    <div class="cp-pane on" id="cpPaneScan">
      <div class="cp-qr-box">
        <div id="cp-qr-canvas"><div class="cp-qr-lbl">Generating&hellip;</div></div>
        <div class="cp-qr-coin" id="cpQrCoin" style="background:#f7931a;">&#8383;</div>
      </div>
      <a href="#" class="cp-wallet" id="cpWallet">&#128275; Open in Wallet</a>
    </div>
    <?php endif; ?>

    <!-- COPY PANE -->
    <div class="cp-pane<?php echo ! $cp_show_qr ? ' on' : ''; ?>" id="cpPaneCopy">
      <div class="cp-ci">
        <span class="cp-cl">Amount</span>
        <div class="cp-crow">
          <span class="cp-cv" id="cpCvAmt">&mdash;</span>
          <button class="cp-cb" onclick="cpCopy('cpCvAmt',this)">Copy</button>
        </div>
      </div>
      <div class="cp-sep">&#9670;</div>
      <div class="cp-ci">
        <span class="cp-cl">Address</span>
        <div class="cp-crow">
          <span class="cp-cv" id="cpCvAddr">&mdash;</span>
          <button class="cp-cb" onclick="cpCopy('cpCvAddr',this)">Copy</button>
        </div>
      </div>
      <div class="cp-sep">&#9670;</div>
      <div class="cp-ci">
        <span class="cp-cl">Payment Link</span>
        <div class="cp-crow">
          <span class="cp-cv" id="cpCvLink">&mdash;</span>
          <button class="cp-cb" onclick="cpCopy('cpCvLink',this)">Copy</button>
        </div>
      </div>
    </div>

  </div><!-- /cpMain -->

  <?php if ( $cp_show_fee ) : ?>
  <div class="cp-foot">
    <div class="cp-fee">Rec. fee:&nbsp;<span class="cp-fee-val" id="cpFee">&mdash;</span></div>
    <span class="cp-pow">Secured by <a href="https://chainpay.store" target="_blank" rel="noopener">chainpay.store</a></span>
  </div>
  <?php endif; ?>

</div><!-- /cpCard -->

<!-- COIN SHEET -->
<div class="cp-sheet-bg" id="cpShBg" onclick="cpCloseSheet()">
  <div class="cp-sheet" id="cpSheet" onclick="event.stopPropagation()">
    <span class="cp-sh-handle"></span>
    <span class="cp-sh-hd">Select Currency</span>
    <div id="cpShList"></div>
  </div>
</div>

<!-- LICENSE MODAL -->
<div class="cp-modal-bg" id="cpModalBg" onclick="if(event.target===this)cpCloseModal()">
  <div class="cp-modal">
    <span class="cp-modal-ico">&#128274;</span>
    <span class="cp-modal-title">Pro License Required</span>
    <span class="cp-modal-desc">Unlock all <strong>14 cryptocurrencies</strong> for just <strong>$49/year</strong>. Bitcoin &amp; Litecoin are always free.</span>
    <a class="cp-modal-cta" href="https://chainpay.store/pricing" target="_blank" rel="noopener">Get Pro License &rarr;</a>
    <button class="cp-modal-skip" onclick="cpCloseModal()">Continue with free coins</button>
  </div>
</div>

<!-- INLINE QR CODE LIBRARY (no external dependency) -->
<script>
!function(){var a=function(a){this.mode=4,this.data=a,this.parsedData=[];for(var b=[],c=0,d=this.data.length;d>c;c++){var e=this.data.charCodeAt(c);e>65536?(b[0]=240|(1835008&e)>>>18,b[1]=128|(258048&e)>>>12,b[2]=128|(4032&e)>>>6,b[3]=128|63&e):e>2048?(b[0]=224|(61440&e)>>>12,b[1]=128|(4032&e)>>>6,b[2]=128|63&e):e>128?(b[0]=192|(1984&e)>>>6,b[1]=128|63&e):b[0]=e,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))},b=function(a,b){this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]},c={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},d={L:1,M:0,Q:3,H:2},e={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},f={POSITION_DETECTION_PATTERN:[[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,1,1,1,0,1],[1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(a){for(var b=a<<10;f.getBCHDigit(b)-f.getBCHDigit(f.G15)>=0;)b^=f.G15<<f.getBCHDigit(b)-f.getBCHDigit(f.G15);return(a<<10|b)^f.G15_MASK},getBCHTypeNumber:function(a){for(var b=a<<12;f.getBCHDigit(b)-f.getBCHDigit(f.G18)>=0;)b^=f.G18<<f.getBCHDigit(b)-f.getBCHDigit(f.G18);return a<<12|b},getBCHDigit:function(a){for(var b=0;0!=a;)b++,a>>>=1;return b},getPatternPosition:function(a){return g[a-1]},getMask:function(a,b,c){switch(a){case e.PATTERN000:return(b+c)%2==0;case e.PATTERN001:return b%2==0;case e.PATTERN010:return c%3==0;case e.PATTERN011:return(b+c)%3==0;case e.PATTERN100:return(Math.floor(b/2)+Math.floor(c/3))%2==0;case e.PATTERN101:return b*c%2+b*c%3==0;case e.PATTERN110:return(b*c%2+b*c%3)%2==0;case e.PATTERN111:return(b*c%3+(b+c)%2)%2==0}},getErrorCorrectPolynomial:function(a){for(var b=new i([1],0),c=0;a>c;c++)b=b.multiply(new i([1,h.gexp(c)],0));return b},getLengthInBits:function(a,b){if(b>=1&&10>b)switch(a){case 1:return 10;case 2:return 9;case 4:return 8;case 8:return 8}else if(27>b)switch(a){case 1:return 12;case 2:return 11;case 4:return 16;case 8:return 10}else if(41>b)switch(a){case 1:return 14;case 2:return 13;case 4:return 16;case 8:return 12}},getLostPoint:function(a){for(var b=a.getModuleCount(),c=0,d=0;b>d;d++){for(var e=0;b>e;e++){for(var f=0,g=a.isDark(d,e),h=-1;1>=h;h++)if(!(0>d+h||d+h>=b))for(var i=-1;1>=i;i++)0>e+i||e+i>=b||0==h&&0==i||(g==a.isDark(d+h,e+i)&&f++);f>5&&(c+=3+f-5)}for(var e=0;b-1>e;e++){var j=0;a.isDark(d,e)&&j++,a.isDark(d,e+1)&&j++,a.isDark(d+1,e)&&j++,a.isDark(d+1,e+1)&&j++,(0==j||4==j)&&(c+=3)}}for(var e=0;b>e;e++)for(var d=0;b-6>d;d++){a.isDark(d,e)&&!a.isDark(d+1,e)&&a.isDark(d+2,e)&&a.isDark(d+3,e)&&a.isDark(d+4,e)&&!a.isDark(d+5,e)&&a.isDark(d+6,e)&&(c+=40),a.isDark(e,d)&&!a.isDark(e,d+1)&&a.isDark(e,d+2)&&a.isDark(e,d+3)&&a.isDark(e,d+4)&&!a.isDark(e,d+5)&&a.isDark(e,d+6)&&(c+=40)}for(var g=0,d=0;b>d;d++)for(var e=0;b>e;e++)a.isDark(d,e)&&g++;return c+=10*Math.abs(100*g/b/b-50)/5}},g=[[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],h={glog:function(a){if(1>a)throw new Error("glog("+a+")");return h.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;a>=256;)a-=255;return h.EXP_TABLE[a]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},i=function(){},j=function(){};a.prototype={getLength:function(){return this.parsedData.length},write:function(a){for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={addData:function(b){this.dataList.push(new a(b)),this.dataCache=null},isDark:function(a,b){if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;this.moduleCount>d;d++){this.modules[d]=new Array(this.moduleCount);for(var e=0;this.moduleCount>e;e++)this.modules[d][e]=null}this.setupPositionDetectionPattern(0,0),this.setupPositionDetectionPattern(this.moduleCount-7,0),this.setupPositionDetectionPattern(0,this.moduleCount-7),this.setupPositionAlignmentPattern(),this.setupTimingPattern(),this.setupTypeInfo(a,c),this.typeNumber>=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionDetectionPattern:function(a,b){for(var c=0;7>c;c++)for(var d=0;7>d;d++)this.modules[a+c][b+d]=f.POSITION_DETECTION_PATTERN[c][d]},setupTimingPattern:function(){for(var a=8;this.moduleCount-8>a;a++)null==this.modules[a][6]&&(this.modules[a][6]=a%2==0);for(var b=8;this.moduleCount-8>b;b++)null==this.modules[6][b]&&(this.modules[6][b]=b%2==0)},setupPositionAlignmentPattern:function(){for(var a=f.getPatternPosition(this.typeNumber),b=0;a.length>b;b++)for(var c=0;a.length>c;c++){var d=a[b],e=a[c];if(null==this.modules[d][e])for(var g=-2;2>=g;g++)for(var h=-2;2>=h;h++)-2==g||2==g||-2==h||2==h||0==g&&0==h?this.modules[d+g][e+h]=!0:this.modules[d+g][e+h]=!1}},setupTypeNumber:function(a){for(var b=f.getBCHTypeNumber(this.typeNumber),c=0;18>c;c++){var d=!a&&1==(b>>c&1);this.modules[Math.floor(c/3)][c%3+this.moduleCount-8-3]=d}for(var c=0;18>c;c++){var d=!a&&1==(b>>c&1);this.modules[c%3+this.moduleCount-8-3][Math.floor(c/3)]=d}},setupTypeInfo:function(a,b){for(var c=f.getBCHTypeInfo(this.errorCorrectLevel<<3|b),d=0;15>d;d++){var e=!a&&1==(c>>d&1);6>d?this.modules[d][8]=e:8>d?this.modules[d+1][8]=e:this.modules[this.moduleCount-15+d][8]=e}for(var d=0;15>d;d++){var e=!a&&1==(c>>d&1);8>d?this.modules[8][this.moduleCount-d-1]=e:9>d?this.modules[8][15-d-1+1]=e:this.modules[8][15-d-1]=e}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,b){for(var c=-1,d=this.moduleCount-1,e=7,g=0,h=this.moduleCount-1;h>0;h-=2)for(6==h&&h--;;){for(var i=0;2>i;i++)if(null==this.modules[d][h-i]){var j=!1;g<a.length&&(j=1==(a[g]>>>e&1)),f.getMask(b,d,h-i)&&(j=!j),this.modules[d][h-i]=j,e--,-1==e&&(g++,e=7)}if(d+=c,0>d||this.moduleCount<=d){d-=c,c=-c;break}}},getBestMaskPattern:function(){for(var a=0,b=0,c=0;8>c;c++){this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b}},b.PAD0=236,b.PAD1=17,b.createData=function(a,c,d){for(var e=k.getRSBlocks(a,c),f=new l,g=0;d.length>g;g++){var h=d[g];f.put(h.mode,4),f.put(h.getLength(),m.getLengthInBits(h.mode,a)),h.write(f)}for(var i=0,g=0;e.length>g;g++)i+=e[g].dataCount;if(f.getLengthInBits()>8*i)throw new Error("code length overflow.");for(f.getLengthInBits()+4<=8*i&&f.put(0,4);f.getLengthInBits()%8!=0;)f.putBit(!1);for(;;){if(f.getLengthInBits()>=8*i)break;if(f.put(b.PAD0,8),f.getLengthInBits()>=8*i)break;f.put(b.PAD1,8)}return b.createBytes(f,e)},b.createBytes=function(a,b){for(var c=0,d=0,e=0,f=new Array(b.length),g=new Array(b.length),h=0;b.length>h;h++){var i=b[h].dataCount,j=b[h].totalCount-i;d=Math.max(d,i),e=Math.max(e,j),f[h]=new Array(i);for(var k=0;f[h].length>k;k++)f[h][k]=255&a.buffer[c++];g[h]=new Array(j);for(var k=0;g[h].length>k;k++)g[h][k]=0}var l=0,m=new Array(0);for(var h=0;d>h;h++)for(var k=0;b.length>k;k++)h<f[k].length&&(m[l++]=f[k][h]);for(var h=0;e>h;h++)for(var k=0;b.length>k;k++)h<g[k].length&&(m[l++]=g[k][h]);for(var k=0;b.length>k;k++){var n=new Array(b[k].totalCount-b[k].dataCount),o=0;for(var h=0;n.length>h;h++)n[h]=b[k].dataCount+h;for(var p=j_=f.getErrorCorrectPolynomial(b[k].totalCount-b[k].dataCount),q=new i(f[k].concat(g[k]),n.length-1),r=q.mod(p),h=0;p.getLength()-1>h;h++){var s=h+q.getLength()-n.length+h;m[o++]=0>s||r.getLength()<=s?0:r.get(s)}}return m};var k={},l=function(){this.buffer=[],this.length=0},m=f;return i.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var b=new Array(this.getLength()+a.getLength()-1),c=0;this.getLength()>c;c++)for(var d=0;a.getLength()>d;d++)b[c+d]^=h.gexp(h.glog(this.get(c))+h.glog(a.get(d)));return new i(b,0)},mod:function(a){if(this.getLength()-a.getLength()<0)return this;var b=h.glog(this.get(0))-h.glog(a.get(0)),c=new Array(this.getLength());for(var d=0;this.getLength()>d;d++)c[d]=this.get(d);for(var d=0;a.getLength()>d;d++)c[d]^=h.gexp(h.glog(a.get(d))+b);return new i(c,0).mod(a)}},l.prototype={get:function(a){var b=Math.floor(a/8);return 1==(this.buffer[b]>>>7-a%8&1)},put:function(a,b){for(var c=0;b>c;c++)this.putBit(1==(a>>>b-c-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var b=Math.floor(this.length/8);this.buffer.length<=b&&this.buffer.push(0),a&&(this.buffer[b]|=128>>>this.length%8),this.length++}},for(var p=0;255>p;p++)h.EXP_TABLE[p]=1>p?1:127>p?h.EXP_TABLE[p-1]<<1:h.EXP_TABLE[p-1]<<1^285,h.LOG_TABLE[h.EXP_TABLE[p]]=p;for(var p=255;512>p;p++)h.EXP_TABLE[p]=h.EXP_TABLE[p-255];k.getRSBlocks=function(a,b){var c=k.getRsBlockTable(a,b);if(void 0==c)throw new Error("bad rs block");for(var d=c.length/3,e=[],f=0;d>f;f++)for(var g=c[3*f+0],h=c[3*f+1],i=c[3*f+2],j=0;g>j;j++)e.push({dataCount:i,totalCount:h});return e},k.getRsBlockTable=function(a,b){switch(b){case 1:return[[1,26,19],[1,44,34],[1,70,55],[1,100,80],[1,134,108],[2,86,68],[2,98,78],[2,121,97],[2,146,116],[2,86,68,2,87,69],[4,101,81],[2,116,92,2,117,93],[4,133,107],[3,145,115,1,146,116],[5,109,87,1,110,88],[5,122,98,1,123,99],[1,135,107,5,136,108],[5,150,120,1,151,121],[3,141,113,4,142,114],[3,135,107,5,136,108],[3,144,116,4,145,117],[4,144,115,4,145,116],[2,174,140,4,175,141],[4,160,132,6,161,133],[6,163,131,4,164,132],[8,157,125,4,158,126],[10,155,124,2,156,125],[8,163,130,4,164,131],[3,174,140,11,175,141],[7,160,132,7,161,133]];case 0:return[[1,26,16],[1,44,28],[1,70,44],[2,50,32],[2,67,43],[4,43,27],[4,49,31],[2,60,38,2,61,39],[3,58,36,2,59,37],[4,69,43,1,70,44],[1,80,50,4,81,51],[6,58,36,2,59,37],[8,59,37,1,60,38],[4,64,40,5,65,41],[5,65,41,5,66,42],[7,73,45,3,74,46],[10,74,46,1,75,47],[9,69,43,4,70,44],[3,70,44,11,71,45],[3,67,41,13,68,42],[17,68,42],[17,74,46],[4,75,47,14,76,48],[6,73,45,14,74,46],[8,75,47,13,76,48],[19,74,46,4,75,47],[22,73,45,3,74,46],[3,73,45,23,74,46],[21,73,45,7,74,46],[19,75,47,10,76,48]]}},window.QRCode=function(el,opt){if("string"==typeof opt)opt={text:opt};var o={width:256,height:256,colorDark:"#000",colorLight:"#fff",correctLevel:0};for(var k in opt)o[k]=opt[k];var qr=new b(1,o.correctLevel);qr.addData(o.text),qr.make();var c=document.createElement("canvas"),w=o.width,h=o.height;c.width=w,c.height=h;var ctx=c.getContext("2d"),mc=qr.getModuleCount(),tw=Math.floor(w/mc),th=Math.floor(h/mc);ctx.fillStyle=o.colorLight,ctx.fillRect(0,0,w,h),ctx.fillStyle=o.colorDark;for(var r=0;mc>r;r++)for(var col=0;mc>col;col++)qr.isDark(r,col)&&ctx.fillRect(col*tw,r*th,tw,th);var el2="string"==typeof el?document.getElementById(el):el;el2.innerHTML="",el2.appendChild(c),this.clear=function(){el2.innerHTML=""}}}();
</script>

<!-- MAIN CHECKOUT SCRIPT -->
<script>
(function(){
'use strict';
var C=<?php echo $cp_cfg; ?>;
var invoice=null,activeCoin=C.first_coin||'BTC',timerInt=null,pollInt=null,qrObj=null;

function g(id){return document.getElementById(id);}
function st(id,v){var e=g(id);if(e)e.textContent=v;}

document.addEventListener('DOMContentLoaded',function(){bootCoin(C.first_coin||'BTC');});

function bootCoin(key){
  activeCoin=key;
  var coin=C.all_coins[key]||{};
  var dot=g('cpCdot');
  if(dot){dot.style.background=coin.color||'#888';dot.textContent=coin.icon||'';}
  st('cpCname',coin.name||key);
  st('cpCnet',(coin.symbol||key)+'\u00b7'+(coin.network||''));
  st('cpAmt','\u2014');
  var r=g('cpRate'); if(r)r.textContent='';
  st('cpCvAmt','\u2014'); st('cpCvAddr','\u2014'); st('cpCvLink','\u2014');
  if(g('cpFee'))g('cpFee').textContent=coin.rec_fee||'\u2014';
  clearQR();
  setBar('','Awaiting Payment\u2026');
  ajax('chainpay_get_invoice',{order_id:C.order_id,order_key:C.order_key,coin:key},function(r){
    if(r&&r.success&&r.data){invoice=r.data;renderInv(invoice);startTimer(invoice.expires_at);startPoll(invoice.invoice_id);}
    else{
      var errData=r&&r.data;
      var errMsg='Could not create invoice.';
      if(errData&&typeof errData==='object'){
        var code=errData.code||'';
        if(code==='FREE_LIMIT_REACHED'){
          setBar('s-expired','Monthly limit reached');
          var mn=g('cpMain');if(mn)mn.style.display='none';
          var ex=g('cpStExp');if(ex){ex.classList.add('show');
            var ti=ex.querySelector('.cp-state-title');if(ti)ti.textContent='Monthly limit reached';
            var su=ex.querySelector('.cp-state-sub');if(su)su.innerHTML='You\'ve used all 50 free payments this month.<br><a href="'+C.license_url+'" target="_blank" style="color:#ff6b2b;font-weight:800;">Upgrade to Pro for unlimited →</a>';
          }return;
        }
        if(code==='LICENSE_REQUIRED'){clearQR();cpOpenModal();return;}
        errMsg=errData.message||errMsg;
      }else if(typeof errData==='string'){errMsg=errData;}
      setBar('','Error: '+errMsg);
    }
  });
}

function renderInv(inv){
  var coin=C.all_coins[inv.coin]||{};
  var sym=coin.symbol||inv.coin||'';
  var color=coin.color||'#f7931a';
  var icon=coin.icon||'';
  var n=parseFloat(inv.amount_crypto);
  var ca=isNaN(n)?(inv.amount_crypto||''):n.toFixed(8).replace(/\.?0+$/,'');
  st('cpAmt',ca+' '+sym);
  st('cpCvAmt',ca+' '+sym);
  if(g('cpRate')&&inv.exchange_rate){var r2=parseFloat(inv.exchange_rate);g('cpRate').textContent='1 '+sym+' \u2248 $'+r2.toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});}
  st('cpCvAddr',inv.address||'\u2014');
  st('cpCvLink',inv.uri||inv.address||'\u2014');
  var wb=g('cpWallet'); if(wb)wb.href=inv.uri||'#';
  if(g('cpFee')&&coin.rec_fee)g('cpFee').textContent=coin.rec_fee;
  if(g('cp-qr-canvas')&&inv.uri)buildQR(inv.uri);
  var ov=g('cpQrCoin'); if(ov){ov.style.background=color;ov.textContent=icon;}
}

function buildQR(data){
  var w=g('cp-qr-canvas'); if(!w)return;
  w.innerHTML='';
  try{qrObj=new QRCode(w,{text:data,width:166,height:166,colorDark:'#000000',colorLight:'#ffffff',correctLevel:0});}
  catch(e){w.innerHTML='<div class="cp-qr-lbl">QR error</div>';}
}
function clearQR(){var w=g('cp-qr-canvas');if(w)w.innerHTML='<div class="cp-qr-lbl">Generating\u2026</div>';if(qrObj){try{qrObj.clear();}catch(e){}qrObj=null;}}

function startTimer(exp){
  clearInterval(timerInt);
  var te=g('cpTmr'); if(!te)return;
  timerInt=setInterval(function(){
    var diff=Math.floor((new Date(exp)-Date.now())/1000);
    if(diff<=0){clearInterval(timerInt);te.textContent='00:00';if(!invoice||invoice.status==='pending')showState('exp');return;}
    var m=String(Math.floor(diff/60)).padStart(2,'0'),s=String(diff%60).padStart(2,'0');
    te.textContent=m+':'+s;
    te.className='cp-sb-tmr'+(diff<=60?' crit':diff<=180?' warn':'');
  },1000);
}

function startPoll(invId){
  clearInterval(pollInt);
  pollInt=setInterval(function(){
    ajax('chainpay_poll_status',{invoice_id:invId},function(r){
      if(!r||!r.success||!r.data)return;
      var d=r.data;
      if(d.status==='detected'){setBar('s-detected','Payment Detected \u2014 awaiting confirmation\u2026');}
      else if(d.status==='confirmed'){clearInterval(pollInt);clearInterval(timerInt);showState('ok');if(d.redirect_url)setTimeout(function(){window.location.href=d.redirect_url;},3000);}
      else if(d.status==='expired'){clearInterval(pollInt);clearInterval(timerInt);showState('exp');}
    });
  },8000);
}

function setBar(cls,msg){
  var bar=g('cpSb'),spn=g('cpSpin');
  if(!bar)return;
  bar.className='cp-sb'+(cls?' '+cls:'');
  st('cpMsg',msg);
  if(spn)spn.classList.toggle('off',cls==='s-confirmed'||cls==='s-expired');
}

function showState(type){
  var m=g('cpMain'); if(m)m.style.display='none';
  if(type==='ok'){setBar('s-confirmed','Payment Confirmed!');var e=g('cpStOk');if(e)e.classList.add('show');}
  else{setBar('s-expired','Invoice Expired');var e=g('cpStExp');if(e)e.classList.add('show');}
}

window.cpTab=function(name,btn){
  document.querySelectorAll('.cp-tab').forEach(function(b){b.classList.remove('on');});
  document.querySelectorAll('.cp-pane').forEach(function(p){p.classList.remove('on');});
  btn.classList.add('on');
  var pane=g('cpPane'+name.charAt(0).toUpperCase()+name.slice(1));
  if(pane)pane.classList.add('on');
};

window.cpOpenSheet=function(){
  buildSheet();
  var bg=g('cpShBg'),sh=g('cpSheet'),carr=g('cpCarr');
  if(bg)bg.classList.add('open');
  if(sh)sh.classList.add('open');
  if(carr)carr.style.transform='rotate(180deg)';
  document.body.style.overflow='hidden';
};
window.cpCloseSheet=function(){
  var bg=g('cpShBg'),sh=g('cpSheet'),carr=g('cpCarr');
  if(bg)bg.classList.remove('open');
  if(sh)sh.classList.remove('open');
  if(carr)carr.style.transform='';
  document.body.style.overflow='';
};
function buildSheet(){
  var list=g('cpShList'); if(!list)return;
  var h='';
  for(var k in C.all_coins){
    var c=C.all_coins[k];
    var isFr=C.free_coins.indexOf(k)!==-1;
    var lkd=!C.has_license&&!isFr;
    var sel=k===activeCoin;
    h+='<div class="cp-sh-row'+(lkd?' lkd':'')+(sel?' sel':'')+'" data-k="'+k+'" data-lkd="'+(lkd?1:0)+'">'
      +'<div class="cp-sh-dot" style="background:'+(c.color||'#888')+'">'+(c.icon||'')+'</div>'
      +'<div class="cp-sh-info"><span class="cp-sh-name">'+c.name+'</span><span class="cp-sh-sym">'+c.symbol+' \u00b7 '+c.network+'</span></div>'
      +(lkd?'<span class="cp-sh-lkd">\uD83D\uDD12 Pro</span>':(sel?'<span class="cp-sh-chk">\u2713</span>':''))
      +'</div>';
  }
  list.innerHTML=h;
  list.querySelectorAll('.cp-sh-row').forEach(function(row){
    row.addEventListener('click',function(){
      if(this.dataset.lkd==='1'){cpCloseSheet();cpOpenModal();return;}
      cpCloseSheet(); bootCoin(this.dataset.k);
    });
  });
}

window.cpOpenModal =function(){var m=g('cpModalBg');if(m)m.classList.add('open');};
window.cpCloseModal=function(){var m=g('cpModalBg');if(m)m.classList.remove('open');};

window.cpCopy=function(elId,btn){
  var val=(g(elId)||{}).textContent||'';
  if(!val||val==='\u2014')return;
  var orig=btn.textContent;
  var done=function(){btn.textContent='Copied \u2713';btn.classList.add('done');setTimeout(function(){btn.textContent=orig;btn.classList.remove('done');},1800);};
  if(navigator.clipboard){navigator.clipboard.writeText(val).then(done).catch(function(){fallback(val);done();});}
  else{fallback(val);done();}
};
function fallback(t){var ta=document.createElement('textarea');ta.value=t;ta.style.cssText='position:fixed;top:-9999px;opacity:0';document.body.appendChild(ta);ta.focus();ta.select();try{document.execCommand('copy');}catch(e){}document.body.removeChild(ta);}

function ajax(action,data,cb){
  var body='action='+encodeURIComponent(action)+'&nonce='+encodeURIComponent(C.nonce);
  for(var k in data)body+='&'+encodeURIComponent(k)+'='+encodeURIComponent(data[k]);
  var x=new XMLHttpRequest();
  x.open('POST',C.ajax_url,true);
  x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  x.onreadystatechange=function(){if(x.readyState===4){try{cb(JSON.parse(x.responseText));}catch(e){cb(null);}}};
  x.send(body);
}
})();
</script>
</body>
</html>
