$(document).ready(function() {


if($("#orderdcforprog").val()=='true'){

$(".dcbacktohotel").click(function(){
	location.href='hotel/spa/'+$("#hotelid").val()+'/dc_program/'+$("#programid").val()+'/viesbuciai/programs/';
});

$(".pirktibtm_room").click(function(){
	if($("#dcsalygos").attr("checked")!=true){
		alert($("#dcimtinesutinkususalygom").val());
		return false;
	}
});

// dovanu cekio pirkimas

$(".adresbox").css("display", "none");
$(".checkadresas").click(function(){
	if($(this).attr("checked")==true) $(".adresbox").css("display", ""); else $(".adresbox").css("display", "none");
});

$("#dcgryztiimaketavima").click(function(){
	$("#buydovcek").slideDown();
	$("#dcstep2bank").slideUp();
});

$("#buynow22").click(function(){
var u=true;
if(!$("#dc_mail").val()||!$("#dc_tel").val()||!validate_email($("#dc_mail").val())) u=false;
if($("#dc_pristatymas").attr("checked")==true&&!$("#dc_pristatymoadresas").val()) u=false;
if(u){
document.pirktidcprograma.submit();


//$("input[name='amount']").val(parseFloat($(".dc_kaina").html())*100);
//$('#dcpdf').html('<img src="images/base/progress.gif" alt="" />');
//var extraurl="";
//extra=$("#extra").val();
//for(i=0;i<extra;i++){extraurl+="&va[]="+$("#va"+i).val();}
//$.ajax({
//    type: 'post',
//    url: 'index.php?page=dovanu-cekio-perziura&tikras=true&roomid='+$("#roomid").val()+'&h=pdf&tip=program&maitinimas='+$("#maittype").val()+'&days='+$("#days").val()+'&persons='+$("#persons").val()+'&extra='+$("#extra").val()+'&suma='+$("#dc_kaina").val()+'&kam='+$("#dc_kam").val()+'&tekstas='+$("#dc_text").val()+'&mail='+$("#dc_mail").val()+'&pristatymas='+$("#dc_pristatymas").attr("checked")+'&adresas='+$("#dc_pristatymoadresas").val()+'&galiojimas='+$("#dc_trume").val()+'&pk='+$("#dc_trume").attr("alt")+'&dizainas='+$("input[name='diz']:checked").val()+'&programid='+$("#programid").val()+'&hotelid='+$("#hotelid").val()+'&tel='+$("#dc_tel").val()+'&maittype='+$("#maittype").val()+extraurl,
//    dataType: 'html',
//    success: function (html){
//     $('#dcpdf').html(html);
//    },
//    complete: function () {
//	$("input[name='orderid']").val($("#toid").val());
//	$("input[name='p_email']").val($("#dc_mail").val());
//	mksign("");
//    }
//   });


	
//	$("#buydovcek").slideUp();
//	$("#dcstep2bank").slideDown();
}else{
	alert($("#klaida2").val());
}
});



$("#showcheck").click(function(){


var u=true;
if(!$("#dc_mail").val()||!$("#dc_tel").val()||!validate_email($("#dc_mail").val())) u=false;
if($("#dc_pristatymas").attr("checked")==true&&!$("#dc_pristatymoadresas").val()) u=false;

var extraurl="";
extra=$("#extra").val();
for(i=0;i<extra;i++){extraurl+="&va[]="+$("#va"+i).val();}

if(u){
$('#dcpdf').html('<img src="images/base/progress.gif" alt="" />');

$.ajax({
    type: 'post',
    url: 'index.php?page=dovanu-cekio-perziura&roomid='+$("#roomid").val()+'&h=pdf&tip=program&maitinimas='+$("#maittype").val()+'&extraurl='+extraurl+'&days='+$("#days").val()+'&persons='+$("#persons").val()+'&extra='+$("#extra").val()+'&suma='+$("#dc_kaina").val()+'&mail='+$("#dc_mail").val()+'&pristatymas='+$("#dc_pristatymas").attr("checked")+'&adresas='+$("#dc_pristatymoadresas").val()+'&galiojimas='+$("input[name='dc_trume']").val()+'&pk='+$("#procvprog").val()+'&dizainas='+$("input[name='diz']:checked").val()+'&programid='+$("#programid").val()+'&hotelid='+$("#hotelid").val()+'&tel='+$("#dc_tel").val(),
    dataType: 'html',
    data: 'kam='+$("#dc_kam").val()+'&tekstas='+$("#dc_text").val(),
    success: function (html){
     $('#dcpdf').html(html);
    },
    complete: function () {
	$('#dcpdf').append("<iframe src='libs/download.php?file="+$("#tname").val()+"' width='0' height='0' frameborder='0'></iframe>");

    }
   });


}else{
	alert($("#klaida2").val());
}
});



}// orderdcforprog



if($("#kambariu_uzsakymo_forma").val()=="true"){


// programos ir kambariu pirkimas
	$("#buy_room,#darytiuzklausima,#rsrv_room").click(function(){
			var uzpildyta=true;
			var c_tel=$("input[name='c_tel']").val(),
				c_mail=$("input[name='c_mail']").val(),
				c_vymail=$("input[name='c_vymail']").val(),
				c_pastabos=$("input[name='c_pastabos']").val(),
				c_pavarde=$("input[name='c_pavarde']").val(),
				persons=returnInteger($("input[name='persons']").val()),
				extra=returnInteger($("input[name='extra']").val());

			if(c_tel==""||!validate_email(c_mail)||!validate_email(c_vymail)||c_pavarde=="") uzpildyta=false;

			for(i=1;i<=persons;i++){
				if($("input[name='c_vardas"+i+"']").val()=="") uzpildyta=false;
			}
				
			for(i=1;i<=extra;i++){
				if($("input[name='c_vvardas"+i+"']").val()=="") uzpildyta=false;
			}
			
			if(uzpildyta){
				if($("input[name='dcsalygos']").attr("checked")==true||$("input[name='aruzklausimas']").val()=="taip"){
					this.form.submit(); // subminitu jei viskas ok
				}else alert($("#dc_nesutinkususalygomis").val());
			}else alert($("#dcimtineviskasupildyta").val());
	});



	if($("input[name='disablefields']").val()=="taip"){
		$(".roompirkti input[type='text']").attr("readonly", "readonly").addClass("readonly");
		$(".roompirkti textarea").attr("readonly", "readonly").addClass("readonly");
	}

	$("#panaudotidcprogramoj").click(function(){
		$("#tceki").fadeIn();
		$("#panaudotidcprogramoj").css("display", "none");
	});

	$("#dcreloadprice").click(function(){
		$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
		$.ajax({
			type: 'post',
			url: 'index.php?page=jquery-kambariu-rezervavimas&h=reloadprogrampricewithdc&pin='+$("#p_pin").val()+'&secret='+$("#p_secret").val(),
			dataType: 'html',
			success: function (html){
				if(html.length>10){
					$('#kainosinfo').html(html);
					$("#tceki").css("display", "none");
				}else alert($("#mok_blogasdcnomicek").val());
			},
			complete: function () {
				$("#loading").remove();
				if($("#kainasudc").val()=='12345'){ $("#dcuzrezervuoti").css("display", "inline-block"); }
			}
		});
	});
	

	$(".backtohotel").click(function(){
	if(returnInteger($("input[name='programid']").val())==0)
		location.href="hotel/spa/"+$("input[name='hotelid']").val()+"/review/viesbuciai/rooms/";
	else
		location.href="hotel/spa/"+$("input[name='hotelid']").val()+"/program/"+$("input[name='programid']").val()+"/"+$("input[name='obtyp']").val()+"/programs/";
	});
	


}

if($("input[name='showmenu']").val()=="true"&&$("input[name='tabas']").val()=="programs"&&$("input[name='progtip']").val()!="dc_programa"&&$("input[name='progtip']").val()!="programa"){
	getprogramlist($("input[name='vid']").val(), 2);
}else{

	if($("input[name='progtip']").val()=="dc_programa"){
		order_programa(returnInteger($("input[name='programid']").val()), $(this).attr("abbr"), 'dovcek');
	}
	if($("input[name='progtip']").val()=="programa"){
		order_programa(returnInteger($("input[name='programid']").val()), $(this).attr("abbr"));
		
	}
}

if($("input[name='showmenu']").val()=="true"&&$("input[name='tabas']").val()=="info"){
	getsubtabtext($("input[name='tab0']").val(), $("input[name='vid']").val(), $("input[name='tab0']").val());
	getsubtab($("input[name='tab0']").val(), $("input[name='vid']").val());
}
if($("input[name='showmenu']").val()=="true"&&$("input[name='tabas']").val()=="rooms"){
	order_rooms($("input[name='vid']").val());
}
if($("input[name='showmenu']").val()=="true"&&$("input[name='tabas']").val()=="about"){
	$(".dspi").click(function(){
		dspi();
		changeImg('bigimg', $(this).attr("src"));
	});
	$(".dspv").click(function(){
		dspv();
		changeImg('bigimg', $(this).attr("src"));
	});
	
}



$(".chinfotb").click(function(){
	getsubtab(returnInteger($(this).attr("class")), $("input[name='vid']").val()); 
	getsubtabtext(returnInteger($(this).attr("class")), $("input[name='vid']").val(), returnInteger($(this).attr("class")));
});


$(function() { $(".lavaLamp").lavaLamp({ 
	fx: "backout", 
	speed: 700,
	click: function(event, menuItem) {
		//return false;
}})});





$("#search_input").change(function(){
	if(($("#search_input").val().length>=4)){
		location.href='index.php?page=spa&src=true&fraze='+$("#search_input").val();
	}else alert($("#klaidamazaisimb").val());
});


$("#dosrc").click(function(){
	if(($("#search_input").val().length>=4)){
		location.href='index.php?page=spa&src=true&fraze='+$("#search_input").val();
	}else alert($("#klaidamazaisimb").val());
});

$("#pasirinkite_tipa").change(function(){
	getcountriesbytype(this.value);
});

$("#pasirinkite_country").change(function(){
	getregionsbytype($("#pasirinkite_tipa").val(), this.value);
});

$("#country3").change(function(){hotelfilterregion(3, 3);});
$("#runsrc3").click(function(){	if($("#country3").val()!="choose") document.src_filtras3.submit();});

$("#country2").change(function(){hotelfilterregion(2, 1);});
$(".runsrc2").click(function(){if($("#country2").val()!="choose") document.src_filtras2.submit();});


$("#country1").change(function(){hotelfilterregion(1, 2);});
$(".runsrc1").click(function(){if($("#country1").val()!="choose") document.src_filtras1.submit();});

$("#r1").change(function(){choosepradinistab1();});
$("#r2").change(function(){choosepradinistab2();});
$("#r3").change(function(){choosepradinistab3();});
$("#r4").change(function(){choosepradinistab4();});




$(".registerme").click(function(){
	$("#registertable").fadeIn();
	$("#loginttable").fadeOut();
	$('#regcnt').html('<img src="images/base/progress.gif" alt="" />')+'&logintype='+$("#logintype").val();
	$.ajax({
		type: 'post',
		url: "index.php",
		data: "page=registruokites",
		dataType: 'html',
		success: function (hj){
			$("#regcnt").html(hj);
		},
		complete: function () {
		
			$("#nt2").click(function(){
				$("#regblock1").css("display", "none");
				$("#regblock2").fadeIn();
				$("#logintype").val("2");
			});
			$("#nt1").click(function(){
				$("#regblock2").css("display", "none");
				$("#regblock1").fadeIn();
				$("#logintype").val("1");
			});
			$("#registbt").click(function(){
				if($("#regtaisykles").attr("checked")==true){
				
				if($("#logintype").val()==2){
					var contact_name=$("input[name='contact_name1']").val()+" "+$("input[name='contact_name2']").val(),
					pass1=$("input[name='pass12']").val(),
					pass2=$("input[name='pass22']").val(),
					contact_imcode=$("input[name='contact_imcode2']").val(),
					contact_pvmcode=$("input[name='contact_pvmcode2']").val(),
					contact_street=$("input[name='contact_street2']").val(),
					contact_zip=$("input[name='contact_zip2']").val(),
					contact_city=$("input[name='contact_city2']").val(),
					contact_country=$("input[name='contact_country2']").val(),
					contact_phone=$("input[name='contact_phone2']").val(),
					contact_mail=$("input[name='contact_mail2']").val(),
					contact_www=$("input[name='contact_www2']").val(),
					username=$("input[name='username2']").val();
				}else{
					var contact_name=$("input[name='contact_name']").val(),
					login_person=$("input[name='login_person1']").val()+' '+$("input[name='login_person2']").val();
					pass1=$("input[name='pass11']").val(),
					pass2=$("input[name='pass21']").val(),
					contact_imcode=$("input[name='contact_imcode1']").val(),
					contact_pvmcode=$("input[name='contact_pvmcode1']").val(),
					contact_street=$("input[name='contact_street1']").val(),
					contact_zip=$("input[name='contact_zip1']").val(),
					contact_city=$("input[name='contact_city1']").val(),
					contact_country=$("input[name='contact_country1']").val(),
					contact_phone=$("input[name='contact_phone1']").val(),
					contact_mail=$("input[name='contact_mail1']").val(),
					contact_www=$("input[name='contact_www1']").val(),
					username=$("input[name='username1']").val();
				}
				var posturl='page=registruokites&fin=true&reseller='+returnInteger($("#ref_reseller").html())+'&contact_type='+$("#logintype").val()+'&pass1='+pass1+'&pass2='+pass2+'&contact_name='+(contact_name.replace(/\&/gi, "_amp_"))+'&contact_imcode='+contact_imcode+'&contact_pvmcode='+contact_pvmcode+'&contact_street='+contact_street+'&contact_zip='+contact_zip+'&contact_city='+contact_city+'&contact_country='+contact_country+'&contact_phone='+contact_phone+'&contact_mail='+contact_mail+'&contact_www='+contact_www+'&login_person='+login_person+'&username='+username;
				var klaida=false;
				
				if(username.length>4&&(pass1==pass2)&&pass1.length>=6&&contact_phone!=""&&validate_email(contact_mail)){
					if($("#logintype").val()==2){
						if($("input[name='contact_name1']").val()!=""&&$("input[name='contact_name2']").val()!="") klaida=false; else klaida=true;
					}else{
						if(contact_name!="") klaida=false; else klaida=true;
					}
				}else klaida=true;
				
				if(!klaida){
					$('#loadreg').html('<img src="images/base/progress.gif" alt="" />')+'&logintype='+$("#logintype").val();
					$.ajax({
						type: 'post',
						url: "index.php",
						data: posturl,
						dataType: 'html',
						success: function (hf){
							$("#regresult").html(hf);
							if(hf.length>10)
								alert($("#regresult").html());
							else{
								alert($("#reg_finish").val());
								$("#registertable").fadeOut();
							}
						},
						complete: function () {
							$('#loadreg').html("");
						}
					});
				
				}else alert($("#neviskasuzpildytareg").val());
				
				}else alert($("#reg_sutiksutaisyklem").val());
			});
		}
	});
	
});


$(".registerclose").click(function(){
	$("#registertable").fadeOut();
});



var posturl="page=please-login";
$('#logntext').html('<img src="images/base/progress.gif" alt="" />')+'&logintype='+$("#logintype").val();
$(".pleaselogin").click(function(){
$("#loginttable").fadeIn();
$("#registertable").fadeOut();
$.ajax({
	type: 'post',
	url: "index.php",
	data: posturl,
	dataType: 'html',
	success: function (p){
		$('#logntext').html(p);
	},
	complete: function () {
		$("#remindpass").click(function(){
			$('#logntext').html('<img src="images/base/progress.gif" alt="" />');
			$.ajax({
				type: 'post',
				url: "index.php",
				data: "page=slaptazodzio-priminimas",
				dataType: 'html',
				success: function (ht){
					$('#logntext').html(ht);
				},
				complete: function () {
					$("#resetpass").click(function(){
						if(validate_email($("input[name='user']").val())){
							$.ajax({
								type: 'post',
								url: "index.php",
								data: "page=slaptazodzio-priminimas&change=sendit&user="+$("input[name='user']").val(),
								dataType: 'html',
								success: function (h1){
									alert($("#remindersend").val());
									$("#loginttable").fadeOut();
								},
								complete: function () {
								}
							});
						}
					});
				}
			});
		
		});
	
	
		$("#loginmtm").click(function(){
			var lgnurl="page=please-login&h=1&username="+$("input[name='username']").val()+"&password="+$("input[name='password']").val();
			$.ajax({
				type: 'post',
				url: "index.php",
				data: lgnurl,
				dataType: 'html',
				success: function (h){
					if(h.length>10) alert(h); else{
						//alert($("#welcometext").val());
						location.href=$("base").attr("href");
					}
				},
				complete: function () {
				}
			});
		});
	}
});


});

$(".logntbclose").click(function(){
	$("#loginttable").fadeOut();
});

$(".myhistorym").click(function(){
$("#settingsbar").fadeOut();
$("#myhistory").fadeIn();


var posturl="page="+($("#logintype").val()=="0"?'uzsakymu-istorija':'mano-uzsakymu-istorija');
$('#histinfo').html('<img src="images/base/progress.gif" alt="" />')+'&logintype='+$("#logintype").val();
$.ajax({
	type: 'post',
	url: "index.php",
	data: posturl,
	dataType: 'html',
	success: function (p){
		$('#histinfo').html(p);
	},
	complete: function () {
	
		$("#myusershist").click(function(){
			if($(this).attr("checked")==true){
				$("#his1").css("display", "none");
				$("#his2").fadeIn();
			}else{
				$("#his2").css("display", "none");
				$("#his1").fadeIn();
			}
		});

	}
});


});


$(".myhistoryclose").click(function(){
	$("#myhistory").fadeOut();
});



$(".mysettings").click(function(){
$("#myhistory").fadeOut();
$("#settingsbar").fadeIn();


$('#setinfo').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
	type: 'post',
	url: 'index.php?page='+($("#logintype").val()=="0"?'mano-nustatymai':'asmeniniai-nustatymai')+'&refurl='+$("#refurl").val(),
	dataType: 'html',
	success: function (html){
	$('#setinfo').html(html);
    },
    complete: function () {
	$("#daugiaumygt").click(function(){
		$("#moreset").fadeIn();
		$("#daugiaumygt").fadeOut();
	});
	$("#keiciuduomenis").click(function(){
		var urlas="index.php", posturl='page='+($("#logintype").val()=="0"?'mano-nustatymai':'asmeniniai-nustatymai')+'&fin=true&pass1='+$("input[name='pass1']").val()+'&pass2='+$("input[name='pass2']").val()+'&contact_name='+($("input[name='contact_name']").val().replace(/\&/gi, "_amp_"))+'&contact_imcode='+$("input[name='contact_imcode']").val()+'&contact_pvmcode='+$("input[name='contact_pvmcode']").val()+'&contact_street='+$("input[name='contact_street']").val()+'&contact_zip='+$("input[name='contact_zip']").val()+'&contact_city='+$("input[name='contact_city']").val()+'&contact_country='+$("input[name='contact_country']").val()+'&contact_phone='+$("input[name='contact_phone']").val()+'&contact_fax='+$("input[name='contact_fax']").val()+'&contact_mail='+$("input[name='contact_mail']").val()+'&login_mail='+$("input[name='login_mail']").val()+'&contact_www='+$("input[name='contact_www']").val()+'&login_person='+$("input[name='login_person']").val();
		if(($("input[name='pass1']").val()==$("input[name='pass2']").val())&&$("input[name='contact_name']").val()!=""&&$("input[name='contact_phone']").val()!=""&&validate_email($("input[name='contact_mail']").val())||($("#logintype").val()=="0"&&validate_email($("input[name='login_mail']").val()))){
			$('#setinfo').html('<img src="images/base/progress.gif" alt="" />');
			$.ajax({
				type: 'post',
				url: urlas,
				data: posturl,
				dataType: 'html',
				success: function (p){
					$('#setinfo').html(p);
				},
				complete: function () {
					//setTimeout(function(){ $("#settingsbar").fadeOut() }, 5000);
				}
			});
		}else alert($("#setsaveerror").val());
	});
	
    }
   });
});

	
	
	
$(".mysettingsclose").click(function(){
	$("#settingsbar").fadeOut();
});

