function _$(id)
{ 
    if (document.getElementById(id))
	{
		return document.getElementById(id)
	} else
	{
		return false;
	}
}

function showhide(id)
{
  if (_$(id).style.display!='none')
  {
	hide(id);
  } else
  {
	show(id);
  }
}

function show(id)
{
	_$(id).style.display='block';
}

function hide(id)
{
	_$(id).style.display='none';
}

function catalog(id)
{
	sub_id_obj=document.getElementById('s'+id)
	showhide(sub_id_obj.id)

	id_obj=document.getElementById(id)

	zn_id_obj=document.getElementById('zn'+id)
	if (zn_id_obj.style.backgroundPosition=='0px 0px')
	{
		zn_id_obj.style.backgroundPosition='0px -9px'
	} else
	{
		zn_id_obj.style.backgroundPosition='0px 0px'
	}
	
}

var _BannerSample=0;

function BannerSample()
{
	showhide('T');
	showhide('L1');
	showhide('L2');
	showhide('L3');
	showhide('L4');
	showhide('B1');
	showhide('B2');

	showhide('_L2');
	showhide('_L3');
	showhide('_L4');
	showhide('_B');
//	document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop
	
	document.body.scrollTop=0;
	document.documentElement.scrollTop=0
	
}

var b_ver=new browser_check();


function aj(action, loadingShow, hideBoxShow, callback_function)
{
    method='get';
	var req = new JsHttpRequest();

	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			document.body.style.cursor = '';

			if (typeof callback_function != 'undefined')
			{
			        callback_function(req.responseJS);
			}

			return true;
		}
	}

	req.open(method, action, true);
	req.send(null);
	document.body.style.cursor = "wait";
	if (hideBoxShow) showhide('hidebox');
	if (loadingShow) showLoading();
	
}


//    AJAX.
function showLoading()
{
	if (load_div=_$('loadingBox'))
	{
		show('loadingBox');
	} else
	{
		var load_div = document.createElement("div");
		var body = document.getElementsByTagName("body")[0];
		body.appendChild(load_div);

		load_div.id = "loadingBox";
		load_div.className = "loadingBox";
		load_div.style.zIndex = 999;
		load_div.className = "loading_box";

		var load_div_img = document.createElement("img");
		load_div_img.src = '/imgs/loadingbar.gif';
		load_div.appendChild(load_div_img);

		var load_div_txt = document.createElement("span");
		load_div_txt.innerHTML = ", ...";
		load_div.appendChild(load_div_txt);
		load_div.style.display = 'block';
	}
}

function hideLoading()
{
	if (load_div=_$('loadingBox'))
	{
		hide('loadingBox');
	}
}

function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function browser_check()
{
   this.ver=navigator.appVersion;
   this.agent=navigator.userAgent;
   this.dom=document.getElementById?1:0;
   this.opera=this.agent.indexOf("Opera")>-1;
   this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera)?1:0;
   this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera)?1:0;
   this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera)?1:0;
   this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera)?1:0;
   this.ie9=(this.ver.indexOf("MSIE 9")>-1 && this.dom && !this.opera)?1:0;
   this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
   this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8||this.ie9;
   this.mac=this.agent.indexOf("Mac")>-1;
   this.moz=this.agent.indexOf("Mozilla")>-1;
   this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
   this.ns4=(document.layers && !this.dom)?1:0;
   this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);

   return this
}


