// $Id: common.js,v 1.148 2009/10/16 13:47:26 i.hrustalev Exp $

 undefined;

Number.prototype.toFixed = Number.prototype.toFixed || function(fractionDigits) {
	return Math.floor( this * Math.pow(10, fractionDigits) + .5) / Math.pow(10, fractionDigits);
};

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

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

function copyBoard(txt){
	if(document.body.createTextRange) {
		var d=document.createElement('INPUT');
		d.type='hidden';
		d.value=txt;
		document.body.appendChild(d).createTextRange().execCommand("Copy");
		document.body.removeChild(d);
		return;
	} else try {
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
		gClipboardHelper.copyString(txt);
	} catch (e) {}
}

function getCoords(obj){
	var o=typeof(obj) == 'string' ? gebi(obj) : obj;
	var ret={'l':o.offsetLeft,'t':o.offsetTop,'w':o.offsetWidth,'h':o.offsetHeight};
	while(o=o.offsetParent){
		ret.l+=o.offsetLeft;
		ret.t+=o.offsetTop;
	}
	return ret;
}

var waitFuncId=0;
function waitObj(id,evFunc){
	if(document.getElementById){
		if(typeof evFunc=='function'){
			window['waitFunc'+waitFuncId]=evFunc;
			evFunc='waitFunc'+waitFuncId;
			waitFuncId++;
		}
		var obj=(id=='body')?document.body:document.getElementById(id);
		if(obj) window[evFunc]();
		else setTimeout("waitObj('"+id+"','"+evFunc+"')",100);
	}else{
		onload=evFunc;
	}
}

function preloadImages() {
	var d = document;
	if(!d._prImg) {
		d._prImg = new Array();
	}
	var i, j = d._prImg.length, a = preloadImages.arguments;
	for (i=0; i<a.length; i++) {
		d._prImg[j] = new Image;
		d._prImg[j++].src = a[i];
	}
}

function checkbox_set(pfx, val) {
	var chk=document.getElementsByTagName('INPUT');
	for(var i=0;i<chk.length;i++){
		if(chk[i].name.indexOf(pfx)==0 || chk[i].getAttribute('grp')==pfx){
			chk[i].checked = (val == undefined ? !chk[i].checked: val);
		}
	}
}

// ==============================================================================

function showError(error) {
	return showMsg2("error.php?error="+error);
}

function error_close() {
	try {
		var win = top.window;
		var obj = top.gebi('error');
		var div = top.gebi('error_div');
		if (!obj || !div) return false;
		obj.style.display = 'none';
		div.style.display = 'none';
		obj.src='';
		obj.width = 1;
		obj.height = 1;
		obj.style.left = 0;
		obj.style.top = 0;
	} catch(e) {}
	return true;
}

function showMsg2(url, title, w, h) {
	try {
		w=w||480;
		h=h||300;
		var win = top.window;
		var doc = top.document;
		var width = doc.body.clientWidth;
		var height = doc.body.clientHeight;
		var div_width = Math.max(doc.compatMode != 'CSS1Compat' ? doc.body.scrollWidth : doc.documentElement.scrollWidth,width);
		var div_height = Math.max(doc.compatMode != 'CSS1Compat' ? doc.body.scrollHeight : doc.documentElement.scrollHeight,height);
		var obj = top.gebi('error');
		var div = top.gebi('error_div');
		if (!obj || !div) return false;
		obj.src=url;
		
		div.style.width = div_width;
		div.style.height = div_height;
		
		obj.width = w;
		obj.height = h;
		obj.style.left = ((width-w)/2);
		obj.style.top = ((height-h)/2);
		div.style.display = 'block';
		obj.style.display = 'block';
		win.scrollTo(0,0);
//		obj = top.gebi('artifact_alt');
//		if (obj) obj.innerHTML='';
	} catch(e) {}
	return true;
}