$("#dcwp").click(function(){
	location.href='index.php?week=plus&datefrom='+$("#datefrom").val()+'&mdc_pin='+$("#pin").val()+'&mdc_secret='+$("#secret").val()+'&page=order-program-gift';
});

$("#dcwm").click(function(){
	location.href='index.php?week=minus&datefrom='+$("#datefrom").val()+'&page=order-program-gift&mdc_pin='+$("#pin").val()+'&mdc_secret='+$("#secret").val();
});


if($("#dc_orderprograma").val()){

$("#datanuo").datepicker({minDate: returnInteger($("#hotel_daysoff").val()), maxDate: '+'+$("#maxdaysfuture").val()+'D'});
$("#datanuo").change(function(){
	location.href="index.php?datefrom="+$("#datanuo").val()+"&mdc_pin="+$("#pin").val()+"&mdc_secret="+$("#secret").val()+"&page=order-program-gift";
});

$(".procminfo").mouseover(function(){
	var idi=returnInteger($(this).attr("alt"));
	$(".prca"+idi).fadeIn();
});

$(".procminfo").mouseout(function(){
	var idi=returnInteger($(this).attr("alt"));
	$(".prca"+idi).fadeOut();
});


$(".vdproc").click(function(){
	checkprocsel($(this).val(), returnInteger($(this).attr("name")), $(this).attr("abbr"));
});

$("#perkudceki").click(function(){
	if($("#procedurosok").val()=="true"){
		$("#h").val("pirktidc");
		var link="";
		$('.vdproc').each(function() {
			if($(this).val()>0){
				if($(this).attr("abbr")==1){
					if(($("#v_procs").val()=="1"&&$(this).attr("checked")==true)||($("#v_procs").val()!="1"))
						link=link+'<input type="hidden" name="ps['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).attr("id"))+'" /><input type="hidden" name="psv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).val())+'" />';
				}else{
					if(($("#v_procv").val()=="1"&&$(this).attr("checked")==true)||($("#v_procv").val()!="1"))
						link=link+'<input type="hidden" name="pv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).attr("id"))+'" /><input type="hidden" name="pvv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).val())+'" />';
				}
			}
		});
		$("#procsar").html(link);
		document.dcf.submit();
	}else alert($("#nesuvedeteproceduruklaida").val());
});


