function localtime ()
{
return Math.round ((new Date()).getTime()/1000);
}
function get_by_id (d, n)
{
if (!d) return false;
if (d.getElementById) return d.getElementById (n);
else if (d.all) return d.all[n];
else return false;
}
function get_by_idl (n)
{
if (document.getElementById) return document.getElementById (n);
else if (document.all) return document.all[n];
else return false;
}
// wants document.form_name.radio_name
function get_rvalue (el)
{
if (!el.length) return el.value;
for (var i = 0; i < el.length; i++) if (el[i].checked) return el[i].value;
return 0;
}
function ask_nav (txt, loc) { if (confirm (txt)) { window.location = loc; } }
function input_nav (qt, qv, loc) {
var s = prompt (qt, '');
if ((s != null) && (s != '')) { window.location = loc + '&' + qv + '=' + s; }
}
function info_pic (pic,txt,h,w,am,br,t)
{
var pstr = '
';
if (t) return pstr; else document.write (pstr);
return;
}
// smart timer [interval, seconds count, show squares [1 - [], 2 - ],
// compulsory prefix, show in div 'name', reload location (?)]
function set_tick (tint,met,sq,prf,dnm,loc)
{
if (met <= 0) return;
var vr = new String(Math.random()).substr(2);
var vm = 'm'+vr;
vr = 't'+vr;
document.write ('
');
get_by_idl (vm).innerHTML = met;
get_by_idl (vr).innerHTML = setInterval('do_tick("'+vr+'","'+vm+'",'+sq+',"'+prf+'","'+dnm+'","'+loc+'")',tint);
return do_tick (vr,vm,sq,prf,dnm,loc);
}
function do_tick (vn,vm,sq,prf,dnm,loc)
{
var el = get_by_idl (dnm);
var hel = get_by_idl (vm);
if (!hel) return;
var __met = parseInt (hel.innerHTML);
var m0 = __met - (__met % 3600);
var m1 = __met - m0;
m0 /= 3600;
var m2 = m1 % 60;
m1 = (m1 - m2) / 60;
var __s = prf;
if (sq == 1) __s += '[ ';
else if (sq == 2) __s += '';
if (m0) __s += m0+' ч ';
__s += m1+' мин '+m2+' сек';
if (sq == 1) __s += ' ]';
else if (sq == 2) __s += '';
if (el) el.innerHTML = __s;
__met--;
if (__met < 0) {
clearInterval (parseInt (get_by_idl (vn).innerHTML));
if (loc && (loc != undefined)) window.location = loc;
} else {
hel.innerHTML = __met;
}
return;
}
// current page, last page, common link, sublink, to-show limit, write sign
function plist (tpage,lim,bl,sl,ts,w)
{
var result = '';
if (tpage > lim) tpage=lim;
var pgst = tpage - 5;
var pgfn = tpage + 5;
if (pgst < 1) { pgst = 1; pgfn = ts + 1; }
if (pgfn > lim) {pgfn = lim; pgst = pgfn > ts ? pgfn - ts : 1;}
if (pgst>2) result += '« ... ';
else if (pgst==2) result += '... ';
for (i=pgst; i<=pgfn; i++) {
result += i==tpage ? ''+i+' ' : ''+i+' ';
}
if (pgfn < lim-1) result += '... » ';
else if (pgfn == lim-1) result += '...';
if (w) { document.write (result); return; }
return result;
}
function grow_branch (abr,blev,bt,am)
{
var sbranch = '';
for (var j = 0; j < abr.length; j += 6) {
for (var k = 0; k < blev; k++) sbranch += ' ';
var tota = am * abr[j + 2];
if (tota < 10) sbranch += ' ';
sbranch += tota;
var wstp = new String (abr[j + 1]).substr (0,3);
if (bt) sbranch += ' ';
else if (tota > abr[j + 3]) sbranch += ' ';
else sbranch += ' ';
sbranch += abr[j];
if (bt) sbranch += ' ';
else sbranch += ' ['+abr[j + 3]+'] ';
if (am > 1) sbranch += '('+abr[j + 2]+' x '+am+')';
sbranch += '
';
if (abr[j + 5])
sbranch += grow_branch (abr[j + 5], blev + 1, bt, Math.ceil (tota / abr[j + 4]));
}
return sbranch;
}
// name, type, amount, has amount, composition production amount, composition
function grow_tree (atr,bt)
{
var stree = grow_branch (atr, 0, bt, 1);
document.write (stree);
}