// Кроссбраузерная фунФцУя по>ученУя разjероI эФрана,
// Успо>ьзуется I фунФцУУ ShowLoadingScreen.
function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	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 = xScroll;
	}
	else
	{
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

// ФунФцУя отображенУя бо>ьшоп ФартУнФУ I спУсФах прУ наIеденУУ
function ShowInfo(img,evt)
{

var b_ver=new browser_check();

if (b_ver.ie)
{
      mouse_x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
      mouse_y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
} else
{

      mouse_x=(b_ver.ns4 || b_ver.ns6)?evt.pageX:event.x||event.clientX
      mouse_y=(b_ver.ns4 || b_ver.ns6)?evt.pageY:event.y||event.clientY
}
	var d=document.getElementById(img);
	if(!d)
        {
          d=document.createElement("div");
          document.body.insertBefore(d,document.body.firstChild)
	  d.id=img;
	  d.className="showInfoImg";
	  d.style.position='absolute';
//	  d.style.width='100%';
//	  d.style.height='100%';
	  d.style.border='1px solid #ccc';
	  d.style.background='#fff';
	  d.style.zIndex='120';
	
	  d.innerHTML='<img src="'+img+'">';
        } else
        {
          d.style.display='block';
        }
d.style.left=(mouse_x+20)+'px';
d.style.top=(mouse_y-120)+'px';

}

function HideInfo(img)
{
document.getElementById(img).style.display='none';
}


//ФунФцУя обратного IызоIа. ВстаIФа I готоIып б>оФ
function cb_function_resToBox(responseJS)
{
	if (typeof responseJS != 'undefined')
	{
		hideLoading();
		if (responseJS.result != 'undefined')
		{

			resp=document.getElementById(responseJS.box);
			resp.innerHTML=responseJS.result;
			show(responseJS.box);
//			runScripts(resp.getElementsByTagName('SCRIPT'));
			detectJS(resp.innerHTML)
		}
	}
}

//ФунФцУя обратного IызоIа. ВстаIФа I готоIып б>оФ
function cb_function_resToBox2(responseJS)
{
	if (typeof responseJS != 'undefined')
	{
		hideLoading();
		if (responseJS.result != 'undefined')
		{
			resp=document.getElementById(responseJS.box);
			resp.innerHTML=responseJS.result;
			show(responseJS.box);

			detectJS(resp.innerHTML)
		}
	}
}

//ФунФцУя обратного IызоIа. ВстаIФа I готоIып б>оФ
function cb_function_resAddToBox(responseJS)
{
	if (typeof responseJS != 'undefined')
	{
		hideLoading();
		if (responseJS.result != 'undefined')
		{

			resp=document.getElementById(responseJS.box);
			resp.innerHTML=resp.innerHTML+responseJS.result;
			show(responseJS.box);

			detectJS(resp.innerHTML)
		}
	}
}

//ФунФцУя обратного IызоIа. ВстаIФа I готоIып б>оФ
function cb_function_resAddToBox2(responseJS)
{
	if (typeof responseJS != 'undefined')
	{
		hideLoading();
		if (responseJS.result != 'undefined')
		{

			resp=document.getElementById(responseJS.box);
			resp.innerHTML=resp.innerHTML+responseJS.result;
			show(responseJS.box);

			detectJS(resp.innerHTML)
		}
	}
}


detectJS = function(code)
{
  matchAllJS=/<script.*?>((\n|\r|.)*?)<\/script>/img

  var js_code=code.match(matchAllJS) || []

  if (js_code.length)
  {
    for(var i = 0; i < js_code.length; i++)
    {
      js_code[i]=js_code[i].replace(/<script.*?>/img, '');
      js_code[i]=js_code[i].replace(/<\/script>/img, '');

      _execScript(js_code[i])
    }
  }
}

function _execScript(text)
{
  if (!text)
    return;

    var script = document.createElement('script');

    script.setAttribute('type', 'text/javascript');
    script.setAttribute('language', 'JavaScript');
    if (b_ver.ie)
      script.text = text;
      else
      script.appendChild( document.createTextNode( text ) );


    if (b_ver.ie)
    {
      var head = document.getElementsByTagName("head")[0] || document.documentElement;
      head.insertBefore( script, head.firstChild );
//   head.removeChild( script );

//     document.getElementsByTagName("head")[0].appendChild(script)
    } else
    {

      var head = document.getElementsByTagName("head")[0] || document.documentElement;
      head.insertBefore( script, head.firstChild );
      head.removeChild( script );
//         document.body.appendChild(script)

    }

  return;
}

