function $(elemID){ return document.getElementById(elemID); }

var js_window_reload = false;
var js_window_loaded = false;
var js_window_inited = false;
var js_window_cache = new Array();
var cache_name = '';
setTimeout('js_window_clean();', 180000);

function js_window(name, title, request){
	if(!js_window_loaded) js_window_init(name, title, $('js_window'));
	else js_window_reinit(name, title);
	js_window_load(name, '', request);
	$('js_window').style.visibility = 'visible';
	$('js_window_back').style.visibility = 'visible';
	document.body.onkeyup = function(e){
		if (!e) e = window.event;
		if(e.keyCode == 27) return js_window_close();
	}
/*
	document.body.addEventListener('keyup', function(e){
		if (!e) e = window.event;
		if(e.keyCode == 27) return js_window_close();
	}, false);
*/
	return false;
}

function js_window_reinit(name, title){
	$('js_w_title').innerHTML = title;
	$('js_w_content').innerHTML = '<img src="http://img.zone403.ru/des/loadinfo.gif" width="46" height="46" align="absmiddle"><b class="gray s16">&nbsp;&nbsp;Подождите, загрузка данных...</b>';
	$('js_w_backlink').innerHTML = '';
}

function js_window_init(name, title, js_w_obj){
	js_window_inited = true;
	js_w_obj.style.left = js_window_left;
//	'<div class="js_w_back"></div>' +
//(bl ? '			<a href="#" class="brown s12" onclick="return js_window_back();">назад</a> | ' : '') +
	js_w_obj.innerHTML = '<div class="js_w_front"><div class="js_w_main">' +
'<table cellspacing="5" cellpadding="0" border="0" style="width: 100%;">' +
'	<tr>' +
'		<td style="width: 80%;"><span id="js_w_title" class="gray s18">' + title + '</span></td>' +
'		<td align="right"><a href="#" class="brown s12" onclick="return js_window_close();">закрыть</a></td>' +
'		<td style="width: 33px;"><a href="#" onclick="return js_window_close();"><img height="33" width="33" alt="закрыть" src="http://img.zone403.ru/des/js_window_close.gif" title="закрыть"/></a></td>' +
'	</tr>' +
'	<tr><td colspan="3" id="js_w_content"><img src="http://img.zone403.ru/des/loadinfo.gif" width="46" height="46" align="absmiddle"><b class="gray s16">&nbsp;&nbsp;Подождите, загрузка данных...</b></td></tr>' +
'	<tr><td colspan="3" id="js_w_backlink"></td></tr>' +
'	</table>' +
'</div></div>';
	js_window_loaded = true;
}

function js_window_init_dom(name, title, js_w_obj){
	var w_back = document.createElement('div');
		w_back.className = "js_w_back";
	js_w_obj.appendChild( w_back );
	
	var w_front = document.createElement('div');
		w_front.className = "js_w_front";
		w_front.style.left = js_window_left;
	var w_main = document.createElement('div');
		w_main.className = "js_w_main";

	var table_content = document.createElement('table');
		table_content.cellSpacing = 5;
		table_content.cellPadding = 0;
		table_content.border = 0;
		table_content.style.width = '100%';
		var w_tr = document.createElement('tr');
			var w_td = document.createElement('td');
				var w_title = document.createElement('span');
					w_title.id = "js_w_title";
					w_title.className = "gray s18";
					w_title.appendChild( document.createTextNode(title) );
				w_td.appendChild( w_title );
			w_tr.appendChild( w_td );
			var w_td = document.createElement('td');
				w_td.align = "right";
				var w_close_a = document.createElement('a');
					w_close_a.href = "#";
					w_close_a.onclick = function(){
						return js_window_close()
					};
					w_close_a.className = "brown s12";
					w_close_a.appendChild( document.createTextNode("закрыть") );
				w_td.appendChild( w_close_a );
			w_tr.appendChild( w_td );

			var w_td = document.createElement('td');
				w_td.width = 33;
				var w_close_a = document.createElement('a');
					w_close_a.href = "#";
					w_close_a.onclick = function(){
						return js_window_close()
					};
					var w_close_img = document.createElement('img');
						w_close_img.height = 33;
						w_close_img.width = 33;
						w_close_img.alt = "закрыть";
						w_close_img.src = "http://img.zone403.ru/des/js_window_close.gif";
						w_close_img.title = "закрыть";
					w_close_a.appendChild( w_close_img );
				w_td.appendChild( w_close_a );
			w_tr.appendChild( w_td );
		table_content.appendChild( w_tr );
		
		var w_tr = document.createElement('tr');
		var w_content = document.createElement('td');
			w_content.colSpan = 3;
			w_content.id = "js_w_content";
			/* Аяксовый контент */
			w_content.innerHTML = '<img src="http://img.zone403.ru/des/loadinfo.gif" width="46" height="46" align="absmiddle"><b class="gray s16">&nbsp;&nbsp;Подождите, загрузка данных...</b>';
			//w_content.appendChild( document.createTextNode("Подождите, загрузка данных...") );
			
			w_tr.appendChild( w_content );
		table_content.appendChild( w_tr );
	w_main.appendChild( table_content );
	w_front.appendChild( w_main );
	js_w_obj.appendChild( w_front );
	js_window_loaded = true;
}

