fbuilderjQuery = (typeof fbuilderjQuery != 'undefined' ) ? fbuilderjQuery : jQuery;
fbuilderjQuery(function(){
(function($) {
// Namespace of fbuilder
$.fbuilder = $.fbuilder || {};
$.fbuilder[ 'objName' ] = 'fbuilderjQuery';
$.fbuilder[ 'controls' ] = ( typeof $.fbuilder[ 'controls' ] != 'undefined' ) ? $.fbuilder[ 'controls' ]: {};
$.fbuilder[ 'forms' ] = ( typeof $.fbuilder[ 'forms' ] != 'undefined' ) ? $.fbuilder[ 'forms' ]: {};
$.fbuilder[ 'htmlEncode' ] = function(value)
{
value = $('
');
}
else
{
$("#fieldlist"+opt.identifier+" .pb"+page).append(items[i].show());
if (items[i].predefinedClick)
{
$("#fieldlist"+opt.identifier+" .pb"+page).find("#"+items[i].name).attr("placeholder",items[i].predefined);
$("#fieldlist"+opt.identifier+" .pb"+page).find("#"+items[i].name).attr("value","");
}
if (items[i].userhelpTooltip)
{
var uh = $("#fieldlist"+opt.identifier+" .pb"+page).find("#"+items[i].name).closest(".fields");
uh.find(".uh").css("display","none");
if (uh.find(".uh").text()!="")
{
uh.attr("uh",uh.find(".uh").text());
}
}
}
}
if (page>0)
{
$("#fieldlist"+opt.identifier+" .pb"+page).addClass("pbEnd");
$("#fieldlist"+opt.identifier+" .pbreak").each(function(index) {
var code = $(this).html();
var bSubmit = '';
if (index == page)
{
if ( $( "#cpcaptchalayer"+opt.identifier ).length && !/^\s*$/.test( $( "#cpcaptchalayer"+opt.identifier ).html() ) )
{
code += ''+$("#cpcaptchalayer"+opt.identifier).html()+'
';
$("#cpcaptchalayer"+opt.identifier).html("");
}
if ($("#cp_subbtn"+opt.identifier).html())
{
bSubmit = ''+$("#cp_subbtn"+opt.identifier).html()+'
';
}
}
$(this).html(''+opt.messages.pageof.replace( /\{\s*\d+\s*\}/, (index+1) ).replace( /\{\s*\d+\s*\}/, (page+1) )+' '+code+''+opt.messages.previous+'
'+opt.messages.next+'
'+bSubmit+'
');
});
$( '#fieldlist'+opt.identifier).find(".pbPrevious,.pbNext").bind("click", { 'identifier' : opt.identifier }, function( evt ) {
var identifier = evt.data.identifier;
if ( ($(this).hasClass("pbPrevious")) || (($(this).hasClass("pbNext")) && $(this).parents("form").valid()) )
{
var page = parseInt($(this).parents(".pbreak").attr("page"));
(($(this).hasClass("pbPrevious"))?page--:page++);
$("#fieldlist"+identifier+" .pbreak").css("display","none");
$("#fieldlist"+identifier+" .pbreak").find(".field").addClass("ignorepb");
$("#fieldlist"+identifier+" .pb"+page).css("display","block");
$("#fieldlist"+identifier+" .pb"+page).find(".field").removeClass("ignorepb");
if ($("#fieldlist"+identifier+" .pb"+page).find(".field").length>0)
{
try
{
$("#fieldlist"+identifier+" .pb"+page).find(".field")[0].focus();
}
catch(e){}
}
}
else
{
$(this).parents("form").validate().focusInvalid();
}
return false;
});
}
else
{
if ( $( "#cpcaptchalayer"+opt.identifier ).length && !/^\s*$/.test( $( "#cpcaptchalayer"+opt.identifier ).html() ) )
{
$("#fieldlist"+opt.identifier+" .pb"+page).append(''+$("#cpcaptchalayer"+opt.identifier).html()+'
');
$("#cpcaptchalayer"+opt.identifier).html("");
}
if ($("#cp_subbtn"+opt.identifier).html())
{
$("#fieldlist"+opt.identifier+" .pb"+page).append(''+$("#cp_subbtn"+opt.identifier).html()+'
');
}
}
// Set Captcha Event
$( document ).on( 'click', '#fbuilder .captcha img', function(){ var e = $( this ); e.attr( 'src', e.attr( 'src' ).replace( /&\d+$/, '' ) + '&' + Math.floor( Math.random()*1000 ) ); } );
$( '#fieldlist'+opt.identifier).find(".pbSubmit").bind("click", { 'identifier' : opt.identifier }, function( evt )
{
$(this).closest("form").submit();
});
if (i>0)
{
theForm.after_show( opt.identifier );
for (var i=0;i'+(this.title!=''?''+this.title+' ':'')+(this.description!=''?''+this.description+' ':'')+'';
},
after_show:function( id ){
$( '#cp_calculatedfieldsf_pform'+id ).attr( 'data-evalequations', this.evalequations ).attr( 'autocomplete', ( ( this.autocomplete ) ? 'on' : 'off' ) );
}
});
//var theForm = new fform(),
var theForm,
ffunct = {
getItem: function( name )
{
for( var i in items )
{
if( items[ i ].name == name )
{
return items[ i ];
}
}
return false;
},
getItems: function()
{
return items;
},
loadData:function(f)
{
var d,
e = $("#"+f);
this.formId = e.parents( 'form' ).attr( 'id' );
if ( d = $.parseJSON( e.val() ))
{
if (d.length==2)
{
items = [];
for (var i=0;i'+this.title+''+((this.required)?"* ":"")+' '+this.userhelp+'
';
}
}
); $.fbuilder.controls[ 'femail' ] = function(){};
$.extend(
$.fbuilder.controls[ 'femail' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Email",
ftype:"femail",
predefined:"",
predefinedClick:false,
required:false,
size:"medium",
equalTo:"",
show:function()
{
return '';
},
val:function()
{
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length ) return $.fbuilder.parseValStr( e.val() );
return '';
}
}
); $.fbuilder.controls[ 'facceptance' ]=function(){};
$.extend(
$.fbuilder.controls[ 'facceptance' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Accept terms and conditions",
ftype:"facceptance",
value:"I accept",
required:true,
url:"",
message:"",
show:function()
{
var me = this,
dlg = '',
label = me.title;
if(!/^\s*$/.test(me.url))
{
label = ''+label+' ';
}
else if(!/^\s*$/.test(me.message))
{
label = ''+label+' ';
dlg += ''
}
return '';
},
after_show:function()
{
$(document).on('click','.cff-open-dlg', function(){
var dlg = $(this).closest('.fields').find('.cff-dialog'), w = dlg.data('width'), h=dlg.data('height');
dlg.removeClass('hide');
if('undefined' == typeof w) w = Math.min($(this).closest('form').width(), $(window).width(), dlg.width());
if('undefined' == typeof h) h = Math.min($(this).closest('form').height(), $(window).height(), dlg.height());
dlg.data('width',w);
dlg.data('height',h);
dlg.css({'width': w+'px', 'height': h+'px', 'margin-top': (-1*h/2)+'px', 'margin-left': (-1*w/2)+'px'});
});
$(document).on('click','.cff-close-dlg', function(){$(this).closest('.cff-dialog').addClass('hide');});
},
val:function()
{
var e = $('[id="'+this.name+'"]:checked:not(.ignore)');
if( e.length )
{
var t = $.fbuilder.parseValStr( e[0].value );
if(!$.isNumeric(t)) t = t.replace(/^"/,'').replace(/"$/,'');
}
return (v) ? (($.isNumeric(v)) ? v : '"'+v+'"') : 0;
}
}
);$.fbuilder.controls[ 'fslots' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fslots' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Slots booking",
ftype:"fslots",
slotsavailInit:{"d1":[{h1:8,m1:0,c:1,p:0,min:8*60}],
"d2":[{h1:8,m1:0,c:1,p:0,min:8*60}],
"d3":[{h1:8,m1:0,c:1,p:0,min:8*60}],
"d4":[{h1:8,m1:0,c:1,p:0,min:8*60}],
"d5":[{h1:8,m1:0,c:1,p:0,min:8*60}]},
slots_special:new Array(),
min_quantity:1,
max_quantity:5,
quantity1:1,
label1:"",
quantity2:1,
label2:"",
prices:new Array({name:"default",price1:new Array(),price2:new Array()}),
cacheArr:new Array(),
usedSlots:new Array(),
dateFormat:"mm/dd/yy",
showDropdown:false,
showTotalCost:false,
showTotalCostFormat:"$ {0}",
dropdownRange:"-10:+10",
working_dates:[true,true,true,true,true,true,true],
numberOfMonths:1,
firstDay:0,
minDate:"0",
maxDate:"",
defaultDate:"",
invalidDates:"",
required:true,
formId:0,
extras:0,
size:"medium",
current_quantity:1,
invalidDatesByQuantity:new Array(),
pctByDay:new Array(),
loadOK:false,
initialapp:"",
initialID:0,
arr:new Array(),
militaryTime:1,
formattime:function(t,mt)//mt=2 for database 09:00
{
var h = Math.floor(t/60);
var m = t%60;
var suffix = "";
if (mt==0)
{
if (h>12)
{
h = h-12;
suffix = " PM";
}
else if (h==12)
suffix = " PM";
else
{
if (h==0 && mt!=2) h=12;
suffix = " AM";
}
}
return (((h<10)?((mt==2)?"0":""):"")+h+":"+(m<10?"0":"")+m)+suffix;
},
disableSpecificDates: function(d) {
var currentdate = d.getTime();
if ($.inArray(currentdate, this.tmpinvalidDatestime) > -1 )
return false;
var day = $.datepicker.formatDate('yy-mm-dd', d);
if (this.working_dates[d.getDay()]==0 && ($.inArray(day, this.special_days) == -1))
return false;
return true;
},
getAvailableSlots: function(d) {
me = this;
var str = "";
var c = "c"+me.current_quantity;
var dday = $.datepicker.parseDate("yy-mm-dd", d);
var item = $.datepicker.formatDate("yy-mm-dd",dday);
me.arr[d] = new Array();
var day = $.datepicker.formatDate('yy-mm-dd', dday);
var ind = -1;
for (var i=0;ind==-1 && i=used[i].c)
me.arr[d][j].c -= used[i].c;
else
me.arr[d][j].c = 0;
}
}
}
me.pctByDay[day] = Math.floor(10*usedC/totalC);
var dt = $.datepicker.parseDate("yy-mm-dd",d).getTime();
var dmin = (typeof me.minDate.getMonth === 'function')?me.minDate.getTime():0;
var dmax = (typeof me.maxDate.getMonth === 'function')?me.maxDate.getTime():0;
for (var j=0;me.arr[d] && j= me.current_quantity)
{
if ((dmin==0) || (dt+me.arr[d][j].min*60*1000 > dmin) && (dmax==0) || (dt+me.arr[d][j].min*60*1000 < dmax))
str += '';
}
if (str=="")
{
me.invalidDatesByQuantity[c] = me.invalidDatesByQuantity[c] || [];
me.invalidDatesByQuantity[c][me.invalidDatesByQuantity[c].length]= item;
}
}
return str;
},
show:function()
{
var str1 = "", str2 = "";
str1 = ' ';
if (this.quantity1>1)
{
str1 = "";
for (var i=1;i<=this.quantity1;i++)
str1 += ''+i+' ';
str1 = '';
}
str2 = ' ';
if (this.quantity1>1 && this.quantity2>1)
{
str2 = "";
for (var i=0;i<=this.quantity2;i++)
str2 += ''+i+' ';
str2 = '';
}
return '';
},
after_show:function()
{
function closeOtherDatepicker(){
$('#ui-datepicker-div').css("display","none");
}
setTimeout(closeOtherDatepicker,100);
function renderCalendarCallback(d) {
var day = $.datepicker.formatDate('yy-mm-dd', d);
var c = new Array(day,"d"+day);
if (me.working_dates[d.getDay()]==0 && ($.inArray(day, me.special_days) == -1))
c.push("nonworking ui-datepicker-unselectable ui-state-disabled nonworkingweekday");
for( var i = 0, l = me.invalidDates.length; i < l; i++ )
{
if (d.getTime() === me.invalidDates[i].getTime())
c.push("nonworking ui-datepicker-unselectable ui-state-disabled invalidDate");
}
me.invalidDatesByQuantity["c"+me.current_quantity] = me.invalidDatesByQuantity["c"+me.current_quantity] || [];
me.getAvailableSlots($.datepicker.formatDate("yy-mm-dd", d));
if ($.inArray(day, me.invalidDatesByQuantity["c"+me.current_quantity]) > -1)
c.push("nonworking ui-datepicker-unselectable ui-state-disabled tmpinvalidDate nonavailableslots");
var cclass = c.join(" ");
if (cclass.indexOf("nonworking")==-1)
cclass +=" ts_booked"+me.pctByDay[day];
return [true,cclass];
}
function onChangeDateOrQuantity(d)
{
function loadSlots(d)
{
if (!me.loadOK)
{
me.formId = $(".sbfieldCalendar"+me.name).parents("form").find('input[type="hidden"][name$="_id"]').val();
$.ajax(
{
dataType : 'json',
type: "POST",
url : document.location.href,
cache : true,
data : { cp_slots_action: 'get_slots',
formid: me.formId,
initialID: me.initialID,
formfield: me.name.replace(me.form_identifier, "")
},
success : function( data ){
for (var i=0;i=1000)
{
e.datepicker("setDate", me.startdate);
s.html(""+cp_tslotsbk_nomore_label+"
");
}
}
else
s.html(""+$.datepicker.formatDate(me.dateFormat, $.datepicker.parseDate("yy-mm-dd", d))+" "+str+"
");
var str1="",str2="";
me.allUsedSlots = me.allUsedSlots || [];
j = 0;
var total = 0, subtotal = 0;
me.allUsedSlots.sort(function(a, b){ return ($.datepicker.parseDate("yy-mm-dd", a.d).getTime()+a.min*60*1000) - ($.datepicker.parseDate("yy-mm-dd", b.d).getTime()+b.min*60*1000)});
for (var i=0;i"+$.datepicker.formatDate(me.dateFormat, $.datepicker.parseDate("yy-mm-dd", me.allUsedSlots[i].d))+" "+me.formattime(me.allUsedSlots[i].h1*60+me.allUsedSlots[i].m1*1,me.militaryTime)+" ["+cp_tslotsbk_cancel_label+"] ";
str2 += ((str2=="")?"":";")+me.allUsedSlots[i].d+" "+me.formattime(me.allUsedSlots[i].h1*60+me.allUsedSlots[i].m1*1,2)+" "+me.allUsedSlots[i].quantity1+" "+me.allUsedSlots[i].quantity2+" "+subtotal;
if (me.allUsedSlots[i].d==d)
j++;
}
getExtras();
if (me.showTotalCost && (str1!=""))
str1 += ''+cp_tslotsbk_cost_label+' '+me.showTotalCostFormat.replace("{0}", (me.extras+total))+'
';
$( '#field' + me.form_identifier + '-' + me.index + ' .usedSlots'+me.name ).html(str1);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).val(str2);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).change();
$( '#field' + me.form_identifier + '-' + me.index + ' #tcost'+me.name ).val(total);
$( '#field' + me.form_identifier + '-' + me.index + ' .slots a').off("click").on("click", function(){
if ($(this).parents("fieldset").hasClass("ahbgutenberg_editor"))
return false;
$( "#field" + me.form_identifier + "-" + me.index + " div.cpefb_error").remove();
me.allUsedSlots = me.allUsedSlots || [];
if (me.max_quantity==0 || me.allUsedSlots.length0 || me.slots_special.length>0)//
{
var nextdateAvailable = e.datepicker("getDate");
while (!me.disableSpecificDates(nextdateAvailable))
nextdateAvailable.setDate(nextdateAvailable.getDate() + 1);
e.datepicker("setDate", nextdateAvailable);
me.getD = new Date(nextdateAvailable.getTime());
me.startdate = new Date(nextdateAvailable.getTime());
onChangeDateOrQuantity($.datepicker.formatDate("yy-mm-dd", me.getD));
function ifLoadOk()
{
if (!me.loadOK)
setTimeout(ifLoadOk,100);
else
{
$( '#field' + me.form_identifier + '-' + me.index + ' .sbfieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", renderCalendarCallback );
onChangeDateOrQuantity($.datepicker.formatDate("yy-mm-dd", me.getD));
$( '#field' + me.form_identifier + '-' + me.index + ' .sbfieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", renderCalendarCallback );
}
}
ifLoadOk();
}
if (me.initialapp!="" && dd!="")
{
onChangeDateOrQuantity(dd);
}
getExtras=function()
{
var f = $( '#field' + me.form_identifier + '-' + me.index ).parents( "form" );
var v = 0;
var e = f.find(".tsb_service").find(':checked:not(.ignore)');
if( e.length )
{
e.each( function(){
v += this.value*1;
});
}
e = f.find(".tsb_service_per_slot").find(':checked:not(.ignore)');
me.allUsedSlots = me.allUsedSlots || [];
var s = me.allUsedSlots.length;
if( e.length )
{
e.each( function(){
v += this.value * s;
});
}
e = f.find(".tsb_service_per_quantity_selection").find(':checked:not(.ignore)');
var q = f.find(".sbquantity1").val() * 1 + f.find(".sbquantity2").val() * 1;
if( e.length )
{
e.each( function(){
v += this.value * q;
});
}
f.find('#'+me.name+'_services').val(v);
me.extras = v;
var total = $( '#field' + me.form_identifier + '-' + me.index + ' #tcost'+me.name ).val()*1+ v
$( '#field' + me.form_identifier + '-' + me.index ).find(".totalCost .n").html(" " +me.showTotalCostFormat.replace("{0}",total));
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).change();
}
$( '#field' + me.form_identifier + '-' + me.index ).parents( "form" ).find(".tsb_service,.tsb_service_per_slot,.tsb_service_per_quantity_selection").on("click", function(){
getExtras();
});
$( '#field' + me.form_identifier + '-' + me.index ).parents( "form" ).submit(function( ) {
getExtras();
});
},
val:function()
{
return 0;
}
}
); var fcount = 1;
var fnum = "_"+fcount;
while (10>fcount || eval("typeof cp_tslotsbooking_fbuilder_config"+fnum+" != 'undefined'"))
{
try {
var cp_tslotsbooking_fbuilder_config = eval("cp_tslotsbooking_fbuilder_config"+fnum);
var f = $("#fbuilder"+fnum).fbuilder($.parseJSON(cp_tslotsbooking_fbuilder_config.obj));
f.fBuild.loadData("form_structure"+fnum);
$("#cp_tslotsbooking_pform"+fnum).validate({
ignore:".ignore,.ignorepb",
errorElement: "div",
errorPlacement: function(e, element)
{
if (element.hasClass('group'))
element = element.parent();
e.insertBefore(element);
e.addClass('message'); // add a class to the wrapper
e.css('position', 'absolute');
e.css('left',0 );
e.css('top',element.parent().outerHeight(true));
}
});
} catch (e) {}
fcount++;
fnum = "_"+fcount;
}
})(fbuilderjQuery);
});