<script type="text/javascript" src="webui/jquery.min.js"></script>
<script type="text/javascript" src="webui/jquery.flot.min.js"></script>
<style>
td.maturity {
	text-align: right;
	white-space: nowrap;
}
</style>
<div id="light" class="white_content">
<table width="100%"><tr>
<td><h3><b class="mono" id="disp_txid"></b></h3>
<td align="right"><a href="javascript:closepopup()">X</a>
</table>
<pre id="rawdiv" style="background-color:white"></pre>
</div><div id="fade" class="black_overlay"></div>
<table width="100%">
<tr>
<td><b>Memory Pool:</b></td>
<td align="right">
<input type="checkbox" id="mempool_spb_range" onchange="show_mempool_fees()" checked>
<span onclick="mempool_spb_range.click()" style="cursor:pointer">Limit range</span>
</td>
</tr>
</table>

<table width="100%">
<tr>
<td colspan="2">
<div id="mempool_fees" style="height:200px;margin:5px"></div>
</tr>


<tr>
<td valign="top">
	<table>
	<colgroup>
		<col width="200">
		<col width="100">
		<col width="100">
	</colgroup>
		<tr><td>Memory pool size:
			<td colspan="2">
			<input type="button" id="ts_t2s_size" onclick="show_mempool_fees()"
				title="Click to see mempool fee statistics"
				style="width:100%">
			<td align="right">
		<tr><td>UTXOs spent in memory:
			<td><b id="outspent"></b>
			<td align="right">avg. <b id="avgoutspertx"></b> / tx
		<tr><td>Rejected transactions:
			<td><input type="button" id="butre" value="" onclick="show_txsre()">
			<td align="right"><b id="ts_tre_size"></b>
		<tr><td>Waiting for inputs:<td colspan="2"><input type="button" id="butw4i" value="" onclick="show_txw4i()">
		<tr><td>Being processed:
			<td><b id="ts_ptr1_cnt"></b> / <b id="ts_ptr2_cnt"></b>
			<td><input type="button" onclick="show_txs2s('&ownonly=1')" value="Own TXs">
	</table>
<td valign="top">
	<table>
		<col width="150">
		<col width="100">
		<col width="150">
		<tr>
			<td>Memory pool:
			<td><b><!--MEM_POOL_ENABLED--></b>
			<td><span id="el_txp_switch" style="display:none">[<a href="javascript:config('txponoff')">Switch ON/OFF</a>]</span>
		<tr>
			<td>Relay transactions:
			<td><b><!--TX_ROUTE_ENABLED--></b>
			<td><span id="el_txr_switch" style="display:none">[<a href="javascript:config('txronoff')">Switch ON/OFF</a>]</span>
		<tr><td colspan="3">&nbsp;
		<tr>
			<td colspan="3" bgcolor="#f0fff0" style="border:1px solid black">
				<b>Upload Transaction File:</b><br>
				<br>
				<form id="the-form" method="post" enctype="multipart/form-data">
					<input name="txfile" type="file">
					<input type="submit" value="Upload" />
				</form>
				... or use
				<a href="https://blockchain.info/pushtx" target="_blank">blockchain.info</a>
				| <a href="https://coinb.in/send-raw-transaction.html" target="_blank">coinb.in</a>
				| <a href="http://eligius.st/~wizkid057/newstats/pushtxn.php" target="_blank">eligius.st</a>
				to push it.
	</table>

<tr>
<td colspan="2">
<hr>
Up to
	<select id="mp_show_cnt">
		<option selected>50</option>
		<option>100</option>
		<option>250</option>
		<option>500</option>
		<option>1000</option>
		<option>2000</option>
		<option>5000</option>
		<option>10000</option>
	</select>
mempool transactions,
sorted by
	<select id="mp_show_sort">
		<option value="age">age</option>
		<option value="siz">length</option>
		<option value="vsi">virtual size</option>
		<option value="inp">inputs count</option>
		<option value="out">outputs count</option>
		<option value="btc">BTC volume</option>
		<option value="fee">fee amount</option>
		<option value="ops">sigops count</option>
		<option value="spb" selected>fee per byte</option>
		<option value="rbf">RFB first</option>
		<option value="ver">verify time</option>
	</select>
in descending <input id="mp_show_sort_desc" type="checkbox" checked="checked"> order
- <input type="button" value="show me now..." onclick="show_txs2s('')">
&nbsp;&nbsp;&nbsp;
<input type="button" value="Decode mempool TX" onclick="show_txid()">
</table>


