$(document).ready(function(){


	$(".master_table").dataTable();
    $(".cheque_field").hide();
    $("#co_contract_start, #co_cheque_date, #co_bill_date, #co_service_1, #co_service_2, #co_service_3").datepicker({
        format: 'dd-mm-yyyy'
    });

    $("#promo_date_start, #promo_date_expiry, .date_plug, #date_picker").datepicker({
        format: 'dd-mm-yyyy'
    });

    $('#date_range').daterangepicker();

    $("#co_contract_start").datepicker()
        .on('changeDate', function(){
        
        var start_date = $("#co_contract_start").val();
        var period = $("#co_period").val();

        set_expiry(start_date, period);
    });

    $("#co_period").change(function(){

        var start_date = $("#co_contract_start").val();
        var period = $("#co_period").val();

        set_expiry(start_date, period);

    });
});


// var base_url = 'http://localhost/albarkaatmumbai/';
var base_url = 'http://albarkaatmumbai.edu.in/';






    function display_alert(type,message)
    {
        var alert_msg = '';

        if(type == 'err')
        {
            alert_msg += '<div class="alert alert-danger" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'warn')
        {
            alert_msg += '<div class="alert alert-warning" role="alert">';
            alert_msg += '<span ><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'succ')
        {
            alert_msg += '<div class="alert alert-success" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }

        $(".alert_msg").html(alert_msg);


        setTimeout(function(){
            $(".alert_msg").html("");       
        },5000);
    }

    function display_alert_dealer(type,message)
    {
        var alert_msg = '';

        if(type == 'err')
        {
            alert_msg += '<div class="alert alert-danger" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'warn')
        {
            alert_msg += '<div class="alert alert-warning" role="alert">';
            alert_msg += '<span ><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'succ')
        {
            alert_msg += '<div class="alert alert-success" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }

        $(".alert_msg_d").html(alert_msg);


        setTimeout(function(){
            $(".alert_msg_d").html("");       
        },5000);
    }

    function display_alert_newsletter(type,message)
    {
        var alert_msg = '';

        if(type == 'err')
        {
            alert_msg += '<div class="alert alert-danger" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'warn')
        {
            alert_msg += '<div class="alert alert-warning" role="alert">';
            alert_msg += '<span ><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'succ')
        {
            alert_msg += '<div class="alert alert-success" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }

        $(".alert_msg_n").html(alert_msg);


        setTimeout(function(){
            $(".alert_msg_n").html("");       
        },5000);
    }

    function display_alert_comment(type,message)
    {
        var alert_msg = '';

        if(type == 'err')
        {
            alert_msg += '<div class="alert alert-danger" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'warn')
        {
            alert_msg += '<div class="alert alert-warning" role="alert">';
            alert_msg += '<span ><strong>'+message+'</strong></span></div>';
        }
        else if(type == 'succ')
        {
            alert_msg += '<div class="alert alert-success" role="alert">';
            alert_msg += '<span><strong>'+message+'</strong></span></div>';
        }

        $(".alert_msg_c").html(alert_msg);


        setTimeout(function(){
            $(".alert_msg_c").html("");       
        },5000);
    }

/********************************* Common Function *********************************/

    function delete_item(id, path)
    {
        var ans = confirm("Are you sure? You want to delete item.");

        if(ans == true)
        {
            var update_path = base_url+"admin/cmaster/"+path+"/"+id;
            
            $("#loading").show();  
            $.ajax({
                type:'POST',
                url:update_path,
                success:function(resp)
                {
                    if(resp == 2){

                        alert("You can not delete this item!");
                    }
                    else{

                        window.location.reload();
                    }

                    $("#loading").hide();
                },
                error:function(resp)
                {
                    console.log(resp);
                }
            });
        }
    } 

    function get_preview(input) 
    {
        if (input.files && input.files[0]) 
        {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#test_img').attr('src', e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }  

/********************************* User Master *********************************/

    function add_update_user_popup(user_id){

        var path = base_url+"admin/cmaster/get_role";
                    
        $("#loading").show();
        $.ajax({
            type:'POST',
            url:path,
            dataType:'json',
            success:function(resp)
            {
                var data = '';
                              
                data += '<div class="alert_msg"></div>';                      
                data += '<div class="row">';
                data += '<div class="col-md-12">'
                data += '<form class="form-horizontal" id="user_form">';
                
                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">User Name<span style="color:red">*</span></label><div class="col-sm-9"><input type="text" name="user_name" class="form-control" id="user_name"></div></div>';

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Full Name<span style="color:red">*</span></label><div class="col-sm-9"><input type="text" name="user_full_name" class="form-control" id="user_full_name"></div></div>';

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Password<span style="color:red">*</span></label><div class="col-sm-9"><input type="password" name="user_password" class="form-control" id="user_password"></div></div>';

                if(session_role == 1)
                {
                    data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Role<span style="color:red">*</span></label><div class="col-sm-9">';
                    data += '<select name="user_role_id" id="user_role_id" class="form-control">';

                $.each(resp['role'], function(index, value){

                    data += '<option value="'+index+'">'+value+'</option>';

                });

                    data += '</select>';

                    data += '</div></div>';
                }

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Address</label><div class="col-sm-9"><textarea name="user_address" class="form-control" id="user_address"></textarea></div></div>';

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Telephone</label><div class="col-sm-9"><input type="text" name="user_telephone" class="form-control" id="user_telephone"></div></div>';

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Mobile</label><div class="col-sm-9"><input type="text" name="user_mobile" class="form-control" id="user_mobile"></div></div>';

                data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Email</label><div class="col-sm-9"><input type="email" name="user_email" class="form-control" id="user_email"></div></div>';

                data += '</form>';
                data += '</div>';
                data += '</div>';

                $(".modal-body-sm").html(data);

                var sbt_btn = '<button type="button" class="btn btn-default" onClick="reload_page();" data-dismiss="modal">Close</button>';  
                
                if(user_id == 0){

                    sbt_btn += '<button type="button" class="btn btn-success" onClick="add_user(0)">Submit</button>';

                    $(".modal-title-sm").html("Add User");
                }
                else
                {

                    var update_path = base_url+"admin/cmaster/get_single_user/"+user_id;
                    
                    $("#loading").show();
                    $.ajax({
                        type:'POST',
                        url:update_path,
                        dataType:'json',
                        success:function(resp)
                        {
                            console.log(resp);
                            $("#user_name").val(resp[0]['user_name']);
                            $("#user_full_name").val(resp[0]['user_full_name']);
                            if(session_role == 1)
                            {
                                $("#user_role_id").val(resp[0]['user_role_id']);
                            }
                            $("#user_address").html(resp[0]['user_address']);
                            $("#user_mobile").val(resp[0]['user_mobile']);
                            $("#user_telephone").val(resp[0]['user_telephone']);
                            $("#user_email").val(resp[0]['user_email']);

                            $("#loading").hide();
                        },
                        error:function(resp)
                        {
                            console.log(resp);
                        }
                    });

                    sbt_btn += '<button type="button" class="btn btn-success" onClick="add_user('+user_id+')">Submit</button>';

                    $(".modal-title-sm").html("Update User");
                }

                $(".modal-footer-sm").html(sbt_btn);

                $("#loading").hide();
                $("#popup_modal_sm").modal('show'); 
            },
            error:function(resp)
            {
                console.log(resp);
            }
        });
    }

    function add_user(id){

        var check = 1;

        if($("#user_name").val() == '')
        {
            $("#user_name").css({
                'border-color':'red'
            });
            check = 0;
        }
        else
        {
            $("#user_name").css({
                'border-color':'#CCC'
            });
        }

        if(id == 0)
        {
            if($("#user_password").val() == 0)
            {
                $("#user_password").css({
                    'border-color':'red'
                });
                check = 0;
            }
            else
            {
                $("#user_password").css({
                    'border-color':'#CCC'
                });
            }
        }

        if($("#user_full_name").val() == '')
        {
            $("#user_full_name").css({
                'border-color':'red'
            });
            check = 0;
        }
        else
        {
            $("#user_full_name").css({
                'border-color':'#CCC'
            });
        }

        if(check == 0)
        {
            var msg = 'Oh snap ! You forgot to enter some information';
            display_alert('err',msg);

            $("body, html").animate({
                'scrollTop':0
            },1000);
        }
        else
        {     
            
            var path = base_url+"admin/cmaster/user_insert/"+id;   
            var form_data = $("#user_form").serialize();

            $("#loading").show();
            $.ajax({
                type:'POST',
                url:path,
                data:form_data,
                success:function(resp)
                {
                    if(resp == 1)
                    {
                        if(id == 0)
                        {
                            var msg = 'Successfully added!';
                            display_alert('succ',msg);

                            $("#user_form")[0].reset();

                            $("body, html").animate({
                                'scrollTop':0
                            },1000);

                        }
                        else
                        {
                            var msg = 'Successfully updated!';
                            display_alert('succ',msg);  

                            $("body, html").animate({
                                'scrollTop':0
                            },1000);
                        }
                    }
                    else if(resp == 2)
                    {
                        var msg = 'User is already exists!';
                        display_alert('err',msg);

                        $("body, html").animate({
                            'scrollTop':0
                        },1000);
                    }
                    else
                    {
                        var msg = 'Database Error ! Please try again later';
                        display_alert('warn',msg);

                        $("body, html").animate({
                            'scrollTop':0
                        },1000);
                    }
                    $("#loading").hide();
                },
                error:function(resp){
                    console.log(resp);
                }   
            });
        }
    }

/********************************* Category Master ******************************/

    function add_update_category_popup(cat_id)
    {

        var data = '';                      
        data += '<div class="alert_msg"></div>';                      
        data += '<div class="row">';
        data += '<div class="col-md-12">'
        data += '<form class="form-horizontal" id="category_form">';
        
        data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Category Name</label><div class="col-sm-9"><input type="text" name="cat_name" class="form-control" id="cat_name"></div></div>';
        data += '</form>';
        data += '</div>';
        data += '</div>';

        $(".modal-body-sm").html(data);

        var sbt_btn = '<button type="button" class="btn btn-default" onClick="reload_page();" data-dismiss="modal">Close</button>';  
        
        if(cat_id == 0)
        {

            sbt_btn += '<button type="button" class="btn btn-success" onClick="add_category(0)">Submit</button>';

            $(".modal-title-sm").html("Add Category");
        }
        else
        {

            var update_path = base_url+"admin/cmaster/get_single_category/"+cat_id;
            
            $.ajax({
                type:'POST',
                url:update_path,
                dataType:'json',
                success:function(resp)
                {
                    $("#cat_name").val(resp[0]['cat_name']);
                },
                error:function(resp)
                {
                    console.log(resp);
                }
            });

            sbt_btn += '<button type="button" class="btn btn-success" onClick="add_category('+cat_id+')">Submit</button>';

            $(".modal-title-sm").html("Update Category");
        }

        $(".modal-footer-sm").html(sbt_btn);

        $("#loading").hide();
        $("#popup_modal_sm").modal('show'); /*use to show model box*/ 
    }

    function add_category(id)
    {
        var check = 1;

        if($("#cat_name").val() == '')
        {
            $("#cat_name").css({
                'border-color':'red'
            });
            check = 0;
        }
        else
        {
            $("#cat_name").css({
                'border-color':'#CCC'
            });
        }

        if(check == 0)
        {
            var msg = 'Oh snap ! You forgot to enter some information';
            display_alert('err',msg);

            $("body, html").animate({
                'scrollTop':0
            },1000);
        }
        else
        {     
            
            var path = base_url+"admin/cmaster/category_insert/"+id;
            var form_id = document.getElementById("category_form");    
            var form_data = new FormData(form_id);

            $("#loading").show(); 
            
            $.ajax({
                type:'POST',
                url:path,
                data:form_data,
                contentType:false,
                processData:false,
                success:function(resp)
                {
                    // alert(resp);
                    // console.log(resp);

                    if(resp == 1)
                    {
                        if(id == 0)
                        {
                            var msg = 'Successfully added!';
                            display_alert('succ',msg);

                            $("#category_form")[0].reset();

                            $("#popup_modal_sm").animate({
                                'scrollTop':0
                            },1000);

                        }
                        else
                        {
                            var msg = 'Successfully updated!';
                            display_alert('succ',msg);  

                            $("#popup_modal_sm").animate({
                                'scrollTop':0
                            },1000);
                        }
                    }
                    else if(resp == 2)
                    {
                        var msg = 'Category already exists!';
                        display_alert('err',msg);

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                    else
                    {
                        var msg = 'Unknown Error ! Please try again letter';
                        display_alert('warn',msg);

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                    $("#loading").hide();
                },
                error:function(resp){
                    console.log(resp);
                }   
            });
        }
    }

    function remove_pic(pic_name,pic_cnt)
    {
        var id = parseFloat($("#pm_id").val());
        var ans = confirm("Are you sure you want to Remove this Picture Permenetly?")
        if(ans == true)
        {
           var path = base_url+"admin/cmaster/remove_picture_permenently/"+pic_name+"/"+id; 
           $("#loading").show();
            $.ajax({
                type:'POST',
                url:path,
                dataType:'json',
                success:function(resp)
                {  
                    $("#pic_"+pic_cnt).detach();
                },
                error:function(resp)
                {
                    console.log(resp);
                }
            });
        }
    }
/********************************* Product Master ******************************/

    function add_update_product_popup(pro_id)
    {
        var path = base_url+"admin/cmaster/get_all_cat_height_data_for_product";
            
        $.ajax({
            type:'POST',
            url:path,
            dataType:'json',
            success:function(resp)
            {
                // alert(resp);
                // console.log(resp);
                var data = '';                      
                
                data += '<div class="alert_msg"></div>';                      
                data += '<div class="row">';
                data += '<div class="col-md-12">'
                data += '<form class="form-horizontal" id="product_form" enctype="multipart/form_data">';

                data += '<div class="form-group">';
                data += '<label for="inputEmail3" class="col-sm-3 control-label">Product Name</label>';
                data += '<div class="col-sm-9">';
                data += '<input type="text" name="pro_name" class="form-control" id="pro_name">';
                data += '</div>';
                data += '</div>';
                
                data += '<div class="form-group">';
                data += '<label for="inputEmail3" class="col-sm-3 control-label">Category</label>';
                data += '<div class="col-sm-9">';
                data += '<select name="pro_cat_id" class="form-control" id="pro_cat_id">';
                data += '<option value="">Please Select</option>';
                $.each(resp['category_data'],function(index,value){
                    data += '<option value="'+value['cat_id']+'">'+value['cat_name']+'</option>';
                });
                data += '</select>';
                data += '</div>';
                data += '</div>';
                
                data += '<div class="form-group">';
                data += '<label for="inputEmail3" class="col-sm-3 control-label">Height</label>';
                data += '<div class="col-sm-9">';
                data += '<select name="pro_height_id" class="form-control" id="pro_height_id">';
                data += '<option value="">Please Select</option>';
                $.each(resp['height_data'],function(index,value){
                    data += '<option value="'+value['ht_id']+'">'+value['ht_name']+'</option>';
                });
                data += '</select>';
                data += '</div>';
                data += '</div>';
                
                data += '<div class="form-group">';
                data += '<label for="inputEmail3" class="col-sm-3 control-label">Upload</label>';
                data += '<div class="col-sm-9">';
                data += '<input type="file" name="pro_file" class="form-control" id="pro_file">';
                data += '</div>';

                data += '<div class="form-group">';
                data += '<label for="inputEmail3" class="col-sm-3 control-label"></label>';
                data += '<div class="col-sm-9">';
                data += '<div id="upload_file_id">';
                data += '</div>';
                data += '</div>';      
                
                data += '</form>';
                data += '</div>';
                data += '</div>';

                $(".modal-body-sm").html(data);

                var sbt_btn = '<button type="button" class="btn btn-default" onClick="reload_page();" data-dismiss="modal">Close</button>';  
                
                if(pro_id == 0)
                {

                    sbt_btn += '<button type="button" class="btn btn-success" onClick="add_product(0)">Submit</button>';

                    $(".modal-title-sm").html("Add Product");
                }
                else
                {

                    var update_path = base_url+"admin/cmaster/get_single_product/"+pro_id;
                    
                    $.ajax({
                        type:'POST',
                        url:update_path,
                        dataType:'json',
                        success:function(resp)
                        {
                            // alert(resp);
                            $("#pro_name").val(resp[0]['pro_name']);
                            $("#pro_cat_id").val(resp[0]['pro_cat_id']);
                            $("#pro_height_id").val(resp[0]['pro_height_id']);
                            // $("#pro_height_id").val(resp[0]['pro_height_id']);
                            if(resp[0]['pro_file_name'] != '') 
                            {
                                var data1 = "";
                                data1 += '<a href= "'+base_url+'/public/uploads/file/'+resp[0]['pro_file_name']+'" target="_blank">view</a>';


                                $("#upload_file_id").append(data1);
                            }
                            


                        },
                        error:function(resp)
                        {
                            console.log(resp);
                        }
                    });

                    sbt_btn += '<button type="button" class="btn btn-success" onClick="add_product('+pro_id+')">Submit</button>';

                    $(".modal-title-sm").html("Update Product");
                }

                $(".modal-footer-sm").html(sbt_btn);

                $("#loading").hide();
                $("#popup_modal_sm").modal('show'); /*use to show model box*/ 
            },
            error:function(resp)
            {
                console.log(resp);
            }
        });
    }

    // function add_product(id)
    // {
    //     var check = 1;

    //     if($("#pro_name").val() == '')
    //     {
    //         $("#pro_name").css({
    //             'border-color':'red'
    //         });
    //         check = 0;
    //     }
    //     else
    //     {
    //         $("#pro_name").css({
    //             'border-color':'#CCC'
    //         });
    //     }

    //     if(check == 0)
    //     {
    //         var msg = 'Oh snap ! You forgot to enter some information';
    //         display_alert('err',msg);

    //         $("body, html").animate({
    //             'scrollTop':0
    //         },1000);
    //     }
    //     else
    //     {     
            
    //         var path = base_url+"admin/cmaster/product_insert/"+id;   
    //         var form_id = document.getElementById("product_form");
    //         var form_data = new FormData(form_id);

    //         $("#loading").show(); 
            
    //         $.ajax({
    //             type:'POST',
    //             url:path,
    //             data:form_data,
    //             contentType:false,
    //             processData:false,
    //             success:function(resp)
    //             {
    //                 alert(resp);
    //                 // console.log(resp);

    //                 if(resp == 1)
    //                 {
    //                     if(id == 0)
    //                     {
    //                         var msg = 'Successfully added!';
    //                         display_alert('succ',msg);

    //                         $("#product_form")[0].reset();

    //                         $("#product_form").animate({
    //                             'scrollTop':0
    //                         },1000);

    //                     }
    //                     else
    //                     {
    //                         var msg = 'Successfully updated!';
    //                         display_alert('succ',msg);  

    //                         $("#popup_modal_sm").animate({
    //                             'scrollTop':0
    //                         },1000);
    //                     }
    //                 }
    //                 else if(resp == 2)
    //                 {
    //                     var msg = 'Product already exists!';
    //                     display_alert('err',msg);

    //                     $("#popup_modal_sm").animate({
    //                         'scrollTop':0
    //                     },1000);
    //                 }
    //                 else
    //                 {
    //                     var msg = 'Unknown Error ! Please try again letter';
    //                     display_alert('warn',msg);

    //                     $("#popup_modal_sm").animate({
    //                         'scrollTop':0
    //                     },1000);
    //                 }
    //                 $("#loading").hide();
    //             },
    //             error:function(resp){
    //                 console.log(resp);
    //             }   
    //         });
    //     }
    // }



/********************************* Height Master ******************************/

    function add_update_height_popup(ht_id)
    {

        var data = '';                      
        data += '<div class="alert_msg"></div>';                      
        data += '<div class="row">';
        data += '<div class="col-md-12">'
        data += '<form class="form-horizontal" id="height_form">';
        
        data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Height Name</label><div class="col-sm-9"><input type="text" name="ht_name" class="form-control" id="ht_name"></div></div>';
        data += '<div class="form-group"><label for="inputEmail3" class="col-sm-3 control-label">Height Status</label><div class="col-sm-9"><select name="ht_status" class="form-control" id="ht_status"><option value="ACTIVE">ACTIVE</option><option value="INACTIVE">INACTIVE</option></select></div></div>';    
        data += '</form>';
        data += '</div>';
        data += '</div>';

        $(".modal-body-sm").html(data);

        var sbt_btn = '<button type="button" class="btn btn-default" onClick="reload_page();" data-dismiss="modal">Close</button>';  
        
        if(ht_id == 0)
        {

            sbt_btn += '<button type="button" class="btn btn-success" onClick="add_height(0)">Submit</button>';

            $(".modal-title-sm").html("Add Height");
        }
        else
        {

            var update_path = base_url+"admin/cmaster/get_single_height/"+ht_id;
            
            $.ajax({
                type:'POST',
                url:update_path,
                dataType:'json',
                success:function(resp)
                {
                    $("#ht_name").val(resp[0]['ht_name']);
                },
                error:function(resp)
                {
                    console.log(resp);
                }
            });

            sbt_btn += '<button type="button" class="btn btn-success" onClick="add_height('+ht_id+')">Submit</button>';

            $(".modal-title-sm").html("Update Height");
        }

        $(".modal-footer-sm").html(sbt_btn);

        $("#loading").hide();
        $("#popup_modal_sm").modal('show'); /*use to show model box*/ 
    }

    function add_height(id)
    {
        var check = 1;

        if($("#ht_name").val() == '')
        {
            $("#ht_name").css({
                'border-color':'red'
            });
            check = 0;
        }
        else
        {
            $("#ht_name").css({
                'border-color':'#CCC'
            });
        }

        if(check == 0)
        {
            var msg = 'Oh snap ! You forgot to enter some information';
            display_alert('err',msg);

            $("body, html").animate({
                'scrollTop':0
            },1000);
        }
        else
        {     
            
            var path = base_url+"admin/cmaster/height_insert/"+id;   
            var form_data = $("#height_form").serialize();

            $("#loading").show(); 
            
            $.ajax({
                type:'POST',
                url:path,
                data:form_data,
                success:function(resp)
                {
                    // alert(resp);
                    // console.log(resp);

                    if(resp == 1)
                    {
                        if(id == 0)
                        {
                            var msg = 'Successfully added!';
                            display_alert('succ',msg);

                            $("#height_form")[0].reset();

                            $("#popup_modal_sm").animate({
                                'scrollTop':0
                            },1000);

                        }
                        else
                        {
                            var msg = 'Successfully updated!';
                            display_alert('succ',msg);  

                            $("#popup_modal_sm").animate({
                                'scrollTop':0
                            },1000);
                        }
                    }
                    else if(resp == 2)
                    {
                        var msg = 'Height already exists!';
                        display_alert('err',msg);

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                    else
                    {
                        var msg = 'Unknown Error ! Please try again letter';
                        display_alert('warn',msg);

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                    $("#loading").hide();
                },
                error:function(resp){
                    console.log(resp);
                }   
            });
        }
    }

function add_slider(id)
{
    var check = 1;

    if($("#sm_name").val() == '')
    {
        $("#sm_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#sm_name").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        
        var path = base_url+"admin/cmaster/slider_insert/"+id;
        var form_id = document.getElementById("slider_form");    
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#slider_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'Slider already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_course(id)
{
    var check = 1;

    if($("#cm_name").val() == '')
    {
        $("#cm_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#cm_name").css({
            'border-color':'#CCC'
        });
    }
    if($("#cm_status").val() == '')
    {
       $("#cm_status").css({
            'border-color':'red'
        });
        check = 0; 
    }
    else
    {
        $("#cm_status").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        
        var path = base_url+"admin/cmaster/course_insert/"+id;   
        var form_data = $("#course_form").serialize();

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            success:function(resp)
            {
                console.log(resp);

                if(resp == 1)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#course_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'Course already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_about_us(id)
{
    var check = 1;

    if($("#am_name").val() == '')
    {
        $("#am_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#am_name").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        
        var path = base_url+"admin/cmaster/about_insert/"+id;
        var form_id = document.getElementById("about_form");    
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#about_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'product already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}



function add_product(id)
{
    var check = 1;

    if($('#pm_name').val() == "")
    {
        $('#pm_name').css({'border-color' :'red'});
        check = 0;
    }
    else
    {
        $('#pm_name').css({'border-color' :'#ccc'});
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        
        var path = base_url+"admin/cmaster/product_insert/"+id;
        var form_id = document.getElementById("product_form");    
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#product_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'product already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_event(id)
{
    var check = 1;

    if($("#em_name").val() == '')
    {
        $("#em_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#em_name").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {   

        var path = base_url+"admin/cmaster/event_insert/"+id;
        var form_id = document.getElementById("event_form");    
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#event_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'event already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_comment(id)
{
    var check = 1;

    if($("#cm_name").val() == '')
    {
        $("#cm_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#cm_name").css({
            'border-color':'#CCC'
        });
    }
     var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if(reg.test($("#cm_email").val()) == false) 
    {
        alert('Invalid Email Address');
        return false;
        $("#cm_email").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#cm_email").css({
            'border-color':'#CCC'
        });
    }



    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        // console.log(base_url);
        
        var path = base_url+"admin/cmaster/comment_insert/"+id;
        var form_id = document.getElementById("comment_form");
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Thank You for Your Comment. Your Comments will help us to improve our quality service.';
                        display_alert_comment('succ',msg);

                        $("#comment_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'event already exists!';
                    display_alert_comment('err',msg);

                    $("html , body").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert_comment('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_feeds(id)
{
    var check = 1;

    if($("#fm_name").val() == '')
    {
        $("#fm_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#fm_name").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        var path = base_url+"admin/cmaster/feeds_insert/"+id;
        var form_id = document.getElementById("feeds_form");
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#feeds_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'Feed already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_dealers(id)
{
    var check = 1;

    if($("#dm_name").val() == '')
    {
        $("#dm_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#dm_name").css({
            'border-color':'#CCC'
        });
    }
     var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if(reg.test($("#dm_email").val()) == false) 
    {
        alert('Invalid Email Address');
        return false;
        $("#dm_email").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#dm_email").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        // console.log(base_url);
        
        var path = base_url+"admin/cmaster/dealer_insert/"+id;
        var form_id = document.getElementById("dealer_form");
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Thank You for your Registration.Our Backend Team will responed you shortly.';
                        display_alert_dealer('succ',msg);

                        $("#dealer_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'Dealer already exists!';
                    display_alert_dealer('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert_dealer('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function add_newsletter(id)
{
    var check = 1;
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if(reg.test($("#nm_email").val()) == false) 
    {
        alert('Invalid Email Address');
        return false;
        $("#nm_email").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#nm_email").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {     
        var path = base_url+"admin/cmaster/newsletter_insert/"+id;
        var form_id = document.getElementById("newsletter_form");
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Thank You for newsletter subscription.You will soon received products update.';
                        display_alert_newsletter('succ',msg);

                        $("#newsletter_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'E-mail already exists!';
                    display_alert_newsletter('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert_newsletter('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

// function add_to_inquiry() 
// {
//     if ('localStorage' in window && window['localStorage'] !== null) {
//         try {
//             //Get stored data
//             var users = JSON.parse(localStorage.getItem('users1'));

//             if (users === null) {
//                 //If no stored data, create empty array
//                 users = [];
//             }

//             //Create new user entry
//             user = {
//                 p_id: $("#pm_id").val(),
//                 product: $("#pm_name").val(),
//                 rate: $("#pm_rate").val(),
//                 qty: $("#qty").val(),
//                 photo: $("#pm_file_name").val(),

//             };

//             //Add new entry to stored array
//             users.push(user);

//             //Save array
//             localStorage.setItem("users1", JSON.stringify(users));

//             alert("Added To Inquiry.");
//             display_inquiry();
           

//         } catch (e) {
//             if (e == QUOTA_EXCEEDED_ERR) {
//                 alert('Quota exceeded!');
//             }
//         }
//     } else {
//         alert('Cannot store user preferences as your browser do not support local storage');
//     }
// }

// function add_to_inquiry_multiple(cnt) 
// {
//     if ('localStorage' in window && window['localStorage'] !== null) {
//         try {
//             //Get stored data
//             var users = JSON.parse(localStorage.getItem('users1'));

//             if (users === null) {
//                 //If no stored data, create empty array
//                 users = [];
//             }

//             //Create new user entry
//             user = {
//                 p_id: $("#pm_id_"+cnt).val(),
//                 product: $("#pm_name_"+cnt).val(),
//                 rate: $("#pm_rate_"+cnt).val(),
//                 qty: $("#qty_"+cnt).val(),
//                 photo: $("#pm_file_name_"+cnt).val(),

//             };

//             //Add new entry to stored array
//             users.push(user);

//             //Save array
//             localStorage.setItem("users1", JSON.stringify(users));

//             alert("Added To Inquiry.");
//             display_inquiry();
           

//         } catch (e) {
//             if (e == QUOTA_EXCEEDED_ERR) {
//                 alert('Quota exceeded!');
//             }
//         }
//     } else {
//         alert('Cannot store user preferences as your browser do not support local storage');
//     }
// }

// function display_inquiry()
// {
//     items = JSON.parse(localStorage.getItem('users1'));
    
//     var data = '';
//     var cnt = 1;
//     var cnt_len = items.length;
//     $("#cartt").text(cnt_len);

//     for (var i = 0; i < items.length; i++) {

//         var srcc = base_url+"public/uploads/file/product/"+items[i].photo;

//         var qty = items[i].qty;
//         var rate = items[i].rate;

//         var total = parseFloat(qty) *  parseFloat(rate);

//         var pro = parseFloat($("#m_total").val());

//         // console.log(pro);
//         pro_total = parseInt(pro) + parseInt(total); 

//         data += '<li class="item odd" id="rowid_'+cnt+'">'; 
//         data += '<a href="shopping_cart.html" title="'+items[i].product+'" class="product-image">';
//         data += '<img src="'+srcc+'" alt="html Template" width="65">';
//         data += '</a>';
//         data += '<div class="product-details">'; 
//         data += '<a onClick="remove_inq_item('+cnt+')" title="Remove This Item" class="remove-cart"><i class="pe-7s-trash"></i>';
//         data += '</a>';
//         data += '<p class="product-name">';
//         data += '<a href="shopping_cart.html">'+items[i].product+'</a>'; 
//         data += '</p>';
//         data += '<strong>'+items[i].qty+'</strong> x <span class="price">US$ '+items[i].rate+'</span>'; 
//         data += '</div>';
//         data += '</li>';
//     cnt++;

//     $("#sub_total").text('US$ '+pro_total);
//     $("#m_total").val(pro_total);
    

//     }

//     var demo = document.getElementById("cart-sidebar"); 
//     demo.innerHTML = data ; 

// }

// function remove_inq_item(cnt)
// {
//     $("#rowid_"+cnt).detach();
// }

// function shopping_cart()
// {
//     items = JSON.parse(localStorage.getItem('users1'));
    
//     var data = "";
//     var cnt = 1;

//     // alert(items.length);


//     for (var i = 0; i < items.length; i++) {

//         var srcc = base_url+"public/uploads/file/product/"+items[i].photo;

//         var qty = items[i].qty;
//         var rate = items[i].rate;



//         var total = parseFloat(qty) *  parseFloat(rate);
//         // console.log(total);
        

//         var pro = parseFloat($("#om_total").val());

//         // console.log(pro);
//         pro_total = parseInt(pro) + parseInt(total); 



//         data += '<tr id="rowid_'+cnt+'">';

//         data += '<td class="cart_product">';
//         data += '<input type="hidden" name="ot_photo[]" class="form-control" value="'+items[i].photo+'" readonly/>';
//         data += '<input type="hidden" name="ot_id[]" class="form-control" value="0" readonly/>';
//         data += '<img src="'+srcc+'">';
//         data += '</td>';
        
//         data += '<td>';
//         data += '<input type="hidden" name="ot_pm_id[]" class="form-control" value="'+items[i].p_id+'" readonly/>';
//         data += '<input type="text" class="form-control" style="border:none;background:#fff;" value="'+items[i].product+'" readonly/>';
//         data += '</td>';

//         data += '<td>';
//         data += '<input type="text" class="form-control" style="border:none;background:#fff;" name="ot_qty[]" value="'+items[i].qty+'" readonly/>';
//         data += '</td>';

//         data += '<td>';
//         data += '<input type="text" class="form-control" style="border:none;background:#fff;" name="ot_total[]" value="'+total+'" readonly/>';
//         data += '</td>';
        
//         data += '<td class="action"><a onClick="remove_viewcart_item('+cnt+')"><i class="icon-close"></i></a></td>';
//         data += '</tr>';
//     cnt++;

//         $("#om_total").val(pro_total)


//     }

//     var demo = document.getElementById("cart"); 
//     demo.innerHTML = data ; 

//     // $("#cart-sidebar").append(data);


// }

function remove_viewcart_item(cnt)
{
    $("#rowid_"+cnt).detach();
}

function order_entry(id)
{
    var check = 1; 
    if($("#om_first_name").val() == '')
    {
        $("#om_first_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#om_first_name").css({
            'border-color':'#CCC'
        });
    }
    if($("#om_last_name").val() == '')
    {
        $("#om_last_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#om_last_name").css({
            'border-color':'#CCC'
        });
    }
    if($("#om_city").val() == '')
    {
        $("#om_city").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#om_city").css({
            'border-color':'#CCC'
        });
    }
    if($("#om_country").val() == 0)
    {
        $("#om_country").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#om_country").css({
            'border-color':'#CCC'
        });
    }

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if(reg.test($("#om_email").val()) == false) 
    {
        alert('Invalid Email Address');
        return false;
        $("#om_email").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#om_email").css({
            'border-color':'#CCC'
        });
    }


    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {
        var form_data = $("#order_form").serialize();  
        var path = base_url+"admin/cmaster/order_insert/"+id;
        $.ajax({
            type:"post",
            url:path,
            data:form_data,
            dataType : 'JSON',
            success:function(resp)
            {
               console.log(resp);

                if(resp['flag'] == 1)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#order_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                        localStorage.clear();
                        setInterval(function(){window.location.reload(); },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'E-mail already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
            },
            error:function(resp){
                console.log(resp);
            }
        });
    }
} 

 function add_order_follow_data(dash_cnt,om_id)
{
   
   var check = 1;
    
    if(check == 1)
    {
        var path = base_url+"admin/cmaster/insert_data_order_follow_up/"+om_id;
        var form_data = $("#order_follow_form_"+dash_cnt).serialize();
        $.ajax({
            type :'POST',
            url : path,
            data : form_data,
            success: function(resp)
            {
                console.log(resp);
                window.location.reload();
            },
            error:function(err)
            {
                console.log(err);

            }
        });
    }
}


function validateEmail(email) {
    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(String(email).toLowerCase());
}

function send_contact_form_email()
{
    var email_validate = [];
    var check = 1;

    if($("#om_email").val() == '')
    {
        $("#om_email").css({'border-color':'red'});
        check = 0;
    }
    else
    {
        var om_email = $("#om_email").val();
        om_email = om_email.split(/[\s,]+/); // split with comma and dot
        
        $.each(om_email, function(index, value)
        {
            value = value.trim();
            test = validateEmail(value); 
    
            if(test == true)
            {
                email_validate[index] = 1;
            }
            else
            {
                email_validate[index] = 0;
            }
        });
        $("#om_email").css({'border-color':'#CCC'});
    }

    if(check == 0)
    {
        var msg = 'Please enter receiver name & email address.';
        display_alert('err',msg);

        $("#popup_modal_sm").animate({'scrollTop':0},1000);
    }
    else if($.inArray(0,email_validate) != -1)
    {
        var msg = 'Please check enter email id';
        display_alert('err',msg);
        $("#om_email").css({'border-color':'red'});

        $("#popup_modal_sm").animate({'scrollTop':0},1000);
    }
    else
    {
        var path = base_url+"common/send_contact_email";
        var form_data = $("#contact_form").serialize();
                
        $("#loading").show();  
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            success:function(resp)
            {
                $("#loading").hide();
                console.log(resp);
                if(resp == 1)
                {
                    var msg = 'Email Successfully Sent.';
                    display_alert('succ',msg);

                }
                else
                {
                    var msg = 'Unknown error! Please try again later.';
                    display_alert('warn',msg);

                }
            },
            error:function(resp)
            {
                console.log(resp);
            }
        });
    }
}

function add_announcement(id)
{
    var check = 1;

    if($("#am_name").val() == '')
    {
        $("#am_name").css({
            'border-color':'red'
        });
        check = 0;
    }
    else
    {
        $("#am_name").css({
            'border-color':'#CCC'
        });
    }

    if(check == 0)
    {
        var msg = 'Oh snap ! You forgot to enter some information';
        display_alert('err',msg);

        $("body, html").animate({
            'scrollTop':0
        },1000);
    }
    else
    {   

        var path = base_url+"admin/cmaster/announcement_insert/"+id;
        var form_id = document.getElementById("ann_form");    
        var form_data = new FormData(form_id);

        $("#loading").show(); 
        
        $.ajax({
            type:'POST',
            url:path,
            data:form_data,
            contentType:false,
            processData:false,
            success:function(resp)
            {
                console.log(resp);

                if(resp > 0)
                {
                    if(id == 0)
                    {
                        var msg = 'Successfully added!';
                        display_alert('succ',msg);

                        $("#ann_form")[0].reset();

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);

                    }
                    else
                    {
                        var msg = 'Successfully updated!';
                        display_alert('succ',msg);  

                        $("#popup_modal_sm").animate({
                            'scrollTop':0
                        },1000);
                    }
                }
                else if(resp == 2)
                {
                    var msg = 'event already exists!';
                    display_alert('err',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                else
                {
                    var msg = 'Unknown Error ! Please try again letter';
                    display_alert('warn',msg);

                    $("#popup_modal_sm").animate({
                        'scrollTop':0
                    },1000);
                }
                $("#loading").hide();
            },
            error:function(resp){
                console.log(resp);
            }   
        });
    }
}

function remove_pic(pic_name,pic_cnt)
{
    var id = parseFloat($("#em_id").val());
    var ans = confirm("Are you sure you want to Remove this Picture Permenetly?")
    if(ans == true)
    {
       var path = base_url+"admin/cmaster/remove_picture_permenently/"+pic_name+"/"+id; 
       $("#loading").show();
        $.ajax({
            type:'POST',
            url:path,
            dataType:'json',
            success:function(resp)
            {  
                $("#pic_"+pic_cnt).detach();
                $("#loading").hide();

            },
            error:function(resp)
            {
                console.log(resp);
            }
        });
    }
}

/**********************************Add Follow Up data Start***********************************/
function add_follow_up_data(dash_cnt,am_id)
{
   
   var check = 1;
    if($("#am_follow_comment_"+dash_cnt).val().length < 2)
    {
        $("#am_follow_comment_"+dash_cnt).css({'border-color': 'red'});
        check = 0;
    }
    else
    {
        $("#am_follow_comment_"+dash_cnt).css({'border-color': '#ccc'});

    }
    
    if(check == 1)
    {
        var path = base_url+"admin/cmaster/insert_data_follow_up/"+am_id;
        var form_data = $("#admission_form_"+dash_cnt).serialize();
        $.ajax({
            type :'POST',
            url : path,
            data : form_data,
            success: function(resp)
            {
                console.log(resp);
                if(resp == 1)
                {
                    alert("Successfully added!");
                    setInterval(function(){window.location.reload(); },1000);
                }
                // window.location.reload();

            },
            error:function(err)
            {
                console.log(err);

            }
        });
    }
}