// JavaScript Document
//utf8 УТФ8 кодировка lietuviškai ąčęėįšųūž
var def_language = 'LT';
var is_modal_open = false;
var modal_over = false;

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;
ajax = new GLM.AJAX();

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)
{
	is_modal_open = true;
	_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,'');
	var img = obj.src.replace(/_small100/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 style="cursor:pointer;" 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)
{
	is_modal_open = true;
	_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 style="cursor:pointer;" 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(nocheck)
{
	if (!nocheck)
	{
		if (modal_over) return;
		is_modal_open = false;
	}
	_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); }
}




//===============================
//   TOP MENU
//===============================

var active_top_menu = -1;
var last_shown_active_top_menu = -1;
//top menu
function activate_top_mp(num)
{
	if ((active_top_menu > 0)&&(num != active_top_menu)) { disactivate_top_mp(active_top_menu); }
	last_shown_active_top_menu = num;
	if (_obj('tm_vh_'+(num))) { _obj('tm_vh_'+(num)).style.visibility = 'hidden'; }
	if (_obj('tm_vh_'+(num+1))) { _obj('tm_vh_'+(num+1)).style.visibility = 'hidden'; }
	//_obj('tmc_'+(num)).className = 'tmp_act';
	colorFade('tmc_'+(num),'background','525252','ccde02',10,20);
	//colorFade('tmc_'+(num),'color','ffffff','000000',10,20);
}

function disactivate_top_mp(num)
{
	//_obj('tmc_'+(num)).className = 'tmp';
	colorFade('tmc_'+(num),'background','ccde02','525252',40,20);
	//colorFade('tmc_'+(num),'color','000000','ffffff',10,20);
	if (_obj('tm_vh_'+(num))) { _obj('tm_vh_'+(num)).style.visibility = 'visible'; }
	if (_obj('tm_vh_'+(num+1))) { _obj('tm_vh_'+(num+1)).style.visibility = 'visible'; }

	if ((active_top_menu > 0)&&(num != active_top_menu)) { activate_top_mp(active_top_menu); }
}


// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(true) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}




//-------------------------
//smooth_scroll
//-------------------------
function currentYPosition() 
{
	// Firefox, Chrome, Opera, Safari
	if (self.pageYOffset) return self.pageYOffset;
	// Internet Explorer 6 - standards mode
	if (document.documentElement && document.documentElement.scrollTop)
	return document.documentElement.scrollTop;
	// Internet Explorer 6, 7 and 8
	if (document.body.scrollTop) return document.body.scrollTop;
	return 0;
}

function elmYPosition(eID) 
{
	if (!document.getElementById(eID)) { return 0; }
	else 
	{
		var elm = document.getElementById(eID);
		var y = elm.offsetTop;
		var node = elm;
		while (node.offsetParent && node.offsetParent != document.body) 
		{
			node = node.offsetParent;
			y += node.offsetTop;
		} 
		return y;
	}
}

function smoothScroll(eID) 
{
	var Y = currentYPosition();
	var stopY = elmYPosition(eID);
	var distance = Y - stopY;
	var steps = 5; //30;
	var time = 50;
	var x = 0;
	
	while (true)
	{
		if (  (Y - stopY)  <=  (distance / steps)  )
		{
			setTimeout("scroll(0, "+stopY+");", x);
			return;
		}
		else
		{
			Y = Y - Math.round(distance / steps);
			setTimeout("scroll(0, "+Y+");", x);
			x += time;
		}
	}
}

function page_refresh()
{
	//var sURL = unescape(window.location.pathname);
	//_url(sURL);
	//location.reload(true);
	_url(current_page_url);
}


function nustatyti_rusiavima(mp_id, budas)
{
	var key = 'rusiavimas_'+mp_id;
	var rvalue = readCookie(key);
	if (rvalue != budas)
	{
		createCookie(key,budas,7);
		page_refresh();
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function user_link(uid)
{
	_url('http://www.kinogarazas.lt/LT/a_profilis/'+uid+'/');
	//alert('clicked on user ID:'+uid);	
}



function check_rekomenduok_frm()
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(_obj('rekomenduok_frm_mail').value)) { return true; } else { alert('Įveskite teisingą el.pašto adresą!'); return false; }
}


