// JavaScript Document
//utf8 УТФ8 кодировка lietuviškai ąčęėįšųūž

function _obj(id)
{
	if ((id != undefined)&&(id != '')) { return document.getElementById(id); } else { return ''; }
}

function _url(path)
{
	var real_link = path;
	real_link = real_link.replace(/&amp;/g,'&');
	window.location = real_link;	
}


//======================
// KOMENTARAI
//======================
var ajax = null;

function comments_loading()
{
	_obj('comments_cont').innerHTML = '<table cellspacing="5" cellpadding="0" width="100%"><tr><td align="center">'+lng_loading+'</td></tr><tr><td align="center"><img src="admin/images/loading2.gif" alt="" /></td></tr></table>';
}

function show_comments(id,sub1,sub2,page)
{
	ajax = new GLM.AJAX();
	comments_loading();
	setTimeout("get_comments("+id+","+sub1+","+sub2+","+page+");",1000);
}

function get_comments(id,sub1,sub2,page)
{
	ajax.callPage('komentarai.php?act=list&id='+id+'&sub='+sub1+'&sub2='+sub2+'&page='+page, echo_comments);
}

function echo_comments(responce)
{
	_obj('comments_cont').innerHTML = responce;
	_obj('links_cont').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:scroll(0,0);">'+lng_top+'</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:history.go(-1);">'+lng_atgal+'</a>';
}






//==========ENLARGER=============
var myWidth = 0, myHeight = 0;
function getClientSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	}
}
var scrOfX = 0, scrOfY = 0;
function getScrollXY() {
	if( typeof( window.pageYOffset ) == 'number' ) { scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; } 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; } 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; }
}

function enlarge_thumb(obj)
{
	_obj('bdy').style.overflow = 'hidden';

	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);

	getClientSize();
	getScrollXY();
	//myWidth = myWidth - 30;
	
	var img = obj.src.replace(/_thumb100/g,'');
	last_img_src = img;

	_obj('img_enlarge_bg').style.top = (scrOfY + 'px');
	_obj('img_enlarge_bg').style.left = (scrOfX + 'px');
	_obj('img_enlarge_bg').style.width = (myWidth + 'px');
	_obj('img_enlarge_bg').style.height = (myHeight + 'px');


	_obj('img_enlarge').style.top = (scrOfY + 'px');
	_obj('img_enlarge').style.left = (scrOfX + 'px');
	_obj('img_enlarge').style.width = (myWidth + 'px');
	_obj('img_enlarge').style.height = (myHeight + 'px');

	_obj('img_enlarge_bg').style.display = 'block';

	var data = '<table width="100%" height="'+myHeight+'" onclick="hide_enlarger();"><tr><td align="center" valign="middle"><img class="img_enl_border" onclick="hide_enlarger();" src="'+img+'" alt="" /></td></tr></table>';

	_obj('img_enlarge').innerHTML = data;
	_obj('img_enlarge').style.display = 'block';
	
}

function enlarge_img(path)
{
	_obj('bdy').style.overflow = 'hidden';

	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);

	getClientSize();
	getScrollXY();
	//myWidth = myWidth - 30;
	
	_obj('img_enlarge_bg').style.top = (scrOfY + 'px');
	_obj('img_enlarge_bg').style.left = (scrOfX + 'px');
	_obj('img_enlarge_bg').style.width = (myWidth + 'px');
	_obj('img_enlarge_bg').style.height = (myHeight + 'px');


	_obj('img_enlarge').style.top = (scrOfY + 'px');
	_obj('img_enlarge').style.left = (scrOfX + 'px');
	_obj('img_enlarge').style.width = (myWidth + 'px');
	_obj('img_enlarge').style.height = (myHeight + 'px');

	_obj('img_enlarge_bg').style.display = 'block';

	var data = '<table width="100%" height="'+myHeight+'" onclick="hide_enlarger();"><tr><td align="center" valign="middle"><img class="img_enl_border" onclick="hide_enlarger();" src="'+path+'" alt="" /></td></tr></table>';

	_obj('img_enlarge').innerHTML = data;
	_obj('img_enlarge').style.display = 'block';
	
}

function hide_enlarger()
{
	_obj('img_enlarge_bg').style.display = 'none';
	_obj('img_enlarge').style.display = 'none';
	_obj('bdy').style.overflow = 'auto';
	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);
}



//drop footer
function adjust_footer_position(footer_height)
{
	_obj('footer_cont').style.position = 'relative';
	_obj('footer_cont').style.top = '0px';
	var windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
	var pageHeight = 0;
	if( window.innerHeight && window.scrollMaxY ) { pageHeight = window.innerHeight + window.scrollMaxY; }
	else if( document.body.scrollHeight > document.body.offsetHeight ) { pageHeight = document.body.scrollHeight; }
	else { pageHeight = document.body.offsetHeight + document.body.offsetTop; }

	var b=document.body, e=document.documentElement;
	var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
	if (e) { esh = e.scrollHeight; eoh = e.offsetHeight; }
	if (b) { bsh = b.scrollHeight; boh = b.offsetHeight; }

	if (windowY > pageHeight)
	{
		_obj('footer_cont').style.position = 'absolute';
		_obj('footer_cont').style.top = (windowY-67)+'px';
	}
	else if (bsh > boh) 
	{
		_obj('footer_cont').style.position = 'absolute';
		_obj('footer_cont').style.top = (bsh-67)+'px';
	}
	//else { alert('not changed' + windowY + ' ' + pageHeight); }
}