function js_window_load(name, load, request){
	cache_name = request['cn'];
	if(request['bn']) var back_name = request['bn'];
	if(!js_window_cache[cache_name]){
		var page = 'http://www.zone403.ru/' + js_window_pages[name];
		JsHttpRequest.query(
			page,
			request,
			function(result, errors){
				if(errors){
					$('js_w_title' + load).innerHTML = 'Ошибка';
					$('js_w_content' + load).innerHTML = errors;
				}else{
					$('js_w_title' + load).innerHTML = result['title'];
					$('js_w_content' + load).innerHTML = result['content'];
					if(result['debug']) $('js_debug').innerHTML += result['debug'];
					
					if(back_name){
						result['backlink'] = '<a href="#" class="red s12" onclick="return js_window_back(\'' + back_name + '\', \'' + load + '\');">&laquo; назад</a>';
						$('js_w_backlink' + load).innerHTML = result['backlink'];
					}
					if(cache_name) js_window_cache[cache_name] = result;
					js_window_reload = result['refresh'];
				}
			},
			true
		);
	}else{
		$('js_w_title' + load).innerHTML = js_window_cache[cache_name]['title'];
		$('js_w_content' + load).innerHTML = js_window_cache[cache_name]['content'];
		if(js_window_cache[cache_name]['backlink']) $('js_w_backlink' + load).innerHTML = js_window_cache[cache_name]['backlink'];
	}
	return false;
}

function js_window_back(back_name, load){
	//alert(back_name);
	if(js_window_cache[back_name]){
		cache_name = back_name;
		$('js_w_title' + load).innerHTML = js_window_cache[back_name]['title'];
		$('js_w_content' + load).innerHTML = js_window_cache[back_name]['content'];
		$('js_w_backlink' + load).innerHTML = js_window_cache[back_name]['backlink'] ? js_window_cache[back_name]['backlink'] : '';
	}else js_window_close();
	return false;
}

function js_window_close(){
	if(js_window_reload) window.location.reload();
	else{
		$('js_window').style.visibility = 'hidden';
		$('js_window_back').style.visibility = 'hidden';
	}
	js_window_inited = false;
	document.body.removeEventListener('keyup', function(){}, false);

	return false;
}

function js_info(name, target, request){
	if(!request['no']) $(target).innerHTML = '<img src="http://img.zone403.ru/des/loadinfo.gif" width="46" height="46" align="absmiddle"><b class="gray s16">&nbsp;&nbsp;Подождите, загрузка данных...</b>';
	cache_name = request['cn'];
	if(!js_window_cache[cache_name]){
		var page = 'http://www.zone403.ru/' + js_window_pages[name];
		JsHttpRequest.query(
			page,
			request,
			function(result, errors){
				if(errors){
					$(target).innerHTML = errors;
				}else{
					$(target).innerHTML = result['content'];
					//if(result['debug']) $('js_debug').innerHTML += result['debug'];
					
					if(cache_name) js_window_cache[cache_name] = result;
				}
			},
			true
		);
	}else{
		$(target).innerHTML = js_window_cache[cache_name]['content'];
	}
	return false;
}

