$(function()	{
	var duration = 500, checkInterval, rotateInterval, 
		parambooking='', parambooking1='', parambooking2='', paramconfirm='',
		detailmargin = 0, idxnewsrot = 0, idxpromorot = 0, idxnewsmax = 1, idxpromomax = 1;
	init();
	function init() {
		$.ajax({ 
			type: "POST", 
			url: "AJAXCheckRedir.php", 
			data: "", 
			success: function(response){ 
				if(response.indexOf("paypal")>=0) { 
					arResp = response.split("@@@");
					parambooking='';
					var $bookingstatus = arResp[3],
						$bookingcode = arResp[1],
						$ori = $("#maincontent .reservation"),
						$dest = $("#reservationform");
					parambooking = "promo="+arResp[2]+"&";
					$("#reservationform").show();
					/*$("#anim").css({ 
					   left:$ori.offset().left, top:$ori.offset().top, 
					   width:$ori.width(), height:$ori.height(), 
					   background:"#FFF", display:"block",
					   opacity:0, filter:"alpha(opacity=0)"
					});*/
					$("#mask").fadeIn(1000); 
					/*$("#anim").animate({
					   left:$dest.css("left"), top:$dest.css("top"), 
					   marginLeft:$dest.css("margin-left"), 
					   marginTop:$dest.css("margin-top"), 
					   width:$dest.css("width"), height:$dest.css("height"),
					   opacity:0.5, filter:"alpha(opacity=50)"
					},500, function() { 
						$("#reservationform").animate({ opacity:1.0, filter:"alpha(opacity=100)" },500);
						goStepPPLast($bookingcode,$bookingstatus);
					});*/
					$("#anim").css({ 
					   left:$dest.css("left"), top:$dest.css("top"), 
					   marginLeft:$dest.css("margin-left"), 
					   marginTop:$dest.css("margin-top"), 
					   width:$dest.css("width"), height:$dest.css("height"),
					   background:"#FFF", display:"block",
					   opacity:0, filter:"alpha(opacity=0)"
					});
					$("#reservationform").animate({ opacity:1.0, filter:"alpha(opacity=100)" },1000);
					goStepPPLast($bookingcode,$bookingstatus);
				} 
				/* set expression reservation form position */
				
				$("#container").click(function(e) { /* to hide Combo */
					var $target = $(e.target);
					if($(e.target).is(":not(.Combo, .ComboScroll, .ComboForm)")) {
						$(".Combo").hide(); 
						$(".ComboScroll").hide(); 
					}
				});
				$("#maincontent .map a").click(function(e) { e.preventDefault(); showMap() });
				checkLatestContent();
				setMenuTopEvent();
				setBookingFormEvent();
			},
			error: function() { window.alert('Internal Error... Call the vendor...') }
		});
	}
	function checkLatestContent() {
		clearInterval(checkInterval);
		genLatestContent();
		checkInterval = setInterval(genLatestContent,2*60*duration); 	// 1 minutes		
	}
	function checkRotator() {
		clearInterval(rotateInterval);
		rotateContent();
		rotateInterval = setInterval(rotateContent,20*duration);		// 10 detik	
	}
	function rotateContent() {
		setYMStatus();
		// refresh map
		$("#maincontent .map img").each(function(){
			$(this).attr("src",$(this).attr("src")+ "?" + (new Date()).getTime());
		});
		// rotate News;
		/*
		$("#maincontent .news .content .item").each(function() {
			if($("#maincontent .news .content .item").index(this)==idxnewsrot)
				$(this).css({ display:"block"});	
			else
				$(this).css({ display:"none"});	
		});
		idxnewsrot+=1;
		if(idxnewsrot>=$("#maincontent .news .content .item").length) idxnewsrot=0;
		*/
		/* diganti below */
		if($("#maincontent .news .content .item").get().length>3) {
			$("#maincontent .news .content .item").eq(0).clone().appendTo($("#maincontent .news .content"));
			$("#maincontent .news .content .item").eq(0).remove();
		}
		$("#maincontent .news .content .item a.title").unbind()
		.click(function(e){
			e.preventDefault(); showNewsDetail($(this));
		});
		$("#maincontent .news .content .item").each(function() {
			if($("#maincontent .news .content .item").index(this)<=2)
				$(this).css({ display:"block"});	
			else
				$(this).css({ display:"none"});	
		});
		// rotate Promo;
		/*$("#maincontent .promo .content .item").each(function() {
			if($("#maincontent .promo .content .item").index(this)==idxpromorot)
				$(this).css({ display:"block"});	
			else
				$(this).css({ display:"none"});	
		});
		idxpromorot+=1;
		if(idxpromorot>=$("#maincontent .promo .content .item").length) idxpromorot=0;*/
		/* diganti below */
		if($("#maincontent .promo .content .banner").get().length>3) {
			$("#maincontent .promo .content .banner").eq(0).clone().appendTo($("#maincontent .promo .content"));
			$("#maincontent .promo .content .banner").eq(0).remove();
		}
		$("#maincontent .promo .banner").unbind()
		.click(function(){
			showPromoDetail($(this));
		});
		$("#maincontent .promo .content .banner").each(function() {
			if($("#maincontent .promo .content .banner").index(this)<=2)
				$(this).css({ display:"block"});	
			else
				$(this).css({ display:"none"});	
		});
	}
	function setYMStatus() {
		$.ajax({ 
			type: "POST", 
			url: "AJAXGetYMStatus.php", 
			data: "",
			success: function(response){ 
				var ymid = response.substr(2,response.length-2),
					state = response.substr(0,2);
				$("#YMSender").unbind();
				if(state=="01") {
					$("#maincontent .YM").css({ background:"url(images/YMon.gif) no-repeat center" });	
					$("#YMSender").attr("href","ymsgr:sendIM?"+ymid);
					$("#YMSender").attr("title","Contact Guest Service via YM pandanaran_hotel@yahoo.com");
					$("#YMSender").click(function(e) { e.preventDefault(); showYMPingBox(); });
				} else if(state=="00") {
					$("#maincontent .YM").css({ background:"url(images/YMoff.gif) no-repeat center" });	
					$("#YMSender").removeAttr("href");
					$("#YMSender").removeAttr("title");
					$("#YMSender").click(function(e) { e.preventDefault(); showYMPingBox(); });
				} else {
					$("#maincontent .YM").css({ background:"url(images/YMoff.gif) no-repeat center" });	
					$("#YMSender").removeAttr("href");
					$("#YMSender").removeAttr("title");
					$("#YMSender").click(function(e) { e.preventDefault() });
				}
			}, error: function() { 
				$("#maincontent .YM").css({ background:"url(images/YMoff.gif) no-repeat center" });	
			}
		});
	}
	function showYMPingBox() {
		$.ajax({ 
			type: "POST", 
			url: "AJAXYMPingBox.php", 
			success: function(html){ 
				var offset = $("#maincontent .YM").offset(), 
					width = $("#maincontent .YM").width(), height = $("#maincontent .YM").height();
				$("#YMPingBox").css({ 
				   display:"block", opacity:0, filter:"alpha(opacity=0)"
				});
				//$("#YMPingBox").html(html);	
				$("#anim").css({ 
				   left:offset.left, top:offset.top, width:width, height:height, 
				   background:"#FFF", display:"block",
				   opacity:0, filter:"alpha(opacity=0)"
				});
				//$("#mask").fadeIn(1000); 
				$("#anim").animate({ 
				   left:$("#YMPingBox").offset().left, top:$("#YMPingBox").offset().top, 
				   width:$("#YMPingBox").width(), height:$("#YMPingBox").height(), 
				   opacity:1.0, filter:"alpha(opacity=100)"
				},500,function() {
					$("#YMPingBox").html(html)
					.animate({ opacity:1.0, filter:"alpha(opacity=100)"},500);
					$("#YMPingBox .header span").click(function() {
						$("#YMPingBox").html('');
						$("#YMPingBox").fadeOut(500);
						setTimeout(function() {
							//$("#mask").fadeOut(1000); 
							$("#anim").animate({ 
							   left:offset.left, top:offset.top, width:width, height:height, 
							   opacity:0, filter:"alpha(opacity=0)"
							},500,function() { $("#anim").hide(); /*$("#YMPingBox").html('');*/ });
						},500);
																	
					});
				}); 
			}
		});
	}
	function setMenuTopEvent() {
		/* menu events */
		$("#mnutop .mnutop").click(function(){
			var idx = $("#mnutop .mnutop").index(this),
				offset = $(this).offset(), width = $(this).width(), height = $(this).height();
			if(idx==5) { showLocation($(this),$("#mainpic")); } 
			else if(idx==4) { showReservation($(this)); } 
			else { showMnuDetail(idx); }
		});
		$("#detail .underconstruction").click(function(){ 
			$dest = $("#mnutop .mnutop[title]"),
			$transit = $("#mnutop .mnutop[title]").get().length>0 ? 
							$("#mainpic") : $("#maincontent");
			$("#anim").css({ 
			   left:$("#detail").offset().left, top:$("#detail").offset().top, 
			   width:$("#detail").width(), height:$("#detail").height(), 
			   /*background:"#FFF", display:"block",*/
			   opacity:1.0, filter:"alpha(opacity=100)"
			});
			$("#detail").fadeOut(500);
			setTimeout(function() {
				$("#mask").fadeOut(1000); 
				$("#anim").animate({ 
				   left:$transit.offset().left, top:$transit.offset().top, 
				   width:$transit.width(), height:$transit.height(), 
				   opacity:0.5, filter:"alpha(opacity=50)"
				},500)
				.animate({ 
				   left:$dest.offset() ? $dest.offset().left : 0.5*$transit.width()+"px", 
				   top:$dest.offset() ? $dest.offset().top : 1.5*$transit.height()+"px", 
				   width:$dest.offset() ? $dest.width() : 0, 
				   height:$dest.offset() ? $dest.height() : 0, 
				   opacity:0, filter:"alpha(opacity=0)"
				},500, function() { $dest.removeAttr("title"); $("#anim").hide() });
			},500);
		});
	}
	function setMenuTopEvents() {
		/* menu events */
		$("#mnutop .mnutop").click(function(){
			var idx = $("#mnutop .mnutop").index(this),
				offset = $(this).offset(), width = $(this).width(), height = $(this).height();
			if(idx==5) { showLocation($(this),$("#mainpic")); } 
			else if(idx==4) { showReservation($(this)); } 
			else {
				var $mnutop = $(this);
				$("#anim").css({ 
				   left:$(this).offset().left, top:$(this).offset().top, 
				   width:$(this).width(), height:$(this).height(), 
				   background:"#FFF", display:"block",
				   opacity:0, filter:"alpha(opacity=0)"
				});
				$("#mask").fadeIn(1000); 
				$("#anim").animate({ 
				   left:$("#mainpic").offset().left, top:$("#mainpic").offset().top, 
				   width:$("#mainpic").width(), height:$("#mainpic").height(), 
				   opacity:0.5, filter:"alpha(opacity=50)"
				},500)
				.animate({
					height:3*$("#mainpic").height(),
				   opacity:1, filter:"alpha(opacity=100)"
				},500, function() { $("#detail").fadeIn(500); $mnutop.attr("title","shown"); });
			}
		});
		$("#detail .underconstruction").click(function(){ 
			$dest = $("#mnutop .mnutop[title]"),
			$transit = $("#mnutop .mnutop[title]").get().length>0 ? 
							$("#mainpic") : $("#maincontent");
			$("#anim").css({ 
			   left:$("#detail").offset().left, top:$("#detail").offset().top, 
			   width:$("#detail").width(), height:$("#detail").height(), 
			   /*background:"#FFF", display:"block",*/
			   opacity:1.0, filter:"alpha(opacity=100)"
			});
			$("#detail").fadeOut(500);
			setTimeout(function() {
				$("#mask").fadeOut(1000); 
				$("#anim").animate({ 
				   left:$transit.offset().left, top:$transit.offset().top, 
				   width:$transit.width(), height:$transit.height(), 
				   opacity:0.5, filter:"alpha(opacity=50)"
				},500)
				.animate({ 
				   left:$dest.offset() ? $dest.offset().left : 0.5*$transit.width()+"px", 
				   top:$dest.offset() ? $dest.offset().top : 1.5*$transit.height()+"px", 
				   width:$dest.offset() ? $dest.width() : 0, 
				   height:$dest.offset() ? $dest.height() : 0, 
				   opacity:0, filter:"alpha(opacity=0)"
				},500, function() { $dest.removeAttr("title"); $("#anim").hide() });
			},500);
		});
	}
	function genLatestContent() {
		$.ajax({ 
			type: "POST", 
			url: "AJAXHomeLatestContent.php", 
			success: function(html){ 
				arHTML = html.split('<!---splitter--->');
				$("#maincontent .news .content").html(arHTML[0]);	
				$("#maincontent .promo .content").html(arHTML[1]);	
				$("#maincontent .news .readmore a").click(function(e){
					e.preventDefault(); 
				});
				$("#maincontent .news .content .item a.title").click(function(e){
					e.preventDefault(); showNewsDetail($(this));
				});
				$("#maincontent .promo .readmore a").click(function(e){
					e.preventDefault(); 
				});
				$("#maincontent .promo .banner").click(function(){
					showPromoDetail($(this));
				});
				checkRotator();
			}
		});
	}
	function showDetail(ori,transit,html) { 
		var offset = ori.offset(), width = ori.width(), height = ori.height();
		$("#detail").css({ 
		   display:"block", opacity:0, filter:"alpha(opacity=0)"
		});
		$("#anim").css({ 
		   left:offset.left, top:offset.top, width:width, height:height, 
		   background:"#FFF", display:"block",
		   opacity:0, filter:"alpha(opacity=0)"
		});
		$("#mask").fadeIn(1000); 
		$("#anim").animate({ 
		   left:$("#detail").offset().left, top:transit.offset().top, 
		   width:$("#detail").width(), height:transit.height(), 
		   opacity:0.5, filter:"alpha(opacity=50)"
		},500)
		.animate({
			top:$("#detail").offset().top, 
			height:$("#detail").height(),
		   opacity:1, filter:"alpha(opacity=100)"
		},500, function() { 
			var x = $("#detail").offset().left+$("#detail").width()-10,
				y = $("#detail").offset().top-10; 
			var clickDetail = function(code) {
				$.ajax({ 
					type: "POST", 
					url: "AJAXMnuDetail"+code+".php", 
					success: function(html){ 
						$("#detail .content").html(html);
						$("#detail .content").scrollTop(0);
						$("#detail .content .link").click(function(e) {
							e.preventDefault();
							var code = $(this).attr("href");
							code = code .substr(code .indexOf("#")+1,code .length-code .indexOf("#")-1);
							clickDetail(code);
						});
					}
				});
			}
			$("#detail").html(html) 
			.animate({ opacity:1.0, filter:"alpha(opacity=100)"},500);
			/* added to maintain anim's position on resizing */
			$("#anim").css({ 
				top:"50%", marginTop:$("#detail").css("margin-top"),
				left:"50%", marginLeft:$("#detail").css("margin-left")
			});
			/* set Close Detail Button */
			$("#closedetail").css({ 
				display:"block", /*left:x+"px", top:y+"px", */
				top:"50%", marginTop:($("#detail").height()/-2)-10,
				left:"50%", marginLeft:$("#detail").width()/2-10,
				opacity:0, filter:"alpha(opacity=0)"
			})
			.animate({ opacity:1, filter:"alpha(opacity=100)"},500);
			$("#detail .content").scrollTop(0);
			$("#detail .content .link").click(function(e) {
				e.preventDefault();
				var code = $(this).attr("href");
				code = code .substr(code .indexOf("#")+1,code .length-code .indexOf("#")-1);
				clickDetail(code);
			});
			$("#detail .title").click(function() { clickDetail($(this).attr("title")) });
			$("#closedetail").unbind();
			$("#closedetail").click(function() {
				$("#anim").css({
				   top:$("#detail").offset().top, marginTop:0, 
				   left:$("#detail").offset().left, marginLeft:0
				})
				$(this).fadeOut(500);
				$("#detail").fadeOut(500);
				setTimeout(function() {
					$("#mask").fadeOut(1000); 
					$("#anim").animate({ 
					   top:transit.offset().top, 
					   height:transit.height(), 
					   opacity:0.5, filter:"alpha(opacity=50)"
					},500)
					.animate({ 
					   left:offset.left, top:offset.top, width:width, height:height, 
					   opacity:0, filter:"alpha(opacity=0)"
					},500,function() { $("#anim").hide(); $("#detail").html(''); });
				},500);
			});
		});
	}
	function showDetailMedium(ori,transit,html) { 
		var offset = ori.offset(), width = ori.width(), height = ori.height();
		$("#detailmedium").css({ 
		   display:"block", opacity:0, filter:"alpha(opacity=0)"
		});
		$("#anim").css({ 
		   left:offset.left, top:offset.top, width:width, height:height, 
		   background:"#FFF", display:"block",
		   opacity:0, filter:"alpha(opacity=0)"
		});
		$("#mask").fadeIn(1000); 
		$("#anim").animate({ 
		   left:$("#detailmedium").offset().left, top:transit.offset().top, 
		   width:$("#detailmedium").width(), height:transit.height(), 
		   opacity:0.5, filter:"alpha(opacity=50)"
		},500)
		.animate({
			top:$("#detailmedium").offset().top, 
			height:$("#detailmedium").height(),
		   opacity:1, filter:"alpha(opacity=100)"
		},500, function() { 
			var x = $("#detailmedium").offset().left+$("#detailmedium").width()-10,
				y = $("#detailmedium").offset().top-10; 
			$("#detailmedium").html(html) 
			.animate({ opacity:1.0, filter:"alpha(opacity=100)"},500);
			/* added to maintain anim's position on resizing */
			$("#anim").css({ 
				top:"50%", marginTop:$("#detailmedium").css("margin-top"),
				left:"50%", marginLeft:$("#detailmedium").css("margin-left")
			});
			/* set Close Detail Button */
			$("#closedetail").css({ 
				display:"block", /*left:x+"px", top:y+"px", */
				top:"50%", marginTop:($("#detailmedium").height()/-2)-10,
				left:"50%", marginLeft:$("#detailmedium").width()/2-10,
				opacity:0, filter:"alpha(opacity=0)"
			})
			.animate({ opacity:1, filter:"alpha(opacity=100)"},500);
			$("#closedetail").unbind();
			$("#closedetail").click(function() {
				$("#anim").css({
				   top:$("#detailmedium").offset().top, marginTop:0, 
				   left:$("#detailmedium").offset().left, marginLeft:0
				})
				$(this).fadeOut(500);
				$("#detailmedium").fadeOut(500);
				setTimeout(function() {
					$("#mask").fadeOut(1000); 
					$("#anim").animate({ 
					   top:transit.offset().top, 
					   height:transit.height(), 
					   opacity:0.5, filter:"alpha(opacity=50)"
					},500)
					.animate({ 
					   left:offset.left, top:offset.top, width:width, height:height, 
					   opacity:0, filter:"alpha(opacity=0)"
					},500,function() { $("#anim").hide(); $("#detailmedium").html(''); });
				},500);
			});
		});
	}
	function showReservation(ori) {
		$.ajax({ 
			type: "POST", 
			url: "AJAXMnuReservation.php", 
			data: "",
			success: function(html){ 
				var offset = ori.offset(), width = ori.width(), height = ori.height(),
					$dest = $("#reservationform");
				//parambooking = param+"promo=regular&";
				$("#reservationform").show();
				$("#reservationform .content").html(html);
				$("#reservationform .ButtonForm[name='Cancel']").val('Cancel');
				$("#reservationform .step").hide();
				$("#reservationform .buttons").hide();
				$("#reservationform .button").show();
				setMnuReservationFormEvent(ori);
				$("#anim").css({ 
				   left:offset.left, top:offset.top, 
				   width:width, height:height, 
				   background:"#FFF", display:"block",
				   opacity:0, filter:"alpha(opacity=0)"
				});
				$("#mask").fadeIn(1000); 
				$("#anim").animate({
				   left:$dest.css("left"), top:$dest.css("top"), 
				   marginLeft:$dest.css("margin-left"), 
				   marginTop:$dest.css("margin-top"), 
				   width:$dest.css("width"), height:$dest.css("height"),
				   opacity:0.5, filter:"alpha(opacity=50)"
				},500, function() { 
					$("#reservationform").animate({ opacity:1.0, filter:"alpha(opacity=100)" },500);
					//goStep(0); 
				});
			}
		});
	}
	function showMnuDetail(idx) { 
		$.ajax({ 
			type: "POST", 
			url: "AJAXMnu"+idx+".php", 
			data: "",
			success: function(html){ 
				showDetail($("#mnutop .mnutop:eq("+idx+")"),$("#mainpic"),html); 
			}
		});
	}
	function showLocation(ori,transit) { 
		$.ajax({ 
			type: "POST", 
			url: "AJAXLocation.php", 
			data: "",
			success: function(html){ showDetailMedium(ori,transit,html) }
		});
	}
	function showNewsDetail(a) {
		var code = a.attr("href"),
			offset = a.offset(), width = a.width(), height = a.height();
		code = code .substr(code .indexOf("#")+1,code .length-code .indexOf("#")-1);
		$.ajax({ 
			type: "POST", 
			url: "AJAXNewsDetail.php", 
			data: "id="+escape(code),
			success: function(html){ 
				showDetailMedium(a,$("#maincontent"),html); 
			}, error: function() { 
				window.alert('Unknown Error. Try Again!');
			}
		});
	}
	function showPromoDetail(banner) {
		var code = banner.text();
		$.ajax({ 
			type: "POST", 
			url: "AJAXPromoDetail.php", 
			data: "id="+escape(code),
			success: function(html){ 
				showDetailMedium(banner,$("#maincontent"),html); 
				setTimeout(function() { checkBookNow(code) },500);
			}, error: function() { 
				window.alert('Unknown Error. Try Again!');
			}
		});
	}
	function checkBookNow(code) { 
		if($("#detailmedium .promo .booknow").get().length>0) { 
			$("#detailmedium .promo .booknow").unbind();
			$("#detailmedium .promo .booknow").css({ cursor:"pointer" });
			$("#detailmedium .promo .booknow").click(function() { 
				/* reset margin first */
				$("#anim").css({
				   top:$("#detailmedium").offset().top, marginTop:0, 
				   left:$("#detailmedium").offset().left, marginLeft:0
				});
				$("#detailmedium").fadeOut(500);
				$("#closedetail").fadeOut(500);
				$("#reservationform").show();
				$("#reservationform .promosign").show();
				$("#reservationform .step").hide();
				$("#reservationform .buttons").hide();
				$("#reservationform .button").show();
				setTimeout(function() {
					$("#detailmedium").html('');
					$("#anim").animate({ 
					   left:$("#reservationform").offset().left, 
					   top:$("#reservationform").offset().top, 
					   width:$("#reservationform").width(), height:$("#reservationform").height()/*, 
					   opacity:0.5, filter:"alpha(opacity=50)"*/
					},500, function() { 
						$("#reservationform").animate({ opacity:1.0, filter:"alpha(opacity=100)" },500);
						/*var param = '', date = new Date();
						$("#maincontent .reservation input[class!='ButtonForm']").each(function() { 
							$(this).val(''); // reset regular parameter 
							if($(this).attr("class").indexOf('DateForm')>=0) {
								if($(this).attr("name").indexOf('eckIn')>0)
									param+=$(this).attr("name")+"="+escape(Date.parse("today").toString('yyyy-MM-dd'))+"&"	
								else
									param+=$(this).attr("name")+"="+escape(Date.parse("tomorrow").toString('yyyy-MM-dd'))+"&"	
							} else {
								param+=$(this).attr("name")+"=1&"	
							}
						});
						param+='promo='+escape(code)+'&';
						parambooking=param;
						goStep(0);*/
						showPromoBookingForm(code);
					});
				},500);
			})
		} else { setTimeout(function() { checkBookNow(code) },500); }
	}
	function showMap() {
		$.ajax({ 
			type: "POST", 
			url: "AJAXGMap.php", 
			data: "",
			success: function(html){ 
				showDetailMedium($("#maincontent .map"),$("#maincontent"),html); 
			}, error: function() { 
				window.alert('Unknown Error. Try Again!');
			}
		});
	}
	function setBookingFormEvent() {
		/* to prevent Combo position mlethat mlethot */
		$(window).unbind();
		$("#maincontent .DateForm").unbind();
		$("#maincontent .ComboForm").unbind();
		$("#maincontent .ButtonForm").unbind();
		$(window).resize(function(e){ $(".Combo").hide(); $(".ComboScroll").hide(); });
		$("#maincontent .DateForm").datepicker({
			dateFormat: 'DD, d MM, yy', showOn: "focus", 
			autoSize: true,
			buttonImageOnly: false
		});
		$("#maincontent .ComboForm").click(function(e) { 
			var cbo = $(this);
			$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
			var el = $(this),
				cboList = $("#Combo"+$(this).attr("name")),
				cboListOpt = $("#Combo"+$(this).attr("name")+" a");
			if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
				var offset = el.offset();
				var offset1 = $("#maincontent .reservation").offset();
				cboList.css({ 
					left: offset.left+"px", 
					top: offset.top+el.height()+1+"px", 
					width: el.width()+5+"px"
				});
				cboList.show();
				cboListOpt.unbind();
				cboListOpt.click(function(e) { 
					e.preventDefault();
					var text = $(this).text(),
						kode = $(this).attr("href");
					kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
					el.val(text);
					if(cbo.attr("name")=='Rooms') {
						$("#maincontent .ComboForm[name='Persons']").val(text);
						genComboList($("#ComboPersons"),parseInt(text),3);
					}
					cboList.hide();
				});
			} else cboList.hide();
		});
		$("#maincontent .ButtonForm[name='Reset']").click(function() { 
			$("#maincontent .DateForm").val('');
			$("#maincontent .ComboForm").val('');
			parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
		});
		$("#maincontent .ButtonForm[name='CheckAvail']").click(function() { 
			var param = ''; parambooking = '';
			$("#maincontent input[class*='Form']").each(function() {
				if($(this).val()=='') {
					window.alert("Fill the "+$(this).attr("title")+" data!");
					param = '';
					return false;
				} else {
					if($(this).attr("class").indexOf('DateForm')>=0) {
						/* var dt = $(this).datepicker("getDate"); // equal to below */
						var dt = new Date($(this).val()); 
						param+=$(this).attr("name")+"="+escape(dt.toString('yyyy-MM-dd'))+"&"	
					} else {
						param+=$(this).attr("name")+"="+escape($(this).val())+"&"	
					}
				}
			});
			if(param!='') { 
				var CheckIn = new Date($("#maincontent .DateForm[name='CheckInDate']").val()),
					CheckOut = new Date($("#maincontent .DateForm[name='CheckOutDate']").val()),
					Today = new Date();
				if(Today-CheckIn>86400000 || CheckOut-CheckIn<=0) {
					window.alert('Please check your Check-in and Check-out Date!');
					param = '';
				} else {
					var $ori = $("#maincontent .reservation"),
						$dest = $("#reservationform");
					parambooking = param+"promo=regular&";
					$("#reservationform").show();
					$("#anim").css({ 
					   left:$ori.offset().left, top:$ori.offset().top, 
					   width:$ori.width(), height:$ori.height(), 
					   background:"#FFF", display:"block",
					   opacity:0, filter:"alpha(opacity=0)"
					});
					$("#mask").fadeIn(1000); 
					$("#anim").animate({
					   /*left:$dest.css("left"), top:$dest.css("top"), */
					   left:"50%", top:"50%",
					   marginLeft:$dest.css("margin-left"), 
					   marginTop:$dest.css("margin-top"), 
					   width:$dest.css("width"), height:$dest.css("height"),
					   opacity:0.5, filter:"alpha(opacity=50)"
					},500, function() { 
						$("#reservationform").animate({ opacity:1.0, filter:"alpha(opacity=100)" },500);
						goStep(0); 
					});
				}
			} 
		});
	}
	function setMnuReservationFormEvent(ori) { /* from Mnu Reservation */
		var offset = ori.offset(), width = ori.width(), height = ori.height(),
			$dest = $("#reservationform");
		/* to prevent Combo position mlethat mlethot */
		$(window).unbind();
		$("#reservationform .DateForm").unbind();
		$("#reservationform .ComboForm").unbind();
		$("#reservationform .ButtonForm").unbind();
		$(window).resize(function(e){ $(".Combo").hide(); $(".ComboScroll").hide(); });
		$("#reservationform .DateForm").datepicker({
			dateFormat: 'DD, d MM, yy', showOn: "focus", 
			autoSize: true,
			buttonImageOnly: false
		});
		$("#reservationform .TextForm[name='BookingCode']").mask("999999",{placeholder:"-"});
		$("#reservationform .ComboForm").click(function(e) { 
			var cbo = $(this);
			$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
			var el = $(this),
				cboList = $("#Combo"+$(this).attr("name")),
				cboListOpt = $("#Combo"+$(this).attr("name")+" a");
			if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
				var offset = el.offset();
				var offset1 = $("#reservationform").offset();
				cboList.css({ 
					left: offset.left+"px", 
					top: offset.top+el.height()+1+"px", 
					width: el.width()+5+"px"
				});
				cboList.show();
				cboListOpt.unbind();
				cboListOpt.click(function(e) { 
					e.preventDefault();
					var text = $(this).text(),
						kode = $(this).attr("href");
					kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
					el.val(text);
					if(cbo.attr("name")=='Rooms') {
						$("#reservationform .ComboForm[name='Persons']").val(text);
						genComboList($("#ComboPersons"),parseInt(text),3);
					}
					cboList.hide();
				});
			} else cboList.hide();
		});
		$("#reservationform .confirmation .TextForm[name='BookingCode']").keypress(function(e) {
			var key = e.charCode; /*|| e.keyCode;*/
			if(e.which==13 && $(this).val().indexOf('-')<0 && $.trim($(this).val())!='') {
				$("#reservationform .confirmation .ButtonForm[name='Submit']").click();	
			}
		});
		$("#reservationform .reservation .ButtonForm[name='Reset']").click(function() { 
			$("#reservationform .DateForm").val('');
			$("#reservationform .ComboForm").val('');
			parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
		});
		$("#reservationform .confirmation .ButtonForm[name='Reset']").click(function() { 
			$("#reservationform .TextForm[name='BookingCode']").val('');
		});
		$("#reservationform .confirmation .ButtonForm[name='Submit']").click(function() { 
			//goStep_Mnu(3);
			showProcessBar(true);
			var opt = '',
				code = $("#reservationform .confirmation .TextForm[name='BookingCode']").val();
			$("#reservationform .confirmation .RadioForm[name='optConfirm']").each(function() {
				if($(this).attr("checked")) { opt = $(this).val(); return false; }
			})
			$.ajax({ 
				type: "POST", 
				url: "AJAXReservationConfirm.php", 
				data: "code="+escape(code)+
						"&opt="+escape(opt),
				success: function(html){ 
					if(html.indexOf("style=")>=0) {
						$("#reservationform .content").html(html);
						$("#reservationform .buttons").show();
						$("#reservationform .button").hide();
						if(opt=="1") {
							var printVoucher = function() {
								$.ajax({ 
									type: "POST", 
									url: "AJAXReservationRandCode.php", 
									data: "code="+escape(code),
									success: function(response){ 
										window.open("AJAXVoucherPrint.php?q="+escape(response))
									},
									error: function() { 
										window.alert('Unknown error... Try again...') 
									}
								});
							}
							var saveVoucher = function() {
								$.ajax({ 
									type: "POST", 
									url: "AJAXReservationRandCode.php", 
									data: "code="+escape(code),
									success: function(response){ 
										window.open("AJAXVoucherSave.php?q="+escape(response))
									},
									error: function() { 
										window.alert('Unknown error... Try again...') 
									}
								});
							}
							$("#reservationform .step[title]").css("background","url(images/reservationstepoff.gif)");
							$("#reservationform .step[title]").removeAttr("title");
							$("#reservationform .step").eq(3).attr("title","Current Step");
							$("#reservationform .step").eq(3).css("background","url(images/reservationstepon.gif)");
							$("#reservationform .step").show();
							if(html.indexOf("<table")>=0)
								setBookingEvent_Mnu(8); /* confirmation only */
							else { /* print voucher available */
								$("#reservationform .ButtonForm[name='Back']").unbind()
								.val('Print Voucher')
								.removeAttr("disabled")
								.css({ color:"#FFF",cursor:"pointer"})
								.click(function() { printVoucher(code) });
								$("#reservationform .ButtonForm[name='Continue']").unbind()
								.val('Save Voucher')
								.removeAttr("disabled")
								.css({ color:"#FFF",cursor:"pointer"})
								.click(function() { saveVoucher(code) });
								$("#reservationform .ButtonForm[name='Cancel']").val('Close')
								.removeAttr("disabled")
								.css({ color:"#FFF",cursor:"pointer"});
								showProcessBar(false);
							}
						} else 
							setCancellationEvent(escape(code));
					} else {
						window.alert(html);	
						showProcessBar(false);
					}
				}
			});
		});
		$("#reservationform .ButtonForm[name='CheckAvail']").click(function() { 
			var param = ''; parambooking = '';
			$("#reservationform input[class*='Form'][name!='BookingCode']").each(function() {
				if($(this).val()=='') {
					window.alert("Fill the "+$(this).attr("title")+" data!");
					param = '';
					return false;
				} else {
					if($(this).attr("class").indexOf('DateForm')>=0) {
						var dt = new Date($(this).val()); 
						param+=$(this).attr("name")+"="+escape(dt.toString('yyyy-MM-dd'))+"&"	
					} else {
						param+=$(this).attr("name")+"="+escape($(this).val())+"&"	
					}
				}
			});
			if(param!='') { 
				var CheckIn = new Date($("#reservationform .DateForm[name='CheckInDate']").val()),
					CheckOut = new Date($("#reservationform .DateForm[name='CheckOutDate']").val()),
					Today = new Date();
				if(Today-CheckIn>86400000 || CheckOut-CheckIn<=0) {
					window.alert('Please check your Check-in and Check-out Date!');
					param = '';
				} else {
					parambooking = param+"promo=regular&";
					goStep_Mnu(0); 
				}
			} 
		});
		$("#reservationform .ButtonForm[name='Cancel']").click(function() { 
			/*if($(this).val()=='Skip') window.alert('apa ini enaknya');*/
			$("#reservationform .TextForm").val('');	
			$("#maincontent .reservation .DateForm").val('');	
			$("#maincontent .reservation .ComboForm").val('');	
			parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
			$("#anim").css({ 
			   left:$dest.css("left"), top:$dest.css("top"), 
			   marginLeft:$dest.css("margin-left"), 
			   marginTop:$dest.css("margin-top"), 
			   width:$dest.css("width"), height:$dest.css("height"),
			   opacity:0.5, filter:"alpha(opacity=50)"
			});
			$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
			$("#mask").fadeOut(1000); 
			$("#anim").animate({
			   left:offset.left, top:offset.top, 
			   marginLeft:ori.css("margin-left"), 
			   marginTop:ori.css("margin-top"), 
			   width:width, height:height, 
			   background:"#FFF", opacity:0, filter:"alpha(opacity=0)"
			},500, function() {
				$("#anim").hide();
				$("#reservationform").hide();
				$("#reservationform .promosign").hide();
				$("#reservationform .content").html('');
			});
		});
	}
	function setMnuReservationPromoEvent(ori,code) { /* from Promo */
		var offset = ori.offset(), width = ori.width(), height = ori.height(),
			$dest = $("#reservationform");
		/* to prevent Combo position mlethat mlethot */
		$(window).unbind();
		$("#reservationform .DateForm").unbind();
		$("#reservationform .ComboForm").unbind();
		$("#reservationform .ButtonForm").unbind();
		$(window).resize(function(e){ $(".Combo").hide(); $(".ComboScroll").hide(); });
		$("#reservationform .DateForm").datepicker({
			dateFormat: 'DD, d MM, yy', showOn: "focus", 
			autoSize: true,
			buttonImageOnly: false
		});
		$("#reservationform .TextForm[name='BookingCode']").mask("999999",{placeholder:"-"});
		$("#reservationform .ComboForm").click(function(e) { 
			var cbo = $(this);
			$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
			var el = $(this),
				cboList = $("#Combo"+$(this).attr("name")),
				cboListOpt = $("#Combo"+$(this).attr("name")+" a");
			if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
				var offset = el.offset();
				var offset1 = $("#reservationform").offset();
				cboList.css({ 
					left: offset.left+"px", 
					top: offset.top+el.height()+1+"px", 
					width: el.width()+5+"px"
				});
				cboList.show();
				cboListOpt.unbind();
				cboListOpt.click(function(e) { 
					e.preventDefault();
					var text = $(this).text(),
						kode = $(this).attr("href");
					kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
					el.val(text);
					if(cbo.attr("name")=='Rooms') {
						$("#reservationform .ComboForm[name='Persons']").val(text);
						genComboList($("#ComboPersons"),parseInt(text),3);
					}
					cboList.hide();
				});
			} else cboList.hide();
		});
		$("#reservationform .reservation .ButtonForm[name='Reset']").click(function() { 
			$("#reservationform .DateForm").val('');
			$("#reservationform .ComboForm").val('');
			parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
		});
		$("#reservationform .ButtonForm[name='CheckAvail']").click(function() { 
			var param = ''; parambooking = '';
			$("#reservationform input[class*='Form'][name!='BookingCode']").each(function() {
				if($(this).val()=='') {
					window.alert("Fill the "+$(this).attr("title")+" data!");
					param = '';
					return false;
				} else {
					if($(this).attr("class").indexOf('DateForm')>=0) {
						var dt = new Date($(this).val()); 
						param+=$(this).attr("name")+"="+escape(dt.toString('yyyy-MM-dd'))+"&"	
					} else {
						param+=$(this).attr("name")+"="+escape($(this).val())+"&"	
					}
				}
			});
			if(param!='') { 
				var CheckIn = new Date($("#reservationform .DateForm[name='CheckInDate']").val()),
					CheckOut = new Date($("#reservationform .DateForm[name='CheckOutDate']").val()),
					Today = new Date();
				if(Today-CheckIn>86400000 || CheckOut-CheckIn<=0) {
					window.alert('Please check your Check-in and Check-out Date!');
					param = '';
				} else {
					parambooking = param+"promo="+escape(code)+"&";
					goStep(0); 
				}
			} 
		});
		$("#reservationform .ButtonForm[name='Cancel']").click(function() { 
			/*if($(this).val()=='Skip') window.alert('apa ini enaknya');*/
			$("#reservationform .TextForm").val('');	
			$("#maincontent .reservation .DateForm").val('');	
			$("#maincontent .reservation .ComboForm").val('');	
			parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
			$("#anim").css({ 
			   left:$dest.css("left"), top:$dest.css("top"), 
			   marginLeft:$dest.css("margin-left"), 
			   marginTop:$dest.css("margin-top"), 
			   width:$dest.css("width"), height:$dest.css("height"),
			   opacity:0.5, filter:"alpha(opacity=50)"
			});
			$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
			$("#mask").fadeOut(1000); 
			$("#anim").animate({
			   left:offset.left, top:offset.top, 
			   marginLeft:ori.css("margin-left"), 
			   marginTop:ori.css("margin-top"), 
			   width:width, height:height, 
			   background:"#FFF", opacity:0, filter:"alpha(opacity=0)"
			},500, function() {
				$("#anim").hide();
				$("#reservationform").hide();
				$("#reservationform .promosign").hide();
				$("#reservationform .content").html('');
			});
		});
	}
	function genComboList(cbo,init,multi) {
		$cboUL = cbo.children().eq(0);
		$cboUL.children().remove();
		for(var i=init;i<=init*multi;i++) {
			$cboUL.append('<li><a href="#'+i+'">'+i+'</a></li>');
		}
	}
	function genComboListPlusZero(cbo,init,multi) {
		$cboUL = cbo.children().eq(0);
		$cboUL.children().remove();
		$cboUL.append('<li><a href="#0">0</a></li>');
		for(var i=init;i<=init*multi;i++) {
			$cboUL.append('<li><a href="#'+i+'">'+i+'</a></li>');
		}
	}
	function showPromoBookingForm(code) {
		showProcessBar(true);
		$.ajax({ 
			type: "POST", 
			url: "AJAXReservationPromo.php", 
			data: "code="+code,
			success: function(html){ 
				// better trap here if not found
				$("#reservationform .content").html(html);
				showProcessBar(false);
				/*$("#reservationform .step").show();
				if($("#reservationform .step").eq(idx).get().length>0) {
					$("#reservationform .button").hide();
					$("#reservationform .buttons").show();
					$("#reservationform .step[title]").css("background","url(images/reservationstepoff.gif)");
					$("#reservationform .step[title]").removeAttr("title");
					$("#reservationform .step").eq(idx).attr("title","Current Step");
					$("#reservationform .step").eq(idx).css("background","url(images/reservationstepon.gif)");
				} else {
					$("#reservationform .buttons").hide();
					$("#reservationform .button").show();
					$("#reservationform .ButtonForm[name='Cancel']").val('OK');
					showProcessBar(false);	
				}*/
				var ori = $("#maincontent .banner").eq(0);
				$("#maincontent .banner").each(function() {
					if($.trim($(this).text())==code) {
						ori	= $(this);
						return false;
					}
				});
				setMnuReservationPromoEvent(ori,code);
				//setBookingEvent(0);
			}
		});
	}
	function goStepPPLast(code,paystat) {
		var idx = 9;
		$.ajax({ 
			type: "POST", 
			url: "AJAXReservation9PP.php", 
			data: "status="+paystat,
			success: function(html){ 
				$("#reservationform .content").html(html);
				$("#reservationform .step").show();
				$("#reservationform .step[title]").css("background","url(images/reservationstepoff.gif)");
				$("#reservationform .step[title]").removeAttr("title");
				$("#reservationform .step").eq(3).attr("title","Current Step");
				$("#reservationform .step").eq(3).css("background","url(images/reservationstepon.gif)");
				if(paystat=="0") {
					$("#reservationform .buttons").hide();
					$("#reservationform .button").show();
					$("#reservationform .ButtonForm[name='Cancel']").val('OK');
					setBookingEvent(idx);
				} else if(paystat=="1") {
					$("#reservationform .buttons").show();
					$("#reservationform .button").hide();
					$("#reservationform .ButtonForm[name='Back']").unbind()
					.val('Print Voucher')
					.removeAttr("disabled")
					.css({ color:"#FFF",cursor:"pointer"})
					.click(function() { printVoucher(code) });
					$("#reservationform .ButtonForm[name='Continue']").unbind()
					.val('Save Voucher')
					.removeAttr("disabled")
					.css({ color:"#FFF",cursor:"pointer"})
					.click(function() { saveVoucher(code) });
					$("#reservationform .ButtonForm[name='Cancel']").unbind()
					.val('Close')
					.removeAttr("disabled")
					.css({ color:"#FFF",cursor:"pointer"})
					.click(function() {
						var promo = parambooking.substr(parambooking.indexOf('promo=')+6,
										parambooking.length-parambooking.indexOf('promo=')-7),
							$dest = $("#maincontent .reservation"),
							$ori = $("#reservationform");
						if(idx>=3) {
							$("#reservationform .TextForm").val('');	
							$("#maincontent .reservation .DateForm").val('');	
							$("#maincontent .reservation .ComboForm").val('');	
							parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
						}
						if(promo!='regular') {
							var index = 0;
							$("#maincontent .promo .banner").each(function() {
								if($(this).text()==promo)
									index = $("#maincontent .promo .banner").index(this);
							});
							$dest = $("#maincontent .promo .banner").eq(index);
						}
						$(".Combo").hide(); 
						$(".ComboScroll").hide(); 
						$("#anim").css({ 
						   left:$ori.css("left"), top:$ori.css("top"), 
						   marginLeft:$ori.css("margin-left"), 
						   marginTop:$ori.css("margin-top"), 
						   width:$ori.css("width"), height:$ori.css("height"),
						   opacity:0.5, filter:"alpha(opacity=50)"
						});
						$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
						$("#mask").fadeOut(1000); 
						$("#anim").animate({
						   left:$dest.offset().left, top:$dest.offset().top, 
						   marginLeft:$dest.css("margin-left"), 
						   marginTop:$dest.css("margin-top"), 
						   width:$dest.width(), height:$dest.height(), 
						   background:"#FFF", /*display:"block",*/
						   opacity:0, filter:"alpha(opacity=0)"
						},500, function() {
							$("#anim").hide();
							$("#reservationform").hide();
							$("#reservationform .promosign").hide();
							$("#reservationform .content").html('');
						});
					
					});
					var printVoucher = function() {
						$.ajax({ 
							type: "POST", 
							url: "AJAXReservationRandCode.php", 
							data: "code="+escape(code),
							success: function(response){ 
								window.open("AJAXVoucherPrint.php?q="+escape(response))
							},
							error: function() { 
								window.alert('Unknown error... Try again...') 
							}
						});
					}
					var saveVoucher = function() {
						$.ajax({ 
							type: "POST", 
							url: "AJAXReservationRandCode.php", 
							data: "code="+escape(code),
							success: function(response){ 
								window.open("AJAXVoucherSave.php?q="+escape(response))
							},
							error: function() { 
								window.alert('Unknown error... Try again...') 
							}
						});
					}
				}
				showProcessBar(false);
			}
		});
	}
	function goStep(idx) {
		showProcessBar(true);
		if(idx==4) idx=9;
		$.ajax({ 
			type: "POST", 
			url: "AJAXReservation"+idx+".php", 
			data: parambooking+parambooking1+parambooking2+paramconfirm,
			success: function(html){ 
				if(idx==3 && parambooking2.indexOf("PayPal")>0) {
					window.location.replace("PPECSet.php");
				} else if(idx!=3 || (idx==3 && html.indexOf('<table')>=0)) {
					$("#reservationform .content").html(html);
					$("#reservationform .step").show();
					if($("#reservationform .step").eq(idx).get().length>0) {
						$("#reservationform .button").hide();
						$("#reservationform .buttons").show();
						$("#reservationform .step[title]").css("background","url(images/reservationstepoff.gif)");
						$("#reservationform .step[title]").removeAttr("title");
						$("#reservationform .step").eq(idx).attr("title","Current Step");
						$("#reservationform .step").eq(idx).css("background","url(images/reservationstepon.gif)");
					} else {
						$("#reservationform .buttons").hide();
						$("#reservationform .button").show();
						$("#reservationform .ButtonForm[name='Cancel']").val('OK');
						showProcessBar(false);	
					}
					setBookingEvent(idx);
				} else {
					$("#reservationform .content").html(html);
					$("#reservationform .buttons").hide();
					$("#reservationform .button").show();
					$("#reservationform .ButtonForm[name='Cancel']").val('OK');
					showProcessBar(false);	
					setBookingEvent(9);
				}
			}
		});
	}
	function setBookingEvent(idx) { 
		$("#reservationform input").unbind();
		$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default"})
			.val('Next');
		$("#reservationform .ButtonForm[name='Back']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default"});
		if(idx<=3)
			$("#reservationform .ButtonForm[name='Cancel']").val('Cancel');
		$("#reservationform .ButtonForm[name='Continue']").click(function() { goStep(idx+1); });
		$("#reservationform .ButtonForm[name='Back']").click(function() { goStep(idx-1); });
		$("#reservationform .ButtonForm[name='Cancel']").click(function() { 
			/*if($(this).val()=='Skip') window.alert('apa ini enaknya');*/
			var promo = parambooking.substr(parambooking.indexOf('promo=')+6,
							parambooking.length-parambooking.indexOf('promo=')-7),
				$dest = $("#maincontent .reservation"),
				$ori = $("#reservationform");
			if(idx>=3) {
				$("#reservationform .TextForm").val('');	
				$("#maincontent .reservation .DateForm").val('');	
				$("#maincontent .reservation .ComboForm").val('');	
				parambooking=''; parambooking1=''; parambooking2=''; paramconfirm='';
			}
			if(promo!='regular') {
				var index = 0;
				$("#maincontent .promo .banner").each(function() {
					if($(this).text()==promo)
						index = $("#maincontent .promo .banner").index(this);
				});
				$dest = $("#maincontent .promo .banner").eq(index);
			}
			$(".Combo").hide(); 
			$(".ComboScroll").hide(); 
			$("#anim").css({ 
			   left:$ori.css("left"), top:$ori.css("top"), 
			   marginLeft:$ori.css("margin-left"), 
			   marginTop:$ori.css("margin-top"), 
			   width:$ori.css("width"), height:$ori.css("height"),
			   opacity:0.5, filter:"alpha(opacity=50)"
			});
			$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
			$("#mask").fadeOut(1000); 
			$("#anim").animate({
			   left:$dest.offset().left, top:$dest.offset().top, 
			   marginLeft:$dest.css("margin-left"), 
			   marginTop:$dest.css("margin-top"), 
			   width:$dest.width(), height:$dest.height(), 
			   background:"#FFF", /*display:"block",*/
			   opacity:0, filter:"alpha(opacity=0)"
			},500, function() {
				$("#anim").hide();
				$("#reservationform").hide();
				$("#reservationform .promosign").hide();
				$("#reservationform .content").html('');
			});
		});
		if(idx>0 && idx<3) {
			$("#reservationform .ButtonForm[name='Back']").css({ color:"#FFF",cursor:"pointer"});
			$("#reservationform .ButtonForm[name='Back']").removeAttr("disabled");
		}
		if(idx==0) { 
			var checkEmpty = function() {
				if($("*:animated").get().length>0) {
					setTimeout(function() { checkEmpty() },500);
				} else { 
					var promo = parambooking.substr(parambooking.indexOf('promo=')+6,
							parambooking.length-parambooking.indexOf('promo=')-7);
					//alert(promo)
					/*if(promo!='regular')
						window.alert('Sorry, all rooms for this promo have already been booked.');	
					else*/
						window.alert('Sorry, no available room meets your criteria.');	
				}
			}
			if($("#reservationform .content .scrollerdata").get().length>0) {
				if($.trim($("#reservationform .content .scrollerdata").html())=='') {
					checkEmpty();
				}
			}
			$("#reservationform .ButtonForm[name='Back']").css({ color:"#999",cursor:"default"});
			$("#reservationform .ButtonForm[name='Back']").attr("disabled","disabled");
			
			$("#reservationform span[class*='Rate']").hide();	
			$("#reservationform span[class='Rate"+$("#reservationform .ComboForm[name='Rates']").val()+"']").show();	
			$("#reservationform .content .tbldata tr").hover(
				function(e)	{ 
					if(!$(this).parent().parent().attr("title"))
						$(this).css({backgroundColor: "#ffdd89"}) 
				}, function(e)	{ 
					if(!$(this).parent().parent().attr("title"))
						$(this).css({backgroundColor: ""}) 
				}
			);
			$("#reservationform .ComboForm").click(function(e) { 
				var cbo = $(this);
				$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
				var el = $(this),
					cboList = $("#Combo"+$(this).attr("name")),
					cboListOpt = $("#Combo"+$(this).attr("name")+" a");
				if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
					var offset = el.offset();
					var offset1 = $("#reservationform").offset();
					cboList.css({ 
						left: offset.left+"px", 
						top: offset.top+el.height()+1+"px", 
						width: el.width()+5+"px"
					});
					cboList.show();
					cboListOpt.unbind();
					cboListOpt.click(function(e) { 
						e.preventDefault();
						var text = $(this).text(),
							kode = $(this).attr("href");
						kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
						el.val(text);
						if(cbo.attr("name")=='Rates') {
							$("#reservationform span[class*='Rate']").hide();	
							$("#reservationform span[class='Rate"+kode+"']").show();	
						}
						cboList.hide();
					});
				} else cboList.hide();
			});
			$("#reservationform .ButtonForm[name='Select']").click(function() {
				var $tbl = $(this).parent().parent().parent().parent(),
					$tr = $(this).parent().parent();
				if($(this).val()=='Select') {
					var indeks = 0;
					$("#reservationform .content .tbldata[title] tr").each(function() {
						var indeks = $("#reservationform .content .tbldata tr").index(this);
						$(this).css({ background:"" });
						$(this).parent().parent().removeAttr("title");
						$("#reservationform .content .tbldata:eq("+indeks+") .ButtonForm[name='Select']").val("Select");
					});
					/*$tbl.css({ background:"#fdbc59" });*/
					$tr.css({ background:"#fdbc59" });
					$tbl.attr("title","selected");
					$(this).val("Deselect");
					/* get param */
					parambooking1 = "room="+$("#reservationform .content .tbldata[title] td").eq(0).text()+"&currency="+$("#reservationform .ComboForm[name='Rates']").val()+"&";
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"});
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled");
				} else {
					/*$tbl.css({ background:"" });*/
					$tr.css({ background:"" });
					$tbl.removeAttr("title");
					$(this).val("Select");
					/* reset param */
					parambooking1 = '';
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#999",cursor:"default"});
					$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled");
				}
			});
		} else if(idx==1) { 
			if($("#reservationform .ComboForm[name='ExtraBed']").get().length>0) {
				var extrabeds = $("#reservationform .ComboForm[name='ExtraBed']").val(),
					rooms = $("#reservationform span.Rooms").text();
				genComboListPlusZero($("#ComboExtraBed"),1,parseInt(rooms));
			}
			var setContinueOn = function(){
				parambooking2 = '';
				$("#reservationform .TextForm").each(function() {
					if($.trim($(this).val())=='' 
						&& $(this).attr("alt")=="1") { parambooking2 = ''; return false; } 
					else { parambooking2+=$(this).attr("name")+"="+escape($(this).val())+"&" }	
				});
				if(parambooking2!='') {
					$("#reservationform .ComboForm").each(function() {
						if($.trim($(this).val())=='' 
							&& $(this).attr("alt")=="1") { parambooking2 = ''; return false; } 
						else { parambooking2+=$(this).attr("name")+"="+escape($(this).val())+"&" }	
					});
				}
				$("#reservationform .ButtonForm[name='Continue']").css({ color:"#999",cursor:"default"});
				$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled");
				if(parambooking2!='' 
				   && ($("#reservationform .RadioForm[name='PaymentMethod']:checked").length>0)) {
					parambooking2 += "PaymentMethod="+escape($("#reservationform .RadioForm[name='PaymentMethod']:checked").val())+"&";
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"});
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled");
				}
				// paypal
				//$("#reservationform .RadioForm[name='PaymentMethod'][value='PayPal']").removeAttr("disabled"); // disabled dulu
				if($("#reservationform .TextForm[name='Email']").val().indexOf('@',1)<0 ||
					$("#reservationform .TextForm[name='Email']").val().indexOf('.',$("#reservationform .TextForm[name='Email']").val().indexOf('@',1)+1)<0) {
					$("#reservationform .RadioForm[name='PaymentMethod'][value='PayPal']").attr("disabled","disabled");
				}
			}
			$("#reservationform").click(function(e) { /* to hide Combo */
				var $target = $(e.target);
				if($(e.target).is(":not(.Combo, .ComboScroll, .ComboForm)")) {
					$(".Combo").hide(); 
					$(".ComboScroll").hide(); 
				}
			});
			$("#reservationform .ComboForm").click(function(e) { 
				var cbo = $(this);
				$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
				var el = $(this),
					cboList = $("#Combo"+$(this).attr("name")),
					cboListOpt = $("#Combo"+$(this).attr("name")+" a");
				if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
					var offset = el.offset();
					var offset1 = $("#reservationform").offset();
					cboList.css({ 
						left: offset.left+"px", 
						top: offset.top+el.height()+1+"px", 
						width: el.width()+5+"px"
					});
					
					cboList.show();
					cboListOpt.unbind();
					cboListOpt.click(function(e) { 
						e.preventDefault();
						var text = $(this).text(),
							kode = $(this).attr("href");
						kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
						el.val(text);
						if(cbo.attr("name")=='Rooms') {
							$("#reservationform .ComboForm[name='Persons']").val(text);
							genComboList($("#ComboPersons"),parseInt(text),3);
						}
						cboList.hide();
					});
				} else cboList.hide();
			});
			if(parambooking2!='') {
				arParam = parambooking2.split("&");
				for(var i=0;i<arParam.length;i++) {
					arElmnt = arParam[i].split("=");	
					$("#reservationform .TextForm[name='"+arElmnt[0]+"']").val(arElmnt[1]);
				}
			}
			$("#reservationform .TextForm").keyup(function() { setContinueOn() });
			$("#reservationform .RadioForm").click(function() { setContinueOn() });
			setContinueOn();
		} else if(idx==2) {
			$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"})
			.removeAttr("disabled");
		} else if(idx==3) { 
			$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"})
			.removeAttr("disabled")
			.val('Submit');
			var setConfirmOn = function(){
				paramconfirm = '';
				$("#reservationform .TextForm").each(function() {
					if($(this).attr("alt")=="1" || $(this).attr("name")=='Note') {
						if($.trim($(this).val())=='' && $(this).attr("alt")=="1") { 
							paramconfirm = ''; return false; 
						} else { 
							paramconfirm+=$(this).attr("name")+"="+escape($(this).val())+"&" 
						}	
					}
				});
				$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled")
					.css({ color:"#999",cursor:"default"});
				if(paramconfirm!='') {
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled")
						.css({ color:"#FFF",cursor:"pointer"});
				}
			}
			$("#reservationform .TextForm[name='Note']").keypress(function(e) { 
				var key = e.charCode; /*|| e.keyCode;*/
				if(($(this).val().length==255 && key>0) || key==35) {
					return false;	
				}
			});
			$("#reservationform .TextForm").keyup(function() { setConfirmOn() });
			setConfirmOn();
			$("#reservationform .buttons .ButtonForm[name='Cancel']").val('Skip');
		}
		showProcessBar(false);
	}
	function goStep_Mnu(idx) { 
		showProcessBar(true);
		if(idx==4) idx=9;
		$.ajax({ 
			type: "POST", 
			url: "AJAXReservation"+idx+".php", 
			data: parambooking+parambooking1+parambooking2+paramconfirm,
			success: function(html){ 
				if(idx==3 && parambooking2.indexOf("PayPal")>0) {
					window.location.replace("PPECSet.php");
				} else if(idx!=3 || (idx==3 && html.indexOf('<table')>=0)) {
					$("#reservationform .content").html(html);
					$("#reservationform .step").show();
					if($("#reservationform .step").eq(idx).get().length>0) {
						$("#reservationform .button").hide();
						$("#reservationform .buttons").show();
						$("#reservationform .step[title]").css("background","url(images/reservationstepoff.gif)");
						$("#reservationform .step[title]").removeAttr("title");
						$("#reservationform .step").eq(idx).attr("title","Current Step");
						$("#reservationform .step").eq(idx).css("background","url(images/reservationstepon.gif)");
					} else {
						$("#reservationform .buttons").hide();
						$("#reservationform .button").show();
						$("#reservationform .ButtonForm[name='Cancel']").val('OK');
						showProcessBar(false);	
					}
					setBookingEvent_Mnu(idx);
				} else {
					$("#reservationform .content").html(html);
					$("#reservationform .buttons").hide();
					$("#reservationform .button").show();
					$("#reservationform .ButtonForm[name='Cancel']").val('OK');
					showProcessBar(false);	
					setBookingEvent_Mnu(9);
				}
			}
		});
	}
	function setCancellationEvent(code) { 
		var closeCancellation = function() {
			var $dest = $("#mnutop .mnutop:eq(4)"),
				$ori = $("#reservationform");
			$("#anim").css({ 
			   left:$ori.css("left"), top:$ori.css("top"), 
			   marginLeft:$ori.css("margin-left"), 
			   marginTop:$ori.css("margin-top"), 
			   width:$ori.css("width"), height:$ori.css("height"),
			   opacity:0.5, filter:"alpha(opacity=50)"
			});
			$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
			$("#mask").fadeOut(1000); 
			$("#anim").animate({
			   left:$dest.offset().left, top:$dest.offset().top, 
			   marginLeft:$dest.css("margin-left"), 
			   marginTop:$dest.css("margin-top"), 
			   width:$dest.width(), height:$dest.height(), 
			   background:"#FFF", opacity:0, filter:"alpha(opacity=0)"
			},500, function() {
				$("#anim").hide();
				$("#reservationform").hide();
				$("#reservationform .promosign").hide();
				$("#reservationform .content").html('');
			});
		}
		$("#reservationform input").unbind();
		/*$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default"})
			.val('Next');*/
		$("#reservationform .ButtonForm[name='Back']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default", 
				 display:"none" });
		$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled")
		.css({ color:"#FFF",cursor:"pointer"})
		.val('Submit');
		$("#reservationform .ButtonForm[name='Continue']").click(function() { 
			$.ajax({ 
				type: "POST", 
				url: "AJAXReservationCancel.php", 
				data: "code="+escape(code),
				success: function(html){ 
				//	if(html.indexOf("<table")>=0) {
						$("#reservationform .content").html(html);
						$("#reservationform .button").show();
						$("#reservationform .buttons").hide();
						$("#reservationform .ButtonForm[name='Cancel']").val('OK')
						.unbind()
						.click(function() { closeCancellation(); });
			//		} else {
			//			window.alert(html);	
			//			showProcessBar(false);
			//		}
				}
			});
		});
		$("#reservationform .ButtonForm[name='Cancel']").click(function() { 
			closeCancellation();
		});
		showProcessBar(false);
	}
	function setBookingEvent_Mnu(idx) { 
		$("#reservationform input").unbind();
		$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default"})
			.val('Next');
		$("#reservationform .ButtonForm[name='Back']").attr("disabled","disabled")
			.css({ color:"#999",cursor:"default"});
		if(idx<=3)
			$("#reservationform .ButtonForm[name='Cancel']").val('Cancel');
		$("#reservationform .ButtonForm[name='Continue']").click(function() { goStep_Mnu(idx+1); });
		$("#reservationform .ButtonForm[name='Back']").click(function() { goStep_Mnu(idx-1); });
		$("#reservationform .ButtonForm[name='Cancel']").click(function() { 
			/*if($(this).val()=='Skip') window.alert('apa ini enaknya');*/
			var promo = parambooking.substr(parambooking.indexOf('promo=')+6,
							parambooking.length-parambooking.indexOf('promo=')-7),
				$dest = $("#mnutop .mnutop:eq(4)"),
				$ori = $("#reservationform");
			if(idx>=3) {
				$("#reservationform .TextForm").val('');	
				$("#reservationform .reservation .DateForm").val('');	
				$("#reservationform .reservation .ComboForm").val('');	
				$("#maincontent .reservation .DateForm").val('');	
				$("#maincontent .reservation .ComboForm").val('');	
				parambooking=''; parambooking1=''; parambooking2='';
			}
			$(".Combo").hide(); $(".ComboScroll").hide(); 
			$("#anim").css({ 
			   left:$ori.css("left"), top:$ori.css("top"), 
			   marginLeft:$ori.css("margin-left"), 
			   marginTop:$ori.css("margin-top"), 
			   width:$ori.css("width"), height:$ori.css("height"),
			   opacity:0.5, filter:"alpha(opacity=50)"
			});
			$("#reservationform").animate({ opacity:0, filter:"alpha(opacity=0)" },500);
			$("#mask").fadeOut(1000); 
			$("#anim").animate({
			   left:$dest.offset().left, top:$dest.offset().top, 
			   marginLeft:$dest.css("margin-left"), 
			   marginTop:$dest.css("margin-top"), 
			   width:$dest.width(), height:$dest.height(), 
			   background:"#FFF", opacity:0, filter:"alpha(opacity=0)"
			},500, function() {
				$("#anim").hide();
				$("#reservationform").hide();
				$("#reservationform .promosign").hide();
				$("#reservationform .content").html('');
			});
		});
		if(idx>0 && idx<3) {
			$("#reservationform .ButtonForm[name='Back']").css({ color:"#FFF",cursor:"pointer"});
			$("#reservationform .ButtonForm[name='Back']").removeAttr("disabled");
		}
		if(idx==0) { 
			var checkEmpty = function() {
				if($("*:animated").get().length>0) {
					setTimeout(function() { checkEmpty() },500);
				} else { 
					var promo = parambooking.substr(parambooking.indexOf('promo=')+6,
							parambooking.length-parambooking.indexOf('promo=')-7);
					if(promo!='regular')
						window.alert('Sorry, all rooms for this promo have already been booked.');	
					else
						window.alert('Sorry, no available room meets your criteria.');	
				}
			}
			if($("#reservationform .content .scrollerdata").get().length>0) {
				if($.trim($("#reservationform .content .scrollerdata").html())=='') {
					checkEmpty();
				}
			}
			$("#reservationform .ButtonForm[name='Back']").css({ color:"#999",cursor:"default"});
			$("#reservationform .ButtonForm[name='Back']").attr("disabled","disabled");
			
			$("#reservationform span[class*='Rate']").hide();	
			$("#reservationform span[class='Rate"+$("#reservationform .ComboForm[name='Rates']").val()+"']").show();	
			$("#reservationform .content .tbldata tr").hover(
				function(e)	{ 
					if(!$(this).parent().parent().attr("title"))
						$(this).css({backgroundColor: "#ffdd89"}) 
				}, function(e)	{ 
					if(!$(this).parent().parent().attr("title"))
						$(this).css({backgroundColor: ""}) 
				}
			);
			$("#reservationform .ComboForm").click(function(e) { 
				var cbo = $(this);
				$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
				var el = $(this),
					cboList = $("#Combo"+$(this).attr("name")),
					cboListOpt = $("#Combo"+$(this).attr("name")+" a");
				if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
					var offset = el.offset();
					var offset1 = $("#reservationform").offset();
					cboList.css({ 
						left: offset.left+"px", 
						top: offset.top+el.height()+1+"px", 
						width: el.width()+5+"px"
					});
					cboList.show();
					cboListOpt.unbind();
					cboListOpt.click(function(e) { 
						e.preventDefault();
						var text = $(this).text(),
							kode = $(this).attr("href");
						kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
						el.val(text);
						if(cbo.attr("name")=='Rates') {
							$("#reservationform span[class*='Rate']").hide();	
							$("#reservationform span[class='Rate"+kode+"']").show();	
						}
						cboList.hide();
					});
				} else cboList.hide();
			});
			$("#reservationform .ButtonForm[name='Select']").click(function() {
				var $tbl = $(this).parent().parent().parent().parent(),
					$tr = $(this).parent().parent();
				if($(this).val()=='Select') {
					var indeks = 0;
					$("#reservationform .content .tbldata[title] tr").each(function() {
						var indeks = $("#reservationform .content .tbldata tr").index(this);
						$(this).css({ background:"" });
						$(this).parent().parent().removeAttr("title");
						$("#reservationform .content .tbldata:eq("+indeks+") .ButtonForm[name='Select']").val("Select");
					});
					$tr.css({ background:"#fdbc59" });
					$tbl.attr("title","selected");
					$(this).val("Deselect");
					/* get param */
					parambooking1 = "room="+$("#reservationform .content .tbldata[title] td").eq(0).text()+"&currency="+$("#reservationform .ComboForm[name='Rates']").val()+"&";
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"});
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled");
				} else {
					$tr.css({ background:"" });
					$tbl.removeAttr("title");
					$(this).val("Select");
					/* reset param */
					parambooking1 = '';
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#999",cursor:"default"});
					$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled");
				}
			});
		} else if(idx==1) { 
			if($("#reservationform .ComboForm[name='ExtraBed']").get().length>0) {
				var extrabeds = $("#reservationform .ComboForm[name='ExtraBed']").val(),
					rooms = $("#reservationform span.Rooms").text();
				genComboListPlusZero($("#ComboExtraBed"),1,parseInt(rooms));
			}
			var setContinueOn = function(){
				parambooking2 = '';
				$("#reservationform .TextForm").each(function() {
					if($.trim($(this).val())=='' 
						&& $(this).attr("alt")=="1") { parambooking2 = ''; return false; } 
					else { parambooking2+=$(this).attr("name")+"="+escape($(this).val())+"&" }	
				});
				if(parambooking2!='') {
					$("#reservationform .ComboForm").each(function() {
						if($.trim($(this).val())=='' 
							&& $(this).attr("alt")=="1") { parambooking2 = ''; return false; } 
						else { parambooking2+=$(this).attr("name")+"="+escape($(this).val())+"&" }	
					});
				}
				$("#reservationform .ButtonForm[name='Continue']").css({ color:"#999",cursor:"default"});
				$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled");
				if(parambooking2!='' 
				   && ($("#reservationform .RadioForm[name='PaymentMethod']:checked").length>0)) {
					parambooking2 += "PaymentMethod="+escape($("#reservationform .RadioForm[name='PaymentMethod']:checked").val())+"&";
					$("#reservationform .ButtonForm[name='Continue']").css({ color:"#FFF",cursor:"pointer"});
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled");
				}
				// paypal
				//$("#reservationform .RadioForm[name='PaymentMethod'][value='PayPal']").removeAttr("disabled"); // disabled dulu
				if($("#reservationform .TextForm[name='Email']").val().indexOf('@',1)<0 ||
					$("#reservationform .TextForm[name='Email']").val().indexOf('.',$("#reservationform .TextForm[name='Email']").val().indexOf('@',1)+1)<0) {
					$("#reservationform .RadioForm[name='PaymentMethod'][value='PayPal']").attr("disabled","disabled");
				}
			}
			$("#reservationform").click(function(e) { /* to hide Combo */
				var $target = $(e.target);
				if($(e.target).is(":not(.Combo, .ComboScroll, .ComboForm)")) {
					$(".Combo").hide(); 
					$(".ComboScroll").hide(); 
				}
			});
			$("#reservationform .ComboForm").click(function(e) { 
				var cbo = $(this);
				$(".Combo, .ComboScroll").each(function() { $(this).hide(); });	
				var el = $(this),
					cboList = $("#Combo"+$(this).attr("name")),
					cboListOpt = $("#Combo"+$(this).attr("name")+" a");
				if($("#Combo"+$(this).attr("name")+"").is(":hidden")) {
					var offset = el.offset();
					var offset1 = $("#reservationform").offset();
					cboList.css({ 
						left: offset.left+"px", 
						top: offset.top+el.height()+1+"px", 
						width: el.width()+5+"px"
					});
					
					cboList.show();
					cboListOpt.unbind();
					cboListOpt.click(function(e) { 
						e.preventDefault();
						var text = $(this).text(),
							kode = $(this).attr("href");
						kode = kode.substr(kode.indexOf("#")+1,kode.length-kode.indexOf("#")-1);
						el.val(text);
						if(cbo.attr("name")=='Rooms') {
							$("#reservationform .ComboForm[name='Persons']").val(text);
							genComboList($("#ComboPersons"),parseInt(text),3);
						}
						cboList.hide();
					});
				} else cboList.hide();
			});
			if(parambooking2!='') {
				arParam = parambooking2.split("&");
				for(var i=0;i<arParam.length;i++) {
					arElmnt = arParam[i].split("=");	
					$("#reservationform .TextForm[name='"+arElmnt[0]+"']").val(arElmnt[1]);
				}
			}
			$("#reservationform .TextForm").keyup(function() { setContinueOn() });
			$("#reservationform .RadioForm").click(function() { setContinueOn() });
			setContinueOn();
		} else if(idx==2) {
			$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled")
			.css({ color:"#FFF",cursor:"pointer"});
		} else if(idx==3 || idx==8) { 
			if(idx==3) $("#reservationform .buttons .ButtonForm[name='Cancel']").val('Skip');
			$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled")
			.css({ color:"#FFF",cursor:"pointer"})
			.val('Submit');
			var setConfirmOn = function(){
				paramconfirm = '';
				$("#reservationform .TextForm").each(function() {
					if($(this).attr("alt")=="1" || $(this).attr("name")=='Note') {
						if($.trim($(this).val())=='' && $(this).attr("alt")=="1") { 
							paramconfirm = ''; return false; 
						} else { 
							paramconfirm+=$(this).attr("name")+"="+escape($(this).val())+"&" 
						}	
					}
				});
				$("#reservationform .ButtonForm[name='Continue']").attr("disabled","disabled")
					.css({ color:"#999",cursor:"default"});
				if(paramconfirm!='') {
					$("#reservationform .ButtonForm[name='Continue']").removeAttr("disabled")
						.css({ color:"#FFF",cursor:"pointer"});
				}
			}
			$("#reservationform .TextForm[name='Note']").keypress(function(e) { 
				var key = e.charCode; /*|| e.keyCode;*/
				if(($(this).val().length==255 && key>0) || key==35) {
					return false;	
				}
			});
			$("#reservationform .TextForm").keyup(function() { setConfirmOn() });
			setConfirmOn();
			//$("#reservationform .buttons .ButtonForm[name='Cancel']").val('Skip');
			
		}
		showProcessBar(false);
	}
	function showProcessBar(state)	{ 
		if($("#processbar").get().length==0) $(document.body).append('<div id="processbar"></div>');
		if(!state) $("#processbar").hide();
		else $("#processbar:hidden").show();
	}
});

