function calendar_click(url, obj){

	$('.days a').attr('class', 'cell'); 
	obj.attr('class', 'cell a');
	PageClass.getPageContent(url, 'calendar_day_hours');
}


$(document).ready(function () { 
	$('a[rel]').lightBox(); 
	
	//$('#tarzanas').animate({ height:"564px", left:"300px" }, 3000, "linear", function(){ $('#tarzanas').animate({height:"0px", left:"1000px"}, 3000); });
	$('#tarzanas img').animate({ left:$('#tarzanas').width()+500+"px" }, 5000, "linear", function(){ $('#tarzanas').hide(); });

	//$('embed').each(function(){ $(this).attr('wmode', 'transparent'); });
	//$('object').each(function(){ $(this).html('<param value="transparent" name="wmode" />'+$(this).html()); });
	
});


function show_rez(url, date, hour){

	PageClass.getPageContent(url+'xml.php?get=rezervacija_form&date='+date+'&hour='+hour, 'calendar_form');
	
	$('#OVERLAY').show();
	$('#WINDOW').width(570);
	$('#WINDOW').css('top','150px');
	$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
	$('#WINDOW').show();
	
}

function closeUzklausa(){
	$('#OVERLAY').hide();
	$('#WINDOW').hide();	
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function atsiliepimaiSubmit(){
	var error = 0;
	if(document.forms['atsliepimai'].elements['name_'].value==0){ 
		error = 1;
		document.forms['atsliepimai'].elements['name'].className = 'fo_text error';
	}else{
		document.forms['atsliepimai'].elements['name'].className = 'fo_text';
	}
	if(document.forms['atsliepimai'].elements['email_'].value==0){ 
		error = 1;
		document.forms['atsliepimai'].elements['email'].className = 'fo_text error';
	}else{
		document.forms['atsliepimai'].elements['email'].className = 'fo_text';
	}
	if(document.forms['atsliepimai'].elements['comment_'].value==0){ 
		error = 1;
		document.forms['atsliepimai'].elements['comment'].className = 'fo_textarea error';
	}else{
		document.forms['atsliepimai'].elements['comment'].className = 'fo_textarea';
	}
	//alert(error);
	if(error==0) document.forms['atsliepimai'].submit();
}

function submitSearchForm(url, form){
	location = url + document.forms['search'].elements['q'].value;
}

function showPostForm(obj){
	document.getElementById('NL_overlay').style.display = 'block';
	document.getElementById(obj).style.display = 'block';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}catch(e){}
}

function closePostForm(obj){
	
	clearPostForm(obj);
	
	document.getElementById('NL_overlay').style.display = 'none';
	document.getElementById(obj).style.display = 'none';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "";
	}catch(e){}
}

function clearPostForm(obj){
	document.getElementById(obj + '_form').reset();
}

function format_float(number){
	var str = new String();
	str = number + "";
	arr = str.split(/\./);
	if(arr.length>1){
		if((arr[1]).length<2)
			str = str + "0";
		if((arr[1]).length>2)
			str = Math.round(str*100)/100;
	}else{
		str = str + ".00";
	}
	return str;
}

function checkInt(x){
	var filter  = /^[0-9]*$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_email(){
	if(checkMail(document.forms['news'].elements['email'].value)) 
		document.forms['news'].submit();
	else
		alert('Neteisingai įvestas el. paštas.');
}

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_number(x)
{
	var filter  = /^([0-9])*$/;
	if (filter.test(x)) return true;
	else return false;
}

function inputFocus(field){
	if(document.getElementById(field.name + '_').value != 1) 
		field.value='';
}

function inputBlur(field, text){
	if(document.getElementById(field.name + '_').value != 1 && field.value != '') 
		document.getElementById(field.name + '_').value = 1;
	if(document.getElementById(field.name + '_').value != 1) 
		field.value = text;
}

function show_hide(id){
	var obj = document.getElementById(id);
	if(obj.style.display=='none'){
		//obj.style.visibility='visible';
		//obj.style.position='static';
		obj.style.display = 'block';
	}else{
		//obj.style.visibility='hidden';
		//obj.style.position='absolute';
		obj.style.display = 'none';
	}
	
}

function delete_item(id){
	var obj = document.getElementById('count_' + id);
	if(obj){
		obj.value = 0;
		count_item(id);
	}
	var obj_ = document.getElementById('secondlist_secondlist_' + id);
	obj_.style.display = "none";
}

function plus_item(id){
	var obj = document.getElementById('count_' + id);
	if(obj && checkInt(obj.value)){
		obj.value++;
		count_item(id);
	}
}

function minus_item(id){
	var obj = document.getElementById('count_' + id);
	if(obj){
		if(obj.value>0 && checkInt(obj.value)){
			obj.value = obj.value - 1;
			count_item(id);
		}
	}
}

function count_item(id){
	
	var obj = document.getElementById('count_' + id);
	if(checkInt(obj.value)){
		var price_obj = document.getElementById('price_' + id);
		var sum_price_obj = document.getElementById('sum_price_' + id);
		var all_price_obj = document.getElementById('all_price');
		
		var old_value = sum_price_obj.innerHTML;
		var new_value = format_float(price_obj.innerHTML * obj.value);
		sum_price_obj.innerHTML = new_value;
		var pokytis = new_value - old_value;
		var all_sum = format_float(pokytis*1 + all_price_obj.innerHTML*1);
		all_price_obj.innerHTML = all_sum;
	}
	
}