<!--TX_LOAD-->
<table class="txs bord" id="txs2s" style="display:none" width="100%">
	<tr>
		<th width="20" align="right">#
		<th width="20" align="right">totlen
		<th>Transaction ID
		<th onclick="sortclick('age')" style="cursor:pointer" width="60" align="right">Maturity
		<th onclick="sortclick('siz')" style="cursor:pointer" width="80" align="right">Len
		<th onclick="sortclick('vsi')" style="cursor:pointer" width="80" align="right">VSiz
		<th onclick="sortclick('inp')" style="cursor:pointer" width="30" align="right">Inps
		<th onclick="sortclick('out')" style="cursor:pointer" width="30" align="right">Outs
		<th onclick="sortclick('btc')" style="cursor:pointer" width="90" align="right">Total BTC
		<th onclick="sortclick('fee')" style="cursor:pointer" width="80" align="right">Fee BTC
		<th onclick="sortclick('spb')" style="cursor:pointer" width="60" align="right">SPB
		<th onclick="sortclick('ops')" style="cursor:pointer" width="40" align="right">SOps
		<th onclick="sortclick('rbf')" style="cursor:pointer" width="30" align="right" title="Transaction is not final">RBF
		<th onclick="sortclick('ver')" style="cursor:pointer" width="40" align="right" title="Verification time in ms">ms
		<th width="40" align="right">Sent
		<th align="right">Extras
	</tr>
</table>
<table class="txs bord" id="txsre" style="display:none" width="100%">
	<tr>
		<th width="20" align="right">#
		<th>Transaction ID
		<th onclick="sorttab('txsre', 2)" style="cursor:pointer" width="60" align="right">Maturity
		<th onclick="sorttab('txsre', 3)" style="cursor:pointer" width="60" align="right">Size
		<th width="100" align="right">Reason rejected
</table>
<table class="txs bord" id="txw4i" style="display:none" width="100%">
	<tr>
		<th width="20" align="right">#
		<th>Waiting for
		<th>Pending Tx
		<th onclick="sorttab('txw4i', 3)" style="cursor:pointer" width="60" align="right">Maturity
</table>
<script>
if (!server_mode) {
	el_txp_switch.style.display='inline'
	el_txr_switch.style.display='inline'
}

function sortclick(type) {
	var os = mp_show_sort.options
	if (os[mp_show_sort.selectedIndex].value!=type) {
		mp_show_sort_desc.checked = true
		for (var i=0; i<os.length; i++) {
			if (os[i].value==type) {
				mp_show_sort.selectedIndex = i
				break
			}
		}
	} else {
		mp_show_sort_desc.checked = !mp_show_sort_desc.checked
	}
	show_txs2s('')
}

function sorter(a,b) {
	return a.val<b.val
}

function sorttab(tid,col) {
	var tbl = document.getElementById(tid).tBodies[0]
	var store = []
	for(var i=0, len=tbl.rows.length; i<len; i++) {
		var row = tbl.rows[i];
		var sortnr = parseFloat(row.cells[col].textContent || row.cells[col].innerText);
		if (!isNaN(sortnr)) store.push([sortnr, row]);
	}
	store.sort(function(x,y) {
		return y[0] - x[0];
	});
	for(var i=0, len=store.length; i<len; i++) {
		tbl.appendChild(store[i][1]);
	}
	for (var i=0; i<tbl.rows.length; i++) {
		tbl.rows[i].cells[0].innerHTML = i.toString()
	}
	store = null
}

function get_maturity(t) {
	var secs = parseInt(((new Date()).getTime()/1000) - parseInt(t))
	if (secs<0) secs=0
	if (secs<180)  return secs + ' s'
	var mins = secs / 60
	if (mins>300) return  (mins/60).toFixed(2) + ' h'
	return mins.toFixed(1) + ' min'
}

function val2reason(r) {
	switch (parseInt(r)) {
		case 1: return "RELAY_OFF"
		case 101: return "TOO_BIG"
		case 102: return "FORMAT"
		case 103: return "LEN_MISMATCH"
		case 104: return "EMPTY_INPUT"
		case 201: return "DOUBLE_SPEND"
		case 202: return "NO_TXOUT"
		case 203: return "DUST"
		case 204: return "OVERSPEND"
		case 205: return "LOW_FEE"
		case 206: return "SCRIPT_FAIL"
		case 207: return "BAD_INPUT"
		case 208: return "NOT_MINED"
		case 209: return "CB_INMATURE"
		case 210: return "RBF_LOWFEE"
		case 211: return "RBF_FINAL"
		case 212: return "RBF_100"
	}
	return r
}


