function isIE() {
	var ua = navigator.userAgent.toLowerCase();
	return (!window.opera && navigator.vendor != 'KDE' && document.all
			&& ua.indexOf('msie') != -1 && !document.layers);
}

// xPageX r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of
// the GNU LGPL
function xPageXnoBitrixElems(e) {
	var x = 0;
	e = xGetElementById(e);
	while (e) {
		if (xDef(e.offsetLeft)) {
			x += e.offsetLeft;
		}
		e = xDef(e.offsetParent) ? e.offsetParent : null;
		if (e != null && xDef(e.className)) {
			var className = e.className;
			if (className.indexOf("bx-") > -1 || className.indexOf("bx_") > -1) {
				e = xDef(e.offsetParent) ? e.offsetParent : null;
			}
		}
	}
	return x;
}

// xPageY r4, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of
// the GNU LGPL
function xPageYnoBitrixElems(e) {
	var y = 0;
	e = xGetElementById(e);
	while (e) {
		if (xDef(e.offsetTop)) {
			y += e.offsetTop;
		}
		e = xDef(e.offsetParent) ? e.offsetParent : null;
		if (e != null && xDef(e.className)) {
			var className = e.className;
			if (className.indexOf("bx-") > -1 || className.indexOf("bx_") > -1) {
				e = xDef(e.offsetParent) ? e.offsetParent : null;
			}
		}
	}
	return y;
}

function xDisplay(e, s) {
	if (!(e = xGetElementById(e)))
		return null;
	if (e.style && xDef(e.style.display)) {
		if (xStr(s))
			e.style.display = s;
		return e.style.display;
	}
	return null;
}


function toggleTxt(srcA) {
	var contentRow = xGetElementById("txt-content");
	if (xDef(contentRow)) {
		var currentDisplayValue = xDisplay(contentRow);
		if (currentDisplayValue == 'none') {
			xDisplay(contentRow, 'table-row');
			srcA.innerHTML = 'Decrease';
		}
		else {
			xDisplay(contentRow, 'none');
			srcA.innerHTML = 'Increase';
		}
	}
	return false;
}


function xMainMenu(triggerId, menuId, mouseMargin, openEvent, shiftX, shiftY,
		definedWidth) {
	var isOpen = false;
	var trg = xGetElementById(triggerId);
	var mnu = xGetElementById(menuId);
	if (trg && mnu) {
		xAddEventListener(trg, openEvent, onOpen, false);
	}
	function onOpen() {
		if (!isOpen) {
			mnu.style.display = 'block';
			// alert(xPageY(trg) +" "+ xHeight(trg));
			if (shiftY == 0) {
				var x = xPageXnoBitrixElems(trg);
				var y = xPageYnoBitrixElems(trg) + xHeight(trg);
				if (!isIE()) {
					y = xPageYnoBitrixElems(trg) + xHeight(trg) / 2
				}

				if (definedWidth > 0) {
					var mostRightX = xScrollLeft(document.body)
							+ xWidth(document.body);
					if (x + definedWidth > mostRightX) {
						x = mostRightX - definedWidth;
					}
				}

				xMoveTo(mnu, x, y);
			} else {
				xMoveTo(mnu, xPageXnoBitrixElems(trg) + shiftX,
						xPageYnoBitrixElems(trg) + shiftY);
			}

			xAddEventListener(document, 'mousemove', onMousemove, false);
			isOpen = true;
		}
	}

	function onMousemove(ev) {
		var e = new xEvent(ev);
		if (!xHasPoint(mnu, e.pageX, e.pageY, -mouseMargin)
				&& !xHasPoint(trg, e.pageX, e.pageY, -mouseMargin)) {
			mnu.style.display = 'none';
			xRemoveEventListener(document, 'mousemove', onMousemove, false);
			isOpen = false;
		}
	}
}

function BioBlock(triggerId, menuId, mouseMargin, openEvent) {
	var isOpen = false;
	var trg = xGetElementById(triggerId);
	var mnu = xGetElementById(menuId);
	if (trg && mnu) {
		xAddEventListener(trg, openEvent, onOpen, false);
	}
	function onOpen() {
		if (!isOpen) {
			mnu.style.display = 'block';
			xMoveTo(mnu, xPageXnoBitrixElems(trg) - 3,
					xPageYnoBitrixElems(trg) - 16);
			xAddEventListener(document, 'mousemove', onMousemove, false);
			isOpen = true;
		}
	}

	function onMousemove(ev) {
		var e = new xEvent(ev);
		if (!xHasPoint(mnu, e.pageX, e.pageY, -mouseMargin)
				&& !xHasPoint(trg, e.pageX, e.pageY, -mouseMargin)) {
			mnu.style.display = 'none';
			xRemoveEventListener(document, 'mousemove', onMousemove, false);
			isOpen = false;
		}
	}
}

