var openIdShown = false;
var submenu_adj_top=1;
var submenu_adj_left=0;
var ie_top = 0;
var ie_left = 0;
var delay_hide=500;
var displayed_menu;
var browserName=navigator.appName;


function checkie() {

if (browserName=="Microsoft Internet Explorer")
 {
	//alert(document.getElementById('hl_3').style.left);
	document.getElementById('hl_2').style.bottom = '20px';
	document.getElementById('hl_3').style.bottom = '330px';
//	alert(document.getElementById('hl_3').style.bottom);
//	alert(document.getElementById('hl_2').style.bottom);
 }
 else
  {
	return;
  }
}
function showarrow(k,img) {
	//checkie();
	div = document.getElementById('news_box_frame');

	divek = div.getElementsByTagName('div');
	for (j=0;j<divek.length;j++){
		if (divek[j].className == 'active_bg') 
			divek[j].className = 'passive_bg';
		if (divek[j].className == 'floater') 
			divek[j].className = 'no_floater';
		if (divek[j].className == 'nb_img_lead') {
			divek[j].parentNode.style.display = 'none';
		}
	}	
	//alert(k.nextSibling.nextSibling.className)
	//div.className = 'nb_image_' + (k.id.match(/\d+$/));
	k.className = 'active_bg';
	document.getElementById('f' + (k.id.match(/\d+$/))).className = 'floater';
	document.getElementById('img_cat_' + (k.id.match(/\d+$/))).style.display = 'block';
	document.getElementById('img_cat_' + (k.id.match(/\d+$/))).parentNode.style.bottom = '110px'
	document.getElementById('img_lead_' + (k.id.match(/\d+$/))).style.display = 'block';
	document.getElementById('img_lead_' + (k.id.match(/\d+$/))).parentNode.style.display = 'block';
	document.getElementById('nb_table').style.backgroundImage = 'url('+img+')';
}
function toggle_btn(k,szam) {
	var elem = k;
	var lik = k.parentNode.getElementsByTagName('li');
	for (i=0;i<lik.length;i++)
	{
		lik[i].style.backgroundImage = 'url(/images/btn_off_1.png)';
		lik[i].style.color = '#646464';
	}
	if (elem.style.backgroundImage == 'url(/images/btn_off_1.png)')
	{
		elem.style.backgroundImage = 'url(/images/btn_on_1.png)';
		elem.style.color = '#ff6600';
	}
	else {
		elem.style.backgroundImage = 'url(/images/btn_off_1.png)';
		elem.style.color = '#ff6600';
	}
	var szamsztring = szam;
	var cont_div = document.getElementById('hl_content_' + szamsztring);
	//for (g=0;g<6;g++)
	//{
//		divs[g] = document.getElementById('hl_content_' + ((g+1).toString()));
//	}
	var divs = cont_div.parentNode.getElementsByTagName('div');
	for (var z=0;z<divs.length;z++)
	{
		divs[z].style.display = 'none';
	}
	cont_div.style.display = 'block';
}

