$(document).ready(function() {
	cal_single = ics();
	cal_single.addEvent(
		'AGM',
		'',
		'Ying Li International Real Estate Limited',
		'4/27/2022 9:30 am',
		'4/27/2022 10:00 am'
	); //D/M/Y Time am/pm

	var shareholderForm = $('#shareholderForm');
	shareholderForm.on('submit', function(ev) {
		var form = new FormData();
		form.append('app', 'yingli');
		form.append('type', $('#type').val());
		form.append('name_of_representative', $('#name_of_representative').val());
		form.append('identity_number', $('#identity_number').val());
		form.append('full_name', $('#full_name').val());
		form.append('contact_number', $('#contact_number').val());
		form.append('contact_email', $('#contact_email').val());
		form.append('shareholding_type', $('#shareholding_type').val());
		form.append('meeting_type', $('#meeting_type').val());
		form.append('preference', $('#preference').val());
		form.append('question', $('#question').val());

		var settings = {
			url: '../web/index.php?r=shareholder/create',
			method: 'POST',
			timeout: 0,
			processData: false,
			mimeType: 'multipart/form-data',
			contentType: false,
			data: form
		};

		$('#loading-image').show();
		$.ajax(settings).done(function(response) {
			var res = JSON.parse(response);
			if (res.status) {
				// alert(res.data);
				$('#loading-image').hide();
				window.location.href = 'register-success.php';
			} else {
				alert(res.data);
			}
		});
		ev.preventDefault();
		return false;
	});

	$('#type')
		.change(function() {
			if ($(this).val() === 'Corporate') {
				document.getElementById('name_of_representative').setAttribute('required', '');
				$('.hideme').show();
			} else {
				document.getElementById('name_of_representative').removeAttribute('required');
				$('.hideme').hide();
			}
		})
		.change();

	var maxchars = 3000;
	$('textarea').keyup(function() {
		var tlength = $(this).val().length;
		$(this).val($(this).val().substring(0, maxchars));
		var tlength = $(this).val().length;
		remain = maxchars - parseInt(tlength);
		$('#remain').text(remain + ' characters remaining');
	});

	const current_date = new Date();
	const event_0_1 = new Date('April 19, 2022 23:59:00');
	console.log(event_0_1);
	if (current_date > event_0_1) {
		$('.questions').hide();
	}

	setTimeout(function() {
		$('#myModal').modal('show', {});
	}, 15 * 60 * 1000);
});
