function popup(url){
	features = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=490,height=500";
	window.open("/custom/scripts/popup.php?f="+url,"Nuotrauka",features);
}
function body_onload(){
	if (document.getElementById('isearch')){
		document.getElementById('isearch').focus();
	}
}
function swapPairs(s){
    var res = "";
    for (var i=0; i<s.length; i++){
         var ch = s.charCodeAt(i) ;
         res += String.fromCharCode(
            ( ch & 0xF0 ) +
            ((ch & 0x0C)>>2) +
            ((ch & 0x03)<<2)
         );
    }
    return res;
}

// Add to favorites/bookmarks/hotlist

function add2fav() {
 title = document.title; 
 url = location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if (window.opera && window.print) { // Opera Hotlist - nerabotajit?!
		return true; }
 }

function body_load(){
	if (typeof(load)=='function'){
		load();
	}
}

function unload(){
	if (typeof(GUnload)=='function'){
		GUnload();
	}
}

function update_regions(cid){
	bajax.include('region_id','/custom/console/resselers.php?cid='+cid);
}

/* start sodybos uzsakymas */
$(function()
{
	$("#orderform").submit(function() {
		$.post('/custom/blocks/sodybos_uzsakymas/send.php', $(this).serialize(), function(html){$("#responce").html(html)});
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#fff9ee', color: '#000' }, 2000);
		return false;
	});
	
	$("#want_food").click(function(){
		$(".maistas_atitrauktas").show();
	});
	$("#no_food").click(function(){
		$(".maistas_atitrauktas").hide();
	});
	reloadcalclick();
});

function pg($page){
	$("#cal").load(window.location.href+"/?page=" + $page + " #cal");
	$("#cal").ajaxStart(function(){
		$("#guestbook_loadingStatus").html('<img width="60" src="/images/loading.gif" />');
	});
	$("#cal").ajaxStop(function(){
		$("#guestbook_loadingStatus").html('');
		reloadcalclick();
	});
}

function reloadcalclick(){
	$(".kalendorius td").click(function(){
		$number = $(this).find("span").html();
		if ($number==null){
			$number = $(this).html();
		}
		if ($number=="&nbsp;"){
			$number = 1;
		}
		$realdate = $(this).parent().parent().parent().parent().parent().parent().find(".realdate").html();
		$("#arrival_date").attr('value', $realdate+"-"+$number);
	});	
}

$(function()
{
	$('.date-pick').datePicker({ createButton:true, clickInput:false});
	
	$('#arrival_date').change(function(){
		$startdate = $('#arrival_date').attr("value");
		$('#order_start_date.date-pick').datePicker({ createButton:false, clickInput:true, startDate:$startdate});
	});
	
	$('#arrival_date').change(function(){
		var $selected_date = $(this).attr("value");
		if($selected_date>$('#departure_date').attr("value"))
			$('#departure_date').attr("value",$selected_date);
		$('#departure_date').datePicker({ createButton:false, clickInput:true, startDate:$startdate});
	});
});
/* end sodybos uzsakymas */
$(function()
{
	$('a.flgal').click(function(){
		$.nyroModalManual({
			url: '/files/Flash/viewer.swf',
			width: 564,
			height: 510,
			type: 'swf',
			bgColor: '#000',
			swf: {
				wmode: 'transparent',
				height: '510',
				width: '564',
				flashvars: 'xmlDataPath=/custom/blocks/Albumas/xml.php?album=paslaugos_'+$(this).attr('href')+'&LAN=lt'
			},
			closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close"><img src="/images/close.png"></a>',
			title: $(this).attr('title'),
		});
		return false;
	});
});