var js_res_data;
function js_data(name, request, js_eval){
	cache_name = request['cn'];
	if(!js_window_cache[cache_name]){
		var page = 'http://www.zone403.ru/' + js_window_pages[name];
		JsHttpRequest.query(
			page,
			request,
			function(result, errors){
				if(errors){
					js_res_data = errors;
				}else{
					js_res_data = result['content'];
					//if(result['debug']) $('js_debug').innerHTML += result['debug'];
					
					if(cache_name) js_window_cache[cache_name] = result;
					if(js_eval) eval(js_eval);
				}
			},
			false
		);
	}else{
		js_res_data = js_window_cache[cache_name]['content'];
	}
	return js_res_data;
}

function xsize(){
	var width = -1;
	if(window.innerWidth){
		width = window.innerWidth;
	}else if(document.getElementsByTagName){
		var html = document.getElementsByTagName('html');
		if(html[0].offsetWidth){
			width = html[0].offsetWidth-2;
		}
	}
	return width;
}

function js_window_clean(){ js_window_cache = new Array(); setTimeout('js_window_clean();', 180000); }

var js_window_left = (xsize() / 2) - 260;

/* Global Action functions */
function get_hash(hash_link){
	local_hash = location.hash;
	if(local_hash != '' && hash_link != local_hash.substr(1)) hash_link = local_hash.substr(1);
	return hash_link;
}

function form_send(obj, e){
	if (!e) e = window.event;
	if((e.ctrlKey || e.shiftKey) && (e.keyCode == 10 || e.keyCode == 13)) obj.form.submit();
}

function text_count(msg_id){
	var cnt = parseInt($(msg_id).value.length);
	$(msg_id + '_cnt').innerHTML = cnt;
}

function mark_check(fobj, cn) {
	var el = fobj.form.elements;
	for(var i = 0; i < el.length; i++) {
		var en = el[i].id;
		if(en.indexOf(cn) != -1) el[i].checked = fobj.checked;
	}
}

function form_ajax(fobj, w_name, w_load, w_data){
	var w_request = [];
	var el = fobj.elements;
	for(var i = 0; i < el.length; i++) {
		var en = el[i];
		if(en.name != '') w_request[en.name] = en.value;
		if(w_load == '1') alert((en.value));
	}
	w_request['cn'] = '';
	w_request['aj'] = '1';
	//alert(w_request);
	if(w_data) return js_data(w_name, w_request);
	return js_window(w_name, w_load, w_request);
}

function get_path(num){
	var nn = new Array();
	nn[0] = Math.floor(num / 1000000);
	nn[1] = Math.floor((num % 1000000) / 10000);
	nn[2] = Math.floor((num % 10000) / 100);
	return nn.join("/");
}

var hp_upd = new Array();
function hp_update(trg, p){
	if(hp_upd['timer_' + trg] >= 0) clearTimeout(hp_upd['timer_' + trg]);
	hp_upd['timer_' + trg] = setTimeout('hp_update(\''+trg+'\', '+p+')', 1000);
	hp_upd['cur_' + trg] = hp_upd['cur_' + trg] + hp_upd['spd_' + trg];
	if(hp_upd['cur_' + trg] > hp_upd['max_' + trg]) hp_upd['cur_' + trg] = hp_upd['max_' + trg];
	rnd = 1;
	var res = Math.round(hp_upd['cur_' + trg]*rnd)/rnd;
	if(hp_upd['cur_' + trg] < hp_upd['max_' + trg]*0.7) res = '<span class=\"red\">' + res + '</span>';
	$('c_'+trg).innerHTML = res;
	if(p) $('p_'+trg).style.width = Math.round(100*hp_upd['cur_' + trg]/hp_upd['max_' + trg]) + '%';
}

function vote_for_user(vote, sign, request){
	var page = '/user-ajax.php';
	var tName = 'user_vote_' + request['user_id'];
	request['vote'] = vote;
	request['sign'] = sign;
	JsHttpRequest.query(
		page,
		request,
		function(result, errors){ $(tName).innerHTML = result['voter']; },
		true
	);
	return false;
}

function print_user(n, trg){
	js_res_data = js_data('user_info', {'info_tag':'print_user', 'user_name':n, 'class':'blue s18', 'cn':'un:'+n}, 'if(js_res_data) $("'+trg+'").innerHTML = js_res_data + \'<input type="hidden" name="'+trg+'" value="'+n+'">\';');
	if(js_res_data) $(trg).innerHTML = js_res_data + '<input type="hidden" name="'+trg+'" value="'+n+'">';
}