$("#dcuzdarytiask,.duzd,#home_box").click(function(){
	$("#perkucekiform").css("display", "none");
	$("#home_box").css("display", "none");
	$("html").css("overflow", "auto");
});



$("#perkudcekiklausti").click(function(){
	alert($("#dcuzklausimastext").val());
	location.href='hotel/spa/'+$("#hotelid").val()+'/program/'+$("#programid").val()+'/viesbuciai/programs/';
});




orderdcprogram();


}







$("#dcuzrezervuoti").click(function(){


var uzpildyta=true;
var	c_tel=$("input[name='c_tel']").val(),
	c_mail=$("input[name='c_mail']").val(),
	c_vymail=$("input[name='c_vymail']").val(),
	c_pastabos=$("input[name='c_pastabos']").val(),
	c_pavarde=$("#c_pavarde").val(),
	persons=$("#persons").val(),
	extra=$("#extra").val(),
	asmlink="";

if(c_tel==""||!validate_email(c_mail)||!validate_email(c_vymail)||c_pavarde=="") uzpildyta=false;

for(i=1;i<=persons;i++){
	asmlink=asmlink+"&c_vardas[]="+$("#c_vardas"+i).val();
	if($("#c_vardas"+i).val()=="") uzpildyta=false;
}
for(i=1;i<=extra;i++){
	asmlink=asmlink+"&c_vvardas[]="+$("#c_vvardas"+i).val();
	if($("#c_vvardas"+i).val()=="") uzpildyta=false;
}


if(uzpildyta){
if($("#dcsalygos").attr("checked")==true){




//var linkas='index.php?page=jquery-kambariu-rezervavimas&h=rezervuotidc&'+asmlink+'&c_tel='+c_tel+'&c_mail='+c_mail+'&c_pastabos='+c_pastabos+'&c_pavarde='+c_pavarde+'&datanuo='+$("#datanuo").val()+link+'&pin='+$("#pin").val()+'&secret='+$("#secret").val();
document.dcf.submit();



}else alert($("#dcimtinesutinkususalygom").val());
}else alert($("#dcimtineviskasupildyta").val());

});











