');
}
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;
function focusTop(){try {$('html, body').animate({scrollTop: $("#fieldlist"+identifier+" .pb"+page).find("fieldset").offset().top}, 100);}catch(e){}}
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
{
if ($("#fieldlist"+identifier+" .pb"+page).find(".field").is(":visible"))
{
var f1 = $("#fieldlist"+identifier+" .pb"+page).find(".field:visible");
if (f1.parents("fieldset").parents("#fieldlist"+identifier+" .pb"+page).length>0)
focusTop();
else
f1[0].focus();
}
else
focusTop();
}
catch(e){focusTop()}
}
else
focusTop();
}
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 ) ); } );
$( document ).on("click","#fieldlist"+opt.identifier+" .pbSubmit", function( evt )
{
$("#fieldlist"+opt.identifier+" .pbSubmit").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[ 'fcurrency' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fcurrency' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Currency",
ftype:"fcurrency",
predefined:"",
predefinedClick:false,
required:false,
size:"small",
readonly:false,
currencyText:"USD",
thousandSeparator:",",
centSeparator:".",
min:"",
max:"",
formatDynamically:false,
getFormattedValue:function( value )
{
this.centSeparator = $.trim(this.centSeparator);
if( /^\s*$/.test( this.centSeparator ) )
{
this.centSeparator = '.';
}
var v = $.trim( value );
v = v.replace( new RegExp( $.fbuilder[ 'escape_symbol' ](this.currencySymbol), 'g' ), '' )
.replace( new RegExp( $.fbuilder[ 'escape_symbol' ](this.currencyText), 'g' ), '' );
v = $.fbuilder.parseVal( v, this.thousandSeparator, this.centSeparator );
if( !isNaN( v ) )
{
v = v.toString();
var parts = v.toString().split("."),
counter = 0,
str = '';
if( !/^\s*$/.test( this.thousandSeparator ) )
{
for( var i = parts[0].length-1; i >= 0; i--){
counter++;
str = parts[0][i] + str;
if( counter%3 == 0 && i != 0 ) str = this.thousandSeparator + str;
}
parts[0] = str;
}
if( typeof parts[ 1 ] != 'undefined' && parts[ 1 ].length == 1 )
{
parts[ 1 ] += '0';
}
if( /^\s*$/.test( this.centSeparator ) )
{
this.centSeparator = '.';
}
return this.currencySymbol+parts.join( this.centSeparator )+this.currencyText;
}
else
{
return value;
}
},
show:function()
{
return '';
},
after_show:function()
{
if( this.formatDynamically )
{
var me = this;
$( document ).on( 'change', '[name="' + me.name + '"]', function(){
this.value = me.getFormattedValue( this.value );
} );
}
if( typeof $[ 'validator' ] != 'undefined' )
{
$.validator.addMethod( 'min', function( value, element, param )
{
var e = element;
if( element.id.match( /_\d+$/) )
{
var e = $.fbuilder[ 'forms' ][ element.id.match( /_\d+$/)[ 0 ] ].getItem( element.name )
}
var thousandSeparator = ( typeof e.thousandSeparator != 'undefined' ) ? e.thousandSeparator : '',
centSymbol = ( typeof e.centSeparator != 'undefined' && $.trim( e.centSeparator ) ) ? e.centSeparator : '.';
return this.optional(element) || $.fbuilder.parseVal( value, thousandSeparator, centSymbol ) >= param;
}
);
$.validator.addMethod( 'max', function( value, element, param )
{
var e = element;
if( element.id.match( /_\d+$/) )
{
var e = $.fbuilder[ 'forms' ][ element.id.match( /_\d+$/)[ 0 ] ].getItem( element.name )
}
var thousandSeparator = ( typeof e.thousandSeparator != 'undefined' ) ? e.thousandSeparator : '',
centSymbol = ( typeof e.centSeparator != 'undefined' && $.trim( e.centSeparator ) ) ? e.centSeparator : '.';
return this.optional(element) || $.fbuilder.parseVal( value, thousandSeparator, centSymbol ) <= param;
}
);
}
},
val:function()
{
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length )
{
var v = $.trim( e.val() );
v = v.replace( new RegExp( $.fbuilder[ 'escape_symbol' ](this.currencySymbol), 'g' ), '' )
.replace( new RegExp( $.fbuilder[ 'escape_symbol' ](this.currencyText), 'g' ), '' );
return $.fbuilder.parseVal( v, this.thousandSeparator, this.centSeparator );
}
return 0;
}
}
); $.fbuilder.controls[ 'fnumber' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fnumber' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Number",
ftype:"fnumber",
predefined:"",
predefinedClick:false,
required:false,
size:"small",
thousandSeparator:"",
decimalSymbol:".",
min:"",
max:"",
dformat:"digits",
formats:new Array("digits","number"),
show:function()
{
return '';
},
after_show:function()
{
if( typeof $[ 'validator' ] != 'undefined' )
{
$.validator.addMethod( 'number', function( value, element )
{
var e = element;
if( element.id.match( /_\d+$/) )
{
var e = $.fbuilder[ 'forms' ][ element.id.match( /_\d+$/)[ 0 ] ].getItem( element.name )
}
var thousandSeparator = ( typeof e.thousandSeparator != 'undefined' ) ? e.thousandSeparator : '',
decimalSymbol = ( typeof e.decimalSymbol != 'undefined' && $.trim( e.decimalSymbol ) ) ? e.decimalSymbol : '.';
var regExp = new RegExp( '^-?(?:\\d+|\\d{1,3}(?:' + $.fbuilder.escape_symbol( thousandSeparator ) + '\\d{3})+)?(?:' + $.fbuilder.escape_symbol( decimalSymbol ) + '\\d+)?$' );
return this.optional(element) || regExp.test( value );
}
);
$.validator.addMethod( 'min', function( value, element, param )
{
var e = element;
if( element.id.match( /_\d+$/) )
{
var e = $.fbuilder[ 'forms' ][ element.id.match( /_\d+$/)[ 0 ] ].getItem( element.name )
}
var thousandSeparator = ( typeof e.thousandSeparator != 'undefined' ) ? e.thousandSeparator : '',
decimalSymbol = ( typeof e.decimalSymbol != 'undefined' && $.trim( e.decimalSymbol ) ) ? e.decimalSymbol : '.';
return this.optional(element) || $.fbuilder.parseVal( value, thousandSeparator, decimalSymbol ) >= param;
}
);
$.validator.addMethod( 'max', function( value, element, param )
{
var e = element;
if( element.id.match( /_\d+$/) )
{
var e = $.fbuilder[ 'forms' ][ element.id.match( /_\d+$/)[ 0 ] ].getItem( element.name )
}
var thousandSeparator = ( typeof e.thousandSeparator != 'undefined' ) ? e.thousandSeparator : '',
decimalSymbol = ( typeof e.decimalSymbol != 'undefined' && $.trim( e.decimalSymbol ) ) ? e.decimalSymbol : '.';
return this.optional(element) || $.fbuilder.parseVal( value, thousandSeparator, decimalSymbol ) <= param;
}
);
}
},
val:function()
{
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length )
{
var v = $.trim( e.val() );
return $.fbuilder.parseVal( v, this.thousandSeparator, this.decimalSymbol );
}
return 0;
}
}
); $.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[ 'fdate' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fdate' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Date",
ftype:"fdate",
predefined:"",
predefinedClick:false,
size:"medium",
required:false,
dformat:"mm/dd/yyyy",
dseparator:"/",
tformat:"24",
showDropdown:false,
dropdownRange:"-10:+10",
minDate:"",
maxDate:"",
invalidDates:"",
minHour:0,
maxHour:23,
minMinute:0,
maxMinute:59,
stepHour: 1,
stepMinute: 1,
showDatepicker: true,
showTimepicker: false,
ariaHourLabel: 'hours',
ariaMinuteLabel: 'minutes',
ariaAMPMLabel: 'am or pm',
defaultDate:"",
defaultTime:"",
working_dates:[true,true,true,true,true,true,true],
_set_Events : function()
{
var me = this,
f = function(){
$( '#'+me.name+'_date' ).valid();
me.set_dateTime();
};
$( document ).on( 'change', '#'+me.name+'_date', function(){ f(); } );
$( document ).on( 'change', '#'+me.name+'_hours', function(){ f(); } );
$( document ).on( 'change', '#'+me.name+'_minutes', function(){ f(); } );
$( document ).on( 'change', '#'+me.name+'_ampm', function(){ f(); } );
$( '#cp_calculatedfieldsf_pform'+me.form_identifier ).bind( 'reset', function(){ setTimeout( function(){ me.set_DefaultDate(); me.set_DefaultTime(); me.set_dateTime(); }, 500 ); } );
},
_validateDate: function( d, w, i )
{
try{
if( d === null || !w[ d.getDay()] ) return false;
if( i !== null )
{
for( var j = 0, h = i.length; j < h; j++ )
{
if( d.getDate() == i[ j ].getDate() && d.getMonth() == i[ j ].getMonth() && d.getFullYear() == i[ j ].getFullYear() ) return false;
}
}
}
catch( _err ){}
return true;
},
_validateTime : function( e, i )
{
if( i.showTimepicker )
{
var base = e.name.replace( '_date', '' ),
h = $('#'+base+'_hours').val(),
m = $('#'+base+'_minutes').val();
if( i.tformat == 12 )
{
if( $('#'+base+'_ampm').val() == 'pm' && h != 12 ) h = h*1 + 12;
if( $('#'+base+'_ampm').val() == 'am' && h == 12 ) h = 0;
}
if(
h < i.minHour ||
i.maxHour < h ||
(h == i.minHour && m < i.minMinute) ||
(h == i.maxHour && i.maxMinute < m)
) return false;
}
return true;
},
init:function()
{
var me = this,
_checkValue = function( v, min, max )
{
v = parseInt( v );
v = ( isNaN( v ) ) ? max : v;
return Math.min(Math.max(v,min),max);
};
// Date
me.dformat = me.dformat.replace(/\//g, me.dseparator);
me.invalidDates = me.invalidDates.replace( /\s+/g, '' );
if( me.dropdownRange.indexOf( ':' ) == -1 ) me.dropdownRange = '-10:+10';
if( !/^\s*$/.test( me.invalidDates ) )
{
var dateRegExp = new RegExp( /^\d{1,2}\/\d{1,2}\/\d{4}$/ ),
counter = 0,
dates = me.invalidDates.split( ',' );
me.invalidDates = [];
for( var i = 0, h = dates.length; i < h; i++ )
{
var range = dates[ i ].split( '-' );
if( range.length == 2 && range[0].match( dateRegExp ) != null && range[1].match( dateRegExp ) != null )
{
var fromD = new Date( range[ 0 ] ),
toD = new Date( range[ 1 ] );
while( fromD <= toD )
{
me.invalidDates[ counter ] = fromD;
var tmp = new Date( fromD.valueOf() );
tmp.setDate( tmp.getDate() + 1 );
fromD = tmp;
counter++;
}
}
else
{
for( var j = 0, k = range.length; j < k; j++ )
{
if( range[ j ].match( dateRegExp ) != null )
{
me.invalidDates[ counter ] = new Date( range[ j ] );
counter++;
}
}
}
}
}
// Time
me.minHour = _checkValue( me.minHour, 0, 23 );
me.maxHour = _checkValue( me.maxHour, 0, 23 );
me.minMinute = _checkValue( me.minMinute, 0, 59 );
me.maxMinute = _checkValue( me.maxMinute, 0, 59 );
me.stepHour = _checkValue( me.stepHour, 1, Math.max( 1, me.maxHour - me.minHour ) );
me.stepMinute = _checkValue( me.stepMinute, 1, Math.max( 1, me.maxMinute - me.minMinute ) );
// Set handles
me._setHndl('minDate');
me._setHndl('maxDate');
},
get_hours:function()
{
var me = this,
str = '',
i = 0,
h,
from = ( me.tformat == 12 ) ? 1 : me.minHour,
to = ( me.tformat == 12 ) ? 12 : me.maxHour;
while( ( h = from + me.stepHour * i ) <= to )
{
if( h < 10 ) h = '0'+''+h;
str += '' + h + ' ';
i++;
}
return '' + str + ' :';
},
get_minutes:function()
{
var me = this,
str = '',
i = 0,
m,
n = (me.minHour == me.maxHour)?me.minMinute : 0,
x = (me.minHour == me.maxHour)?me.maxMinute : 59;
while( ( m = n + me.stepMinute * i ) <= x )
{
if( m < 10 ) m = '0'+''+m;
str += '' + m + ' ';
i++;
}
return '' + str + ' ';
},
get_ampm:function()
{
var str = '';
if( this.tformat == 12 )
{
return 'am pm ';
}
return str;
},
set_dateTime:function()
{
var me = this,
str = $( '#'+me.name+'_date' ).val();
if( me.showTimepicker && str!="")
{
str += ' '+$( '#'+me.name+'_hours' ).val();
str += ':'+$( '#'+me.name+'_minutes' ).val();
if( $( '#'+me.name+'_ampm' ).length ) str += $( '#'+me.name+'_ampm' ).val();
}
$( '#'+me.name ).val( str ).change();
},
set_minDate:function(v, ignore)
{
var e = $('[id*="'+this.name+'"].hasDatepicker');
if(e.length)
{
e.datepicker('option', 'minDate', (ignore) ? null : v);
e.change();
}
},
set_maxDate:function(v, ignore)
{
var e = $('[id*="'+this.name+'"].hasDatepicker');
if(e.length)
{
e.datepicker('option', 'maxDate', (ignore) ? null : v);
e.change();
}
},
set_DefaultDate : function()
{
var me = this,
p = {
dateFormat: me.dformat.replace(/yyyy/g,"yy"),
minDate: me._getAttr('minDate'),
maxDate: me._getAttr('maxDate')
},
dp = $( "#"+me.name+"_date" ),
dd = (me.defaultDate != "") ? me.defaultDate : ( ( me.predefined != "" ) ? me.predefined : new Date() );
dp.click( function(){ $(document).click(); $(this).focus(); } );
if(me.showDropdown ) p = $.extend(p,{changeMonth: true,changeYear: true,yearRange: me.dropdownRange});
p = $.extend(p, {beforeShowDay:(function(w,i) { return function(d){return [me._validateDate(d, w, i), ""];};})(me.working_dates, me.invalidDates)});
dp.datepicker(p);
if(!me.predefinedClick) dp.datepicker( "setDate", dd);
if(!me._validateDate(dp.datepicker("getDate"), me.working_dates, me.invalidDates)) dp.datepicker( "setDate", '');
},
set_DefaultTime : function()
{
var me = this,
_setValue = function( f, v, m )
{
v = Math.min( v*1, m*1 );
v = ( v < 10 ) ? 0+''+v : v;
$( '#' + f + ' [value="' + v + '"]' ).prop( 'selected', true );
};
if( me.showTimepicker )
{
var parts, time = {}, tmp = 0, max_minutes = 59;
if( ( parts = /(\d{1,2}):(\d{1,2})\s*([ap]m)?/gi.exec( me.defaultTime ) ) != null )
{
time[ 'hour' ] = parts[ 1 ]*1+((parts.length == 4 && /pm/i.test(parts[3]) && parts[1] != 12) ? 12 : 0);
time[ 'minute' ] = parts[ 2 ];
}
else
{
var d = new Date();
time[ 'hour' ] = d.getHours();
time[ 'minute' ] = d.getMinutes();
}
time[ 'hour' ] = Math.min(Math.max(time[ 'hour' ], me.minHour), me.maxHour);
if(time[ 'hour' ] <= me.minHour) time[ 'minute' ] = Math.max(time['minute'],me.minMinute);
if(me.maxHour <= time[ 'hour' ]) time[ 'minute' ] = Math.min(time['minute'],me.maxMinute);
_setValue(
me.name+'_hours',
( me.tformat == 12 ) ? ( ( time[ 'hour' ] > 12 ) ? time[ 'hour' ] - 12 : ( ( time[ 'hour' ] == 0 ) ? 12 : time[ 'hour' ] ) ) : time[ 'hour' ],
( me.tformat == 12 ) ? 12 : me.maxHour
);
_setValue( me.name+'_minutes', time[ 'minute' ], (time[ 'hour' ] == me.maxHour) ? me.maxMinute : 59);
$( '#'+me.name+'_ampm'+' [value="' + ( ( time[ 'hour' ] < 12 ) ? 'am' : 'pm' ) + '"]' ).prop( 'selected', true );
}
},
show:function()
{
var me = this,
n = me.name,
attr = 'value',
format_label = [],
date_tag_type = 'text',
disabled = '',
date_tag_class = 'field date'+me.dformat.replace(/[^a-z]/ig,"")+' '+me.size+((me.required && me.showDatepicker)?' required': '');
if( me.predefinedClick ) attr = 'placeholder';
if( me.showDatepicker ) format_label.push(me.dformat);
else{ date_tag_type = 'hidden'; disabled='disabled';}
if( me.showTimepicker ) format_label.push('HH:mm');
return '';
},
after_show:function()
{
function closeOtherDatepicker(){
$('#ui-datepicker-div').css("display","none");
}
setTimeout(closeOtherDatepicker,100);
var me = this,
date_format = 'date'+me.dformat.replace(/[^a-z]/ig,""),
validator = function( v, e )
{
try
{
var _dp = $.datepicker,
_fb = $.fbuilder,
p = e.name.replace('_date', '').split('_'),
_index = (p.length > 1) ? '_'+p[ 1 ] : '',
item = ('forms' in _fb && _index in _fb[ 'forms' ])
? _fb[ 'forms' ][ _index ].getItem(p[ 0 ]+'_'+p[ 1 ]) : null,
inst = _dp._getInst( e ),
minDate = _dp._determineDate( inst, _dp._get( inst, 'minDate'), null),
maxDate = _dp._determineDate(inst, _dp._get(inst, 'maxDate'), null),
dateFormat = _dp._get(inst, 'dateFormat'),
date = _dp.parseDate(dateFormat, v, _dp._getFormatConfig(inst));
if( item != null )
{
return this.optional( e ) ||
(
( minDate == null || date >= minDate ) &&
( maxDate == null || date <= maxDate ) &&
item._validateDate( $( e ).datepicker( 'getDate' ), item.working_dates, item.invalidDates ) &&
item._validateTime( e, item )
);
}
return true;
}
catch( er )
{
return false;
}
};
if(!(date_format in $.validator.methods)) $.validator.addMethod(date_format, validator );
me.set_DefaultDate();
me.set_DefaultTime();
me._set_Events();
me.set_dateTime();
},
val:function(raw)
{
raw = raw || false;
var me = this,
e = $( '[id="' + me.name + '"]:not(.ignore)' ),
dformat = me.dformat.replace(new RegExp('\\'+me.dseparator, 'g'), '/');
if( e.length )
{
var v = e.val(), rt;
if(raw) return $.fbuilder.parseValStr(v, raw);
if( dformat == 'yyyy/mm/dd' || dformat == 'yyyy/dd/mm' )
rt = '(\\d{4})[\\/\\-\\.](\\d{1,2})[\\/\\-\\.](\\d{1,2})';
else
rt = '(\\d{1,2})[\\/\\-\\.](\\d{1,2})[\\/\\-\\.](\\d{4})';
v = $.trim(e.val());
var re = new RegExp( rt+'(\\s(\\d{1,2})[:\\.](\\d{1,2})\s*([amp]{2})?)?' ),
d = re.exec( v ),
h = 0,
m = 0,
date;
if( d )
{
if( typeof d[ 5 ] != 'undefined' ) h = d[ 5 ]*1;
if( typeof d[ 6 ] != 'undefined' ) m = d[ 6 ]*1;
if( typeof d[ 7 ] != 'undefined' )
{
var am = d[ 7 ].toLowerCase();
if(am == 'pm' && h < 12 ) h += 12;
if(am == 'am' && h == 12) h -= 12;
}
switch( dformat )
{
case 'yyyy/dd/mm':
date = new Date( d[ 1 ], ( d[ 3 ] * 1 - 1 ), d[ 2 ], h, m, 0, 0 );
break;
case 'yyyy/mm/dd':
date = new Date( d[ 1 ], ( d[ 2 ] * 1 - 1 ), d[ 3 ], h, m, 0, 0 );
break;
case 'dd/mm/yyyy':
date = new Date( d[ 3 ], ( d[ 2 ] * 1 - 1 ), d[ 1 ], h, m, 0, 0 );
break;
case 'mm/dd/yyyy':
date = new Date( d[ 3 ], ( d[ 1 ] * 1 - 1 ), d[ 2 ], h, m, 0, 0 );
break;
}
if( me.showTimepicker ) return date.valueOf() / 86400000;
else return Math.ceil( date.valueOf() / 86400000 );
}
}
return 0;
},
setVal:function( v )
{
try
{
v = $.trim(v)
.replace( /\s+/g, ' ' )
.split( ' ' );
if(this.showDatepicker)
{
this.defaultDate = v[ 0 ];
this.set_DefaultDate();
}
if(this.showTimepicker)
{
var t = (v.length == 2) ? v[1] : ((!this.showDatepicker) ? v[0] : false);
if(t !== false)
{
this.defaultTime = t;
this.set_DefaultTime();
}
}
this.set_dateTime();
}
catch( err )
{}
}
}
); $.fbuilder.controls[ 'ftextarea' ] = function(){};
$.extend(
$.fbuilder.controls[ 'ftextarea' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Untitled",
ftype:"ftextarea",
predefined:"",
predefinedClick:false,
required:false,
size:"medium",
minlength:"",
maxlength:"",
rows:4,
show:function()
{
return '';
},
val:function()
{
var e = $( '[id="' + this.name + '"]:not(.ignore)' ),
v = '';
if( e.length )
{
v = e.val();
}
return v;
}
}
); $.fbuilder.controls[ 'fcheck' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fcheck' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Check All That Apply",
ftype:"fcheck",
layout:"one_column",
required:false,
showDep:false,
show:function()
{
this.choicesVal = ((typeof(this.choicesVal) != "undefined" && this.choicesVal !== null)?this.choicesVal:this.choices.slice(0));
var str = "";
if (!(typeof(this.choicesDep) != "undefined" && this.choicesDep !== null))
{
this.choicesDep = new Array();
for (var i=0;i '+this.choices[i]+' ';
}
return '';
},
showHideDep:function( toShow, toHide )
{
var item = $( '#'+this.name+'.depItem' ),
form_identifier = this.form_identifier;
try
{
if( item.length )
{
var parent = item.closest( '.fields' );
parent.find( '.field' ).each( function()
{
var item = $( this );
if( item.attr( 'dep' ) && item.attr( 'dep' ) != '' )
{
var d = item.attr( 'dep' ).split( ',' );
for ( i=0; i '+this.choices[i]+' ';
}
return '';
},
showHideDep:function( toShow, toHide )
{
var item = $( '#'+this.name+'.depItem' ),
form_identifier = this.form_identifier;
try
{
if( item.length )
{
var parent = item.closest( '.fields' );
parent.find( '.field' ).each( function()
{
var item = $( this );
if( item.attr( 'dep' ) && item.attr( 'dep' ) != '' )
{
var d = item.attr( 'dep' ).split( ',' );
for ( i=0; i'+l[i]+'';
}
return '';
},
showHideDep:function( toShow, toHide )
{
var item = $( '#'+this.name ),
form_identifier = this.form_identifier;
try
{
if( item.find( '.depItem' ).length )
{
var id = item.attr( 'id' );
item.find( '.depItem' ).each( function()
{
var item = $( this );
if( item.attr( 'dep' ) && item.attr( 'dep' ) != '' )
{
var d = item.attr( 'dep' ).split( ',' );
for ( i=0; i'+this.title+''+((this.required)?"* ":"")+' '+((this._patch) ? ' ' : '' )+''+this.userhelp+'
';
},
after_show:function()
{
var me = this;
if (typeof message_ffile_accept != "undefined")
$.extend($.validator.messages, {accept: $.validator.format(message_ffile_accept)});
if(!('accept' in $.validator.methods))
$.validator.addMethod("accept", function(value, element, param)
{
if( this.optional( element ) ) return true;
else{
param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
var regExpObj = new RegExp(".(" + param + ")$", "i");
for( var i = 0, h = element.files.length; i < h; i++ )
if( !element.files[ i ].name.match( regExpObj ) ) return false;
return true;
}
});
if (typeof cp_hourbk_message_ffile_size != "undefined")
$.extend($.validator.messages, {upload_size: $.validator.format(cp_hourbk_message_ffile_size)});
if(!('upload_size' in $.validator.methods))
$.validator.addMethod("upload_size", function(value, element,params)
{
if( this.optional( element ) ) return true;
else{
var total = 0;
for( var i = 0, h = element.files.length; i < h; i++ )
total += element.files[ i ].size/1024;
return ( total <= params );
}
});
$( '#'+me.name ).change( function(){
var h = this.files.length, n = 0;
$( this ).siblings( 'span.files-list' ).remove();
$('[id="'+me.name+'_patch"]').remove();
if(1 <= h)
{
var filesContainer = $(' ');
for( var i = 0; i < h; i++ )
{
(function(i, file){
if(me.preview && file.type.match('image.*') && 'FileReader' in window)
{
var reader = new FileReader();
reader.onload = function (e) {
var img = $(' ');
img.attr('src', e.target.result).css('maxWidth', '100%');
if(me.thumb_height != '') img.attr('height', me.thumb_height);
if(me.thumb_width != '') img.attr('width', me.thumb_width);
filesContainer.append($(''+(n ? ', ' : '')+' ').append(img));
n++;
};
reader.readAsDataURL(file);
}
else if(1 < h){filesContainer.append($('').text((n ? ', ' : '')+file.name));n++;}
})(i, this.files[i]);
}
$( this ).after( filesContainer );
}
});
}
}
); $.fbuilder.controls[ 'fpassword' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fpassword' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Untitled",
ftype:"fpassword",
predefined:"",
predefinedClick:false,
required:false,
size:"medium",
minlength:"",
maxlength:"",
equalTo:"",
show:function()
{
return '';
},
val:function()
{
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length ) return $.fbuilder.parseValStr( e.val() );
return '';
}
}
); $.fbuilder.controls[ 'fPhone' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fPhone' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Phone",
ftype:"fPhone",
required:false,
readonly:false,
dformat:"### ### ####",
predefined:"888 888 8888",
predefinedClick:true,
show:function()
{
var me = this,
str = "",
tmp = this.dformat.split(' '),
tmpv = this.predefined.split(' '),
attr = ( typeof this.predefinedClick != 'undefined' && this.predefinedClick ) ? 'placeholder' : 'value';
for (var i=0;i'+$.trim(tmp[i])+'
';
}
}
return '';
},
after_show: function()
{
var me = this,
tmp = me.dformat.split(' ');
$.validator.messages["phone"] = $.validator.messages["digits"];
if(!('phone' in $.validator.methods))
$.validator.addMethod("phone", function(value, element)
{
if( this.optional( element ) ) return true;
else return /^\+{0,1}\d*$/.test(value);
});
for (var i = 0, h = tmp.length; i < h; i++ )
{
$( '#'+me.name+'_'+i ).bind( 'change', function(){
var v = '';
for( var i = 0; i < tmp.length; i++ )
{
v += $( '#'+me.name+'_'+i ).val();
}
$( '#'+me.name ).val( v ).change();
} );
if( i+1 < h )
{
$('#'+me.name+'_'+i).bind( 'keyup', { 'next': i+1 }, function( evt ){
var e = $( this );
if( e.val().length == e.attr( 'maxlength' ) )
{
e.change();
$( '#'+me.name+'_'+evt.data.next ).focus();
}
} );
}
}
},
val:function(raw)
{
raw = raw || false;
var e = $( '[id="' + this.name + '"]:not(.ignore)' );
if( e.length ) return $.fbuilder.parseValStr( e.val(), raw );
return 0;
},
setVal:function( v )
{
$( '[name="'+this.name+'"]' ).val( v );
v = $.trim( v ).replace( /[^\d]/g, ' ').split( ' ' );
for( var i in v ) $( '[id="' + this.name + '_' + i + '"]' ).val( v[ i ] );
}
}
); $.fbuilder.controls[ 'fCommentArea' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fCommentArea' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Comments here",
ftype:"fCommentArea",
userhelp:"A description of the section goes here.",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fhidden' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhidden' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fhidden",
title:"",
predefined:"",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fSectionBreak' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fSectionBreak' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Section Break",
ftype:"fSectionBreak",
userhelp:"A description of the section goes here.",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fPageBreak' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fPageBreak' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Page Break",
ftype:"fPageBreak",
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fsummary' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fsummary' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Summary",
ftype:"fsummary",
fields:"",
titleClassname:"summary-field-title",
valueClassname:"summary-field-value",
fieldsArray:[],
show:function()
{
var me = this,
p = $.trim( me.fields.replace( /\,+/g, ',') ).split( ',' ),
l = p.length;
if( l )
{
var str = '';
return str;
}
},
after_show: function(){
var me = this,
p = $.trim(me.fields.replace( /\,+/g, ',') ).split( ',' ),
l = p.length;
if( l )
{
for( var i = 0; i < l; i++ )
{
if( !/^\s*$/.test( p[ i ] ) )
{
p[ i ] = $.trim( p[ i ] );
me.fieldsArray.push( p[ i ] + me.form_identifier );
$( document ).on( 'change', '#' + p[ i ] + me.form_identifier, function(){ me.update(); } );
}
}
$( document ).on( 'showHideDepEvent', function( evt, form_identifier )
{
me.update();
});
$( '#cp_calculatedfieldsf_pform'+me.form_identifier ).bind( 'reset', function(){ setTimeout( function(){ me.update(); }, 10 ); } );
}
},
update:function()
{
for ( var j = 0, k = this.fieldsArray.length; j < k; j++ )
{
var i = this.fieldsArray[ j ],
e = $( '[id="' + i + '"]'),
tt = $( '[ref="' + i + '"]');
if( e.length && tt.length )
{
//var t = $( '#' + i ).closest( '.fields' ).find( 'label[for="'+i+'"]' ).text(),
var t = $( '#' + i ).closest( '.fields' ).find( 'label:first' ).html(),
v = [];
e.each(
function(){
var e = $(this);
if( /(checkbox|radio)/i.test( e.attr( 'type' ) ) && !e.is( ':checked' ) )
{
return;
}
else if( e[0].tagName == 'SELECT' )
{
v.push( $(e[0].options[ e[0].selectedIndex ]).attr( 'vt' ) );
}
else
{
if( e.attr( 'vt' ) )
{
v.push( e.attr( 'vt' ) );
}
else if( e.attr( 'summary' ) )
{
v.push( $( '#' + i ).closest( '.fields' ).find( '.'+e.attr( 'summary' )+i ).html() );
}
else
{
v.push( e.val() );
}
}
}
);
try
{
if (t.substring(t.length-1)=='*')
t = t.substring(0, t.length-1);
if (t.substring(t.length-1)==':')
t = t.substring(0, t.length-1);
}
catch (e)
{}
tt.find( '.cff-summary-title' ).html( ( /^\s*$/.test( t ) ) ? '' : t );
tt.find( '.cff-summary-value' ).html( v.join( ', ' ) );
if (v.join( ', ' ).trim()=="")
tt.addClass("emptyvalue");
else
tt.removeClass("emptyvalue");
if( e.hasClass( 'ignore' ) )
{
tt.hide();
}
else
{
tt.show();
}
}
}
}
});
$.fbuilder.controls[ 'datasource' ] = function(){};
$.fbuilder.controls[ 'datasource' ].prototype = {
isDataSource:true,
active : '',
list : {
'database' : {
databaseData: '',
queryData : {
active: 'structure',
query: '',
value: '',
text: '',
table: '',
where: '',
orderby: ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.queryData );
if( data.active == 'structure' )
{
data.where = btoa(p.replaceVariables( data.where ));
data.orderby = btoa(p.replaceVariables( data.orderby ));
}
else
{
data.query = p.replaceVariables( data.query );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction944ffa6a0facfea7cc12: 'RUdiNUFhY1ZraGRld2p5c1V5SVZ2VmlWWXRqTk1wVEl5Vit3U1RyclM1WT0=' }, this.databaseData, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'csv' : {
csvData : {
text : 0,
value : 0,
fields : [],
rows : []
},
getData : function( callback )
{
var obj = {
data : []
};
for( var i in this.csvData.rows )
{
var text = this.csvData.text,
value = this.csvData.value;
if( typeof this.csvData.rows[ i ].length == 'undefined' )
{
text = this.csvData.fields[ text ];
value = this.csvData.fields[ value ];
}
obj.data.push( { text: this.csvData.rows[ i ][ text ], value : this.csvData.rows[ i ][ value ] } );
}
callback( obj );
}
},
'posttype' : {
posttypeData:{
posttype : '',
value : '',
text : '',
last : '',
id : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.posttypeData );
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction944ffa6a0facfea7cc12: 'a0JIai9MSW9TaWlUTmdXZUhSbmtsQT09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'taxonomy' : {
taxonomyData:{
taxonomy : '',
value : '',
text : '',
id : '',
slug : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.taxonomyData );
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
if( !/^\s*$/.test( data.slug ) )
{
data.slug = p.replaceVariables( data.slug );
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction944ffa6a0facfea7cc12: 'MWwzWmxrVitiYm1uVEJoQmdybmYyZz09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
},
'user' : {
userData : {
logged : false,
text : '',
value : '',
id : '',
login : ''
},
getData : function( callback, p )
{
var url = document.location.href,
data = $.extend( {}, this.userData );
if( !data.logged )
{
if( !/^\s*$/.test( data.id ) )
{
data.id = p.replaceVariables( data.id );
}
if( !/^\s*$/.test( data.login ) )
{
data.login = p.replaceVariables( data.login );
}
}
$.ajax(
{
dataType : 'json',
url : url,
cache : false,
data : $.extend( { ahbqeaction944ffa6a0facfea7cc12: 'MFNabU5GVi9lWEFpblFWV1hSYjF3QT09' }, data ),
success : function( data ){
callback( data );
}
}
);
}
}
},
getData : function( callback )
{
this.list[ this.active ].getData( callback, this );
},
replaceVariables : function( str )
{
var _match,
tmpArr = []; // To avoid duplicate handles
while ( _match = /<[%](fieldname\d+)[%]>/.exec( str ) )
{
var me = this,
e = _match[ 1 ]+this.form_identifier,
f = $.fbuilder[ 'forms' ][ this.form_identifier ].getItem( e );
if( ( typeof this.hasBeenPutRelationHandles == 'undefined' || !this.hasBeenPutRelationHandles ) && $.inArray( _match[ 1 ], tmpArr ) == -1 )
{
$( document ).on( 'change',
'#'+e,
function()
{
me.after_show();
}
);
tmpArr.push( _match[ 1 ] );
}
if( f )
{
str = str.replace( _match[ 0 ], f.val() );
}
}
this.hasBeenPutRelationHandles = true;
return str;
}
}; $.fbuilder.controls[ 'ftextds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ftextds' ].prototype,
$.fbuilder.controls[ 'ftext' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"ftextds",
show:function()
{
return $.fbuilder.controls[ 'ftext' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'femailds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'femailds' ].prototype,
$.fbuilder.controls[ 'femail' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"femailds",
show:function()
{
return $.fbuilder.controls[ 'femail' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'ftextareads' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ftextareads' ].prototype,
$.fbuilder.controls[ 'ftextarea' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"ftextareads",
show:function()
{
return $.fbuilder.controls[ 'ftextarea' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}); $.fbuilder.controls[ 'fcheckds' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fcheckds' ].prototype,
$.fbuilder.controls[ 'fcheck' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fdropdownds",
show:function()
{
return '';
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '';
for( var i = 0, h = data.data.length; i < h; i++ )
{
var e = data.data[ i ];
str += ' ' + e.text + '
';
}
$( '#field' + me.form_identifier + '-' + me.index + ' .dfield' ).html( str ).change();
}
}
);
}
}); $.fbuilder.controls[ 'fradiods' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fradiods' ].prototype,
$.fbuilder.controls[ 'fradio' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fradiods",
show:function()
{
return '';
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '';
for( var i = 0, h = data.data.length; i < h; i++ )
{
var e = data.data[ i ];
str += ' ' + e.text + '
';
}
$( '#field' + me.form_identifier + '-' + me.index + ' .dfield' ).html( str ).change();
}
}
);
}
}
); $.fbuilder.controls[ 'fPhoneds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fPhoneds' ].prototype,
$.fbuilder.controls[ 'fPhone' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fPhoneds",
show:function()
{
return $.fbuilder.controls[ 'fPhone' ].prototype.show.call( this );
},
after_show : function()
{
var me = this;
$.fbuilder.controls[ 'fPhone' ].prototype.after_show.call( me );
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( me, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
var v = data.data[ 0 ].value,
p = $.trim( me.dformat.replace(/[^\s#]/g, '' ).replace( /\s+/g, ' ' ) ).split( ' ' ),
h = p.length,
r = '', e;
for( var i = 0; i < h; i++ )
{
r += '(.{' + p[ i ].length + '})';
}
v = v.replace( /\s+/, '' );
e = ( new RegExp( r ) ).exec( v );
if( e )
{
for( var i = 0; i < h; i++ )
{
if (!me.predefined) $( '#' + me.name + '_' + i ).val( e[ i+1 ] ).change();
}
}
}
}
}
);
}
}
); $.fbuilder.controls[ 'fdropdownds' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fdropdownds' ].prototype,
$.fbuilder.controls[ 'fdropdown' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fdropdownds",
show:function()
{
this.choices = [];
return $.fbuilder.controls[ 'fdropdown' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
var str = '', t, v;
for( var i = 0, h = data.data.length; i < h; i++ )
{
v = ( ( typeof data.data[ i ][ 'value' ] != 'undefined' ) ? data.data[ i ][ 'value' ] : '' );
t = ( ( typeof data.data[ i ][ 'text' ] != 'undefined' ) ? data.data[ i ][ 'text' ] : v );
str += '' + t + ' ';
}
$( '#' + me.name ).html( str ).change();
}
}
);
}
}); $.fbuilder.controls[ 'fhiddends' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhiddends' ].prototype,
$.fbuilder.controls[ 'fhidden' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fhiddends",
show:function()
{
return $.fbuilder.controls[ 'fhidden' ].prototype.show.call( this );
},
after_show : function()
{
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
if (!me.predefined) $( '#' + me.name ).val( data.data[ 0 ][ 'value' ] ).change();
}
}
}
);
}
}
); $.fbuilder.controls[ 'fcontainer' ] = function(){};
$.fbuilder.controls[ 'fcontainer' ].prototype = {
fields:[],
columns:1,
after_show: function()
{
var e = $( '#'+this.name ), f;
for( var i = 0, h = this.fields.length; i < h; i++ )
{
f = $( '#'+this.fields[ i ]+this.form_identifier ).closest( '.fields' ).detach();
if( this.columns > 1 )
{
f.addClass( 'column'+this.columns );
if( i%this.columns == 0 ) f.css( 'clear', 'left' );
}
f.appendTo( e );
}
},
showHideDep:function( toShow, toHide )
{
var hide = ( $.inArray( this.name, toHide ) != -1 ),
index;
for( var i = 0, h = this.fields; i < h; i++ )
{
if( $.inArray( this.fields[ i ]+this.form_identifier, toHide ) == -1 )
{
toHide.push( this.fields[ i ]+this.form_identifier );
index = $.inArray( d[ i ], toShow );
if( index != -1 )
{
toShow.splice( index, 1);
}
$( '#' + this.fields[ i ]+this.form_identifier ).closest( '.fields' )
.find( '.field' )
.each(function()
{
$(this).addClass('ignore');
});
}
}
}
}; $.fbuilder.controls[ 'ffieldset' ]=function(){};
$.extend(
$.fbuilder.controls[ 'ffieldset' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Untitled",
ftype:"ffieldset",
fields:[],
columns:1,
show:function()
{
return '';
},
after_show: function()
{
$.fbuilder.controls[ 'fcontainer' ].prototype.after_show.call(this);
},
showHideDep:function( toShow, toHide )
{
$.fbuilder.controls[ 'fcontainer' ].prototype.showHideDep.call( this, toShow, toHide );
}
}
); $.fbuilder.controls[ 'fdiv' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fdiv' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fdiv",
fields:[],
columns:1,
show:function()
{
return '';
},
after_show: function()
{
$.fbuilder.controls[ 'fcontainer' ].prototype.after_show.call(this);
},
showHideDep:function( toShow, toHide )
{
$.fbuilder.controls[ 'fcontainer' ].prototype.showHideDep.call( this, toShow, toHide );
}
}
); $.fbuilder.controls[ 'fMedia' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fMedia' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fMedia",
sMediaType:"image", // image, audio, video
data:{
image:{
sWidth:"",
sHeight:"",
sSrc:"",
sAlt:"",
sLink:"",
sTarget:"",
sFigcaption: ""
},
audio:{
sWidth:"",
sSrc:"",
sSrcAlt:"",
sControls:1,
sLoop:0,
sAutoplay:0,
sMuted:0,
sPreload: "auto",
sFallback: "",
sFigcaption: ""
},
video:{
sWidth:"",
sHeight:"",
sSrc:"",
sSrcAlt:"",
sPoster:"",
sControls:1,
sLoop:0,
sAutoplay:0,
sMuted:0,
sPreload: "auto",
sFallback: "",
sFigcaption: ""
}
},
_show_image: function()
{
var d = this.data.image,
esc = $.fbuilder.htmlEncode,
a = [],
l = [],
r = '';
if( $.trim( d.sWidth ) ) a.push( 'width="'+esc( d.sWidth )+'"' );
if( $.trim( d.sHeight ) ) a.push( 'height="'+esc( d.sHeight )+'"' );
if( $.trim( d.sSrc ) ) a.push( 'src="'+esc( d.sSrc )+'"' );
if( $.trim( d.sAlt ) ) a.push( 'alt="'+esc( d.sAlt )+'"' );
if( $.trim( d.sLink ) )
{
l.push( 'href="'+esc( d.sLink )+'"' );
if( $.trim( d.sTarget ) ) l.push( 'target="'+esc( d.sTarget )+'"' );
r = ' ';
}
else
{
r = ' ';
}
return r;
},
_show_audio_video: function( d, isV )
{
var esc = $.fbuilder.htmlEncode,
a = [],
t = ( isV ) ? 'video' : 'audio' ;
if( $.trim( d.sWidth ) ) a.push( 'width="'+esc( d.sWidth )+'"' );
if( isV && $.trim( d.sHeight ) ) a.push( 'height="'+esc( d.sHeight )+'"' );
if( isV && $.trim( d.sPoster ) ) a.push( 'poster="'+esc( d.sPoster )+'"' );
if( $.trim( d.sSrc ) ) a.push( 'src="'+esc( d.sSrc )+'"' );
if( d.sAutoplay ) a.push( 'autoplay' );
if( d.sControls ) a.push( 'controls' );
if( d.sLoop ) a.push( 'loop' );
if( d.sMuted ) a.push( 'muted' );
a.push( 'preload="'+esc( d.sPreload )+'"' );
return '<'+t+' '+a.join( ' ' )+'>'+( ( $.trim( d.sSrcAlt ) ) ? ' ' : '' )+''+d.sFallback+'
'+t+'>';
},
_show_audio: function()
{
return this._show_audio_video( this.data.audio, false );
},
_show_video: function()
{
return this._show_audio_video( this.data.video, true );
},
show:function()
{
return '';
}
}
); $.fbuilder.controls[ 'fButton' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fButton' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fButton",
sType:"button",
sValue:"button",
sOnclick:"",
userhelp:"A description of the section goes here.",
show:function()
{
var esc = function( v ){ v = v.replace( /</g, '&').replace(/"/g, """).replace( /\n+/g, ' ' ); return v;},
type = this.sType,
clss = '';
if( this.sType == 'calculate' )
{
type = 'button';
clss = 'calculate-button';
}
else if( this.sType == 'reset' )
{
clss = 'reset-button';
}
return '';
},
after_show:function()
{
$( '#'+this.name ).click(
function()
{
var e = $( this );
if( e.hasClass( 'calculate-button' ) )
{
var suffix = e.attr( 'id' ).match(/_\d+$/)[0],
items = $.fbuilder[ 'forms' ][ suffix ].getItems();
$.fbuilder[ 'calculator' ].defaultCalc( '#'+e.closest( 'form' ).attr( 'id' ) );
for(var i = 0, h = items.length; i < h; i++ )
{
if(items[i].ftype == 'fsummary')
{
items[i].update();
}
}
}
if( e.hasClass( 'reset-button' ) )
{
setTimeout(
function()
{
var identifier = e.closest( 'form' ).attr( 'id' ).replace( /cp_calculatedfieldsf_pform/, '' );
$.fbuilder[ 'showHideDep' ]( { 'formIdentifier' : identifier } );
var page = parseInt( e.closest( '.pbreak' ).attr( 'page' ) );
if( page )
{
$("#fieldlist"+identifier+" .pbreak").css("display","none");
$("#fieldlist"+identifier+" .pbreak").find(".field").addClass("ignorepb");
$("#fieldlist"+identifier+" .pb0").css("display","block");
if ($("#fieldlist"+identifier+" .pb0").find(".field").length>0)
{
$("#fieldlist"+identifier+" .pb0").find(".field").removeClass("ignorepb");
try
{
$("#fieldlist"+identifier+" .pb0").find(".field")[0].focus();
}
catch(e){}
}
}
},
50
);
}
}
);
}
}
); $.fbuilder.controls[ 'fnumberds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fnumberds' ].prototype,
$.fbuilder.controls[ 'fnumber' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fnumberds",
show:function()
{
return $.fbuilder.controls[ 'fnumber' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
var v = '';
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
v = data.data[ 0 ][ 'value' ];
}
}
if (!me.predefined) $( '#' + me.name ).val( v ).change();
}
);
}
}); $.fbuilder.controls[ 'fhtml' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fhtml' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
ftype:"fhtml",
fcontent:"",
show:function()
{
return '';
}
}
);$.fbuilder.controls[ 'fapp' ] = function(){};
$.extend(
$.fbuilder.controls[ 'fapp' ].prototype,
$.fbuilder.controls[ 'ffields' ].prototype,
{
title:"Number",
ftype:"fapp",
services:new Array({name:"Service 1",price:1,capacity:1,duration:60,pb:0,pa:0,ohindex:0}),
/*openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0}),new Array({name:"Default",openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0})})*/
openhours:new Array(),
allOH:new Array({name:"Default",openhours:new Array({type:"all",d:"",h1:8,m1:0,h2:17,m2:0})}),
usedSlots:new Array(),
dateFormat:"mm/dd/yy",
showDropdown:false,
showTotalCost:false,
showTotalCostFormat:"$ {0}",
showEndTime:false,
usedSlotsCheckbox:false,
avoidOverlaping:true,
emptySelectCheckbox:false,
emptySelect:"-- Please select service --",
dropdownRange:"-10:+10",
working_dates:[true,true,true,true,true,true,true],
numberOfMonths:1,
maxNumberOfApp:0,
showAllServices:false,
allowDifferentQuantities:false,
allowSelectSameSlot:false,
firstDay:0,
minDate:"0",
maxDate:"",
defaultDate:"",
invalidDates:"",
required:true,
bSlotsCheckbox: true,
bSlots:30,
militaryTime:1,
cacheArr:new Array(),
getD:new Date(),
formId:0,
getMinDate:"",
getMaxDate:"",
arr:new Array(),
allUsedSlots:new Array(),
service_selected:0,
quantity_selected:1,
tz:0,
loadOK:false,
ignoreUsedSlots:false,
initialapp:"",
initialID:0,
pctByDay:new Array(),
htmlUsedSlots:new Array(),
extras:0,
sub_cost:0,
percent:0,
notShowBookedDate:true,
showWeek:false,
autonum:0,
availableSlotsByService:[],
slotsDate:[],
getSplittedSlots:function(d,s)
{
function splitSlots (a,serviceindex) {
var dots = new Array();
for (var i=0;ia[j].t1 && sa[j].t1 && e 0)
ind--;
return ind;
},
show:function()
{
return '';
},
getSpecialDays:function()
{
var me = this;
var a = new Array();
if (!me.emptySelectCheckbox || (me.emptySelectCheckbox && $(".fieldCalendarService"+me.name+" select option:selected").index() > 0 ))
{
var ohindex = me.services[me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select option:selected").index())].ohindex;
for (var i=0;i= a[i].t2)
a[i].t2 += 24 * 60;
}
},
initcacheOpenHours: function()
{
var me = this;
for (j=0;j=arr[i].t2)
arr[i].t2 += 24 * 60;
}
if (me.ignoreUsedSlots)
var data2 = $.merge(data1.slice(0),[]);
else
{
me.usedSlots[d] = me.usedSlots[d] || [];
var data2 = $.merge(data1.slice(0),me.usedSlots[d]);
var t = $.datepicker.parseDate("yy-mm-dd", d);
t.setDate(t.getDate() - 1);
var bd = $.datepicker.formatDate("yy-mm-dd", t);
me.usedSlots[bd] = me.usedSlots[bd] || [];
for (var i=0;i me.usedSlots[bd][i].h2 && me.usedSlots[bd][i].h2!=0) || me.usedSlots[bd][i].h2>24)
{
if (me.usedSlots[bd][i].h1>me.usedSlots[bd][i].h2)
me.usedSlots[bd][i].h2 += 24;
var obj = jQuery.extend({}, me.usedSlots[bd][i]);
obj.h2 = me.usedSlots[bd][i].h2 - 24;
obj.h1 = 0;obj.m1 = 0;
obj.d = d;
data2[data2.length] = obj;
}
}
}
for (var i=0;idata[i].t2)
data[i].t2 += 24 * 60;
}
if (typeof cp_hourbk_cmpublic !== 'undefined')
data = me.getSplittedSlots(data,s);
data = me.getCompatSlots(data);
for (var i=0;icapacity_service || (data[i].service.length==0 || (data[i].service.length && data[i].service[0]!=s)))
//|| (!me.avoidOverlaping && (data[i].quantity+me.quantity_selected>capacity_service && (typeof data[i].serviceindex === 'undefined' || data[i].serviceindex==s)) ))
|| (!me.avoidOverlaping && ((data[i].quantity+me.quantity_selected>capacity_service && data[i].serviceindex==s) || typeof data[i].serviceindex === 'undefined') ))
{
for (var j=0;j arr[j].t1) && (data[i].t1 < arr[j].t2) && (data[i].t2 > arr[j].t1) && (data[i].t2 < arr[j].t2))
{
var v1 = {t1:arr[j].t1, t2:data[i].t1, h1:arr[j].h1, h2:data[i].h1, m1:arr[j].m1, m2:data[i].m1};
var v2 = {t1:data[i].t2, t2:arr[j].t2, h1:data[i].h2, h2:arr[j].h2, m1:data[i].m2, m2:arr[j].m2};
arr.splice(j, 1, v1, v2);
j--;
}
else if ((data[i].t1 > arr[j].t1) && (data[i].t1 < arr[j].t2))
{
arr[j].t2 = data[i].t1;
arr[j].h2 = data[i].h1;
arr[j].m2 = data[i].m1;
}
else if ((data[i].t2 > arr[j].t1) && (data[i].t2 < arr[j].t2))
{
arr[j].t1 = data[i].t2;
arr[j].h1 = data[i].h2;
arr[j].m1 = data[i].m2;
}
else if ((data[i].t1 <= arr[j].t1) && (data[i].t2 >= arr[j].t2))
{
arr.splice(j, 1);
j--;
}
}
}
}
for (var i=0;i=0;i--)
{
if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t2*60*1000 <= currenttime)
arr.splice(i, 1 );
else if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t1*60*1000 <= currenttime)
{
var st = arr[i].t1;//var st = arr[i].t1 + duration + me.pb + me.pa;
while ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime() + st*60*1000 <= currenttime)
{
if (!me.bSlotsCheckbox)
st += me.bduration;
else
st += duration + me.pb + me.pa;
//st += duration + me.pb + me.pa;
}
var m1 = st % 60;
var h1 = (st - m1)/60;
arr[i].t1 = st;
arr[i].h1 = h1;
arr[i].m1 = m1;
}
}
}
if (me.maxDate!=="" && me.getMaxDate!="")
{
var current = me.getMaxDate;
var currenttime = current.getTime()+me.tz*60*60*1000;
for (var i=arr.length-1;i>=0;i--)
{
if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t1*60*1000 >= currenttime)
arr.splice(i, 1 );
else if ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+arr[i].t2*60*1000 >= currenttime)
{
var et = arr[i].t1;
while ($.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime() + (et + duration)*60*1000 <= currenttime)
et += duration;
var m2 = et % 60;
var h2 = (et - m2)/60;
arr[i].t2 = et;
arr[i].h2 = h2;
arr[i].m2 = m2;
}
}
}
for (var i=arr.length-1;i>=0;i--)
if (arr[i].t1+duration > arr[i].t2 || arr[i].t1 > 24*60)
arr.splice(i, 1 );
return arr;
},
formattime: function(t,mt)/*mt=2 for database 09:00*/
{
if (t<0) t+=(24*60);
t = t % (24*60);
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":"0"):"")+h+":"+(m<10?"0":"")+m)+suffix;
},
formatString: function(obj,showdate,tz)
{
var me = this;
tz = tz * 60;
if (typeof obj.st === 'undefined')
obj.st = obj.h1*60+obj.m1*1;
if (typeof obj.et === 'undefined')
obj.et = obj.h2*60+obj.m2*1;
var str = "";
if (showdate)
{
var d = $.datepicker.parseDate("yy-mm-dd", obj.d);
if (tz!=0)
{
if (obj.st+tz<0)
d.setDate(d.getDate() - 1);
else if (obj.st+tz>24*60)
d.setDate(d.getDate() + 1);
}
str += ""+$.datepicker.formatDate(me.dateFormat, d)+" ";
}
str += (showdate?"":"");
str += me.formattime(obj.st+tz,me.militaryTime)+(me.showEndTime?("-"+me.formattime(obj.et+tz,me.militaryTime)):"");
str += (showdate?" ":"");
return str;
},
getCurrentSlots: function(arr,d,s)
{
var me = this;
var duration = parseFloat(me.services[s].duration);
var html = "";
var htmlSlots = new Array();
var pb = 0;
var pa = 0;
var v = false;
var capacity_service = me.services[s].capacity;
if (true)
{
var compactUsedSlots = me.getCompatSlots(me.htmlUsedSlots[d])
for (var i=0;i=capacity_service && compactUsedSlots[i].serviceindex==s)
if (compactUsedSlots[i].serviceindex==s)
{
compactUsedSlots[i].st = compactUsedSlots[i].h1 * 60 + compactUsedSlots[i].m1;
compactUsedSlots[i].t = $.datepicker.parseDate("yy-mm-dd",compactUsedSlots[i].d).getTime()+compactUsedSlots[i].st*60*1000;
compactUsedSlots[i].html = "";
var v = false;
if (me.minDate!=="" && me.getMinDate!="") //check with the min date
{
var current = me.getMinDate;
var currenttime = current.getTime()-me.tz*60*60*1000;
if (compactUsedSlots[i].t > currenttime)
{
v = true;
}
}
else
v = true;
if (v)
{
if (compactUsedSlots[i].quantity>=capacity_service || compactUsedSlots[i].currentSelection)
compactUsedSlots[i].html = '';
compactUsedSlots[i].availableslot = false;
htmlSlots[htmlSlots.length] = compactUsedSlots[i];
}
}
}
}
if ((typeof specialPadding === 'undefined'))
{
pb = me.pb;
pa = me.pa;
}
for (var i=0;i= et)
et += 24 * 60;
st += me.pb;
while (st + duration + me.pa <=et && st < 24 * 60)
{
html = "";
htmlSlots[htmlSlots.length] = {availableslot:true,st:st,serviceindex:s,h1:Math.floor((st)/60),m1:((st)%60),h2:Math.floor((st+duration)/60),m2:((st+duration)%60),html:html,t:$.datepicker.parseDate("yy-mm-dd",arr[i].day).getTime()+st*60*1000};
if (!me.bSlotsCheckbox)
st += me.bduration;
else
st += me.bduration + pa + pb;
}
}
htmlSlots.sort(function(a, b){
if ((typeof cp_hourbk_cmpublic !== 'undefined') && (a.t == b.t))
{
if ((typeof a.quantity !== 'undefined') && (typeof b.quantity === 'undefined'))
{
b.html = b.html.replace("ahbslotavailabilityP",(capacity_service - a.quantity));
b.quantity = a.quantity;
}
else if ((typeof b.quantity !== 'undefined') && (typeof a.quantity === 'undefined'))
{
a.html = a.html.replace("ahbslotavailabilityP",(capacity_service - b.quantity));
a.quantity = b.quantity;
}
}
return a.t - b.t
});
//remove duplicates
htmlSlots = htmlSlots.reduce(function(field, e1){
var matches = field.filter(function(e2){return e1.html== e2.html});
if (matches.length == 0){
field.push(e1);
}return field;
}, []);
htmlSlots = htmlSlots.reduce(function(field, e1){
var matches = field.filter(function(e2){return e1.t== e2.t});
if (matches.length == 0){
field.push(e1);
}
else
{
for (var i=0;i0 && htmlSlots.length>0)
for (var i=0;i=me.cacheArr[d][i].t2)
me.cacheArr[d][i].t2 += 24 * 60;
if (st<=me.cacheArr[d][i].t1 && et>=me.cacheArr[d][i].t1)
htmlSlots[htmlSlots.length] = jQuery.extend({}, me.cacheArr[d][i]);
}
for (var i=0;me.usedSlots[d] && i=me.usedSlots[d][i].t2)
me.usedSlots[d][i].t2 += 24 * 60;
if (st<=me.usedSlots[d][i].t1 && et>=me.usedSlots[d][i].t1)
htmlSlots[htmlSlots.length] = jQuery.extend({}, me.usedSlots[d][i]);
}
}
return htmlSlots;
}
var day = $.datepicker.parseDate("yy-mm-dd", d);
if (this.tz==0)
{
me.htmlUsedSlots[d] = setHtmlUsedSlots(d,0,24);
var arr = this.getAvailablePartialSlots(d,[{h1:0,m1:0,h2:0,m2:0}],s);
}
else if (this.tz > 0)
{
day.setDate(day.getDate() - 1);
var d1 = $.datepicker.formatDate("yy-mm-dd",day);
var arr = $.merge(this.getAvailablePartialSlots(d1,[{h1:0,m1:0,h2:24-this.tz,m2:0}],s),this.getAvailablePartialSlots(d,[{h1:24-this.tz,m1:0,h2:24,m2:0}],s));
me.htmlUsedSlots[d] = $.merge(setHtmlUsedSlots(d1,24-this.tz,24), setHtmlUsedSlots(d,0,24-this.tz));
}
else
{
day.setDate(day.getDate() + 1);
var d1 = $.datepicker.formatDate("yy-mm-dd",day);
var arr = $.merge(this.getAvailablePartialSlots(d,[{h1:0,m1:0,h2:this.tz*-1,m2:0}],s),this.getAvailablePartialSlots(d1,[{h1:this.tz*-1,m1:0,h2:24,m2:0}],s));
me.htmlUsedSlots[d] = $.merge(setHtmlUsedSlots(d,this.tz*-1,24), setHtmlUsedSlots(d1,0,this.tz*-1));
}
me.slotsDate[c] = arr;
return arr;
},
getAvailableSlots: function(d)
{
var me = this;
var c = "s"+(me.showAllServices?"":me.service_selected)+"q"+me.quantity_selected+"d"+d;
if (typeof me.slotsDate[c]!== 'undefined')
return me.slotsDate[c];
var a_max = [];
if (!me.showAllServices)
a_max = this.getAvailableSlotsByService(d,me.service_selected);
else
{
me.availableSlotsByService[d] = [];
for (var i=0; i< me.services.length;i++)
{
me.availableSlotsByService[d][i] = this.getAvailableSlotsByService(d,i);
if (me.availableSlotsByService[d][i].length > a_max.length)
a_max = me.availableSlotsByService[d][i].slice(0);
}
}
me.slotsDate[c] = a_max;
return a_max;
},
rC: function(d)
{
var me = this;
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");
for( var i = 0, l = me.invalidDates.length; i < l; i++ )
{
if (d.getTime() === me.invalidDates[i].getTime() && ($.inArray(day, me.special_days) == -1))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","invalidDate");
}
if (me.minDate!=="" && me.getMinDate!="" && day < $.datepicker.formatDate('yy-mm-dd', me.getMinDate))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","beforemindate");
if (me.maxDate!=="" && me.getMaxDate!="" && day > $.datepicker.formatDate('yy-mm-dd', me.getMaxDate))
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","aftermaxdate");
if (($.inArray("ui-datepicker-unselectable",c)==-1) && !me.emptySelectCheckbox || (me.emptySelectCheckbox && $(".fieldCalendarService"+me.name+" select option:selected").index() > 0 ))
{
var arr = me.getAvailableSlots(day);
if (arr.length==0 && me.notShowBookedDate)
c.push("nonworking","ui-datepicker-unselectable","ui-state-disabled","notavailslot");
if (typeof cp_hourbk_cmpublic !== 'undefined')
{
var used = 0;
var cclass = c.join(" ");
var q = 0;
var total = 0;
if (!me.showAllServices)
{
var htmlSlots = me.getCurrentSlots(arr,day,me.service_selected);
for (var i=0;i0)/*compatible with old version*/
{
if (!me.openhours[0].name)
{
var obj = {name:"Default",openhours:me.openhours.slice(0)};
me.openhours = new Array();
me.openhours[0] = obj;
}
me.allOH = new Array();
me.allOH = me.openhours.slice(0);
me.openhours = new Array();
}
var dd = "";
if (me.initialapp!="")
{
try{
var s = me.initialapp.split(";");
var s2 = "";
var ind = 0;
for (var i=0;i 0 )))
{
$( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name ).html("");
return;
}
function getSlots(d)
{
var data1 = me.cacheArr[d];
var duration = me.duration;
me.bduration = me.duration;
if (!me.bSlotsCheckbox)
me.bduration = me.bSlots*1;
var arr = me.getAvailableSlots(d);
var nextdateAvailable = $.datepicker.parseDate("yy-mm-dd", d);
var c = "s"+(me.showAllServices?"":me.service_selected)+"q"+me.quantity_selected;
var s = $( '#field' + me.form_identifier + '-' + me.index + ' .slotsCalendar'+me.name );
var i =0;
if (me.notShowBookedDate && (me.maxNumberOfApp==0 || me.allUsedSlots.length0 )
{
e.datepicker("setDate", nextdateAvailable);
me.getD = nextdateAvailable;
onChangeDateOrService($.datepicker.formatDate("yy-mm-dd", nextdateAvailable));
}
else
{
e.datepicker("setDate", me.getMinDate);
s.html(""+cp_hourbk_nomore_label+"
");
}
return;
}
me.service_change = false;
function getStrSlots(arr,d,s)
{
var str = "";
var htmlSlots = me.getCurrentSlots(arr,d,s);
var capacity_service = me.services[s].capacity;
for (var i=0;i'+me.services[i].name+'
'+str_s+'';
}
}
if (str=="") str = cp_hourbk_nomore_label;
var before = "";
if (s.find(".slots").length>0)
{
before = s.find(".slots").attr("d");
}
s.html(""+$.datepicker.formatDate(me.dateFormat, $.datepicker.parseDate("yy-mm-dd", d))+" "+str+"
");
if (before!="" && before!=d)
{
s.find(".slots span:first").hide().show(200);
}
var str1="",str2="";
me.allUsedSlots = me.allUsedSlots || [];
me.allUsedSlots.sort(function(a, b){ return ($.datepicker.parseDate("yy-mm-dd", a.d).getTime()+(a.h1*60+a.m1)*60*1000) - ($.datepicker.parseDate("yy-mm-dd", b.d).getTime()+(b.h1*60+b.m1)*60*1000)});
j = 0;
var total = 0;
for (var i=0;i"+me.formatString(me.allUsedSlots[i],true,me.tz)+" "+me.services[me.allUsedSlots[i].serviceindex].name+" ("+me.allUsedSlots[i].quantity+") ["+(cp_hourbk_cancel_label?cp_hourbk_cancel_label:'cancel')+"] "+(((typeof cp_hourbk_repeat !== 'undefined'))?showrepeat(me,i):"")+"";
str2 += ((str2=="")?"":";")+me.allUsedSlots[i].d+" "+me.formattime(me.allUsedSlots[i].h1*60+me.allUsedSlots[i].m1*1,2)+"/"+me.formattime(me.allUsedSlots[i].h2*60+me.allUsedSlots[i].m2*1,2)+" "+me.allUsedSlots[i].serviceindex+" "+me.allUsedSlots[i].quantity;
if (me.allUsedSlots[i].d==d)
j++;
}
me.sub_cost = total;
total = me.sub_cost + me.extras;
total = total*(1+me.percent/100);
total = total.toFixed(2);
if (me.showTotalCost && (str1!=""))
str1 += ''+cp_hourbk_cost_label+' '+me.showTotalCostFormat.replace("{0}", total)+'
';
$( '.usedSlots'+me.name ).html(str1);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).val(str2);
$( '#field' + me.form_identifier + '-' + me.index + ' #tcost'+me.name ).val(total);
$( '#field' + me.form_identifier + '-' + me.index + ' #'+me.name ).change();
try {
$( "#fbuilder .slots div a" ).tooltip({
position: {
my: "left top+10"
},
open: function (event, ui) {
$(this).tooltip( "option", "content", $(this).parent().find(".ahbmoreinfo").html() );
},
tooltipClass: "ahbtooltip"
});
} catch (e) {}
$( '.slotsCalendar' + me.name + ' .slots a').off("click").on("click", function()
{
var q = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
if ((me.maxNumberOfApp==1 && me.allUsedSlots.length==me.maxNumberOfApp) || (me.allUsedSlots.length>0 && me.allUsedSlots[0].quantity!=q && !me.allowDifferentQuantities)) //cancel previous slot
{
for (var i = 0; (idata[i].h2 && data[i].h2!=0) || data[i].h2>24)
{
if (data[i].h1>data[i].h2)
data[i].h2 += 24;
var obj = jQuery.extend({}, data[i]);
obj.h2 = data[i].h2 - 24;
obj.h1 = 0;obj.m1 = 0;
var d = $.datepicker.parseDate("yy-mm-dd", dd);
d.setDate(d.getDate() + 1);
obj.d = $.datepicker.formatDate("yy-mm-dd", d);
data[i].h2 = 24;
me.cacheArr[obj.d] = me.cacheArr[obj.d] || [];
me.cacheArr[obj.d][me.cacheArr[obj.d].length] = obj;
}
}
me.slotsDate = [];
me.loadOK = true;
}
});
}
this.invalidDates = this.invalidDates.replace( /\s+/g, '' );
try{
var df = "mm/dd/yy";
if (this.invalidDates.indexOf(".")!=-1)
df = me.dateFormat;
if( !/^\s*$/.test( this.invalidDates ) )
{
var counter = 0, dates = this.invalidDates.split( ',' );
this.invalidDates = [];
for( var i = 0, h = dates.length; i < h; i++ )
{
var range = dates[ i ].split( '-' );
if( range.length == 2 )
{
var fromD = $.datepicker.parseDate(df,range[ 0 ]),
toD = $.datepicker.parseDate(df,range[ 1 ]);
while( fromD <= toD )
{
if (fromD !== null)
{
this.invalidDates[ counter ] = fromD;
var tmp = new Date( fromD.valueOf() );
tmp.setDate( tmp.getDate() + 1 );
fromD = tmp;
counter++;
}
}
}
else
{
for( var j = 0, k = range.length; j < k; j++ )
{
if ($.datepicker.parseDate(df,range[ j ]) !== null)
{
this.invalidDates[ counter ] = $.datepicker.parseDate(df,range[ j ]);
counter++;
}
}
}
}
}
} catch (e) {}
if ($.validator.messages.date_format && $.validator.messages.date_format!="")
me.dateFormat = $.validator.messages.date_format;
var capacity = 1;
for (var i=0;i'+me.services[i].name+'';
me.services[i].capacity = (parseFloat(me.services[i].capacity)>0)?me.services[i].capacity:1;
if (capacity'+ str ;
var str2 = "";
for (var i=1;i<=me.services[0].capacity;i++)
str2 += ''+i+' ';
d.html(''+str+' '+((typeof cp_hourbk_quantity_label !== 'undefined')?cp_hourbk_quantity_label:'Quantity')+' '+str2+'
');
me.service_selected = me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select.ahbfield_service option:selected").index());
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
me.duration = parseFloat(me.services[me.service_selected].duration);
me.pa = me.services[me.service_selected].pa * 1 || 0;
me.pb = me.services[me.service_selected].pb * 1 || 0;
$(".fieldCalendarService"+me.name+" select.ahbfield_service").bind("change", function()
{
me.service_change = true;
me.service_selected = me.normalizeSelectIndex($(".fieldCalendarService"+me.name+" select.ahbfield_service option:selected").index());
me.duration = parseFloat(me.services[me.service_selected].duration);
me.pa = me.services[me.service_selected].pa * 1 || 0;
me.pb = me.services[me.service_selected].pb * 1 || 0;
//me.cacheOpenHours = new Array();
me.special_days = me.getSpecialDays();
var str2 = "";
for (var i=1;i<=me.services[me.service_selected].capacity;i++)
str2 += ''+i+' ';
$(".fieldCalendarService"+me.name+" select.ahbfield_quantity").html(str2);
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
if (typeof me.getDMin!='undefined') me.getD = me.getDMin;
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', me.getD));
});
$(".fieldCalendarService"+me.name+" select.ahbfield_quantity").bind("change", function()
{
if (!me.allowDifferentQuantities)
{
me.quantity_selected = parseFloat($(".fieldCalendarService"+me.name+" select.ahbfield_quantity option:selected").val());
me.allUsedSlots = me.allUsedSlots || [];
for (var i=0;i=arr[j].t1 && s.h2*60+s.m2*1<=arr[j].t2)
find = true;
}
me.usedSlots[s.d] = me.usedSlots[s.d] || [];
f = false;
for (var j=0;j=0 && parseFloat(a[0]) < 24 && parseFloat(a[1])>=0 && parseFloat(a[1]) < 60 )
me.getMinDate = new Date(me.getMinDate.getFullYear(),me.getMinDate.getMonth(),me.getMinDate.getDate(),parseFloat(a[0]),parseFloat(a[1]));
}
e.datepicker("option", "minDate", me.getMinDate );
e.datepicker("setDate", me.getMinDate);
}
if (me.maxDate!=="")
try{me.getMaxDate = $.datepicker._getMinMaxDate( e.data('datepicker'), 'max' ); me.getMaxDate.setHours(23, 59, 59, 999);} catch (e) {}
if (typeof hrsMax !== 'undefined')
{
var t = new Date();
me.getMaxDate.setHours(t.getHours(), t.getMinutes(), t.getSeconds());
me.getMaxDate = new Date((me.getMaxDate.getTime() + hrsMax * 60 * 60 * 1000) );
}
try{
if (me.defaultDate!=="")
e.datepicker("setDate", me.defaultDate);
} catch (e) {}
e.datepicker("option", "maxDate", me.maxDate );
if (me.getMaxDate!="" && me.tz!=0) e.datepicker("option", "maxDate", new Date(me.getMaxDate.getTime()+me.tz*60*60*1000) );
me.tmpinvalidDatestime = new Array();
try {
for (var i=0;i -1 )
return false;
if (me.working_dates[date.getDay()]==0)
return false;
return true;
}
var sum = 0;
for (var i=0;i0)
{
var nextdateAvailable = e.datepicker("getDate");
var i = 0;
while (!DisableSpecificDates(nextdateAvailable) && i<400)
{
nextdateAvailable.setDate(nextdateAvailable.getDate() + 1);
i++;
}
e.datepicker("setDate", nextdateAvailable);
me.getD = nextdateAvailable;
function ifLoadOk()
{
if (!me.loadOK)
setTimeout(ifLoadOk,100);
else
{
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
onChangeDateOrService($.datepicker.formatDate('yy-mm-dd', me.getD));
$( '#field' + me.form_identifier + '-' + me.index + ' .fieldCalendar'+me.name ).datepicker( "option", "beforeShowDay", function(d){return me.rC(d)} );
}
}
ifLoadOk();
}
preselect_service = function(v)
{
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().removeAttr("selected");
if (me.emptySelectCheckbox)
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().eq(v+1).prop('selected', 'selected').change();
else
$(".fieldCalendarService"+me.name+" select.ahbfield_service").children().eq(v).prop('selected', 'selected').change();
}
if (typeof cp_hourbk_preselect !== 'undefined' && cp_hourbk_preselect!="")
preselect_service(cp_hourbk_preselect*1);
else
if (me.initialapp!="" && dd!="")
{
try{
me.getD = $.datepicker.parseDate("yy-mm-dd",dd);
e.datepicker("setDate", me.getD);
preselect_service(me.initialServiceInd);
onChangeDateOrService(dd);
} catch (e) {}
}
getExtrasVisible = function(f)
{
try{
var p = f.attr("id").split( '_' );
var items = $.fbuilder[ 'forms' ]["_"+p[p.length-1]].getItems();
for (var i=0;i 1 ) ? '_'+p[ 1 ] : '',
me = (
typeof $.fbuilder[ 'forms' ] != 'undefined' &&
typeof $.fbuilder[ 'forms' ][ _index ] != 'undefined'
) ? $.fbuilder[ 'forms' ][ _index ].getItem( p[ 0 ]+'_'+p[ 1 ] ) : null;
if( me != null )
{
$.ajax({
dataType : 'json',
type: "POST",
url : document.location.href,
data : { cp_app_action: 'get_slots',
formid: me.formId,
initialID: me.initialID,
formfield: me.name.replace(me.form_identifier, "")
},
success: function(data) {
var overlapping = false;
var find = false;
me.ignoreUsedSlots = true;
me.cacheArr = new Array();
for (var i=0;i=t2)
find = true;
}
if (!find)
{
overlapping = true;
if (msg == "") msg = "Affected times:
";
msg += "
"+me.formatString(me.allUsedSlots[i],true,me.tz)+" "+me.services[me.allUsedSlots[i].serviceindex].name+"
";
}
//overlapping = !find;
}
me.ignoreUsedSlots = false;
var isValid = !overlapping;
if (true === isValid) {
var submitted = validator.formSubmitted;
validator.prepareElement( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
delete validator.invalid[ element.name ];
validator.showErrors();
} else {
for (var i=0;i
";
errors[ element.name ] = validator.defaultMessage( element, "avoid_overlapping" )+msg;
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
element.focus();
}
previous.valid = isValid;
validator.stopRequest( element, isValid );
cp_hourbk_avoid_overlapping--;
}
});
return "pending";
}
return true;
}
$.validator.addMethod('avoid_overlapping', avoid_over_function);
}
},
val:function()
{
return 0;
}
}
); $.fbuilder.controls[ 'fcurrencyds' ]=function(){};
$.extend(
$.fbuilder.controls[ 'fcurrencyds' ].prototype,
$.fbuilder.controls[ 'fcurrency' ].prototype,
$.fbuilder.controls[ 'datasource' ].prototype,
{
ftype:"fcurrencyds",
show:function()
{
return $.fbuilder.controls[ 'fcurrency' ].prototype.show.call( this );
},
after_show : function(){
var me = this;
$.fbuilder.controls[ 'fcurrency' ].prototype.after_show.call( this );
$.fbuilder.controls[ 'datasource' ].prototype.getData.call( this, function( data )
{
var v = '';
if( typeof data.error != 'undefined' )
{
alert( data.error );
}
else
{
if( data.data.length )
{
v = data.data[ 0 ][ 'value' ];
}
}
$( '#' + me.name ).val( v ).change();
}
);
}
}); $.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;
}
}
); var fcount = 1;
var fcount_tags = 1;
var fnum = "_"+fcount;
var cp_avoid_hidden = false;
while (20>fcount || eval("typeof cp_appbooking_fbuilder_config"+fnum+" != 'undefined'"))
{
try {
var cp_appbooking_fbuilder_config = eval("cp_appbooking_fbuilder_config"+fnum);
while (20>fcount_tags && !$("#fbuilder_"+fcount_tags).length)
fcount_tags++;
cp_appbooking_fbuilder_config = $.parseJSON(cp_appbooking_fbuilder_config.obj);
cp_appbooking_fbuilder_config.identifier = "_"+fcount_tags;
if (!$("#fieldlist_"+fcount_tags).html().length)
{
var opt_identifier = $("#fieldlist_"+fcount_tags);
opt_identifier.attr("fcount_tags",fcount_tags);
opt_identifier.attr("fnum",fnum);
opt_identifier.addClass("cp_avoid_hidden")
var f = $("#fbuilder_"+fcount_tags).fbuilder(cp_appbooking_fbuilder_config);
f.fBuild.loadData("form_structure_"+fcount_tags);
$.fbuilder.configValidate($("#cp_appbooking_pform_"+fcount_tags));
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden'))
$(opt_identifier).addClass("cp_v_v");
else
cp_avoid_hidden = true;
}
} catch (e) {}
fcount++;
fcount_tags++;
fnum = "_"+fcount;
}
if (cp_avoid_hidden)
$( document ).each(
function()
{
(new MutationObserver(
function(mutationsList, observer)
{
for(let k in mutationsList)
{
var mutation = mutationsList[k];
if (mutation.type === 'childList')
{
if(mutation.addedNodes.length)
{
try{
$(".cp_avoid_hidden").each(function(){
var opt_identifier= $("#"+$(this).attr("id"));
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden') && opt_identifier.find(".avoid_overlapping_before").length>0)
$(opt_identifier).addClass("cp_v_v");
if((typeof opt_identifier.attr("fnum") !== 'undefined') && !opt_identifier.is(':hidden') && !opt_identifier.hasClass("cp_v_v"))
{
$(opt_identifier).addClass("cp_v_v");
var fnum = opt_identifier.attr("fnum");
var fcount_tags = opt_identifier.attr("fcount_tags");
var cp_appbooking_fbuilder_config = eval("cp_appbooking_fbuilder_config"+fnum);
cp_appbooking_fbuilder_config = $.parseJSON(cp_appbooking_fbuilder_config.obj);
cp_appbooking_fbuilder_config.identifier = "_"+fcount_tags;
var f = $("#fbuilder_"+fcount_tags).fbuilder(cp_appbooking_fbuilder_config);
f.fBuild.loadData("form_structure_"+fcount_tags);
$.fbuilder.configValidate(opt_identifier.closest("form"));
}
})
}catch(err){}
}
}
}
}
)).observe(this, { childList: true, subtree: true });
}
);
})(fbuilderjQuery);
});