var XMLHTTP=function(){var xh; try{xh=new XMLHttpRequest();} catch(e){try{xh=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){null;}}finally{return xh;}}
var switchAjaxTab=function(id)
	{
		//alert(id.firstChild);
		var path = id.firstChild.href + '?tab=on';
		var xh=new XMLHTTP();
		var xxh=new XMLHTTP();
		if(xh)
		{	
			try{
				/*
				if (path.indexOf('?page=')>-1){
					var fname='ajax_office_details_tab.asp';
					path = path.replace("http:","")
					path=path.replace(/(\/)([\S]+)(\?[\S]*)$/, '$1'+fname+'$3')
				}*/
				//alert(path);
				xh.open('GET', path, true);
				xh.setRequestHeader("Accept-Charset","windows-1251");
				xh.onreadystatechange=function(){if(4==xh.readyState){if(xh.status<400){document.getElementById('content_container').innerHTML=xh.responseText;tab_light(id) }else{document.getElementById('content_container').innerHTML=xh.responseText;}}}
				if(xh.overrideMimeType) xh.overrideMimeType("text/html; charset=windows-1251");
				xh.send(null);

				path="/js_offices.asp";
				xxh.open('GET', path, true);
				xxh.setRequestHeader("Accept-Charset","windows-1251");
				if(xxh.overrideMimeType) xxh.overrideMimeType("text/html; charset=windows-1251");
				codeStr='';
				xxh.onreadystatechange=function(){if(4==xxh.readyState){if(200==xxh.status){codeStr=xxh.responseText; if(codeStr)eval(codeStr);}}};
				xxh.send(null);

				return false;
			}
			catch(e)
			{
				alert('s');
				return false;
			}

		}
		return true;
			
	}
var switchTab=function(id)
	{
		//alert(id.firstChild);
		var path = id.firstChild.id;
		tab_light(id);
		showhideblock(path,aRubrics);
		//alert(path)
		return true;
	}
	
//switchAjaxTab('aa');
var appeardelay = 400;
var delayshow_ajaxtab = 0;
var loaded = false;

function check_load_tab(id){
	if(!loaded){window.setTimeout(function(){check_load_tab(id)}, 100);return;}
	delay_tab(id);
}
function delay_tab_light(id){
	if(!loaded){check_load_tab(id);return;}
	if (ie4||ns6)
		delayhide0=window.setTimeout(function(){delay_ajax_write(id)},appeardelay)
}
function delay_ajax_write(id){
	delayshow_ajaxtab = window.setTimeout(function(){switchAjaxTab(id)},appeardelay);
	//switchAjaxTab(id);
}
function delay_tab(id){
	if(!loaded){check_load_tab(id);return;}
	delayshow_ajaxtab = window.setTimeout(function(){switchTab(id)},appeardelay);
}
function clearshowmenu(num){
	if (typeof window["delayshow"+num]!="undefined") clearTimeout(window["delayshow"+num]);
}
function tab_light(id){
	var tmp_class, parent, master_parent;
	parent = id.parentNode.parentNode.parentNode.parentNode;
	master_parent = id.parentNode.parentNode.parentNode.parentNode.parentNode;
//	alert(id.firstChild.href);
	for(x=0;x<master_parent.childNodes.length;x++){
		if(master_parent.childNodes[x].nodeType==1){
			tmp_class=master_parent.childNodes[x].className;
			if (tmp_class.indexOf('orange_')==0){
				master_parent.childNodes[x].className = tmp_class.replace('orange_','white_');
				if (master_parent.childNodes[x].previousSibling){
					var ps=master_parent.childNodes[x].previousSibling;
					while(ps.nodeType!=1&&ps.previousSibling)ps=ps.previousSibling;
					if (ps.nodeType==1){
						tmp_class=ps.className;
						tmp_class = tmp_class.substr(0,tmp_class.length-2);
						ps.className = tmp_class;
					}
				}
			}
		}
	}
	tmp_class = parent.className;
	parent.className = tmp_class.replace('white_','orange_');
	if(parent.previousSibling){
		ps=parent.previousSibling;
		while(ps.nodeType!=1&&ps.previousSibling)ps=ps.previousSibling;
		if(ps.nodeType==1){
			ps.className += '_b';
		}
	}
/*	if (ie4||ns6)
		delayshow0=setTimeout(function(){switchAjaxTab(id.firstChild.href)},appeardelay)*/
	
}


function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge,obj2){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		obj2.contentmeasure=obj2.offsetWidth
		if (windowedge-obj2.x < obj2.contentmeasure){
			edgeoffset=obj2.contentmeasure-obj.offsetWidth
		}
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		obj2.contentmeasure=obj2.offsetHeight
		if (windowedge-obj2.y < obj2.contentmeasure){
			edgeoffset=obj2.contentmeasure+obj.offsetHeight
			if ((obj2.y-topedge)<obj2.contentmeasure)
				edgeoffset=obj2.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}
function ShowHtmlAtCursor(o){
	//alert(o.id);
	var div = document.getElementById('detaileddiv');
	div.innerHTML=detailedArray[o.id.replace('i','l')];
	div.style.display='block';
	var Pos=absPosition(o);
	div.x = Pos.x;
	div.y = Pos.y;
	div.style.top = Pos.y - clearbrowseredge(o, "bottomedge",div) + o.offsetHeight + 'px';
	div.style.left = Pos.x - clearbrowseredge(o, "rightedge",div) + 'px';
//	alert(clearbrowseredge(o, "bottomedge",div));
}
function absPosition(obj) {
	var x = y = 0;
	var w=h='';
	var id=tag='';
	while(obj) {
		w+=obj.offsetLeft + ' : ';
		h+=obj.offsetTop + ' : ';
		id+=obj.id + ' : ';
		tag+=(1==obj.nodeType?obj.tagName :'') + ' : ';
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return {x:x, y:y, w:w, h:h, id:id, tag:tag};
}
var disappeardelay=50
var ie4=document.all
var ns6=document.getElementById&&!document.all

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}
function clearhidemenu(num){
	if (typeof window["delayhide"+num]!="undefined") clearTimeout(window["delayhide"+num]);
}

function dynamichide(e,dropmenuobj,num){
	if (ie4&&!dropmenuobj.contains(e.toElement)){
		delayhidemenu(dropmenuobj,num)
	}
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)){
		delayhidemenu(dropmenuobj,num)
	}
}

function delayhidemenu(dropmenuobj,num){
	if (ie4||ns6) window["delayhide"+num]=setTimeout(function(){hidemenu(dropmenuobj)},disappeardelay);
}

function hidemenu(dropmenuobj,e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6) dropmenuobj.style.display="none";
	}
}