$("#ziuretikomentarus").click(function(){
$("#viesbuciokomentarai").fadeIn();
$.ajax({
    type: 'post',
    url: 'index.php?page=balsavimas&hotelid='+$("#viesbuciokomentarai").attr("title"),
    dataType: 'html',
    success: function (html){
     $('#vkomentarai').html(html);
    },
    complete: function () {
    }
   });

});

var minsuma=($("input[name='diz']:checked").val()=="4"?20:100);


$("input[name='diz']").change(function(){
	minsuma=($("input[name='diz']:checked").val()=="4"?20:100);
});


$("#vkuzdaryti").click(function(){
	$("#viesbuciokomentarai").fadeOut();
});

$("#showcheck").click(function(){

var u=true;
if(!$("#dc_mail").val()||!$("#dc_tel").val()||!validate_email($("#dc_mail").val())) u=false;
if($("#dc_pristatymas").attr("checked")==true&&!$("#dc_pristatymoadresas").val()) u=false;


if(returnInteger($("#dc_gkaina").html())<minsuma) u=false;
if(u){
$('#dcpdf').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=dovanu-cekio-perziura&h=pdf&suma='+$("#dc_kaina").val()+'&mail='+$("#dc_mail").val()+'&pristatymas='+$("#dc_pristatymas").attr("checked")+'&adresas='+$("#dc_pristatymoadresas").val()+'&galiojimas='+$("input[name='dc_trume']:checked").attr("value")+'&pk='+$("input[name='dc_trume']:checked").attr("alt")+'&dizainas='+$("input[name='diz']:checked").val()+'&tel='+$("#dc_tel").val(),
    dataType: 'html',
    data: '&kam='+$("#dc_kam").val()+'&tekstas='+$("#dc_text").val(),
    success: function (html){
     $('#dcpdf').html(html);
    },
    complete: function () {
	$('#dcpdf').append("<iframe src='libs/download.php?file="+$("#tname").val()+"' width='0' height='0' frameborder='0'></iframe>");
    }
   });


}else{
if(returnInteger($("#dc_gkaina").html())<minsuma) alert($("#klaida1").val()); else	alert($("#klaida2").val());
}

});

$("#apmoketibanke").click(function(){
	if($("#dcsalygos").attr("checked")==true){
		$("#dovanucekis").fadeOut();
		$("#dcstep1").fadeIn();
		$("#dcstep2").fadeOut();
		document.pirktidcnominala.submit();
	} else alert($("#dc_nesutinkususalygomis").val());
});

$("#buynow").click(function(){
var u=true;
if(!$("#dc_mail").val()||!$("#dc_tel").val()||!validate_email($("#dc_mail").val())) u=false;
if($("#dc_pristatymas").attr("checked")==true&&!$("#dc_pristatymoadresas").val()) u=false;
if(returnInteger($("#dc_gkaina").html())<minsuma) u=false;

if(u){
$("input[name='amount']").val(parseFloat($("#dc_gkaina").html())*100);
$('#dcpdf').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=dovanu-cekio-perziura&h=pdf&tikras=true&suma='+$("#dc_kaina").val()+'&kam='+$("#dc_kam").val()+'&tekstas='+$("#dc_text").val()+'&mail='+$("#dc_mail").val()+'&pristatymas='+$("#dc_pristatymas").attr("checked")+'&adresas='+$("#dc_pristatymoadresas").val()+'&galiojimas='+$("input[name='dc_trume']:checked").attr("value")+'&pk='+$("input[name='dc_trume']:checked").attr("alt")+'&dizainas='+$("input[name='diz']:checked").val()+'&tel='+$("#dc_tel").val(),
    dataType: 'html',
    success: function (html){
     $('#dcpdf').html(html);
    },
    complete: function () {
	$("input[name='orderid']").val($("#toid").val());
	$("input[name='p_email']").val($("#dc_mail").val());
	mksign("");
    }
   });


	$(".dc_kaina").html($("#dc_gkaina").html());
	$("#dcstep2").slideDown("slow");
	$("#dcstep1").slideUp("slow");
}else{
	if(returnInteger($("#dc_gkaina").html())<minsuma) alert($("#klaida1").val()); else	alert($("#klaida2").val());
}
});

$("#dcgryztiimaketavima").click(function(){
	$("#dcstep1").slideDown("slow");
	$("#dcstep2").slideUp("slow");
});

$("#dc_kaina").keyup(function(){
	var ilt=returnInteger($(this).val());
	var vv=returnInteger($("input[name='dc_trume']:checked").attr("alt"));
	var proc=ilt+((ilt/100)*vv);
	if($("#dc_pristatymas").attr("checked")==true) proc=proc+10;
	$("#dc_gkaina").html(proc);
});

$("input[name='dc_trume']").click(function(){
	var ilt=returnInteger($("#dc_kaina").val());
	var vv=returnInteger($(this).attr("alt"));
	var proc=ilt+((ilt/100)*vv);
	if($("#dc_pristatymas").attr("checked")==true) proc=proc+10;
	$("#dc_gkaina").html(proc);
});

$("#dc_pristatymas").click(function(){
	$(".adresbox").css("display", "");
	var ilt=returnInteger($("#dc_kaina").val());
	var vv=returnInteger($("input[name='dc_trume']:checked").attr("alt"));
	var proc=ilt+((ilt/100)*vv);
	var kpd=proc+10;
	var kmd=proc;
	if($(this).attr("checked")==true) $("#dc_gkaina").html(kpd); else $("#dc_gkaina").html(kmd);
});


$(".duzd").click(function(){
$("#dovanucekis").fadeOut();
$("#home_box").css("display", "none");
$("#buydovcek").css("display", "none");
$("html").css("overflow", "auto");
$("#step2").css("display", "none");
$("#dcstep2bank").css("display", "none");
});


$("#imgdovanucekiai").click(function(){
	$("#dovanucekis").fadeIn();
});