function send1tx_click(id) {
	if (confirm("Send TX "+id+" to one random peer")) {
		show_txs2s('&sendone='+id+'&ownonly=1')
	}
}

function sendtx_click(id) {
	if (confirm("Broadcast TX "+id)) {
		show_txs2s('&send='+id+'&ownonly=1')
	}
}

function deltx_click(id) {
	if (confirm("Delete TX "+id)) {
		show_txs2s('&del='+id+'&ownonly=1')
	}
	txrawdata.innerText = ''
}

var prvpos = null
var tx_decoding_in_progress = false

function decode_tx() {
	if (!tx_decoding_in_progress) {
		decode_tx_id(this.id)
	}
}

function decode_tx_id(txid) {
	var aj = ajax()
	tx_decoding_in_progress = true
	aj.onreadystatechange=function() {
		if(aj.readyState==4) {
			var sta = xval(aj.responseXML,  "status")
			if (sta!="OK") {
				alert(sta)
				return
			}

			disp_txid.innerHTML = xval(aj.responseXML,  "id")

			var tin=0, tout=0, s = ''
			var len = xval(aj.responseXML,  "size")

			s += "Version: " + xval(aj.responseXML,  "version") + "\n\n"

			var is = aj.responseXML.getElementsByTagName('input')
			for (var i=0; i<is.length; i++) {
				s += (i+1) + ") "
				var st = xval(is[i], "status")
				if (st=="OK") {
					var val = parseInt(xval(is[i], "value"))
					tin += val
					s += (parseFloat(val)/1e8).toFixed(8)
					s += " BTC <= "
					var ad = xval(is[i], "addr")
					if (typeof(ad)!="string") {
						s += xval(is[i], "pkscript")
					} else {
						s += ad
					}
				} else {
					s += st
				}
				var bl = xval(is[i], "block")
				if (bl==0) {
					s += " (unconfirmed yet)"
				} else {
					s += " (confirmed in #"+xval(is[i], "block")+")"
				}
				s += " seq=" + parseInt(xval(is[i], "sequence")).toString(16)
				var sops = parseInt(xval(is[i], "input_sigops"))
				if (!isNaN(sops)) {
					s += "  + " + sops + ' sigops'
				}
				var inspcr = xval(is[i], "script_sig")
				if (!isNaN(inspcr)) {
					s += " - SigScript length " +inspcr.length/2
					for (var k=0; k<inspcr.length; k+=140) {
						s += "\n    " + inspcr.substr(k, 140)
					}
				}

				var segwit = is[i].getElementsByTagName("witness")
				if (segwit.length>0) {
					s += "\n  SegWit stack:"
					for (var k=0; k<segwit.length; k++) {
						s += "\n    " + segwit[k].childNodes[0].nodeValue
					}
				}

				s += "\n"
			}
			s += "Total input: " + (parseFloat(tin)/1e8).toFixed(8) + " BTC\n"
			s += "\n"

			is = aj.responseXML.getElementsByTagName('output')
			for (var i=0; i<is.length; i++) {
				s += (i+1) + ") "
				var val = parseInt(xval(is[i], "value"))
				tout += val
				s += (parseFloat(val)/1e8).toFixed(8)
				s += " BTC => " + xval(is[i], "addr")
				s += "\n"
			}
			s += "Total output: " + (parseFloat(tout)/1e8).toFixed(8) + " BTC\n"
			s += "\n"
			s += "Lock time: " + xval(aj.responseXML,  "lock_time") + "\n\n"
			var fee = tin-tout
			s += 'TxSize: ' + len
			s += '  /  NoWit:' + xval(aj.responseXML,  "nwsize")
			s += '  /  VSize: ' + xval(aj.responseXML,  "vsize")
			s += ' bytes  /  Sigops: ' + xval(aj.responseXML,  "sigops") + '\n'

			var vsize = parseFloat(xval(aj.responseXML,  "vsize"))
			s += "Fee: " + (parseFloat(fee)/1e8).toFixed(8) + " BTC"
			s += '  ==> ' + parseFloat(fee/vsize).toFixed(1) + ' Satoshis per byte\n'
			s += 'Verification took: ' + xval(aj.responseXML,  "verify_us") + ' microseconds\n'

			rawdiv.innerHTML = s

			if (prvpos==null) {
				fade.addEventListener('click', closepopup)
				fade.style.cursor = 'pointer'
				fade.title = 'Click here to close the popup'
			}


			prvpos = document.body.scrollTop
			window.scrollTo(0,0)

			light.style.display='block'
			fade.style.display='block'
			document.addEventListener("scroll", noscroll)
			tx_decoding_in_progress = false
		}
	}
	aj.open("GET","txs2s.xml?id="+txid+'&sid='+sid, true);
	aj.send(null);
}

