// $.noConflict();
$(document).ready(function () {
    $('#tmpl_Form').on('submit', function (event) {
        event.preventDefault();
        var formdata = new FormData($(this)[0]);
        formdata.append('logo',$('#logoFile').val());
        $.ajax({
            url: 'pages/template/save_templ.php',
            method: 'POST',
            data: formdata,
            dataType : 'JSON',
            contentType: false,
            processData: false,
            success: function (response) {
                console.log(response);
                if(response.success){
                    swal('Success','Template created successfully')
                    // $("#tmpl_Form")[0].reset();                    
                }
                else{
                    // alert(response.error_derail);
                    console.log(response.error_derail);
                    swal('error',response.error_derail);
                }               
            }

        })
    });
    $('#tmpl_Form > #name').on('keyup', function(e) {
        console.log('template keyup');
        var val = $(this).val();        
        $.ajax({
            url: 'pages/template/template_check.php',
            methd: 'POST',
            data: {
                'template': val,
            },
            datatype: 'JSON',
            success: function(response) {
                var result = $.parseJSON(response);
                $('.tempateError').html(result.status_info);
                console.log(result.status_info);
            }
        });
    })
    
    $("form[name='tmpl_Form']").validate({
        rules:{
            name: "required",
            C_name: "required",
            C_Addr1: "required",
            C_Addr2: "required",
            C_Addr3: "required",
            C_Addr4: "required",
            C_gstin: "required",
            C_pan: "required"
            
        },
        messages: {
            name: "template name required",
            C_name: "company name required",
            C_Addr1: "Address line 1 required",
            C_Addr2: "Address line 2 required",
            C_Addr3: "Address line 3 required",
            C_Addr4: "Address line 4 required",
            C_gstin: "GSTIN required",
            C_pan: "PAN required"
            
        }
    });
});



