$(function(){

        if($('input.date').size() > 0){ 
        $('input.date').datepicker({ dateFormat: 'yy/mm/dd' , altFormat: 'yy/mm/dd',changeMonth: true,changeYear: true,yearRange: '1930:2026'}); 
        }
		
		
    	$('#form_67200e90d0862').validate({ 
		submitHandler:function(e){
		
		var g_recaptcha_response = $('#form_67200e90d0862 .g-recaptcha-response').val();			
	   if (!g_recaptcha_response && 1 ) {
			Swal.fire({icon: 'warning',title:'You must verfiy the CAPTCHA'});
			return false;
		} else {
			if (typeof ga === 'function') {
			console.log('fffff');
			 ga('send', 'event', { eventCategory: 'form', eventAction: 'submit'});
			} else if (typeof gtag === 'function') {
			console.log('ddddd');
                        gtag('event', 'submit', {
                          'event_category': 'form',
                          'event_label': 'Form Submit',
						  'send_to': window.send_to['GAGT']
                        });
						gtag('event', 'conversion', {'send_to': window.send_to['GT']}); 
			}
			var comId = $('#form_67200e90d0862').find('.comp_id').val();
			
		var data = new FormData(document.getElementById('form_67200e90d0862'));
		data.append('href',  location.href);

		if(window.AttachmentArray !== undefined && window.AttachmentArray.length > 0 ) {
			data.append('attachmentArray',window.AttachmentArray.map(o=>[ (o.FileName +'|'+ o.MimeType +'|'+ o.Content) ])); 
		}

	
Swal.showLoading();
		$.ajax({
			type: 'POST',
			url:'/helper/form-mailer',
			data: data,
			dataType: 'text',
			contentType: false,
			cache: false,
			usecaptcha:1,
			processData:false,
			success: function(data){ 
			Swal.close();
			if(typeof data =='string') {
				data =  JSON.parse(data.trim());
			}
				if(data.error == 0){
					 Swal.fire({
                          icon: 'success',
                          showClass: {
                            popup: `
                              form-thank-you
                            `
                          },
                          title: 'Sent Successfully',
                          timerProgressBar: true,
						  showConfirmButton: true,
						  allowOutsideClick: true,
                          timer: 6000
                        }).then(function() {
							window.location = '/';
						});

				} else{
					Swal.fire({icon: 'error',title:data.msg,  showConfirmButton: true,});
					grecaptcha.reset(); 
				}
			}
		});
			
			
			} 
		}})
			

	
	});
$(function(){
		//To save an array of attachments 
				window.AttachmentArray = [];
				//counter for attachment array
				window.arrCounter = 0;

				//to make sure the error message for number of files will be shown only one time.
				window.filesCounterAlertStatus = false;

				window.startUpload = 0;
				//console.log($('#images').size());
			$(document).on('change','#images',function(e){	
				handleFileSelect(e);
			})
		})
        

        //the handler for file upload event
		function handleFileSelect(e) {
		
            //to make sure the user select file/files
			console.log(1);
            if (!e.target.files) 
			{
				return;
			}
			console.log(2);
			Swal.showLoading();
			window.startUpload = 1;

            var files = e.target.files;
console.log(files);
            // Loop through the FileList and then to render image files as thumbnails.
            for (var i = 0, f; f = files[i]; i++) {
/*				if(i === 0) {
				 Swal.showLoading();
				}*/
                //instantiate a FileReader object to read its contents into memory
                var fileReader = new FileReader();

                // Closure to capture the file information and apply validation.
                fileReader.onload = (function (readerEvt) {
                    return function (e) {
                         //$("#overlay").fadeIn(300);　
						
                        //Apply the validation rules for attachments upload
                        //ApplyFileValidationRules(e,readerEvt)

                        //Render attachments thumbnails.
                        //RenderThumbnail(e, readerEvt);

                        //Fill the array of attachment
                        FillAttachmentArray(e, readerEvt)
                    };
                })(f);

                // Read in the image file as a data URL.
                // readAsDataURL: The result property will contain the file/blob's data encoded as a data URL.
                // More info about Data URI scheme https://en.wikipedia.org/wiki/Data_URI_scheme
                fileReader.readAsDataURL(f);
            }
            //document.getElementById('images').addEventListener('change', handleFileSelect, false);
			Swal.close();
			window.startUpload = 0;
			// $("#overlay").fadeOut(300);　
        };

        //Fill the array of attachment
        function FillAttachmentArray(e, readerEvt)
        {
            window.AttachmentArray[window.arrCounter] =
            {
                AttachmentType: 1,
                ObjectType: 1,
                FileName: readerEvt.name,
                FileDescription: "Attachment",
                NoteText: "",
                MimeType: readerEvt.type,
                Content: e.target.result.split("base64,")[1],
                FileSizeInBytes: readerEvt.size,
            };
            window.arrCounter = window.arrCounter + 1;
        };
window.WebsiteModal = false;
		window.PageModal = false;