$(".dctikrinti").click(function(){
$('#dcloadingrez').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=dcpanaudoti&pin='+$("#mdc_pin").val()+'&secret='+$("#mdc_secret").val(),
    dataType: 'html',
    success: function (html){
     $('#dcsrcrez').html(html);
    },
    complete: function () {
	$('#dcloadingrez').html('');
	$("#dctikrink2").click(function(){
		location.href='index.php?page=order-program-gift&mdc_pin='+$("#mdc_pin").val()+'&mdc_secret='+$("#mdc_secret").val();
	});


	$("#dctikrink1").click(function(){
		$('#dcloadingrez').html('<img src="images/base/progress.gif" alt="" />');
		$.ajax({
			type: 'post',
			url: 'index.php?page=jquery-kambariu-rezervavimas&h=dcnurasyti&pin='+$("#mdc_pin").val()+'&secret='+$("#mdc_secret").val(),
			dataType: 'html',
			success: function (html){
				$('#dcsrcrez').html(html);
			},
			complete: function () {$('#dcloadingrez').html('');}
		});
	});
    }
   });
});

$("#dovanucekis .dcmygt").click(function(){
	var id=$(this).attr("id");
	$(".dccn").css("display", "none");
	$('#a'+id).fadeIn();
});
$(".adresbox").css("display", "none");
$(".checkadresas").click(function(){
	if($(this).attr("checked")==true) $(".adresbox").css("display", "");  else $(".adresbox").css("display", "none");
});

$('.uzsakytinaujienas').click(function() {
  $('#naujienlaiskai').submit();
});



$("#flags b").click(function(){
	$("#valiutos").fadeIn();
	$("#langblock").fadeOut();
});


$("#langblocks").click(function(){
	$("#langblock").fadeIn();
	$("#valiutos").fadeOut();
});

$(".rdo").click(function(){
	$("#langblock").fadeIn();
	$("#valiutos").fadeOut();
});


$("#valiutos span").click(function(){
	window.location.href = "index.php?currency="+returnInteger($(this).attr("id"));
});




var toggleFx = function() {
  $.fx.off = false;
};
toggleFx();

//prid=window.location.hash;
//openprogram(prid);

//$("#menut a").click(function(v){
//	window.location.hash=$(v[name]).val();
//});



$("#laisvos_vietos").click(function(){

$("#laisvos_vietosl").fadeIn();
$('#laisvos_vietosl').html('<p align="center"><img src="images/base/progress.gif" alt="" /></p>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=laisvosvietostbl',
    dataType: 'html',
    success: function (html){
    	$("#laisvos_vietosl").html(html);
    },
    complete: function () {
	$('#laisvos_vietosl').html();
	$("#lvietosclose").click(function(){$("#laisvos_vietosl").fadeOut();});
	$("#comein").datepicker({minDate: returnInteger($("#hdof").val()), maxDate: '+'+$("#mdft").val()+'D'});
	$("#comeout").datepicker({minDate: returnInteger($("#hdof").val()), maxDate: '+'+$("#mdft").val()+'D'});
	$("#laisvos_vietosl select[name='country']").change(function(){
		$('#loarreg').html('<p align="center"><img src="images/base/progress.gif" alt="" /></p>');
		$.ajax({
			type: 'post',
			url: 'index.php?page=jquery-kambariu-rezervavimas&h=getregionsbycountry&country='+$(this).val(),
			dataType: 'html',
			success: function (html){
				$("#laisvos_vietosl select[name='region']").html(html);
			},
			complete: function () {
				$('#loarreg').html("");
			}
		});
	});
	$("#srclaisvos_vietos").click(function(){
		if($("#comein").val()!=""&&$("#comeout").val()!=""&&$("#laisvos_vietosl select[name='country']").val()!="choose"){
			document.laisvosvietosklausti.submit();
		}else alert($("#pradinis_klaidalaisvosvietos").val());
	});
    }
   });

});




$(".h2prant1").click(function(){
	$("#pnaujienos").fadeIn();
	$("#ptemos").css("display", "none");
	$(".h2prant1").addClass("h2prant1a");
	$(".h2prant2").removeClass("h2prant1a");
	$(".daugiaunews").css("display", "block");
	$(".h2prant2").html("<img class='uzd' src='images/tabs/uzd2.png' alt='' />");
	$(".h2prant1").html("");
});

$(".h2prant2").click(function(){
	$("#pnaujienos").css("display", "none");
	$(".daugiaunews").css("display", "none");
	$("#ptemos").fadeIn();
	$(".h2prant1").removeClass("h2prant1a");
	$(".h2prant2").addClass("h2prant1a");
	$(".h2prant1").html("<img class='uzd' src='images/tabs/uzd.png' alt='' />");
	$(".h2prant2").html("");
});


});



function choosepradinistab1(){$('.fil1').removeClass('pfil2');$('.fil2').removeClass('pfil1');$(".fil1").addClass("pfil1");$(".fil2").addClass("pfil2");}
function choosepradinistab2(){$('.fil1').removeClass('pfil1');$('.fil2').removeClass('pfil2');$(".fil1").addClass("pfil2");$(".fil2").addClass("pfil1");}

function choosepradinistab3(){$('.fil3').removeClass('pfil4');$('.fil4').removeClass('pfil3');$(".fil3").addClass("pfil3");$(".fil4").addClass("pfil4");}
function choosepradinistab4(){$('.fil3').removeClass('pfil3');$('.fil4').removeClass('pfil4');$(".fil3").addClass("pfil4");$(".fil4").addClass("pfil3");}


function changeImg(image_id, image_folder){
   document.getElementById(image_id).src = image_folder;
}



function dspi(){
	document.getElementById('i2').style.display='none';
	document.getElementById('i1').style.display='block';
}

function dspv(){
	document.getElementById('i2').style.display='block';
	document.getElementById('i1').style.display='none';
}





function weekplus(){
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=changedateplus&datefrom='+$("#datefrom").val()+'&hotelid='+$("#hotelid").val()+'&isdc='+$("#isdc").val(),
    dataType: 'html',
    success: function (html){
    	$("#datefrom").val(str_replace([' ', '\n', '\r'], ['', ''], html));
	if($("#programid").val()) programu_kalendorius(); else kambariu_kalendorius();
    },
    complete: function () {

    }
   });
}



function weekminus(){
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=changedateminus&datefrom='+$("#datefrom").val()+'&hotelid='+$("#hotelid").val()+'&isdc='+$("#isdc").val(),
    dataType: 'html',
    success: function (html){
    	$("#datefrom").val(str_replace([' ', '\n', '\r'], ['', ''], html));
	if($("#programid").val()) programu_kalendorius(); else kambariu_kalendorius();
    },
    complete: function () {

    }
   });
}



function hotelfilterregion(r, j){
$('.loadingfilt'+r).html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=slregion&country='+document.getElementById('country'+r).value+'&j='+j,
    dataType: 'html',
    data: $('#region :input'),
    success: function (html){
     $('#slregion'+r).html(html);
     $('.loadingfilt'+r).html("");
    },
    complete: function () {

    }
   });
}





function getcountriesbytype(t){
$('#loadfil').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=gslcountries&typ='+t,
    dataType: 'html',
    success: function (html){
    	$('#pasirinkite_country').html(html);
    },
    complete: function () {
	$('#loadfil').html("");
    }
   });
}


function getregionsbytype(t,c){
$('#loadfil').html('<img src="images/base/progress.gif" alt="" />');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=gslregions&typ='+t+'&country='+c,
    dataType: 'html',
    success: function (html){
    	$('#pasirinkite_region').html(html);
    },
    complete: function () {
	$('#loadfil').html("");
    }
   });
}


