//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// (c)2008 Art-n-Tech.com
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
cur_nn = 0;
cur_page = 0;
max_on_page = 40;
tabledata = new Array();
tabletypes = new Array();
coords_ids = coords_names = null;
menu_hiding = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
menu_showing = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
menu_hiding2 = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
page = 1;
global_pg = default_jd = '';
var tab_anyway = false;
tab_items_num = new Array();
zone_default = null;
coords_z= false;
zone_name = zone_id = null;
is_admin = false;
coords_x = new Array();
coords_y = new Array();
coords_r = new Array();
coords_alts = null;
dontresize = false;
search_dd_id = '';
_win_x = _win_y = 500;
dtr = false;
curzone_id = false;
var pins_shown = true;
var pins_s = '';
var cur_zone = 0;
var qsearch_prev = '';

var MENU_HIDE_TIME = 700;
var MMENU_SHOW_TIME = 50;
//////////////////////////////////////////////////////////////////////////////////////////////////
function GetInGameLink(type, id, name, clr) {
	
	var s;
	
	if (!clr) clr = 'a335ee';
	
	switch (type) {
		case 'item':
				s = '/script DEFAULT_CHAT_FRAME:AddMessage("'+
				    str_ingamelink_1+
					'\\124cff'+clr+'\\124H'+type+':'+id+':0:0:0:0:0:0:0\\124h['+name+']\\124h\\124r");';
				break;
				
		case 'quest':
				s = '/script DEFAULT_CHAT_FRAME:AddMessage("'+
				    str_ingamelink_1+
					'\\124cffffff00\\124H'+type+':'+id+':0:0:0:0:0:0:0\\124h['+name+']\\124h\\124r");';
				break;
			
	}

	prompt(str_ingamelink_2, s);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SwitchZone(id) { 
//	alert(window.document.getElementById('smallmap').src);
	window.document.getElementById('img_smallmap').src = 'data/maps/small/' + id + '.jpg';
	if (curzone_id) window.document.getElementById('ahref_zone_'+curzone_id).className = '';
	window.document.getElementById('ahref_zone_'+id).className = 'current_zone';
	curzone_id = id;
	DrawMapPins(id);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Array.prototype.swap=function(a, b)
{
	var tmp=this[a];
	this[a]=this[b];
	this[b]=tmp;
}


function partition(array, begin, end, pivot, field, asc)
{
	var piv=eval("array["+pivot+"]."+field);
	array.swap(pivot, end-1);
	var store=begin;
	var ix;
	for(ix=begin; ix<end-1; ++ix) {
		if (asc) {
			if (eval("array["+ix+"]."+field)<=piv){
				array.swap(store, ix);
				++store;
			}
		} else {
			if (eval("array["+ix+"]."+field)>=piv){
				array.swap(store, ix);
				++store;
			}
		}
	}
	array.swap(end-1, store);

	return store;
}

function qsort(array, begin, end, field, asc)
{
	if(end-1>begin) {
		var pivot=begin+Math.floor(Math.random()*(end-begin));

		pivot=partition(array, begin, end, pivot, field, asc);

		qsort(array, begin, pivot, field, asc);
		qsort(array, pivot+1, end, field, asc);
	}
}

function quick_sort(array, field, asc)
{
	qsort(array, 0, array.length, field, asc);
}


function SortData(field, asc) {
	
	var d = new Date()
	var t1 = d.getMilliseconds() + d.getSeconds()*1000;
	
	nn = cur_nn;
	quick_sort(tabledata[nn], field, asc);
/*	for (i=0; i<tabledata[nn].length ; i++) {
		for (j=i+1; j<tabledata[nn].length ; j++) {
			if (((asc) && (eval("tabledata[nn][i]."+field) > eval("tabledata[nn][j]."+field))) ||
				((!asc) && (eval("tabledata[nn][i]."+field) < eval("tabledata[nn][j]."+field)))) {
				aa = tabledata[nn][i]; tabledata[nn][i] = tabledata[nn][j]; tabledata[nn][j] = aa;
			}
		}
	}*/
	PutData();
	
	d = new Date()
	var t2 = d.getMilliseconds() + d.getSeconds()*1000;
//	alert(t2-t1);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PutDataTabs() {
	
	var jd = ''; 
	var nn = 0;
	var start_tbl = '<table class="tabstable"><tr>';
	var sp = 0;
	var spmax = 7;
	var maxlt = 55;
	var lt = 0;
	
	if ((tabletypes.length > 1) || (tab_anyway == true)) { 
		jd = '</tr></table>';
/*		if ((tabletypes.length > spmax)) {
			sp = tabletypes.length - spmax;
		}*/
		for (i=tabletypes.length-1; i>=0; i--) {
			lt += tabnames[tabletypes[i]].length; 
			ss = String(data_templates['tabletab']);
			while (ss.indexOf('%n') > 0) ss = ss.replace('%n', i);
			while (ss.indexOf('%s') > 0) ss = ss.replace('%s', tabnames[tabletypes[i]] + '&nbsp;(' + tab_items_num[i] +')' );
			while (ss.indexOf('%i') > 0) ss = ss.replace('%i', tabletypes[i]);
				
			jd = ss + jd;
//			if (sp > 0) {
				if ((nn++ >= spmax-1) || (lt > maxlt)) {
					nn=0; sp = 100; lt = 0; 
					jd = '</tr></table>'+start_tbl + jd;
				}
//			}
		}
		
		jd = start_tbl + jd;
	}
	
	default_jd = jd;
	document.getElementById('tabletabs').innerHTML = jd;
	
	if (tabletypes.length > 0) ChangeDataTab(0);
	
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PutPageLine() {
	
	var pg = pageline+'';
	
	if (pages > 1) {
		for (var i=1; i<=pages; i++) {
			cl = (i == cur_page+1) ? 'a_page_cur' : 'a_page';
			pp = "<a id=\"a_page_"+i+"\" class=\""+cl+"\" href=\"javascript:SwitchPage("+i+");\">" + i + "</a>";
			pg += pp + ' ' ;
		}
		pg = '<table class="pageline"><tr><td>' + pg + '</td></tr></table>';
	} else {
		pg = '';
	}
	
	global_pg = pg;
	
	document.getElementById('tabletabs').innerHTML = pg + default_jd;
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ChangeDataTab(n, dont_change_page) {
	
	cur_nn = n;
	if (dont_change_page != 1) cur_page = 0;
	PutData();
	
	for (i=0; i<tabletypes.length; i++) {
		a = (n == i) ? 1 : 0;
		if (!document.getElementById('tab_l_'+i)) continue;
		document.getElementById('tab_l_'+i).src = "img/tab_l_"+a+".png";
		document.getElementById('tab_r_'+i).src = "img/tab_r_"+a+".png";
		document.getElementById('tab_m_'+i).className  = "tabstable_cell_in2_"+a;
	}

	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SwitchPage(n) {
	//alert(document.getElementById('a_page_'+n));
/*	var obj = document.getElementById('a_page_'+n);
	if (!obj) { 
//		alert('No object #'+n); 
		return; 
	}
//	alert(obj.className);*/
	cur_page = n-1;
//	PutData();
	ChangeDataTab(cur_nn, 1);
//	obj.className = "a_page_cur";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PutData() {
	
	if (tabledata.length == 0) return;
	
	jd = ''; nn = cur_nn;
	imgs = (tabletypes[nn] == 'images'); 
	//SortData('chance_num', false);
	
	jd += "<table class=\"search_res_tbl\" cellpadding=0 cellspacing=0>";
	
	jd += "<tr class=\"search_res_row_hdr\">";
	for (i=0; i<data_headers[tabletypes[nn]].length; i++) {
		var cansort = (data_headerN[tabletypes[nn]][i] != '');
		jd += '<td class="search_res_hdr_cell';
		if (i == 0) jd += '_1st';
		jd += '"';
		if (imgs) jd += ' colspan=4';
		jd += '>';
		jd += data_headers[tabletypes[nn]][i];
		if (cansort) {
			jd += '&nbsp;';
			jd += '<a href="javascript:SortData(\'' + data_headerN[tabletypes[nn]][i] + '\', true);">';
			jd += '<img src="img/arr_up.png" width="9" height="8" border=0 />';
			jd += '</a>';

			jd += '&nbsp;';
			jd += '<a href="javascript:SortData(\'' + data_headerN[tabletypes[nn]][i] + '\', false);">';
			jd += '<img src="img/arr_down.png" width="9" height="8" border=0 />';
			jd += '</a>';
		}
		jd += '</td>';
	}
	jd += '</tr>';
	
	maxn = tabledata[nn].length;
	pages = Math.ceil(maxn/max_on_page);
	PutPageLine();
	nit = 0;
	jr = '';
	max_in_imgs = 3;
	for (i=cur_page*max_on_page; i<(cur_page+1)*max_on_page ; i++) {
		if (i >= maxn) break;
		if (tabledata[nn][i].name == 'object') continue;
		ss = String(data_templates[tabletypes[nn]]);
		nit++;

		if (tabledata[nn][i].side == '') tabledata[nn][i].side = '&nbsp;';
		if (tabledata[nn][i].rew == '') tabledata[nn][i].rew = '&nbsp;';
		if (tabledata[nn][i].type == 'undefined') tabledata[nn][i].type = '&nbsp;';
		if (tabledata[nn][i].cat == 'undefined') tabledata[nn][i].cat = '&nbsp;';

		for (jj=0; jj<4; jj++)
			ss = ss.replace('%id', tabledata[nn][i].id);
		ss = ss.replace('%name', tabledata[nn][i].name);
		ss = ss.replace('%chance', tabledata[nn][i].chance);
		ss = ss.replace('%level', tabledata[nn][i].level);
		ss = ss.replace('%side', tabledata[nn][i].side);
		ss = ss.replace('%rew', tabledata[nn][i].rew);
		ss = ss.replace('%cat', tabledata[nn][i].cat);
		ss = ss.replace('%ctp', tabledata[nn][i].ctype);
		ss = ss.replace('%img', tabledata[nn][i].img);
		ss = ss.replace('%type', tabledata[nn][i].type);
		ss = ss.replace('%src', tabledata[nn][i].src);
		ss = ss.replace('%dps', tabledata[nn][i].dps);
		ss = ss.replace('%speed', tabledata[nn][i].speed);
		
		var cls = "search_res_row" + ((i % 2 == 0) ? "" : "_odd");

		
		if (imgs) {
			last = (i+1>=(cur_page+1)*max_on_page) || (i+1 >= maxn);
			if ((last) && (nit <=max_in_imgs)) ss = ss.replace('<td', '<td colspan='+(5-nit));
			jr += ss;
			if ((nit > max_in_imgs) || last) { 
				nit = 0;
				jd += "<tr class=\"" + cls + "\" >";
				jd += jr;
				jd += "</tr>";
				jr = '';
			} else {
			}
		} else {
			jd += "<tr class=\"" + cls + "\">";
			jd += ss;
			jd += "</tr>";
		}
	}
	jd += "</table>";
	
//	alert(jd);

	document.getElementById('tabledata').innerHTML = jd + global_pg;
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function RedrawMapPins() {
	
	DrawMapPins(cur_zone);
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function DrawMapPins(zone) {
	
//	if (coords_z.length <= 1) return;
	
	if (!coords_x) return;
	if (coords_x.length == 0) return;

	if (!zone) zone = zone_default;
	cur_zone = zone;
	pins_shown = true;
//	alert(zone);
//	alert(coords_x.length);
	var s = '';
	var talt = '';
	pic_h = 309;
	var o = document.getElementById('smallmap_main');
	if ((o) && (o.className != 'small_map_size')) pic_h = 515;
	var imax = coords_x.length;
	
	for (i=1; i<imax; i++) {
//		i += 100;
//		alert(zone + ',' + coords_z[i]);
		if (coords_z.length > 1) {
			if (coords_z[i] != zone) {
//				alert('skip');
				continue;
			}
		}
//		if (i > 100) break;
		x = coords_x[i]; y = coords_y[i]; r = coords_r[i];
		tp = y / 309 * 100;
		lf = x / 463 * 100; 
		ttl = x+','+y; lnk = 'javascript:;'; 
		did = '';
		if (coords_names != null) ttl = coords_names[i];
		if (coords_alts != null) 
			talt = coords_alts[i];
		else
			talt = ttl;
		if (coords_ids != null) {
			lnk = 'npc.html?id=' + coords_ids[i];
			did = 'id="pin_npc_' +  coords_ids[i] + '" ';
		}
		
		talt = talt.replace(/'/g, "`");
//		talt = talt.replace("'", "");
		
		s += '<div '+did+'class="pin_'+r+'" x="' + x + '%" y="' + y + '%' +
			'" style="top: '+y/100*pic_h+'px; left: '+x+'%" free="false">' +
//			'" style="top: '+y+'%; left: '+x+'%" free="false">' +
			'<a href="'+lnk+'" onmousemove=AltMove() onmouseout=AltHide() ' +
			'onmouseover=\'ShowAltT("'+talt+'")\' onclick=\'dontresize=true;\'></a></div>\n'; 
//		document.write(s);
		//alert(s);
	}
	
	var oo = document.getElementById('ahref_zone_'+zone);
	if (oo) {
		name = oo.name;
	} else {
		name = zone_name; zone = zone_id;
	}

	s = 
		'<div class="div_map_links">' + 
		'<div style="top:5px; left:5px; position:absolute">'+
			'<div class="map_zone_link2"><nobr>' + name + '</nobr></div></div>'+
		'<div style="top:4px; left:4px; position:absolute">'+
			'<nobr><a onclick="dontresize=true;" class="map_zone_link" href="zone.html?id='+zone+'">'+name+'</a></nobr></div></div>'+
//		'<div style="top:5px; left:5px; position:relative" class="div_map_link" free="false">ABCDEF</div>'+
		'</div>'+
		s;
/*
	s = '<div class="div_map_links">'+
		'<div class="div_map_link" style="top:5px; left:5px" free="false">' +
			'<div class="map_zone_link2">'+name+'</div></div>' + 
	        '<div class="div_map_link" style="top:4px; left:4px" free="false">' +
			'<a class="map_zone_link" href="zone.html?id='+zone+'">'+name+'</a></div></div>' + 
			s;
*/			
//	alert(document.getElementById('map_pins_div').innerHTML);
	pins_s = s;
	if (document.getElementById('map_pins_div'))
		document.getElementById('map_pins_div').innerHTML = s;
	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function ActivateNPC(id) {
	obj = document.getElementById('pin_npc_'+id);
	obj.className = "pin_2a";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function DeactivateNPC(id) {
	obj = document.getElementById('pin_npc_'+id);
	obj.className = "pin_1";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function getY(oElement) {
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function getX(oElement) {
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
//////////////////////////////////////////////////////////////////////////////////////////////////

isDOM=document.getElementById?true:false
isOpera=isOpera5=window.opera && isDOM
isOpera6=isOpera && window.print
isOpera7=isOpera && document.readyState
isMSIE=isIE=document.all && document.all.item && !isOpera
isStrict=document.compatMode=="CSS1Compat";
if (document.documentElement && document.documentElement.scrollTop) isStrict = true;
isNN=isNC=navigator.appName=="Netscape";
isNN4=isNC4=isNN && !isDOM
isMozilla=isNN6=isNN && isDOM
//////////////////////////////////////////////////////////////////////////////////////////////////
var AltShowing=-1;

var Alts=new Array;
//////////////////////////////////////////////////////////////////////////////////////////////////
function getBody(w) {
  if (!w) w=window
  if (isStrict){
    return w.document.documentElement
  } else {
    return w.document.body
  }
}

function getWindowLeft(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return w.screenLeft
  if(isNN || isOpera) return w.screenX
}

function getWindowTop(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return w.screenTop
  if(isNN || isOpera) return w.screenY
}

function getWindowWidth(w){
  if(!w) w=window
  if(isMSIE) return getBody(w).clientWidth
  if(isNN || isOpera) return w.innerWidth
}

function getWindowHeight(w){
  if(!w) w=window
  if(isMSIE) return getBody(w).clientHeight
  if(isNN || isOpera) return w.innerHeight
}

function getDocumentWidth(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return getBody(w).scrollWidth
  if(isNN) return w.document.width
  if(isOpera) return w.document.body.style.pixelWidth
}

function getDocumentHeight(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return getBody(w).scrollHeight
  if(isNN) return w.document.height
  if(isOpera) return w.document.body.style.pixelHeight
}

function getScrollX(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return getBody(w).scrollLeft
  if(isNN || isOpera) return w.pageXOffset
}

function getScrollY(w){
	if(!w) w=window
	if(isMSIE || isOpera7) return getBody(w).scrollTop
	if(isNN || isOpera) return w.pageYOffset
}

function setScrollX(x,w){
  if(!w) w=window
  if(isMSIE || isOpera7) getBody(w).scrollLeft=x
  if(isNN || isOpera) pageXOffset=x
}

function setScrollY(y,w){
  if(!w) w=window
  if(isMSIE || isOpera7) getBody(w).scrollTop=y
  if(isNN || isOpera) w.pageYOffset=y
}


function getDocumentHeight(doc) {
	return document.body.offsetHeight;
    if (doc.all) {
        return document.body.offsetHeight;
	} else if (doc.layers)
        return document.body.document.height;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////mouse//////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var mousex = 0;
var mousey = 0;

if(isNN4) document.captureEvents(Event.MOUSEMOVE)
if(isMSIE || isOpera7){
  document.onmousemove=function(){
    mousex=event.clientX+document.body.scrollLeft
    mousey=event.clientY+document.body.scrollTop
    return true
  }
}else if(isOpera){
  document.onmousemove=function(){
    mousex=event.clientX
    mousey=event.clientY
    return true
  }
}else if(isNN4 || isMozilla){
  document.onmousemove=function(e){
    mousex = e.pageX
    mousey = e.pageY
    return true
  }  
}

//////////////////////////////////////////////////////////////////////////////////////////////////
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;
	}
	return {left:offsetLeft, top:offsetTop};
} 
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowAlt(type, id) {

	_win_x = getWindowWidth(); _win_y = getWindowHeight();
	if (!xhttp) return;

	AltShowing=1;
	el=document.getElementById('idAlt');
	el.style.top=0+"px";
	
	el.innerHTML = ajaxLoadingText;
//	el.src = "popup.html";
//	el.src  = "popup.html?type=" + type + "&id=" + id;


	xhttp.abort();
//	if (id == 14555) {
//		xhttp.open("get", "http://a.wowdata.ru/tooltip.php?type=" + type + "&id=" + id, true);
		xhttp.open("get", "a/tooltip.php?type=" + type + "&id=" + id, true);
//	} else {
//		xhttp.open("get", "popup.html?type=" + type + "&id=" + id, true);
//	}
	xhttp.onreadystatechange = myonreadystatechange;
	xhttp.send(null);

	
	el.style.display="block";
	
	AltMove();
	
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowAltT(text, w) {

	_win_x = getWindowWidth(); _win_y = getWindowHeight();
	AltShowing=1;
	el=document.getElementById('idAlt');
	el.style.top=0+"px";
	
	cl = (w) ? ' style="width:'+w+'px;text-align:justify;" ' : '';
	
	el.innerHTML = '<div class="popup" '+cl+'>'+text+'</div>';
	
	el.style.display="block";
	
	AltMove();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function AltMove() {
	AltMove_(0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function AltMoveLeft() {
	AltMove_(1);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function AltMove_(type) {
	if (AltShowing==1) { 
		
		var ssy = (isMSIE) ? getScrollY() : 0;
		//var ssx = (isMSIE) ? getScrollX() : 0;
		
		var el=document.getElementById('idAlt');
		var el2=el;//document.getElementById('idAltBox');
		scry = getScrollY();
		
		var wx = el2.clientWidth;
		var wy = el2.clientHeight;
//		if (wx < 200) wx = 200;
		//alert(wx);
		if (((wx+mousex+30)>_win_x) || (type == 1)) {
			el.style.left=(mousex-wx-10)+"px";
		} else {
			el.style.left=(mousex+15)+"px"; 
		}

		if ((wy+mousey+35)>_win_y+scry) 
			el.style.top=(_win_y-wy-10+scry)+"px";
		else 
			el.style.top=(mousey+15)+"px";
		
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function AltHide(){
	if (AltShowing==1){
		el=document.getElementById('idAlt');
		el.style.display="none";
		el.style.top=0+"px";
		AltShowing=0;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
var use_ajax = false;
var xhttp = false;
//////////////////////////////////////////////////////////////////////////////////////////////////
function get_http(){    
    var xmlhttp;    
    /*@cc_on   
    @if (@_jscript_version >= 5)   
        try {   
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");   
        } catch (e) {   
            try {   
                xmlhttp = new    
                ActiveXObject("Microsoft.XMLHTTP");   
            } catch (E) {   
                xmlhttp = false;   
            }   
        }   
    @else   
        xmlhttp = false;   
    @end @*/   
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {    
        try {    
            xmlhttp = new XMLHttpRequest();    
        } catch (e) {    
            xmlhttp = false;    
        }    
    }    
    return xmlhttp;    
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function initAjax() {

	if(!xhttp){
		xhttp = get_http();
		use_ajax = true;
	}
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function myonreadystatechange() {
//	alert(xhttp.readyState);

	obj = window.document.getElementById('idAlt');


//alert  (xhttp.readyState);
	switch (xhttp.readyState) {
		case 1: 
//			obj.innerHTML = ajaxLoadingText;
			break;
			
		case 4: //complete
			var s = xhttp.responseText;
			if (s.indexOf('<body>')) s = s.substr(s.indexOf('<body>')+6);
			if (s.indexOf('</body')) s = s.substr(0, s.indexOf('</body'));
			obj.innerHTML = s;
			//alert(xhttp.responseText);
			break;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function myonreadystatechange_d() {
//	alert(xhttp.readyState);

	obj = window.document.getElementById(search_dd_id);

//alert  (xhttp.readyState);
	switch (xhttp.readyState) {
		case 1: 
//			obj.innerHTML = ajaxLoadingText;
			break;
			
		case 4: //complete
			var s = xhttp.responseText;
			if (s.indexOf('<body>')) s = s.substr(s.indexOf('<body>')+6);
			if (s.indexOf('</body')) s = s.substr(0, s.indexOf('</body'));
			obj.innerHTML = s;
			//alert(xhttp.responseText);
			break;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// ******************************* MENU *********************************
//////////////////////////////////////////////////////////////////////////////////////////////////
function showSubMenu(){
	var objThis = this;	

	for(var i = 0; i  < objThis.childNodes.length; i++)
	{
		if(objThis.childNodes.item(i).nodeName == "UL")			
		{							
			objThis.childNodes.item(i).style.display = "block";						
		}		
	}	
}

function hideSubMenu()
{								
	var objThis = this;	
	
	for(var i = 0; i  < objThis.childNodes.length; i++)			
	{
		if(objThis.childNodes.item(i).nodeName == "UL")
		{				
			objThis.childNodes.item(i).style.display = "none";			
			return;
		}			
	}	
}			

function initialiseMenu()
{
	var objLICollection = document.body.getElementsByTagName("LI");		
	for (var i = 0; i < objLICollection.length; i++) {		
		var objLI = objLICollection[i];										
		for (var j = 0; j  < objLI.childNodes.length; j++) {
			if (objLI.childNodes.item(j).nodeName == "UL") {
				objLI.onmouseover=showSubMenu;
				objLI.onmouseout=hideSubMenu;
				
				for (var j = 0; j  < objLI.childNodes.length; j++) {
					if (objLI.childNodes.item(j).nodeName == "A") {					
						objLI.childNodes.item(j).className = "hassubmenu";								
					}
				}
			}
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function InitAll() {
//	initialiseMenu();
	//dbMenu.init();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
var menu_over = false;
var menu_sub_over = false;
//var smenup = null;
var menu_shown = false;
var menu_dont_hide = false;
//////////////////////////////////////////////////////////////////////////////////////////////////
function DebugPrint(s) {
	return;
	if (!is_admin) return; 
	Stamp = new Date();
	document.getElementById('debugdiv').innerHTML += 
		Stamp.getHours() + ':' + Stamp.getMinutes() + ':' + Stamp.getSeconds() 
		+ ' - ' + s + "<br>\n";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenu(n, prnt) {
	DebugPrint('ShowMenu('+n+')');
	menu_hiding2[n] = 0;
	//menu_dont_hide = false;
	//smenup = prnt;
	x = getX(prnt); y = getY(prnt);
	menu_dont_hide = !true;
	HideMenuMain();
	if (menu_over) {
/*		for (var i=0; i<=10; i++) { 
			menu_hiding[i] = 1; HideMenuMainItem(i);
		}*/
		ShowMenu2(n, prnt);
		return;
	}
//	alert("ShowMenu2('"+n+"', '"+prnt+"');");
//	setTimeout("ShowMenu3("+n+", "+getX(prnt)+", "+getY(prnt)");", MMENU_SHOW_TIME);
	menu_hiding2[n] = menu_hiding[n] = 0;
	setTimeout("ShowMenu3("+n+", "+x+", "+y+");", MMENU_SHOW_TIME);
//	ShowMenu3(n, x, y);

}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenu2(n, prnt) {
	ShowMenu2_y(n, prnt, 0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenuS2(n, prnt) {
	ShowMenuS2_y(n, prnt, 0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenu2_y(n, prnt, y) {
	DebugPrint('ShowMenu2('+n+')');
	var ps = String(n).indexOf('_');
	if (ps > 0) {
		var mmenu = String(n).substr(0, ps);
		menu_hiding[mmenu] = 0;
	}
	ShowMenu3(n, getX(prnt), getY(prnt)+y);
	HideSubSubMenus(1);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenuS2_y(n, prnt, y) {
	DebugPrint('ShowMenuS2('+n+')');
	var ps = String(n).indexOf('_');
	if (ps > 0) {
		var mmenu = String(n).substr(0, ps);
//		menu_hiding[mmenu] = 0;
	}
	ShowMenuS3(n, getX(prnt), getY(prnt)+y);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenu3(n, xx, yy) {
	DebugPrint('ShowMenu3('+n+')');
	if 	(menu_hiding2[n] == 1) { menu_hiding2[n]=0; return; }
	var ps = String(n).indexOf('_');
	var submenu = ps > 0;
	var dx; var dy;

	var obj = document.getElementById('menu_' + n);

	if (submenu) {
		//if (obj) menu_sub_over = true;
		cur_submenu = n;
		var mmenu = String(n).substr(0, ps);
		dx = 222; dy = 0;
		HideSubMenus(mmenu); 
	} else {
		menu_over = true; 
		menu_sub_over = false;
		cur_menu = n; menu_hiding[n] = 0;
		HideMenuMain();
		dy = 20; dx = 0;
		menu_showing[n] = 1;
	}
	
	if (!obj) return;
	obj.style.display = 'block';
	obj.style.left = (xx+dx)+"px"; obj.style.top = (yy+dy)+"px";
	menu_shown = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShowMenuS3(n, xx, yy) {
	//DebugPrint('ShowMenuS3('+n+')');
	//if 	(menu_hiding2[n] == 1) { menu_hiding2[n]=0; return; }
	var ps = String(n).indexOf('_');
	var submenu = true;
	var dx; var dy;

	var obj = document.getElementById('menu_' + n);

	//if (obj) menu_sub_over = true;
	cur_submenu = n;
	mmenu = String(n).substr(0, ps);
	dx = 222; dy = 0;
	HideSubSubMenus(mmenu); 

	if (!obj) return;
	obj.style.display = 'block';
	obj.style.left = (xx+dx)+"px"; obj.style.top = (yy+dy)+"px";
	menu_shown = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideMenuItem(n) {
	//DebugPrint('HideMenuItem('+n+')');
//	if (!menu_showing[n]) return;
	var obj = document.getElementById('menu_' + n);
	if (!obj) return;
	obj.style.display = 'none';
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideMenu(n, prnt) {
	//DebugPrint('HideMenu('+n+')');
	menu_hiding[n] = 1;
	menu_hiding2[n] = 1;
//	alert(n+ '<br>');
	if (!menu_over) { smenup = null; return; }
//	alert('del');
	setTimeout("HideMenuMainItem("+n+", 1);", 500);
/*	if (submenu) {
		HideSubMenus(mmenu);
	} else {*/
//	}
	 
//	setTimeout("CheckHideMenuMain();", 500);
	//OutMenu(n);
/*	var ps = String(n).indexOf('_');
	var submenu = ps > 0;
	
	if (submenu) {
		menu_sub_over = false; //alert('sub false '+n);
	} else {
		menu_over = false;
	}
	
	setTimeout("CheckHideMenuMain();", 500);
*/			   
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function CheckHideMenuMain() {
	
	if (menu_sub_over) return;
	if (menu_over) return;
	HideMenuMain();
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideMenuMainItem(i, auto) {
	//DebugPrint('HideMenuMainItem('+i+', '+auto+')');
	//if (!menu_showing[i]) return;
	menu_showing[i] = 0;
	if (auto == 1) {
		if (menu_hiding[i] == 0) { DebugPrint('don\'t hide'); return; }
		//if (n == cur_menu) return;
	}
	var obj = document.getElementById('menu_' + i);		
	if (!obj) return;
	if (obj.style.display == 'none') return;
	obj.style.display = 'none';
	HideSubMenus(i);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideMenuMain() {
	DebugPrint('HideMenuMain()');
	if (menu_dont_hide) { menu_dont_hide = false; return; }
	for (var i=1; i<=10; i++) {
		HideMenuMainItem(i);
	}
	HideSubSubMenus(1);
	smenup = null; menu_shown = false; menu_dont_hide = false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideSubMenus(n) {
	DebugPrint('HideSubMenus('+n+')');
	for (var i=1; i<=40; i++) {
		var obj = document.getElementById('menu_' + n + '_' + i);
		if (!obj) continue;
		if (obj.style.display == 'none') continue;
		obj.style.display = 'none';
		//HideMenuItem(i);
	}
	HideSubSubMenus(1);
	menu_shown = false; menu_dont_hide = false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function HideSubSubMenus(n) {
	DebugPrint('HideSubSubMenus('+n+')');
	for (var i=1; i<=10; i++) {
		var obj = document.getElementById('menu_' + n + '__' + i);
		if (!obj) continue;
		obj.style.display = 'none';
		//HideMenuItem(i);
	}
	menu_shown = false; menu_dont_hide = false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function OverMenu(o) {
	DebugPrint('OverMenu('+o.id+')');
	menu_dont_hide = true;
	var submenu = String(o.id).substr(5).indexOf('_') > 0;
	if (submenu) {
		menu_sub_over = true; //alert('sub true');
		menu_over = false;
	} else {
		var ps = String(o.id).indexOf('_');
		if (ps > 0) {
			var mmenu = String(o.id).substr(ps+1);
//			alert(mmenu);
			menu_hiding[mmenu] = 0;
		}
		menu_over = true; 
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////

function OutMenu(o) {
	
	DebugPrint('OutMenu('+o.id+')');
	var submenu = String(o.id).substr(5).indexOf('_') > 0;
	if (submenu) {
		menu_sub_over = false;
		setTimeout("CheckHideMenuMain();", MENU_HIDE_TIME);
	} else {
		menu_over = false;
		setTimeout("CheckHideMenuMain();", MENU_HIDE_TIME);
	}
	//alert("sub:"+submenu + " subover:" + menu_sub_over + ", over:" + menu_over);
		
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
function CreateFilter() {
	if (document.getElementById('filter').style.display == 'block') {
		document.getElementById('filter').style.display = 'none'; return;
	}
	if ((ctt != '') || (ct != '')) {
		document.getElementById('dopfilter_1').style.display = 'none';
		document.getElementById('dopfilter_2').style.display = 'none';
	}
	document.getElementById('filter').style.display = "block";						
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function InsertLink(textid, type) {
	
	var stype;
	
	switch (type) {
		case 'z': stype = str_of_zone; break;
		case 'i': stype = str_of_item; break;
		case 'q': stype = str_of_quest; break;
		case 'n': stype = str_of_npc; break;
		case 's': stype = str_of_spell; break;
		default: return;
	}
	
	var id = prompt(str_input_id+stype, "");
	if (!id) return;
	if (id*1 != id) {
		alert(str_wrong_id); return;
	}
	document.getElementById(textid).value += "{" + type + "," + id + "}";
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function InsertLinkZoneCoords(textid) {
	var id = prompt(str_input_id+str_of_zone, "");
	if (!id) return;
	if (id*1 != id) {
		alert(str_wrong_id); return;
	}
	var x = prompt(str_input_+"X", "");
	if (x*1 != x) {
		alert(str_wrong_coord); return;
	}
	var y = prompt(str_input_+"Y", "");
	if (y*1 != y) {
		alert(str_wrong_coord); return;
	}
	document.getElementById(textid).value += "{z," + id + "," + x + "," + y + "}";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ToggleMap() {
	
	if (dontresize) return; 

	var o = document.getElementById('smallmap_main');
	
	if (o.className == 'small_map_size') {
		o.className = 'mid_map_size';
		document.getElementById('img_smallmap').src = document.getElementById('img_smallmap').src.replace('maps/small/', 'maps/');
		document.getElementById('img_smallmap').width = '771';
		document.getElementById('img_smallmap').height = '515';
	} else {
		o.className = 'small_map_size';
		document.getElementById('img_smallmap').src = document.getElementById('img_smallmap').src.replace('maps/', 'maps/small/');
		document.getElementById('img_smallmap').width = '463';
		document.getElementById('img_smallmap').height = '309';
	}
	
	RedrawMapPins();

}
//////////////////////////////////////////////////////////////////////////////////////////////////
function MapMouseMove() {
	
	var mapw = document.getElementById('img_smallmap').width;
	var maph = document.getElementById('img_smallmap').height;

	var mapx = getX(document.getElementById('img_smallmap'));
	var mapy = getY(document.getElementById('img_smallmap'))+4;
	var x = Math.round((mousex - mapx)/mapw*100);
	var y = Math.round((mousey - mapy)/maph*100);
	if (y < 0) y = 0; if (x < 0) x = 0;
	if (y > 100) y = 100; if (x > 100) x = 100;
	
	document.getElementById('div_map_coords').innerHTML = x + "," + y;

}
//////////////////////////////////////////////////////////////////////////////////////////////////
// UPLOADED IMAGE
//////////////////////////////////////////////////////////////////////////////////////////////////
var usrc_ismousedown = false;
var usrc_phase = 0;
var usrc_x1 = 0; var usrc_x2 = 0;
var usrc_y1 = 0; var usrc_y2 = 0;
var clickavail = true;
//////////////////////////////////////////////////////////////////////////////////////////////////
function UpScrChangeFrameSize() {
	var ix = getX(document.getElementById('imgup'));
	var iy = getY(document.getElementById('imgup'));
	var iw = document.getElementById('imgup').width;
	var ih = document.getElementById('imgup').height;
	if (iw <= 0) iw = 1;
	if (ih <= 0) ih = 1;
	var obj = document.getElementById('imgsel_frame');

	var xx = mousex - usrc_x1 - 1;
	var yy = mousey - usrc_y1 - 1;
	if (xx < 0) xx = 0;
	if (yy < 0) yy = 0;

	usrc_x2 = obj.style.height = yy; 
	usrc_y2 = obj.style.width = xx;
	
	document.getElementById('img_x2').value = (xx )/iw;
	document.getElementById('img_y2').value = (yy )/ih;
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function UpScrMD() {
	
	if (!clickavail) return;
	setTimeout("clickavail=true;", 50);
	clickavail = false;
	
	usrc_ismousedown = true;

	var ix = getX(document.getElementById('imgup'));
	var iy = getY(document.getElementById('imgup'));
	var iw = document.getElementById('imgup').width;
	var ih = document.getElementById('imgup').height;
	if (iw <= 0) iw = 1;
	if (ih <= 0) ih = 1;
	var obj = document.getElementById('imgsel_frame');
//	alert(usrc_phase);
	
	switch (usrc_phase) {
		case 0:
			usrc_y1 = obj.style.top = mousey; 
			usrc_x1 = obj.style.left = mousex;
			document.getElementById('img_x').value = (usrc_x1 - ix)/iw;
			document.getElementById('img_y').value = (usrc_y1 - iy)/ih;
			obj.style.height = 0; 
			obj.style.width = 0;
			obj.style.visibility = "visible";
			break;
		case 1:
			//UpScrChangeFrameSize();
//			obj.style.bottom = mousey; obj.style.right = mousex;
			break;
	}
	if (++usrc_phase > 1) usrc_phase = 0;

	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function UpScrMU() {
	usrc_ismousedown = false;
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function UpScrMMove() {
	if (usrc_phase == 1) UpScrChangeFrameSize();
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function UpScrReset() {
	document.getElementById('imgsel_frame').style.visibility = "hidden";
	usrc_x2 = usrc_y2 = 0;	
	document.getElementById('img_x2').value = document.getElementById('img_y2').value = 0;
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function SearchCh(obj, id) {
	
	var o = document.getElementById(id);
	var s = obj.value;
	search_dd_id = id;
	if (qsearch_prev == s) return;
	qsearch_prev = s;
	
	xhttp.abort();
	
	if (s.length < 3) {
		o.style.display = 'none';
	} else {
		o.style.display = 'block';
	}
	
	var lf = (id == 'srcfd_1') ? 1 : 0;
	
//	s = encodeURI(s);
//	alert(s);
	
	var params = "q=" + s + '&lf=' + lf + '&rand=' + Math.random()*10000;
	
//	if (is_admin)
		xhttp.open("get", "search/qsearch.php?"+params , true);
//	else
//		xhttp.open("get", "srch.html?"+params , true);
	
	xhttp.onreadystatechange = myonreadystatechange_d;
//	xhttp.setRequestHeader('Content-type', 'text/plain; charset=windows-1251');
//	xhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//	xhttp.setRequestHeader("Accept-Charset", "windows-1251");
//	xhttp.setRequestHeader("Content-length", params.length);
	xhttp.send(null);

	o.innerHTML = "Loading...";
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function BodyClick() {
	var o = document.getElementById('srcfd_1');
	if (o) o.style.display = 'none';
	o = document.getElementById('srcfd_2');
	if (o) o.style.display = 'none';
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function DNE(name) {
	var o = document.getElementById(name);
	if (!o) return;
	o.style.width = '0px';
	o.style.height = '0px';
	o.innerHTML =  "<div style=\"position:absolute;top:-20px;left:-63px;\"><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"80\" height=\"110\">" +
 '<param name="movie" value="img/dancing_ne.swf" />'+
  '<param name="quality" value="high" />'+ '<param name="wmode" value="transparent" />'+
 '<embed src="img/dancing_ne.swf" width="80" height="110" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed>'+ 
		'</object></div>';
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function AddFFSearchPlugin() {
/*  
   if ((typeof window.sidebar.addSearchEngine == "function") &&
		  (typeof window.sidebar == "object")) {
		  var file = "http://www.wowdata.ru/data/searchplugins/wowdata.xml";
		  var icon = "http://www.wowdata.ru/favicon.png"; 

		  window.sidebar.addSearchEngine(file,icon,"MajoRSofT search","FFPlugin");
   }
   else alert("Your browser doesn't suppoert this function.");*/
	
	window.external.AddSearchProvider('http://www.wowdata.ru/data/searchplugins/wowdata.xml');  
   
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function AddToFavs() {

	if (!isIE) return true;
	window.external.AddFavorite('http://www.wowdata.ru/','WowData.ru');
	return false;

}
//////////////////////////////////////////////////////////////////////////////////////////////////
function BJump(lnk, obj, msg) {

	document.location = lnk;
	if (msg) {
		if (obj) obj.value = "Loading...";
		document.body.innerHTML = "<br><br><br><center>"+
			"&#1054;&#1078;&#1080;&#1076;&#1072;&#1085;&#1080;&#1077; &#1086;&#1090;&#1074;&#1077;&#1090;&#1072; &#1089;&#1072;&#1081;&#1090;&#1072;...</center>";
	}

	return false;

}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ToggleHints() {
	
	dontresize = true;
	
	if (pins_shown) {
		document.getElementById('map_pins_div').innerHTML = '';
		document.getElementById('map_righttop_1').innerHTML = 
			document.getElementById('map_righttop_lnk').innerHTML = '[&#1055;&#1086;&#1082;&#1072;&#1079;&#1072;&#1090;&#1100; &#1084;&#1077;&#1090;&#1082;&#1080;]';
	} else {
		document.getElementById('map_pins_div').innerHTML = pins_s;
		document.getElementById('map_righttop_1').innerHTML = 
			document.getElementById('map_righttop_lnk').innerHTML = '[&#1059;&#1073;&#1088;&#1072;&#1090;&#1100; &#1084;&#1077;&#1090;&#1082;&#1080;]';
	}
	pins_shown = !pins_shown;
	
	setTimeout("dontresize = false;", 10);


	return false;

}
//////////////////////////////////////////////////////////////////////////////////////////////////

// 234324242423423423
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////