var j = jQuery.noConflict();
;(function($)
{
	app = {
		//active: (config.admin === false || app.in_array(config.page, ['idevices', 'ihours', 'irepair', 'isettings', 'istore']) ? true : false),
		longpress: 750,
		startime: 0,
		start: function(config)
		{
			config.colors = JSON.parse(config.colors);
			if(config.admin)
			{
				$('#adminmenu .wp-submenu li a').each(function()
				{
					var href = $(this).attr('href');
					if (href.indexOf('admin.php') > -1)
					{
						$(this).attr('href', href + '&time=' + $.now())
					} 
				});
				$(document).on('keypress', 'input[name="s"], input[name="reason"], input[name="description"], input[name="price"]', function(e)
				{
					//console.log('keypress input[name="s"], input[name="reason"], input[name="description"], input[name="price"]');
					var key = (e.keyCode ? e.keyCode : e.which), name = $(this).attr('name');
					/*
						Disabled: Currency comma replace
						if(name == 'price')
						{
							if(key == 46)
							{
								e.preventDefault();
								$(this).val($(this).val()+',');
								return false;
							}
						}
					*/
					if(key == 13)
					{
						e.preventDefault();
						$(this).trigger('blur').trigger('change').next('a[class*="button"]:first').trigger('click');
						return false;
					}

				}).on('click', 'a[name="insert"]', function(e)
				{
					//console.log('click a[name="insert"]');
					e.preventDefault();
					if(app.validate($(this)))
					{
						if(app.check('facts'))
						{
							$(this).closest('form')
								.append('<input type="hidden" name="action" value="insert" />')
								.append('<input type="hidden" name="page" value="' + config.page + '" />')
							.submit();
						}
					}
				}).on('click', 'a[name="adjust"]', function(e)
				{
					//console.log('click a[name="adjust"]');
					e.preventDefault();
					if(app.validate($(this)))
					{
						$(this).closest('form')
							.append('<input type="hidden" name="action" value="adjust" />')
							.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.append('<input type="hidden" name="page" value="' + config.page + '" />')
						.submit();
					}
				}).on('click', 'a[name="assign"][class*="button"]', function(e)
				{
					console.log('click a[name="assign"][class*="button"]');
					e.preventDefault();
					/*
						Test: Trigger price on click assign
						$(this).closest('td input[name="price"]').trigger('change');
					*/
					/*
						price empty = delete
						price and empty discount
						price and discount
					*/
					var price = $(this).closest('tr').find('input[name="price"]');
					/*
						, discount = $(this).closest('tr').find('input[name="discount"]');
					*/
					if(price.val() === '' || $('i', this).hasClass('fa-trash'))
					{
						$(this).removeClass('danger').addClass('success');
						$('i', this).removeClass('fa-trash').addClass('fa-pencil');
						price.val('');
						/*
							discount.val('');
						*/
						$(this).closest('tr').find('select[name="duration"] option[value="' + config.duration + '"]').attr('selected', 'selected');
					}
					else
					{
						$(this).removeClass('success').addClass('danger');
						$('i', this).removeClass('fa-pencil').addClass('fa-trash');
					}
					$(this).closest('tr').each(function()
					{
						var tr = $(this);
						if($('input[name="s"]').val())
						{
							var datest = '?repair=' + $(this).find('td.column-id').html() + '&device=' + $('input[name="s"]').val();
						}
						else
						{
							var datest = '?repair=' + config.id + '&device=' + $(this).find('td.column-id').text().replace('Meer details tonen', '');
						}
/*
(id.length ? id.html() : config.id)
($(this).find('td.column-id') ? $(this).find('td.column-id').text() : $('input[name="search"]').val())
						var datest = '?repair=' + config.id + '&device=' + $(this).find('td.column-id').text().replace('Meer details tonen', '');
*/
						tr.find('td input[type=text], select').each(function()
						{
							if($(this).attr('name') === 'price' && $(this).attr('value') === '')
							{
								/*
									Disabled: Reset select on empty price
									tr.find('td select[name="duration"]').val('');
								*/
							}
							datest += '&' + $(this).attr('name') + '=' + (typeof $(this).val() == 'undefined' ? (typeof $(this).attr('value') == 'undefined' ? '' : $(this).attr('value')) : $(this).val());
						});
						console.dir(datest);
						$.ajax({
							url : 'https://' + config.domain + '/wp-admin/admin-ajax.php' + datest,
							type : 'get',
							async:false,
							cache:false,
							data : {
								action : 'assign'
							},
							dataType : 'json',
							success : function(response)
							{
								//console.log(response.status);
								console.dir(response);
							}
						});
					});

				}).on('click', 'a[href*="action=copier"]', function(e)
				{
					//console.log('click a[href*="action=copier"]');
					e.preventDefault();
					app.popupper('Bevestigen', 'Weet je zeker dat je wilt kopiëren?', 'Natuurlijk', function(result)
					{
						if(result)
						{
							$(location).attr('href', $(e.target).attr('href'));
						}
					});
				}).on('click', 'a[name="copier"]', function(e)
				{
					//console.log('click a[name="copier"]');
					e.preventDefault();
					app.popupper('Bevestigen', 'Weet je zeker dat je wilt kopiëren?', 'Natuurlijk', function(result)
					{
						if(result)
						{
							$(e.target).closest('form')
								.append('<input type="hidden" name="action" value="copier" />')
								.append('<input type="hidden" name="page" value="' + config.page + '" />')
								.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.submit();
						}
					});
				}).on('click', 'a[name="favorite"]', function(e)
				{
					//console.log('click a[name="favorite"]');
					e.preventDefault();
					$(this).closest('form')
						.append('<input type="hidden" name="action" value="favorite" />')
						.append('<input type="hidden" name="page" value="' + config.page + '" />')
						.append('<input type="hidden" name="id" value="' + config.id + '" />')
					.submit();
				}).on('click', 'a[href*="action=delete"]', function(e)
				{
					//console.log('click a[href*="action=delete"]');
					e.preventDefault();
					app.popupper('Bevestigen', 'Weet je zeker dat je wilt verwijderen?', 'Natuurlijk', function(result)
					{
						if(result)
						{
							$(location).attr('href', $(e.target).attr('href'));
						}
					});
				}).on('click', 'a[name="update"]', function(e)
				{
					//console.log('click a[name="update"]');
					e.preventDefault();
					if(app.validate($(this)))
					{
						if(app.check('facts'))
						{
							$(this).closest('form')
								.append('<input type="hidden" name="action" value="update" />')
								.append('<input type="hidden" name="page" value="' + config.page + '" />')
								.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.submit();
						}
					}
				}).on('click', 'a[name="search"]', function(e)
				{
					//console.log('click a[name="search"]');
					e.preventDefault();
					if(app.validate($(this)))
					{
						$(this).closest('form')
							.append('<input type="hidden" name="action" value="' + config.action + '" />')
							.append('<input type="hidden" name="page" value="' + config.page + '" />')
							.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.append('<input type="hidden" name="s" value="' + ($('input[name="s"]').val().length <= 1 ? 'delete' : $('input[name="s"]').val()) + '" />')
						.submit();
					}
				}).on('click', 'a[name="unsearch"]', function(e)
				{
					//console.log('click a[name="unsearch"]');
					e.preventDefault();
					if($('input[name="s"]').val().length > 1 && $('input[name="s"]').val() !== config.search)
					{
						$(this).closest('form')
							.append('<input type="hidden" name="action" value="' + config.action + '" />')
							.append('<input type="hidden" name="page" value="' + config.page + '" />')
							.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.append('<input type="hidden" name="s" value="' + ($('input[name="s"]').val().length <= 1 ? 'delete' : $('input[name="s"]').val()) + '" />')
						.submit();
					}
					else
					{
						$(this).closest('form')
							.append('<input type="hidden" name="action" value="' + config.action + '" />')
							.append('<input type="hidden" name="page" value="' + config.page + '" />')
							.append('<input type="hidden" name="id" value="' + config.id + '" />')
							.append('<input type="hidden" name="s" value="delete" />')
						.submit();
					}
				}).on('click', 'option', function(e)
				{
					//console.log('click option');
					/*
						var multi = (typeof $(this).parent().attr('multiple') != 'undefined' ? true : false), name = $(this).parent().attr('name'), value = $(this).attr('value'), text = $(this).text();
						if(!app.empty(name))
						{
							if(multi)
							{
								if(name === 'ram[]' && /^(Aanpassen|Aangepast: [1-9]{1,4}(MB|GB|TB))$/i.test(text))
								{
									alert('click');
									app.popupper('Wat is het aangepaste werkgeheugen?!',
										'<form id="popformer" novalidate="novalidate">' +
											'<div class="form-item">' +
												'<input type="text" name="_ram" placeholder="" pattern="' + app.pattern('storages') + '" required="required" /><br />' +
												'<div class="item-hint">&nbsp;</div>' +
											'</div>' +
										'</form>',
									'Aanpassen', function(str)
									{
										if(str)
										{
											$('select[name="ram"] option:selected').text('Aangepast: ' + $('input[name="_ram"]').val()).attr('value', $('input[name="_ram"]').val());
										}
									});
								}
								else if(name === 'storage[]' && /^(Aanpassen|Aangepast: [1-9]{1,4}(MB|GB|TB))$/i.test(text))
								{
									app.popupper('Wat is het aangepaste opslaggeheugen?!',
										'<form id="popformer" novalidate="novalidate">' +
											'<div class="form-item">' +
												'<input type="text" name="_storage" placeholder="" pattern="' + app.pattern('storages') + '" required="required" /><br />' +
												'<div class="item-hint">&nbsp;</div>' +
											'</div>' +
										'</form>',
									'Aanpassen', function(str)
									{
										if(str)
										{
											$('select[name="storage"] option:selected').text('Aangepast: ' + $('input[name="_storage"]').val()).attr('value', $('input[name="_ram"]').val());
										}
									});
								}
							}
						}
					*/
				}).on('change', 'select', function(e)
				{
					//console.log('change select');
					var multi = ($(this).attr('multiple') === 'multiple' ? true : false), name = $(this).attr('name'), value = $(this).attr('value'), text = $(this).find('option:selected').text();
					if(!app.empty(name))
					{
						if(!multi)
						{
							$('select[name^="' + name + '"] option[value="' + value + '"]', this).attr('selected', 'selected').siblings().removeAttr('selected');
						}
						if(name === 'icon')
						{
							$('span[name="sicon"]').html('<i class="fa fa-' + ($(this).val() === 'none' ? 'eye-slash' : ($(this).val() === 'device' ? 'mobile' : $(this).val())) + ' fa-lg fa-fw"></i>');
						}
						else if(name === 'date_starts')
						{
							$('select[name="' + name.replace('_starts', '_ending') + '"]').val(value);
						}
						else if(name === 'device')
						{
							var device = app.jsobjects(config.devices, 'nummer', $(this).val());
							$.each(['colors', 'processor', 'ram', 'storage'], function(keys, values)
							{
								var name = (app.in_array(values, ['colors']) ? values.slice(0, -1) : values);
								$('select[name^="' + name + '"]').empty();
								if($('select[name^="' + name + '"]').attr('multiple') !== 'multiple')
								{
									$('select[name^="' + name + '"]').append($('<option>').text('-').attr('value', ''));
								}
								if(device[values])
								{
									if(device[values].indexOf(',') > -1)
									{
										$.each(device[values].split(','), function(key, value)
										{
											text = (app.in_array(name, ['processor']) ? value : app.ucfirst(value));
											$('select[name^="' + name + '"]').append($('<option>').text(text).attr('value', value));
										});
									}
									else
									{
										text = (app.in_array(name, ['processor']) ? device[values] : app.ucfirst(device[values]));
										$('select[name^="' + name + '"]').append($('<option>').text(text).attr('value', device[values]));
									}
								}
								if(app.in_array(name, ['ram', 'storage']))
								{
									$('select[name^="' + name + '"]').append($('<option>').text('Aanpassen').attr('value', 'Aanpassen'));
								}
								if(name in config.selected)
								{
									if(app.in_array(config.selected[name], ['', null]))
									{
										
									}
									else
									{
										if(config.selected[name].indexOf(',') > -1)
										{
											$.each(config.selected[name].split(','), function(i, e)
											{
												if($('select[name^="' + name + '"] option[value="' + e + '"]').length > 0)
												{
													$('select[name^="' + name + '"] option[value="' + e + '"]').attr('selected', 'selected');
												}
												else
												{
													$('select[name^="' + name + '"] option[value="Aanpassen"]').remove();
													$('select[name^="' + name + '"]').append($('<option>').text('Aangepast: ' + e).attr('value', e).attr('selected', 'selected'));
												}
												//$('select[name^="' + name + '"] option[value="' + e + '"]').attr('selected', 'selected');
											});
										}
										else
										{
											if($('select[name^="' + name + '"] option[value="' + config.selected[name] + '"]').length > 0)
											{
												$('select[name^="' + name + '"] option[value="' + config.selected[name] + '"]').attr('selected', 'selected');
											}
											else
											{
												$('select[name^="' + name + '"] option[value="Aanpassen"]').remove();
												$('select[name^="' + name + '"]').append($('<option>').text('Aangepast: ' + config.selected[name]).attr('value', config.selected[name]).attr('selected', 'selected'));
											}
										}
									}
								}

								if($('select[name^="' + name + '"]').attr('multiple') === 'multiple')
								{
									$('select[name^="' + name + '"]').attr('size', $('select[name^="' + name + '"] option').length);
								}
							});
						}
						else if(name === 'ram' && /^(Aanpassen|Aangepast: [1-9]{1,4}(MB|GB|TB))$/i.test(text))
						{
							app.popupper('Wat is het aangepaste werkgeheugen?!',
								'<form id="popformer" novalidate="novalidate">' +
									'<div class="form-item">' +
										'<input type="text" name="_ram" placeholder="" pattern="' + app.pattern('storages') + '" required="required" />' +
										'<div class="item-hint">Bijvoorbeeld "512MB", "8GB" óf "32GB"</div>' +
									'</div>' +
								'</form>',
							'Aanpassen', function(result)
							{
								if(result)
								{
									//console.log('#1 ' + result._ram);
									$('select[name="ram"] option:selected').text('Aangepast: ' + result._ram).attr('value', result._ram).siblings().removeAttr('selected');
									//console.log('#2 ' + result._ram);
									$('select[name="ram"] option[value="' + result._ram + '"]').attr('selected', 'selected');
									//console.log('#3 ' + result._ram);
									return true;
								}
								return true;
							});
						}
						else if(name === 'storage' && /^(Aanpassen|Aangepast: [1-9]{1,4}(MB|GB|TB))$/i.test(text))
						{
							app.popupper('Wat is het aangepaste opslaggeheugen?!',
								'<form id="popformer" novalidate="novalidate">' +
									'<div class="form-item">' +
										'<input type="text" name="_storage" placeholder="" pattern="' + app.pattern('storages') + '" required="required" />' +
										'<div class="item-hint">Bijvoorbeeld "80GB", "512GB" óf "1TB"</div>' +
									'</div>' +
								'</form>',
							'Aanpassen', function(result)
							{
								if(result)
								{
									//console.log('#1 ' + result._ram);
									$('select[name="storage"] option:selected').text('Aangepast: ' + result._storage).attr('value', result._storage).siblings().removeAttr('selected');
									//console.log('#2 ' + result._ram);
									$('select[name="storage"] option[value="' + result._storage + '"]').attr('selected', 'selected');
									//console.log('#3 ' + result._ram);
									return true;
								}
								return true;
							});
						}
						/*
						else if(name === 'storage' && /^(Aanpassen|Aangepast: [1-9]{1,4}(MB|GB|TB))$/i.test(text))
						{
							app.popupper('Wat is het aangepaste opslaggeheugen?!',
								'<form id="popformer" novalidate="novalidate">' +
									'<div class="form-item">' +
										'<input type="text" name="_storage" placeholder="" pattern="' + app.pattern('storages') + '" required="required" /><br />' +
										'<div class="item-hint">"80GB", "512GB" óf "1TB"</div>' +
									'</div>' +
								'</form>',
							'Aanpassen', function(str)
							{
								if(str)
								{
									$('select[name="storage"] option').prop('selected', false);
									$('select[name="storage"] option:selected').text('Aangepast: ' + $('input[name="_storage"]').val()).attr('value', $('input[name="_storage"]').val());
									$('select[name="storage"] option[value="' + $('input[name="_storage"]').val() + '"]').attr('selected', 'selected');
								}
							});
						}
						*/
						else if(name.match('^ihours_') && name.match('_1$') || name.match('^time_') && name.match('_starts$'))
						{
							name = (name.match('^ihours_') ? name.replace('_1', '_2') : name.replace('_starts', '_ending'));
							if(value === '')
							{
								$('select[name="' + name + '"]').val('');
							}
							else
							{
								time = value.split(':');
								if(time[0] > '22')
								{
									time[0] = '23';
									time[1] = '59';
								}
								else
								{
									time[0] = (parseInt(time[0])+1);
								}
								$('select[name="' + name + '"]').val(app.str_pad(time[0], 2) + ':' + time[1]);
							}
						}
						else if(name === 'display_name')
						{
							if($('input[name="user_contact"]').val() === '')
							{
								$('input[name="user_contact"]').val(value);
							}
						}
						else if(name === 'duration')
						{
							if($(this).closest('tr').find('input[name="price"]').val() !== '')
							{
								if($(this).closest('tr').find('input[name="price"]').val() === '' || $('i', this).hasClass('fa-trash'))
								{
									$(this).removeClass('danger').addClass('success');
									$('i', this).removeClass('fa-trash').addClass('fa-pencil');
									$(this).closest('tr').find('input[name="price"]').val('');
									$(this).closest('tr').find('select[name="duration"] option[value="' + config.duration + '"]').attr('selected', 'selected');
								}
								else
								{
									$(this).removeClass('success').addClass('danger');
									$('i', this).removeClass('fa-pencil').addClass('fa-trash');
								}
								$(this).closest('tr').each(function()
								{
									var tr = $(this);
									if($('input[name="s"]').val())
									{
										var datest = '?repair=' + $(this).find('td.column-id').html() + '&device=' + $('input[name="s"]').val();
									}
									else
									{
										var datest = '?repair=' + config.id + '&device=' + $(this).find('td.column-id').text().replace('Meer details tonen', '');
									}
			/*
			(id.length ? id.html() : config.id)
			($(this).find('td.column-id') ? $(this).find('td.column-id').text() : $('input[name="search"]').val())
									var datest = '?repair=' + config.id + '&device=' + $(this).find('td.column-id').text().replace('Meer details tonen', '');
			*/
									tr.find('td input[type=text], select').each(function()
									{
										if($(this).attr('name') === 'price' && $(this).attr('value') === '')
										{
											/*
												Disabled: Reset select on empty price
												tr.find('td select[name="duration"]').val('');
											*/
										}
										datest += '&' + $(this).attr('name') + '=' + (typeof $(this).val() == 'undefined' ? (typeof $(this).attr('value') == 'undefined' ? '' : $(this).attr('value')) : $(this).val());
									});
									$.ajax({
										url : 'https://' + config.domain + '/wp-admin/admin-ajax.php' + datest,
										type : 'get',
										data : {
											action : 'assign'
										},
										dataType : 'json',
										success : function(response)
										{
											//console.log(response.status);
											//console.dir(response);
										}
									});
								});
							}
						}
						else if(!app.empty(value))
						{
							//$(this).css('border', '1px solid #4caf50');
							//app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
						}
					}
					return true;
					
				}).on('change', 'input', function(e)
				{
					var name = $(this).attr('name'), value = $(this).attr('value');
					if(app.in_array(name, ['price']))
					{
						//console.log('change input[name="xprice"]');
						var price = $(this).val();
						if(price !== '')
						{
							var price = parseFloat(price.replace(',', '.'));
							if(price !== $(this).val())
							{
								$(this).val(price.toFixed(2)).trigger('blur');
								$(this).css('border', '1px solid #4caf50');
								app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
							}
						}
					}
					else if(app.in_array(name, ['discount']))
					{
						//console.log('change paste input[name="discount"]');
						var discount = $(this).val(), price = $(this).closest('tr').find('input[name="price"]').val(), recalc = (app.in_array(name, ['reparatie']) ? true : false);
						if(app.empty(price))
						{
							if(discount !== '')
							{
								discount = discount.replace(',', '.');
								if(discount.substr(-1) !== '%')
								{
									discount = parseFloat(recalc ? (discount.substr(-1) !== '-' ? '-' + discount : discount) : discount);
									$(this).val(discount.toFixed(2)).trigger('blur');
								}
								$(this).css('border', '1px solid #4caf50');
								app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
							}
						}
						else
						{
							if(price !== '')
							{
								if(discount !== '' && discount !== $(this).val())
								{
									//console.log('Succeed');
									$(this).val(discount.toFixed(2)).trigger('blur');
									$(this).css('border', '1px solid #4caf50');
									app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
								}
								else
								{
									//console.log('Ignored1');
								}
							}
							else
							{
								//console.log('Ignored2');
								$(this).val('');
								$(this).css('border', '1px solid #f44336');
								app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
							}
						}
					}
					else if(app.in_array(name, ['iban']))
					{
						var iban = app.check('iban', value);
						if(!iban)
						{
							app.popupper('Ongeldige invoer', 'Het IBAN rekeningnummer is ongeldig!');
						}
						$(this).val(iban ? app.strtoupper(value) : '');
					}
					else if(name === 'nummer')
					{
						//console.log('change paste input[name="nummer"]');
						var value = $(this).val();
						if(/^[1-9]{4}/i.test(value))
						{
							$('img[class="preview"').error(function()
							{
								$(this).attr('src', 'https://' + config.domain + '/wp-content/themes/custom/devices/A0000.png');
							}).attr('src', 'https://' + config.domain + '/wp-content/themes/custom/devices/' + value.substr(0, 4) + '.png');
						}
						else if(/^A[1-9]{4}/i.test(value))
						{
							$('img[class="preview"').error(function()
							{
								$(this).attr('src', 'https://' + config.domain + '/wp-content/themes/custom/devices/A0000.png');
							}).attr('src', 'https://' + config.domain + '/wp-content/themes/custom/devices/' + value.substr(0, 5) + '.png');
						}
					}
					else if(app.in_array(name, ['user_vat', 'user_kvk']))
					{
						/*
							nl854688973b01 & 62150847
							nl852502667b01 & 57253684
						*/
						//console.log('change paste input[name="user_kvk"], input[name="user_vat"]');
						$('input[name="' + name + '"]').next('span[class="description"]').html('');
						var countries = {'België': 'BE', 'Duitsland': 'DE', 'Nederland': 'NL'}, country = countries[$('select[name="user_country"] option:selected').val()], type;
						if(name === 'user_vat')
						{
							value = app.strtoupper((app.is_numeric(value.substr(0, 2)) ? (typeof country != 'undefined' ? country : 'NL') + value : value)).substr(2), type = country;
						}
						else
						{
							type = 'KVK';
						}
						if(app.test(value, app.pattern(type)))
						{
							app.check(type, value).done(function(result)
							{
								//console.dir(result);
								if(result !== null && app.in_array(result['status'], ['valid', 'unsubscribed', 'unavailable']))
								{
									if(name === 'user_vat')
									{
										$('input[name="' + name + '"]').val(country + value);
									}
									if('company' in result)
									{
										$('input[name="user_company"]').val(result['company']);
										$('input[name="user_company"]').css('border', '1px solid #4caf50');
										app.timeout($('input[name="user_company"]'), 'border', '1px solid #b7b7b7', 5000);
									}
									if('address' in result)
									{
										if('postal' in result['address'])
										{
											$('input[name="user_postal"]').val(result['address']['postal']);
											$('input[name="user_postal"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="user_postal"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('number' in result['address'])
										{
											$('input[name="user_number"]').val(result['address']['number']);
											$('input[name="user_number"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="user_number"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('street' in result['address'])
										{
											$('input[name="user_street"]').val(result['address']['street']);
											$('input[name="user_street"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="user_street"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('city' in result['address'])
										{
											$('input[name="user_city"]').val(result['address']['city']);
											$('input[name="user_city"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="user_city"]'), 'border', '1px solid #b7b7b7', 5000);
										}
									}
									if(result['status'] === 'valid')
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #9bc90d;">Geverifieerd!</b>');
									}
									else if(result['status'] === 'unsubscribed')
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #f44336;">Uitgeschreven!</b>');
									}
									else
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #ed781e;">Verificatie niet beschikbaar, geldig formaat!</b>');
									}
									return true;
								}
								else
								{
									app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
									$('input[name="user_vat"]').val('');
									$('input[name="user_kvk"]').val('');
									$('input[name="user_company"]').val('');
									$('input[name="user_street"]').val('');
									$('input[name="user_number"]').val('');
									$('input[name="user_postal"]').val('');
									$('input[name="user_city"]').val('');
									return false;
								}
							});
						}
						else
						{
							app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
							$('input[name="user_vat"]').val('');
							$('input[name="user_kvk"]').val('');
							$('input[name="user_company"]').val('');
							$('input[name="user_street"]').val('');
							$('input[name="user_number"]').val('');
							$('input[name="user_postal"]').val('');
							$('input[name="user_city"]').val('');
							return false;
						}
					}
					else if(app.in_array(name, ['vat', 'kvk']))
					{
						/*
							nl854688973b01 & 62150847
							nl852502667b01 & 57253684
						*/
						//console.log('change paste input[name="kvk"], input[name="vat"]');
						$('input[name="' + name + '"]').next('span[class="description"]').html('');
						var countries = {'België': 'BE', 'Duitsland': 'DE', 'Nederland': 'NL'}, country = countries[$('select[name="country"] option:selected').val()], type;
						if(name === 'vat')
						{
							//value = app.strtoupper((app.is_numeric(value.substr(0, 2)) ? (typeof country != 'undefined' ? country : 'NL') + value : value)).substr(2), type = country;
							type = app.strtoupper(value.substr(0, 2)), value = app.strtoupper(value).substr(2);
						}
						else
						{
							type = 'KVK';
						}
						if(app.test(value, app.pattern(type)))
						{
							app.check(type, value).done(function(result)
							{
								//console.dir(result);
								if(result !== null && app.in_array(result['status'], ['valid', 'unsubscribed', 'unavailable']))
								{
									if(name === 'vat')
									{
										$('input[name="' + name + '"]').val(country + value);
									}
									if('company' in result)
									{
										$('input[name="company"]').val(result['company']);
										$('input[name="company"]').css('border', '1px solid #4caf50');
										app.timeout($('input[name="company"]'), 'border', '1px solid #b7b7b7', 5000);
									}
									if('address' in result)
									{
										if('postal' in result['address'])
										{
											$('input[name="postal"]').val(result['address']['postal']);
											$('input[name="postal"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="postal"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('number' in result['address'])
										{
											$('input[name="number"]').val(result['address']['number']);
											$('input[name="number"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="number"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('street' in result['address'])
										{
											$('input[name="street"]').val(result['address']['street']);
											$('input[name="street"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="street"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('city' in result['address'])
										{
											$('input[name="city"]').val(result['address']['city']);
											$('input[name="city"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="city"]'), 'border', '1px solid #b7b7b7', 5000);
										}
									}
									if(result['status'] === 'valid')
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #9bc90d;">Geverifieerd!</b>');
									}
									else if(result['status'] === 'unsubscribed')
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #f44336;">Uitgeschreven!</b>');
									}
									else
									{
										$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #ed781e;">Verificatie niet beschikbaar, geldig formaat!</b>');
									}
									return true;
								}
								else
								{
									app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
									if(name === 'vat')
									{
										app.timeout($('input[name="vat"]'), 'html', '', 5000);
										$('input[name="kvk"]').val('');
									}
									else
									{
										app.timeout($('input[name="kvk"]'), 'html', '', 5000);
										$('input[name="vat"]').val('');
									}
									$('input[name="company"]').val('');
									$('input[name="street"]').val('');
									$('input[name="number"]').val('');
									$('input[name="postal"]').val('');
									$('input[name="city"]').val('');
									return false;
								}
							});
						}
						else
						{
							app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
							if(name === 'vat')
							{
								app.timeout($('input[name="vat"]'), 'html', '', 5000);
								$('input[name="kvk"]').val('');
							}
							else
							{
								app.timeout($('input[name="kvk"]'), 'html', '', 5000);
								$('input[name="vat"]').val('');
							}
							$('input[name="company"]').val('');
							$('input[name="street"]').val('');
							$('input[name="number"]').val('');
							$('input[name="postal"]').val('');
							$('input[name="city"]').val('');
							return false;
						}
					}
				}).on('mouseover', 'a[data-img]', function(e)
				{
					//console.log('mouseover a[data-img]');
					var img = $('<img class="preview" />'), src = $(this).data('img');
					img.insertAfter($(this));
					img.error(function()
					{
						$(this).attr('src', 'https://' + config.domain + '/wp-content/themes/custom/devices/A1234.png');
					}).attr('src', src);
				}).on('mouseout', 'a[data-img]', function(e)
				{
					//console.log('mouseout a[data-img]');
					$(this).next('img[class="preview"]').remove();
				}).on('click', 'a[name="test"]', function(e)
				{
					//console.log('click a[name="test"]');
					e.preventDefault();
					$(this).closest('tr[name="insert"]').each(function()
					{
						var datest = '&insert=1';
						datest += '&s=' + $('input[type="search"][name="s"]').val();
						$(this).find('td input[type=text], input[type=email], input[type=password], select').each(function()
						{
							datest += '&' + $(this).attr('name') + '=' + this.value;
						})
						.closest('form').attr('action', $(location).attr('protocol') + '//' + $(location).attr('host') + $(location).attr('pathname') + '?page=ihours' +  datest)
						.closest('form').append('<input type="hidden" name="insert" value="true" />').submit();
					});
				});
				$('select[name="device"]').trigger('change');
			}
			if(config.admin === false || app.in_array(config.page, ['iaccessoires', 'iappointments', 'idevices', 'ihours', 'irepair', 'isettings', 'istore']))
			{
				$(document).on('focus', 'form', function()
				{
					//console.log('focus form');
					$(this).attr({
						'autocomplete': 'off',
						'autocapitalize': 'off',
						'autocorrect': 'off',
						'spellcheck': 'off'
					});
				}).on('focus', 'input[type=text], input[type=email], input[type=password], input[type="number"], select, textarea', function()
				{
					//console.log('focus input[type=text], input[type=email], input[type=password], select, textarea');
					var action = $(this).closest('form').attr('action'), name = $(this).attr('name'), postal, value = $(this).val(), type = $(this).attr('type');
					$(this).attr({
						'autocomplete': 'off',
						'autocapitalize': 'off',
						'autocorrect': 'off',
						'spellcheck': 'off'
					});
					$(this).css('border', '1px solid #ed781e');
					if(!$(this).is('select') && !$(this).is('textarea') && $(this).val() !== '' && !$(this).hasClass('defocus'))
					{
						config.value = $(this).val();
						//$(this).val('');
					}
					if(app.in_array(name, ['_number[]', '_title[]', '_price[]']))
					{
						$(this).select();
					}
					clearTimeout(config.timeouts[name]);
				}).on('blur', 'input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea', function(e)
				{
					//console.log('blur input[type=text], input[type=email], input[type=password], select, textarea');
					// Todo: needed?
					//app.validate($(this));
					var action = $(this).closest('form').attr('action'), name = $(this).attr('name'), postal, value = $(this).val(), type = $(this).attr('type');
					if(name == '_awnsered')
					{
						app.captcha('validate');
					}
					else if(name == '_name')
					{
						if(app.role(['admin', 'administrator', 'developer']))
						{
							$('#_names').slideUp(200);
						}
					}
					else if(name == '_phone')
					{
						$('input[name="_phone"]').val(app.check('phone', value));
					}
					else if(name == '_number[]' || name == '_numbers[]')
					{
						var number = $(this).val(), title = $(this).next('input').val(), price = app.floated($(this).next('input').next('input').val()), prices = app.floated($(this).next('input').next('input').next('input').val()), subtotal = 0;
						if(!app.empty(price))
						{
							$(this).next('input').next('input').next('input').val('€ ' + app.fixed(number*price));
						}
						app.calculate('ioffers');
					}
					else if(name == '_title[]')
					{
						if(app.empty($(this).val()))
						{
							$(this).parent('div').remove();
						}
						else
						{
							$(this).val(app.ucfirst(value));
							if(app.stripos($(this).val(), 'korting'))
							{
								$(this).attr('disabled', 'disabled');
								$(this).prev('input').attr('disabled', 'disabled');
							}
							$(this).prev('input').val($(this).prev('input').val() == '' ? '1' : $(this).prev('input').val());
							if($(this).next('input').val() === '')
							{
								$(this).next('input').trigger('focus');
							}
						}
						app.calculate('ioffers');
					}
					else if(name == '_price[]')
					{
						var number = app.floated($(this).prev('input').prev('input').val()), title = $(this).prev('input'), price = $(this), prices = app.floated($(this).next('input').val());
						if(!app.empty(title.val()))
						{
							if(app.stripos(title.val(), 'Korting'))
							{
								if(price.val().substr(-1) !== '%')
								{
									title.val('Korting');
									pricer = app.floated(price.val().replace(',', '.'));
									$(this).val('€ -' + pricer);
									$(this).next('input').val('€ -' + app.fixed(number*pricer));
								}
								else
								{
									title.val(price.val() + ' Korting');
									$(this).val('€ 0.00');
									$(this).next('input').val('€ 0.00');
								}
							}
							else if(price.val().match(/^\d+((\.|,)\d+)?$/))
							{
								if(price.val().substr(-1) !== '%')
								{
									pricer = app.floated(price.val().replace(',', '.'));
									$(this).val('€ ' + pricer);
									$(this).next('input').val('€ ' + app.fixed(number*pricer));
								}
								else
								{
									$(this).val('').trigger('focus').select();
									return false;
								}
							}
							else if(price.val().match(/^\d+(x)(\-)?\d+((\.|,)\d+)?$/i))
							{
								prices = price.val().toLowerCase().split('x');
								pricer = app.floated(prices[1].replace(',', '.'));
								$(this).val('€ ' + pricer);
								$(this).prev('input').prev('input').val(prices[0]);
								$(this).next('input').val('€ ' + app.fixed(prices[0]*pricer));
							}
							else
							{
								$(this).val('').trigger('focus').select();
								return false;
							}
						}
						else
						{
							$(this).val('');
							$(this).next('input').val('');
							$(this).prev('input').trigger('focus');
						}
						app.calculate('ioffers');
					}
					if(value === '')
					{
						$(this).css('border', '1px solid #b7b7b7');
					}
				}).on('click', 'a[name="fullscreen"]', function(e)
				{
					$('div[class="wrapper"]').css({
						position: 'absolute',
						top: $(window).scrollTop(),
						left: 0,
						height: '100%',
						width: '100%'
					});
				}).on('click', 'a[name="itemert"]', function(e)
				{
					//console.log('click a[name="itemert"]');
					e.preventDefault();
					if($(this).data('title'))
					{
						var device = app.jsobjects(config.devices, 'nummer', $(this).data('device'));
						$('.listeresults').append('<a href="javascript:void(0);" id="" name="listert" data-price="' + $(this).data('price') + '">' + 
							'<div>' +
								'<span class="listert-title">' +
									'1x ' + $(this).data('title') +
								'</span>' +
								'<span class="listert-subtitle">' +
									//$(this).data('subtitle') +
									($(this).data('sort') !== 'aanbiedingen' ? (app.empty($(this).data('subtitle')) ? device['merk'] + ' ' + device['model'] : $(this).data('subtitle')) : (app.empty($(this).data('subtitle')) ? '&nbsp;' : $(this).data('subtitle'))) +
								'</span>' +
								'<span class="listert-price">' +
									'€ ' + app.fixed($(this).data('price'), 2).replace('.', ',') +
								'</span>' +
							'</div>' +
						'</a>');
						$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))+parseFloat($(this).data('price')), 2).replace('.', ','));
					}
					else
					{
						if(app.in_array($(this).data('merk'), ['iPhone', 'iPad', 'MacBook', 'iMac']))
						{
							var merk = $(this).data('merk'), device = (app.empty($(this).data('device')) ? '' : $(this).data('device')), sort = (app.empty($(this).data('sort')) ? '' : $(this).data('sort'));
							$.ajax({
								url: 'https://' + config.domain,
								data: {'merk': merk, 'device' : device, 'sort': sort},
								dataType: 'html',
								success: function(data)
								{
									$('.itemeresults').fadeOut('fast', function()
									{
										$(this).html(data).slideDown();
									});
								}
							});
						}
						else
						{
							$.ajax({
								url: 'https://' + config.domain,
								data: {'merk': 'overview'},
								dataType: 'html',
								success: function(data)
								{
									$('.itemeresults').fadeOut('fast', function()
									{
										$(this).html(data).slideDown();
									});
								}
							});
						}
					}
				}).on('mousedown', 'a[name="listert"]', function(e)
				{
					var that = $(this), price = parseFloat($(that).closest('a').data('price')), subtotal = parseFloat($(that).closest('a').find('span.listert-price').html().substr(2).replace(',', '.')), title = $(that).find('span.listert-title').html();
					e.preventDefault();
					/*
					switch(e.which)
					{
						case 3:
							if(parseInt(title.split('x ')[0]) > 1)
							{
								$(that).find('.listert-title').html(parseFloat(title.split('x ')[0])-1 + 'x ' + title.split('x ')[1]);
								$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal+(subtotal-price), 2).replace('.', ','));
							}
							else
							{
								$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal, 2).replace('.', ','));
								$(that).fadeOut('fast', function()
								{
									setTimeout(function()
									{
										$(that).remove();
									}, 500);
								});
							}
							break;
						default:
							$(that).find('.listert-title').html(parseInt(title.split('x ')[0])+1 + 'x ' + title.split('x ')[1]);
							$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal+(subtotal+price), 2).replace('.', ','));
							break;
					}
					*/
				}).on('contextmenu', '.listerts', function(e)
				{
					return false;
				}).on('click', 'a[name="listeresults"]', function(e)
				{
					//console.log('click a[name="listeresults"]');
					e.preventDefault();
					app.popupper('Artikel toevoegen?!',
						'<form id="popformer" novalidate="novalidate">' +
							'<div class="form-item">' +
								'<label for="_title">Titel:</label>' +
								'<input type="text" name="_title" placeholder="" pattern="' + app.pattern('plain') + '" required="required" /><br />' +
								'<div class="item-hint">&nbsp;</div>' +
							'</div>' +
							'<div class="form-item">' +
								'<label for="_title">Subtitel:</label>' +
								'<input type="text" name="_subtitle" placeholder="" pattern="' + app.pattern('plain') + '" /><br />' +
								'<div class="item-hint">&nbsp;</div>' +
							'</div>' +
							'<div class="form-item">' +
								'<label for="_title">Prijs:</label>' +
								'<input type="text" name="_price" placeholder="" pattern="' + app.pattern('decimal') + '" required="required" /><br />' +
								'<div class="item-hint">&nbsp;</div>' +
							'</div>' +
						'</form>',
					'Toevoegen', function(result)
					{
						if(result)
						{
							$('.listeresults').append('<a href="javascript:void(0);" id="" name="listert" data-price="' + parseFloat(result._price) + '">' + 
								'<div>' +
									'<span class="listert-title">' +
										'1x ' + result._title +
									'</span>' +
									'<span class="listert-subtitle">' +
										(app.empty(result._subtitle) ? '&nbsp;' : result._subtitle) +
									'</span>' +
									'<span class="listert-price">' +
										'€ ' + app.fixed(parseFloat(result._price), 2).replace('.', ',') +
									'</span>' +
								'</div>' +
							'</a>');
							$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))+parseFloat(result._price), 2).replace('.', ','));
						}
					});
				}).on('click', 'a[name="appointlock"]', function(e)
				{
					//console.log('click a[name="appointlock"]');
					e.preventDefault();
					var datest = '?source=iappointments', icon = $(this).find('i');
					$.each($(this).closest('td').data(), function(k, v)
					{
						datest += '&' + k + '=' + v;
					});
					//console.dir(datest);
					$.ajax({
						url : 'https://' + config.domain + '/wp-admin/admin-ajax.php' + datest,
						type : 'GET',
						data : {
							action: 'iclients'
						},
						dataType : 'json',
						success : function(response)
						{
							//console.dir(response);
							location.reload();
						}
					});
				}).on('click', 'a[name="appointmanage"]', function(e)
				{
					//console.log('click a[name="appointment"]');
					e.preventDefault();
					app.popformer('iappointments', 'update', $(this).data());

				}).on('click', 'a[name="undoloader"]', function(e)
				{
					$(this).remove();
				}).on('click', 'a[name="uploader"]', function(e)
				{
					//console.log('click a[name="appointment"]');
					e.preventDefault();
					var file_frame, wp_media_post_id = wp.media.model.settings.post.id;

					file_frame = wp.media.frames.file_frame = wp.media({
						title: 'Accessoire..', button: { text: 'Gebruik afbeelding', }, multiple: false
					});
					file_frame.on('select', function()
					{
						attachment = file_frame.state().get('selection').first().toJSON();
						//console.log(attachment.url);
						$('.images').append('<a href="javascript:void(0);" name="undoloader">' +
							'<img src="' + attachment.url + '" width="100" height="100" style="float: left; margin-right: 25px; border: 1px solid #ed781e;" />' +
							'<input type="hidden" name="photos[]" value="' + attachment.url + '">' +
						'</a>');
					}).on('close',function()
					{
						$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', { action: 'reset_upload_dir' }, function(response)
						{
							//console.dir(response);
						});
					});
					file_frame.open();
				}).on('click', 'a[name="ioffers"]', function(e)
				{
					//console.log('click a[name="ioffers"]');
					e.preventDefault();
					app.popupper('<i class="fa fa-calculator fa-fw"></i> Offerte', 'Het aanvragen is vernieuwd, in 3 eenvoudige stappen!<br><br>' +
					'<ol>' +
						'<li>Kies je ' + app.applify(config.domain.replace('repair.nu', '')) + '.</li>' +
						'<li>Selecteer reparatie(s).</li>' +
						'<li>Klik op aanvragen.</li>' +
					'</ol>' +
					'<small class="muted">Alleen volledig ingevulde aanvragen worden geaccepteerd!</small>', 'Doorgaan', function(result)
					{
						if(result)
						{
							$(location).attr('href', 'https://' + config.domain + '/reparaties/');
						}
					});
				}).on('click', 'a[name="ilovers"]', function(e)
				{
					//console.log('click a[name="ilovers"]');
					e.preventDefault();
					$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
						'action': 'ilovers'
					}, function(data)
					{
						//console.dir(data);
						if(data.status == 'success')
						{
							$('a[name="ilovers"]').find('span[class="fa fa-stack"]').html(function(i, v){
								//console.log(i + ' : ' + v);
								return (parseInt(v)+1)
							});
						}
						else
						{
							app.popupper('Helaas..', 'Super fijn dat je ons zo\'n warm <i class="fa fa-heart fa-3x fa-fw" style="color: #ed781e; text-shadow: 0 3px 10px rgba(0, 0, 0, 0.23), 0 3px 10px rgba(0, 0, 0, 0.16);"></i> toedraagt.. ..echter wordt het slechts één keer meegeteld!');
						}
					});
				}).on('click', 'a[name="ivote"]', function(e)
				{
					//console.log('click a[name="ivote"]');
					e.preventDefault();
					app.popupper('<i class="fa fa-question fa-rotate-180"></i><i class="fa fa-question"></i> Helaas..', 'Er kan momenteel geen stem uitgebracht worden, probeer het later nog eens..');
				}).on('click', 'a[name="ipoll"]', function(e)
				{
					//console.log('click a[name="ipoll"]');
					e.preventDefault();
					$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
						'action': 'ipoll'
					}, function(data)
					{
						//console.dir(data);
						if(app.in_array(data.status, ['success', 'succeed']))
						{
							app.popupper('<i class="fa fa-question fa-rotate-180"></i><i class="fa fa-question"></i> ' + data.question, data.answers, data.button, function(result)
							{
								if(result)
								{
									if(result._status != 'succeed')
									{
										$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
											'action': 'ipoll',
											'answer': result._answer
										}, function(data)
										{
											//console.dir(data);
											if(data.status == 'succeed')
											{
												app.popupper('<i class="fa fa-question fa-rotate-180"></i><i class="fa fa-question"></i> Bedankt!', data.answers, data.button);
											}
											else
											{
												app.popupper('<i class="fa fa-question fa-rotate-180"></i><i class="fa fa-question"></i> Helaas..', 'Er kan tijdelijk geen stem uitgebracht worden, probeer het later nog eens..', data.button);
											}
										});
									}
								}
							});
						}
						else
						{
							app.popupper('<i class="fa fa-question fa-rotate-180"></i><i class="fa fa-question"></i> Helaas..', 'Er kan momenteel geen stem uitgebracht worden, probeer het later nog eens..');
						}
					});
				}).on('click', 'a[name="isubscribers"]', function(e)
				{
					//console.log('click a[name="isubscribers"]');
					e.preventDefault();
					app.popformer('isubscribers', 'insert', $(this).data());
				}).on('click', 'a[name="isubscribmove"]', function(e)
				{
					//console.log('click a[name="isubscribmove"]');
					e.preventDefault();
					app.popformer('isubscribers', 'delete', $(this).data());
				}).on('click', 'a[name="appointmenfo"]', function(e)
				{
					//console.log('click a[name="appointmenfo"]');
					e.preventDefault();
					app.popformer('iappointments', 'view', $(this).data());
				}).on('click', 'a[name="appointmove"]', function(e)
				{
					//console.log('click a[name="appointmove"]');
					e.preventDefault();
					app.popformer('iappointments', 'delete', $(this).data());
				}).on('click', 'a[name="serial"]', function(e)
				{
					//console.log('click a[name="serial"]');
					e.preventDefault();
					app.popformer('iserial', 'check', false);
				}).on('click', 'a[name="appointmeriods"]', function(e)
				{
					//console.log('click a[name="appointmeriods"]');
					e.preventDefault();
					app.popformer('iappointments', 'periods', $(this).data());
				}).on('mouseover', 'i[class="fa fa-square fa-lg fa-fw"], i[class="fa fa-square-o fa-lg fa-fw"]', function(e)
				{
					that = $(this), img = $('img[data-device]');
					devices = ['A2651', 'A2650', 'A2649', 'A2632'];
					if(devices.indexOf(img.data('device')) < 0)
					{
						$('a[name="catalogus"]').data('color', that.attr('title').toLowerCase());
						img.attr('src', 'https://irepair.nu/wp-content/themes/custom/devices/' + img.data('device') + '-' + that.attr('title').toLowerCase() + '.png');						
					}
				}).on('click', 'a[class="icogus"]', function(e)
				{
					console.log('click a[class="icogus"]');
					e.preventDefault();
					that = $(this), target = $('input[name="' + (app.in_array(prevFocus.attr('name'), ['_inscriptie1', '_inscriptie2']) ? '_inscriptie2' : '_inscriptie1') + '"]');
					target.trigger('focus');
					target.val(target.val() + that.data('icon'));
				}).on('click', 'a[name="imgus"]', function(e)
				{
					console.log('click a[name="imgus"]');
					e.preventDefault();
					$('a[name="catalogus"]').first().trigger('click');

				}).on('click', 'a[name="catalogus"]', function(e)
				{
					console.log('click a[name="catalogus"]');
					e.preventDefault();
					app.popformer('icatalogus', 'insert', $(this).data());
				}).on('click', 'a[name="appointment"]', function(e)
				{
					//console.log('click a[name="appointment"]');
					e.preventDefault();
					app.report('<b>Testmelding:</b>', 'Via ' + decodeURIComponent(document.referrer) + ' heeft '  + config.ipaddress + ' de agenda geopend!');
					app.popformer('iappointments', 'insert', $(this).data());
				}).on('click', 'a[name="cookiert"]', function(e)
				{
					//console.log('click a[name="cookiert"]');
					e.preventDefault();
					if(app.cookie('cookies', 'enabled', '+1 year'))
					{
						location.reload();
					}
				}).on('click', 'a[name="deal"]', function(e)
				{
					//console.log('click a[name="cookielp"]');
					e.preventDefault();
					if(config.deals != '')
					{
						html = '';
						$.each(config.deals, function(i, value)
						{
							html += '<i class="fa fa-gift fa-lg"></i> ' + value + '<br>';
						});
						app.popupper('<i class="fa fa-gift fa-fw"></i> ' + config.deal, '<center><img src="https://irepair.nu/wp-content/uploads/custom/deals.jpg" onerror="this.src=\'https://irepair.nu/wp-content/uploads/custom/deals_fallback.jpg\'" width="384" height="165" style="max-width: 40% !important; max-height: 30% !important;"><br>' + html + '</center>', 'Reparaties', function(result)
						{
							if(result)
							{
								$(location).attr('href', 'https://' + $(location).attr('hostname') + '/reparaties/');
							}
						});
					}
					else
					{
						$(location).attr('href', 'https://' + $(location).attr('hostname') + '/aanbiedingen/');
					}
					//app.report('<b>Melding:</b> ' + config.deal + ' Deals', 'Door '  + config.ipaddress + ' zijn de Black Friday deals bekeken!');
				}).on('click', 'a[name="cookielp"]', function(e)
				{
					//console.log('click a[name="cookielp"]');
					e.preventDefault();
					app.popupper('<i class="fa fa-question fa-fw"></i> Cookies', 'Wij serveren alleen virtuele cookies voor de <b>functionele werking</b> van deze website óf echte koekjes voor bij de koffie!', 'Akkoord', function(result)
					{
						if(result)
						{
							//app.report('<b>Melding:</b> Cookiebeleid', 'Door '  + config.ipaddress + ' is het cookiebeleid geaccodeerd!');
							if(app.cookies('cookies', 'enabled', '+1 year'))
							{
								location.reload();
							}
							/*
							app.cookies('cookies', 'enabled', '+1 year');
							setTimeout(function()
							{
								location.reload();
							}, 1000);
							*/
						}
					});
				}).on('click', 'button[name="trackandtracert"]', function(e)
				{
					//console.log('click a[name="trackandtracert"]');
					e.preventDefault();

					tracking = ($('input[name="tracking"]').val().replace(/^\s+|\s+$/gm,'') || false);
					trackert = ($('input[name="trackert"]').val().replace(/^\s+|\s+$/gm,'') || false);
					if(tracking && trackert)
					{
						url = 'https://jouw.postnl.nl/track-and-trace/' + (tracking + '-NL-' + trackert).toUpperCase();
						app.report('<b>Melding:</b> Track en Trace', 'Door '  + config.ipaddress + ' is voor ' + tracking + ' met ' + trackert + ' de tracking gebruikt, zie hier: ' + url);
						window.open(url, '_blank');
					}
				}).on('click', 'a[name="cookielq"]', function(e)
				{
					//console.log('click a[name="cookielq"]');
					e.preventDefault();
					app.popupper('<i class="fa fa-question fa-fw"></i> Cookies', 'Je hebt toestemming gegeven om cookies voor de <b>functionele werking</b> te mogen plaatsen!', 'Intrekken', function(result)
					{
						if(result)
						{
							if(app.cookies('cookies', false))
							{
								location.reload();
							}
							/*
							app.cookies('cookies', false);
							setTimeout(function()
							{
								location.reload();
							}, 500);
							*/
						}
					});
				}).on('click', 'a[name="darkmode"]', function(e)
				{
					var darkmode = app.cookie('darkmode');
					if(darkmode === 'on')
					{
						app.report('<b>Melding:</b>', 'Door '  + config.ipaddress + ' is darkmodus handmatig uitgeschakeld!');
						app.cookie('darkmode', 'off', '365');
					}
					else
					{
						app.report('<b>Melding:</b>', 'Door '  + config.ipaddress + ' is darkmodus handmatig ingeschakeld!');
						app.cookie('darkmode', 'on', '365');
					}
					location.reload();
				}).on('click', 'a[name="safety"]', function(e)
				{
					//console.log('click a[name="safety"]');
					e.preventDefault();
					//$('#popupper').dialog('destroy').remove();
					app.report('<b>Melding:</b> Privacybeleid', 'Door '  + config.ipaddress + ' is het privacybeleid gelezen!');
					app.popupper('<i class="fa fa-exclamation fa-fw"></i> Veiligheid', '' +
						'Wij verzamelen alleen <b>noodzakelijke gegevens</b> om je als klant nog beter van dienst te kunnen zijn, nú en in de toekomst!<br /><br />' +
						'Je privacy beschermen en respecteren we door o.a. een veilige website, overzichtelijk <b><a href="https:///iphonerepair.nu/wp-content/uploads/custom/privacybeleid.pdf" target="_blank">privacybeleid</a></b> en je <b><a href="javascript:app.popformer(\'iprivacy\', \'verify\', false);">persoonsgegevens</a></b> volledig in eigen beheer..<br /><br />' +
						'Mocht je problemen op de website ondervinden, lees dan ons <b><a href="https:///iphonerepair.nu/wp-content/uploads/custom/rd.pdf" target="_blank">Responsible Disclosure</a></b> eens!<br /><br />' +
					'');
					//Wij serveren alleen virtuele cookies voor de <b>functionele werking</b> van deze website óf echte koekjes voor bij de koffie!<br /><br />Er worden geen <b>persoonsgegevens</b> opgeslagen zonder hiervoor vooraf toestemming gevraagd te hebben.
				}).on('click', 'a[name="iprivacielete"]', function(e)
				{
					//console.log('click a[name="iprivacielete"]');
					e.preventDefault();
					//$('#popupper').dialog('destroy').remove();
					//app.report('<b>Melding:</b> Privacybeleid', 'Door '  + config.ipaddress + ' is het privacybeleid gelezen!');
					app.popformer('iprivacy', 'delete', $(this).data());
					//Wij serveren alleen virtuele cookies voor de <b>functionele werking</b> van deze website óf echte koekjes voor bij de koffie!<br /><br />Er worden geen <b>persoonsgegevens</b> opgeslagen zonder hiervoor vooraf toestemming gevraagd te hebben.
				}).on('click', 'a[name="reviewer"]', function(e)
				{
					//console.log('click a[name="reviewer"]');
					e.preventDefault();
					app.popformer('ireviews', 'insert', $(this).data());
				}).on('click', 'a[name="repairs"]', function(e)
				{
					//console.log('click a[name="repairs"]');
					e.preventDefault();
					app.popformer('irepairs', 'insert', $(this).data());
				}).on('click', 'a[name="receipt"]', function(e)
				{
					//console.log('click a[name="repairs"]');
					e.preventDefault();
					app.popformer('ireceipt', 'insert', $(this).data());
				}).on('click', '.button.submit, input[type="submit"]:not(#doaction)', function(e)
				{
					//console.log('click .button.submit, input[type="submit"]:not(#doaction)');
					e.preventDefault();
					if($(this).val() === '' && $(this).hasData('data-sending-label').length)
					{
						$(this).attr('value', $(this).data('data-sending-label'));
					}
					$(e.target).closest('form').submit();
					if(app.validate($(this)))
					{
						return true;
						$(e.target).closest('form').submit(function(e)
						{
							//console.log('submitter!');
							return true;//$(e.target).closest('form').trigger('submit');
							//e.preventDefault();
						});				
					}
				}).on('click', 'video', function()
				{
					if(this.paused)
					{
						app.report('<b>Melding:</b> Commercial', 'Door '  + config.ipaddress + ' is de commercial gestart!');
						this.play();
					}
					else
					{
						this.pause();	
					}
				}).on('click', 'a[name="login"]', function(e)
				{
					//console.log('click a[name="login"]');
					e.preventDefault();
					//console.dir(login);
					app.popupper('Inloggen',
						'<form id="popformer" novalidate="novalidate">' +
							'<small class="centered muted">' + config.ipaddress + '</small>' +
							'<div class="form-item">' +
								'<input type="email" name="_user" placeholder="mail@domein.nl" required="required" />' +
								'<div class="item-hint"></div>' +
							'</div>' +
							'<div class="form-item">' +
								'<input type="password" name="_pass" placeholder="Wachtwoord" required="required" />' +
								'<div class="item-hint">Wachtwoord vergeten? Klik <a href="#">hier</a>!</div>' +
							'</div>' +
						'</form>',
					'Controleren', function(result)
					{
						if(result)
						{
							/*
							$.getJSON(login.url, {
								'action': 'ajaxlogin',
								'user': result._user, 
								'pass': result._pass,
							}, function(data)
							{
								//console.dir(data);
								if(data.loggedin == true)
								{
									location.href = login.redirect;
								}
							});
							*/
							///*
							$.ajax({
								type: 'GET',
								cache: false,
								crossDomain: true,
								crossOrigin: true,
								dataType: 'json',
								jsonpCallback: 'tester',
								url: login.url,
								data: { 
									action: 'ajaxlogin',
									user: result._user, 
									pass: result._pass,
								},
								success: function(data, text)
								{
									//console.dir(data);
									if(data.loggedin == true)
									{
										app.cookie('test', 'jala', 2);
										$('#popupper').dialog('destroy').remove();
										//$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
										//location.href = login.redirect;
									}
								}
							});
							//*/
							return true;
						}
						return false;
					}, false);

				}).on('click', 'a[name="copyright"]', function(e)
				{
					//console.log('click a[name="copyright"]');
					e.preventDefault();
					app.report('<b>Melding:</b> Rechtenbeleid', 'Door '  + config.ipaddress + ' is het rechtenbeleid bestudeerd!');
					app.popupper('<i class="fa fa-info fa-fw"></i> Rechten', 
						'<span class="pull-right">' + config.days[config.date.getDay()] + ' ' + config.date.getDate() + ' ' + config.months[config.date.getMonth()] + ' ' + config.date.getFullYear() + ', Thorn</span><br /><br />' + 
						'Het domein ' + config.merk.replace('repair', '<span style="color:#ed781e; font-weight: bold;">Repair</span>') + '.nu is onderdeel van i<span style="color:#ed781e; font-weight: bold;">Repair</span> en geen eigendom van Apple.<br /><br />' +
						'Door het gebruik van een door i<span style="color:#ed781e; font-weight: bold;">Repair</span> gefaciliteerde website ga je akkoord met onze <a href="https://iphonerepair.nu/algemene-voorwaarden/" target="_blank">algemene voorwaarden</a> en het <a href="https:///iphonerepair.nu/wp-content/uploads/2018/05/25/privacybeleid.pdf" target="_blank">privacybeleid</a>! Zónder voorafgaande toestemming mag gerelateerde inhoud nooit worden gedeeld, gekopieerd, gewijzigd óf op enig andere wijze geëxploiteerd.<br /><br /><br />' + 
						'i<span style="color:#ed781e; font-weight: bold;">Repair</span> respecteert het auteursrecht, merkenrecht, portretrecht of privacyrecht van derden en heeft haar uiterste best gedaan om van alle betrokkenen toestemming te krijgen alvorens hetgeen is gepubliceerd. Mocht het onverhoopt zo zijn dat er materiaal wordt gepubliceerd waarvoor je geen toestemming hebt gegeven, neem dan zo spoedig mogelijk <a href="https://' + config.domain + '/">contact</a> met i<span style="color:#ed781e; font-weight: bold;">Repair</span> op!<br /><br />' +
						'<small>Derden verwijst naar elke persoon, entiteit óf bedrijf dat niet geassocieerd is met i<span style="color:#ed781e; font-weight: bold;">Repair</span>.</small>'
					);
				}).on('click', 'a[name="route"]', function(e)
				{
					//console.log('click a[name="route"]');
					e.preventDefault();
					var device = app.jsobjects(config.devices, 'nummer', config.device);
					//app.report('<b>Melding:</b> Routebeschrijving ' + device.merk + ' ' + device.model, 'Door ' + config.ipaddress + ' is de route knop gebruikt!');
					window.open('https://www.google.nl/maps/place/iPhoneRepair.nu/@51.163723,5.8359393,17z/data=!3m1!4b1!4m5!3m4!1s0x47c0cb014bcd5c49:0xf5377dee6cdf7d59!8m2!3d51.163723!4d5.838128', '_blank');
				}).on('click', 'a[name="afspraak"]', function(e)
				{
					//console.log('click a[name="afspraak"]');
					e.preventDefault();
					var device = app.jsobjects(config.devices, 'nummer', config.device);
					var titles = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="title"]').val();
					}).toArray();
					var prices = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="price"]').val();
					}).toArray();
					repairs = $.map(titles, function (e, i)
					{
						return [[e, prices[i]]];
					});
					var list = '', subtotal = 0;
					$.each(repairs, function(i, value)
					{
						list += '%20%20' + value[0] + '%0A';
					});
					//app.report('<b>Melding:</b> Afspraak ' + device.merk + ' ' + device.model, 'Door '  + config.ipaddress + ' is de afspraken knop gebruikt!');
					$(location).attr('href', 'https://' + $(location).attr('hostname') + '/afspraak/?device=' + device.nummer + '&repair=Geselecteerde reparaties:%0A' + list + '%0A');
				}).on('click', 'a[name="offerte"]', function(e)
				{
					//console.log('click a[name="offerte"]');
					e.preventDefault();
					var device = app.jsobjects(config.devices, 'nummer', config.device);
					var titles = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="title"]').val();
					}).toArray();
					var prices = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="price"]').val();
					}).toArray();
					repairs = $.map(titles, function (e, i)
					{
						return [[e, prices[i]]];
					});
					var list = '', subtotal = 0;
					$.each(repairs, function(i, value)
					{
						list += '%20%20' + value[0] + '%0A';
					});
					//app.report('<b>Melding:</b> Offerte ' + device.merk + ' ' + device.model, 'Door '  + config.ipaddress + ' is de offerte knop gebruikt!');
					$(location).attr('href', 'https://' + $(location).attr('hostname') + '/offerte/?device=' + device.merk + ' ' + device.model + '&repair=Geselecteerde reparaties:%0A' + list + '%0A');
					/*
						var list = '<ul class="repairs">', subtotal = 0;
						//list = '%20%20' + titles.join('%0A%20%20');
						$.each(repairs, function(i, value)
						{
							list += '<li>' + value[0] + '<span style="float: right;">€ ' + value[1] + '</span></li>';
							subtotal += parseInt(value[1]);
						});
						list += '</ul>';
						app.popupper('Offerte op maat', '<b>' + device.merk + ' ' + device.model + '</b><br />' + list + '<span style="float: right; font-weight: bold; color: #ed781e;">€ ' + subtotal.toFixed(2) + '</span>', 'Aanvragen');
					*/
				}).on('click', 'a[name="offertes"]', function(e)
				{
					//console.log('click a[name="offerte"]');
					e.preventDefault();
					var device = app.jsobjects(config.devices, 'nummer', config.device);
					//console.dir(device);
					var numbers = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="number"]').val();
					}).toArray();
					var titles = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="title"]').val().replace(' *', '');
					}).toArray();
					var prices = $(this).closest('form').find('li:has(input:checked)').map(function()
					{
						return $(this).find('input[name="price"]').val();
					}).toArray();
					rules = $.map(titles, function (e, i)
					{
						return [[numbers[i], e, prices[i]]];
					});
					/*
					var list = '', subtotal = 0;
					$.each(rules, function(i, value)
					{
						list += '%20%20' + value[0] + '%0A';
					});
					$(location).attr('href', 'https://' + $(location).attr('hostname') + '/offerte/?device=' + device.merk + ' ' + device.model + '&repair=Geselecteerde reparaties:%0A' + list + '%0A');
					*/
					//var list = '<ul class="rules">', subtotal = 0;
					//list = '%20%20' + titles.join('%0A%20%20');
					/*
					$.each(rules, function(i, value)
					{
						list += '<li>' + value[0] + '<span style="float: right;">€ ' + value[1] + '</span></li>';
						subtotal += parseInt(value[1]);
					});
					list += '</ul>';
					app.popupper('Offerte op maat', '<b>' + device.merk + ' ' + device.model + '</b><br />' + list + '<span style="float: right; font-weight: bold; color: #ed781e;">€ ' + subtotal.toFixed(2) + '</span>', 'Aanvragen');
					*/
					app.popformer('ioffers', 'confirm', {'device': device.nummer, 'rules': rules});
					var datas = $(this).data();
					setTimeout(function()
					{
						$.each(datas, function(i, v)
						{
							if($('input[name="_' + i + '"]').length)
							{
								$('input[name="_' + i + '"]').val(v);
							}
						});
						if($('input[name="_cid"]').val() !== '0')
						{
							$('div[class="form-item"] input[name="_title[]"]').first().trigger('focus');
							$('#popformer select[name="_device"] option[value="' + device.nummer + '"]').attr('selected', 'selected');
						}
					}, 100);
				}).on('click', 'a[name="remove"]', function(e)
				{
					//console.log('click a[name="remove"]');
					e.preventDefault();
					$(this).parent().remove();
				}).on('click', '#form-items div[class="form-item"]', function(e)
				{
					//console.log('click #form-items div[class="form-item"]');
					e.preventDefault();
					/*
						selected = $(this).index();
						//console.log('Selected: ' + selected);
					*/
				}).on('click', 'a[name="form-downs"]', function(e)
				{
					//console.log('click a[name="form-downs"]');
					e.preventDefault();
					var parent = $(this).parents('div[class="form-item"]'), parents = $(this).parent().nextAll('div[class="form-item"]');
					if(parents.length > 1)
					{
						parent.insertAfter(parent.next());
					}
				}).on('click', 'a[name="pdf"]', function(e)
				{
					//console.log('click a[name="test"]');
					e.preventDefault();
					$(this).closest('tr[name="insert"]').each(function()
					{
						var datest = '&insert=1';
						datest += '&s=' + $('input[type="search"][name="s"]').val();
						$(this).find('td input[type=text], input[type=email], input[type=password], select').each(function()
						{
							datest += '&' + $(this).attr('name') + '=' + this.value;
						})
						.closest('form').attr('action', $(location).attr('protocol') + '//' + $(location).attr('host') + $(location).attr('pathname') + '?page=ihours' +  datest)
						.closest('form').append('<input type="hidden" name="insert" value="true" />').submit();
					});
				}).on('click', 'label[class="switch"]', function(e)
				{
					//console.log('click label[class="switch"]');
					e.preventDefault();
					var checked = $(this).find('input');
					if(checked.is(':checked'))
					{
						checked.removeAttr('checked').trigger('change');
					}
					else
					{
						checked.attr('checked', 'checked').trigger('change');
					}
				}).on('click', 'a[class="repairs"]', function(e)
				{
					//console.log('click a[class="repairs"]');
					e.preventDefault();
					var check = $(this).prev().closest('h5').find('input[type=checkbox]');
					if(!check.is(':disabled'))
					{
						if(check.is(':checked'))
						{
							check.removeAttr('checked').trigger('change');
						}
						else
						{
							check.attr('checked', 'checked').trigger('change');
						}
					}
				}).on('click', 'li[name="autofiller"]', function(e)
				{
					//console.log('li[name="autofiller"]');
					e.preventDefault();
					var form = $(this).closest('form');

					$('input[name="_id"]').val('0');
					$('input[name="_cid"]').val('0');
					$('input[name="_discount"]').val('0');
					$('input[type=text], input[type=email], input[type=password]').not('.defocus').each(function(i, v)
					{
						//if($(this).attr('name') !== '_name')
						//{
							$(this).val('');
						//}
					});
					var datas = $(this).data();
					//console.dir(datas);
					$.each(datas, function(i, v)
					{
						if($('input[name="_' + i + '"]').length)
						{
							$('input[name="_' + i + '"]').val(v);
							if(v !== '')
							{
								//$('input[name="_' + i + '"]').attr('readonly', 'readonly');
							}
						}
					});
					if(form.attr('name') === 'ioffers')
					{
						app.reorder('ioffers');
						///*
						if($('input[name="_discount"]').val() !== '0')
						{
							var discounter = form.find('#form-items .form-item').last();
							if(discounter.find('input[name="_title[]"]').val() === 'Korting' && discounter.find('input[name="_price[]"]').val() !== '')
							{
								if($('input[name="_discount"]').val().substr(-1) === '%')
								{
									discounter.find('input[name="_title[]"]').val($('input[name="_discount"]').val() + ' korting');
									discounter.find('input[name="_price[]"]').val($('input[name="_discount"]').val());
									discounter.find('input[name="_price[]"]').trigger('blur');
								}
								else
								{
									discounter.find('input[name="_price[]"]').val($('input[name="_discount"]').val());
									discounter.find('input[name="_price[]"]').trigger('blur');
								}
							}
						}
						//*/
					}
				}).on('click', '#slider a.prev', function(e)
				{
					e.preventDefault();
					app.slider('stop').slider('left');
				}).on('click', '#slider a.next', function(e)
				{
					e.preventDefault();
					app.slider('stop').slider('right');
				}).on('mousedown', 'a[name="listert"]', function(e)
				{
					app.startime = new Date().getTime();
					return true;
				}).on('mousedown', '.button.submit, input[type="submit"]', function(e)
				{
					
					//console.log('mousedown .button.submit, input[type="submit"]');
					if($(this).val() === '' && $(this).hasData('data-sending-label'))
					{
						$(this).val($(this).data('data-sending-label'));
					}
				}).on('mouseleave', 'a[name="listert"]', function(e)
				{
					app.startime = 0;
					return true;
				}).on('mouseup', 'a[name="listert"]', function(e)
				{
					var that = $(this), price = parseFloat($(that).closest('a').data('price')), subtotal = parseFloat($(that).closest('a').find('span.listert-price').html().substr(2).replace(',', '.')), title = $(that).find('span.listert-title').html();
					if(new Date().getTime() >= (app.startime+app.longpress))
					{
						if(parseInt(title.split('x ')[0]) > 1)
						{
							$(that).find('.listert-title').html(parseFloat(title.split('x ')[0])-1 + 'x ' + title.split('x ')[1]);
							$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal+(subtotal-price), 2).replace('.', ','));
						}
						else
						{
							$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal, 2).replace('.', ','));
							$(that).fadeOut('fast', function()
							{
								setTimeout(function()
								{
									$(that).remove();
								}, 500);
							});
						}
					}
					else
					{
						$(that).find('.listert-title').html(parseInt(title.split('x ')[0])+1 + 'x ' + title.split('x ')[1]);
						$('a[name="total"]').html('€ ' + app.fixed(parseFloat($('a[name="total"]').html().substr(2).replace(',', '.'))-subtotal+(subtotal+price), 2).replace('.', ','));
					}
					return true;
				}).on('input', 'input[type=text], input[type=email], input[type=password], select, textarea', function(e)
				{
					//console.log('input input[type=text], input[type=email], input[type=password], select, textarea');
					var action = $(this).closest('form').attr('action'), name = $(this).attr('name'), postal, value = $(this).val(), type = $(this).attr('type');
					app.validate($(this));
					if(app.role(['admin', 'administrator', 'developer']))
					{
						if(name == '_name' && !$(this).date('readonly'))
						{
							app.autocomplete('iclients', value);
							$('#_names').slideDown(200);
						}
					}
				}).on('copy', 'body', function(e)
				{
					var selection = (window.getSelection ? window.getSelection().toString() : (document.selection && document.selection.type != "Control" ? document.selection.createRange().text : null));
					if(!app.empty(selection) && selection.length > 100)
					{
						if(!app.role(['admin', 'administrator', 'developer']))
						{
							var footer = "<br /><br />Bron: <a href='https://" + $(location).attr('hostname') + "/'>https://" + $(location).attr('hostname') + "/</a><br /><br />Onderdeel van iRepair.nu | Snel en vakkundig | Al 10 jaar!", holder = $('<div>', {html: selection+footer, style: {position: 'absolute', left: '-99999px'}});
							if(!app.empty(selection))
							{
								app.report('<b>Melding:</b> Door ' + config.ipaddress + ' is op ' + $(location).attr('href') + ' de volgende tekst geselecteerd: ' + selection);
							}
							//console.log('copy body');
							$('body').append(holder);
							//selection.selectAllChildren(holder[0]);
							window.setTimeout(function()
							{
								holder.remove();
							}, 0);
						}
					}
				}).on('change', 'select', function(e)
				{
					var multi = ($(this).attr('multiple') === 'multiple' ? true : false), form = $(this).closest('form').attr('name'), name = $(this).attr('name'), value = $(this).attr('value'), text = $(this).find('option:selected').text();
					if(name === '_device')
					{
						var device = app.jsobjects(config.devices, 'nummer', $(this).val());
						$.each(['colors', 'processor', 'ram', 'storage'], function(keys, values)
						{
							var name = (app.in_array(values, ['colors']) ? values.slice(0, -1) : values);
							$('select[name^="_' + name + '"]').empty();
							if($('select[name^="_' + name + '"]').attr('multiple') !== 'multiple')
							{
								$('select[name^="_' + name + '"]').append($('<option>').text('-').attr('value', ''));
							}
							if(device[values])
							{
								if(device[values].indexOf(',') > -1)
								{
									$.each(device[values].split(','), function(key, value)
									{
										text = (app.in_array(name, ['processor']) ? value : app.ucfirst(value));
										$('select[name^="_' + name + '"]').append($('<option>').text(text).attr('value', value));
									});
								}
								else
								{
									text = (app.in_array(name, ['processor']) ? device[values] : app.ucfirst(device[values]));
									$('select[name^="_' + name + '"]').append($('<option>').text(text).attr('value', device[values]));
								}
							}
						});
					}
				}).on('change', 'input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="checkbox"], input[type="radio"], textarea', function(e)
				{
					//console.log('change input[type=text], input[type=email], input[type=password], input[type=checkbox], textarea');
					var action = $(this).closest('form').attr('action'), form = $(this).closest('form').attr('name'), name = $(this).attr('name'), postal, value = $(this).val(), type = $(this).attr('type');
					if(app.startswidth(action, '/reparatie/'))
					{
						if($(this).is(':checkbox'))
						{
							app.calculate('reparatie');
						}
					}
					else if(config.page === 'iaccessoires')
					{
						if(app.in_array(name, ['title']))
						{
							$(this).val(app.applify(value, true));
						}
						else if(app.in_array(name, ['description', 'subtitle', 'specifications']))
						{
							$(this).val(app.applify(value, false));
						}
					}
					else if(app.endswith(action, 'offerte/'))
					{
						if(name === 'avia_3_1')
						{
							//value = value.replace(/\s/g, '');
							value = value.replace(/(\s|^(B-?|D-?|NL-?))/ig, '');
							//value = value.replace(/B(\s|-)|D(\s|-)|NL(\s|-)/ig, '');
							if(postal = app.check('postal', value))
							{
								$(this).val(postal);
								return true;
							}
							else
							{
								$(this).val('').focus();
								melding = (app.test(value, '^[1-9][0-9]{4}$') ? 'Liebe Besucher, <br /><br />Sowohl die geografischen und logistische Gründe machen können wir nur Online-Angebote für die Bewohner von Antwerpen (BE), Lüttich (BE), Limburg (BE & NL), Südost-Brabant (NL) und Nordrhein-Westfalen. <br /> <br /> <br /> Wenn Sie sowieso in unserem persönlich besuchen wollen, sind Sie dann natürlich willkommen!' : 'Beste bezoeker,<br /><br />Zowel om de geografische als logistieke redenen kunnen wij online alleen offertes maken voor de inwoners van Antwerpen (BE), Luik (BE), Limburg (BE & NL), Zuidoost Brabant (NL) én Noord-Rijnland (DE).<br /><br /><br />Mocht je ons tóch in eigen persoon een bezoek willen brengen dan ben je natuurlijk van harte welkom!');
								app.popupper('Mededeling', melding, 'Neem contact op', function(result)
								{
									melding = '';
									external = app.cookie('external');
									app.report('<b>Melding:</b> De offerte aanvraag via ' + config.ipaddress + ' ' + (app.empty(external) ? '' : 'dankzij <b>' + external + '</b> ') + 'voor <b>' + $('input[name="avia_1_1"]').val() + '</b> met <a href="mailto:' + $('input[name="avia_2_1"]').val() + '">' + $('input[name="avia_2_1"]').val() + '</a> als e-mailadres en postcode <b>' + app.strtoupper(value) + '</b> valt buiten het werkgebied!', melding);
									if(result)
									{
										$(location).attr('href', '/contact');
									}
								});
								return false;
							}
						}
						else if(name === 'avia_4_1')
						{
							value = $('#avia_3_1').val() + '|' + value;
							//console.log(value);
							app.check('address', value);
						}
					}
					else if(app.endswith(action, 'retail/'))
					{
						if(app.in_array(name, ['avia_2_1', 'avia_3_1']))
						{
							/*
								nl854688973b01 & 62150847
								nl852502667b01 & 57253684
							*/
							//console.log('change paste input[name="avia_2_1"], input[name="avia_3_1"]');
							$('input[name="' + name + '"]').after('<span class="description">&nbsp;</span>');
							var countries = {'België': 'BE', 'Duitsland': 'DE', 'Nederland': 'NL'}, country = countries[$('select[name="avia_1_1"] option:selected').val()], type;
							if(name === 'avia_2_1')
							{
								value = app.strtoupper((app.is_numeric(value.substr(0, 2)) ? (typeof country != 'undefined' ? country : 'NL') + value : value)).substr(2), type = country;
							}
							else
							{
								type = 'KVK';
							}
							if(app.test(value, app.pattern(type)))
							{
								app.check(type, value).done(function(result)
								{
									//console.dir(result);
									if(result !== null && app.in_array(result['status'], ['valid', 'unsubscribed', 'unavailable']))
									{
										if(name === 'avia_2_1')
										{
											$('input[name="' + name + '"]').val(country + value).attr('disabled', 'disabled');
										}
										else
										{
											$('input[name="' + name + '"]').val(value).attr('disabled', 'disabled');
										}
										$('select[name="avia_1_1"]').attr('disabled', 'disabled');
										if('company' in result)
										{
											$('input[name="avia_4_1"]').val(result['company']).attr('disabled', 'disabled');
											$('input[name="avia_4_1"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="avia_4_1"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('address' in result)
										{
											if('postal' in result['address'])
											{
												$('input[name="avia_5_1"]').val(result['address']['postal']).attr('disabled', 'disabled');
												$('input[name="avia_5_1"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="avia_5_1"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('number' in result['address'])
											{
												$('input[name="avia_6_1"]').val(result['address']['number']).attr('disabled', 'disabled');
												$('input[name="avia_6_1"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="avia_6_1"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('street' in result['address'])
											{
												$('input[name="avia_7_1"]').val(result['address']['street']).attr('disabled', 'disabled');
												$('input[name="avia_7_1"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="avia_7_1"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('city' in result['address'])
											{
												$('input[name="avia_8_1"]').val(result['address']['city']).attr('disabled', 'disabled');
												$('input[name="avia_8_1"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="avia_8_1"]'), 'border', '1px solid #b7b7b7', 5000);
											}
										}
										if(result['status'] === 'valid')
										{
											$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #9bc90d;">Geverifieerd!</b>');
										}
										else if(result['status'] === 'unsubscribed')
										{
											$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #f44336;">Uitgeschreven!</b>');
										}
										else
										{
											$('input[name="' + name + '"]').next('span[class="description"]').html('<b style="color: #ed781e;">Verificatie niet beschikbaar, geldig formaat!</b>');
										}
										return true;
									}
									else
									{
										app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
										/*
										if(type === 'KVK')
										{
										*/
											$('input[name="avia_2_1"]').val('');
											$('input[name="avia_3_1"]').val('');
											$('input[name="avia_4_1"]').val('');
											$('input[name="avia_5_1"]').val('');
											$('input[name="avia_6_1"]').val('');
											$('input[name="avia_7_1"]').val('');
											$('input[name="avia_8_1"]').val('');
										/*
										}
										else
										{
											$('input[name="user_vat"]').val('');
										}
										*/
										return false;
									}
								});
							}
							else
							{
								app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
								/*
								if(type === 'KVK')
								{
								*/
									$('input[name="avia_2_1"]').val('');
									$('input[name="avia_3_1"]').val('');
									$('input[name="avia_4_1"]').val('');
									$('input[name="avia_5_1"]').val('');
									$('input[name="avia_6_1"]').val('');
									$('input[name="avia_7_1"]').val('');
									$('input[name="avia_8_1"]').val('');
								/*
								}
								else
								{
									$('input[name="user_vat"]').val('');
								}
								*/
								return false;
							}
						}
						else if(name === 'avia_4_1')
						{
							app.check('address', $('#avia_3_1').val() + value);
						}
					}
					else if(app.in_array(name, ['_vat', '_kvk']))
					{
						/*
							nl854688973b01 & 62150847
							nl852502667b01 & 57253684
						*/
						//console.log('change input[name="_vat"], input[name="_kvk"]');
						if(app.role(['admin', 'administrator', 'developer']))
						{
							$('label[for="' + name + '"] span[class^="state"]').html('');
							var countries = {'België': 'BE', 'Duitsland': 'DE', 'Nederland': 'NL'}, type = 'KVK', value = value.replace(/[\.\s-]+/g, '');
							if(name === '_vat')
							{
								type = app.strtoupper(value.substr(0, 2)), value = app.strtoupper(value).substr(2);
							}
							//console.log(type + ' - ' + value);
							if(app.test(value, app.pattern(type)))
							{
								//console.log('checked');
								app.check(type, value).done(function(result)
								{
									//console.dir(result);
									if(result !== null && app.in_array(result['status'], ['valid', 'unsubscribed', 'unavailable']))
									{
										if(name === '_vat')
										{
											$('input[name="' + name + '"]').val(type + value);
										}
										if('company' in result)
										{
											$('input[name="_company"]').val(result['company']);
											$('input[name="_company"]').css('border', '1px solid #4caf50');
											app.timeout($('input[name="_company"]'), 'border', '1px solid #b7b7b7', 5000);
										}
										if('address' in result)
										{
											if('postal' in result['address'])
											{
												$('input[name="_postal"]').val(result['address']['postal']);
												$('input[name="_postal"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="_postal"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('number' in result['address'])
											{
												$('input[name="_number"]').val(result['address']['number']);
												$('input[name="_number"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="_number"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('street' in result['address'])
											{
												$('input[name="_street"]').val(result['address']['street']);
												$('input[name="_street"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="_street"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											if('city' in result['address'])
											{
												$('input[name="_city"]').val(result['address']['city']);
												$('input[name="_city"]').css('border', '1px solid #4caf50');
												app.timeout($('input[name="_city"]'), 'border', '1px solid #b7b7b7', 5000);
											}
											$('.accordion').eq(1).find('input[id^="accordion-"]').attr('checked', true);
											//app.timeout($('.accordion').eq(1).find('input[id^="accordion-"]'), 'checked', false, 8000);
										}
										if(result['status'] === 'valid')
										{
											$('label[for="' + name + '"] span[class^="state"]').html('<b style="color: #9bc90d;">Geverifieerd!</b>');
										}
										else if(result['status'] === 'unsubscribed')
										{
											$('label[for="' + name + '"] span[class^="state"]').html('<b style="color: #f44336;">Uitgeschreven!</b>');
										}
										else
										{
											$('label[for="' + name + '"] span[class^="state"]').html('<b style="color: #ed781e;">Ongeldig!</b>');
										}
										return true;
									}
									else
									{
										//app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
										$('label[for="' + name + '"] span[class^="state"]').html('<b style="color: #ed781e;">Ongeldig!</b>');
										app.timeout($('label[for="' + name + '"] span[class^="state"]'), 'html', '', 5000);
										if(name === '_vat')
										{
											app.timeout($('input[name="_vat"]'), 'html', '', 5000);
											$('input[name="_kvk"]').val('');
										}
										else
										{
											app.timeout($('input[name="_kvk"]'), 'html', '', 5000);
											$('input[name="_vat"]').val('');
										}
										$('input[name="_company"]').val('');
										$('input[name="_street"]').val('');
										$('input[name="_number"]').val('');
										$('input[name="_postal"]').val('');
										$('input[name="_city"]').val('');
										$('select[name="_country"]').val('Nederland').trigger('change');
										return false;
									}
								});
							}
							else
							{
								//app.popupper('Ongeldige invoer', 'Het ' + (app.in_array(type, ['BE', 'DE', 'NL']) ? 'BTW-' + type : type) + ' ' + value + ' nummer is ongeldig!');
								$('label[for="' + name + '"] span[class^="state"]').html('<b style="color: #ed781e;">Ongeldig!</b>');
								app.timeout($('label[for="' + name + '"] span[class^="state"]'), 'html', '', 5000);
								if(name === '_vat')
								{
									app.timeout($('input[name="_vat"]'), 'html', '', 5000);
									$('input[name="_kvk"]').val('');
								}
								else
								{
									app.timeout($('input[name="_kvk"]'), 'html', '', 5000);
									$('input[name="_vat"]').val('');
								}
								$('input[name="_company"]').val('');
								$('input[name="_street"]').val('');
								$('input[name="_number"]').val('');
								$('input[name="_postal"]').val('');
								$('input[name="_city"]').val('');
								$('select[name="_country"]').val('Nederland').trigger('change');
								return false;
							}
						}
					}
					else if(name === '_postal')
					{
						/*
						value = value.replace(/\s/g, '');
						if(postal = app.check('postal2', value))
						{
							$(this).val(postal);
							return true;
						}
						else
						{
							$(this).val('').focus();
						}
						*/
						//value = value.replace(/^(\s|B-?|D-?|NL-?)/ig, '');
						value = value.replace(/(\s|^(B-?|D-?|NL-?))/ig, '');
						if(app.in_array(form, ['ioffers']))
						{
							if(postal = app.check('postal', value))
							{
								$(this).val(postal);
								return true;
							}
							else
							{
								$(this).val('').focus();
								var _name = $('input[name="_name"]').val(), _emailaddress = $('input[name="_emailaddress"]').val();
								melding = (app.test(value, '^[1-9][0-9]{4}$') ? 'Liebe ' + _name + ', <br /><br />Sowohl die geografischen und logistische Gründe machen können wir nur Online-Angebote für die Bewohner von Antwerpen (BE), Lüttich (BE), Limburg (BE & NL), Südost-Brabant (NL) und Nordrhein-Westfalen. <br /> <br /> <br /> Wenn Sie sowieso in unserem persönlich besuchen wollen, sind Sie dann natürlich willkommen!' : 'Beste ' + _name + ',<br /><br />Zowel om de geografische als logistieke redenen kunnen wij online alleen offertes maken voor de inwoners van Antwerpen (BE), Luik (BE), Limburg (BE & NL), Zuidoost Brabant (NL) én Noord-Rijnland (DE).<br /><br /><br />Mocht je ons tóch in eigen persoon een bezoek willen brengen dan ben je natuurlijk van harte welkom!');
								app.popupper('Mededeling', melding, 'Neem contact op', function(result)
								{
									if(result)
									{
										$(location).attr('href', '/contact');
									}
								});
								app.report('<b>Melding:</b> De offerte aanvraag voor <b>' + _name + '</b> met <a href="mailto:' + _emailaddress + '">' + _emailaddress + '</a> als e-mailadres en postcode <b>' + app.strtoupper(value) + '</b> valt buiten het werkgebied!', '', true);
								return false;
							}
						}
						else
						{
							if(postal = app.check('postal2', value))
							{
								$(this).val(postal);
								return true;
							}
							else
							{
								$(this).val('').focus();
							}
						}
						/*
						if(postal = app.check('postal', value))
						{
							$(this).val(postal);
							return true;
						}
						else
						{
							$(this).val('').focus();
							melding = (app.test(value, '^[1-9][0-9]{4}$') ? 'Liebe Besucher, <br /><br />Sowohl die geografischen und logistische Gründe machen können wir nur Online-Angebote für die Bewohner von Antwerpen (BE), Lüttich (BE), Limburg (BE & NL), Südost-Brabant (NL) und Nordrhein-Westfalen. <br /> <br /> <br /> Wenn Sie sowieso in unserem persönlich besuchen wollen, sind Sie dann natürlich willkommen!' : 'Beste bezoeker,<br /><br />Zowel om de geografische als logistieke redenen kunnen wij online alleen offertes maken voor de inwoners van Antwerpen (BE), Luik (BE), Limburg (BE & NL), Zuidoost Brabant (NL) én Noord-Rijnland (DE).<br /><br /><br />Mocht je ons tóch in eigen persoon een bezoek willen brengen dan ben je natuurlijk van harte welkom!');
							app.popupper('Mededeling', melding, 'Neem contact op', function(result)
							{
								if(result)
								{
									$(location).attr('href', '/contact');
								}
							});
							return false;
						}
						*/
					}
					else if(name === '_number')
					{
						value = $('input[name="_postal"]').val() + '|' + value;
						//console.log(value);
						app.check('address2', value);
						//app.check('address2', $('input[name="_postal"]').val() + value);
					}
					else if(name === '_number[]')
					{
						$(this).trigger('blur');
					}
					return true;
				}).on('keypress', function(e)
				{
					var key = (e.keyCode ? e.keyCode : e.which), target = (e.target ? e.target : e.srcElement), name = $(target).attr('name'), value = $(target).val(), type = $(target).attr('type');
				}).on('keydown', function(e)
				{
					//config.idler = 0;
					//console.log('keydown');
					var key = (e.keyCode ? e.keyCode : e.which), target = (e.target ? e.target : e.srcElement), name = $(target).attr('name');
					if(key == 8 && $(target).is('input, textarea') && $(target).val() === '')
					{
						config.value = '';
						$(target).trigger('blur');
					}
					else if(key == 8 && !$(target).is('input, textarea'))
					{
						e.stopPropagation();
						/*
							Test: Prevent backspace on keypress
							$(location).attr('href', $(location).attr('href').split('&action=')[0]);
						*/
						return false;
					}
					else if(key == 13)
					{
						if(app.in_array(name, ['price', 'discount', 's', 'search', 'reason']))
						{
							e.preventDefault();
							if($(target).next('a[class*="button"]').length)
							{
								//console.log('Next');
								$(target).trigger('blur').trigger('change').next('a[class*="button"]').trigger('click');
							}
							else if($(target).closest('tr').find('a[class*="button"]').length)
							{
								//console.log('Closest');
								$(target).trigger('blur').trigger('change').closest('tr').find('a[class*="button"]').trigger('click');
							}
							return false;
						}
						else if(!$(target).is('textarea'))
						{
							e.preventDefault();
							$(target).trigger('blur');
							return false;
						}
					}
					else if($(target).is('input, textarea'))
					{
						//console.log(name + ':' + key);
						if(app.in_array(name, ['_price[]']) && $(target).hasClass('numerics'))
						{
							/*
							if(app.numerics(e))
							{
								e.preventDefault();
								$(target).trigger('input');
							}
							else
							{
								 return;
							}
							*/
						}
						else
						{
							// TODO: focus
							$(target).trigger('input');
						}
					}
				}).on('keyup', function(e)
				{
					//console.log('keyup');
					var key = (e.keyCode ? e.keyCode : e.which), target = (e.target ? e.target : e.srcElement), name = $(this).attr('name');
					if(key == 46 && $(target).is('input, textarea') && $(target).val() === '')
					{
						config.value = '';
						$(target).trigger('blur');
					}
				});
			}
			app.marquee('init');
			app.slider('init');
			if(config.alerts != false)
			{
				app.popupper('Opgelet!', config.alerts, 'alert', true);
			}
			/*
				$('a[href*="ideeinbeeld.nl"]').each(function()
				{
					$(this).attr('href', $(this).attr('href').replace('ideeinbeeld.nl', config.domain));
				});
			*/
			app.fullscreen('load');
			if($(location).attr('host') !== 'irepair.nu')
			{
				app.captcha('generate');
				$('#container-floating .floating-button').animate({bottom: ($(window).width() < 768 ? 20 : 60)}, 'slow', function(e)
				{
					$('#container-floating .floating-button .bars i').fadeOut('fast').removeClass('fa-chevron-down fa-chevron-up').addClass('fa-thumbs-o-up').fadeIn('fast');
					/*
					setTimeout(function()
					{
						$('#container-floating .floating-button .bars i').fadeOut('fast').removeClass('fa-thumbs-o-up').fadeIn('fast').addClass('fa-chevron-down');
					}, 3000);
					*/
				});					
			}
			$('a[href^="//"], a[href^="http://"], a[href^="https://"]').not('[class*="internal"], [href*="mailto:"], [href*="tel:"]').filter(function()
			{
				return this.host && this.host.slice(-9) !== 'repair.ga' && this.host.slice(-9) !== 'repair.nu';
			}).each(function(e)
			{
				$(this)
					.attr('href', $(this).attr('href').replace('ideeinbeeld.nl', config.domain))
					.attr({
						target: '_blank',
						title: 'Deze link opent in een nieuw tabblad!'
					});
			});

if($('.welcomessage').length)
{
	app.typers('.welcomessage', [
	'#2500 <i class="fa fa-mobile fa-fw"></i> iPhone',
	'#2500 <i class="fa fa-tablet fa-fw"></i> iPad',
	'#2500 <i class="fa fa-laptop fa-fw"></i> MacBook',
	'#2500 <i class="fa fa-tv fa-fw"></i> iMac',
	], 1000, '<i class="fa fa-apple fa-fw"></i> i', '|', true, false);	
}
			/*
				$('#wrap_all a').removeAttr('title');
			*/
			$('#wrap_all img').removeAttr('title');
			$('form').each(function(i)
			{
				$(this).attr('novalidate', 'novalidate');
				if(app.empty($(this).attr('action')))
				{
					$(this).attr('action', $(location).attr('pathname'));
				}
			});
			if(config.page == 'checkout')
			{
				var href = $(location).attr('href'), href = (href.substr(href.length-1) == '/' ? href.substr(0, href.length-1) : href);
				$(':input:enabled:visible:first').focus();
				$.ajax({
					url: 'https://' + config.domain,
					data: {'merk': 'overview'},
					dataType: 'html',
					success: function(data)
					{
						$('.itemeresults').fadeOut('fast', function()
						{
							$(this).html(data).slideDown();
						});
					}
				});
				/*
					ajax call
				*/

				/*
				if(app.in_array(href.split('/').pop(), ['iphone', 'ipad', 'macbook', 'imac']))
				{
					var device = href.split('/').pop();
					$.ajax({
						url: 'irepair.nu',
						data: {'device': device},
						dataType: 'html',
						success: function(data)
						{
							$('.itemerts').fadeOut(function()
							{
								$(this).html(data).slideDown();
							});
						}
					});
				}
				*/
			}
			else if(config.page == 'offerte')
			{
				var offerte, unique = [];
				var device, repair;
				$('#avia_10_1').empty();
				$.each($.parseJSON(config.devices), function(i, value)
				{
					if(!app.in_array(value.model, unique))
					{
						offerte = value.merk + ' ' + value.model;
						$('#avia_10_1').append($('<option>').text(offerte).attr('value', offerte));
						unique.push(value.model);
					}
				});
				$('#avia_10_1').attr('size', $('#avia_10_1 option').length);
				if(device = app.query('device'))
				{
					$('#avia_10_1 option[value="' + device + '"]').attr('selected', 'selected');
				}
				if(repair = app.query('repair'))
				{
					$('#avia_11_1').val(repair);
				}
			}
			else if(config.page == 'reparatie')
			{
				app.calculate('reparatie');
			}
			else if(config.page == 'privacy')
			{
				//app.timeout('iprivacy', 'init', config.client);
			}
			/*
				$('form').find(':text,select,textarea').filter(':visible:first').trigger('focus');
			*/
			$(window).on('resize orientationchange', function(e)
			{
				var wrap = $('#wrap_all');
				if(wrap.hasClass('show_mobile_menu'))
				{
					wrap.removeClass('show_mobile_menu');
				}
				app.dialogs();
				//config.idler = 0;
			});
			var word = "SERIAL", typed = '';
			window.prevFocus = $();
			$(document).on('focusin', ':input', function()
			{
				window.prevFocus = $(this);
			}).on('keydown', function(e)
			{
				/*
					if(((e.ctrlKey || e.metaKey) && (e.keyCode == 70 || e.which == 70)) || e.keyCode === 114)
					{
						app.popformer('iserial', 'check', false);
						return false;
					}
				*/
				/*
				typed += String.fromCharCode(e.keyCode || e.which);
				if(typed === word)
				{
					//console.log(typed + '!');
					app.popformer('iserial', 'check', false);
				}
				else
				{
					//console.log(typed + '?');
				}
				if(typed.length > word.length)
				{
					typed = typed.substr(1);
				}
				*/
				/*
				if((e.ctrlKey || e.metaKey) && (e.keyCode || e.which == 70) || e.keyCode === 114)
				{
					e.preventDefault();
					app.popformer('iserial', 'check', false);
					return false;
				}
				*/
				return true;
			}).on('click', 'div[class="box"]', function(e)
			{
				//console.log('click div[class="box"]');
				var href = $(this).find('a').attr('href');
				if(typeof href !== "undefined")
				{
					$(location).attr('href', href);
				}
			}).on('click', 'a[class="scrolltop"]', function(e)
			{
				//console.log('click a[class="scrolltop"]');
				/*
					if(config.clicks === 0)
					{
						config.clicks += 1;
						e.preventDefault();
						return false;
					}
					else
					{
						config.clicks = 0;
						return true;
					}
				*/
				if($(this).hasClass('scrolltopper'))
				{
					$(this).removeClass('scrolltopper');
				}
				else
				{
					e.preventDefault();
					$(this).addClass('scrolltopper');
				}
			}).on('click', 'a[href*=#]:not([href=#])', function(e)
			{
				//console.log('click a[href*=#]:not([href=#])"]');
				e.preventDefault();
				$('html, body').animate({ scrollTop: $(this.hash).offset().top }, 'normal', 'swing');
			}).on('scroll', function(e)
			{
				var scrollTop = $(this).scrollTop();
				if(scrollTop  > 425 && scrollTop < 675)
				{
					$(this).find('div[class="box"] img[data-rotate]').css({
						'-webkit-transition': '-webkit-transform 0.75s ease-in-out',
						'-moz-transition': '-moz-transform 0.75s ease-in-out',
						'transition': 'transform 0.75s ease-in-out',
						'-webkit-transform': 'rotate(90deg)',
						'-moz-transform': 'rotate(90deg)',
						'transform': 'rotate(90deg)'
					});
				}
				else
				{
					$(this).find('div[class="box"] img[data-rotate]').css({
						'-webkit-transform': 'rotate(0deg)',
						'-moz-transform': 'rotate(0deg)',
						'transform': 'rotate(0deg)'
					});
				}
				if(scrollTop > config.lastScroll)
				{
					if($(window).scrollTop()+$(window).height() > $(document).height()-75)
					{
						$('#container-floating .floating-button, #container-floating .button1, #container-floating .button2, #container-floating .button3').hide();
					}
					else
					{
						$('#container-floating .floating-button, #container-floating .button1, #container-floating .button2, #container-floating .button3').show();
						$('#container-floating .floating-button a').attr('href', '#footer');
						$('#container-floating .floating-button a i').removeClass('fa-chevron-up').addClass('fa-chevron-down');
					}
				}
				else
				{
					if($(window).scrollTop() < 75)
					{
						$('#container-floating .floating-button, #container-floating .button1, #container-floating .button2, #container-floating .button3').hide();
					}
					else
					{
						$('#container-floating .floating-button, #container-floating .button1, #container-floating .button2, #container-floating .button3').show();
						$('#container-floating .floating-button a').attr('href', '#top');
						$('#container-floating .floating-button a i').removeClass('fa-chevron-down').addClass('fa-chevron-up');
					}

				}
				config.lastScroll = scrollTop;

				//config.idler = 0;
			}).on('touchstart touchend', function(e)
			{
				/*
					e.preventDefault();
				*/
				//config.idler = 0;
			}).on('mouseover', 'div#quotes', function(e)
			{
				clearInterval(config.quotations);
			}).on('click', 'label[for^="star"]:not(.disabled)', function(e)
			{
				$(this).closest('fieldset').find('input[id^="star"]').removeAttr('checked').css('display', 'none');
				$('input[id="' + $(this).attr('for') + '"]').attr('checked', 'checked').css('display', 'inherit');
			}).on('click', 'label[for^="accordion-"]', function(e)
			{
				/*
					$(this).find('input[id^="accordion-"]').attr('checked', true);
				*/
				$(this).closest('.accordion-content').find('input[type="text"]:first').trigger('focus');
			}).on('mouseout', '.accordion', function(e)
			{
				/*
					$(this).find('input[id^="accordion-"]').attr('checked', false);
				*/
			}).on('mouseout', 'div#quotes', function(e)
			{
				config.quotations = setInterval(app.quotations, config.quoter);
			}).on('click', '#quotes', function(e)
			{
				clearInterval(config.quotations);
				app.quotations();
			}).on('click', '#float_toggle', function(e)
			{
				config.axis = (parseInt($(this).data('axis'))-180);
				$('#float_menu').css('transform', 'rotate(' + config.axis + 'deg)');
				$('#float_menu').css('webkitTransform', 'rotate(' + config.axis + 'deg)');
				if((config.axis / 180) % 2 == 0)
				{
					$('#float_toggle').parent().addClass('float_active');
					$('#float_toggle').addClass('close');
				}
				else
				{
					$('#float_toggle').parent().removeClass('float_active');
					$('#float_toggle').removeClass('close');
				}
				$(this).data('axis', config.axis);
			}).on('transitionend webkitTransitionEnd oTransitionEnd', '#float_menu', function()
			{
				if((config.axis / 180) % 2 == 0)
				{
					$('#float_menu div i').addClass('float_animate');
				}
				else
				{
					$('#float_menu div i').removeClass('float_animate');
				}
			}).on('click', '.quote-control', function(e)
			{
				clearInterval(config.quotations);
				$('.slider-quote').removeClass('quote-focused');
				$('.quote-control').removeClass('quote-selected');
				$('#' + $(this).attr('id') + '-content').addClass('quote-focused');
				$(this).addClass('quote-selected');
				$('div#quotes').unbind('mouseover mouseout');
			}).ajaxError(function(e, xhr, settings, error)
			{
				var errors = {
					'400' : 'Het verzoek is incompleet',
					'401' : 'Het verzoek is ongewenst',
					'403' : 'Het verzoek is geblokkeerd',
					'500' : 'De server heeft problemen',
					'503' : 'De server is onbereikbaar'
				}, message = '<p>Er is een onbekende fout opgetreden..<p>';
				/*
					if(xhr.status && xhr.status in errors)
					{
						message = '<p>' + errors[xhr.status] + '..</p>';
					}
					else if(error == 'parsererror')
					{
						message = '<p>Het verzoek is ongeldig..</p>';
					}
					else if(error == 'timeout')
					{
						message = '<p>Het verzoek is verlopen..</p>';
					}
					else if(error == 'abort')
					{
						message = '<p>Het verzoek is afgebroken..</p>';
					}
					$('#popupper').dialog('destroy').remove();
				*/
				//$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
			}).ajaxSend(function(e, xhr, settings)
			{
				//console.dir(settings);
			}).ajaxStart(function()
			{
				//console.log('Starting..');
				$('#loader').show(500);
			}).ajaxStop(function()
			{
				//console.log('Stopped!');
				$('#loader').hide(250);
			}).ajaxComplete(function(e, xhr, settings)
			{
				//console.log('Complete:');
				if(xhr.status == 200)
				{
					//console.dir(xhr);
					var result = xhr.responseJSON;
					/*
					if(result.csrf)
					{
						//console.log(result.status);
					}
					*/
				}
				//$('#loader').hide(250);
			});
			$.ajaxPrefilter(function(options, original, xhr)
			{
				//console.log('ajaxPrefilter');
				//console.dir(original);
				if(!options.data)
				{
					options.data = 'csrf=' + config.csrf;
					xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				}
				else if(typeof(options.data) == 'string')
				{
					options.data += '&csrf=' + config.csrf;
				}
				else if(!options.data._token)
				{
					options.data.csrf = config.csrf;
				}
				//console.log(options.data);
			});
			$.ajaxSetup(function()
			{
				//console.log('ajaxSetup');
				/*
				beforeSend: function(xhr, settings)
				{
					if(!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type))
					{
						xhr.setRequestHeader("X-CSRFToken", csrftoken)
					}
				},
				*/
				timeout: 5000
			});
			$.fn.extend({
				/*
					$(":checkbox").check();
					$(":checkbox").uncheck();
				*/
				check : function()
				{
					return this.filter(':radio, :checkbox').attr('checked', 'checked');
				},
				uncheck : function()
				{
					return this.filter(':radio, :checkbox').removeAttr('checked');
				}
			});
			$.widget('ui.dialog', $.extend({}, $.ui.dialog.prototype,
			{
				_title: function(title)
				{
					if(!this.options.title)
					{
						title.html('&#160;');
					}
					else
					{
						title.html(this.options.title);
					}
				}
			}));
			$('.datepicker').datepicker({
				autoclose: true,
				dateFormat : 'dd-mm-yy',
				'dayNamesMin': ['Zo','Ma','Di','Wo','Do','Vr','Za'],
				'dayNamesShort': ['Zo','Ma','Di','Wo','Do','Vr','Za'],
				selectOtherMonths: true
			});
			$('.rotator').each(function(i)
			{
				var target = $(this).find('ul').attr('class');
				app.rotator(target);
			});
	var deg = 0, index = 0;
	$('#intro2018').on('contextmenu', function(e)
	{
		return false;
	/*
	}).on('mousewheel', function(e)
	{
		if(index === 5)
		{
			location.href = 'https://iphonerepair.nu/aanbiedingen/';
			return null;
		}
		var move = -60, nextIndex = nextIndex = ((index + 1) % 6);
		//if(e.originalEvent.wheelDelta / 120 <= 0)
		//{
		//	move = 60;
		//	nextIndex = (index - 1 < 0 ? 5 : index - 1);
		//}
		$('#intro2018 .scrollist').css('transform', 'rotateX(' + (deg + move) + 'deg)');
		$('#intro' + index).css('opacity', '0.01');
		$('#intro' + nextIndex).css('opacity', '1');
		index = nextIndex;
		deg = deg + move;
		e.stopPropagation();
		return false;
	*/
	}).on('click', function(e)
	{
		if(index === 5)
		{
			location.href = 'https://iphonerepair.nu/aanbiedingen/';
			return false;
		}
		var move = -60, nextIndex = (nextIndex = (index + 1) % 6);
		/*
		if(e.which !== 1)
		{
			move = 60;
			nextIndex = (index - 1 < 0 ? 5 : index - 1);
		}
		*/
		$('#intro2018 .scrollist').css('transform', 'rotateX(' + (deg + move) + 'deg)');
		$('#intro' + index).css('opacity', '0.01');
		$('#intro' + nextIndex).css('opacity', '1');
		index = nextIndex;
		deg = deg + move;
		e.stopPropagation();
		return false;
	});
	$('#intro2018').animate({backgroundColor: '#fff'}, 1000, function(e)
	{
		$('#intro2018 .scroller').animate({opacity: 1}, 750);
	});
		//$('div[class="box"] img[data-rotate]').on('mouseenter', function(e)
		//{
			// $(this).effect('shake', {times: 2}, 100);
		//});

			if($('html').hasClass('js_active'))
			{
				//$('.js').css('display', 'inherit');
			}
			app.language();
			var $dropTrigger = $('.dropdown dt a'), $languageList = $('.dropdown dd ul');
			$dropTrigger.toggle(function()
			{
				$languageList.slideDown(200);
				$dropTrigger.addClass('active');
			}, function()
			{
				$languageList.slideUp(200);
				$(this).removeAttr('class');
			});
			$(document).bind('click', function(e)
			{
				var $clicked = $(e.target);
				if(!$clicked.parents().hasClass('dropdown'))
				{
					$languageList.slideUp(200);
				}
				$dropTrigger.removeAttr('class');
			});
			$('.dropdown dd ul li a').on('click', function(e)
			{
				e.preventDefault();
				var language = $(this).parent().attr('class');
				if(language && app.in_array(language, ['nl', 'en', 'de']))
				{
					//app.cookie('language', language, 365);
					$('#loader').show(500);
					app.cookies('language', language, '+1 year');
					/*
						//console.log(app.cookies('language'));
						//console.log(app.cookies('language', 'nl', '+1 year'));
						

					*/
					/*
					$.each(['irepair.nu', 'iphonerepair.nu', 'ipadrepair.nu', 'macbookrepair.nu', 'imacrepair.nu'], function(i, domain)
					{
						expires = '+1 year';
						
						$('body').append('<iframe src="https://' + domain + '/index.php?language=' + language + '" height="0" width="0">');
						$.get('https://' + domain + '/?host=' + config.domain + '&cookie=language&value=' + language, function(data)
						{
							//console.log(domain + ': ' + data);
						});
					});
					//*/
				}
				var clickedValue = $(this).parent().attr('class'), clickedTitle = $(this).find('em').html();
				$('#target dt').removeClass().addClass(clickedValue);
				$('#target dt em').html(clickedTitle);
				$languageList.hide();
				$dropTrigger.removeAttr('class');
				setTimeout(function()
				{
					location.reload();
				}, 500);
			});
			if(app.homepage())
			{
				if(!app.cookie('cookies'))
				{
					$('a[name="cookielp"]').trigger('click');
				}
			}
			config.quotations = setInterval(app.quotations, config.quoter);
			//setInterval(app.idler, 1000);
		},
		homepage: function()
		{
			return ((window.location.protocol + '//' + window.location.hostname + '/') === (window.location.href));
		},
		reorder: function(name)
		{
			switch(name)
			{
				case 'ioffers':
				case 'ireceipt':
					var counter = $('form[name="' + name + '"] input[name="_title[]"]').filter(function()
					{
						return !$(this).val();
					}).length, items = $('form[name="' + name + '"] #form-items').length, latest = $('form[name="' + name + '"] #form-items .form-item').last();
					if(counter === 0)
					{
						if(app.role(['admin', 'administrator', 'developer']))
						{
							$('form[name="' + name + '"] #form-items').append('<div class="form-item">' +
								'<input type="number" name="_number[]" value="" placeholder="1" class="defocus" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="" placeholder="Extra accessoire óf reparatie.." class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" disabled="disabled" />' +
							'</div>');
							if($('form[name="' + name + '"] #form-items .form-item:nth-last-child(1)').find('a[name="form-downs"]').length !== 1)
							{
								$('form[name="' + name + '"] #form-items .form-item:last-child()').append(
									//(app.is_mobile() || app.stripos($('form[name="' + name + '"] #form-items .form-item:nth-last-child(2)').find('input[name="_title[]"]').val(), 'korting') ? '<br />' : '<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a>')
									'<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a>'
								);
							}
						}
					}
					else if(counter > 1)
					{
						//latest.prev().remove();
					}
					if($('form[name="' + name + '"] input[name="_title[]"][value*="Korting"]').length)
					{
						$('form[name="' + name + '"] input[name="_title[]"][value*="Korting"]').parent('div').insertAfter($('form[name="' + name + '"] #form-items .form-item').last());
					}
					break;
				default:
					break;
			}
		},
		marquee: function(action)
		{
			var off = 10, l = off, $As = $('#marquee li'), speed = 2, stack = [], pause = false;
			$.each($As, function()
			{
				var W = $(this).css({
					left: l
				}).width()+off;
				l+=W; 
				stack.push($(this));
			});
			var tick = setInterval(function()
			{
				if(!pause)
				{
					$.each($As, function()
					{
						var ml = parseFloat($(this).css('left'))-speed;
						$(this).css({
							left: ml
						});
						/*
							if(ml <= 0)
							{
								$(this).fadeTo(3000 , 0);
							}
							else if(ml > 0 && ml < 1100)
							{
								$(this).fadeTo(3000 , 1);
							}
							else if(ml > 1100)
							{
								$(this).css('opacity', 0);
							}
						*/
						
						if((ml+$(this).width()) <= 0)
						{
							var $first = stack.shift(), $last = stack[stack.length-1];
							$(this).css({
								left: (parseFloat($last.css('left'))+parseFloat($last.width()))+off
							});
							stack.push($first);
						}
					});
				}
			}, 50);
			$('#marquee').on('mouseover', function()
			{
				pause = true;
			}).on('mouseout', function()
			{
				pause = false;
			});
		},
		slider: function(action)
		{
			var slideCount = $('#slider ul li').length, slideWidth = $('#slider ul li').width(), slideHeight = $('#slider ul li').height(), sliderUlWidth = slideCount * slideWidth;
			switch(action)
			{
				case 'left':
					$('#slider ul').animate({
						left: +slideWidth
					}, 250, function()
					{
						$('#slider ul li:last-child').prependTo('#slider ul');
						$('#slider ul').css('left', '');
					});
					break;
				case 'right':
					$('#slider ul').animate({
						left: -slideWidth
					}, 250, function()
					{
						$('#slider ul li:first-child').appendTo('#slider ul');
						$('#slider ul').css('left', '');
					});
					break;
				case 'stop':
					clearInterval(config.slide);
					$('#slider .options #slide').prop('checked', false);
					setTimeout(function()
					{
						config.slide = setInterval(function()
						{
							$('#slider .options #slide').prop('checked', true);
							app.slider('right');
						}, 2500);
					}, 25000);
					return this;
				default:
					config.slide = setInterval(function()
					{
						app.slider('right');
					}, 2500);
					$('#slider .options #slide').on('change', function()
					{
						clearInterval(config.slide);
						if($(this).is(':checked'))
						{
							config.slide = setInterval(function()
							{
								app.slider('right');
							}, 2500);
						}
						else
						{
							clearInterval(config.slide);
						}
					});
					var slideCount = $('#slider ul li').length, slideWidth = $('#slider ul li').width(), slideHeight = $('#slider ul li').height(), sliderUlWidth = slideCount * slideWidth;
					$('#slider').css({
						width: slideWidth, height: slideHeight
					});
					$('#slider ul').css({
						width: sliderUlWidth, marginLeft: -slideWidth
					});
					$('#slider ul li:last-child').prependTo('#slider ul');
					break;
			}
		},
		typer: function(element, t)
		{
			config.typers[element][3] = (config.typers[element][3] === '' ? config.typers[element][2][config.typers[element][1]] : config.typers[element][3]);
			var secs = 100, txt = config.typers[element][3], t2t = txt.substr(t);
			if(txt.substr(t)[0] === '<')
			{
				while(txt.substr(t+1)[0] !== '>')
				{
					t++;
					if(t+1 > txt.length)
					{
						break;
					}
				}
				t++;
			}
			if(t2t[0] === '#')
			{
				var str = 1;
				if(t2t.match(/^#\d+/))
				{
					t2t = /\d+/.exec(t2t)[0];
					str += t2t.length;
					secs = parseInt(t2t);
					config.typers[element][3] = txt.substr(0, t) + txt.substr(t+str);
				}
				setTimeout(function(e)
				{
					app.typer(element, t);
				}, secs);
				return;
			}
			$(element).html(txt.substr(0, t++));
			if(t < txt.length+1)
			{
				config.typers[element][0] = t;
				setTimeout(function(e)
				{
					app.typer(element, t);
				}, secs);
			}
			else
			{
				if(config.typers[element][1] === config.typers[element][2].length-1 && config.typers[element][7] === false)
				{
					$(element).next('span').remove();
					delete config.typers[element];
					return true;
				}
				else
				{
					setTimeout(function(e)
					{
						app.typed(element);
					}, config.typers[element][4]);
				}
			}
		},
		typed: function(element)
		{
			var t = config.typers[element][0], txt = config.typers[element][3];
			if(txt.substr(t)[0] === '>')
			{
				while(txt.substr(t-1)[0] !== '<')
				{
					t--;
					if(t-1 > txt.length)
					{
						break;
					}
				}
				t--;
			}
			$(element).html(txt.substr(0, t--));
			if(t >= 0)
			{
				config.typers[element][0] = t;
				setTimeout(function(e)
				{
					app.typed(element);
				}, 100);
			}
			else
			{
				config.typers[element][3] = '';
				app.typers(element);
			}
		},
		typers: function(element, array, secs, placeholder, typer, loop, keep)
		{
			array = ($.isArray(array) && app.empty(array) ? [$(element).html()] : array);
			if($.isArray(array))
			{
				$.each(array, function(i, value)
				{
					this.value = $.parseHTML(value);
				});
				config.typers[element] = [0, 0, array, '', (secs || 2000), (placeholder || ''), (typer ? '<abbr class="cursor">' + typer + '</abbr>' : ''), (loop || false), (keep || false)];
				$(element).html(config.typers[element][5]).after(config.typers[element][6]);
			}
			else
			{
				var cnt = config.typers[element][1], max = config.typers[element][2].length-1, nxt = config.typers[element][7];
				if(cnt >= max)
				{
					cnt = 0;
					if(nxt === false)
					{
						$(element).next('span').remove();
						delete config.typers[element];
						return;
					}
				}
				else
				{
					
					cnt += 1;
				}
				config.typers[element][1] = cnt;
				$(element).html(config.typers[element][5]);
			}
			setTimeout(function(e)
			{
				return app.typer(element, 0);
			}, config.typers[element][4]);
		},
		calculate: function(name)
		{
			switch(name)
			{
				case 'reparatie':
					var items = $('form[name="' + name + '"]').find('input:checkbox'), last = items.length, discount = 0, subtotal = 0;
					//(parseInt($('#subtotal').text().replace(/€ /g, '')) || 0);
					items.each(function(i, e)
					{
						if($(this).is(':checked') && i !== (last-1))
						{
							subtotal += parseFloat($(this).closest('h5').find('input[name="price"]').val());
						}
					});
					var discount = $('form[name="' + name + '"] input:checkbox:last').closest('h5').find('input[name="price"]'), title = $('form[name="' + name + '"] input:checkbox:last').closest('h5').find('input[name="title"]');
					if(app.stripos(title.val(), '%'))
					{
						var percentage = title.val().split('%')[0];
						discount.val('-' + ((subtotal/100)*percentage));
					}
					$('form[name="' + name + '"] input:checkbox:last').closest('h5').find('#discount span').html('€ ' + app.fixed(discount.val(), 2).replace('.', ','));
					if($('form[name="' + name + '"] input:checkbox:last').is(':checked'))
					{
						subtotal += parseFloat(discount.val());
						//console.log('Checked: ' + discount.val());
					}
					else
					{
						//console.log('Unchecked: ' + discount.val());
					}
					if(subtotal > 0)
					{
						$('a[name="afspraak"]').removeClass('disabled').animate({ opacity: 1 });
						$('a[name="offerte"]').removeClass('disabled').animate({ opacity: 1 });
						$('a[name="route"]').removeClass('disabled').animate({ opacity: 1 });
						$('a[name="offertes"]').removeClass('disabled').animate({ opacity: 1 });
						$('#subtotal').html('€ ' + app.fixed(subtotal, 2).replace('.', ','));
					}
					else
					{
						$('a[name="afspraak"]').addClass('disabled').animate({ opacity: 0 });
						$('a[name="offerte"]').addClass('disabled').animate({ opacity: 0 });
						$('a[name="route"]').addClass('disabled').animate({ opacity: 0 });
						$('a[name="offertes"]').addClass('disabled').animate({ opacity: 0 });
						$('#subtotal').html('€ 0,00');
					}
					break;
				case 'ioffers':
				case 'ireceipt':
					app.reorder(name);
					var items = $('form[name="' + name + '"] #form-items input[name="_prices[]"]'), last = items.length, discount = 0, discounter = $('form[name="' + name + '"]').find('#form-items .form-item').last(), subtotal = 0;
					items.each(function(i, e)
					{
						if(app.role(['admin', 'administrator', 'developer']))
						{
							if(i !== (last-1))
							{
								//subtotal += parseFloat($(this).closest('h5').find('input[name="price"]').val());
								subtotal += +($(this).val() === '' ? 0 : app.floated($(this).val()));
							}
						}
						else
						{
							subtotal += +($(this).val() === '' ? 0 : app.floated($(this).val()));
						}
					});
					//console.log('Subtotal: ' + subtotal);
					if(discounter.length && app.stripos(discounter.find('input[name="_title[]"]').val(), 'Korting'))
					{
						//console.log('Korting: ' + discounter.find('input[name="_price[]"]').val());
						if(app.stripos(discounter.find('input[name="_title[]"]').val(), '%'))
						{
							var percentage = parseFloat(discounter.find('input[name="_title[]"]').val().split('%')[0]);
							discount = ((subtotal/100)*percentage);
							discounter.find('input[name="_price[]"]').val('€ -' + app.fixed(discount));
							discounter.find('input[name="_prices[]"]').val('€ -' + app.fixed(discount));
						}
						else
						{
							discount = app.floated(discounter.find('input[name="_prices[]"]').val()).substr(1);
						}
						subtotal += +(parseFloat('-' + discount));
						$('span[name="subtotal"]').html('€ ' + app.fixed(subtotal).replace('.', ','));
					}
					else
					{
						$('span[name="subtotal"]').html('€ ' + app.fixed(subtotal).replace('.', ','));
					}
					//console.log('Korting: ' + discount);
					/*
						if(discounter.find('input[name="_price[]"]').val() === '%')
						{
							discount = ((subtotal/100)*parseFloat(price));
							$(this).val('€ -' + app.fixed(discount));
							$(this).next('input').val('€ -' + app.fixed(discount));
						}
						subtotal += +(parseFloat('-' + discount));
						$('span[name="subtotal"]').html('€ ' + app.fixed(subtotal));
					*/
				default:
					break;
			}

		},
		autocomplete: function(table, value)
		{
			if(!app.in_array(config.page, ['privacy']))
			{
				$('input[name="_cid"]').val('0');
				$('input[type="text"], input[type="email"], input[type="password"]').not('input[name="_name"], .defocus').each(function(i, v)
				{
					$(this).val('');
				});
				if(value.length < 1)
				{
					if(table == 'iclients')
					{
						$('#_names').html('<ul class="linput">' +
							'<li><abbr class="muted">Minimaal 2 tekens vereist!</abbr></li>' +
						'</ul>' +
						'<small class="pull-right muted">Dit is een bétaversie!</small>');
					}
				}
				else
				{
					$.ajax({
						url : 'https://' + config.domain + '/wp-admin/admin-ajax.php?table=' + table + '&value=' + encodeURIComponent(app.phone(value)),
						type : 'get',
						data : {
							action : 'autocomplete'
						},
						dataType : 'json',
						global: false,
						success : function(response)
						{
							//console.dir(response);
							if(table == 'iclients')
							{
								$('#_names').html('<ul class="linput">' +
									response.list +
								'</ul>' +
								'<small class="pull-right muted">Dit is een bétaversie!</small>');
							}
							// csrf
							//console.dir(response);
						}
					});
				}
			}
		},
		captcha: function(action)
		{
			var awnser = $('input[name="_awnser"]'), awnselp = $('span[name="_awnselp"]'), awnsered = $('input[name="_awnsered"]'), awnseresponse = $('span[name="_awnseresponse"]'), awnselptcha = $('.recaptcha'), code,
				captcha = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
				captchas = config.captchas,
			rotate = -25, rotations = ['30-', '20-', '10-', '0', '10', '20', '30'], sizes = [14, 16, 18, 20], weights = ['lighter', 'normal', 'bold', 'bolder'], result = '';

			if(awnsered.length)
			{
				switch(action)
				{
					case 'validate':
						decrypted = app.code('decrypt', awnser.val());
						if(decrypted.toLowerCase() != awnsered.val().toLowerCase())
						{
													
							awnselp.html(awnsered.val() !== '' ? 'Dat leek niet eens op ' + awnsered.val() + '!' : 'Bovenstaand s.v.p. overtypen..');
							app.captcha('regenerate');
						}
						else
						{
							awnselp.remove();
							awnselptcha.remove();
							awnsered.css('width', '100%').attr('disabled', 'disabled');
							
						}
						break;
					case 'regenerate':
						app.captcha('generate');
						awnsered.css('width', '75%').removeAttr('disabled', 'disabled').trigger('focus');
						break;
					default:
						for(var i = 0; i <= 6; i++)
						{
							var a = captcha[Math.floor(Math.random() * captcha.length)], b = captcha[Math.floor(Math.random() * captcha.length)], c = captcha[Math.floor(Math.random() * captcha.length)], d = captcha[Math.floor(Math.random() * captcha.length)], e = captcha[Math.floor(Math.random() * captcha.length)], f = captcha[Math.floor(Math.random() * captcha.length)];
						}
						code = (captchas.length && app.is_array(captchas) ? app.random(captchas.filter(function(val){return val !== app.code('decrypt', awnser.val())})) : (a + b + c + d + e + f));
						awnser.val(app.code('encrypt', code));
						awnsered.val('');
						awnseresponse.html(('<span>' + code.split('').join('</span><span>') + '</span>'));
						awnseresponse.find('span').each(function()
						{
							rotate = (rotate+5);
							$(this).css({
								'-webkit-transform': 'rotate(' + rotate + 'deg)',
								'transform': 'rotate(' + rotate + 'deg)',
								'display': 'inline-block',
								'font-size': sizes[Math.floor(Math.random()*sizes.length)],
								'font-weight': weights[Math.floor(Math.random()*weights.length)]
							}).after('<span style="padding: 0px; font-size: 8px; color: #fff;">' + captcha[Math.floor(Math.random()*captcha.length)] + '</span>');
						});
				}
			}
		},
		check: function(type, value)
		{
			//console.log(type + ' : ' + value);
			if(type === 'address')
			{
				var values = value.split('|'), address, number = values[1], postal = values[0];
				if(postal.length === 4)
				{
					// 3500 = Hasselt
					postal += ',+Belgium|country:BE';
				}
				else if(postal.length === 5)
				{
					// 20038 = Dresden
					postal += ',+Germany|country:DE';
				}
				else if(postal.length === 6)
				{
					// 2033CS2 = Haarlem
					postal += ',+Netherlands|country:NL';
				}
				else 
				{
					return false;
				}
				var lat, lng, street, city, country;
				//console.log('1: https://maps.googleapis.com/maps/api/geocode/json?address=' + postal + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false');
				//console.log('2: https://maps.googleapis.com/maps/api/geocode/json?address=' + app.urlencode(postal) + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false');
				$.getJSON('https://maps.googleapis.com/maps/api/geocode/json?address=' + app.urlencode(postal) + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false', function(data)
				{
					lat = data.results[0].geometry.location.lat, lng = data.results[0].geometry.location.lng;
				}).then(function(data)
				{
					if(data.results[0].geometry)
					{
						$.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false').done(function(data)
						{
							//console.dir(data);
							address = data.results[0].address_components;

							street = address[1].long_name;
							city = (address[2].long_name === street ? address[3].long_name : address[2].long_name);
							key = (address.length-2), country = (address[key].long_name == 'Netherlands' ? 'Nederland' : (address[key].long_name == 'Belgium' ? 'België' : (address[key].long_name == 'Germany' ? 'Duitsland' : address[key].long_name)));
							//console.log(key + ': ' + country);
							if(app.in_array(country, ['Nederland', 'België', 'Duitsland']))
							{
								$('#avia_4_1').val(number);
								$('#avia_5_1').val(street);
									$('#avia_5_1').css('border', '1px solid #4caf50');
									app.timeout($('#avia_5_1'), 'border', '1px solid #b7b7b7', 5000);
								$('#avia_6_1').val(city);
									$('#avia_6_1').css('border', '1px solid #4caf50');
									app.timeout($('#avia_6_1'), 'border', '1px solid #b7b7b7', 5000);
								$('#avia_7_1').val(country);
									$('#avia_7_1').css('border', '1px solid #4caf50');
									app.timeout($('#avia_7_1'), 'border', '1px solid #b7b7b7', 5000);
								$('input[type=text], textarea').trigger('blur');
							}
							else
							{
								$('#avia_3_1').val('');
								$('#avia_4_1').val('');
								$('#avia_5_1').val('');
								$('#avia_6_1').val('');
								$('#avia_7_1').val('Nederland');
							}
						}).done(function(data)
						{
							return true;
						});
					}
				});
			}
			else if(type === 'address2')
			{
				var values = value.split('|'), address, number = values[1], postal = values[0];

				if(postal.length === 4)
				{
					// 3500 = Hasselt
					postal += ',+Belgium|country:BE';
					//postal += '|country:BE';
				}
				else if(postal.length === 5)
				{
					// 20038 = Dresden
					postal += ',+Germany|country:DE';
					//postal += '|country:DE';
				}
				else if(postal.length === 6)
				{
					// 2033CS2 = Haarlem
					postal += ',+Netherlands|country:NL';
					//postal += '|country:NL';
				}
				else 
				{
					return false;
				}
				var lat, lng, street, city, country;
				//console.log('https://maps.googleapis.com/maps/api/geocode/json?address=' + app.urlencode(postal) + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false');
				$.getJSON('https://maps.googleapis.com/maps/api/geocode/json?address=' + app.urlencode(postal) + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false', function(data)
				{
					lat = data.results[0].geometry.location.lat, lng = data.results[0].geometry.location.lng;
				}).then(function(data)
				{
					if(!data.results[0].address_components)
					{
						$('input[name="_postal"]').val('');
						$('input[name="_number"]').val('');
						$('input[name="_street"]').val('');
						$('input[name="_city"]').val('');
						$('select[name="_country"]').val('Nederland');
					}
					else
					{
						$.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + app.urlencode(lat) + ',' + app.urlencode(lng) + '&key=AIzaSyAgJW_iwxe604ZU82V6Cya7NQ1aXk3oQl8&sensor=false').done(function(data)
						{
							//console.dir(data);
							address = data.results[0].address_components;
							
							street = address[1].long_name;
							city = (address[2].long_name === street ? address[3].long_name : address[2].long_name);
							key = (address.length-2), country = (address[key].long_name == 'Netherlands' ? 'Nederland' : (address[key].long_name == 'Belgium' ? 'België' : (address[key].long_name == 'Germany' ? 'Duitsland' : address[key].long_name)));
							//console.log(key + ': ' + country);
							if(app.in_array(country, ['Nederland', 'België', 'Duitsland']))
							{
								$('input[name="_number"]').val(number);
								$('input[name="_street"]').val(street);
									$('input[name="_street"]').css('border', '1px solid #4caf50');
									app.timeout($('input[name="_street"]'), 'border', '1px solid #b7b7b7', 5000);
								$('input[name="_city"]').val(city);
									$('input[name="_city"]').css('border', '1px solid #4caf50');
									app.timeout($('input[name="_city"]'), 'border', '1px solid #b7b7b7', 5000);
								$('select[name="_country"]').val(country).trigger('change');
									$('select[name="_country"]').css('border', '1px solid #4caf50');
									app.timeout($('select[name="_country"]'), 'border', '1px solid #b7b7b7', 5000);
							}
							else
							{
								$('input[name="_postal"]').val('');
								$('input[name="_number"]').val('');
								$('input[name="_street"]').val('');
								$('input[name="_city"]').val('');
								$('select[name="_country"]').val('Nederland');
							}
						});
					}
				}).done(function(data)
				{
					return true;
				});
			}
			else if(type === 'iban')
			{
				var lengths = {
					AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29, CH: 21, CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24, FI: 18, FO: 18, FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21, HU: 28, IE: 22, IL: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28, LI: 21, LT: 20, LU: 20, LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27, MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29, RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24, SM: 27, TN: 24, TR: 26
				};
				var iban = String(value).toUpperCase().replace(/[^A-Z0-9]/g, ''), code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/), digits;
				if(!code || iban.length !== lengths[code[1]])
				{
					return false;
				}
				digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function(letter)
				{
					return (letter.charCodeAt(0)-55);
				});
				return (app.check('ibanalize', digits) === 1);
			}
			else if(type === 'ibanalize')
			{
				var checksum = value.slice(0, 2), fragment;
				for(var offset = 2 ; offset < value.length ; offset += 7)
				{
					fragment = String(checksum) + value.substring(offset, offset + 7);
					checksum = parseInt(fragment, 10) % 97;
				}
				return checksum;
			}
			else if(type === 'imei')
			{
				if(/^[0-9]{15}$/.test(value))
				{
					var m = 2, l = 14, s = 0;
					value = value.replace(/\s+/g, '');
					for (i = 0; i < l; i++)
					{
						digit = value.substring(l-i-1, l-i);
						tp = parseInt(digit,10)*m;
						if(tp >= 10)
						{
							s += (tp % 10) +1;
						}
						else
						{
							s += tp;
						}
						if(m == 1)
						{
							m++;
						}
						else
						{
							m--;
						}
					}
					chk = ((10 - (s % 10)) % 10);
					return (chk == parseInt(value.substring(14, 15), 10));
				}
				return false;
			}
			else if(type === 'phone')
			{
				number = app.phone(value);
				if(app.test(number, app.pattern('phone')))
				{
					return number;
				}
				return '';
			}
			else if(type === 'postal' && app.test(value, app.pattern('postal')))
			{
				return (app.test(value, app.pattern('postal', (config.user ? false : 'local'))) ? value.toUpperCase() : false);
			}
			else if(type === 'postal2' && app.test(value, app.pattern('postal')))
			{
				return value.toUpperCase();
			}
			else if(app.in_array(type, ['MX', 'KVK', 'BE', 'DE', 'NL']))
			{
				return $.ajax({
					url: 'https://' + config.domain + '/wp-admin/admin-ajax.php?type=' + type + '&value=' + value,
					type: 'GET',
					global: false,
					data: {
						action: 'validate'
					},
					dataType: 'json'
				});
			}
			else if(type === 'pwnd')
			{
				// url: 'https://haveibeenpwned.com/api/v2/pwnedpassword/' + encodeURIComponent(value), 
				return $.ajax({ 
					url: 'https://haveibeenpwned.com/api/v2/breachedaccount/' + encodeURIComponent(value),
					crossDomain: true,
					dataType: 'json'
				});
			}
			else if(type === 'facts')
			{
				if(config.page === 'idevices')
				{
					if(typeof $('select[name="merk"] option:selected').val() != 'undefined')
					{
						var merk = $('select[name="merk"] option:selected').val(), model = $('input[name="model"]').val(), value = $('select[name="starts"] option:selected').val();
						if(merk == 'Apple')
						{
							return true;
						}
						else if(merk == 'AppleTV')
						{
							return true;
						}
						else if(merk == 'AppleTV')
						{
							return true;
						}
						else if(merk == 'iPhone')
						{
							if($('input[type="checkbox"][name="facetime"]:checked').length > 0 && value < 2011)
							{
								$('input[type="checkbox"][name="facetime"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2011 heeft Apple de eerste betá van facetime gelanceerd, een apparaat uit ' + value + ' kán dus geen facetime ondersteunen!');
							}
							if($('input[type="checkbox"][name="facetime"]:checked').length > 0 && value < 2011)
							{
								$('input[type="checkbox"][name="facetime"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2011 heeft Apple de eerste betá van facetime gelanceerd, een apparaat uit ' + value + ' kán dus geen facetime ondersteunen!');
							}
							if($('input[type="checkbox"][name="gps"]:checked').length > 0 && value < 2008)
							{
								$('input[type="checkbox"][name="gps"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2008 heeft Apple het eerste apparaat met GPS gelanceerd, een apparaat uit ' + value + ' kán dus geen GPS ondersteunen!');
							}
							if($('input[type="checkbox"][name="nfc"]:checked').length > 0 && value < 2014)
							{
								$('input[type="checkbox"][name="nfc"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2014 heeft Apple het eerste apparaat met NFC gelanceerd, een apparaat uit ' + value + ' kán dus geen NFC ondersteunen!');
							}
							if($('input[type="checkbox"][name="retina"]:checked').length > 0 && value < 2012)
							{
								$('input[type="checkbox"][name="retina"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2012 heeft Apple het eerste product, de was de iPhone 5, met een Retina scherm uitgebracht, een apparaat uit ' + value + ' kán dus geen Retina scherm bezitten!');
							}
							if($('input[type="checkbox"][name="siri"]:checked').length > 0 && value < 2011)
							{
								$('input[type="checkbox"][name="siri"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2010 was Siri als App gelanceerd, waarna Apple het heeft gekocht om vanaf 2011 te itegreren in iOS, een apparaat uit ' + value + ' kán dus geen Siri ondersteunen!');
							}
							if($('input[type="checkbox"][name="watch"]:checked').length > 0 && value < 2014)
							{
								$('input[type="checkbox"][name="watch"]').attr('checked', false);
								app.popupper('Helaas!', 'In 2014 heeft Apple de eerste Watch gelanceerd, een apparaat uit ' + value + ' kán dus geen Watch ondersteunen!');
							}
							return true;
						}
						else if(merk == 'iPad')
						{
							/*
							if(model.slice(-1) !== '+' && ($('select[name="network"] option:selected').val() !== '' || $('input[type="checkbox"][name="gps"]:checked').length < 0 || $('select[name="sim"] option:selected').val() !== '-'))
							{
								app.popupper('Helaas!', 'Als een iPad wél een GPS/SIM module bevat, moet het model eindigen op een "+", dit om verwarring te voorkomen!');
								$('input[name="model"]').focus();
								return false;
							}
							else if(model.slice(-1) === '+' && ($('select[name="network"] option:selected').val() === '' || $('input[type="checkbox"][name="gps"]:checked').length < 0 || $('select[name="sim"] option:selected').val() === '-'))
							{
								app.popupper('Helaas!', 'Als een iPad géén een GPS/SIM module bevat, mag het model niet eingigen op een "+", dit om verwarring te voorkomen!');
								$('input[name="model"]').focus();
								return false;
							}
							*/
							return true;
						}
						else if(merk == 'iPod')
						{
							return true;
						}
						else if(merk == 'MacBook')
						{
							return true;
						}
						else if(merk == 'iMac')
						{
							return true;
						}
						else if(merk == 'Sony')
						{
							//popupper('Helaas!', 'Dit merk is gereserveerd voor debugging!');
							return true;
						}
						else
						{
							return true;
						}
					}
					else
					{
						return true;
					}
				}
				else
				{
					return true;
				}
			}
			//return false;
		},
		code: function(action, string)
		{
			var key = 146, pos = 0, result = '';
			string = (!string || string == 'undefined' || string == 'null' ? '' : string);
			switch(action)
			{
				case 'ascii':
					for(i = 0; i < string.length; i++)
					{
						var c = '' + s.charCodeAt(i);
						while(c.length < 3)
						{
							c = '0' + c;
						}
						result += c;
					}
					return result;
					break;
				case 'encrypt':
					try {
						while(pos < string.length)
						{
							result = result + String.fromCharCode(string.charCodeAt(pos) ^ key);
							pos += 1;
						}
						return result;
					}
					catch(ex)
					{
						return '';
					}
					break;
				case 'decrypt':
				default:
					try {
						while(pos < string.length)
						{
							result = result + String.fromCharCode(key ^ string.charCodeAt(pos));
							pos += 1;
						}
						return result;
					}
					catch (ex)
					{
						return '';
					}
					break;
			}
		},
		cookie: function(name, value, expires)
		{
			//value = (app.empty(value) ? false : value);
			if(value === false)
			{
				return (document.cookie = encodeURIComponent(name) + '=; expires=-1; path=/');
			}
			else if(app.empty(value))
			{
				//return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, "$&") + "s*=s*([^;]*).*$)|^.*$"), "$1")) || null);
				var name = encodeURIComponent(name) + '=';
				var cookies = document.cookie.split(';');
				for(var i = 0; i < cookies.length; i++)
				{
					var cookie = cookies[i];
					while(cookie.charAt(0) === ' ')
					{
						cookie = cookie.substring(1, cookie.length);
					}
					if(cookie.indexOf(name) === 0)
					{
						return decodeURIComponent(cookie.substring(name.length, cookie.length));
					}
				}
				return null;
			}
			else
			{
				if(expires)
				{
					if(expires instanceof Date)
					{
						if(isNaN(expires.getTime()))
						{
							expires = new Date();
						}
					}
					else if(app.is_numeric(expires))
					{
						expires = config.date.setDate(config.date.getDate()+expires);
					}
					else
					{
						expires = config.date.getTime() + (parseInt(expires) * 1000 * 60 * 60 * 24);
					}
				}
				document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=/';
				return true;
			}
		},
		cookies: function(name, value, expires)
		{
			result = false;
			//value = (app.empty(value) ? '' : value);
			expires = (app.empty(expires) ? '-1 hour' : expires);
			//console.log(value + ' : ' + expires);
			if(value === false)
			{
				
				$.each(['irepair.nu', 'iphonerepair.nu', 'ipadrepair.nu', 'macbookrepair.nu', 'imacrepair.nu'], function(i, domain)
				{
					$('body').append('<img src="https://' + domain + '/?host=' + config.domain + '&cookie=' + name + '&expires=' + expires + '&timestamp=' + new Date().getTime() + '" style="display:none;">');
				});
			}
			else if(app.empty(value))
			{
				//app.cookies('language');
				$.each(['irepair.nu', 'iphonerepair.nu', 'ipadrepair.nu', 'macbookrepair.nu', 'imacrepair.nu'], function(i, domain)
				{
					$('body').append('<img src="https://' + domain + '/?host=' + config.domain + '&cookie=' + name + '&timestamp=' + new Date().getTime() + '" style="display:none;">');
				});
				/*
					$.get('https://irepair.nu/?host=' + config.domain + '&cookie=' + name, function(data)
					{
						//console.log('Get ' + name + ': ' + data);
						result = (app.empty(data) ? false : data);
					});
				*/
			}
			else
			{
				//app.cookies('language', 'nl', '+1 year');
				$.each(['irepair.nu', 'iphonerepair.nu', 'ipadrepair.nu', 'macbookrepair.nu', 'imacrepair.nu'], function(i, domain)
				{
					$('body').append('<img src="https://' + domain + '/?host=' + config.domain + '&cookie=' + name + '&value=' + value + '&expires=' + expires + '" style="display:none;">');
				});
				/*
					$.get('https://irepair.nu/?host=' + config.domain + '&cookie=' + name + '&value=' + value + '&expires=' + expires, function(data)
					{
						//console.log('Set: ' + name + ': ' + data);
						result =   (app.empty(data) ? false : data);
					});
				*/
			}
				/*
				setTimeout(function()
				{
					app.apply(true);
					//return true;
				}, 500);
				*/
		},
		apply: function(bool)
		{
			return bool;
		},
		language: function()
		{
			if(!app.cookie('language'))
			{
				app.cookie('language', 'nl', 365);
			}
			/*
				var x = app.cookies('language');
				//console.log(x);
				if(!x)
				{
					app.cookies('language', 'nl', '+1 year');
				}
			*/
			app.languages();
		},
		languages: function()
		{
			var form = $('div#country-select form'), source = $('#country-options'), selected = source.find('option:selected'), options = $('option', source);
			form.hide();
			source.removeAttr('autocomplete');
			$('#country-select').append('<dl id="target" class="dropdown"></dl>');
			$('#target').append('<dt class="' + selected.val() + '"><a href="#"><span class="flag"></span><em>' + selected.text() + '</em></a></dt>');
			$('#target').append('<dd><ul></ul></dd>');
			options.each(function(i, e)
			{
				if(e.value != selected.val())
				{
					$('#target dd ul').append('<li class="' + $(this).val() + '"><a href="/"><span class="flag"></span><em>' + $(this).text() + '</em></a></li>');
				}
			});
		},
		darkmode: function(state)
		{
			state = (state || 'off');
		},
		dates: function(date, action)
		{
			// app.dates('2016, 11, 16', 'before');
			date = new Date(date);
			switch(action)
			{
				case 'before':
					return new Date(date.toDateString()) < new Date(new Date().toDateString());
				default:
					return false;
			}
		},
		dialogs: function()
		{
			$('.ui-dialog-content:visible').each(function(e)
			{
				var dialog = $(this).closest('.ui-dialog:visible'), height = $(window).height(), width = $(window).width();
				$(this).dialog('option', 'position', $(this).dialog('option', 'position'));
				$(this).css({'max-height': (height-50)});
				//$(dialog).css('top', (height <= 768 ? '25px' : '150px'));
				$(dialog).find('.ui-dialog-titlebar').css({'width': (config.admin ? $(this).width() : $(dialog).width())});
				$(dialog).scrollTop(0);
			});
		},
		empty: function(str)
		{
			return (typeof str == 'string' && !str.trim() || typeof str == 'object' && !str.length || typeof str == 'undefined' || str === null);
		},
		endswith: function(str, value)
		{
			return (app.empty(str) || !str.endsWith(value) ? false : true);
		},
		fullscreen: function()
		{
			if(app.is_mobile())
			{
				setTimeout(function(e)
				{
					$(window).scrollTo(0, 0);
				}, 0);
			}
		},
		in_array: function(search, array)
		{
			return  ($.inArray(search, array) != -1);
		},
		is_array: function(array)
		{
			return  ($.isArray(array) || app.typeOf(array) === 'array' ? true : false);
		},
		is_numeric: function(str)
		{
			return /^\d+$/.test(str);
		},
		numerics: function(e)
		{
			var key = (e.keyCode ? e.keyCode : e.which);
			//console.log(key + ' : ' + e.shiftKey);
			if($.inArray(key, [46, 8, 9, 27, 13, 110, 190]) !== -1 || (key == 65 && (e.shiftKey == true || e.metaKey == true)) || (key == 53 && e.shiftKey == true) || (key >= 35 && key <= 40))
			{
				// Allow: backspace, delete, tab, escape, enter and period
				// Allow: Shift+5, Command+5
				// Allow: Ctrl+A, Command+A
				// Allow: home, end, left, right, down, up
				return true;
			}
			if ((e.shiftKey || (key < 48 || key > 57)) && (key < 96 || key > 105))
			{
				return false;
			}
			return true;
		},
		is_decimal: function(str)
		{
			return (str === parseInt(str, 10));
		},
		is_mobile: function()
		{
			return (typeof $(window).orientation !== 'undefined' ? true : false);
		},
		stripos: function(haystack, needle, bool, offset)
		{
			haystack = (haystack || '');
			needle = (needle || '');
			bool = (bool || true);
			offset = (offset || 0);
			var i = ('' + haystack.toLowerCase() + '').indexOf(needle.toLowerCase(), offset);
			return (i === -1 ? false : (bool ? true : i));
		},
		jsobjects: function(obj, key, val)
		{
			var newObj = false; 
			$.each($.parseJSON(obj), function()
			{
				var testObject = this; 
				$.each(testObject, function(k,v)
				{
					if(val == v && k == key)
					{
						newObj = testObject;
					}
				});
			});
			return newObj;
		},
		pattern: function(regex, limit)
		{
			limit = (app.empty(limit) ? false : limit);
			limits = (!app.in_array(regex, ['finance', 'storages']) && /^([0-9]+)?,([0-9]+)$/.test(limit) ? true : false);
			switch(regex)
			{
				case 'alpha':
					regex = (limits ? '^[A-zÀ-ÿ]{' + limit + '}$' : '^[A-zÀ-ÿ]+$');
					break;
				case 'numeric':
					regex = (limits ? '^[0-9]{' + limit + '}$' : '^[0-9]+$');
					break;
				case 'alphanumeric':
					regex = (limits ? '^[A-zÀ-ÿ0-9\\s/\\-,\\.]{' + limit + '}$' : '^[A-zÀ-ÿ0-9\\s/\\-,\\.]+$');
					break;
				case 'plain':
					regex = (limits ? '^[A-zÀ-ÿ0-9\\s/,\/\\.\\+\\*\\?\\(\\)\\=\\!\\:\\;\\&#€@\\%\\-]{' + limit + '}$' : '^[A-zÀ-ÿ0-9\\s/,\/\\.\\+\\*\\?\\(\\)\\=\\!\\:\\;\\&#€@\\%\\-]+$');
					break;
				case 'textarea':
					regex = (limits ? '^[A-zÀ-ÿ0-9\\s/,\/\\.\\+\\*\\?\\(\\)\\=\\!\\:\\;\\&#€@\\%\\-\\r\\n\\t\\<\\>]{' + limit + '}$' : '^[A-zÀ-ÿ0-9\\s/,\/\\.\\+\\*\\?\\(\\)\\=\\!\\:\\;\\&#€@\\%\\-\\r\\n\\t\\<\\>]+$');
					break;
				case 'decimal':
					regex = '^\s*|0|[0-9]{1,}(.\d{0,2})?$';
					break;
				case 'euro':
					regex = '^\\€ \\-?[0-9]*[0-9]\\.?[0-9]{0,2}$';
					break;
				case 'discount':
					regex = '^(\\-?[0-9]*[0-9]((\\.|,)[0-9]{0,2})?|([1-9]|[1-6][0-9]|7[0-5])((\\.|,)[0-9]{0,2})?\\%)$';
					break;
				case 'email':
					regex = '^(?=[A-z0-9][A-z0-9@._%+-]{5,253}$)[A-z0-9._%+-]{1,64}@(?:(?=[A-z0-9-]{1,63}\\.)[A-z0-9]+(?:-[A-z0-9]+)*\\.){1,8}[A-z]{2,63}$';
					break;
				case 'hours':
					regex = '^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$';
					break;
				case 'postal':
					/*
						Regio's: Antwerpen (BE), Luik (BE), Limburg (BE & NL), Zuidoost Brabant (NL) én Noord-Rijnland (DE)
						^(((?:B-?)?[2-4][0-9]{3})|((?:D-?)?((4[0-2])|47|(5[0-4])|56)[0-9]{3})|((?:NL-?)?[5|6][0-4][0-9]{2}\\s?[A-z]{2}))$
						^((?:B-?)?[1-9][0-9]{3}|(?:D-?)?[1-9][0-9]{4}|(?:NL-?)?[1-9][0-9]{3}(\\s?[A-z]{2}))?$
						OR
						value = value.replace(/(\s|^(B-?|D-?|NL-?))/ig, '');
						//console.log(value);
					*/
					regex = (limit == 'local' ? '^^(((2([2-4]{1})|3([1-9]{1})|4([1-9]{1}))[0-9]{2})|(((4[0-2])|47|(5[0-4])|56)[0-9]{3})|((5[02-9]|6[0-4])[0-9]{2}\\s?[A-z]{2}))$' : '^([1-9][0-9]{3}|[1-9][0-9]{4}|[1-9][0-9]{3}(\\s?[A-z]{2}))?$');
					break;
				case 'numbers':
					regex = '^[\+]?[(]?[0-9]{2,3}[)]?[-\s\.]?[0-9]{1,4}[-\s\.]?[0-9]{2,9}$';
					break;
				case 'storages':
					regex = '^[1-9]{1,3}[A-Z]{2}$';
					break;
				case 'address':
					regex = '^([1-9][e][\\s])*([A-zÀ-ÿ]+(([\\.][\\s])|([\\s]))?)+[1-9][0-9]*(([-][1-9][0-9]*)|([\\s]?[A-zÀ-ÿ]+))?$';
					break;
				case 'phone':
					regex = '(^\\+[0-9]{2}|^\\+[0-9]{2}\\(0\\)|^\\(\\+[0-9]{2}\\)\\(0\\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\\-\\s]{10}$)';
					break;
				case 'IBAN':
					regex = '^[A-z]{2}[0-9]{2}[A-z0-9]{4}[0-9]{7}([A-z0-9]?){0,16}$';
					break;
				case 'KVK':
					regex = '^[0-9]{8}$';
					break;
				case 'BE':
					regex = '^(BE)?0[0-9]{9}$';
					break;
				case 'DE':
					regex = '^(DE)?[0-9]{9}$';
					break;
				case 'NL':
					regex = '^(NL)?[0-9]{9}B[0-9]{2}$';
					break;
				default:
					regex = (limits ? '^[' + regex + ']{' + limit + '}$' : '^[' + regex + ']+$');
					break;
			}
			return regex;
			//return app.replace(regex);
			//return '/' + regex + '/';
		},
		phone: function(value)
		{
			var prefixes = {'België': '+32', 'Duitsland': '+49', 'Nederland': '+31'};
			number = value.replace(/[^\d+]+/g, ''), number = number.replace(/^00/, '+');
			if(number !== '')
			{
				if(number.match(/^0/))
				{
					number = ($('select[name="_country"]').length ? prefixes[$('select[name="_country"] option:selected').val()] : '+31') + number.substr(1);
				}
				else if(number.match(/^32/) || number.match(/^\+32/))
				{
					number = number.replace(/^32/, '+32');
					if($('select[name="_country"]').length)
					{
						$('select[name="_country"]').val('België').trigger('change');
					}
				}
				else if(number.match(/^49/) || number.match(/^\+49/))
				{
					number = number.replace(/^49/, '+49');
					if($('select[name="_country"]').length)
					{
						$('select[name="_country"]').val('Duitsland').trigger('change');
					}
				}
				else
				{
					number = number.replace(/^31/, '+31');
					if($('select[name="_country"]').length)
					{
						$('select[name="_country"]').val('Nederland').trigger('change');
					}
				}
				return (!number.match(/^\+/) ? ($('select[name="_country"]').length ? prefixes[$('select[name="_country"] option:selected').val()] : '+31') + number : number);
			}
			return value;
		},
		popformer: function(target, action, info)
		{
			//console.dir(info);
			//info.device = (empty(info.device) ? config.device : info.device);
			
			var autocomplete = '<ul class="linput">' +
				'<li><abbr class="muted">Begin met typen..</abbr></li>' +
			'</ul>' +
			'<small class="pull-right muted">Dit is een bétaversie!</small>',
			device = app.jsobjects(config.devices, 'nummer', info.device), options = unique = [],
			istart, iclient, iemailaddress, iphone, icompany, iaddress, idevinfo, iprivacy, icatalogus, iappointments, iperiod, ireceipt, ioffers, ireviews, idevider, iverify, iend,
			readonly = (target === 'ioffers' && app.role(['admin', 'administrator', 'developer']) && !app.empty(info.rules) ? true : false);

			$.each($.parseJSON(config.devices), function(i, value)
			{
				if(!app.in_array(value.merk + ' ' + value.model, unique))
				{
					options['devices'] += '<option value="' + value.nummer + '" ' + (value.nummer == info.device ? 'selected="selected"' : '') + '>' + value.nummer.substr(0, 5) + ' - ' + value.merk + ' ' + value.model + '</option>';
					unique.push(value.merk + ' ' + value.model);
				}
			});

			istart = '<form id="popformer" name="' + target + '" novalidate="novalidate">' +
				'<input type="hidden" name="_id" value="0" />' +
				'<input type="hidden" name="_cid" value="0" />' +
				'<input type="hidden" name="_discount" value="0" />' +
				'<input type="hidden" name="_roles" value="' + config.roles.join(',') + '" />' +
				'<input type="hidden" name="_ipaddress" value="' + config.ipaddress + '" />';

			iclient = '<div class="form-item">' +
				'<label for="_name">' + (app.role(['admin', 'administrator', 'developer']) && !app.in_array(target, ['iprivacy'])  ? 'Klant' : 'Naam') + ':</label>' +
				'<input type="text" name="_name" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : (app.empty(info.name) ? '' : 'value="' + info.name + '"')) + ' placeholder="' + (app.role(['admin', 'administrator', 'developer']) && !app.in_array(target, ['iprivacy']) ? 'Naam, telefoonnummer óf e-mailadres..' : 'Piet Janssen') + '" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" data-source="manual" required="required" ' + (readonly ? 'data-readonly="" readonly="readonly"' : '') + ' />';
				if(!readonly && app.role(['admin', 'administrator', 'developer']) && !app.in_array(target, ['iprivacy'])){
					iclient += '<div id="_names" class="linput">' + autocomplete + '</div>';
				}
			iclient += '</div>';

			iemailaddress = '<div class="form-item">' +
				'<label for="_emailaddress">E-mailadres:</label><br />';
				if(app.role(['admin', 'administrator', 'developer'])){
					if(app.in_array(target, ['iappointments']))
					{
						iemailaddress += '<input type="email" name="_emailaddress" placeholder="mail@domein.ext" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" style="float: left; width: 75%" />' +
						'<div style="text-align: center; vertical-align: middle;">' +
							'<label class="switch">' +
								'<input type="checkbox" name="_notify" ' + (app.dates(info.year + ', ' + info.month + ', ' + info.day, 'before') ? 'disabled="disabled"' : 'checked="checked"') + ' style="float: left; width: 25%" tabindex="-1" />' +
								'<div class="slider round"></div>' +
							'</label>' +
						'</div>';
					}
					else if(app.in_array(target, ['iprivacy', 'ireviews']))
					{
						iemailaddress += '<input type="email" name="_emailaddress" placeholder="mail@domein.ext" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />';
					}
					else
					{
						iemailaddress += '<input type="email" name="_emailaddress" placeholder="mail@domein.ext" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />';
					}
				} else {
					iemailaddress += '<input type="email" ' + (app.empty(info.emailaddress) ? '' : 'value="' + info.emailaddress + '"') + ' name="_emailaddress" placeholder="mail@domein.ext" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" />' + 
					'<input type="hidden" name="_notify" checked="checked" />';
				}
			iemailaddress += '</div>';

			iphone = '<br style="clear: both;"><div class="form-item">' +
				'<label for="_phone">Telefoonnummer:</label>' +
				'<input type="text" name="_phone" placeholder="+31612345678" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
			'</div>';
			icompany = iaddress = '';
			/*
				icompany = '<div class="accordion">' +
					'<input id="accordion-one" type="checkbox" name="accordions">' +
					'<label for="accordion-one">Bedrijfsgegevens <sup class="muted pull-right" style="padding-right: 50px;">Optioneel</sup></label>' +
					'<div class="accordion-content">' +
						'<div class="form-item">' +
							'<label for="_vat">BTW: <span class="state pull-right">&nbsp;</span></label>' +
							'<input type="text" name="_vat" placeholder="NL123456789B01" tabindex="-1" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_kvk">KVK: <span class="state pull-right">&nbsp;</span></label>' +
							'<input type="text" name="_kvk" placeholder="12345678" tabindex="-1" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_company">Bedrijfsnaam:</label>' +
							'<input type="text" name="_company" placeholder="Bedrijf B.V." tabindex="-1" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
					'</div>' +
				'</div>' +
				'<br />';
				icompany = '';
			*/
			if(target === 'ioffers')
			{
				iaddress = '<div class="form-item">' +
							'<label for="_postal">Postcode:</label>' +
							'<input type="text" name="_postal" placeholder="6017BR" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_number">Huisnummer:</label>' +
							'<input type="text" name="_number" placeholder="33" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_street">Straat:</label>' +
							'<input type="text" name="_street" placeholder="Casino" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_city">Plaats:</label>' +
							'<input type="text" name="_city" placeholder="Thorn" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_country">Land:</label>' +
							'<select name="_country" id="_country" required="required" ' + (readonly ? 'disabled="disabled"' : '') + '>' +
								'<option value="Nederland" selected="selected">Nederland</option>' +
								'<option value="België">België</option>' +
								'<option value="Duitsland">Duitsland</option>' +
							'</select>' +
						'</div>' +
				'<br />';
			}
			else
			{
				iaddress = '<div class="accordion">' +
					'<input id="accordion-two" type="checkbox" name="accordions">' +
					'<label for="accordion-two">Adresgegevens <sup class="muted pull-right" style="padding-right: 50px;">Optioneel</sup></label>' +
					'<div class="accordion-content">' +
						'<div class="form-item">' +
							'<label for="_postal">Postcode:</label>' +
							'<input type="text" name="_postal" placeholder="6017BR" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_number">Huisnummer:</label>' +
							'<input type="text" name="_number" placeholder="33" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_street">Straat:</label>' +
							'<input type="text" name="_street" placeholder="Casino" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_city">Plaats:</label>' +
							'<input type="text" name="_city" placeholder="Thorn" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />' +
						'</div>' +
						'<div class="form-item">' +
							'<label for="_country">Land:</label>' +
							'<select name="_country" id="_country">' +
								'<option value="Nederland" selected="selected">Nederland</option>' +
								'<option value="België">België</option>' +
								'<option value="Duitsland">Duitsland</option>' +
							'</select>' +
						'</div>' +
					'</div>' +
				'</div>'+
				'<br />';
			}
			if(app.in_array(target, ['ioffers', 'ireceipt']))
			{
				idevinfo = '<div class="form-item">' +
					'<label for="_serie">IMEI- of serienummer: <span class="state pull-right">&nbsp;</span></label>' +
					'<input type="text" name="_serie" placeholder="X0XXX0X000XX" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" ' + (readonly ? 'readonly="readonly"' : '') + ' />' +
				'</div>' +
				'<div class="accordion">' +
					'<input id="accordion-three" type="checkbox" name="accordions">' +
					'<label for="accordion-three">Specificaties <sup class="muted pull-right" style="padding-right: 50px;">Optioneel</sup></label>' +
					'<div class="accordion-content">';
						names = ['Kleur', 'Processor', 'Werkgeheugen', 'Opslag'];
						var items = {};
						items['Kleur'] = 'colors';
						if(app.role(['admin', 'administrator', 'developer'])){
							items['Processor'] = 'processor';
							items['Werkgeheugen'] = 'ram';
						}
						items['Opslag'] = 'storage';
						$.each(items, function(key, values)
						{
							var name = (app.in_array(values, ['colors']) ? values.slice(0, -1) : values);
							idevinfo += '<div class="form-item">' +
								'<label for="_' + name + '">' + key + ': <span class="state pull-right">&nbsp;</span></label>' +
								'<select name="_' + name + '" style="float: left;" ' + (readonly ? 'disabled="disabled"' : '') + '>' +
									'<option value="">-</option>';
									if(device[values])
									{
										if(device[values].indexOf(',') > -1)
										{
											$.each(device[values].split(','), function(key, value)
											{
												idevinfo += '<option value="' + value + '">' + app.ucfirst(value) + '</option>';
											});
										}
										else
										{
											idevinfo += '<option value="' + device[values] + '">' + app.ucfirst(device[values]) + '</option>';
										}
									}
								idevinfo += '</select>' +
							'</div>';
						});
					idevinfo += '</div>' +
				'</div>' +
				'<br />';
			}
			else if(app.in_array(target, ['icatalogus']))
			{
				i = 0;
				idevinfo = '';
				names = ['Kleur', 'Werkgeheugen', 'Opslag'];
				var items = {};
				items['Kleur'] = 'colors';
				if(app.in_array(info.merk, ['MacBook', 'iMac']))
				{
					items['Werkgeheugen'] = 'ram';
					items['Opslag'] = 'storage';
				}
				rams = [0, 230];
				storages = [0, 230, 460, 920];

				$.each(items, function(keys, values)
				{
					var name = (app.in_array(values, ['colors']) ? values.slice(0, -1) : values);
					idevinfo += '<div class="form-item">' +
						'<label for="_' + name + '">' + keys + ': <span class="state pull-right">&nbsp;</span></label>' +
						'<select name="_' + name + '" style="float: left;" required="required">';
							if(device[values])
							{
								if(device[values].indexOf(',') > -1)
								{
									devices = device[values].split(',');
									if(keys == 'Opslag')
									{
										if(info.device == 'A2438' && info.storage == '512GB')
										{
											storages = [0, 230, 690];
											devices.shift();
										}
										else if(info.device == 'A2338' && info.storage == '512GB')
										{
											storages = [0, 230, 690];
											devices.shift();
										}
									}									
									$.each(devices, function(key, value)
									{
										if(keys == 'Werkgeheugen')
										{
											idevinfo += '<option value="' + value + '">' + app.ucfirst(value) + ' + € ' + rams[key] + '</option>';
										}
										else if(keys == 'Opslag')
										{
											idevinfo += '<option value="' + value + '">' + app.ucfirst(value) + ' + € ' + storages[key] + '</option>';
										}
										else
										{
											idevinfo += '<option value="' + value + '" ' + (info.color == value ? 'selected="selected"' : '') + '>' + app.ucfirst(value) + '</option>';
										}
									});
								}
								else
								{
									idevinfo += '<option value="' + device[values] + '">' + app.ucfirst(device[values]) + '</option>';
								}
							}
						idevinfo += '</select>' +
					'</div>';
					i = (i+1);
				});
				/*
					RAM
						8GB +0
						16GB +230
					SSD
						256GB +0
						512GB +230
						1TB +460
						2TB +920
					Muis of Trackpad
						Magic Mouse +0
						Trackpad +50
						Magic Mouse + Trackpad +135
					Office
						Nee +0
						Ja +119
					Overzetten data
						Nee +0
						Ja +99
				*/
if(app.in_array(info.merk, ['iPad']))
{
	idevinfo += '<div class="form-item">' +
		'<label for="_inscriptie">Inscriptie: <span class="state pull-right">&nbsp;</span></label>' +
		'<input type="text" name="_inscriptie1" placeholder="Eerste regel" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue">' +
		'<input type="text" name="_inscriptie2" placeholder="Tweede regel (optioneel)" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue">' +
		'<span class="centered">' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="😀">😀</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="😜">😜</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="😬">😬</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="😘">😘</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="👍">👍</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="✌">✌</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="🤟">🤟</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="👊">👊</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="❤️">❤️</a>&emsp;' +
			'<a href="onclick:javascript:void();" class="icogus" data-icon="⭐">⭐</a>&emsp;' +
		'</span><br>' +
	'</div>';
	idevinfo += '<div class="form-item">' +
		'<label for="_office">Office: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_office" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="ja">Ja + € 119</option>' +
		'</select>' +
	'</div>';
	idevinfo += '<div class="form-item">' +
		'<label for="_data">Overzetten gegevens: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_data" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="macOS">macOS + € 99</option>' +
			'<option value="Windows">Windows + € 149</option>' +
		'</select>' +
	'</div>';

}
else if(app.in_array(info.merk, ['MacBook']))
{
	idevinfo += '<div class="form-item">' +
		'<label for="_office">Office: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_office" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="ja">Ja + € 119</option>' +
		'</select>' +
	'</div>';
	idevinfo += '<div class="form-item">' +
		'<label for="_data">Overzetten gegevens: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_data" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="macOS">macOS + € 99</option>' +
			'<option value="Windows">Windows + € 149</option>' +
		'</select>' +
	'</div>';
}
else if(app.in_array(info.merk, ['iMac']))
{
	idevinfo += '<div class="form-item">' +
		'<label for="_keyboard">Toetsenbord: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_keyboard" style="float: left;" required="required">' +
			'<option value="standard">Standaard + € 0</option>' +
			'<option value="numeric">Numeriek + € 26</option>' +
		'</select>' +
	'</div>';
	idevinfo += '<div class="form-item">' +
		'<label for="_magic">Magic Mouse of Magic Trackpad: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_magic" style="float: left;" required="required">' +
			'<option value="Mouse">Magic Mouse + € 0</option>' +
			'<option value="Trackpad">Magic Trackpad + € 50</option>' +
			'<option value="Mouse + Trackpad">Magic Mouse en Magic Trackpad + € 135</option>' +
		'</select>' +
	'</div><br><br>';
	idevinfo += '<div class="form-item">' +
		'<label for="_office">Office: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_office" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="ja">Ja + € 119</option>' +
		'</select>' +
	'</div>';
	idevinfo += '<div class="form-item">' +
		'<label for="_data">Overzetten gegevens: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_data" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="macOS">macOS + € 99</option>' +
			'<option value="Windows">Windows + € 149</option>' +
		'</select>' +
	'</div>';

}
else
{
	idevinfo += '<div class="form-item">' +
		'<label for="_data">Overzetten gegevens: <span class="state pull-right">&nbsp;</span></label>' +
		'<select name="_data" style="float: left;" required="required">' +
			'<option value="nee">Nee + € 0</option>' +
			'<option value="iPadOS">iPadOS + € 19.95</option>' +
			'<option value="iOS">iOS + € 19.95</option>' +
		'</select>' +
	'</div>';
}
$.each(['1', '2', '3'], function(key, extras)
{
	idevinfo += '<div class="form-item">' +
		'<label for="_extra' + extras + '">Extra regel ' + extras + ': <span class="state pull-right">&nbsp;</span></label>' +
		'<input type="text" name="_extra' + extras + '" placeholder="Extra accessoire of randapparatuur" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue">' +
	'</div>';
});	
				idevinfo += '</div>' +
				'<br />';
			}
			else
			{
				idevinfo = '<div class="accordion">' +
					'<input id="accordion-three" type="checkbox" name="accordions">' +
					'<label for="accordion-three">Specificaties <sup class="muted pull-right" style="padding-right: 50px;">Optioneel</sup></label>' +
					'<div class="accordion-content">' +
						'<div class="form-item">' +
							'<label for="_serie">IMEI- of serienummer: <span class="state pull-right">&nbsp;</span></label>' +
							'<input type="text" name="_serie" placeholder="X0XXX0X000XX" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" />' +
						'</div>';
						names = ['Kleur', 'Processor', 'Werkgeheugen', 'Opslag'];
						var items = {};
						items['Kleur'] = 'colors';
						if(app.role(['admin', 'administrator', 'developer'])){
							items['Processor'] = 'processor';
							items['Werkgeheugen'] = 'ram';
						}
						items['Opslag'] = 'storage';
						$.each(items, function(key, values)
						{
							var name = (app.in_array(values, ['colors']) ? values.slice(0, -1) : values);
							idevinfo += '<div class="form-item">' +
								'<label for="_' + name + '">' + key + ': <span class="state pull-right">&nbsp;</span></label>' +
								'<select name="_' + name + '" style="float: left;">' +
									'<option value="">-</option>';
									if(device[values])
									{
										if(device[values].indexOf(',') > -1)
										{
											$.each(device[values].split(','), function(key, value)
											{
												idevinfo += '<option value="' + value + '">' + app.ucfirst(value) + '</option>';
											});
										}
										else
										{
											idevinfo += '<option value="' + device[values] + '">' + app.ucfirst(device[values]) + '</option>';
										}
									}
								idevinfo += '</select>' +
							'</div>';
						});
					idevinfo += '</div>' +
				'</div>' +
				'<br />';
			}

			idevider = '<hr />';

			iend = ''; 
			if(!app.role(['admin', 'administrator', 'developer'])){
				iend += '<hr />' +
				'<div class="form-item">' +
					'<label for="_awnser">Overtypen:</label><br />' +
					'<span name="_awnseresponse" class="captchas"></span>' + 
					'<input type="hidden" name="_awnser" value="" /><br />' +
					'<input type="text" name="_awnsered" value="" placeholder="?" onfocus="" onblur="if (this.value==\'\') this.value = this.defaultValue" style="width: 75%; float: left;" required="required" />' +
					'<span class="recaptcha tooltip-left" data-tooltip="Klik om te vernieuwen.."><a href="javascript:app.captcha(\'generate\');" name="rechaptcha"><i class="fa fa-refresh fa-fw"></i></a></span><br />' +
					'<span class="pull-left muted" name="_awnselp">&nbsp;</span>' + 
				'</div>';
			}
			iend += '<small class="muted pull-right">';
				if(app.in_array(target, ['icatalogus']))
				{
					iend += 'Bestellingen dienen persoonlijk afgehaald te worden, klik <a href="/contact" target="_blank">hier</a> voor ons contactgegevens én openingstijden.<br>Zodra de definitieve datum voor afhalen bekend is wordt er door ons contact opgenomen.<br>';
				}
				iend += 'Alle gegevens worden conform ons <a href="https://irepair.nu/wp-content/uploads/2018/05/25/privacybeleid.pdf" target="_blank">privacybeleid</a> verwerkt!' +
			'</small>' +
			'</form>';

			if(app.in_array(target, ['iworked']))
			{
				iworked = '';
				switch(action)
				{
					case 'day':
						iworked += '';
					default:
						iworked += '';
				}
				return iworked;
			}
			else if(app.in_array(target, ['iprivacy']))
			{
				iprivacy = '';
				switch(action)
				{
					case 'insert':
						app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + iprivacy + iend,
						'Bevestigen', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iprivacy',

									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'notify': result._notify,
								}, function(data)
								{
									if(data.status === 'success')
									{
										app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 'Je gegevens zijn toegevoegd en veilig opgeslagen, nu is het aan ons je op de hoogte te houden!', 'alert', function(result)
										{
											location.replace('/');
										});
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					case 'update':
						app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + '<span class="muted">Klik <a href="javascript:void(0);" name="iprivacielete" data-cid="' + info.cid + '" data-emailaddress="' + info.emailaddress + '">hier</a> om je persoonsgegevens te verwijderen!</span><br /><br />' + iprivacy + iend,
						'Aanpassen', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iprivacy',

									'update': '',

									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,
									'notify': result._notify,
								}, function(data)
								{
									if(data.status === 'success')
									{
										app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 'Je gegevens zijn aangepast en veilig opgeslagen, nu is het aan ons je op de hoogte te houden!', 'alert', function(result)
										{
											location.replace('/');
										});
									}
								});
								return true;
							}
							return false;
						}, true);
						$.each(['cid', 'name', 'vat', 'kvk', 'company', 'emailaddress', 'phone', 'postal', 'number', 'street', 'city', 'country'], function(i, value)
						{
							$('#popformer input[name="_' + value + '"').val(info[value]);
						});
						break;
					case 'delete':
						app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 'Weet je zeker dat je alle persoonsgegevens wilt verwijderen?', 'Natuurlijk', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iprivacy', 

									'delete': '',
									
									'cid': info.cid, 

									'emailaddress': info.emailaddress,

								}, function(data)
								{
									if(data.status === 'success')
									{
										app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 'Je verzoek tot het verwijderen van je persoonsgegevens is ontvangen en wordt zo spoedig mogelijk uitgevoerd!', 'alert', function(result)
										{
											location.replace('/');
										});
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					case 'verify':
						app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', istart + iemailaddress + iend, 'Controleren', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iprivacy', 

									'emailaddress': result._emailaddress,
									'verify': result._verify,

								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'success')
									{
										app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 'Ter verificatie is er naar <b>' + result._emailaddress + '</b> een link verzonden, controleer snel je e-mail!');
									}
									else if(data.status === 'verified')
									{
										app.popformer('iprivacy', 'update', data.client);
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					default:
						address = (app.empty(info.street) || app.empty(info.number) ? info.city : info.street + ' ' + info.number + ', ' + info.city);
						app.popupper('<i class="fa fa-address-card-o fa-fw"></i> Persoonsgegevens', 
							'<h1>' + info.name + '</h1>' +
							(app.empty(info.company) ? '' : '<i class="fa fa-building-o fa-fw"></i> <abbr style="font-weight: bold;" class="tooltip" data-tooltip="BTW: ' + (app.empty(info.vat) ? '' : info.vat) + ' KVK: ' + (app.empty(info.kvk) ? '' : info.kvk) + '">' + info.company + '</abbr><br />') +
							(app.empty(info.emailaddress) ? '' : '<i class="fa fa-envelope-o fa-fw"></i> <a href="mailto:' + info.emailaddress + '" class="tooltip" data-tooltip="Klik om te e-mailen!">' + info.emailaddress + '</a><br />') +
							(app.empty(info.phone) ? '' : '<i class="fa fa-mobile fa-fw"></i> <a href="tel:' + info.phone + '" class="tooltip" data-tooltip="Klik om te bellen!">' + info.phone + '</a><br />') +
							(app.empty(info.city) ? '' : '<i class="fa fa-map-marker fa-fw"></i> <a href="https://www.google.com/maps?q=' + address + '" target="_blank">' + address + '</a>')
						);
						break;
				}
			}
			else if(app.in_array(target, ['iappointments', 'iperiods']))
			{
				$.each(app.range(00, 23), function(i, value)
				{
					value = app.str_pad(value, 2);
					options['hours'] += '<option value="' + value + ':00" ' + (value + ':00' == info.time ? 'selected="selected"' : '') + '>' + value + ':00</option>';
					options['hours'] += '<option value="' + value + ':30" ' + (value + ':30' == info.time ? 'selected="selected"' : '') + '>' + value + ':30</option>';
				});
				iappointments = '<div class="form-item">' +
					'<label for="_device">Apparaat:</label>' +
					'<select name="_device" required="required">' +
						'<option value="">-</option>' +
						options['devices'] +
					'</select>' +
				'</div>' +
				idevinfo +
				'<div class="form-item">' +
					'<label for="_description">Opmerkingen:</label>' +
					'<textarea name="_description" placeholder="Omschrijf de gewenste reparaties of vraag zo duidelijk mogelijk.." required="required" rows="3"></textarea>' +
				'</div>',
				iperiods = '<div class="form-item">' +
					'<label for="_date">Datum:</label>' +
					'<input type="text" name="_date" value="' + info.date + '" placeholder="31-01-2007" onfocus="" onblur="if (this.value==\'\') this.value = this.defaultValue" class="datepicker" />' +
				'</div>' +
				'<div class="form-item">' +
					'<label for="_time">Tijd:</label>' +
					'<select name="_time" required="required">' +
						'<option value="">-</option>' +
						options['hours'] +
					'</select>' +
				'</div>';
				switch(action)
				{
					case 'insert':
						app.popupper('<i class="fa fa-calendar-plus-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + iappointments + iend,
						'Bevestigen', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iappointments',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'notify': result._notify,
									'datetime': info.datetime, 
									'device': result._device,
										'serie': result._serie,
										'color': result._color,
										'processor': result._processor,
										'ram': result._ram,
										'storage': result._storage,
									'description': result._description,
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'unavailable')
									{
										$('#popupper').dialog('destroy').remove();
										//$('#popupper').dialog('close').dialog().dialog('destroy');
										app.popupper('<i class="fa fa-calendar-plus-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 'Helaas, op <b>' + info.weekday + ' ' + info.day + ' ' + info.month + '</b> om <b>' + info.time + '</b> staat al een andere afspraak, vernieuw de pagina én probeer het nog eens?!', 'alert', function(result)
										{
											location.reload();
										});
										
									}
									else if(data.status === 'success')
									{
										if(!app.role(['admin', 'administrator', 'developer']))
										{
											$('body').append($('<form action="https://' + config.domain + '/afspraak/bevestiging" method="post" name="confirmated">' +
												'<input type="hidden" name="when" value="<b>' + info.weekday + ' ' + info.day + ' ' + info.month + '</b> om <b>' + info.time + '</b>">' +
												'<input type="hidden" name="device" value="' + result._device + '">' +
											'</form>'));
											$('form[name="confirmated"]').submit();
											/*
												app.popupper('<i class="fa fa-calendar-plus-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 'Hartelijk dank voor je vertrouwen in ons!<br /><hr />Wij zorgen op <b>' + info.weekday + ' ' + info.day + ' ' + info.month + '</b> om <b>' + info.time + '</b> voor de koffie!', 'Afgesproken', function(result)
												{
													.. ..neem jij dan de <b>' + app.random(['appelcake', 'boterkoek', 'brownies', 'cake', 'muffins', 'vlaai']) + '</b> mee?!
													location.reload();
												});
											*/
										}
										else
										{
											location.reload();
											/*
												$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
												info.push({'name': result._name, 'emailaddress': result._emailaddress, 'number': result._number, 'device': result._device, 'description': result._description});
												app.appointment('view', info);
											*/
										}
									}
									//console.dir(data);
								});
								return true;
							}
							return false;
						}, true);
						if(device = app.query('device'))
						{
							$('#popformer select[name="_device"] option[value="' + device + '"]').attr('selected', 'selected');
						}
						if(repair = app.query('repair'))
						{
							$('#popformer textarea[name="_description"]').val(repair);
						}
						break;
					case 'update':
						$('#popupper').dialog('destroy').remove();
						//$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
						app.popupper('<i class="fa fa-calendar-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + iappointments + iend,
						'Aanpassen', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iappointments',

									'update': '',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'datetime': info.datetime, 
									'device': result._device,
										'serie': result._serie,
										'color': result._color,
										'processor': result._processor,
										'ram': result._ram,
										'storage': result._storage,
									'description': result._description,
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'success')
									{
										if(!app.role(['admin', 'administrator', 'developer']))
										{
											app.popupper('<i class="fa fa-calendar-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 'Hartelijk dank voor je vertrouwen in ons!<br /><hr />Wij zorgen op ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time + ' voor de koffie!', 'Afgesproken', function(result)
											{
												/*
													.. ..neem jij dan de <b>' + app.random(['appelcake', 'boterkoek', 'brownies', 'cake', 'muffins', 'vlaai']) + '</b> mee?!
												*/
												location.reload();
											});
										}
										else
										{
											location.reload();
											/*
												$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
												info.push({'name': result._name, 'emailaddress': result._emailaddress, 'phone': result._phone, 'device': result._device, 'description': result._description});
												app.appointment('view', info);
											*/
										}
									}
								});
								return true;
							}
							return false;
						}, true);
						$.each(['id', 'cid', 'name', 'vat', 'kvk', 'company', 'emailaddress', 'phone', 'postal', 'number', 'street', 'city', 'country', 'serie'], function(i, value)
						{
							$('#popformer input[name="_' + value + '"').val(info[value]);
						});
						$.each(['device', 'color', 'processor', 'ram', 'storage'], function(i, value)
						{
							$('#popformer select[name="_' + value + '"]').val(info[value]);
						});
						//$('#popformer select[name="_device"]').val(info['device']).trigger('change');
						if($('#popformer textarea[name="_description"]').length)
						{
							$('#popformer textarea[name="_description"]').val(info['description']);
						}
						break;
					case 'delete':
						app.popupper('<i class="fa fa-calendar-times-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 'Weet je zeker dat je ' + (info.name ? 'de afspraak met <b>' + info.name + '</b> ' + (info.company ? 'van <b>' + info.company + '</b>' : '') : 'deze afspraak') + ' wilt verwijderen?', 'Natuurlijk', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iappointments', 

									'delete': '',

									'id': info.id, 
									'cid': info.cid, 

									'datetime': info.datetime,

								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'success')
									{
										location.reload();
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					case 'periods':
						app.popupper('<i class="fa fa-calendar fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, istart + iperiods + iend,
						'Verplaatsen', function(result)
						{
							if(result)
							{
								//console.dir(result);
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'user': info.user, 
									
									'action': 'iclients',
									'source': 'iappointments',

									'period': '',

									'id': info.id, 
									'cid': info.cid, 

									'datetime': info.datetime, 
									'date': result._date, 
									'time': result._time,
									
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'unavailable')
									{
											$('#popupper').dialog('destroy').remove();
											//$('#popupper').dialog().dialog('close').dialog().dialog('destroy');
											app.popupper('<i class="fa fa-calendar fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 'Op <b>' + result._date + '</b> om <b>' + result._time + '</b> zou ' + (info.name ? '<b>' + info.name + '</b>' + (info.company ? ' van <b>' + info.company + '</b>' : '') : 'een andere klant') + ' graag langs willen komen!', 'alert', true);
									}
									else if(data.status === 'success')
									{
										location.reload();
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					default:
						address = (app.empty(info.street) || app.empty(info.number) ? info.city : info.street + ' ' + info.number + ', ' + info.city);
						specifications = '';
						$.each(['serie', 'processor', 'ram', 'storage'], function(key, values)
						{
							if(!app.empty(info[values]))
							{
								specifications += ', ' + info[values];
							}	
						});
						app.popupper('<i class="fa fa-calendar-check-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 
							'<span class="pull-right">' + 
								'<a href="" name="appointmanage" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-cid="' + info.cid + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-serie="' + info.serie + '" data-color="' + info.color + '" data-processor="' + info.processor + '" data-ram="' + info.ram + '" data-storage="' + info.storage + '" data-description="' + info.description + '"><i class="fa fa-pencil fa-fw"></i></a>' +
								'&emsp;' + 
								'<a href="" name="appointmeriods" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-cid="' + info.cid + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-serie="' + info.serie + '" data-color="' + info.color + '" data-processor="' + info.processor + '" data-ram="' + info.ram + '" data-storage="' + info.storage + '" data-description="' + info.description + '"><i class="fa fa-calendar fa-fw"></i></a>' +
								'&emsp;' + 
								'<a href="" name="appointmove" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-cid="' + info.cid + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-serie="' + info.serie + '" data-color="' + info.color + '" data-processor="' + info.processor + '" data-ram="' + info.ram + '" data-storage="' + info.storage + '" data-description="' + info.description + '"><i class="fa fa-trash fa-fw"></i></a>' +
							'</span><br />' +
							'<h1>' + info.name + '</h1>' +
							(app.empty(info.company) ? '' : '<i class="fa fa-building-o fa-fw"></i> <abbr style="font-weight: bold;" class="tooltip" data-tooltip="BTW: ' + (app.empty(info.vat) ? '' : info.vat) + ' KVK: ' + (app.empty(info.kvk) ? '' : info.kvk) + '">' + info.company + '</abbr><br />') +
							(app.empty(info.emailaddress) ? '' : '<i class="fa fa-envelope-o fa-fw"></i> <a href="mailto:' + info.emailaddress + '" class="tooltip" data-tooltip="Klik om te e-mailen!">' + info.emailaddress + '</a><br />') +
							(app.empty(info.phone) ? '' : '<i class="fa fa-mobile fa-fw"></i> <a href="tel:' + info.phone + '" class="tooltip" data-tooltip="Klik om te bellen!">' + info.phone + '</a><br />') +
							(app.empty(info.city) ? '' : '<i class="fa fa-map-marker fa-fw"></i> <a href="https://www.google.com/maps?q=' + address + '" target="_blank">' + address + '</a>') + 
							'<hr >' +
							'<h1>' + (app.empty(info.color) ? '' : '<i class="fa fa-' + (app.in_array(app.strtolower(info.color), ['wit']) ? 'square-o' : 'square') + ' fa-fw" style="color: ' + config.colors[app.strtolower(info.color)] + '" title="' + info.color + '"></i>') + ' ' + device.merk + ' ' + device.model + '</h1>' +
							(!app.empty(specifications) ? '<h6>Specificaties: <span style="font-style: italic">' + specifications.substr(2) + '.</span></h6><br />' : '') +
							'<b>Opmerkingen:</b> ' + info.description
						);
				}
			}
			else if(target === 'icatalogus')
			{
				/*
					ibills
						
				*/
				var ioffextra = '<div class="form-item">' +
					'<input type="number" name="_numbers[]" value="" placeholder="1" class="defocus numerics" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="" placeholder="Extra accessoire óf reparatie.." class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" tabindex="-1" disabled="disabled" />' +
					'<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a>' +
				'</div>', rules, subtotal = 0;

				/*
					var rules = $('input[name="_title[]"]').map(function(){return $(this).val();}).get();

					var arrNumber = new Array();
					$('input[type=number]').each(function(){
						arrNumber.push($(this).val());
					});
				*/
				console.dir(device, 'Device:');
				icatalogus = '<h1>' + device.merk + ' ' + device.model + '<small class="active" name="storage" style="float: right;">' + info.storage + ' <sup class="muted" name="ram">' + info.ram + '</sup></small></h1>';
				icatalogus += '' +
					'<input type="hidden" name="_merk" value="' + device.merk + '">' +
					'<input type="hidden" name="_model" value="' + device.model + '">' +
					'<input type="hidden" name="_device" value="' + device.nummer + '">' +
					'<input type="hidden" name="_storage" value="' + info.storage + '">' +
					'<input type="hidden" name="_ram" value="' + info.ram + '">' +
					'<input type="hidden" name="_price" value="' + info.price + '">' +
					'<input type="hidden" name="_total" value="' + info.price + '">' +
				'';
				icatalogus += idevinfo;
				/*
				icatalogus += '<div class="form-item">' +
					'<label for="_date">Afhalen:</label>' +
					'<input type="text" name="_date" value="' + info.date + '" placeholder="31-01-2007" minDate="' + info.mindate + '" onfocus="" onblur="if (this.value==\'\') this.value = this.defaultValue" class="datepicker" />' +
				'</div>';
				*/
				icatalogus += '<div class="form-item">' +
					'<label for="_comments">Opmerkingen:</label>' +
					'<textarea name="_comments" placeholder="Eventuele opmerkingen.." pattern="' + app.pattern('textarea') + '" rows="3"></textarea>' +
				'</div>' +
				'<div style="width: 100%;"><span name="price" style="float: right; font-weight: bold; color: #ed781e; font-size: 1.5em; padding-right: 3%;">€ ' + app.fixed(info.price).replace('.', ',') + '</span></div>' +
				'<br /><br />';

				/*
					'<div class="form-item">' +
						'<label for="_comments">Opmerkingen:</label>' +
						'<textarea name="_comments" placeholder="Eventuele opmerkingen.." rows="3"></textarea>' +
					'</div>';

					'<div class="form-item">' +
						'<label for="_number">Titel:</label>' +
						'<input type="text" name="_subject" placeholder="Korte versie.." onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" />' +
					'</div>' +
					'<div class="form-item">' +
						'<label for="_description">Beoordeling:</label>' +
						'<textarea name="_description" placeholder="Uitgebreid verslag.." required="required" rows="3"></textarea>' +
					'</div>';
				*/

				switch(action)
				{
					case 'insert':
						app.popupper('<i class="fa fa-shopping-basket fa-fw"></i> Bestelling ', istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + icatalogus + iend,
						'Bestellen', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'action': 'iclients',
									'source': 'icatalogus',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'device': result._device,
										'merk': result._merk,
										'model': result._model,
										'color': result._color,
										'ram': result._ram,
										'storage': result._storage,
										
										'data': result._data || false,
										'keyboard': result._keyboard || false,
										'office': result._office || false,
										'magic': result._magic || false,
										'extra1': result._extra1 || false,
										'extra2': result._extra2 || false,
										'extra3': result._extra3 || false,
										
										'inscriptie1': result._inscriptie1 || false,
										'inscriptie2': result._inscriptie2 || false,

									'price': result._price,
									'total': result._total,
									'comments': result._comments,
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'success')
									{
										if(!app.role(['admin', 'administrator', 'developer']))
										{
											app.popupper('<i class="fa fa-shopping-basket fa-fw"></i> Bestelling', 'Hartelijk dank, de bestelling is ontvangen!<br /><hr />Je ontvangt spoedig van ons een reactie per e-mail..', 'Graag gedaan', function(result)
											{
												$(location).attr('href', 'https://' + config.domain + '/catalogus/');
											});
										}
										else
										{
											$(location).attr('href', 'https://' + config.domain + '/catalogus/');
										}
									}
								});
								return true;
							}
							return false;
						});
						/*
						'date': result._date,
						$('input[name="_date"]').datepicker(
							'option', {
								'beforeShowDay': function(date)
								{
									var day = date.getDay();
									return [(day != 0), ''];
								},
								'minDate': new Date(info.mindate.substring(6,10), info.mindate.substring(3,5)-1, info.mindate.substring(0,2))
							}
						);
						*/
						$('select[name="_ram"]').on('change', function(e)
						{
							$('sup[name="ram"]').html($(this).find('option:selected').val());
							$('input[name="_ram"').val($(this).find('option:selected').val());
						});
						$('select[name="_storage"]').on('change', function(e)
						{
							$('small[name="storage"]').html($(this).find('option:selected').val() + ' <sup class="muted" name="ram">' + $('sup[name="ram"]').html() + '</sup>');
							$('input[name="_storage"').val($(this).find('option:selected').val());
						});
						$('input[name="_extra1"], input[name="_extra2"], input[name="_extra3"], select').on('change', function(e)
						{
							if(app.in_array(info.merk, ['MacBook']))
							{
								_price = parseFloat($('input[name="_price"]').val());
								_price += parseFloat($('select[name="_ram"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_storage"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_data"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_office"]').find('option:selected').text().split('€').pop());
								$.each(['1', '2', '3'], function(key, extras)
								{
									if($('input[name="_extra' + extras + '"]').val().indexOf('€') != -1)
									{
										_price += parseFloat($('input[name="_extra' + extras + '"]').val().split('€').pop().replace(',', '.'));
									}
								});
								$('input[name="_total"').val(app.fixed(_price));
								$('span[name="price"').html('€ ' + app.fixed(_price).replace('.', ','));
							}
							else if(app.in_array(info.merk, ['iMac']))
							{
								_price = parseFloat($('input[name="_price"]').val());
								_price += parseFloat($('select[name="_ram"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_storage"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_keyboard"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_magic"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_data"]').find('option:selected').text().split('€').pop());
								_price += parseFloat($('select[name="_office"]').find('option:selected').text().split('€').pop());
								$.each(['1', '2', '3'], function(key, extras)
								{
									if($('input[name="_extra' + extras + '"]').val().indexOf('€') != -1)
									{
										_price += parseFloat($('input[name="_extra' + extras + '"]').val().split('€').pop().replace(',', '.'));
									}
								});
								$('input[name="_total"').val(app.fixed(_price));
								$('span[name="price"').html('€ ' + app.fixed(_price).replace('.', ','));
							}
							else
							{
								_price = parseFloat($('input[name="_price"]').val());
								_price += parseFloat($('select[name="_data"]').find('option:selected').text().split('€').pop());
								$.each(['1', '2', '3'], function(key, extras)
								{
									if($('input[name="_extra' + extras + '"]').val().indexOf('€') != -1)
									{
										_price += parseFloat($('input[name="_extra' + extras + '"]').val().split('€').pop().replace(',', '.'));
									}
								});
								$('input[name="_total"').val(app.fixed(_price));
								$('span[name="price"').html('€ ' + app.fixed(_price, 2).replace('.', ','));
							}
						});
						break;
					default:
						address = (app.empty(info.street) || app.empty(info.number) ? info.city : info.street + ' ' + info.number + ', ' + info.city);
						specifications = '';
						$.each(['serie', 'processor', 'ram', 'storage'], function(key, values)
						{
							if(!app.empty(info[values]))
							{
								specifications += ', ' + info[values];
							}	
						});
						app.popupper('<i class="fa fa-bars fa-fw"></i> Bestellen', 
							'<h1>' + info.name + '</h1>' +
							(app.empty(info.company) ? '' : '<i class="fa fa-building-o fa-fw"></i> <abbr style="font-weight: bold;" class="tooltip" data-tooltip="BTW: ' + (app.empty(info.vat) ? '' : info.vat) + ' KVK: ' + (app.empty(info.kvk) ? '' : info.kvk) + '">' + info.company + '</abbr><br />') +
							(app.empty(info.emailaddress) ? '' : '<i class="fa fa-envelope-o fa-fw"></i> <a href="mailto:' + info.emailaddress + '" class="tooltip" data-tooltip="Klik om te e-mailen!">' + info.emailaddress + '</a><br />') +
							(app.empty(info.phone) ? '' : '<i class="fa fa-mobile fa-fw"></i> <a href="tel:' + info.phone + '" class="tooltip" data-tooltip="Klik om te bellen!">' + info.phone + '</a><br />') +
							(app.empty(info.city) ? '' : '<i class="fa fa-map-marker fa-fw"></i> <a href="https://www.google.com/maps?q=' + address + '" target="_blank">' + address + '</a>') + 
							'<hr >' +
							'<h1>' + (app.empty(info.color) ? '' : '<i class="fa fa-' + (app.in_array(app.strtolower(info.color), ['wit']) ? 'square-o' : 'square') + ' fa-fw" style="color: ' + config.colors[app.strtolower(info.color)] + '" title="' + info.color + '"></i>') + ' ' + device.merk + ' ' + device.model + '</h1>' +
							'<h5>' + info.color + ' ' + info.processor + '</h5>' +
							info.description
						);
				}
			}
			else if(target === 'ioffers')
			{
				/*
					ibills
						
				*/
				var ioffextra = '<div class="form-item">' +
					'<input type="number" name="_numbers[]" value="" placeholder="1" class="defocus numerics" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="" placeholder="Extra accessoire óf reparatie.." class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" tabindex="-1" disabled="disabled" />' +
					'<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a>' +
				'</div>', rules, subtotal = 0;
				/*
					var rules = $('input[name="_title[]"]').map(function(){return $(this).val();}).get();

					var arrNumber = new Array();
					$('input[type=number]').each(function(){
						arrNumber.push($(this).val());
					});
				*/
				console.log('Device:');
				console.dir(device);
				ioffers = '<h1>' + device.merk + ' ' + device.model + '</h1>';
				ioffers += idevinfo;
				if(app.role(['admin', 'administrator', 'developer']))
				{
					ioffers += '<div style="font-size: 75%; font-weight: bold;">' + 
						'<span style="width: 7%; float: left;">#</span>' +
						'<span style="width: 63%; float: left;">Omschrijving</span>' +
						'<span style="width: 15%; float: left;">Prijs</span>' +
						'<span style="width: 15%; float: left; text-align: right; padding-right: 3%;">Subtotaal</span>' +
					'</div>';
				}
				else
				{
					ioffers += '<div style="font-size: 75%; font-weight: bold;">' + 
						'<span style="width: 85%; float: left;">Omschrijving</span>' +
						'<span style="width: 15%; float: left; text-align: right; padding-right: 3%;">Prijs</span>' +
					'</div><br />';
				}
				if(app.role(['admin', 'administrator', 'developer']))
				{
					ioffers += '<div id="form-items">';
						$.each(info.rules, function(i, value)
						{
							ioffers += '<div class="form-item">' +
								//'<input type="text" name="_number[]" value="1" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 5%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="' + value[0] + '" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 75%; float: left;" /><input type="text" name="_price[]" value="€ ' + app.floated(value[1]) + '" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 10%; float: left;" /><input type="text" name="_prices[]" value="€ ' + app.floated(value[1]) + '" class="defocus" style="width: 10%; float: left; text-align: right;" disabled="disabled" />' +
								'<input type="number" name="_numbers[]" value="' + value[0] + '" class="defocus numerics" style="width: 7%; float: left;" tabindex="-1" ' + (app.stripos(value[1], 'korting') ? 'disabled="disabled"' : '') + ' /><input type="text" name="_title[]" value="' + value[1] + '" class="defocus" style="width: 60%; float: left;" ' + (app.stripos(value[1], 'korting') ? 'disabled="disabled"' : '') + ' /><input type="text" name="_price[]" value="€ ' + app.fixed(value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" ' + (app.stripos(value[1], 'korting') ? 'tabindex="-1"' : '') + ' /><input type="text" name="_prices[]" value="€ ' + app.fixed(value[0]*value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" tabindex="-1" disabled="disabled" />' +
								//'<input type="number" name="_number[]" value="1" class="defocus" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="' + value[0] + '" class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="€ ' + app.floated(value[1]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="€ ' + app.floated(value[1]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" disabled="disabled" />' +
								(app.is_mobile() || app.stripos(value[1], 'korting') ? '<br />' : '<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a><br />') +
							'</div>';
							subtotal += +(value[2] === '' ? 0 : app.fixed(value[0]*value[2]));
						});
						ioffers += ioffextra + 
					'</div>';
				} 
				else
				{
					ioffers += '<div id="form-items">';
						$.each(info.rules, function(i, value)
						{
							ioffers += '<div class="form-item" style="left: 20px; width: 90%;">' + 
								'<input type="number" name="_numbers[]" value="' + value[0] + '" class="defocus" style="position: absolute; left: -999em;" /><input type="text" name="_title[]" value="' + value[1] + '" class="defocus" style="position: absolute; left: -999em;" /><input type="text" name="_price[]" value="€ ' + app.fixed(value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="position: absolute; left: -999em;" /><input type="text" name="_prices[]" value="€ ' + app.fixed(value[0]*value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="position: absolute; left: -999em;" />' +
								'<span class="pull-left"><i class="fa-li fa fa-check" style="color: #ed781e;"></i>' + value[0] + 'x ' + value[1] + '</span><span style="float: right;">€ ' + app.fixed(value[2]).replace('.', ',') + '</span><br />' +
							'</div>';
							subtotal += +(value[2] === '' ? 0 : app.fixed(value[0]*value[2]));
						});
					ioffers += '</div><br />';
				}
				subtotal = app.fixed(subtotal);
				ioffers += '<div style="width: 100%;"><input type="hidden" name="_subtotal" value="' + subtotal + '" /><span name="subtotal" style="float: right; font-weight: bold; color: #ed781e; font-size: 1.5em; padding-right: 3%;">€ ' + app.fixed(subtotal).replace('.', ',') + '</span></div>' +
				'<br /><br />' +
				'<div class="form-item">' +
					'<label for="_comments">Opmerkingen:</label>' +
					'<textarea name="_comments" placeholder="Eventuele opmerkingen.." pattern="' + app.pattern('textarea') + '" rows="3"></textarea>' +
				'</div>';
				setTimeout(function()
				{
				  app.calculate('ioffers');
				}, 100);
				/*
					'<div class="form-item">' +
						'<label for="_comments">Opmerkingen:</label>' +
						'<textarea name="_comments" placeholder="Eventuele opmerkingen.." rows="3"></textarea>' +
					'</div>';

					'<div class="form-item">' +
						'<label for="_number">Titel:</label>' +
						'<input type="text" name="_subject" placeholder="Korte versie.." onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" />' +
					'</div>' +
					'<div class="form-item">' +
						'<label for="_description">Beoordeling:</label>' +
						'<textarea name="_description" placeholder="Uitgebreid verslag.." required="required" rows="3"></textarea>' +
					'</div>';
				*/

				switch(action)
				{
					case 'confirm':
						app.popupper('<i class="fa fa-calculator fa-fw"></i> Offerte', istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + ioffers + iend,
						'Bevestigen', function(result)
						{
							if(result)
							{
								var  numbers, titles, price, prices, rules;
								//console.log(result);
								numbers = (result._numbers.substr(result._numbers.length - 1) == '|' ? result._numbers.slice(0, -1).split('|') : result._numbers.split('|'));
								//console.dir(numbers);
								titles = (result._title.substr(result._title.length - 1) == '|' ? result._title.slice(0, -1).split('|') : result._title.split('|'));
								//console.dir(titles);
								price = (result._price.substr(result._price.length - 1) == '|' ? result._price.slice(0, -1).split('|') : result._price.split('|'));
								//console.dir(price);
								prices = (result._prices.substr(result._prices.length - 1) == '|' ? result._prices.slice(0, -1).split('|') : result._prices.split('|'));
								//console.dir(prices);
								rules = $.map(titles, function (e, i)
								{
									return (e ? [[numbers[i], e, price[i], prices[i]]] : null);
									//return [[numbers[i], e, price[i], prices[i]]];
								});

								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'action': 'iclients',
									'source': 'ioffers',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'device': info.device,
										'serie': result._serie,
										'color': result._color,
										'processor': result._processor,
										'ram': result._ram,
										'storage': result._storage,
									'rules': rules,
									'subtotal': result._subtotal,
									'comments': result._comments,
								}, function(data)
								{
									//console.dir(data);
									// updated notification
									if(data.status === 'updated')
									{
										$(location).attr('href', 'https://irepair.nu/wp-admin/admin.php?page=ioffers');
									}
									else if(data.status === 'success')
									{
										if(!app.role(['admin', 'administrator', 'developer']))
										{
											app.popupper('<i class="fa fa-calculator fa-fw"></i> Offerte', 'Hartelijk dank, de aanvraag is ontvangen!<br /><hr />Je ontvangt spoedig van ons een offerte voor de ' + device.merk + ' ' + device.model + ' per e-mail..', 'Graag gedaan', function(result)
											{
												$(location).attr('href', 'https://' + config.domain + '/afspraak/');
											});
										}
										else
										{
											$(location).attr('href', 'https://irepair.nu/wp-admin/admin.php?page=ioffers');
										}
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					default:
						address = (app.empty(info.street) || app.empty(info.number) ? info.city : info.street + ' ' + info.number + ', ' + info.city);
						specifications = '';
						$.each(['serie', 'processor', 'ram', 'storage'], function(key, values)
						{
							if(!app.empty(info[values]))
							{
								specifications += ', ' + info[values];
							}	
						});
						app.popupper('<i class="fa fa-calendar-check-o fa-fw"></i> ' + info.weekday + ' ' + info.day + ' ' + info.month + ' om ' + info.time, 
							'<span class="pull-right">' + 
								'<a href="" name="appointmanage" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-description="' + info.description + '"><i class="fa fa-pencil fa-fw"></i></a>' +
								'&emsp;' + 
								'<a href="" name="appointmeriods" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-description="' + info.description + '"><i class="fa fa-calendar fa-fw"></i></a>' +
								'&emsp;' + 
								'<a href="" name="appointmove" data-user="' + info.user + '" data-datetime="' + info.datetime + '" data-date="' + info.date + '" data-day="' + info.day + '" data-month="' + info.month + '" data-weekday="' + info.weekday + '" data-time="' + info.time + '" data-id="' + info.id + '" data-name="' + info.name + '" data-company="' + info.company + '" data-emailaddress="' + info.emailaddress + '" data-phone="' + info.phone + '" data-postal="' + info.postal + '" data-number="' + info.number + '" data-street="' + info.street + '" data-city="' + info.city + '" data-country="' + info.country + '" data-device="' + info.device + '" data-description="' + info.description + '"><i class="fa fa-trash fa-fw"></i></a>' +
							'</span><br />' +
							'<h1>' + info.name + '</h1>' +
							(app.empty(info.company) ? '' : '<i class="fa fa-building-o fa-fw"></i> <abbr style="font-weight: bold;" class="tooltip" data-tooltip="BTW: ' + (app.empty(info.vat) ? '' : info.vat) + ' KVK: ' + (app.empty(info.kvk) ? '' : info.kvk) + '">' + info.company + '</abbr><br />') +
							(app.empty(info.emailaddress) ? '' : '<i class="fa fa-envelope-o fa-fw"></i> <a href="mailto:' + info.emailaddress + '" class="tooltip" data-tooltip="Klik om te e-mailen!">' + info.emailaddress + '</a><br />') +
							(app.empty(info.phone) ? '' : '<i class="fa fa-mobile fa-fw"></i> <a href="tel:' + info.phone + '" class="tooltip" data-tooltip="Klik om te bellen!">' + info.phone + '</a><br />') +
							(app.empty(info.city) ? '' : '<i class="fa fa-map-marker fa-fw"></i> <a href="https://www.google.com/maps?q=' + address + '" target="_blank">' + address + '</a>') + 
							'<hr >' +
							'<h1>' + (app.empty(info.color) ? '' : '<i class="fa fa-' + (app.in_array(app.strtolower(info.color), ['wit']) ? 'square-o' : 'square') + ' fa-fw" style="color: ' + config.colors[app.strtolower(info.color)] + '" title="' + info.color + '"></i>') + ' ' + device.merk + ' ' + device.model + '</h1>' +
							'<h5>' + info.color + ' ' + info.processor + '</h5>' +
							info.description
						);
				}
			}
			else if(target === 'ireceipt')
			{
				var irecextra = '<div class="form-item">' +
					'<input type="number" name="_numbers[]" value="" placeholder="1" class="defocus numerics" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="" placeholder="Extra accessoire óf reparatie.." class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="" placeholder="€ 0.00" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" tabindex="-1" disabled="disabled" />' +
					'<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a>' +
				'</div>', rules, subtotal = 0;
				/*
					var rules = $('input[name="_title[]"]').map(function(){return $(this).val();}).get();

					var arrNumber = new Array();
					$('input[type=number]').each(function(){
						arrNumber.push($(this).val());
					});
				*/
				console.log('Device:');
				console.dir(device);
				// ireceipt = '<h1>' + device.merk + ' ' + device.model + '</h1>';
				ireceipt = '<div class="form-item">' +
					'<label for="_device">Apparaat:</label>' +
					'<select name="_device" required="required">' +
						'<option value="">-</option>' +
						options['devices'] +
					'</select>' +
				'</div>';
				ireceipt += idevinfo;
				if(app.role(['admin', 'administrator', 'developer']))
				{
					ireceipt += '<div style="font-size: 75%; font-weight: bold;">' + 
						'<span style="width: 7%; float: left;">#</span>' +
						'<span style="width: 63%; float: left;">Omschrijving</span>' +
						'<span style="width: 15%; float: left;">Prijs</span>' +
						'<span style="width: 15%; float: left; text-align: right; padding-right: 3%;">Subtotaal</span>' +
					'</div>';
				}
				else
				{
					ireceipt += '<div style="font-size: 75%; font-weight: bold;">' + 
						'<span style="width: 85%; float: left;">Omschrijving</span>' +
						'<span style="width: 15%; float: left; text-align: right; padding-right: 3%;">Prijs</span>' +
					'</div><br />';
				}
				if(app.role(['admin', 'administrator', 'developer']))
				{
					ireceipt += '<div id="form-items">';
						$.each(info.rules, function(i, value)
						{
							ireceipt += '<div class="form-item">' +
								//'<input type="text" name="_number[]" value="1" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 5%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="' + value[0] + '" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 75%; float: left;" /><input type="text" name="_price[]" value="€ ' + app.floated(value[1]) + '" onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" class="defocus" style="width: 10%; float: left;" /><input type="text" name="_prices[]" value="€ ' + app.floated(value[1]) + '" class="defocus" style="width: 10%; float: left; text-align: right;" disabled="disabled" />' +
								'<input type="number" name="_numbers[]" value="' + value[0] + '" class="defocus numerics" style="width: 7%; float: left;" tabindex="-1" ' + (app.stripos(value[1], 'korting') ? 'disabled="disabled"' : '') + ' /><input type="text" name="_title[]" value="' + value[1] + '" class="defocus" style="width: 60%; float: left;" ' + (app.stripos(value[1], 'korting') ? 'disabled="disabled"' : '') + ' /><input type="text" name="_price[]" value="€ ' + app.fixed(value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="width: 15%; float: left;" ' + (app.stripos(value[1], 'korting') ? 'tabindex="-1"' : '') + ' /><input type="text" name="_prices[]" value="€ ' + app.fixed(value[0]*value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" tabindex="-1" disabled="disabled" />' +
								//'<input type="number" name="_number[]" value="1" class="defocus" style="width: 7%; float: left;" tabindex="-1" /><input type="text" name="_title[]" value="' + value[0] + '" class="defocus" style="width: 60%; float: left;" /><input type="text" name="_price[]" value="€ ' + app.floated(value[1]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left;" /><input type="text" name="_prices[]" value="€ ' + app.floated(value[1]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="width: 15%; float: left; text-align: right;" disabled="disabled" />' +
								(app.is_mobile() || app.stripos(value[1], 'korting') ? '<br />' : '<a href="javascript:void(0);" name="form-downs" tabindex="-1"><span style="height: 35px; width: 3%; float: left; padding: 5px; margin: 0px;" ><i class="fa fa-angle-down fa-fw fa-lg"></i></span></a><br />') +
							'</div>';
							subtotal += +(value[2] === '' ? 0 : app.fixed(value[0]*value[2]));
						});
						ireceipt += irecextra + 
					'</div>';
				} 
				else
				{
					ireceipt += '<div id="form-items">';
						$.each(info.rules, function(i, value)
						{
							ireceipt += '<div class="form-item" style="left: 20px; width: 90%;">' + 
								'<input type="number" name="_numbers[]" value="' + value[0] + '" class="defocus" style="position: absolute; left: -999em;" /><input type="text" name="_title[]" value="' + value[1] + '" class="defocus" style="position: absolute; left: -999em;" /><input type="text" name="_price[]" value="€ ' + app.fixed(value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus numerics" style="position: absolute; left: -999em;" /><input type="text" name="_prices[]" value="€ ' + app.fixed(value[0]*value[2]) + '" pattern="' + app.pattern('euro') + '" class="defocus" style="position: absolute; left: -999em;" />' +
								'<span class="pull-left"><i class="fa-li fa fa-check" style="color: #ed781e;"></i>' + value[0] + 'x ' + value[1] + '</span><span style="float: right;">€ ' + app.fixed(value[2]).replace('.', ',') + '</span><br />' +
							'</div>';
							subtotal += +(value[2] === '' ? 0 : app.fixed(value[0]*value[2]));
						});
					ireceipt += '</div><br />';
				}
				subtotal = app.fixed(subtotal);
				ireceipt += '<div style="width: 100%;"><input type="hidden" name="_subtotal" value="' + subtotal + '" /><span name="subtotal" style="float: right; font-weight: bold; color: #ed781e; font-size: 1.5em; padding-right: 3%;">€ ' + app.fixed(subtotal).replace('.', ',') + '</span></div>' +
				'<br><br style="clear: both;">' +
				'<div class="form-item">' +
					'<label for="_comments">Opmerkingen:</label>' +
					'<textarea name="_comments" placeholder="Eventuele opmerkingen.." pattern="' + app.pattern('textarea') + '" rows="3"></textarea>' +
				'</div>';
				setTimeout(function()
				{
				  app.calculate('ireceipt');
				}, 100);
				/*
					'<div class="form-item">' +
						'<label for="_comments">Opmerkingen:</label>' +
						'<textarea name="_comments" placeholder="Eventuele opmerkingen.." rows="3"></textarea>' +
					'</div>';

					'<div class="form-item">' +
						'<label for="_number">Titel:</label>' +
						'<input type="text" name="_subject" placeholder="Korte versie.." onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" required="required" />' +
					'</div>' +
					'<div class="form-item">' +
						'<label for="_description">Beoordeling:</label>' +
						'<textarea name="_description" placeholder="Uitgebreid verslag.." required="required" rows="3"></textarea>' +
					'</div>';
				*/

				switch(action)
				{
					case 'insert':
						app.popupper('<i class="fa fa-file-o fa-fw"></i> Werkbon', istart + iclient + iemailaddress + iphone + icompany + iaddress + idevider + ireceipt + iend,
						'Printen', function(result)
						{
							if(result)
							{
								var  numbers, titles, price, prices, rules;
								//console.log(result);
								numbers = (result._numbers.substr(result._numbers.length - 1) == '|' ? result._numbers.slice(0, -1).split('|') : result._numbers.split('|'));
								//console.dir(numbers);
								titles = (result._title.substr(result._title.length - 1) == '|' ? result._title.slice(0, -1).split('|') : result._title.split('|'));
								//console.dir(titles);
								price = (result._price.substr(result._price.length - 1) == '|' ? result._price.slice(0, -1).split('|') : result._price.split('|'));
								//console.dir(price);
								prices = (result._prices.substr(result._prices.length - 1) == '|' ? result._prices.slice(0, -1).split('|') : result._prices.split('|'));
								//console.dir(prices);
								rules = $.map(titles, function (e, i)
								{
									return (e ? [[numbers[i], e, price[i], prices[i]]] : null);
									//return [[numbers[i], e, price[i], prices[i]]];
								});

								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'action': 'iclients',
									'source': 'ioffers',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'company': result._company, 
										'vat': result._vat, 
										'kvk': result._kvk, 
									'emailaddress': result._emailaddress,
									'phone': result._phone,
										'postal': result._postal,
										'number': result._number,
										'street': result._street,
										'city': result._city,
										'country': result._country,

									'device': info.device,
										'serie': result._serie,
										'color': result._color,
										'processor': result._processor,
										'ram': result._ram,
										'storage': result._storage,
									'rules': rules,
									'subtotal': result._subtotal,
									'comments': result._comments,
								}, function(data)
								{
									//console.dir(data);
									// updated notification
									if(data.status === 'updated')
									{
										$(location).attr('href', 'https://irepair.nu/wp-admin/admin.php?page=ioffers');
									}
									else if(data.status === 'success')
									{
										if(!app.role(['admin', 'administrator', 'developer']))
										{
											app.popupper('<i class="fa fa-calculator fa-fw"></i> Offerte', 'Hartelijk dank, de aanvraag is ontvangen!<br /><hr />Je ontvangt spoedig van ons een offerte voor de ' + device.merk + ' ' + device.model + ' per e-mail..', 'Graag gedaan', function(result)
											{
												$(location).attr('href', 'https://' + config.domain + '/afspraak/');
											});
										}
										else
										{
											$(location).attr('href', 'https://irepair.nu/wp-admin/admin.php?page=ioffers');
										}
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
				}
			}
			else if(target === 'irepairs')
			{
				irepairs = (app.role(['admin', 'administrator', 'developer']) ? '<small class="muted text-center">Laat onderstaande leeg om alleen een uitnodiging te versturen!</small>' : '<small class="active text-center">Selecteer het aantal sterren!</small>');
				irepairs += '<div class="form-item">' +
					'<fieldset class="stars">' +
						'<input type="radio" id="star5" name="_stars" value="10" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star5" title="Uitstekend"></label>' +
						'<input type="radio" id="star4half" name="_stars" value="9" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star4half" title="Uitstekend"></label>' +
						'<input type="radio" id="star4" name="_stars" value="8" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star4" title="Geweldig"></label>' +
						'<input type="radio" id="star3half" name="_stars" value="7" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star3half" title="Geweldig"></label>' +
						'<input type="radio" id="star3" name="_stars" value="6" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star3" title="Redelijk"></label>' +
						'<input type="radio" id="star2half" name="_stars" value="5" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star2half" title="Redelijk"></label>' +
						'<input type="radio" id="star2" name="_stars" value="4" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star2" title="Onvoldoende"></label>' +
						'<input type="radio" id="star1half" name="_stars" value="3" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star1half" title="Onvoldoende"></label>' +
						'<input type="radio" id="star1" name="_stars" value="2" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star1" title="Slecht"></label>' +
						'<input type="radio" id="starhalf" name="_stars" value="1" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="starhalf" title="Slecht"></label>' +
					'</fieldset>' +
				'</div>' +
				'<br /><br />' + 
				'<div class="form-item">' +
					'<label for="_number">Titel:</label>' +
					'<input type="text" name="_subject" placeholder="Korte versie.." onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' />' +
				'</div>' +
				'<div class="form-item">' +
					'<label for="_description">Beoordeling:</label>' +
					'<textarea name="_description" placeholder="Uitgebreid verslag.." pattern="' + app.pattern('textarea') + '" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' rows="3"></textarea>' +
				'</div>';
				app.popupper('<i class="fa fa-list fa-fw"></i> Reparatie', istart + iclient + iemailaddress + idevider + irepairs + iend,
				'Bevestigen', function(result)
				{
					if(result)
					{
						$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
							'action': 'iclients',
							'source': 'irepairs',

							'id': result._id, 
							'cid': result._cid, 
							'roles': result._roles, 
							'name': result._name, 
							'emailaddress': result._emailaddress,

							'stars': result._stars,
							'subject': result._subject,
							'description': result._description,
						}, function(data)
						{
							//console.dir(data);
							if(data.status === 'unavailable')
							{
								app.popupper('<i class="fa fa-bullhorn fa-fw"></i> Review', 'Helaas, je hebt je review al eens aangepast..<br /><hr />Neem voor meer informatie contact met ons op..', 'Contact', function(result)
								{
									location.replace('/reviews/');
								});
							}
							else if(data.status === 'success')
							{
								if(!app.role(['admin', 'administrator', 'developer']))
								{
									app.popupper('<i class="fa fa-bullhorn fa-fw"></i> Review', 'Hartelijk dank voor je eerlijke én inhoudelijke review!<br /><hr />Wij zullen je review onder het genot van een ' + app.random(['kop thee', 'bak koffie', 'vruchtensapje', 'glaasje limonade']) + ' voor plaatsing eerst handmatig controleren, dit om ongewenste spam te voorkomen..', 'Graag gedaan', function(result)
									{
										location.replace('/reviews/');
									});
								}
								else
								{
									location.replace('/reviews/');
								}
							}
						});
						return true;
					}
					return false;
				}, true);
			}
			else if(target === 'ireviews')
			{
				ireviews = (app.role(['admin', 'administrator', 'developer']) ? '<small class="muted text-center">Laat onderstaande leeg om alleen een uitnodiging te versturen!</small>' : '<small class="active text-center">Selecteer het aantal sterren!</small>');
				ireviews += '<div class="form-item">' +
					'<fieldset class="stars">' +
						'<input type="radio" id="star5" name="_stars" value="10" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star5" title="Uitstekend"></label>' +
						'<input type="radio" id="star4half" name="_stars" value="9" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star4half" title="Uitstekend"></label>' +
						'<input type="radio" id="star4" name="_stars" value="8" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star4" title="Geweldig"></label>' +
						'<input type="radio" id="star3half" name="_stars" value="7" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star3half" title="Geweldig"></label>' +
						'<input type="radio" id="star3" name="_stars" value="6" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star3" title="Redelijk"></label>' +
						'<input type="radio" id="star2half" name="_stars" value="5" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star2half" title="Redelijk"></label>' +
						'<input type="radio" id="star2" name="_stars" value="4" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star2" title="Onvoldoende"></label>' +
						'<input type="radio" id="star1half" name="_stars" value="3" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="star1half" title="Onvoldoende"></label>' +
						'<input type="radio" id="star1" name="_stars" value="2" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="full" for="star1" title="Slecht"></label>' +
						'<input type="radio" id="starhalf" name="_stars" value="1" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' /><label class="half" for="starhalf" title="Slecht"></label>' +
					'</fieldset>' +
				'</div>' +
				'<br /><br />' + 
				'<div class="form-item">' +
					'<label for="_number">Titel:</label>' +
					'<input type="text" name="_subject" placeholder="Korte versie.." onfocus="if (this.value==this.defaultValue) this.value = \'\'" onblur="if (this.value==\'\') this.value = this.defaultValue" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' />' +
				'</div>' +
				'<div class="form-item">' +
					'<label for="_description">Beoordeling:</label>' +
					'<textarea name="_description" placeholder="Uitgebreid verslag.." pattern="' + app.pattern('textarea') + '" ' + (app.role(['admin', 'administrator', 'developer']) ? '' : 'required="required"') + ' rows="3"></textarea>' +
				'</div>';
				app.popupper('<i class="fa fa-bullhorn fa-fw"></i> Review', istart + iclient + iemailaddress + idevider + ireviews + iend,
				'Bevestigen', function(result)
				{
					if(result)
					{
						$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
							'action': 'iclients',
							'source': 'ireviews',

							'id': result._id, 
							'cid': result._cid, 
							'roles': result._roles, 
							'name': result._name, 
							'emailaddress': result._emailaddress,

							'stars': result._stars,
							'subject': result._subject,
							'description': result._description,
						}, function(data)
						{
							//console.dir(data);
							if(data.status === 'unavailable')
							{
								app.popupper('<i class="fa fa-bullhorn fa-fw"></i> Review', 'Helaas, je hebt je review al eens aangepast..<br /><hr />Neem voor meer informatie contact met ons op..', 'Contact', function(result)
								{
									location.replace('/reviews/');
								});
							}
							else if(data.status === 'success')
							{
								if(!app.role(['admin', 'administrator', 'developer']))
								{
									app.popupper('<i class="fa fa-bullhorn fa-fw"></i> Review', 'Hartelijk dank voor je eerlijke én inhoudelijke review!<br /><hr />Wij zullen je review onder het genot van een ' + app.random(['kop thee', 'bak koffie', 'vruchtensapje', 'glaasje limonade']) + ' voor plaatsing eerst handmatig controleren, dit om ongewenste spam te voorkomen..', 'Graag gedaan', function(result)
									{
										location.replace('/reviews/');
									});
								}
								else
								{
									location.replace('/reviews/');
								}
							}
						});
						return true;
					}
					return false;
				}, true);
			}
			else if(target === 'iserial')
			{
				iserial = '';
				app.popupper('Wat is het IMEI óf Serienummer?!',
					'<form id="popformer" novalidate="novalidate">' +
						'<div class="form-item">' +
							'<input type="text" name="_serial" placeholder="" pattern="[A-z0-9À-ž .]{11,12}" required="required" /><br />' +
							'<div class="item-hint">&nbsp;</div>' +
						'</div>' +
					'</form>',
				'Controleren', function(result)
				{
					if(result)
					{
						//console.dir(result);
						$.ajax({
							url : 'https://' + config.domain + '/wp-admin/admin-ajax.php',
							type : 'get',
							data : {
								'action' : 'check',
								'type' : 'serial',
								'value' : result._serial
							},
							dataType : 'json',
							global: false,
							cache: false,
							crossDomain: true,
							success : function(response)
							{
								console.dir(response);
								if(response.result.device)
								{
									app.popupper((response.device ? response.device.merk + ' ' + response.device.model : response.result.device), 
									'<b>Nummers:</b> ' + response.result.nummers + '<br><br>' +
									'<b>Gefabriceerd:</b> ' + response.result.dates.manufactured + '<br>' +
									'<b>Garantie:</b> ' + response.result.dates.warranty + '<br>' +
									'<b>Care:</b> ' + response.result.dates.care + '<br><br>' +
									'<b>Gestolen:</b> ' + (response.result.gestolen ? 'Ja, sinds ' + response.result.gestolen : 'Nee'));
								}
								else if(response.result)
								{
									app.popupper(response.serial, response.result);
								}
								else
								{
									app.popupper(response.serial, 'Onbekend.. ..probeer het nog eens?');
								}
									/*
									c8rxcqwqjc67
									357329097953782
								*/
								/*

								*/
							}
						});
					}
				});
				/*
				$('input[name="_serial"]').trigger('focus');
				*/
			}
			else if(target === 'isubscribers')
			{
				isubscribers = '<h1>' + device.merk + ' ' + device.model + '</h1><br />Door je in te schrijven ga je ermee akkoord dat wij binnen 3 maanden een notificatie per e-mail versturen zodra het toestel leverbaar is..';
				switch(action)
				{
					case 'insert':
						app.popupper('<i class="fa fa-bell-o fa-fw"></i> Inschrijving', istart + iclient + iemailaddress + idevider + isubscribers + iend,
						'Inschrijven', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'action': 'iclients',
									'source': 'isubscribers',

									'id': result._id, 
									'cid': result._cid, 
									'name': result._name, 
									'emailaddress': result._emailaddress,
									'device': info.device,
									'state': info.state
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'unavailable')
									{
										app.popupper('<i class="fa fa-bell-o fa-fw"></i> Inschrijving', 'Helaas, inschrijven is tijdelijk niet mogelijk..', 'alert');
									}
									else if(data.status === 'unsubscribed')
									{
										app.popupper('<i class="fa fa-bell-o fa-fw"></i> Inschrijving', 'Je bent nú uitgeschreven..', 'alert', function(result){
											location.reload();
										});
									}
									else if(data.status === 'subscribed')
									{
										app.popupper('<i class="fa fa-bell-o fa-fw"></i> Inschrijving', 'Je bent al ingeschreven! Nog eventjes geduld..', 'alert');
									}
									else if(data.status === 'success')
									{
										app.popupper('<i class="fa fa-bell-o fa-fw"></i> Inschrijving', 'Zodra er een ' + device.merk + ' ' + device.model + ' beschikbaar is hoor je van ons!', 'Tot dan', function(result)
										{
											///*
											if(result)
											{
												if(koekje = app.cookie(info.device, true))
												{
													koekje += ', ' + info.state;
												}
												else
												{
													koekje = info.state
												}
												if(app.cookie(info.device, koekje, '365'))
												{
													location.reload();
												}
											}
											//*/
											//location.reload();
										});
									}
									//console.dir(data);
								});
								return true;
							}
							return false;
						}, true);
						break;
					case 'delete':
						app.popupper('<i class="fa fa-bell-slash-o fa-fw"></i> Uitschrijving', 'Weet je zeker dat je jezelf wil uitschrijven?', 'Natuurlijk', function(result)
						{
							if(result)
							{
								$.getJSON('https://' + config.domain + '/wp-admin/admin-ajax.php', {
									'action': 'iclients',
									'source': 'isubscribers',

									'delete': '',

									'id': info.id, 
									'name': info.name, 
									'emailaddress': info.emailaddress,
									'device': info.device,
								}, function(data)
								{
									//console.dir(data);
									if(data.status === 'success')
									{
										location.reload();
									}
								});
								return true;
							}
							return false;
						}, true);
						break;
					default:
				}
			}
			else
			{
				// ignore
			}
		},
		fixed: function(value, decimal)
		{
			decimal = (app.empty(decimal) ? 2 : decimal);
			return parseFloat(value).toFixed(decimal);
			/*
				var re = new RegExp('^-?\\d+(?:\.\\d{' + (decimal || -1) + '})?');
				return value.toString().match(re)[0];
			*/
		},
		floated: function(value, decimal)
		{
			/*
				empty '0'.toFixed(decimal)
				is_numeric > value.toFixed(decimal)
				is_string > parseFloat(value).toFixed(decimal)
			*/
			//console.log(value);
			decimal = (app.empty(decimal) ? 2 : decimal);
			if(value === '')
			{
				return parseFloat('0').toFixed(decimal);
			}
			else if(app.is_numeric(value))
			{
				return parseInt(value).toFixed(decimal);
			}
			else if(app.is_decimal(value))
			{
				return parseFloat(value).toFixed(decimal);
			}
			//value = Number(value.replace(/[€\s,]+/g, ''));
			value = value.replace(/[^0-9\.-]+/g, '');
			return parseFloat(value).toFixed(decimal);
		},
		toFloat: function(value, decimal)
		{
			dotPos = value.indexOf('.');
			dotPos = (dotPos < 0 ? 0 : dotPos);
			commaPos = value.indexOf(',');
			commaPos = (commaPos < 0 ? 0 : commaPos);
			sep = ((dotPos > commaPos) && dotPos ? dotPos : ((commaPos > dotPos) && commaPos ? commaPos : false));
			return (sep == false ? parseFloat(value.replace(/[^\d]/g, "")) : parseFloat(value.substr(0, sep).replace(/[^\d]/g, "") + '.' + value.substr(sep+1, value.length).replace(/[^0-9]/, "")));
		},
		stringify: function(value)
		{
			return JSON.stringify(value);
		},
		/*
		check if #popupper not exists!
		send 'active' on scroll, resize and keypress and config.idler = 0;
		else every 10 seconds 'inactive' and config.idler++;
		idler: function()
		{
			config.idler = config.idler + 1;
			//console.log(config.idler);
			if(config.idler == 5)
			{
				//app.report('<b>Melding:</b> Rechtenbeleid', 'Door '  + config.ipaddress + ' is het rechtenbeleid bestudeerd!');
				app.popupper('<i class="fa fa-life-ring fa-fw"></i> Test!', 
				'Wij helpen je graag persoonlijk bij het maken van een keuze!<br /><br />' +
				'Contact', function(result)
				{
					if(result)
					{
						//location.replace('/contact');
					}
				});
				config.idler = 0;
			}
		},
		activity: function(action)
		{
			config.activity = setTimeout(app.activity('inactive'), 5000);
			switch(action)
			{
				case 'inactive':
					// +1
					break;
				default:
					// =0
					clearTimeout(config.activity);
					config.activity = setTimeout(app.activity('inactive'), 5000);
					break;

			}
			if(5)
			{
				//console.log('Jala!');
			}
			//
			$(document).bind('mousemove', function()
			{
				app.activity('active');
			}).bind('keypress', function()
			{
				app.activity('active');
			}).bind('onscroll', function()
			{
				app.activity('active');
			});
			//
		},
		*/
		popupper: function(title, message, type, callback, autoclose, esc)
		{
			/*
				if app.is_array()
				else

			*/
			var buttons = {};
			type = (app.empty(type) ? 'alert' : type);
			callback = (app.empty(callback) ? false : callback);
			autoclose = (app.empty(autoclose) ? true : autoclose);
			esc = (app.empty(esc) ? true : esc);
			$('#popupper').dialog('destroy').remove();
			switch(type)
			{
				case 'alert':
					buttons = [
						{
							text: 'Sluiten', 
							click: function(e, ui)
							{
								e.preventDefault();
								if($(this).has('form'))
								{
									var checked = true;
									$('input:radio').each(function()
									{
										var name = $(this).attr('name'), required = $(this).attr('required');
										if($('input:radio[name="' + name + '"]:checked').length == 0 && required)
										{
											checked = false;
										}
									});
									if(checked)
									{
										$('#popupper .ui-dialog-titlebar').append('<span style="float: right; font-size: 75%">Laden..</span>');
										app.validate('#popformer', function(result)
										{
											if(callback && typeof (callback) === 'function')
											{
												app.popupper('<i class="fa fa-refresh fa-spin fa-fw"></i> Bezig met laden..', 'Een ogenblik geduld!');
												callback(result);
											};
											if(autoclose){ 
												$('#popupper').dialog('destroy').remove();
												//$('#popupper').dialog().dialog('close').dialog().dialog('destroy'); 
											}
										});
									}
								}
								else
								{
									$(this).dialog('destroy').remove();
									//$(this).dialog().dialog('close').dialog().dialog('destroy');
								}
							}
						}
					];
					break;
				case 'confirm':
					buttons = [
						{
							text: 'Doorgaan', 
							click: function(e, ui)
							{
								e.preventDefault();
								if($(this).has('form'))
								{
									var checked = true;
									$('input:radio').each(function()
									{
										var name = $(this).attr('name'), required = $(this).attr('required');
										if($('input:radio[name="' + name + '"]:checked').length == 0 && required)
										{
											checked = false;
										}
									});
									if(checked)
									{
										$('.ui-dialog-titlebar', this).append('<span style="float: right; font-size: 75%">Laden..</span>');
										app.validate('#popformer', function(result)
										{
											if(callback && typeof (callback) === 'function')
											{
												app.popupper('<i class="fa fa-refresh fa-spin fa-fw"></i> Bezig met laden..', 'Een ogenblik geduld!');
												callback(result);
											};
											if(autoclose){
												$('#popupper').dialog('destroy').remove();
												//$('#popupper').dialog().dialog('close').dialog('destroy');
											}
										});
									}
								}
								else
								{
									$(this).dialog('destroy').remove();
									//$(this).dialog().dialog('close').dialog().dialog('destroy');
								}
							}
						},
						{
							text: 'Annuleren', 
							click: function(e, ui)
							{
								e.preventDefault();
								if(callback && typeof (callback) === 'function')
								{
									callback(false);
								};
								if(autoclose){ 
									$('#popupper').dialog('destroy').remove();
									//$('#popupper').dialog().dialog('close').dialog('destroy');
								}
							},
							'class': 'ui-button-left'
						}
					];
					break;
				case 'waiting':
					buttons = [];
					break;
				default:
					buttons = [
						{
							text: app.ucfirst(type), 
							click: function(e, ui)
							{
								//console.dir(e);
								e.preventDefault();
								if($(this).has('form'))
								{
									var checked = true;
									$('input:radio').each(function()
									{
										var name = $(this).attr('name'), required = $(this).attr('required');
										if($('input:radio[name="' + name + '"]:checked').length == 0 && required)
										{
											checked = false;
										}
									});
									if(checked)
									{
										$('.ui-dialog-titlebar', this).append('<span style="float: right; font-size: 75%">Laden..</span>');
										app.validate('#popformer', function(result)
										{
											if(callback && typeof (callback) === 'function')
											{
												app.popupper('<i class="fa fa-refresh fa-spin fa-fw"></i> Bezig met laden..', 'Een ogenblik geduld!');
												callback(result);
											};
											if(autoclose){ 
												$('#popupper').dialog('destroy').remove();
												//$('#popupper').dialog().dialog('close').dialog('destroy'); 
											}
										});
									}
								}
								else
								{
									$(this).dialog('destroy').remove();
									//$(this).dialog().dialog('close').dialog('destroy');
								}
							}
						},
						{
							text: 'Annuleren', 
							click: function(e, ui)
							{
								e.preventDefault();
								if(callback && typeof (callback) === 'function')
								{
									callback(false);
								};
								$(this).dialog('destroy').remove();
								//$(this).dialog().dialog('close').dialog('destroy');
							},
							'class': 'ui-button-left'
						}
					];
			}
			title = title || 'Bevestigen';

			var dialog = $('<div id="popupper"></div>').appendTo('body').html(message).dialog({
				modal: true,
				autoOpen: false,
				bgiframe: true,
				closeOnEscape: esc,
				draggable: true,
				resizable: false,
				width: 'auto',
				height: 'auto',
				title: title,
				show: {
					effect: 'blind',
					duration: 400,
				},
				hide: {
					effect: 'explode',
					duration: 400
				},
				open: function(e, ui)
				{
					app.dialogs();
					//$('#popformer input').trigger('blur');
					app.captcha('generate');
					$('.datepicker').datepicker({
						autoclose: true,
						dateFormat : 'dd-mm-yy',
						selectOtherMonths: true
					});
					//$('#ui-datepicker-div').css('clip', 'auto');
					/*
						$('#datepicker').datepicker({
							autoclose: true,
							dateFormat : 'dd-mm-yy',
							selectOtherMonths: true
						});//.css('z-index', $(this).parents('.ui-dialog').css('z-index')+1);
					*/
					//console.log($(this).find('button[class*="ui-dialog-titlebar-close"]').attr('title'));
					$('#popformer').on('keypress', function(e)
					{
						var key = (e.keyCode ? e.keyCode : e.which), name = $(this).attr('name');
						if(key == 13)
						{
							e.preventDefault();
						}
					}).on('submit', function(e)
					{
						e.preventDefault();
					});
				},
				close: function(e, ui)
				{
					$('.datepicker').datepicker('hide');
					$(this).dialog().dialog('close').remove();
				},
				buttons: buttons
			});
			dialog.dialog('open');
			return false;
		},
		quotations: function()
		{
			var	currentSlide = '#quote-' + config.quote + '-content', lastSlide = config.quoton + '-content', currentButton = '#quote-' + config.quote;
			$('.slider-quote').removeClass('quote-focused');
			$('.quote-control').removeClass('quote-selected');
			$(currentSlide).addClass('quote-focused');
			$(currentButton).addClass('quote-selected');
			quoton = currentButton;
			if(config.quote < config.quotes)
			{
				config.quote += 1;
			}
			else
			{
				config.quote = 0;
			}
		},
		query: function(name)
		{
			var query = new RegExp('[\?&]' + name + '=([^&#]*)').exec($(location).attr('href'));
			return (query == null ? false : decodeURIComponent(query[1]) || 0);
		},
		random: function(array)
		{
			if(app.is_array(array))
			{
				return array[Math.floor(Math.random() * array.length)];
			}
			else
			{
				return Math.floor(Math.random() * arg);
			}
		},
		range: function(start, end)
		{
			var array = [];
			for(var i = start; i < end; i++)
			{
				array.push(i);
			}
			return array;
		},
		applify: function(str, ucwords)
		{
			result = '';
			ucwords = ucwords || false;
			str = (ucwords ? app.ucwords(str.toLowerCase()) : app.ucfirst(str.toLowerCase())).split(' ');
			for(var i = 0; i < str.length; i++)
			{
				$.each({
					'apple': 'Apple', 'ipod': 'iPod', 'iphone': 'iPhone', 'ipad': 'iPad', 'macbook': 'MacBook', 'imac': 'iMac',
					'applecare': 'AppleCare', 'applelink': 'AppleLink', 'applescript': 'AppleScript', 'appleshare': 'AppleShare', 'appleTalk': 'AppleTalk', 'appleworks': 'AppleWorks',
					'airdrop': 'AirDrop', 'airmac': 'AirMac', 'airplay': 'AirPlay', 'airpods': 'AirPods', 'airport': 'AirPort', 'airpower': 'AirPower', 'airprint': 'AirPrint', 'airtunes': 'AirTunes',
					'carplay': 'CarPlay', 'colorsync': 'ColorSync',
					'earpods': 'EarPods', 'ethertalk': 'EtherTalk',
					'facetime': 'FaceTime', 'fairplay': 'FairPlay',
					'homepod': 'HomePod', 'hd': 'HD',
					'ibook': 'iBook', 'ical': 'iCal', 'ichat': 'iChat', 'icloud': 'iCloud', 'idisk': 'iDisk', 'idvd': 'iDVD', 'iframe': 'iFrame', 'ilive': 'iLive', 'imessage': 'iMessage', 'imix': 'iMix', 'ios': 'iOS', 'imovie': 'iMovie', 'iphoto': 'iPhoto', 'isight': 'iSight', 'itunes': 'iTunes', 'iweb': 'iWeb', 'iworks': 'iWorks', 'iwork': 'iWork',
					'laserwrite': 'LaserWrite', 'lifetype': 'LifeType', 'localtalk': 'LocalTalk',
					'macapp': 'MacApp', 'macdns': 'MacDNS', 'macos': 'MacOS', 'magsafe': 'MagSafe',
					'os': 'OS', 
					'powerbook': 'PowerBook', 'procare': 'ProCare',
					'quickdraw': 'QuickDraw', 'quicktime': 'QuickTime', 'quicktype': 'QuickType',
					'stylewrite': 'StyleWrite', 'superdrive': 'SuperDrive',
					'truetype': 'TrueType', 'tvos': 'tvOS',
					'watchos': 'watchOS'
				}, function(k, v)
				{
					str[i] = str[i].replace(new RegExp('^' + k, 'i'), v);
				});
			}
			return str.join(' ');
		},
		replace: function(str, array)
		{
			$.each(array, function(key, value)
			{
					str = str.replace(key, value);
			});
			return str;
		},
		replacer: function(str)
		{
			return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
		},
		report: function(title, message, debug)
		{
			debug = debug || false;
			var cid = (debug ? '13779930' : '-1001098110286'), url;
			if(app.empty(message))
			{
				url = 'https://api.telegram.org/bot830400600:AAHhwYNHAb40D1ni9CyihI2jIu7mZsiKpZ4/sendmessage?chat_id=' + cid + '&text=' + encodeURI(title) + '&disable_web_page_preview=1&disable_notification=0&parse_mode=HTML';
			}
			else
			{
				url = 'https://api.telegram.org/bot830400600:AAHhwYNHAb40D1ni9CyihI2jIu7mZsiKpZ4/sendmessage?chat_id=' + cid + '&text=' + encodeURI(title + '\n\n' + message.replace(/<br \/>/g, "\n")) + '&disable_web_page_preview=1&disable_notification=0&parse_mode=HTML';
			}
			$.get(url, function(data)
			{
				//console.log(data);
			});
		},
		role: function(roles)
		{
			if(app.is_array(roles))
			{
				var result = false;
				$.each(roles, function(i, role)
				{
					if(app.in_array(role, config.roles))
					{
						result = true;
					}
				});
				return result;
			}
			return (app.in_array(roles, config.roles));
		},

		rotator: function(target)
		{
			target = (app.empty(target) ? 'clients' : target);
			var ul = $('.' + target + ' ul'), lis = parseInt(($(document).width()/300)+1);
			var first = $('.' + target + ' ul li:nth-child(1)'), between = $('.' + target + ' ul li:visible'), last = $('.' + target + ' ul li:nth-child(' + lis + ')');
			between.css({
				'opacity': '1',
			});
			first.css({
				'opacity': '0',
				'margin-left': '-250px'
			});
			last.css({
				'opacity': '0',
			});
			setTimeout(function()
			{
				first.css({
					'opacity': '0',
					
				}).remove();
				last.css({
					'opacity': '1',
				});
				setTimeout(function()
				{
					first.css({
						'opacity': '0',
						'margin-left': '0'
					});
					ul.append(first);
				}, 500);
			}, 100);
			config.rotator[target] = setTimeout(function()
			{
				app.rotator(target);
			}, 3000);
		},
		startswidth: function(str, value)
		{
			return (app.empty(str) || !str.startsWith(value) ? false : true);
		},
		scrollto: function(hash)
		{
			//$('html, body').animate({'scrollTop': (hash == 'top' ? 0 : 'a[name="' + hash.offset().top + '"]'}, 500));
			return false;
			//window.location.hash = '#' + hash;
		},
		str_pad: function(str, max)
		{
			str = str.toString();
			return (str.length < max ? app.str_pad('0' + str, max) : str);
		},
		strtolower: function(str)
		{
			return str.toLowerCase();
		},
		strtoupper: function(str)
		{
			return str.toUpperCase();
		},
		test: function(str, regex)
		{
			regex = (app.empty(regex) ? '^[A-zÀ-ÿ0-9\\s/,\/\\.\\+\\*\\?\\(\\)\\=\\!\\-&#€@\'"]+$' : regex);
			regex = new RegExp(regex);
			return regex.test(str);
		},
		timeout: function(that, target, value, seconds)
		{
			seconds = (app.empty(seconds) ? 1000 : seconds);
			var timeout = (Object.keys(config.timeouts).length*100);
			if(that instanceof j)
			{
				clearTimeout(config.timeouts[$(that).attr('name')]);
				config.timeouts[$(that).attr('name')] = setTimeout(function()
				{
					switch(target)
					{
						case 'border':
							$(that).css('border', value);
							break;
						case 'checked':
							$(that).attr('checked', value);
							break;
						case 'html':
							$(that).html(value);
							break;
						case 'trigger':
							$(that).trigger(value);
							break;
						default:
							//console.dir(that);
					}
				}, seconds + timeout);
			}
			else if(app.in_array(that, ['iprivacy', 'ireviews']))
			{
				clearTimeout(config.timeouts[that]);
				config.timeouts[that] = setTimeout(function()
				{
					app.popformer(that, target, value);
				}, seconds + timeout);

			}
		},
		typeOf: function(value)
		{
			var s = typeof value;
			if(s === 'object')
			{
				if(value)
				{
					if(value instanceof Array)
					{
						s = 'array';
					}
				}
				else
				{
					s = 'null';
				}
			}
			return s;
		},
		ucfirst: function(text)
		{
			return text.substr(0,1).toUpperCase() + text.substr(1);
		},
		ucwords: function(text)
		{
			return (text + '').replace(/^(.)|\s+(.)/g, function($1)
			{
				return $1.toUpperCase();
			});
		},
		urlencode : function(str)
		{
			str = (str + '').toString();
			return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
		},
		validator: function(name, value, type, pattern, required, defaults)
		{
			//console.log(pattern);
			if($(type + '[name="' + name + '"]').length)
			{
				if(required)
				{
					if(value === '' || !app.test(value, pattern))
					{
						//console.log('1! > ' + name + ': "' + value + '"' + ' with ' + pattern);
						return false;
					}
					//console.log('1- > ' + name + ': "' + value + '"');
					return true;
				}
				else
				{
					if(value !== '' && !app.test(value, pattern))
					{
						//console.log('2! > ' + name + ': "' + value + '"' + ' with ' + pattern);
						return false;
					}
					else if(defaults && value === '')
					{
						/*
						if(!$(type + '[name="' + name + '"]').hasClass('defocus'))
						{
							$(type + '[name="' + name + '"]').val(config.value);
							config.value = '';
						}
						*/
					}
					//console.log('2- > ' + name + ': "' + value + '"');
					return true;
				}
			}
			//console.log('3? > ' + name + ': "' + value + '"');
			return true;
		},
		validate: function(that, callback)
		{
			var result, valid = true;
			var name, value, type, pattern, required, timeouts = 0;
			if(that instanceof j && !$(that).hasClass('button') && !$(that).is('button'))
			{
				result = '';
				name = $(that).attr('name'), value = ($(that).has('value') ? $.trim($(that).val()) : ''), type = ($(that).is('input') ? 'input' : ($(that).is('select') ? 'select' : ($(that).is('textarea') ? 'textarea' : 'button'))), email = ($(that).attr('type') === 'email' || $(that).hasClass('is_email') ? true : false), pattern = (app.empty($(that).attr('pattern')) ? ($(that).attr('type') === 'email' || $(that).hasClass('is_email') ? app.pattern('email') : ($(that).is('textarea') ? app.pattern('textarea') : app.pattern('plain'))) : $(that).attr('pattern')), required = (app.empty($(that).attr('required')) && !$(that).hasClass('is_empty') && !$(that).attr('type') !== 'email' && !$(that).hasClass('is_email') && !$(that).hasClass('captcha') ? false : true);
				//console.log('Validate1 for ' + name + ': ' + value);
				if(app.validator(name, value, type, pattern, required, true))
				{
					if(email)
					{
						$(that).css('border', '1px solid #ffff00');
						/*
							app.check('pwnd', value).done(function(result)
							{
								//console.dir(result);
							});
						*/
						app.check('MX', value).done(function(result)
						{
							//console.dir(result);
							if(result['status'] == 'valid')
							{
								$(that).css('border', '1px solid #4caf50');
								app.timeout($(that), 'border', '1px solid #b7b7b7', 5000);
							}
							else
							{
								valid = false;
								$(that).css('border', '1px solid #f44336');
							}
						});
					}
					else
					{
						$(that).css('border', '1px solid #4caf50');
						app.timeout($(that), 'border', '1px solid #b7b7b7', 5000);
					}
				}
				else
				{
					valid = false;
					//$(that).closest('tr').next('tr').find('input, select').filter(':visible').attr('disabled', 'disabled');
					$(that).css('border', '1px solid #f44336');
				}
				result = value;
				//console.log('Jala: ' + result);
			}
			else
			{
				result = {};
				$(that).closest('form').find('input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="radio"], select, textarea').filter(':visible').each(function(i, el)
				{
					var that = $(this), name = $(this).attr('name'), value = ($(this).has('value') ? $.trim($(this).val()) : ''), type = ($(this).is('input') ? 'input' : ($(this).is('select') ? 'select' : ($(this).is('radio') ? 'radio' : ($(this).is('textarea') ? 'textarea' : 'button')))), checkbox = $(this).is(':checkbox'), checked = $(this).is(':checked'), radio = $(this).is(':radio'), selected = $(this).is(':selected'), email = ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? true : false), pattern = (app.empty($(this).attr('pattern')) ? ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? app.pattern('email') : ($(this).is('textarea') ? app.pattern('textarea') : app.pattern('plain'))) : $(this).attr('pattern')), required = (app.empty($(this).attr('required')) && !$(this).hasClass('is_empty') && !$(this).attr('type') !== 'email' && !$(this).hasClass('is_email') ? false : true);
					if(!checkbox && !radio)
					{
						result[name] = '';
						if(app.validator(name, value, type, pattern, required, false))
						{
							if(email)
							{
								$(that).css('border', '1px solid #ffff00');
								/*
									app.check('pwnd', value).done(function(result)
									{
										//console.dir(result);
									});
								*/
								app.check('MX', value).done(function(result)
								{
									//console.dir(result);
									if(result['status'] == 'valid')
									{
										$(that).css('border', '1px solid #4caf50');
										app.timeout($(that), 'border', '1px solid #b7b7b7', 5000);
									}
									else
									{
										//console.log('Invalid: ' + name);
										valid = false;
										$(that).css('border', '1px solid #f44336');
									}
								});
							}
							else
							{
								//console.log('Valid: ' + name + ': ' + value);
								$(this).css('border', '1px solid #4caf50');
								app.timeout($(this), 'border', '1px solid #b7b7b7', 5000);
							}
						}
						else
						{
							//console.log('Invalid: ' + name);
							valid = false;
							$(this).css('border', '1px solid #f44336');
						}
						if(name.substr(name.length-2) === '[]')
						{
							if(app.empty(result[name.slice(0, -2)]))
							{
								result[name.slice(0, -2)] = value;
							}
							else
							{
								result[name.slice(0, -2)] += '|' + value;
							}
						}
						else
						{
							result[name] += value;
						}
					}
					else if(checked || selected)
					{
						result[name] = value;
					}
				});
				$(that).closest('form').find('input[type="checkbox"], input[type="radio"]').each(function(i, el)
				{
					var that = $(this), name = $(this).attr('name'), value = $('input[name="' + name + '"]:checked').val(), type = ($(this).is('input') ? 'input' : ($(this).is('select') ? 'select' : ($(this).is('radio') ? 'radio' : ($(this).is('textarea') ? 'textarea' : 'button')))), checkbox = $(this).is(':checkbox'), checked = $(this).is(':checked'), radio = $(this).is(':radio'), selected = $(this).is(':selected'), email = ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? true : false), pattern = (app.empty($(this).attr('pattern')) ? ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? app.pattern('email') : ($(this).is('textarea') ? app.pattern('textarea') : app.pattern('plain'))) : $(this).attr('pattern')), required = (app.empty($(this).attr('required')) && !$(this).hasClass('is_empty') && !$(this).attr('type') !== 'email' && !$(this).hasClass('is_email') ? false : true);
					//console.log(name + ': ' + value);
					result[name] = value;
				});
				$(that).closest('form').find('input[type="hidden"]').each(function(i, el)
				{
					var that = $(this), name = $(this).attr('name'), value = ($(this).has('value') ? $.trim($(this).val()) : ''), type = ($(this).is('input') ? 'input' : ($(this).is('select') ? 'select' : ($(this).is('radio') ? 'radio' : ($(this).is('textarea') ? 'textarea' : 'button')))), checkbox = $(this).is(':checkbox'), checked = $(this).is(':checked'), radio = $(this).is(':radio'), selected = $(this).is(':selected'), email = ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? true : false), pattern = (app.empty($(this).attr('pattern')) ? ($(this).attr('type') === 'email' || $(this).hasClass('is_email') ? app.pattern('email') : ($(this).is('textarea') ? app.pattern('textarea') : app.pattern('plain'))) : $(this).attr('pattern')), required = (app.empty($(this).attr('required')) && !$(this).hasClass('is_empty') && !$(this).attr('type') !== 'email' && !$(this).hasClass('is_email') ? false : true);
					if(!checkbox && !radio)
					{
						result[name] = value;
					}
					else if(checked || selected)
					{
						result[name] = value;
					}
				});
			}
			//console.dir(result);
			if(valid)
			{
				if(callback && typeof (callback) === 'function')
				{
					return callback(result);
				};
				return true;
			}
			//$(that).css('border', '1px solid #f44336');
			return false;
		},
		/*
			confirmer: function(e, question, callback = function(){})
			{
				callback(confirm(question));
			},
			prompter: function(e, question, pattern = /^\d{0,4}(\.\d{0,2})?$/, callback = function(){})
			{
				var answer = valid = false;
				do {
					answer = prompt(question);
					valid = pattern.test(answer);
				}
				while(!valid);
				callback(answer);
			}
		*/
	};
})(j);

if(!String.prototype.startsWith)
{
	String.prototype.startsWith = function(search, pos)
	{
		return (this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search);
	};
}
if(!String.prototype.endsWith)
{
	String.prototype.endsWith = function(suffix)
	{
		return (this.indexOf(suffix, this.length-suffix.length) !== -1);
	};
}
if(!String.prototype.contains)
{
	String.prototype.contains = function(str, startIndex)
	{
		"use strict";
		return (-1 !== String.prototype.indexOf.call(this, str, startIndex));
	};
}
if(!String.prototype.includes)
{
	String.prototype.includes = function(search, start)
	{
		'use strict';
		if(typeof start !== 'number')
		{
			start = 0;
		}
		return (start + search.length > this.length ? false : this.indexOf(search, start) !== -1);
	};
}