function show_txs2s(extrapar) {
	var aj = ajax()
	aj.onreadystatechange=function() {
		if(aj.readyState==4) {
			while (txs2s.rows.length>1)  txs2s.deleteRow(1)
			txs = aj.responseXML.getElementsByTagName('tx')
			var lensofar = 0
			for (var i=0; i<txs.length; i++) {
				var c,row
				var own = parseInt(xval(txs[i], 'own'))
				var txid = xval(txs[i], 'id')

				row = txs2s.insertRow(-1)
				row.className='hov'

				var len = parseInt(xval(txs[i], 'size'))
				lensofar += len

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = (i+1).toString()

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = lensofar

				c = row.insertCell(-1)
				c.className ='mono'
				c.innerHTML = txid
				c.id = txid
				c.addEventListener('click', decode_tx, false)
				c.style.cursor='pointer'

				c=row.insertCell(-1);c.className='maturity'
				c.innerHTML = get_maturity(xval(txs[i], 'time'))

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = len
				var nws = 'No witness size:' + xval(txs[i], 'nwsize')
				c.title = nws

				c=row.insertCell(-1);c.align='right'
				c.innerHTML += xval(txs[i], 'vsize')
				c.title = nws

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = xval(txs[i], 'inputs')

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = xval(txs[i], 'outputs')


				c=row.insertCell(-1);c.align='right'
				c.innerHTML = (parseFloat(xval(txs[i], 'volume'))/1e8).toFixed(8)

				if (own!=2) {
					var fee = parseFloat(xval(txs[i], 'fee'))

					c=row.insertCell(-1);c.align='right'
					c.innerHTML = (fee/1e8).toFixed(8)

					c=row.insertCell(-1);c.align='right'
					c.innerHTML = (parseFloat(fee)/parseFloat(xval(txs[i], 'vsize'))).toFixed(1)
				} else {
					c=row.insertCell(-1);c.align='right'
					c.innerHTML = '<i>unknown</i>'

					c=row.insertCell(-1);c.align='right'
					c.innerHTML = '<i>unknown</i>'
				}

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = xval(txs[i], 'sigops')

				c=row.insertCell(-1);c.align='center'
				if (xval(txs[i], 'final')!='true') c.innerHTML = '*'

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = (xval(txs[i], 'verify_us')/1e3).toFixed(1)

				c=row.insertCell(-1);c.align='right'
				var sc = xval(txs[i], 'sentcnt')
				c.innerHTML = sc + "/" + xval(txs[i], 'invsentcnt')
				if (sc>0) {
					var tim = new Date(xval(txs[i], 'sentlast')*1000)
					c.title = "Last sent at "+tim.getHours()+":"+leftpad(tim.getMinutes(),'0',2)+":"+leftpad(tim.getSeconds(),'0',2)
				}

				c=row.insertCell(-1);c.align='right'
				if (own!=0) {
                    c.innerHTML = '<img style="cursor:pointer" title="Send this TX to one random peer" onclick="send1tx_click(\''+txid+'\')" src="webui/send_once.png">'
					c.innerHTML += '&nbsp;'
                    c.innerHTML += '<img style="cursor:pointer" title="Broadcast this TX" onclick="sendtx_click(\''+txid+'\')" src="webui/send.png">'
					c.innerHTML += '&nbsp;'
					c.innerHTML += '<img style="cursor:pointer" title="Remove this TX" onclick="deltx_click(\''+txid+'\')" src="webui/del.png">'
				} else {
					var blkd = parseInt(xval(txs[i], 'blocked'))
					if (blkd!=0) {
						c.innerHTML = val2reason(blkd)
					} else {
						c.innerHTML = '&nbsp;'
					}
				}

				if (own!=0) {
					row.classList.add('own')
					row.title = 'Your own transaction'
				}

				if (xval(txs[i], 'witness_cnt') > 0) {
					row.classList.add('segwit')
					row.title = 'Segregated Witness transaction'
				}
			}
			txs2s.style.display = 'table'
		}
	}
	txs2s.style.display = txsre.style.display = txw4i.style.display = 'none'

	extrapar += '&cnt='+mp_show_cnt.options[mp_show_cnt.selectedIndex].value
	extrapar += '&sort='+mp_show_sort.options[mp_show_sort.selectedIndex].value
	if (mp_show_sort_desc.checked) {
		extrapar += '&descending'
	}
	aj.open("GET","txs2s.xml?sid="+sid+extrapar, true);
	aj.send(null);
}


