var filterstart;
$(function(){
//set datepicker
$(".bookingform").validate({
messages: {
'input_date' : {
required: "Please fill in Date !"
},
'input_hours' : {
required: "Please fill in Time !"
},
'input_location' : {
required: "Please fill in Location !"
},
'input_services' : {
required: "Please fill in Service !"
}
},
showErrors: function (errorMap, errorList) {
var msg = "" ;
$.each( errorList, function (i,v){
msg += (v.message+ "\r\n" );
});
if (msg!= "" ) alert(msg);
},
onfocusout: false
});
$( ".input_date" ).datepicker({
onClose: function() {
gnext=$(this).attr("group");
setTimeout(function(){ $('.booking_time'+gnext).click();},1000);
},
numberOfMonths: 2
,dateFormat:'dd M yy'
, maxDate: "+1y"
, minDate:"+0d"
});
$("input").attr("autocomplete","off");
$("input[name=input_hours]").keyup(function(e){
$(this).val("");
e.stopPropagation();
});
$("input[name=input_date]").keyup(function(e){
$(this).val("");
e.stopPropagation();
});
$("html").click(function(){
filterstart=1;
$(".popupwin").hide();
});
for (var i=1; i<=3; i++){
bookingservice(i);
bookingtime(i);
bookinglocation(i);
locationfilter(i);
}
});
function locationfilter(g){
filterstart=1;
$(".input_location"+g).unbind().bind("keydown",function(e){
/*
var value = $(this).val();
if ( value.length>0){
filter=1;
}else{
filter=0;
}*/
if(filterstart===1){
$(".popupwin").hide();
ajaxl("/region_filter","location_list"+g,g);
filterstart=0;
}
e.stopPropagation();
});
$(".input_location"+g).hover(function(e){
$(this).attr("placeholder","What are you looking for?");
},function(e){
$(this).attr("placeholder","Location");
});
}
function bookingservice(g){
$('.booking_service'+g).unbind().bind("click",function(e){
if (g == 1)
locationid = $("input[name='input_location_id'][group=1]").val();
else if (g == 2)
locationid = $("input[name='input_location_id'][group=2]").val();
else if (g==3)
locationid = $("input[name='input_location_id'][group=3]").val();
$(".popupwin").hide();
filterstart=1;
//$(".service_list"+g).show();
//alert("service_list"+g);
ajax("/servicebox?locationid="+locationid,"service_list"+g,g);
e.stopPropagation();
});
}
function bookinglocation(g){
$(".booking_location"+g).unbind().bind('click',function(e){
$(".popupwin").hide();
// $("#location_list").load("region").show();
filterstart=1;
if(g == 1){
ajax_lication("/region","location_list"+g,g);
}else{
ajaxl("/region","location_list"+g,g);
}
//ajaxl("/region","location_list"+g,g);
e.stopPropagation();
});
}
function FormatNumberLength(num, length) {
var r = "" + num;
while (r.length < length) {
r = "0" + r;
}
return r;
}
function bookingtime(g){
$('.booking_time'+g).unbind().bind('click',function(e){
$(".popupwin").hide();
// var timesets="
Time
";
var timesets="- 00:01
";
timesets+="- 00:30
";
for(var i=1;i<12; i++){
timesets+="- "+FormatNumberLength(i, 2)+":00
";
timesets+="- "+FormatNumberLength(i, 2)+":30
";
}
for(var i=12;i<24; i++){
timesets+="- "+i+":00
";
timesets+="- "+i+":30
";
}
timesets+="
";
filterstart=1;
$(".popupwin").hide();
$('.times'+g).show().html(timesets);
timeclick(g);
selecteffect();
e.stopPropagation();
});
};
function timeclick(g){
$(".times"+g+" li").unbind().bind('click', function(e){
var booktime=$(this).html();
$(this).parent().parent().prev().val(booktime);
$(".times"+g).hide();
//$(".booking_location"+g).click();
filterstart=1;
e.stopPropagation();
});
}
function ajax(page,target,g){
$.ajax({
url:page,
dataType:"html",
cache:false,
beforeSend:function(){
},
complete:function(){
servicehandler(g);
selecteffect();
},
success:function(data){
$("."+target).html(data).show();
}
});
}
function ajaxl(page,target,g){
$.ajax({
url:page,
dataType:"html",
cache:false,
beforeSend:function(){
},
complete:function(){
locationhandler(g);
},
success:function(data){
$("."+target).html(data).show();
}
});
}
function ajax_lication(page,target,g){
//target=location_list1
var html = $("."+target+" ").html();
if($.trim(html) == null || $.trim(html) == ''){
$.ajax({
url:page,
dataType:"html",
cache:false,
beforeSend:function(){
if(g == 1){
showLoading();
}
},
complete:function(){
locationhandler(g);
},
success:function(data){
$("."+target).html(data).show();
if(g == 1){
hideLoading();
}
}
});
}else{
if($("."+target).css("display") == 'none'){
$("."+target+" .locationlists .regionblock").show();
$("."+target+" .locationlists .regionblock .country").show();
$("."+target+" .locationlists .regionblock .country .city").show();
$("."+target+" .locationlists .regionblock .country .locations").hide();
var new_html = $("."+target+" ").html();
$("."+target).html(new_html).show();
locationhandler(g);
}else{
$("."+target).html(html).show();
locationhandler(g);
}
}
}
function locationhandler(g){
$(".locationnames").unbind().bind("click",function(e){
var topparent=$(this).closest('.location_list'+g).attr('id');
$("#"+topparent).prev().val($(this).html());
$("#"+topparent).prev().prev().val($(this).attr("id"));
$("input[name=input_services]").val('');
// $("input[name=input_location]").val($(this).html());
if($(this).get(0).tagName == 'SPAN'){
var city = $(this).parent().parent().prev().text();
var airport = $(this).next().text();
}else{
var city=$(this).parent().prev().text();
//var airport=$(this).siblings(".airport").text();
var airport=$(this).prevUntil(".airport").last().prev().text();
}
if (!airport) {
airport=$(this).prev(".airport").text();
}
if (airport) {
airport = ", "+airport;
} else {
airport = "";
}
//$("#booking_airport_name"+g).html(city+airport+",
"+$(this).html());
$("#book_search_txt_"+g).val(city+airport+",
"+$(this).html());
$(".location_list"+g).hide();
$('.booking_service'+g).click();
filterstart=1;
e.stopPropagation();
});
$(".locationlists .country").unbind().bind("click",function(e){
$(".regionblock").hide();
$(".locationlists .country").hide();
$(this).parent().show();
$(this).show();
$(this).children("div").show();
e.stopPropagation();
});
$(".locationlists .city").unbind().bind("click",function(e){
$(".regionblock").hide();
$(".locationlists .country").hide();
$(".locationlists .locations").hide();
$(".locationlists .city").hide();
$(this).parent().parent().show();
$(this).parent().show();
$(this).next().show();
e.stopPropagation();
});
}
function servicehandler(g){
$(".serviceitems").unbind().bind("click",function(e){
var topparent=$(this).closest('.service_list'+g).attr('id');
var country = $(this).attr('country');
if (country && country != '')
{
var isShowerLoc = $(this).attr('shower-loc');
var isUAELoc = $(this).attr('uae-loc');
if (isShowerLoc && isShowerLoc != '') {
$("#"+topparent).prev().val("Shower");
$("#mgdiv").css({"width":winw,"height":"100%"}).show();
$("#sgpopup").show();
closemeetandgreetpopup();
} else if (isUAELoc && isUAELoc != '') {
// $("#"+topparent).prev().val("Booking");
$("#mgdiv").css({"width":winw,"height":"100%"}).show();
$("#uaepopup").show();
closemeetandgreetpopup();
} else {
$("#"+topparent).prev().val("Meet & Greet");
if (country != 'singapore'){
var winw=$(window).width();
var winh=$(window).height();
$("#mgdiv").css({"width":winw,"height":"100%"}).show();
if (country == 'malaysia')
$("#mypopup").show();
else
$("#omanpopup").show();
closemeetandgreetpopup();
// $('#myModal').dialog({show:"fade", model:true, position:"center", width:500, modal:true});
}
}
}
else {
$("#"+topparent).prev().val($(this).text());
}
$("#"+topparent).prev().prev().val($(this).attr('id'));
$(".service_list"+g).hide();
e.stopPropagation();
});
}
function closemeetandgreetpopup(){
$(".closesignupbtn").unbind().bind("click",function(){
$("#mgdiv").hide();
$("#mypopup").hide();
$("#omanpopup").hide();
$("#sgpopup").hide();
$("#uaepopup").hide();
});
}
function closehomepagepopup(){
$("#mgdiv").unbind().bind("click",function(){
$("#mgdiv").hide();
$("#homepagepopup").hide();
});
$("#homepagepopup").unbind().bind("click",function(){
$("#mgdiv").hide();
$("#homepagepopup").hide();
});
}
function closepresspopup(){
$(".closepress").unbind().bind("click",function(){
$("#mgdiv").hide();
$("#presspopup").hide();
$(".zoomtracker").css("display", "none");
$('body').removeClass('noscroll');
});
}
function selecteffect(){
$(".selectbox li").hover(function(){
$(this).css({"backgroundColor":"#6D1A42","color":"#fff"});
},
function(){
$(this).css({"backgroundColor":"#f1f1f1","color":"#666"});
});
}
function showhomepagepopup() {
var winw=$(window).width();
var winh=$(window).height();
$("#mgdiv").css({"width":winw,"height":"100%"}).show();
$("#homepagepopup").show();
closehomepagepopup();
}
function showpresspopup() {
var winw=$(window).width();
var winh=$(window).height();
$("#mgdiv").css({"width":winw,"height":"100%"}).show();
$("#presspopup").show();
// $('body').addClass('noscroll');
closepresspopup();
}