function check_user(n, trg){
	js_res_data = js_data('user_info', {'info_tag':'check_user', 'user_name':n, 'cn':'un:'+n}, 'if(js_res_data) $("'+trg+'").innerHTML = "Игрок с таким ником существует";');
	if(js_res_data) $(trg).innerHTML = 'Игрок с таким ником существует';
}

function check_battle(){
	name = 'user_ajax';
	r = Math.random();
	JsHttpRequest.query(
		'http://www.zone403.ru/' + js_window_pages[name],
		{'info_tag':'check_battle', 'r': r},
		function(result, errors){
			if(errors) js_res_data = errors;
			if(result['eval']) eval(result['eval']);
		},
		false
	);
}


function print_cnt_sub(cnt, text, st, sm, se){
	if(cnt%10 == 1 && Math.floor(cnt/10)%10 != 1) return cnt + text + st;
	if(cnt%10 <= 4 && cnt%10 > 0 && Math.floor(cnt/10)%10 != 1) return cnt + text + sm;
	return cnt + text + se;
}

var o_tag = new Array();
function ajax_sub_info(id, tag, trg){
	js_info('user_info', trg, {'user_id':id, 'info_tag':tag, 'cn':'ui:'+id+':'+tag, 'no':1});
	$(tag).className = 'm_user_a';
	if(o_tag[trg] && o_tag[trg] != tag) $(o_tag[trg]).className = 'm_user_s';
	o_tag[trg] = tag;
	return false;
}

function play_sound(sound){
	if(sound > 0){
		var so = new SWFObject("http://img.zone403.ru/js/swfplay.swf", "gr_server", "1", "1", "8", "#F5fff5");
		so.addVariable("soundPath", 'http://img.zone403.ru/sounds/' + sound + '.mp3');
		so.addParam("allowScriptAccess", "always"); 
		so.write("flash_top_content");
	}
}

function show_div(divid){
	if($(divid).style.display == "block") $(divid).style.display = "none";
	else $(divid).style.display = "block";

	return false;
}