function getsubtab(act, hotelid){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
	type: 'post',
	url: 'index.php?page=jquery-kambariu-rezervavimas&h=getsubtabs&hotelid='+hotelid+'&act='+act,
	dataType: 'html',
	success: function (html){
		$('#subtabai').html(html);
		$('#loading').remove(); 
	},
	complete: function () {
		$("#subtab li").click(function(){
			getsubtabtext(returnInteger($(this).attr("class")), hotelid, returnInteger($("#subtab").attr("class")));
		});
	}
   });
}

function getsubtabtext(act, hotelid, did){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
	type: 'post',
	url: 'index.php?page=jquery-kambariu-rezervavimas&h=gettabinfo&hotelid='+hotelid+'&did='+did+'&act='+act,
	dataType: 'html',
	success: function (html){
		$('#tinfo').html(html);
		$('#loading').remove(); 
	},
	complete: function () {
	}
});
}



function getprogramlist(hotelid, kdays, prid){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=programlist&hotelid='+hotelid,
    dataType: 'html',
    success: function (html){
     $('#list_programs').html(html);
     $('#loading').remove(); 
    },
    complete: function () {
	load_programs(kdays);

	$("#mbutons .acl, #mbutons .btthis").click(function(ob) {
		$("#mbutons a").removeClass("btthis");
		$("#mbutons a").addClass("acl");
		$(this).addClass("btthis");
		$(this).removeClass("acl");
		ob.preventDefault();
		load_programs(returnInteger($(this).attr('href')));
		$("#kdays").val(returnInteger($(this).attr('href')));
	});

    }
   });

}


function load_programs(kdays){

$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=prglst&kdays='+kdays+'&hotelid='+$("#hotelid").val(),
    dataType: 'html',
    success: function (html){
     $('#proglst').html(html);
     $('#loading').remove(); 
    },
    complete: function () {
//alert($("input[name='progtip']").val());
	$("b#proglst a").click(function(ob){
	alert($(this).attr("abbr"));
		ob.preventDefault();
		$("#programid").val(returnInteger($(this).attr('name')));
		var programid=returnInteger($(this).attr('name'));
		if($(this).attr("abbr")=='orderdc'){
			order_programa(programid, $(this).attr("abbr"), 'dovcek');
		}else{
			order_programa(programid, $(this).attr("abbr"));
		}
	});


    }
   });

}



function order_programa(programid, cl, isdc){

$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=prglst&days='+$("#days").val()+'&hotelid='+$("#hotelid").val()+"&programid="+programid+'&odc='+cl+'&isdc='+isdc,
    dataType: 'html',
    success: function (html){
     $('#proglst').html(html);
    },
    complete: function () {

	$("input[name='dc_trume']").change(function(){

		var vaikaiok=true;
		if($("#extra").val()>0){
			for(i=0;i<$("#extra").val();i++){
				if($("#va"+i).val()==0) vaikaiok=false;
			}
		}
		if(!vaikaiok) alert($('#nepasirinktivaikai').val()); else{
			$("input[name='procvprog']").val($(this).attr("abbr"));
			if(returnInteger($("#roomid").val())>0){
				get_programprice($("#kamb input[name='kambarys']").val(), $("#datefrom").val());
			}
		}
	});


	$("#pappasl label").mouseover(function(){
		var idi=returnInteger($(this).attr("for"));
		var ishtm=$(".pap"+idi).html();
		if(ishtm.length>5) $(".pap"+idi).fadeIn();
		$(this).css("background-color", "#bce2f5");
	});
	$("#pappasl label").mouseout(function(){
		var idi=returnInteger($(this).attr("for"));
		$(".pap"+idi).fadeOut();
		$(this).css("background-color", "white");
	});

	bind_days();
	bind_datefrom();
	bind_persons();
	bind_extras();
	$("#datefrom").datepicker({minDate: returnInteger($("#hotel_daysoff").val()), maxDate: '+'+$("#maxdaysfuture").val()+'D'});
	proceduros();
	bindprocedurulist();

	$("#maittype").change(function() {
		get_programprice($("#roomid").val(), $("#datefrom").val());
	});

	$("#pappasl input[type=checkbox]").click(function() {
		if($("#recalconvaik").val()=="ok") get_programprice($("#roomid").val(), $("#datefrom").val());
	});
	programu_kalendorius();
	$('#loading').remove(); 
    }
   });
}


function papildpasl(){

$("#pappasl input[type=checkbox]").each(function() { 
	if(this.checked) alert(this.value);
});




}


function programu_kalendorius(){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=calendar&hotelid='+$("#hotelid").val()+'&datefrom='+$("#datefrom").val()+'&persons='+$("#persons").val()+'&extra='+$("#extra").val()+'&isdc='+$("#isdc").val()+'&programid='+$("#programid").val(),
    dataType: 'html',
    success: function (html){
     $('#kalendorius').html(html);
     $('#loading').remove(); 
    },
    complete: function () {
	chooseday("programa");

	//DC programos pirkimas
	$("#kamb input[name='kambarys']").click(function(){
		$("#roomid").val($("#kamb input[name='kambarys']:checked").val());
		var vaikaiok=true;
		if($("#extra").val()>0){
			for(i=0;i<$("#extra").val();i++){
				if($("#va"+i).val()==0) vaikaiok=false;
			}
		}
		if(!vaikaiok) alert($('#nepasirinktivaikai').val()); else{
			get_programprice($(this).val(), $("#datefrom").val());
		}
	});

	$("#agegroups select").change(function(){
		var vaikaiok=true;
		if($("#extra").val()>0){
			for(i=0;i<$("#extra").val();i++){
				if($("#va"+i).val()==0) vaikaiok=false;
			}
		}
		if(vaikaiok){
			if(returnInteger($("#kamb input[name='kambarys']:checked").val())>0)
				get_programprice($("#kamb input[name='kambarys']").val(), $("#datefrom").val());
		}
	});
	// slenkam kalendoriu
	$("#wm").click(function() {weekminus();programu_kalendorius();});
	$("#wp").click(function() {weekplus();programu_kalendorius();});
    }
   });
}


function proceduros(){

$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=proceduros&days='+$("#days").val()+'&hotelid='+$("#hotelid").val()+'&programid='+$("#programid").val()+'&persons='+$("#persons").val()+'&extra='+$("#extra").val(),
    dataType: 'html',
    success: function (html){
     $('#proceduros').html(html);
     $('#loading').remove(); 
    },
    complete: function () {

	$("#days").change(function() {
		proceduros();
	});


	$(".vdproc").click(function(){
		checkprocsel($(this).val(), returnInteger($(this).attr("name")), $(this).attr("abbr"));
	});


	$("#proceduros .procminfo").mouseover(function(){
		var idi=returnInteger($(this).attr("alt"));
		$(".prca"+idi).fadeIn();
	});

	$("#proceduros .procminfo").mouseout(function(){
		var idi=returnInteger($(this).attr("alt"));
		$(".prca"+idi).fadeOut();
	});

	for(i=0;i<$("#persons").val();i++){
		$("#spp"+i).change(function(st) {
			console.log($(this).text());
		});
	}
    }
   });

}