function check_login_frm(userdef,passdef,err_msg)
{
	var ulogin = _obj('ulogin').value;
	var upass = _obj('upass').value;
	if (  (ulogin != '')&&(ulogin != userdef)&&(upass != '')&&(upass != passdef)  ) { return true; } else { alert(err_msg); return false; }
}

function check_search_frm(defval,err_msg)
{
	var search_query = _obj('search_query').value;
	if (  (search_query != '')&&(search_query != defval) ) { return true; } else { alert(err_msg); return false; }
}

function logoff()
{
	var c = new GLM.AJAX();
	c.callPage('fast.php?act=loggoff', page_refresh);
}



function adjust_main_cont_margin()
{
	if (is_modal_open) return;
	getClientSize();
	var left_pos = ((myWidth - 990-24)/2);
	if (left_pos < 0) { left_pos = 0; }
//	if (_obj('top_banner')) { _obj('top_banner').style.margin = '0px auto 0px '+left_pos+'px'; }
//	if (_obj('main_cont')) { _obj('main_cont').style.margin = '0px auto 0px '+left_pos+'px'; }
//	if (_obj('main_cont2')) { _obj('main_cont2').style.margin = '0px auto 0px '+left_pos+'px'; }
//	if (_obj('bd_bg')) { _obj('bd_bg').style.backgroundPosition = (left_pos-505)+'px 0px'; }
}


function isInteger(s) { return (s.toString().search(/^-?[0-9]+$/) == 0); }


var tikrintas_login = '';
var login_laisvas = false;
var vyksta_submit = false;


var phone = "()-+ 0123456789";
function res(t,v)
{
	var w = "";
	for (i=0; i < t.value.length; i++) 
	{
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1) { w += x; }
	}
	t.value = w;
}

