@if(!defined('LOAD_HANDLEBARS'))
	@push('scripts')
		<script> 
			function renderContractDriveTPL(filename, data, selector) {
				data.translate = translate;
				var path = '/assets/apps/ContractDrive/templates/';
				var content = getTemplate(path + filename, data);
				if (typeof(selector) == 'undefined')
				{
					return content;
				} else {
					$(selector).html(content);
				}
			}

			function getTemplate(file, data) {
				var source = getSource(file);
				var template = Handlebars.compile(source);
				return template(data);
			}

			function getSource(file) {
				var source = null;
				$.ajax({
					async: false,
					dataType: 'html',
					type: 'GET',
					url: file + '?' + Date.now(),
					success: function(data) {
						source = data;
					}
				});
				return source;
			}

			function view(template_id, data) {
				// console.log(template_id);
				// console.log(data);
				var source = document.getElementById(template_id).innerHTML;
				var template = Handlebars.compile(source);
				return template(data);
			}

			function helperSelect(name, items, selected, options) {

				// If the selected value is an array, then convert the
				// select to a multiple select
				if (selected instanceof Array) {
					options.hash.multiple = 'multiple';
				}

				// Generate the list of options
				var optionsHtml = '';
				for (var i = 0, j = items.length; i < j; i++) {

					// <option> attributes
					var attr = {
						value: items[i].value
					};

					// We can specify which options are selected by using either:
					// * an array of selected values or
					// * a single selected value
					if ((selected instanceof Array && indexOf(selected, items[i].value) !== -1) || (selected === items[i].value)) {
						attr.selected = 'selected';
					}

					optionsHtml += createElement('option', true, attr, items[i].text);
				}
			}
		</script>
	@endpush
	@php(define('LOAD_HANDLEBARS', true))
@endif