var fname=(document.forms.length>1)?'KForm':0;

function goform(url,post)
{
if(url.indexOf('.')==-1)
	{ url+=".html"; }
if (post == 1)
	{ document.forms[fname].method='POST'; }
else
	{ document.forms[fname].method='GET'; }
document.forms[fname].action=url;
document.forms[fname].submit();
}

function gourl(url)
{
if(url.indexOf('.')==-1)
	{ url+=".html"; }
window.location.href=url;
}

function byid(id)
{ return document.getElementById(id); }

function SendForm ()
{
if(document.getElementById('RegTown2').checked == true)
     {
     document.getElementById('MForm').action="http://smorye.apeha.ru/user_add_3.html";
     }
if(document.getElementById('RegTown3').checked == true)
     {
     document.getElementById('MForm').action="http://utes.apeha.ru/user_add_3.html";
     }     
document.getElementById('MForm').submit();
}


function convertString(str){
	var query=""
	for (i=0;i<str.length;i++){
		var n=str.charCodeAt(i)
		if (n>=0x410&&n<=0x44F) n-=0x350
		else if (n==0x451) n=0xB8
		else if (n==0x401) n=0xA8
		query=query+String.fromCharCode(n)
	} 
	return escape(query); 
}

function chkR(){
	if(window.refreshed){
		return false
	}else{
		window.refreshed=true
	}
	return true
}
function goR(url){
	if(!window.refreshed){
		window.refreshed=true
		location.href=url
	}
}
function goRC(url){
	if(!window.refreshed){
		window.refreshed=true
		location.href=url+((url.indexOf('?')==-1)?'?':'&')+'xdac='+Math.random()
	}
}

function jsquote(str)
{
str = str.toString();
return str.replace(/'/g,'&#39;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/&/g,'&amp;');
}

function chkpress(obj,elt){
	var elt=obj.nextSibling
	obj.className=(elt.value==1)?
		obj.className.replace(/1$/,'0'):
		obj.className.replace(/0$/,'1')
	elt.value=1-elt.value
}
function radiopress(obj){
	var form=document.forms[0]
	obj.id.match(/^(.*)\-(.*)$/)
	var elt=RegExp.$1
	var val=RegExp.$2
	gebi(elt+'-'+form.elements[elt].value).className=
		gebi(elt+'-'+form.elements[elt].value).className.replace(/1$/,'0')
	form.elements[elt].value=val
	obj.className=obj.className.replace(/0$/,'1')
}

function newWin(goL,id,ww,wh)
{
ww=ww||screen.width*.9
wh=wh||screen.height*.9
var wbx=Math.round((screen.width-ww)/2)*.45
var wby=Math.round((screen.height-wh)/2)*.45
var pos=(document.all)?'left='+wbx+',top='+wby+',':'screenX='+wbx+',screenY='+wby+','
var nw=window.open(goL,'Win'+id,'width='+ww+',height='+wh+','+pos+'toolbar=0,scrollbars=0,resizable=1,status=0')
nw.moveTo(0,0)
nw.resizeTo(screen.availWidth, screen.availHeight)
}

function newWin2(goL,id,ww,wh)
{
ww=ww||screen.width*.9
wh=wh||screen.height*.9
var wbx=Math.round((screen.width-ww)/2)*.45
var wby=Math.round((screen.height-wh)/2)*.45
var pos=(document.all)?'left='+wbx+',top='+wby+',':'screenX='+wbx+',screenY='+wby+','
var nw=window.open(goL,'Win'+id,'width='+ww+',height='+wh+','+pos+'toolbar=0,scrollbars=1,resizable=1,status=0')
nw.moveTo(wbx,wby)
}

function fsetTime(stm)
{
if(!top.frames['d_menu']) return 0;
if(!top.frames['d_menu'].document.clock) return 0;
top.frames['d_menu'].document.clock.SetVariable("servTime",stm);
}

var hloc;
var hlast;
var hpos = 0;
var tID;

function preRoll(c, r)
{
document.getElementById('rollingscroll').innerHTML = c;
window.clearTimeout(tID);
tout = 0;
if (c) tout = 4000;
tID = window.setTimeout("startRoll('" + r + "')", tout);
}

function startRoll(lc)
{
hpos = 0;
if(lc != '')
	{
	hloc = lc;
	document.getElementById('rollingscroll').alt = hloc;
	document.getElementById('rollingscroll').title = hloc;
	}
hlast = hloc.replace(/.*:\s*/, '');
if(hlast.length > 22)
	hlast = hlast.substr(hlast.length - 22, 22);
window.clearTimeout(tID);
Roll(2000);
}

function Roll(tout)
{
var set = hloc.substr(hpos, 22);
if(set != hlast)
	{
	hpos++;
	tID = setTimeout("Roll(150)", tout);
	}
document.getElementById('rollingscroll').innerHTML = set;
}

function butact(name)
{
var st = document.getElementById(name).style;
if(!st.display)
	{ st.display='none'; }
else
	{ st.display=''; }
}

function shBlock(id)
{
byid('BLC_pers').style.display='none'
byid('BLC_par').style.display='none'
byid('BLC_stat').style.display='none'
byid('BUTT_pers').src=byid('BUTT_pers').src.replace(/-a\.gif$/,'.gif')
byid('BUTT_par').src=byid('BUTT_par').src.replace(/-a\.gif$/,'.gif')
byid('BUTT_stat').src=byid('BUTT_stat').src.replace(/-a\.gif$/,'.gif')
byid('BLC_'+id).style.display='block'
byid('BUTT_'+id).src=byid('BUTT_'+id).src.replace(/\.gif$/,'-a.gif')
}

function printTime(s)
{
if (s < 0) s=0;
var min = Math.floor(s/60);
var sec = s - min*60;
return min + ":" + ((sec < 10)?('0' + sec):sec);
}

var RaceNames = new Array('','Hm','Or','Gn','El','Hb','Dr','Ab','Wm','');
var RaceFNames = new Array('Читер','Человек','Орк','Гном','Эльф','Хоббит','Дракон','Животное бойцовое','Боевая машина','');
var InjuryLevels = new Array('Легкая травма','Средняя травма','Тяжелая травма');

var cht=['h','b','r','l','f'];
var fcht=['head','body','rhand','lhand','foot'];

function injColor(inj)
{
var ic=['green','yellow','orange','red']
if(inj>3) inj=3
return ic[inj]
}
	
function injTitle(inj)
{
var ic=['Часть тела в порядке','Часть тела легко повреждена','Часть тела тяжело повреждена','Часть тела не функционирует']
if(inj>3) inj=3
return ic[inj]
}