function showMsg(url, title, w, h) {
	w=w||480;
	h=h||300;
	var win = top.window;
	if (win.showModelessDialog) {
		var sFeatures = 'dialogWidth:' + w + 'px; dialogHeight:' + h + 'px; center:yes; help:no; status:no; unadorned:yes; scroll:no;';
		return win.showModelessDialog("msg.php", {win: win, src: url, title: title}, sFeatures);
	} else {
		return win.open(url, "", 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
	}
}

function showUserInfo(nick) {
	var url = "/user_info.php?nick="+nick;
	window.open(url, "", "width=920,height=700,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showArtifactInfo(artifact_id,artikul_id,set_id) {
	var url = "/artifact_info.php";
	if (artifact_id) url += "?artifact_id="+artifact_id;
	else if (artikul_id) url += "?artikul_id="+artikul_id;
	else if (set_id) url += "?set_id="+set_id;
	else return;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showPetInfo(pet_id,artikul_id) {
	var url = "/pet_info.php";
	if (pet_id) url += "?pet_id="+pet_id;
	else if (artikul_id) url += "?artikul_id="+artikul_id;
	else return;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function dialogEventCheck(event,param,close) {
	if (!param) param = '0';
	if (!top.dialogOn && event != 'FAQ' && event != null) return false;
	if (event) {
		var id = top.dialogEvent[event+'_'+param];
		if (id && id.length && id.length > 0) {
			for(var i=0;i<id.length;i++) {
				if (top.dialogShow[id[i]]) continue;
				var k = false;
				for(var j=0;j<top.dialogNeed.length;j++) {
					if (top.dialogNeed[j] == id[i]) {
						k = true;
						break;
					}
				}
				if (top.showNow == id[i]) k=true;
				if (!k) top.dialogNeed.push(id[i]); 
			}
		}
	}
	try {
		var div = top.frames['main_frame'].gebi('dialog_div');
		//var frame = top.frames['main_frame'].gebi('dialog_frame');
		if (div.style.display == 'none' || close) {
			var id = top.dialogNeed.shift();
			if (id) {
				updateSwf({'dialog': 'id='+id });
				//swfTransfer('id','dialog',id);
				//frame.src='tests.php?id='+id;
				div.style.display = '';
				if (id > 1) top.dialogShow[id] = id;
				top.showNow = id;
			} else {
				div.style.display = 'none';
				//frame.src='';
				top.showNow = 0;
			}
		}
	} catch(e) {}
}

function showFightInfo(fight_id) {
	var url = "/fight_info.php?fight_id="+fight_id;
	window.open(url, "", "width=990,height=700,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
}
function showInstInfo() {
	var url = "/instance_stat.php";
	window.open(url, "", "width=990,height=700,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
}

function showBotInfo(bot_id, artikul_id) {
	var url = "/bot_info.php";
	if (bot_id) {
		if (bot_id > 1000000000) bot_id -= 1000000000;
		url += "?bot_id="+bot_id;
	}	
	else if (artikul_id) url += "?artikul_id="+artikul_id;
	window.open(url, "", "width=915,height=700,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showPunishmentInfo(nick) {
	var url = "/punishment_info.php?nick="+nick;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showInjuryInfo(nick) {
	var url = "/injury_info.php?nick="+nick;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showEffectInfo(nick) {
	var url = "/effect_info.php?nick="+nick;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showClanInfo(clan_id) {
	var url = "/clan_info.php?clan_id="+clan_id;
	window.open(url, "", "width=900,height=650,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showFriendsInfo() {
	var url = "/friend_list.php";
	window.open(url, "contacts", "width=730,height=650,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function showAchievementInfo(achievement_id) {
	var url = "/achievement_info.php?id="+achievement_id;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
}

function userPrvTag() {
	var chatFrame = getChatFrame();
	try {
		for (i=0; i<arguments.length; i++) chatFrame.chatPrvTag(arguments[i]);
	}
	catch (e) {}
}

function userToTag() {
	var chatFrame = getChatFrame();
	try {
		for (i=0; i<arguments.length; i++) chatFrame.chatToTag(arguments[i]);
	}
	catch (e) {}
}


function userIgnore(name,status) {
	var chatFrame = getChatFrame();
	try {
		chatFrame.chatSyncIgnore(name,status);
	}
	catch (e) {}
}

function userAttack(nick, url_error) {
	var rnd = Math.floor(Math.random()*1000000000);
	var url_success = 'fight.php?'+rnd;
	var urlATTACK = 'action_run.php?code=ATTACK&url_success='+url_success+'&url_error='+escape(url_error||'area.php')+'&in[nick]='+(nick ? nick : '');
	try {
		if (!top.frames["main_frame"].frames["main"].__fight_php__) top.frames["main_frame"].frames["main"].location.href = urlATTACK;
	}
	catch (e) {}
}
function confirm_friend(url) {
	try {
		top.frames['main_frame'].frames['main_hidden'].location.href = url;
	}
	catch (e) {}
}

function confirm_bg(area_id) {
	try {
		top.frames['main_frame'].frames['main'].location.href = 'area_bgs.php?area_id=' + area_id + '&action=confirm';
	}
	catch (e) {}
}

function confirm_slaughter(area_id) {
	try {
		top.frames['main_frame'].frames['main'].location.href = 'area_bgs.php?area_id=' + area_id + '&action=confirm_slaughter';
	}
	catch (e) {}
}


function show_slaughter_stat(instance_id, finish) {
	var url = 'instance_stat.php?outside=1&instance_id=' + instance_id + '&finish=' + finish;
	window.open(url, "", "width=730,height=550,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
//	try {
//		top.frames['main_frame'].frames['main'].location.href = 'instance_stat.php?instance_id=' + instance_id + '&finish=' + finish;
//	}
//	catch (e) {}
}

function getChatFrame() {
	var win = window;
	try { win = dialogArguments || window; } catch(e) {};
	while (win.opener) win = win.opener;
	if (win.closed) return;
	
	return win.top.frames['chat'];
}

function fightHelpRequest() {
	var chatFrame = getChatFrame();
	try {
		chatFrame.chatSendMessage('/FIGHTHELP');
	} catch(e) {}
}

// fight_id where `target_nick` need help  
function fightHelp(fight_id, target_nick) {
	if (!confirm('Вы уверены что хотите помочь в бою игроку ' + target_nick + '?'))
		return;
	try {
	var rnd = Math.floor(Math.random()*1000000000);
	var err_url = top.frames["main_frame"].frames["main"].location;
	var url = 'action_run.php?code=FIGHT_HELP'+
			'&in[fight]=' + escape(fight_id) +
			'&in[target_nick]=' + escape(target_nick) +
			'&url_success=' + escape('fight.php?'+rnd) +  
			'&url_error=' + escape(err_url) +
			'&' + rnd;
		top.frames["main_frame"].frames["main"].location.href = url;
	}
	catch (e) {}
}

function botAttack(bot_id, url_error) {
	var rnd = Math.floor(Math.random()*1000000000);
	var url_success = 'fight.php?'+rnd;
	var urlATTACK = 'action_run.php?code=ATTACK_BOT&url_success='+url_success+'&url_error='+escape(url_error||'area.php')+'&bot_id='+bot_id;
	if (!bot_id) return;
	try {
		if (!top.frames["main_frame"].frames["main"].__fight_php__) top.frames["main_frame"].frames["main"].location.href = urlATTACK;
	}
	catch (e) {}
}

function huntAttack(bot_id) {
	botAttack(bot_id,'hunt.php');
}

function _background(obj, name) {
	if (obj.tagName == 'IMAGE') {
		obj.src = name;
	} else {
		obj.style.backgroundImage = 'url('+name+')';
	}
}

function getIframeShift(obj){
	var obj = obj || window;
	var ret={'l':0,'t':0};
	while(o=obj.frameElement){
		obj=obj.parent;
		
		var scrollTop = (obj.document.documentElement.scrollTop?obj.document.documentElement.scrollTop:obj.document.body.scrollTop);
		var scrollLeft = (obj.document.documentElement.scrollLeft?obj.document.documentElement.scrollLeft:obj.document.body.scrollLeft);
		
		ret.l+=o.offsetLeft - scrollLeft;
		ret.t+=o.offsetTop - scrollTop;
		while(o=o.offsetParent){
			ret.l+=o.offsetLeft;
			ret.t+=o.offsetTop;
		}
	}
	return ret;
}


function artifactAlt(obj, evnt, show) {
	var div = gebi(obj.getAttribute('div_id'));
	var artifact_alt = top.gebi('artifact_alt');
	if (!artifact_alt) return;
	
	var act1 = obj.getAttribute('act1');
	var act2 = obj.getAttribute('act2');
	if (show == 2) {
		document.onmousemove=function(e) {artifactAlt(obj, e||event, 1);};
		
		if (!artifact_alt.getAttribute('art_id') || obj.getAttribute('div_id') != artifact_alt.getAttribute('art_id')) {
			artifact_alt.innerHTML = div.innerHTML;
			artifact_alt.setAttribute('art_id',obj.getAttribute('div_id'));
		}
		
		artifact_alt.style.display = 'block';
		if (act1 || act2) {
			_background(obj, (top.locale_path + "images/itemact-"+ act1) + (act2 +".gif"));
		}
		
		top.obj = obj;
		if (top.show_alt) {
			top.show_alt();
		}
	}
	if (!show) {
		if (act1 || act2) {
			_background(obj, 'images/d.gif');
		}
		artifact_alt.style.display = 'none';
		document.onmousemove=function(){}
		return;
	}
	var coor = getIframeShift();
	var ex = evnt.clientX+coor.l;
	var ey = evnt.clientY+coor.t;
	
//	var ex = evnt.clientX + top.document.body.scrollLeft;
//	var ey = evnt.clientY + top.document.body.scrollTop;
	
	if (act1 || act2) {
		obj.style.cursor = 'pointer';
		obj.onclick = (act1 != 0 ? function(){try{artifactAct(obj, act1);}catch(e){}} : function(){showArtifactInfo(obj.getAttribute('aid'), obj.getAttribute('art_id'));});
		_background(obj, (top.locale_path + "images/itemact-"+ act1) + (act2 +".gif"));
		var coord = getCoords(obj);
		var cont = gebi("item_list");
		var rel_x = (ex + cont.scrollLeft + document.body.scrollLeft - coord.l - coor.l);
		if (rel_x >= 40) {
			var rel_y = (ey + cont.scrollTop + document.body.scrollTop - coord.t - coor.t);
			if (rel_y < 20) {
				obj.onclick = function(){showArtifactInfo(obj.getAttribute('aid'));};
				_background(obj, top.locale_path + 'images/itemact_info' + act2 +'.gif');
				try{obj.style.cursor = 'hand';} catch(e){}
				try{obj.style.cursor = 'pointer';} catch(e){}
			}
			if (act2 != 0 && rel_y >= 40) {
				obj.onclick = function(){try{artifactAct(obj, act2);}catch(e){}}
				_background(obj, top.locale_path + 'images/itemact_drop' + act2 +'.gif');
				try{obj.style.cursor = 'hand';} catch(e){}
				try{obj.style.cursor = 'pointer';} catch(e){}
			}
		}
	}
	var x = ex + artifact_alt.offsetWidth > top.document.body.clientWidth - 20 ? ex - artifact_alt.offsetWidth - 10 : ex + 10;
	var y = ey + artifact_alt.offsetHeight > top.document.body.clientHeight - 20 ? ey - artifact_alt.offsetHeight - 10 : ey + 10;

	if (x < 0 ) {
		x = ex - artifact_alt.offsetWidth/2;
	}
	if (x < 7 ) {
		x = 7;
	}
	if (x > top.document.body.clientWidth - artifact_alt.offsetWidth - 20) {
		x= top.document.body.clientWidth - artifact_alt.offsetWidth - 20;
	}
	
	artifact_alt.style.left = x;
	artifact_alt.style.top = y;
	return;
}

function updateBag() {
	var win = window;
	try { win = dialogArguments ?  dialogArguments.win || dialogArguments : window; } catch(e) {};
	while (win.opener) win = win.opener;
	if (win.closed) return false;
	
	try{
		var win_main = win.top.frames['main_frame'].frames['main'];
		if(win_main.is_userphp) {
				win_main.location.href = win_main.urlMODE + '&update_swf=1';
			return true;
		}
	}
	catch (e) {}
	return false;
}
function updateSwf(params) {
	var win = window;
	try { win = dialogArguments ?  dialogArguments.win || dialogArguments : window; } catch(e) {};
	while (win.opener) win = win.opener;
	if (win.closed) return;
	
	var url = 'main_iframe.php?mode=update_swf';
	if (!params) return;
	try {
		for (i in params) {
			url += '&tar[]='+i;
			if (params[i]) url += '&add['+i+']='+escape(params[i]);
		}
		win.top.frames['main_frame'].frames['main_hidden'].location.href = url;
	}
	catch (e) {}
}

function updateHP() {
	updateSwf({'lvl': '' ,'items': ''});
}
function fightRedirect(fight_id) {
	var rnd = Math.floor(Math.random()*1000000000);
	var url = 'fight.php?'+rnd;
	if (top.__lastFightId && (top.__lastFightId >= fight_id)) return;
	top.__lastFightId = fight_id;
	top.frames["main_frame"].frames["main"].location.href = url;
}

function updatePartyLoot() {
	try {
		top.frames['main_frame'].frames['main_hidden'].location.href = 'main_iframe.php?mode=update_party';
	} catch (e) {};
}

function fightUpdateLog(ctime, nick1, level1, nick2, level2, code, i1, i2, i3, s1) {
	try {
		top.frames['main_frame'].frames['main'].fightUpdateLog(ctime, nick1, level1, nick2, level2, code, i1, i2, i3, s1);
	} catch (e) {};
}

function resurrect() {
	top.frames["main_frame"].frames["main"].location.href = 'action_run.php?code=RESURRECT&url_success=area.php&url_error=area.php';
}


// =======================================================================================

function js_money_input_assemble(id_prefix) {
	v = gebi(id_prefix).value;
	res = (isNaN(v) || v <= 0) ? 0 : (1.0 * (1.0*v).toFixed(2)).toFixed(2);
	return res*1.0;
}

function js_money_input_fill(id_prefix, amount) {
	gebi(id_prefix).value = amount;
}

// ========= swf data transfer functions ===============================================================

function getSWF(name) {
	var win = window;
	try { win = dialogArguments || window; } catch(e) {};
	while (win.opener) win = win.opener;
	if (win.closed) return;
	win =
		(name == 'top_mnu' ? win.top.frames.main_frame:
		(name == 'lvl' ? win.top.frames.main_frame:
		(name == 'items' ? win.top.frames.main_frame:
		(name == 'dialog' ? win.top.frames.main_frame:
		(name == 'items_right' ? win.top.frames.main_frame:
		(name == 'game' ? win.top.frames.main_frame.frames.main:
		(name == 'mem' ? win.top.frames.main_frame.frames.main:
		(name == 'inventory' ? win.top.frames.main_frame.frames.main:
		(name == 'magic' ? win.top.frames.main_frame.frames.main:
		(name == 'area' ? win.top.frames.main_frame.frames.main:
		(name == 'instance' ? win.top.frames.main_frame.frames.main:
		window)))))))))));
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return win[name];
	} else {
		return win.document[name];
	}
}

function swfTransfer(name,tar,data) {
	try {
		getSWF(tar).swfData(name,data);
		return true;
	} catch (e) {};
	return false;
}

function moveMedals(shift) {
	if (((shift < 0) && (position > 0)) || ((shift > 0) && (medals[position + MedalsOnPage]))) {
		position += shift;
		showMedals();
	}
}
function showMedals() {
	for(i=0;i<MedalsOnPage;i++) {
		document.getElementById('medal_' + i).innerHTML = medals[i + position] ? medals[i + position] : '&nbsp;';
	}
	if (position > 0) {
		document.getElementById('medal_l').src = "/images/medal_l_act.gif";
		document.getElementById('medal_l').style.cursor = "pointer";
	} else {
		document.getElementById('medal_l').src = "/images/medal_l.gif";
		document.getElementById('medal_l').style.cursor = "default";
	}
	if (medals[position + MedalsOnPage]) {
		document.getElementById('medal_r').src = "/images/medal_r_act.gif";
		document.getElementById('medal_r').style.cursor = "pointer";
	} else {
		document.getElementById('medal_r').src = "/images/medal_r.gif";
		document.getElementById('medal_r').style.cursor = "default";
	}
	return 1;
}

function ShowDiv(obj, evnt, show) {
	var div = gebi(obj.getAttribute('div_id'));
	if (!div) return;
	if (show == 2) {
		document.onmousemove=function(e) {artifactAlt(obj, e||event, 1);};
		div.style.display = 'block';
	}
	if (!show) {
		div.style.display = 'none';
		document.onmousemove=function(){};
		return;
	}
	
	var ex = evnt.clientX + document.body.scrollLeft;
	var ey = evnt.clientY + document.body.scrollTop;
	
	var x = evnt.clientX + div.offsetWidth > document.body.clientWidth - 7 ? ex - div.offsetWidth - 10 : ex + 10;
	var y = evnt.clientY + div.offsetHeight > document.body.clientHeight - 7 ? ey - div.offsetHeight - 10 : ey + 10;

	if (x < 0 ) {
		x = ex - div.offsetWidth/2;
	}
	if (x < 7 ) {
		x = 7;
	}
	if (x > document.body.clientWidth - div.offsetWidth - 7) {
		x= document.body.clientWidth - div.offsetWidth - 7;
	}

	div.style.left = x;
	div.style.top = y;
}

function artifactAltBP(id,show) {
	if (!top.artifactsAltMain[id]) {
		return;
	}
	var ajax_div = top.frames['main_frame'].gebi('AJAX_DIV');
	if (!ajax_div) {
		return;
	}
	ajax_div.innerHTML = top.artifactsAltMain[id];
	var div = top.frames['main_frame'].gebi('AA_'+id);
	if (!div) {
		return;
	}
	if (!show) {
		div.style.display = 'none';
		return;
	}
	div.style.display = 'block';
	var ex = 0;
	var ey = 0;
	
	ex = 74+coord.x + document.body.scrollLeft;
	ey = 78+coord.y + document.body.scrollTop;
	
	var x = coord.x + div.offsetWidth > document.body.clientWidth - 24 ? ex - div.offsetWidth - 10 : ex + 10;
	var y = coord.y + div.offsetHeight > document.body.clientHeight - 24 ? ey - div.offsetHeight - 10 : ey + 10;
	if (x < 0 ) x = ex - div.offsetWidth/2;
	if (x < 7 ) x = 7;
	if (x > document.body.clientWidth - div.offsetWidth - 24) {
		x= document.body.clientWidth - div.offsetWidth - 24;
	}
	div.style.left = x;
	div.style.top = y;
	return;
}

function artifactAltItems(id,show) {
	return; // Убрал отображение Альтов с Левых Итемов
	if (!top.artifactsAltMain[id]) {
		return;
	}
	var ajax_div = top.frames['main_frame'].gebi('AJAX_DIV');
	if (!ajax_div) {
		return;
	}
	ajax_div.innerHTML = top.artifactsAltMain[id];
	var div = top.frames['main_frame'].gebi('AA_'+id);
	if (!div) {
		return;
	}
	if (!show) {
		div.style.display = 'none';
		return;
	}
	div.style.display = 'block';
	var ex = 0;
	var ey = 0;
	
	ex = coord.x + document.body.scrollLeft;
	ey = coord.y + document.body.scrollTop;
	
	var x = coord.x + div.offsetWidth > document.body.clientWidth - 24 ? ex - div.offsetWidth - 10 : ex + 10;
	var y = coord.y + div.offsetHeight > document.body.clientHeight - 24 ? ey - div.offsetHeight - 10 : ey + 10;
	if (x < 0 ) x = ex - div.offsetWidth/2;
	if (x < 7 ) x = 7;
	if (x > document.body.clientWidth - div.offsetWidth - 24) {
		x= document.body.clientWidth - div.offsetWidth - 24;
	}
	div.style.left = x;
	div.style.top = y;
	return;
}


function artifactAltUI(id,show) {
	var div = gebi('AA_'+id);
	if (!div) return;
	if (!show) {
		
		div.style.display = 'none';
		return;
	}
	div.style.display = 'block';
	var ex = coord.x + document.body.scrollLeft;
	var ey = coord.y + document.body.scrollTop;
	var x = coord.x + div.offsetWidth > document.body.clientWidth - 24 ? ex - div.offsetWidth - 10 : ex + 10;
	var y = coord.y + div.offsetHeight > document.body.clientHeight - 24 ? ey - div.offsetHeight - 10 : ey + 10;
	if (x < 0 ) x = ex - div.offsetWidth/2;
	if (x < 7 ) x = 7;
	if (x > document.body.clientWidth - div.offsetWidth - 24) {
		x= document.body.clientWidth - div.offsetWidth - 24;
	}
	//document.title="["+coord.x+" : "+coord.y+"] ["+(document.body.scrollLeft)+":"+(document.body.scrollTop)+"] ["+(div.offsetWidth)+" : "+(div.offsetHeight)+"] ["+x+":"+y+"]";
	
	div.style.left = x;
	div.style.top = y;
}


function artifactAltGet(id){
	var rnd = Math.floor(Math.random()*1000000000);
	top.window.top.frames['main_frame'].frames['AJAX'].location.href = "ajax.php?action=artifactAltGet&param[id]="+id+"&no_cache="+rnd;
}

function artifactAltDelete(id){
	var rnd = Math.floor(Math.random()*1000000000);
	top.window.top.frames['main_frame'].frames['AJAX'].location.href = "ajax.php?action=artifactAltDelete&param[id]="+id+"&no_cache="+rnd;
}

function artifactAltReload(){
	var rnd = Math.floor(Math.random()*1000000000);
	top.window.top.frames['main_frame'].frames['AJAX'].location.href = "ajax.php?action=artifactAltReload&no_cache="+rnd;
}

function refreshEvent (id) { document.location.href = 'user_event.php?mode=events&event_id='+id; }
function enterGreatFights () { document.location.href = 'area_fights.php?mode=great'; }

function common_is_email_valid(email,all) {
	if (!email && !all) {
		return true;
	}
	var re = '';
	if (all) {
		re = /^([A-z0-9_\-]+\.)*[A-z0-9_\-]+@([A-z0-9][A-z0-9\-]*[A-z0-9]\.)+[A-z]{2,4}$/i;
	} else {
		re = /^([A-z0-9_\-]+\.)*[A-z0-9_\-]+(@)?([A-z0-9][A-z0-9\-]*[A-z0-9]\.)*(\.)?[A-z]{0,4}$/i;
	}
	if (!re.test(email)) {
		return false;
	}
	return true;
}

function petAlt(obj, evnt, show) {
	var div = gebi(obj.getAttribute('div_id'));
	if (!div) return;
	var act1 = obj.getAttribute('act1');
	var act2 = obj.getAttribute('act2');
	if (show == 2) {
		document.onmousemove=function(e) {petAlt(obj, e||event, 1);} ;
		div.style.display = 'block';
		if (act1 || act2) {
			_background(obj, (top.locale_path + "images/itemact-"+ act1) + (act2 +".gif"));
		}
	}
	if (!show) {
		if (act1 || act2) {
			_background(obj, 'images/d.gif');
		}
		div.style.display = 'none';
		document.onmousemove=function(){};
		return;
	}
	
	var ex = evnt.clientX + document.body.scrollLeft;
	var ey = evnt.clientY + document.body.scrollTop;

	if (act1 || act2) {
		obj.style.cursor = 'default';
		obj.onclick = (act1 != 0 ? function(){try{petAct(obj, act1)}catch(e){}} : function(){showPetInfo(obj.getAttribute('aid'), obj.getAttribute('art_id'))});
		_background(obj, (top.locale_path + "images/itemact-"+ act1) + (act2 +".gif"));
		var coord = getCoords(obj);
		var cont = gebi("item_list");
		var rel_x = (ex + cont.scrollLeft - coord.l)
		if (rel_x >= 40) {
			var rel_y = (ey + cont.scrollTop - coord.t)
			if (rel_y < 20) {
				obj.onclick = function(){showPetInfo(obj.getAttribute('aid'));}
				_background(obj, top.locale_path + 'images/itemact_info' + act2 +'.gif');
				try{obj.style.cursor = 'hand';} catch(e){}
				try{obj.style.cursor = 'pointer';} catch(e){}
			}
			if (act2 != 0 && rel_y >= 40) {
				obj.onclick = function(){try{petAct(obj, act2)}catch(e){}}
				_background(obj, top.locale_path + 'images/itemact_drop' + act2 +'.gif');
				try{obj.style.cursor = 'hand';} catch(e){}
				try{obj.style.cursor = 'pointer';} catch(e){}
			}
		}
	}
	var x = evnt.clientX + div.offsetWidth > document.body.clientWidth - 7 ? ex - div.offsetWidth - 10 : ex + 10;
	var y = evnt.clientY + div.offsetHeight > document.body.clientHeight - 7 ? ey - div.offsetHeight - 10 : ey + 10;

	if (x < 0 ) {
		x = ex - div.offsetWidth/2
	}
	if (x < 7 ) {
		x = 7
	}
	if (x > document.body.clientWidth - div.offsetWidth - 7) {
		x= document.body.clientWidth - div.offsetWidth - 7
	}

	div.style.left = x;
	div.style.top = y;
}

function fb_feed(lock_id,feed_id, data) {
	try{
		top.frames['main_frame'].wall(lock_id,feed_id, data)
	} catch(e) {}
}


function updateMount(mount_id) {
	top.frames['main_frame'].mountID = mount_id;
}

function switchSkillPanel(current, list) {
	for (i = 0; i <= list.length; ++i) {
		var item = gebi(list[i]);
		var link = gebi(list[i] + '_lnk');
		var left = gebi(list[i] + '_left');
		var right = gebi(list[i] + '_right');
		var bg = gebi(list[i] + '_bg');
		if (item) item.style.display = 'none';
		if (link) link.className = 'tbl-shp_menu-link_inact';
		if (left) left.src = 'images/tbl-shp_menu-left-inact.gif';
		if (right) right.src = 'images/tbl-shp_menu-right-inact.gif';
		if (bg) bg.className = 'tbl-shp_menu-center-inact';
	}
	for (i = 0; i <= current.length; ++i) {
		var item = gebi(current[i]);
		var link = gebi(current[i] + '_lnk');
		var left = gebi(current[i] + '_left');
		var right = gebi(current[i] + '_right');
		var bg = gebi(current[i] + '_bg');
		if (item) item.style.display = '';
		if (link) link.className = 'tbl-shp_menu-link_act';
		if (left) left.src = 'images/tbl-shp_menu-left-act.gif';
		if (right) right.src = 'images/tbl-shp_menu-right-act.gif';
		if (bg) bg.className = 'tbl-shp_menu-center-act';
	}
}



function toggle_visibility(id) {
	var obj = gebi(id);
	if (obj) {
		obj.style.display = obj.style.display=='' ? 'none' : '';
		return obj.style.display=='none';
	}
	return false;
}

function explode(str, delimeter) {
	return str ? str.split(delimeter ? delimeter : '') : [];
}

function implode(array, delimeter) {
	var str = '';
	if(array) {
		var array_length = array.length ? array.length-1 : 0;
		for(var id in array)
			str = str + array[id] + (array_length-- ? delimeter : '');
	}
	return str;
}

// Применительно к объектам Array
// IE сцуко не поддерживает Array::indexOf
function indexOf(arr, value) {
	for(var id in arr)
		if(arr[id] == value) 
			return id;
	return -1;
}

document.write('<script src="\/js\/console_log.js"><\/' + 'script>');