function xMenu1(triggerId, parentId, menuId, imgId, mouseMargin, openEvent) {
	var isOpen = false;
	var tab = xGetElementById(parentId);
	var trg = xGetElementById(triggerId);
	var mnu = xGetElementById(menuId);
	var img = xGetElementById(imgId);

	if (trg && mnu) {
		xAddEventListener(trg, openEvent, onOpen, false);
		if (img) {
			xAddEventListener(img, 'click', imgClose, false);
		}
	}

	function onOpen() {
		if (!isOpen) {
			var x = xPageXnoBitrixElems(tab);
			xMoveTo(mnu, x, xPageYnoBitrixElems(tab));
			mnu.style.display = 'block';
			tab.style.visibility = 'hidden';
			xAddEventListener(document, 'mousemove', onMousemove, false);
			isOpen = true;
		}
	}

	function onMousemove(ev) {
		var e = new xEvent(ev);
		if (!xHasPoint(mnu, e.pageX, e.pageY, -mouseMargin)
				&& !xHasPoint(trg, e.pageX, e.pageY, -mouseMargin)) {
			mnu.style.display = 'none';
			tab.style.visibility = 'visible';
			xRemoveEventListener(document, 'mousemove', onMousemove, false);
			isOpen = false;
		}

	}

	function imgClose() {
		mnu.style.display = 'none';
		tab.style.visibility = 'visible';
		xRemoveEventListener(document, 'mousemove', onMousemove, false);
		isOpen = false;

	}

}

function InputHelperIn(obj, text, normalClass) {
	// если при фокусе значение поля равно значению подсказки, то чистим его и
	// вешаем стили
	if (obj) {
		if (obj.value == text) {
			obj.value = '';
			if (normalClass) {
				obj.className = normalClass;
			}
		}
	}
}

function InputHelperOut(obj, text, helperClass) {
	// если при потере фокуса значение поля равно пустоте или значению по
	// умолчанию,
	// то пихаем в него текст подсказки и вешаем стили подсказки
	if (obj) {
		if (obj.value == '' || obj.value == text) {
			obj.value = text;
			if (helperClass) {
				obj.className = helperClass;
			}
		}
	}
}

function InputHelperCreate(obj, text) {
	// вешаем на поле эвенты. На фокус и потерю фокуса.
	if (obj) {
		obj.onfocus = function() {
			InputHelperIn(this, text, null);
		};
		obj.onblur = function() {
			InputHelperOut(this, text, null);
		};

		// первоначальный инит
		InputHelperOut(obj, text);
	}
}

function InputHelperCreateStyled(obj, text, normalClass, helperClass) {
	// вешаем на поле эвенты. На фокус и потерю фокуса.
	if (obj) {
		obj.onfocus = function() {
			InputHelperIn(this, text, normalClass);
		};
		obj.onblur = function() {
			InputHelperOut(this, text, helperClass);
		};

		// первоначальный инит
		InputHelperOut(obj, text, helperClass);
	}
}

$(document).ready(function(){
    var height = $(".inner-content").height();
    var hTop = $(".top-table").height()+57;
    var contentH = height + hTop;
    myHeight = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
    if (contentH > myHeight) {
        $(".go-up").show();
    }
    $(".content-table").each(function(){
        $(this).find("th:first").wrapInner('<div class="first-c"><div class="first-b"><div class="first-t"></div></div></div>');
        $(this).find("th").not(":first").not(":last").wrapInner('<div class="center-c"><div class="center-b"><div class="center-t"><div class="center-content"></div></div></div></div>');
        $(this).find("th:last").wrapInner('<div class="last-c"><div class="last-b"><div class="last-t"></div></div></div>');    
    });
    maxH = 0;
    $(".content-table th").each(function(){
        if($(this).height() > maxH) {
            maxH = $(this).height();
            
        }
    });
    $(".content-table th").each(function(){
        $(this).find("div:first").height(maxH);
    });
});