function checkprocsel(proc, mid, pt){

	var v_procs=returnInteger($("#v_procs").val());
	var v_procv=returnInteger($("#v_procv").val());
	var viso=0, kiek=0;
	var visoreik=(v_procs*returnInteger($("#persons").val()))+(v_procv*returnInteger($("#extra").val()));

	if(pt=="1"){ // suauge
		if(v_procs==1){
			$(".dsu"+mid).val("1");
			$(".pzm"+mid+"1").removeClass("chkred");
			$(".pzm"+mid+"1").addClass("chkgreen");
			$(".pzm"+mid+"1 span").html(0);
		}else{
			$(".pds"+mid+"1").each(function(index) {
				kiek=kiek+returnInteger($(this).val());
			});
			if(kiek==v_procs){
				$(".dsu"+mid).val(kiek);
				$(".pzm"+mid+"1").removeClass("chkred");
				$(".pzm"+mid+"1").addClass("chkgreen");
			}else{
				$(".dsu"+mid).val("");
				$(".pzm"+mid+"1").addClass("chkred");
				$(".pzm"+mid+"1").removeClass("chkgreen");
			}
			$(".pzm"+mid+"1 span").html(v_procs-kiek);
		}
	}else if(pt=="2"){ // vaikai

		if(v_procv==1){
			$(".dva"+mid).val("1");
			$(".pzm"+mid+"2").removeClass("chkred");
			$(".pzm"+mid+"2").addClass("chkgreen");
			$(".pzm"+mid+"2 span").html(0);
		}else{
			$(".pdv"+mid+"2").each(function(index) {
				kiek=kiek+returnInteger($(this).val());
			});
			if(kiek==v_procv){
				$(".dva"+mid).val(kiek);
				$(".pzm"+mid+"2").removeClass("chkred");
				$(".pzm"+mid+"2").addClass("chkgreen");
			}else{
				$(".dva"+mid).val("");
				$(".pzm"+mid+"2").addClass("chkred");
				$(".pzm"+mid+"2").removeClass("chkgreen");
			}
			$(".pzm"+mid+"2 span").html(v_procv-kiek);
		}

	}
	$(".totalproc").each(function(index) {
		viso=viso+returnInteger($(this).val());
	});	

	if(visoreik==viso) $("#procedurosok").val("true"); else $("#procedurosok").val("false");
}




function bindprocedurulist(){
$("#persons, #extra").change(function() {
	proceduros();
});
}

function bind_days(){
$("#days").change(function() {
	programu_kalendorius();
});
}

function bind_datefrom(){
$("#datefrom").change(function() {
	programu_kalendorius();
});
}

function bind_persons(){
$("#persons").change(function() {
	var vaiku=parseInt($("#maxpersons").val())-parseInt($("#persons").val());
	$("#extra option").remove();
	for(i=0;i<=vaiku;i++) $("#extra").append('<option value="'+i+'">'+i+'</option>');
	$('#agegroups').html("<select><option></option></select>");
	programu_kalendorius();
});
}

function bind_extras(){
$("#extra").change(function() {
	$("#roomid").val("");
	agegroups();
	programu_kalendorius();
});

}


function agegroups(){
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=agrupes&hotelid='+$("#hotelid").val()+'&extra='+$("#extra").val(),
    dataType: 'html',
    data: $('#rezervuoju :input'),
    success: function (html){
     $('#agegroups').html(html);
    },
    complete: function () {
	$("#agegroups select").change(function() {
		if($("#recalconvaik").val()=="ok"){
		if($("#roomid").val()!="")
			get_programprice($("#roomid").val(), $("#datefrom").val());
		}
	});
    }
   });
}







function chooseday(tipas){
var np="X", orr="OR";

$('#kainos td.busyday').html(np);
$('#kainos td.orday').html(orr);

var kiek=parseInt($("#days").val()), rodomdienu=parseInt($("#mindsk").val()), aktyvus, kiekimt;


$('#kainos td').mouseover(function() {
	aktyvus=parseInt(this.id);
	var eil=Math.ceil(aktyvus/rodomdienu);
	if(aktyvus%rodomdienu==0) eil=eil+1;

	if(aktyvus+kiek<=rodomdienu*eil) kiekimt=aktyvus+kiek; else kiekimt=rodomdienu*eil;
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onhover").each(function(index) {
			if($(this).text()==np){
				$(this).removeClass("busyday");
				$(this).addClass("busydayon");
			}
		});
	}else{
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onhovernt");
	}
});

$("#kainos td").mouseout(function(){
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").slice(aktyvus,kiekimt).removeClass("onhover").each(function(index) {
			if($(this).text()==np){
				$(this).removeClass("busydayon");
				$(this).addClass("busyday");
			}
		});
	}else{
		$("#kainos td[id]").slice(aktyvus,kiekimt).removeClass("onhovernt");
	}
});

$('#kainos td').click(function() {
var vaikaiok=true;

if($("#extra").val()>0){
	for(i=0;i<$("#extra").val();i++){
		if($("#va"+i).val()==0) vaikaiok=false;
	}
}
if(vaikaiok){
var u=true;
	$("#recalconvaik").val("ok");
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").removeClass("onclicked");
		$("#kainos td[id]").removeClass("ordayclicked");
		$("#orday").val("");
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onclicked").each(function(index) {
			if($(this).text()==np){u=false; $("#kainos td[id]").removeClass("onclicked");}
			if($(this).text()==orr){$(this).addClass("ordayclicked");$("#orday").val("true");}
		});


			if(u){
				ls=explode("|", this.abbr);
				$("#roomid").val(ls[1]);
				if(tipas=="programa") get_programprice(ls[1], ls[0]); else get_roomprice(ls[1], ls[0]);
			}else{
				if(tipas=="programa") $("programoskaina").text("KLAUSKITE"); else $("kambariokaina").text("KLAUSKITE");
			}
	}
}else alert($('#nepasirinktivaikai').val());
});



}



function get_programprice(roomid, datefrom){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$("#datefrom").val(datefrom);
var extraurl="";
var extra=$("#extra").val();
for(i=0;i<extra;i++){extraurl+="&va"+i+"="+$("#va"+i).val();}

$("#pappasl input[type=checkbox]").each(function() { 
	if(this.checked) extraurl+="&ppa[]="+this.value;
});

$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=getprogramprice&extra='+$("#extra").val()+'&persons='+$("#persons").val()+'&hotelid='+$("#hotelid").val()+'&roomid='+roomid+'&datefrom='+datefrom+'&programid='+$("#programid").val()+extraurl+'&orday='+$("#orday").val()+'&maittype='+$("#maittype").val()+'&isdc='+$("#isdc").val()+'&trukme='+$("input[name='dc_trume']:checked").val()+'&puproc='+$("input[name='dc_trume']:checked").attr("abbr")+'&days='+$("#days").val(),
    dataType: 'html',
    data: $('#rezervuoju :input'),
    success: function (html){
     $('#programoskaina').html(html);
    },
    complete: function () {
		$('#loading').remove();

		$(".pirktibtm_room").click(function(){
		
			var link="";
			$('.vdproc').each(function() {


			if($(this).val()>0){
				if($(this).attr("abbr")==1){
					if(($("#v_procs").val()=="1"&&$(this).attr("checked")==true)||($("#v_procs").val()!="1"))
						link=link+'<input type="hidden" name="ps['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).attr("id"))+'" /><input type="hidden" name="psv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).val())+'" />';
				}else{
					if(($("#v_procv").val()=="1"&&$(this).attr("checked")==true)||($("#v_procv").val()!="1"))
						link=link+'<input type="hidden" name="pv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).attr("id"))+'" /><input type="hidden" name="pvv['+returnInteger($(this).attr("class"))+'][]" value="'+returnInteger($(this).val())+'" />';
				}
			}



			});
			$("#procsar").html(link);
			if($("#procedurosok").val()!="true"){
				alert($("#nesuvedeteproceduruklaida").val());
				return false;
			}
		});

		
	}
	});
}







function openprogram(progid){
	order_programa(returnInteger(progid),0);
}


/*##################################################################################################
##################################################################################################*/


