function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}



function rss_form(){

	var rss_form = document.getElementById('rss_form');
	var isIE = ((navigator.userAgent.indexOf("MSIE") != -1) && (navigator.userAgent.indexOf("Opera") == -1)); 
	var sel = document.getElementById('search_in');

	if (rss_form.style.display == 'block')
	{
		rss_form.style.display = 'none';
		//if (isIE)
		//{
			sel.style.visibility = 'visible';
		//}
		try {
			document.getElementById('in_submit').style.visibility = 'visible';	
		} catch (e) {}
	}
	else {
		rss_form.style.display = 'block';
		//if (isIE)
		//{
			sel.style.visibility = 'hidden';
		//}
		try {
			document.getElementById('in_submit').style.visibility = 'hidden';	
		} catch (e) {}
	}
}

function check_rss_form(err_msg) {
	
    var container = document.getElementById('rss_groups');
    if(!container) { return false; }
    var inputFields = container.getElementsByTagName('INPUT');
    objTotal = inputFields.length;
    for (i = 0; i < objTotal; i++) {
        if (inputFields[i].checked) {
            return true;
        }
    }
    alert(err_msg);
	return false;
}

function news_list(news_item, border) {
	if (!border) {
		$(news_item).next().addClass('no_border');
		news_item.style.backgroundColor='#d9e3ec';
		news_item.style.cursor='pointer';
	}
	else {
		$(news_item).next().removeClass('no_border');
		news_item.style.backgroundColor='#ffffff';
		news_item.style.cursor='';
	}
}

function getElementWidth(Elem) {

	xPos = Elem.offsetWidth;
	return xPos;
}

function getElementHeight(Elem) {

	xPos = Elem.offsetHeight;
	return xPos;
}


function info_tooltip(show, parent, text) {

	var tooltip = document.getElementById('info_tooltip');
	var image = document.getElementById('info_tooltip_image');
	
	document.getElementById('info_tooltip_text').innerHTML = text;
	
	if (show && text!='') {
		parent.style.zIndex = '10';
		parent.appendChild(tooltip);
		tooltip.style.display='block';
		tooltip.style.top = (6 - getElementHeight(tooltip)/2) + 'px';
		tooltip.style.left = (getElementWidth(parent) + 10) + 'px';
		image.style.top = (getElementHeight(tooltip)/2 - 6) + 'px';
	}
	else {
		parent.style.zIndex = '1';
		tooltip.style.display='none';
	}

}

function structure_tooltip(show, parent, text_id, www) {

	var tooltip = document.getElementById('structure_tooltip');
	var image = document.getElementById('structure_tooltip_image');
	var content_container = document.getElementById('content_container');

	document.getElementById('structure_tooltip_text').innerHTML = '';
	
	if (show && text_id != 0) {
		parent.style.zIndex = '10';
		parent.appendChild(tooltip);
		tooltip.style.display='block';
		tooltip.style.bottom = '50px';
		tooltip.style.left = ((getElementWidth(parent)-getElementWidth(tooltip)) / 2) + 'px';
		image.style.left = ((getElementWidth(tooltip)) / 2 - 5) + 'px';

		content_container.style.zIndex = '4';

		$.post(www + "ajax.php", 
				{ object_id: text_id }, 
				function(data){ 
					
					var isIE5 = ((navigator.userAgent.indexOf("MSIE 5.") != -1) && (navigator.userAgent.indexOf("Opera") == -1)); 
					var isIE6 = ((navigator.userAgent.indexOf("MSIE 6.") != -1) && (navigator.userAgent.indexOf("Opera") == -1)); 
					var isIE7 = ((navigator.userAgent.indexOf("MSIE 7.") != -1) && (navigator.userAgent.indexOf("Opera") == -1)); 

					document.getElementById('structure_tooltip_text').innerHTML = data.text; 
					if (findPosY(tooltip) < 120 && (isIE5 || isIE6 || isIE7))
					{
						document.getElementById('search_in').style.visibility = 'hidden';
						document.getElementById('search').style.visibility = 'hidden';
					}
				}, 
				'json');
	}
	else {
		document.getElementById('search_in').style.visibility = 'visible';
		document.getElementById('search').style.visibility = 'visible';
		parent.style.zIndex = '1';
		tooltip.style.display='none';

		content_container.style.zIndex = '1';
	}

}


var active_structure = 0;
var active_block = 0;

function structure(event, id, isOn, link, www, text_id) {


	var toElement = null;
	if (event.relatedTarget)
	toElement = event.relatedTarget;
	else if (event.toElement)
	toElement = event.toElement;
	//while (toElement && toElement.id != submenuId)
	//toElement = toElement.parentNode;
	while (toElement && (toElement.className != 'structure_item')) {
		//alert(toElement.parentNode.className + ' | ' + toElement.parentNode.tagName);
		if (toElement && toElement.parentNode) {
			toElement = toElement.parentNode;
		}
		else {
			toElement = false;
		}
	}
	//alert(toElement);
	if (!toElement)
	{
		//alert(toElement.className);
		//alert('out of td');
	}
	else {
		isOn = true;
		if (document.getElementById('link'+id).className == 'on')
		{
			return;
		}
	}


	var block = document.getElementById('struct'+id);
	if (isOn) {
		

		// if previous does not turned off
		if (active_structure && document.getElementById('link'+active_structure).className == 'on')
		{
			document.getElementById('link'+active_structure).className = '';
			active_block.style.backgroundImage = "";
		}

		block.style.backgroundImage = "url("+www+"img/structure_item_active.gif)";
		//link.className = 'on';
		document.getElementById('link'+id).className="on";
		structure_tooltip(1, block, text_id, www);

		active_structure = id;
		active_block = block;
	}
	else {
		block.style.backgroundImage = "";
		//link.className = '';
		document.getElementById('link'+id).className="";
		structure_tooltip(0, block, 0, www);
	}

}