function show_txsre() {
	var aj = ajax()
	aj.onreadystatechange=function() {
		if(aj.readyState==4) {
			while (txsre.rows.length>1)  txsre.deleteRow(1)
			txs = aj.responseXML.getElementsByTagName('tx')
			butre.value = ' ' + txs.length + ' '
			for (var i=0; i<txs.length; i++) {
				var t,c,row = txsre.insertRow(-1)

				row.className='hov'

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = (i+1).toString()

				c = row.insertCell(-1)
				c.className ='mono'
				t = xval(txs[i], 'id')
				c.innerHTML = '<a href="https://blockchain.info/tx/'+t+'">'+t+'</a>'

				c=row.insertCell(-1);className='maturity'
				c.innerHTML = get_maturity(xval(txs[i], 'time'))

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = xval(txs[i], 'size')

				c=row.insertCell(-1);c.align='right'
				c.innerHTML = val2reason(xval(txs[i], 'reason'))
			}
			txsre.style.display = 'table'
		}
	}
	txs2s.style.display = txsre.style.display = txw4i.style.display = 'none'
	aj.open("GET","txsre.xml", true);
	aj.send(null);
}

function show_txw4i() {
	var aj = ajax()
	aj.onreadystatechange=function() {
		if(aj.readyState==4) {
			while (txw4i.rows.length>1)  txw4i.deleteRow(1)
			wait4s = aj.responseXML.getElementsByTagName('wait4')
			var idx=0
			butw4i.value = ' ' + wait4s.length + ' '
			for (var i=0; i<wait4s.length; i++) {
				pendtxs = wait4s[i].getElementsByTagName('tx')
				idx++
				for (var j=0; j<pendtxs.length; j++) {
					var t,c,row = txw4i.insertRow(-1)

					row.className='hov'

					c=row.insertCell(-1);c.align='right'
					if (j==0) {
						c.innerHTML = idx.toString()
					}

					c = row.insertCell(-1)
					c.className ='mono'
					if (j==0) {
						t = xval(wait4s[i], 'id')
						c.innerHTML = '<a href="https://blockchain.info/tx/'+t+'">'+t+'</a>'
					}

					c = row.insertCell(-1)
					c.className ='mono'
					t = xval(pendtxs[j], 'id')
					c.innerHTML = '<a href="https://blockchain.info/tx/'+t+'">'+t+'</a>'

					c=row.insertCell(-1);className='maturity'
					c.innerHTML = get_maturity(xval(pendtxs[j], 'time'))
				}
			}
			txw4i.style.display = 'table'
		}
	}
	txs2s.style.display = txsre.style.display = txw4i.style.display = 'none'
	aj.open("GET","txw4i.xml", true);
	aj.send(null);
}

var previousPoint = null
var mp = []

function showTooltip(x, y, contents) {
	$('<div id="tooltip">' + contents + '</div>').css( {
		position: 'absolute',
		display: 'none',
		top: y - 30,
		left: x + 5,
		border: '2px solid #fdd',
		padding: '5px',
		'font-size' : '14px',
		'background-color': '#fee',
		opacity: 1
	}).appendTo("body").fadeIn(200);
}