function toggleOpenId() {
	var oidDiv = document.getElementById('openid_inputs');
	var openidDiv = document.getElementById('open_login');
	var habDiv = document.getElementById('hab_login');
	var loginDiv = document.getElementById('login_inputs');
	var oidLink = document.getElementById('openid_link');
	if (openIdShown) {
		oidDiv.style.display = 'none';
		loginDiv.style.display = '';
		openidDiv.style.display = 'none';
		habDiv.style.display = '';
		//oidLink.innerHTML = 'OpenID';
		//idspan.innerHTML = '<span id="hab_id">Hab</span><span id="big_id">ID</span>';
	} else {
		oidDiv.style.display = '';
		loginDiv.style.display = 'none';
		//oidLink.innerHTML = 'HabID';
		openidDiv.style.display = '';
		habDiv.style.display = 'none';
		//idspan.innerHTML = '<span id="hab_id">OpenID</span>';
	}
	openIdShown = !openIdShown;
}
function cleanupLoginInputs() {
	var input = document.getElementById('login_username');
	if (input.value == 'Felhasználónév') {
		input.value = '';
	}
	input = document.getElementById('openid_url');
	if (input.value == 'OpenID cím') {
		input.value = '';
	}
}
function toggle_ss(sender,id) {
	var elem = document.getElementById(id);
	var par = elem.parentNode;
	var tabs = par.getElementsByTagName('div');
	//alert(tabs.length);
	for (t=0;t<tabs.length;t++)
	{
		if (tabs[t].className == 'ss_btn')
		{
		tabs[t].style.backgroundImage = 'url(/images/tab_off_bg.png)';
		}
		if (tabs[t].className == 'ss_tab')
		{
		tabs[t].style.display = 'none';
		}
	}
	elem.style.display = 'block';
	sender.style.backgroundImage = 'url(/images/transparent.png)';
}

function showmenu(menuitem, menu_name) {
	if (displayed_menu!=null) {
		hidemenu();
	}
	if ($.browser.msie) {
        if (parseInt($.browser.version.substr(0,1))<8) {
            ie_top = 58;
            ie_left = 10;
        } else {
            ie_top = 4;
            ie_left = 0;
        }
	}
	clear_delayhide();
	displayed_menu = document.getElementById(menu_name);
	displayed_menu.style.position = 'absolute';
	displayed_menu.style.top = menuitem.offsetTop+menuitem.offsetHeight + ie_top + 'px';
	displayed_menu.style.left = menuitem.offsetLeft+ ie_left + 'px';


	displayed_menu.style.display = 'block';
}

function hidemenu() {
	displayed_menu.style.display='none';
	displayed_menu=null;
}

function start_delayhide() {
	delayhide=setTimeout("hidemenu()",delay_hide)
}

function clear_delayhide() {
	if (window.delayhide)
		clearTimeout(delayhide);
}

function get_position(element) {
	var tmp={top: element.offsetTop, left: element.offsetLeft};
	if (element.offsetParent!=null) {
		var tmp2=get_position(element.offsetParent.clientWidth);
		tmp.top+=tmp2.top;
		tmp.left+=tmp2.left;
	}
	return  tmp;
}
function toggleSendForm() {
	fakka = $('#send_form');
	$('#send_form').toggle('slow');
}
function openPopup(pURL,name,w,h,scrollbars,resizable)
{
	if (resizable==null) resizable=1;
	if (scrollbars==null) scrollbars=1;
	var top  = ((screen.availHeight-h)/2);
	var left = ((screen.availWidth-w)/2);
	var nyit = window.open(pURL,name,'toolbar=0,location=0,directories=0,status=0,\
		menubar=0,scrollbars='+scrollbars+',resizable='+resizable+',width='+w+',height='+h+',top='+top+',left='+left);
	nyit.focus();
	return nyit;
}
function showPrintable() {
	var divElement = $('#send_form').hide();
	openPopup('/print.html', 'printView', 800, 600, 1, 1);
	return false;
}