function check_register_form(lang)
{
	if (!login_laisvas) 
	{
		vyksta_submit = true;
		tikrinti_login();
		return false;
	}
	
	if (def_language == 'LT')
	{
		if (_obj('inp_login').value.length < 4) 
		{ alert('Įvestas slapyvardis yra per trumpas.\nMinimalus slapyvardžio ilgis yra 4 simboliai.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value.length > 15) 
		{ alert('Įvestas slapyvardis yra per ilgas.\nMaksimalus slapyvardžio ilgis yra 15 simboliai.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		var illegalChars = /\W/;
		if (illegalChars.test(_obj('inp_login').value)) 
		{ alert('Slapyvardis turi būti sudarytas iš lotyniškos abėcėlės raidžių bei skaičių.\nLeidžiamas pabraukimo brūkšnys.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value != tikrintas_login) 
		{ alert('Pršome patikrinti ar slapyvardis nėra užimtas.'); _obj('inp_login_flag').src = 'images/field_neutral.gif'; return false; }
		
		if (!login_laisvas) 
		{ alert('Pasirinktas slapyvardis yra užimtas.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
		
		if (_obj('inp_pass').value.length < 6) 
		{ alert('Įvestas slaptažodis yra per trumpas.\nMinimalus slaptažodžio ilgis yra 6 simboliai.'); _obj('inp_pass_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_pass').value != _obj('inp_pass2').value) 
		{ alert('Įvesti slaptažodžiai nesutampa.'); _obj('inp_pass2_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass2_flag').src = 'images/field_correct.gif'; }
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (!reg.test(_obj('inp_email').value)) 
		{ alert('Įveskite teisingą el.pašto adresą!\nŠiuo paštu bus išsiųstas registracijos patvirtinimas.'); _obj('inp_email_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_email_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_name').value.length < 2) 
		{ alert('Įvestas vardas yra per trumpas.\nMinimalus vardo ilgis yra 2 simboliai.'); _obj('inp_name_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_name_flag').src = 'images/field_correct.gif'; }

		if (_obj('inp_city').value.length < 6) 
		{ alert('Įveskite teisingą telefono numerį!'); _obj('inp_city_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_city_flag').src = 'images/field_correct.gif'; }

		if (_obj('inp_kodas').value.length != 4) 
		{ alert('Įveskite kodą pavaizduotą paveikslelyje.'); _obj('inp_kodas').focus(); return false; }
	}
	if (def_language == 'EN')
	{
		if (_obj('inp_login').value.length < 4) 
		{ alert('Entered username is too short.\nMinimum length of username is 4 symbols.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value.length > 15) 
		{ alert('Entered username is too long.\nMaximum length of username is 15 symbols.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		var illegalChars = /\W/;
		if (illegalChars.test(_obj('inp_login').value)) 
		{ alert('Username should contain only latin symbols.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value != tikrintas_login) 
		{ alert('Please chack if username is not taken.'); _obj('inp_login_flag').src = 'images/field_neutral.gif'; return false; }
		
		if (!login_laisvas) 
		{ alert('Chosen username is already taken.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
		
		if (_obj('inp_pass').value.length < 6) 
		{ alert('Entered password is too short.\nMinimum length of password is 6 symbols.'); _obj('inp_pass_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_pass').value != _obj('inp_pass2').value) 
		{ alert('Entered passwords dont match.'); _obj('inp_pass2_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass2_flag').src = 'images/field_correct.gif'; }
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (!reg.test(_obj('inp_email').value)) 
		{ alert('Please enter a valid email address.\nVerification letter will be sent to your email address.'); _obj('inp_email_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_email_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_name').value.length < 2) 
		{ alert('Entered name is too short.\nMinimum length of name is 2 symbols.'); _obj('inp_name_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_name_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_city').value.length < 6) 
		{ alert('Please enter a valid telephone number!'); _obj('inp_city_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_city_flag').src = 'images/field_correct.gif'; }
	
		if (_obj('inp_kodas').value.length != 4) 
		{ alert('Please enter the secure code.'); _obj('inp_kodas').focus(); return false; }
	}
	if (def_language == 'RU')
	{
		if (_obj('inp_login').value.length < 4) 
		{ alert('Слишком короткое имя пользователя.\nМинимальная длина имя пользователя 4 символа.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value.length > 15) 
		{ alert('Слишком длинное имя пользователя.\nМаксимальная длина имя пользователя 15 символов.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		var illegalChars = /\W/;
		if (illegalChars.test(_obj('inp_login').value)) 
		{ alert('Имя пользователя должно состоять из лотинских букв и цифр.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
	
		if (_obj('inp_login').value != tikrintas_login) 
		{ alert('Проверьте занятость имя пользователя.'); _obj('inp_login_flag').src = 'images/field_neutral.gif'; return false; }
		
		if (!login_laisvas) 
		{ alert('Введённое имя пользователя занято.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return false; }
		
		if (_obj('inp_pass').value.length < 6) 
		{ alert('Слишком короткий пароль.\nМинимальная длина пароля 6 символов.'); _obj('inp_pass_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_pass').value != _obj('inp_pass2').value) 
		{ alert('Введённые пароли не совпадают.'); _obj('inp_pass2_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_pass2_flag').src = 'images/field_correct.gif'; }
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (!reg.test(_obj('inp_email').value)) 
		{ alert('Введите правильную эл. почту!\nПодтверждение регистрации будет выслано по введённому адресу.'); _obj('inp_email_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_email_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_name').value.length < 2) 
		{ alert('Слишком короткое имя.\nМинимальная длина имя 4 символа.'); _obj('inp_name_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_name_flag').src = 'images/field_correct.gif'; }
		
		if (_obj('inp_city').value.length < 6) 
		{ alert('Введите правильный номер телефона!'); _obj('inp_city_flag').src = 'images/field_failed.gif'; return false; }
		else 
		{ _obj('inp_city_flag').src = 'images/field_correct.gif'; }
	
		if (_obj('inp_kodas').value.length != 4) 
		{ alert('Введите код изабражённый на картинке.'); _obj('inp_kodas').focus(); return false; }
	}

	return true;
}

function tikrinti_login(lang)
{
	var illegalChars = /\W/;
	var login = _obj('inp_login').value;
	ajax = new GLM.AJAX();

	if (def_language == 'LT')
	{
		if (login.length < 4) { alert('Įvestas slapyvardis yra per trumpas.\nMinimalus slapyvardžio ilgis yra 4 simboliai.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
		if (illegalChars.test(login)) { alert('Slapyvardis turi būti sudarytas iš lotyniškos abėcėlės raidžių bei skaičių.\nLeidžiamas pabraukimo brūkšnys.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
	}
	if (def_language == 'RU')
	{
		if (login.length < 4) { alert('Слишком короткое имя пользователя.\nМинимальная длина имя пользователя 4 символа.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
		if (illegalChars.test(login)) { alert('Имя пользователя должно состоять из лотинских букв и цифр.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
	}
	if (def_language == 'EN')
	{
		if (login.length < 4) { alert('Įvestas slapyvardis yra per trumpas.\nMinimalus slapyvardžio ilgis yra 4 simboliai.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
		if (illegalChars.test(login)) { alert('Slapyvardis turi būti sudarytas iš lotyniškos abėcėlės raidžių bei skaičių.\nLeidžiamas pabraukimo brūkšnys.'); _obj('inp_login_flag').src = 'images/field_failed.gif'; return; }
	}
	
	_obj('tikrinti_cont').innerHTML = '<img src="images/tikriname.gif" width="84" height="21" alt="" />';
	tikrintas_login = login;
	login_laisvas = false;
	_obj('inp_login_flag').src = 'images/field_neutral.gif';
	setTimeout("tikrinti_login_ajax('"+login+"');",700);
}

function login_changed()
{
	if (_obj('inp_login').value != tikrintas_login)	{ login_laisvas = false; _obj('inp_login_flag').src = 'images/field_neutral.gif'; _obj('tikrinti_cont').innerHTML = '<!-- -->'; }
}

function tikrinti_login_ajax(login)
{
	ajax.callPage('fast.php?act=check_login&login='+escape(login), tikrinti_login_responce);
}

function tikrinti_login_responce(responce)
{
	if (responce == 'laisvas['+tikrintas_login+']')
	{
		_obj('tikrinti_cont').innerHTML = '<!-- -->';
		_obj('inp_login_flag').src = 'images/field_correct.gif';
		login_laisvas = true;
		if (vyksta_submit)
		{
			vyksta_submit = false;
			if (check_register_form()) { _obj('registracijos_forma').submit(); };
		}
	}
	else
	{
		if (def_language == 'LT') { _obj('tikrinti_cont').innerHTML = '<font class="error">Slapyvardis užimtas!</font>'; }
		if (def_language == 'RU') { _obj('tikrinti_cont').innerHTML = '<font class="error">Имя пользователя занято!</font>'; }
		if (def_language == 'EN') { _obj('tikrinti_cont').innerHTML = '<font class="error">Username taken!</font>'; }
		_obj('inp_login_flag').src = 'images/field_failed.gif';
		if (vyksta_submit)
		{
			vyksta_submit = false;
			if (def_language == 'LT') { alert('Pasirinktas slapyvardis yra užimtas.');  }
			if (def_language == 'RU') { alert('Введённое имя пользователя занято.');  }
			if (def_language == 'EM') { alert('Chosen username is taken.');  }
			return false;
		}
	}
}

var delete_user_post_redirect_to = '';
function delete_user_post(did,url)
{
	if (confirm('Ar tikrai norite ištrinti darbą?')) 
	{
		delete_user_post_redirect_to = url;
		ajax.callPage('fast.php?act=delete_user_post&did='+did, ajax_responce_eval);
	}
}

function del_user_photo (photo)
{
	ajax.callPage('fast.php?act=del_user_photo&type='+photo, ajax_responce_eval);
}

function ajax_responce_eval(responce)
{
	//alert(responce);
	eval(responce);	
}


function del_message_ang_goto_list(msg_id,redirect_url)
{
	if (confirm('Ar tikrai norite ištrinti žinutę?')) 
	{
		ajax.callPage('fast.php?act=del_user_msg&mid='+msg_id, _url(redirect_url));
	}
}

function delete_msg(msg_id)
{
	if (confirm('Ar tikrai norite ištrinti žinutę?')) 
	{
		ajax.callPage('fast.php?act=del_user_msg&mid='+msg_id, ajax_responce_eval);
	}
}

function select_msgs(msgs)
{
	var msg_ids = _obj('msg_ids').value;
	var msg_array = msg_ids.split(',');
	for (var c=0; c < msg_array.length-1; c++) 
	{
		if (_obj('msg_'+msg_array[c]))
		{
			_obj('msg_'+msg_array[c]).checked = true;
		}
	}
}

function del_selected_msgs()
{
	var msg_ids = _obj('msg_ids').value;
	var msg_array = msg_ids.split(',');
	var selected_ids = '';
	for (var c=0; c < msg_array.length-1; c++) 
	{
		if (_obj('msg_'+msg_array[c])) { if (_obj('msg_'+msg_array[c]).checked) { selected_ids+= (msg_array[c]+','); } }
	}
	if (selected_ids == '') { alert('Žinutės nepažymėtos.'); }
	else
	{
		if (confirm('Ar tikrai norite ištrinti pažymėtas žinutes?')) 
		{
			ajax.callPage('fast.php?act=del_user_msg&mid='+selected_ids, ajax_responce_eval);
		}
	}
}

function prideti_drauga(kvietymo_id)
{
	ajax.callPage('fast.php?act=prideti_drauga&kid='+kvietymo_id, ajax_responce_eval);
}


function delete_comment(msg_id)
{
	ajax.callPage('fast.php?act=delete_comment&mid='+msg_id, ajax_responce_eval);
}




var curdate = new Date()
var curr_year = curdate.getFullYear();
var curr_month = curdate.getMonth()+1;
var curr_day = curdate.getDate();

var menesiai = new Array ('','Sausis','Vasaris','Kovas','Balandis','Gegužė','Birželis','Liepa','Rugpjūtis','Rugsėjis','Spalis','Lapkritis','Gruodis');
var darbai = new Array();

function calendar_go(step)
{
	if (step > 0)
	{
		curr_month++;
		if (curr_month == 13) { curr_month = 1; curr_year++; }
	}
	else
	{
		curr_month--;
		if (curr_month == 0) { curr_month = 12; curr_year--; }
	}
	display_calendar();
}

function daysInMonth(month,year) 
{
	var dd = new Date(year, month-1, 0);
	return dd.getDate();
}

function add_date(date,url)
{
	if (darbai[date] == undefined)
	{
		darbai[date] = new Array(1,url);
	}
	else
	{
		darbai[date][0] = darbai[date][0] + 1;
	}
}

function display_calendar()
{
	var data = '';
	var days = daysInMonth(curr_month,curr_year);

	var dd = new Date(curr_year, curr_month-1, 1);
	var f_day_of_week = dd.getDay();
	if (f_day_of_week == 0) { f_day_of_week = 7; }

	for(c=1;c<f_day_of_week;c++) { data+= '<div class="day"><!-- --></div>'; }

	for(c=1;c<=days;c++)
	{
		var day = c;
		if (c < 10) { day = '0' + c; } else { day = c; }
		if (curr_month < 10) { var cdate = curr_year+'-0'+curr_month+'-'+day; }
		else { var cdate = curr_year+'-'+curr_month+'-'+day; }
		if (darbai[cdate] == undefined)
		{
			data+= '<div class="day">'+c+'</div>';
		}
		else
		{
			var tip_txt = 'Įdėtas <font class=cal_darbu>1</font> darbas';
			if (darbai[cdate][0] > 1) tip_txt = 'Įdėta <font class=cal_darbu>'+darbai[cdate][0]+'</font> darbai(-bų)<br /><font class=small>(Rodomas pirmasis)</font>';
			data+= '<div class="day_act" onmouseover="Tip(\''+ tip_txt +'\')" onmouseout="UnTip()" onclick="_url(\''+darbai[cdate][1]+'\');">'+c+'</div>';
		}
	}
	data+= '<div class="wrapper"><!-- --></div>';
	_obj('kalendorius_data').innerHTML = menesiai[curr_month]+' '+curr_year;
	_obj('kalendorius_dienos').innerHTML = data;
	//alert(curdate + ' -> '+curr_year + '.' + curr_month + '.' + curr_day);
}


//========================
// reitingavimas
//========================
function rout_darbas(did) 
{
	var real_rating = _obj('rating_'+did).value;
	for (c=1;c<=5;c++)	
	{
		if (c <= real_rating) { _obj('s_'+did+'_'+c).src = 'images/star_1.gif'; }
		else { _obj('s_'+did+'_'+c).src = 'images/star_0.gif'; }
	}
}
function sover(did,cnt) 
{
	for (c=1;c<=5;c++)	
	{
		if (c <= cnt) { _obj('s_'+did+'_'+c).src = 'images/star_1.gif'; }
		else { _obj('s_'+did+'_'+c).src = 'images/star_0.gif'; }
	}
}
function sclick(did,cnt) 
{
	var rate_ajax = new GLM.AJAX();
	rate_ajax.callPage('fast.php?act=rate_movie&rating='+cnt+'&mid='+did, ajax_responce_eval);	
}












function show_modale(url)
{
	is_modal_open = true;
	_obj('bdy').style.overflow = 'hidden';
	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);
	getClientSize();
	getScrollXY();
	
	_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 h = Math.round(myHeight/3*2);
	var h = 400;
	var data_cont = '<div class="green_box" style="width:600px; height:'+h+'px;" id="modale_cont" >&nbsp;Prašome palaukti ...</div>';
	var data = '<table width="100%" height="'+myHeight+'"><tr><td align="center" valign="middle">'+data_cont+'</td></tr></table>';

	_obj('img_enlarge').innerHTML = data;
	_obj('img_enlarge').style.display = 'block';	
	
	ajax.callPage('fast.php?act=get_content&page='+url+'&h='+h, modale_content);
}

function modale_content(responce)
{
	//alert(responce);
	_obj('modale_cont').innerHTML = responce;
	_obj('modale_cont').scrollTop = 0;
	_obj('modale_cont').scrollLeft = 0;
}















function check_post_form()
{
	if (_obj('inp_pav').value.length < 2) { alert('Norėdami išsaugoti darbą, turite įrašyti pavadinimą.'); _obj('inp_pav').focus(); return false; }
	if (_obj('inp_embed').value.length < 100) { alert('Norėdami išsaugoti darbą, turite įkelti YouTube filmuko "Embed" kodą.'); _obj('inp_embed').focus(); return false; }
	if (!_obj('inp_allow_public').checked) { alert(' Jūsų darbas bus išsaugotas, bet nepaskelbtas viešai. Darbų saraše (profilyje) jis pažymėtas pilku fonu. Norėdami paskelbti darbą viešai, turite uždėti varnelę ties "Rodyti darbą viešai", po to išsaugoti darbą.'); }
	return true;
}













function update_custom_style_controls(switcher)
{
	//alert(switcher);	
	if (switcher == 0) { _obj('white_disable_layer').style.display = 'block'; }
	else { _obj('white_disable_layer').style.display = 'none'; }
}

function last_login_failed()
{
	alert('Neteisingas slapyvardis arba slaptažodis.');	
}

function mfocus(id)
{
	_obj(id).focus();
}


function win_resize()
{
	adjust_main_cont_margin();
	if (_obj('img_enlarge').style.display == 'block')
	{
		getScrollXY();
		scroll(scrOfX+1,scrOfY+1);
		scroll(scrOfX,scrOfY);
		getClientSize();
		getScrollXY();
		_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');
	}
}

function show_sending_modale()
{
	is_modal_open = true;
	_obj('bdy').style.overflow = 'hidden';
	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);
	getClientSize();
	getScrollXY();
	
	_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 h = Math.round(myHeight/3*2);
	var data_cont = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="200" height="70" id="siunciami" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="allowFullScreen" value="false" /><param name="movie" value="images/siunciami.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="images/siunciami.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="200" height="70" name="siunciami" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	var data = '<table width="100%" height="'+myHeight+'"><tr><td align="center" valign="middle">'+data_cont+'</td></tr></table>';

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



var poll_position = -1;
function poll_init()
{
	// alert(poll_question);
	// createCookie(key,budas,7);
	var key = 'poll_'+poll_id;
	var rvalue = readCookie(key);
	if (rvalue == '1') { show_poll_results(); }
	else { show_poll_form(); }


}

function show_poll_form()
{
	poll_position = -1;
	var data = '<div class="poll_cap">Garažas <b>klausia</b></div>';
	data+= '<div class="poll_question">'+poll_question+'</div>';
	for(c=0;c<poll_answ.length;c++)
	{
		data+= '<div class="poll_answer"><input onclick="poll_clicked('+poll_answ[c][0]+');" type="radio" id="answer_'+poll_answ[c][0]+'" name="vote_group" /><label onclick="poll_clicked('+poll_answ[c][0]+');" for="answer_'+poll_answ[c][0]+'">'+poll_answ[c][1]+'</label><div class="wrapper"><!-- --></div></div>';
	}
	data+= '<div class="poll_btn"><input onclick="submit_poll();" id="poll_subm_btn" type="button" value="" /></div>';
	data+= '<div class="poll_result_link"><a class="lime" href="javascript:show_poll_results();">Noriu matyti rezulatus</a></div>';
	_obj('poll_cont').className = 'poll_cont';
	_obj('poll_cont').innerHTML = data;
}

function poll_clicked(id)
{
	_obj('answer_'+id).blur();
	poll_position = id;
}

function submit_poll()
{
	if (poll_position == -1) { alert('Pamiršai pažymėti atsakymo variantą :)'); return false; }
	_obj('poll_subm_btn').disabled = true;
	ajax.callPage('fast.php?act=poll_vote&pid='+poll_id+'&aid='+poll_position, ajax_responce_eval);
}

function show_poll_results()
{
	var bar_cont_width = 100;
	poll_position = -1;
	var data = '<div class="poll_cap">Jūsų <b>atsakymai</b></div>';
	data+= '<div class="poll_question">'+poll_question+'</div>';
	var maks = 0;
	for(c=0;c<poll_answ.length;c++) { maks+= poll_answ[c][2]; }
	for(c=0;c<poll_answ.length;c++)
	{
		if (maks == 0) { poll_answ[c][3] = 0; }
		else { poll_answ[c][3] = Math.round(poll_answ[c][2]*100/maks); }
		//bar 90 px, skaiciojam kiek px = %
		var bar_width = Math.round(poll_answ[c][3]*bar_cont_width/100);
		var bar = '<table><tr><td><div class="bar_cont"><div class="bar" style="width:'+bar_width+'px;"><!-- --></div></div></td><td style="padding-left:4px; line-height:100%;">'+poll_answ[c][3]+'%</td></tr></table>';
		data+= '<div class="poll_answer">'+poll_answ[c][1]+'<div>'+bar+'</div></div>';
	}
	if (readCookie('poll_'+poll_id) != '1') { data+= '<div class="poll_result_link"><a class="lime" href="javascript:show_poll_form();">Atgal</a></div>'; }
	else { data+= '<div class="poll_result_link"><!-- --></div>'; }
	_obj('poll_cont').className = 'poll_cont';
	_obj('poll_cont').innerHTML = data;

}

function increase_poll_answer(aid)
{
	for(c=0;c<poll_answ.length;c++)
	{
		if (poll_answ[c][0] == aid) { poll_answ[c][2] = poll_answ[c][2] + 1; break; }
	}
}








//========================
// Katalogo krepselis
//========================
var last_add2carp_product = -1;
function add_to_cart(pid,cap,count,lang)
{
	if (count == 0)
	{
		last_add2carp_product = pid;
		is_modal_open = true;
		_obj('bdy').style.overflow = 'hidden';
		getScrollXY();
		scroll(scrOfX+1,scrOfY+1);
		scroll(scrOfX,scrOfY);
		getClientSize();
		getScrollXY();
		_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 h = 400;
		var lng_cap = 'Pavadinimas';
		var lng_close = 'Uždaryti';
		var lng_txt = 'Prašome įvesti kiekį, kurį norite rezervuoti';
		var lng_btn = 'Rezervuoti';
		if (def_language == 'RU') { lng_cap ='Название'; lng_close = 'Закрыть'; var lng_txt = 'Введите колличество, которое хотите резервировать'; lng_btn = 'В корзину'; }
		if (def_language == 'EN') { lng_cap ='Title'; lng_close = 'Close'; var lng_txt = 'Please enter quantity of items'; lng_btn = 'Reserve'; }
		var table = '<table cellspacing="0" width="100%" onmouseover="modal_over=true;" onmouseout="modal_over=false;">';
		table+=     '<tr><td class="add2cart_modale_td1" colspan="2">'+lng_cap+': <b>'+cap+'</b></td><td class="add2cart_modale_td2"><a href="javascript:hide_enlarger(true);">'+lng_close+'</a></td></tr>';
		table+=     '<tr><td class="add2cart_modale_td3">'+lng_txt+'</td><td class="add2cart_modale_td4"><input onkeyup="modal_key_down(event);" type="text" id="modale_cnt" /></td><td class="add2cart_modale_td5"><a href="javascript:check_add2cart_modale('+pid+');" />'+lng_btn+'</a></td></tr>';
		table+=     '</table>';
		
		var data_cont = '<div class="add2cart_modale" id="modale_cont" >'+table+'</div>';
		var data = '<table width="100%" height="'+myHeight+'" onclick="hide_enlarger();"><tr><td align="center" valign="middle">'+data_cont+'</td></tr></table>';
	
		_obj('img_enlarge').innerHTML = data;
		_obj('img_enlarge').style.display = 'block';	
		_obj('modale_cnt').focus();
	}
	else
	{
		var pajax = new GLM.AJAX();
		pajax.callPage('fast.php?act=add2cart&pid='+pid+'&cnt='+count, update_cart_summary);
	}
}
function modal_key_down(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if ((KeyID==13)&&(last_add2carp_product > 0)) { check_add2cart_modale(last_add2carp_product); }
	if (KeyID==27) { hide_enlarger(true); }
}
function frm_cnt_add2cart(e,pid,cap)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if (KeyID==13) { add_to_cart(pid,cap,_obj('product_cnt_'+pid).value,''); }
}
function check_add2cart_modale(pid)
{
	var cnt = _obj('modale_cnt').value;
	if (cnt > 0)
	{
		hide_enlarger(true);
		add_to_cart(pid,'',cnt,'');
	}
	else { _obj('modale_cnt').focus(); }
}
function update_cart_summary(responce)
{
	eval(responce);	
	colorFade('cart_summary','background','ffffff','144768',40,30);
}
function cart_select_all()
{
	for(c=0;c<cart_product_ids.length;c++)	
	{
		_obj('product_del_'+cart_product_ids[c]).checked = true;	
	}
}
function cart_select_none()
{
	for(c=0;c<cart_product_ids.length;c++)	
	{
		_obj('product_del_'+cart_product_ids[c]).checked = false;	
	}
}
function cart_del_selected()
{
	_obj('frm_action').value = 'del_selected';
	_obj('frm').submit();
}
function cart_order()
{
	var lng_q = 'Ar tikrai norite rezervuoti pasirinktus produktus?';
	if (def_language == 'RU') { lng_q ='Вы уверенны, что хотите резервировать выбраные продукты?'; }
	if (def_language == 'EN') { lng_q ='Are you sure you want to submit your order?'; }

	if (!confirm(lng_q)) { return; }
	_obj('frm_action').value = 'order';
	_obj('frm').submit();
}
function del_single_product(pid)
{
	cart_select_none();
	_obj('product_del_'+pid).checked = true;
	_obj('frm_action').value = 'del_selected';
	_obj('frm').submit();
}
