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() {
		if ($('#agree:checked').val() == 1) {
		  submitForm(this);
		} else {
			$("#responce").html("<b>Privalote sutikti su taisyklėmis!</b>");
			$.scrollTo($('#responce'), 500);
			$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
		}
		return false;
	});
	$("#orderform2").submit(function() {
		if ($('#agree:checked').val() == 1) {
		  submitForm2(this);
		} else {
			$("#responce").html("<b>Privalote sutikti su taisyklėmis!</b>");
			$.scrollTo($('#responce'), 500);
			$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
		}
		return false;
	});
	$("#orderform3").submit(function() {
		if ($('#agree:checked').val() == 1) {
		  submitForm3(this);
		} else {
			$("#responce").html("<b>Privalote sutikti su taisyklėmis!</b>");
			$.scrollTo($('#responce'), 500);
			$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
		}
		return false;
	});
	reloadcalclick();
	
});

function submitForm(form){
	$.post('/custom/blocks/sodybos_uzsakymas/send.php', $(form).serialize(), function(html){
		if(html=="<b>Jūsų užsakymas priimtas!</b>"){
			$("#orderform").remove();
		}
		$("#responce").html(html)
	});
	//$('html, body').animate({scrollTop:0}, 'slow');
	$.scrollTo($('#responce'), 500);
	$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
}
function submitForm2(form){
	$.post('/custom/blocks/sodybos_uzsakymas_simple/send.php', $(form).serialize(), function(html){
		if(html=="<b>Jūsų užsakymas priimtas!</b>"){
			$("#orderform").remove();
		}
		$("#responce").html(html)
	});
	//$('html, body').animate({scrollTop:0}, 'slow');
	$.scrollTo($('#responce'), 500);
	$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
}
function submitForm3(form){
	$.post('/custom/blocks/partnerio_uzsakymas/send.php', $(form).serialize(), function(html){
		if(html=="<b>Jūsų užsakymas priimtas!</b>"){
			$("#orderform3").remove();
		}
		$("#responce").html(html)
	});
	//$('html, body').animate({scrollTop:0}, 'slow');
	$.scrollTo($('#responce'), 500);
	$("#responce").animate( { backgroundColor: '#BF432F', color: '#fff' }, 2000).animate( { backgroundColor: '#F8CF99', color: '#000' }, 2000);
}

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).find("a").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});
	});
});

$(function()
{
	$("#sender_type_1").click(function(){
		$(".physical").show();
		$(".juridical").hide();
	});

	$("#sender_type_2").click(function(){
		$(".physical").hide();
		$(".juridical").show();		
	});
});