function loadPrintContent(openedDocument) {
	$('#cikk_title', openedDocument).html($('#cikk_title').html());
	$('#cikk_lead', openedDocument).html($('#cikk_lead').html());
	$('#cikk_content', openedDocument).html($('#cikk_content').html());
}
function validateEmail(email) {
	return email.match(/^[-_{}~.\/=?&'*+0-9a-zA-Z]+@[-.0-9a-zA-Z]+\.[0-9a-zA-Z]+$/);
}
function sendArticleToFriend() {
	var errorDiv = $('#send_error')[0];
	errorDiv.innerHTML = '';
	var errors = [];
	if (!$('#sendName').val()) {
		errors.push('Név nincs kitöltve');
	}
	if (!validateEmail($('#sendEmail').val())) {
		errors.push('Érvénytelen e-mail cím');
	}
	if (!$('#sendFriendName').val()) {
		errors.push('Barát neve nincs kitöltve');
	}
	if (!$('#sendCaptcha').val()) {
		errors.push('Captcha nincs kitöltve');
	}
	if (!validateEmail($('#sendFriendEmail').val())) {
		errors.push('Érvénytelen a barát e-mail címe');
	}
	if (errors.length > 0) {
		errorDiv.innerHTML += '<img src="/images/reg_error.png" width="36" height="36" alt="" />';
		for (var i=0; i<errors.length; i++) {
			errorDiv.innerHTML += errors[i]+'<br />';
		}
	} else {
		errorDiv.innerHTML += '<img src="/images/ajaxupdating.gif" alt="" />';
		$.post('/hu/habostorta/cikk-kuldes', {
				captcha: $('#sendCaptcha').val(),
				senderName: $('#sendName').val(), 
				senderEmail: $('#sendEmail').val(), 
				friendName:$('#sendFriendName').val(),
				friendEmail: $('#sendFriendEmail').val(), 
				url: location.pathname
			}, sendArticleResponse); 
	}
}
function sendArticleResponse(data) {
	$('#sendCaptchaImg').attr('src', '/picture2.php?id='+Math.random());
	$('#send_error').html('');
	var errorMsg = '';
	if ($('error', data).text() == 0) {
		$('#send_error').html('<strong>Levél sikeresen elküldve</strong>');
		setTimeout(
			function() {
				$('#send_form').hide('slow');
				$('#send_form #sendFriendName').val('');
				$('#send_form #sendFriendEmail').val('');
				$('#send_form #sendCaptcha').val('');
				$('#send_error').html('');
			}, 2500);
	} else {
		$('#send_error').html('<img src="/images/reg_error.png" width="36" height="36" alt="" />');
		$('errormessages > errormessage', data).each(function() {$('#send_error')[0].innerHTML += $(this).text()+'<br />'});
	}
}
function setItemHeight(itemId, itemHeight) {
	itemHeight = parseInt(itemHeight);
	$('#'+itemId).css('height', itemHeight+'px');
}
function hideItem(itemId) {
	$('#'+itemId).hide();
}
function toggleMoreRelated(relatedType) {
	$('#more_related_'+relatedType).toggle();
}
function link_to(uri) {
	newsBoxHref = $('a',uri).attr('href');
}
document.gEC = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}; 
function newspic_pos() {
	return;
	var sizer = 85;
	var leads = document.gEC('leadspan');
	var kats = document.gEC('katspan');
	var curr_a,curr_kat,curr_lead = null;
	for (j=0;j<kats.length;j++)
	{
	curr_a = leads[j].getElementsByTagName('a')[0];
	curr_kat = kats[j];
	curr_lead = leads[j];
	//alert(kats[j].style + '   -    ' + leads[j].style);
		if (leads[j].getElementsByTagName('a')[0].offsetHeight < 62)
		{ 
			/*if (navigator.appVersion.indexOf("MSIE 6")!= -1)
			{
				//alert(kats[j].offsetTop);
				kats[j].style.position = 'relative';
				kats[j].style.top = '110px';
				leads[j].style.position = 'relative';
				leads[j].style.top = '110px';
				kats[j].style.zIndex = 999999;
				leads[j].style.zIndex = 999999;
				//alert(leads[j].offsetTop);
			}
			else
			{*/
				kats[j].style.bottom = sizer-(62-leads[j].getElementsByTagName('a')[0].offsetHeight) + 'px';
				leads[j].style.float = '';
				leads[j].style.bottom = sizer-(62-leads[j].getElementsByTagName('a')[0].offsetHeight) + 'px';
				//alert(sizer-(62-leads[j].getElementsByTagName('a')[0].offsetHeight) + 'px');
			//}
		}
	}
}
$(document).ready(newspic_pos);