function order_rooms(hotelid){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=order-room&hotelid='+hotelid,
    dataType: 'html',
    success: function (html){
    	$('#apgyvendinimas').html(html);
    },
    complete: function () {

	$("#pappasl label").mouseover(function(){
		var idi=returnInteger($(this).attr("for"));
		var ishtm=$(".pap"+idi).html();
		if(ishtm.length>5) $(".pap"+idi).fadeIn();
		$(this).css("background-color", "#7CB6CE");
	});
	$("#pappasl label").mouseout(function(){
		var idi=returnInteger($(this).attr("for"));
		$(".pap"+idi).fadeOut();
		$(this).css("background-color", "white");
	});


	$("#programid").remove();
	$("#datefrom").datepicker({minDate: returnInteger($("#hotel_daysoff").val()), maxDate: '+'+$("#maxdaysfuture").val()+'D'});

	bind_kdays();
	bind_kdatefrom();
	bind_kpersons();
	bind_kextras();
	$("#pappasl input[type=checkbox]").click(function() {
		if($("#recalconvaik").val()=="ok") get_roomprice($("#roomid").val(), $("#datefrom").val());
	});
	$("#maittype").change(function() {
		get_roomprice($("#roomid").val(), $("#datefrom").val());
	});
	kambariu_kalendorius();


	$('#loading').remove(); 

    }
   });

}



function bind_kdays(){
$("#days").change(function() {
	kambariu_kalendorius();
});
}


function bind_kpersons(){
$("#persons").change(function() {
	var vaiku=parseInt($("#maxpersons").val())-parseInt($("#persons").val());
	$("#extra option").remove();
	for(i=0;i<=vaiku;i++) $("#extra").append('<option value="'+i+'">'+i+'</option>');
	$('#agegroups').html("<select><option></option></select>");
	kambariu_kalendorius();
});
}


function bind_kextras(){
$("#extra").change(function() {
	$("#roomid").val("");
	kagegroups();
	kambariu_kalendorius();
});

}



function kagegroups(){
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=agrupes&hotelid='+$("#hotelid").val()+'&extra='+$("#extra").val(),
    dataType: 'html',
    data: $('#rezervuoju :input'),
    success: function (html){
     $('#agegroups').html(html);
    },
    complete: function () {
	$("#agegroups select").change(function() {
	if($("#roomid").val()!="")
		get_roomprice($("#roomid").val(), $("#datefrom").val());
	});
    }
   });
}






function kambariu_kalendorius(){
$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=kcalendar&hotelid='+$("#hotelid").val()+'&datefrom='+$("#datefrom").val()+'&persons='+$("#persons").val()+'&extra='+$("#extra").val(),
    dataType: 'html',
    success: function (html){
     $('#kalendorius').html(html);
     $('#loading').remove(); 
    },
    complete: function () {
	chooseday("kambarys");
	$("#wm").click(function() {weekminus();kambariu_kalendorius();});
	$("#wp").click(function() {weekplus();kambariu_kalendorius();});
    }
   });
}



function get_roomprice(roomid, datefrom){
$("#datefrom").val(datefrom);
var extraurl="";
var extra=$("#extra").val();
for(i=0;i<extra;i++){extraurl+="&va"+i+"="+$("#va"+i).val();}

$("#pappasl input[type=checkbox]").each(function() { 
	if(this.checked) extraurl+="&ppa[]="+this.value;
});

$('body').append('<div id="loading"><img src="images/base/progress.gif" alt="" /></div>');
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=getroomprice&persons='+$("#persons").val()+'&extra='+$("#extra").val()+'&hotelid='+$("#hotelid").val()+'&roomid='+roomid+'&datefrom='+datefrom+'&days='+$("#days").val()+extraurl+'&orday='+$("#orday").val()+'&maittype='+$("#maittype").val(),
    dataType: 'html',
    data: $('#rezervuoju :input'),
    success: function (html){
     $('#kambariokaina').html(html);
    },
    complete: function () {
    	$('#loading').remove();
    	roominfo(roomid);
    }
   });

}


function roominfo(roomid){
$.ajax({
    type: 'post',
    url: 'index.php?page=jquery-kambariu-rezervavimas&h=kambarioinfo&roomid='+roomid,
    dataType: 'html',
    success: function (html){
     $('#roominfo').html(html);
    },
    complete: function () {
	

    }
   });
}

function bind_kdatefrom(){
$("#datefrom").change(function() {
	kambariu_kalendorius();
});
}













function mksign(type){
	$('#dovanucekis,#dcstep2bank').append('<p align="center" id="waitmd"><img align="center" src="images/base/progress.gif" alt="" /></p>');
	$("#apmoketibanke").css("display", "none");
//	$("#banksumoketip").css("display", "none");


        var fields = Array('projectid', 'orderid', 'lang', 'amount', 'currency', 'accepturl', 'cancelurl', 'callbackurl', 'payment', 'country', 'p_firstname', 'p_lastname', 'p_email', 'p_street', 'p_city', 'p_state', 'p_zip', 'p_countrycode', 'test', 'version');
	var data = '';
	for ( var i in fields ){
		if($("input[name='"+fields[i]+"']").val()&&jQuery.trim(fields[i])!='') data+=$("input[name='"+fields[i]+"']").val();
	}
	$.ajax({
	    type: 'post',
	    url: 'libs/libwebtopay/md5.php?in='+data,
	    dataType: 'html',
	    success: function (html){
	     $("input[name='sign']").val(html);
	    },
	    complete: function () {
		$('#waitmd').remove();
		$("#apmoketibanke").css("display", "inline-block");
		//$("#banksumoketip").css("display", "inline-block");
		//if(type=="submitafer") document.pirktiprograma.submit();

		}
	});
}

function orderdcprogram(){
var np="X", orr="OR";

$('#kainos td.busyday').html(np);
$('#kainos td.orday').html(orr);


var kiek=parseInt($("#days").val()), rodomdienu=parseInt($("#mindsk").val()), aktyvus, kiekimt, dnuo;

$('#kainos td').mouseover(function() {
	aktyvus=parseInt(this.id);
	var eil=Math.ceil(aktyvus/rodomdienu);
	if(aktyvus%rodomdienu==0) eil=eil+1;

	if(aktyvus+kiek<=rodomdienu*eil) kiekimt=aktyvus+kiek; else kiekimt=rodomdienu*eil;
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onhover").each(function(index) {
			if($(this).text()==np){
				$(this).removeClass("busyday");
				$(this).addClass("busydayon");
			}
		});
	}else{
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onhovernt");
	}
});

$("#kainos td").mouseout(function(){
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").slice(aktyvus,kiekimt).removeClass("onhover").each(function(index) {
			if($(this).text()==np){
				$(this).removeClass("busydayon");
				$(this).addClass("busyday");
			}
		});
	}else{
		$("#kainos td[id]").slice(aktyvus,kiekimt).removeClass("onhovernt");
	}
});


$('#kainos td').click(function() {

var u=true, p=true;
	if($("#kainos td[id]").slice(aktyvus,kiekimt).length==kiek){
		$("#kainos td[id]").removeClass("onclicked");
		$("#kainos td[id]").removeClass("ordayclicked");
		$("#orday").val("");
		$("#kainos td[id]").slice(aktyvus,kiekimt).addClass("onclicked").each(function(index) {
			if($(this).text()==np){u=false; $("#kainos td[id]").removeClass("onclicked");}
			if($(this).text()==orr){p=false;$(this).addClass("ordayclicked");$("#orday").val("true");}
		});


			if(u){
				get_db_btm(this.abbr, p);
			}
	}
});

}



function get_db_btm(datanuo, tipas){
	$("#datanuo").val(datanuo);
	if(!tipas){
		$(".dcpckk").fadeIn();
		$(".dcpck").css("display", "none");
	}else{
		$(".dcpck").fadeIn();
		$(".dcpckk").css("display", "none");
	}
}


function validate_email(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else return true;
}


function iecheck(){
var ie7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
if(ie7){
	$("#home_box").css("display", "none");
}
}