function handlehover(event, pos, item) {
	if (item) {
		if (previousPoint != item.dataIndex) {
			previousPoint = item.dataIndex;
			$("#tooltip").remove();

			var rec = mp[item.dataIndex]
			var str = ''

			str += rec.Current_tx_spb.toFixed(2) + ' SPB'

			str += ' -  Tx #'+(rec.Txs_so_far+1)
			str += ' ('+rec.Current_tx_length+' bytes'
			str += ' @ ' + rec.Offset_in_block+')'
			str += ' - ' + ((parseInt(new Date().getTime())/1000 - rec.Time_received)/60).toFixed(1) +' min old'
			showTooltip(item.pageX, item.pageY, str)
		}
	} else {
		$("#tooltip").remove();
		previousPoint = null;
	}
}


function handleclick(event, pos, item) {
	if (!tx_decoding_in_progress) {
		var rec = mp[item.dataIndex]
		decode_tx_id(rec.Current_tx_id)
	}
}

function show_txid() {
	if (!tx_decoding_in_progress) {
		var tid = prompt("Enter ID of the TX");
		if (tid!=null) {
			decode_tx_id(tid)
		}
	}
}


function show_mempool_fees() {
	var aj = ajax()
	aj.onreadystatechange=function() {
		if(aj.readyState==4) {
			mp = JSON.parse(aj.responseText)
			if (mp==null) return

			var plot_data = [ { data : [], color : 4, points: { show:true }, lines: {show:true, fill:true}} ];
			var plot_options = {
				grid: {
					markings: [ { xaxis: { from: 0, to: 1e6 }, color: "#e0ffe0" },
						{ xaxis: { from: 1e6, to: 2e6 }, color: "#f0f0e0" },
						{ xaxis: { from: 2e6 }, color: "#ffe0e0" },
					 ],
					hoverable: true,
					clickable: true
				},
				xaxis: {
					//tickLength : 1e6,
					minTickSize : 1e5,
					tickFormatter : function(a,b) {return (a/1e6).toFixed(1)}
				},
				yaxis : {
					//position : "left"
				}
			}

			var max_spb = 0
			var max_spb_corrected = 0
			var half = 500e3

			if (mp.length>1 && mp[mp.length-1].Offset_in_block<1e6) {
				half = Math.round(mp[mp.length-1].Offset_in_block / 2)
			}

			for (var i=0; i<mp.length; i++) {
				if (mp[i].Current_tx_spb>max_spb) {
					max_spb = mp[i].Current_tx_spb
				}
				if (mp[i].Offset_in_block<half) {
					max_spb_corrected = 3*mp[i].Current_tx_spb
				}
				plot_data[0].data.push([mp[i].Offset_in_block+mp[i].Current_tx_length, mp[i].Current_tx_spb])
			}

			// calculate 3 times the medium fee in the first block to be mined
			if (mempool_spb_range.checked && max_spb > max_spb_corrected) {
				plot_options.yaxis.max = max_spb_corrected
			}

			$("#mempool_fees").bind("plothover", handlehover)
			$("#mempool_fees").bind("plotclick", handleclick)
			$.plot($("#mempool_fees"), plot_data, plot_options)
		}
	}
	aj.open("GET","mempool_stats.json?max=10000000", true);
	aj.send(null);
}



function refreshtxstat() {
	var aj = ajax()
	aj.onerror=function() {
		setTimeout(refreshtxstat, 5000)
	}
	aj.onload=function() {
		try {
			var ts = JSON.parse(aj.responseText)

			ts_t2s_size.value = bignum(ts.t2s_size)+'B in ' + ts.t2s_cnt + ' txs'
			outspent.innerText = ts.spent_outs_cnt
			if (ts.t2s_cnt>0) {
				avgoutspertx.innerText = (ts.spent_outs_cnt/ts.t2s_cnt).toFixed(2)
			} else {
				avgoutspertx.innerText = '?'
			}
			butre.value = ts.tre_cnt
			ts_tre_size.innerText = bignum(ts.tre_size)+'B'
			butw4i.value = ts.awaiting_inputs
			ts_ptr1_cnt.innerText = ts.ptr1_cnt
			ts_ptr2_cnt.innerText = ts.ptr2_cnt
		} catch(e) {
			console.log(e)
		}
		setTimeout(refreshtxstat, 1000)
	}
	aj.open("GET","txstat.json",true)
	aj.send(null)
}

document.addEventListener('DOMContentLoaded', function() {
	refreshtxstat()
	window.onkeyup = function (event) {
		if(event.keyCode == 27)  closepopup()
	}
})

blno.addEventListener("lastblock", function(e) {
	show_mempool_fees()
})

</script>
