
/* Раскрашивание строк таблицы прайса */



//Вызывается для события onmouseover таблицы
//делает подсветку строк таблицы при прохождении над ними мышки
//проверено в ИЕ и ФФ
function tableFlashRows(_node, _color)
{
    _node.onmouseover=function()	{}	//удаляем обработчик таблицы
    //получаем список строк и на каждую вешаем 2 обработчика
    list = _node.rows;
    for (var i = 0; i < list.length; i++) {
	list[i].onmouseover=function()	{	this.style["backgroundColor"]= _color;	}
	list[i].onmouseout=function()	{	this.style["backgroundColor"]="";	}
    }
}


//Вычисление верхнего/нижнего левого угла переданного узла. Возвращает массив [x,у]
function calcLeftCorner(_node, _calcBottom)
{
	var N=_node;
	var x=0;
	var y=_calcBottom?N.offsetHeight:0;
	while(N!=null){	
		if(isNaN(N.offsetLeft)&&isNaN(N.offsetTop))	break;
		else if(isNaN(N.offsetLeft))	y+=N.offsetTop;
		else if(isNaN(N.offsetTop))		x+=N.offsetLeft;
		else{
			x+=N.offsetLeft;
			y+=N.offsetTop;
		}
		N=N.offsetParent; 
	}
	return [x,y];
}



//Объект надо создавать ПОСЛЕ создания узлов с соответствующими ID
/*
При конструировании передается префикс ID узлов, образующих окно
Главный, объемлющий, с суфиксом _wnd. Желательно за ранее ему сказать display: none;
для тех, кто не пользует javascript
2 обязательных элемента с суфиксами _header и _body образуют заголовок и телдо окна соответственно
Не обязательный тег с суфиксом _close - на него вешается событие закрытия окна

Показ окна с помощью ф-ции show

*/
function jswindow(_prefix)
{
	this.wnd=document.getElementById(_prefix+"_wnd");
	if( !this.wnd ) return;
	with (this.wnd.style) {
		display='none';
		position='absolute';
		zIndex=99;
	}
	var ctrl=document.getElementById(_prefix+"_close");
	if( ctrl ) {
		var wnd=this.wnd;
		ctrl.style.cursor='pointer';
		ctrl.onclick=function()	{	wnd.style.display='none';	}
	}	
	this.header=document.getElementById(_prefix+"_header");
	if( !this.header) return;
	this.body=document.getElementById(_prefix+"_body");
	if( !this.body) return;
	
	this.show=function(_x, _y, _header, _body)
	{
		this.header.innerHTML=_header;
		this.body.innerHTML=_body;
		with (this.wnd.style) {
			display='block';
			left=_x;
			top=_y;
		}
	}
	
	this.hide=function()	{		this.wnd.style.display='none';	}
	
	this.repairX=function()	
	{
		var ww=document.body.clientWidth?document.body.clientWidth:window.innerWidth;
		if(	parseInt(this.wnd.style.left)+this.wnd.offsetWidth>ww )
			this.wnd.style.left=ww-this.wnd.offsetWidth;
//		alert("ww="+ww+"; offsetWidth="+this.wnd.offsetWidth+";left="+this.wnd.style.left+"/"+l);	
	}
}
				    