/* @Global functions */
/*
// Инициализируем таблицу перевода
var trans = [];
for (var i = 0x410; i <= 0x44F; i++) trans[i] = i - 0x350;	// А-Яа-я
trans[0x401] = 0xA8;	// Ё
trans[0x451] = 0xB8;	// ё

// Сохраняем стандартную функцию escape()
var escapeOrig = window.escape;

// Переопределяем функцию escape()
window.escape = function(str){
	var ret = [];
	// Составляем массив кодов символов, попутно переводим кириллицу
	for(var i = 0; i < str.length; i++){
		var n = str.charCodeAt(i);
		if(typeof trans[n] != 'undefined') n = trans[n];
		if(n <= 0xFF) ret.push(n);
	}
	return escapeOrig(String.fromCharCode.apply(null, ret));
}
*/
/*
function show_popup(name, width, border, title){
//	if (document.getElementById("window").innerHTML == '' || !document.getElementById(name)){
		window_create(name,width,border);
		window_setupcontent(name,title);
//	}
}
function getPageSize() { 
	var xScroll, yScroll; 
	if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth; 
		yScroll = window.innerHeight + window.scrollMaxY; 
     } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
          xScroll = document.body.scrollWidth; 
          yScroll = document.body.scrollHeight; 
     } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
          xScroll = document.body.offsetWidth; 
          yScroll = document.body.offsetHeight; 
     } 
     var windowWidth, windowHeight; 
     if (self.innerHeight) {     // all except Explorer 
          windowWidth = self.innerWidth; 
          windowHeight = self.innerHeight; 
          if (yScroll > windowHeight)     windowWidth -= 16; 
     } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
          windowWidth = document.documentElement.clientWidth; 
          windowHeight = document.documentElement.clientHeight; 
     } else if (document.body) { // other Explorers 
          windowWidth = document.body.clientWidth; 
          windowHeight = document.body.clientHeight; 
     } 
     // for small pages with total height less then height of the viewport 
     if(yScroll < windowHeight) pageHeight = windowHeight; 
     else pageHeight = yScroll; 
     // for small pages with total width less then width of the viewport 
     if(xScroll < windowWidth) pageWidth = windowWidth; 
     else pageWidth = xScroll; 
     arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
     return arrayPageSize; 
}
function window_create(name, width, border){
	var left = (xsize() / 2) - width / 2;
	var top = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
//	top = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
//	top = (pageYOffset) ? pageYOffset : 0;
//	alert(top);
//	top = (ysize() / 3);
//	document.getElementById("window").style.left = left + 'px';
	document.getElementById("window").style.top = top + 'px';
	document.getElementById("window").innerHTML = 
		'<div style="width: '+width+'px; height: 1px; position: absolute; left: '+left+'px; top: 75px;" id="'+name+'"></div>'
		+'<div style="width: '+width+'px; height: 18px; top: 95px; left: '+left+'px; position: absolute; z-index: 2000; cursor: move; text-align: right;" id="drag" class="drag">'
			+'<img src="http://i.motorwars.ru/img/window/close.gif" width="26" hspace="20" height="18" alt="Закрыть" title="Закрыть" border="0" style="cursor: pointer;" onClick="window_close(0);">'
		+'</div>';
	document.getElementById("window").style.display = 'block';
	if (border == 1){
		document.getElementById(name).innerHTML = '<table style="width: '+width+'px; height: 1px;" cellspacing="0" cellpadding="0" border="0"><tr style="height: 12px;">'
													+'<td width="12"><img src="http://i.motorwars.ru/img/window/corner_1-trans.png" width="12" height="12" border="0"></td>'
													+'<td class="shade-border"></td>'
													+'<td width="12"><img src="http://i.motorwars.ru/img/window/corner_2-trans.png" width="12" height="12" border="0"></td>'
												+'</tr>'
												+'<tr valign="top" style="height: 1px;">'
													+'<td width="12" class="shade-border"></td>'
													+'<td id="'+name+'_content"></td>'
													+'<td width="12" class="shade-border"></td>'
												+'</tr>'
												+'<tr style="height: 12px;">'
													+'<td width="12"><img src="http://i.motorwars.ru/img/window/corner_3-trans.png" width="12" height="12" border="0"></td>'
													+'<td class="shade-border"></td>'
													+'<td width="12"><img src="http://i.motorwars.ru/img/window/corner_4-trans.png" width="12" height="12" border="0"></td>'
												+'</tr></table>';
	}
}

function window_setupcontent(name, title){
	document.getElementById(name+"_content").innerHTML = document.getElementById(name+"_content").innerHTML
		+'<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; background-color: #E9F3E9; background-image: url(http://i.motorwars.ru/img/window/pbrd_bg.gif);">'
			+'<tr>'
				+'<td width="16"><img src="http://i.motorwars.ru/img/window/pbrd_tl-trans.png" width="16" height="16" border="0"></td>'
				+'<td style="background-image: url(http://i.motorwars.ru/img/window/pbrd_t.gif); background-repeat: repeat-x; background-position: left;"></td>'
				+'<td width="16"><img src="http://i.motorwars.ru/img/window/pbrd_tr-trans.png" width="16" height="16" border="0"></td>'
			+'</tr>'
			+'<tr valign="top">'
				+'<td width="16" style="background-image: url(http://i.motorwars.ru/img/window/pbrd_bgl.gif); background-repeat: repeat-y; background-position: top;"><img src="http://i.motorwars.ru/img/window/pbrd_l.gif" width="16" height="108" border="0"></td>'
				+'<td style="padding: 5px; vertical-align: top;" id="'+name+'_mf"></td>'
				+'<td width="16" style="background-image: url(http://i.motorwars.ru/img/window/pbrd_bgr.gif); background-repeat: repeat-y; background-position: top;"><img src="http://i.motorwars.ru/img/window/pbrd_r.gif" width="16" height="108" border="0"></td>'
			+'</tr>'
			+'<tr>'
				+'<td width="16"><img src="http://i.motorwars.ru/img/window/pbrd_bl-trans.png" width="16" height="16" border="0"></td>'
				+'<td style="background-image: url(http://i.motorwars.ru/img/window/pbrd_b.gif); background-repeat: repeat-x; background-position: left;"></td>'
				+'<td width="16"><img src="http://i.motorwars.ru/img/window/pbrd_br-trans.png" width="16" height="16" border="0"></td>'
			+'</tr>'
		+'</table>';
}

function window_close(name){
	if(name == 0){
		document.getElementById("window").innerHTML = '';
		document.getElementById("window").style.display = 'none';
	}
}

function xsize(){
	var width = -1;
	if(window.innerWidth){
		width = window.innerWidth;
	}else if(document.getElementsByTagName){
		var html = document.getElementsByTagName('html');
		if(html[0].offsetWidth){
			width = html[0].offsetWidth-2;
		}
	}
	return width;
}

function getElementPosition(elemID) {
	    var offsetTrail = document.getElementById(elemID);
	    var offsetLeft = 0;
	    var offsetTop = 0;
	    while (offsetTrail) {
	        offsetLeft += offsetTrail.offsetLeft;
	        offsetTop += offsetTrail.offsetTop;
	        offsetTrail = offsetTrail.offsetParent;
	    }
	    if (navigator.userAgent.indexOf("Mac") != -1 && 
	        typeof document.body.leftMargin != "undefined") {
	        offsetLeft += document.body.leftMargin;
	        offsetTop += document.body.topMargin;
	    }
	   return {left:offsetLeft, top:offsetTop};
}

function $(elemID){ return document.getElementById(elemID); }

function faq_oc (qnum) {
	  if (document.getElementById("q_brown_"+qnum).style.display == "none") {
	  
	    document.getElementById("q_blue_"+qnum).style.display = "none";
	    document.getElementById("q_brown_"+qnum).style.display = "";
	  
	  } else {
		  
		  document.getElementById("q_blue_"+qnum).style.display = "";
	    document.getElementById("q_brown_"+qnum).style.display = "none";
		  
	  }
	  
}
var xmlHttp;
var tName;
var dragName;
function show_page(name, page, request, nonXMLpage){
	document.getElementById(name+"_mf").innerHTML='<span align="center" class="red14">Подождите, загрузка данных...</span>';
	dragName = name;
	tName = name+"_mf";
	JsHttpRequest.query(
		page,
		request,
		function(result, errors){
			document.getElementById(tName).innerHTML = errors;
//			if(result) document.getElementById(tName).innerHTML = result;
		},
		true
	);
	return false;
}

function GetXmlHttpObject(){ 
	var objXMLHttp = null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

var dragobject={
	z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
	initialize:function(){
		document.onmousedown=this.drag
		document.onmouseup=function(){this.dragapproved=0}
	},
	drag:function(e){
		var evtobj=window.event? window.event : e
		this.targetobj=window.event? event.srcElement : e.target
		if (this.targetobj.className=="drag"){
			this.dragapproved=1
			if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left = 0}
			if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top = 0}
			this.offsetx=parseInt(this.targetobj.style.left)
			this.offsety=parseInt(this.targetobj.style.top)
			this.x=evtobj.clientX
			this.y=evtobj.clientY
			if (evtobj.preventDefault)
				evtobj.preventDefault()
				document.onmousemove=dragobject.moveit
		}
	},
	moveit:function(e){
		var evtobj=window.event? window.event : e
		if (this.dragapproved==1){

			this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
			this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"

			document.getElementById(dragName).style.left = this.offsetx+evtobj.clientX-this.x+"px"
			document.getElementById(dragName).style.top = this.offsety+evtobj.clientY-this.y-20+"px"

			return false
		}
	}
}
dragobject.initialize();

//number_format ( float number, int decimals, string dec_point, string thousands_sep)
function number_format(number, decimals, point, separator){
	if(!isNaN(number)){
		number = number.toString().split('.');
		decimals = decimals ? decimals : false;
		point = point ? point : '.';
		separator = separator ? separator : ',';
		
		var tmp_number = new Array();
		for(var i = number[0].toString().length, j = 0; i > 0; i -= 3){
			var pos = i > 0 ? i - 3 : i;
			tmp_number[j++] = number[0].substring(i, pos);
		}
		number[0] = tmp_number.reverse().join(separator);
		
		if(decimals !== false){
			number[1] = number[1] ? number[1] : '0';
			number[1] = Math.round(parseFloat(number[1].substr(0, decimals) + '.' + number[1].substr(decimals, number[1].length), 10));
			var size = decimals - number[1].toString().length;
			for(var i = 0; i < size; i++) number[1] += '0';
			number = number.join(point);
		}else{
			number = number[0];
		}
		return(number);
	}else return(null);
}

var global_wear = new Array();
function update_wear(wear_id){
	var time = new Date().getTime()/1000;
	var loaded = Math.min(100, Math.floor(100*((global_wear[wear_id]['since'] - time)/(global_wear[wear_id]['since'] - global_wear[wear_id]['until']))));
	var text = document.getElementById('weartext_' + wear_id);
	var barr = document.getElementById('wearbarr_' + wear_id);
	if(loaded < 100) {
		barr.style.width = loaded + "%";
		text.innerHTML = (100 - loaded) + "%";
		setTimeout("update_wear('" + wear_id + "')", 1000);
	} else {
		text.innerHTML = "0%";
	}
}

var check_timer = null;
var check_image = new Image();
function check_user(name, good, bad) {
	check_image.src = "http://www.motorwars.ru/user-check.php/" + name;
	check_image.onload = function(){
		clearTimeout(check_timer);
		if(this.height == 1){
			good();
		}else{
			bad();
		}
	}
}

var check_race_timer = null;
function check_race(obj_id, hide_id){
	var check_val = 0;
	var obj_el = document.getElementById(obj_id);
	var hide_el = document.getElementById(hide_id);
	
	hide_el.style.display = 'none';
	obj_el.style.display = 'inline';
	obj_el.innerHTML = '<img src="http://i.motorwars.ru/img/in_page/indicator.gif" alt="Загрузка..." height="10"> Проверка состояния...';

	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null) return true;
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			check_val = parseInt(xmlHttp.responseText);
			race_timer = 30;
			clearTimeout(check_race_timer);
			if(check_val == 0){ obj_el.style.display = 'none'; hide_el.style.display = 'block'; }
			if(check_val == 1){ obj_el.innerHTML = '<b>Вы заявлены в гонке</b>'; race_timer = 10; }
			if(check_val == 2){ obj_el.innerHTML = '<b>Гонка закончилась!</b>'; race_timer = 30; }
			if(check_val >= 3){ obj_el.innerHTML = '<a href="http://www.motorwars.ru/racing.php?race_id='+check_val+'" class="red12"><b>Гонка началась!</b></a>'; race_timer = 60; }
			if(check_val != 0) check_race_timer = setTimeout("check_race('" + obj_id + "', '" + hide_id + "')", race_timer*1000);
		}
	}
	var url = "http://www.motorwars.ru/race-check.php";
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function form_send(obj, e){
	if (!e) e = window.event;
	if(e.ctrlKey && (e.keyCode == 10 || e.keyCode == 13)) obj.form.submit();
}

function alert_mw(alerts){
	show_popup('alert-mw', 375, 1, 'Внимание!'); 
	dragName = 'alert-mw';
	tName = 'alert-mw_mf';

	alert_content = '<br><table width="100%" style="background-color: #F4F9F4; border: 1px solid #CCD0CC;"><tr style="vertical-align: top;">'
				+ '<td style="padding: 10px 0px 10px 10px; text-align: center;"><img src="http://i.motorwars.ru/img/in_page/exclmark.gif" border="0"></td>'
				+ '<td style="padding: 5px 10px 5px 10px; width: 100%;" class="blue11"><b class="red12">Внимание!</b><br><br>';
	for(var atxt in alerts){
		alert_content = alert_content + '<br><li>' + alerts[atxt];
	}
	alert_content = alert_content + '</td></tr></table>'
				+ '<table class="button-red" style="margin: 0px;" border="0" cellpadding="0" cellspacing="0"><tr>'
				+ '<td style="width: 7px;"><img src="http://i.motorwars.ru/img/button/button_red_l.gif" style="width: 7px; height: 23px;" alt=""></td>'
				+ '<td class="shadow-red"><span class="white11" style="cursor: pointer;" onclick="window_close(0);">Закрыть</span></td>'
				+ '<td style="width: 7px;"><img src="http://i.motorwars.ru/img/button/button_red_r.gif" style="width: 7px; height: 23px;" alt=""></td>'
				+ '</tr></table>';
	document.getElementById(tName).innerHTML = alert_content;
}
*/