
scriptJquery(document).ready(function () {
	function selectImagePreview(selectObj) {
		//Create preview container
		if (selectObj.next('.select-image-preview').length == 0) {
			selectObj.after(
				'<div class="select-image-preview" style="margin-top:10px; display:none;">' +
				'<img src="" style="max-width:250px; max-height:100px; border:1px solid #ddd; padding:5px; border-radius:5px;" />' +
				'</div>'
			);
		}
		var previewBox = selectObj.next('.select-image-preview');
		var previewImg = previewBox.find('img');
		function updatePreview() {
			var selectedValue = selectObj.val();
			// Check image extension
			if (selectedValue && /\.(jpg|jpeg|png|gif|webp|svg)$/i.test(selectedValue)) {
				previewImg.attr('src', selectedValue);
				previewBox.show();
			} else {
				previewImg.attr('src', '');
				previewBox.hide();
			}
		}
		updatePreview();
		selectObj.on('change', function () {
			updatePreview();
		});
	}

	scriptJquery('.preview-select-image').each(function () {
		selectImagePreview(scriptJquery(this));
	});
});