<script type="text/javascript">
	$(document).ready(function (e) {
		$("#save").submit(function(e) {
	        e.preventDefault();
	        for (instance in CKEDITOR.instances) {
		        CKEDITOR.instances[instance].updateElement();
		    }
        	loading();
	        var form_data = new FormData(this);
	        $.ajax({
	            url: '{{url("/email_templates/save")}}',
	            type: 'POST',
	            data: form_data,
	            headers: {
		            'X-CSRF-TOKEN': '{{ csrf_token()}}'
		        },
	            contentType: false,
		        processData: false,
		        cache: false,
		        dataType: 'json',
	        })
	        .done(function (res) {
	           swal(res.text,res.cls);
	        })
	        .fail(function () {
	            console.log("error");

	        }).always(function(){
	        	loading("stop");
	        });
	    });

		$("#profile_update").submit(function(e) {
	        e.preventDefault();
	        for (instance in CKEDITOR.instances) {
		        CKEDITOR.instances[instance].updateElement();
		    }
        	loading();
	        var form_data = new FormData(this);
	        $.ajax({
	            url: '{{url("/email_templates/update")}}',
	            type: 'POST',
	            data: form_data,
	            headers: {
		            'X-CSRF-TOKEN': '{{ csrf_token()}}'
		        },
	            contentType: false,
		        processData: false,
		        cache: false,
		        dataType: 'json',
	        })
	        .done(function (res) {
	           swal(res.text,res.cls);
	        })
	        .fail(function () {
	            console.log("error");

	        }).always(function(){
	        	loading("stop");
	        });
	    });
	});

	function state_switch(id) {
    	loading();
        //var cid = $(this).val();
        $.ajax({
            url: '{{url("/email_templates/status")}}',
            type: 'post',
            dataType:'json',
            data: {_token: '{!! csrf_token() !!}', id: id}
        })
        .done(function (res) {
        	swal(res.text,res.cls);
        })
        .fail(function () {
            console.log("error");

        }).always(function(){
        	loading("stop");
        });
    }

	function destroy(id) {
	    bootbox.confirm("{{trans('admin.Are_you_sure_to_delete')}}", function(result){
	      loading();
	      //let id = $(this).val();
	      $.ajax({
	          url: '{{url("/email_templates/destroy")}}',
	          type: 'post',
	          dataType:'json',
	          data: {_token: '{!! csrf_token() !!}', id: id},
	      })
	      .done(function(res) {
	          swal(res.text,res.cls);
	          $("#"+id).hide(1000);
	      })
	      .fail(function() {
	          console.log("error");
	      })
	      .always(function() {
	          loading("stop");
	      }); 
	    })      
  	}
</script>