function dashboard_view(){
	loading("main_section")
	$("#main_section").load("includes_/dashboard.php")
	active_("sidebar_menu_","sidebar_menu_dashboard")
}
function users_view(){
	loading("main_section")
	$("#main_section").load("includes_/users.php")
	active_("sidebar_menu_","sidebar_menu_users")
}
function products_view(){
	loading("main_section")
	$("#main_section").load("includes_/products.php",{
    view_type:"all"
  })
	active_("sidebar_menu_","sidebar_menu_products")
}
function products_viewII(){
  var selected_view_type=$('#products_view_type option:selected').val()
  loading("main_section")
  $("#main_section").load("includes_/products.php",{
    view_type:selected_view_type
  })
  active_("sidebar_menu_","sidebar_menu_products")
}

function products_trash_viewII(){
  var selected_view_type=$('#products_view_type option:selected').val()
  loading("main_section")
  $("#main_section").load("includes_/products/products_trash.php",{
    view_type:selected_view_type
  })
  active_("sidebar_menu_","sidebar_menu_products")
}

function miscellaneous_goods_view(){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods.php")
	active_("sidebar_menu_","sidebar_menu_miscellaneous_goods")
}
function blog_view(){
	loading("main_section")
	$("#main_section").load("includes_/blog.php",{
    view_type:"all"
  })
	active_("sidebar_menu_","sidebar_menu_blog")
}
function blog_viewII(){
  var selected_view_type=$('#blogs_view_type option:selected').val()
  loading("main_section")
  $("#main_section").load("includes_/blog.php",{
    view_type:selected_view_type
  })
  active_("sidebar_menu_","sidebar_menu_blog")
}

function blog_categories_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/blog_categories.php")
}

function profile_view(){
	loading("main_section")
	$("#main_section").load("includes_/profile.php")
}
function profile_readonly_mode_view(){
	loading("profile_mode_view_id")
	$("#profile_mode_view_id").load("includes_/profile/profile_readonly_mode.php")
}
function profile_edit_mode_view(){
	loading("profile_mode_view_id")
	$("#profile_mode_view_id").load("includes_/profile/profile_edit_mode.php")
}

function notifications_view(){
	loading("main_section")
	$("#main_section").load("includes_/notifications.php")

}

function contact_us_view(){
  loading("main_section")
  $("#main_section").load("includes_/contact_us.php")
}

function contact_us_trash_view(){
  loading("main_section")
  $("#main_section").load("includes_/contact_us/contact_us_trash.php")
}

function add_user_view(){
	loading("main_section")
	$("#main_section").load("includes_/users/add_user.php")
}
function edit_user_view(user_id){
	loading("main_section")
	$("#main_section").load("includes_/users/edit_user.php",{
		user_id:user_id
	})
}
function users_trash_view(){
	loading("main_section")
	$("#main_section").load("includes_/users/users_trash.php")
}


function add_product_info_view(){
	loading("main_section")
	$("#main_section").load("includes_/products/add_product_info.php")
}

function edit_blog_post_comment_reply_view(bcr_id){
  $("#blog_comment_replies_block").hide()
  loading("edit_blog_comment_reply_block")
  $("#edit_blog_comment_reply_block").load("includes_/blogs/edit_blog_post_comment_reply.php",{
    bcr_id:bcr_id
  })
}

function cancel_edit_blog_post_comment_reply_view(){
  loading("edit_blog_comment_reply_block")
  $("#edit_blog_comment_reply_block").html("")
  $("#blog_comment_replies_block").show()
}

function contact_us_details_view(c_id){
  $("#contact_us_msgs_container").hide()
  loading("contact_us_details_container")
  $("#contact_us_details_container").load("includes_/contact_us/contact_us_details.php",{
    c_id:c_id
  })
}

function not_contact_us_details_view(c_id){
  loading("main_section")
  $("#main_section").load("includes_/contact_us.php",{
    from_notification:c_id
  }) 
}

function contact_us_details_view_back(){
  loading("contact_us_details_container")
  $("#contact_us_details_container").html("")
  $("#contact_us_msgs_container").show()
}

function set_all_notifications_to_seen(){
  var post_url="includes_/main_handler.php";
  $.ajax({
      url: post_url, 
      type: "POST",
      data:  {
        set_all_notifications_to_seen_note:""
      },
          success: function(resp) {
            if(resp==1){  
              $(".notification_count_class").html("0");
            }
          },
          error: function(xhr, status, error) {
            
          }
    });
}


function add_product_basic_info(){
  form_id="add_product_form";
  response_id="add_product_response";
  post_url="includes_/main_handler.php";
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
      loading(response_id);
      $.ajax({
        url: post_url, 
        
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
            success: function(resp) {
              $("#"+form_id).unbind();
              $("#"+form_id).bind('submit');
              if(resp==1){
                 $("#main_section").load("includes_/products/add_product_main_image.php");  
              }else if((resp==0 || resp=="")){
                $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
              }else{
                $("#"+response_id).html(resp);
              }
            },
            error: function (request, error) {
                console.log(arguments);
                //alert(" Can't do because: " + error);
            }
      });
  });
}
function add_blog_basic_info(){
  form_id="add_blog_form";
  response_id="add_blog_response";
  post_url="includes_/main_handler.php";
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
      loading(response_id);
      $.ajax({
        url: post_url, 
        
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
            success: function(resp) {
              $("#"+form_id).unbind();
              $("#"+form_id).bind('submit');
              if(resp==1){
                 $("#main_section").load("includes_/blogs/add_blog_post_image.php");  
              }else if((resp==0 || resp=="")){
                $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
              }else{
                $("#"+response_id).html(resp);
              }
            },
            error: function (request, error) {
                console.log(arguments);
                //alert(" Can't do because: " + error);
            }
      });
  });
}
function add_miscellaneous_good_basic_info(){
  form_id="add_miscellaneous_good_form";
  response_id="add_miscellaneous_good_response";
  post_url="includes_/main_handler.php";
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
      loading(response_id);
      $.ajax({
        url: post_url, 
        
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
            success: function(resp) {
              $("#"+form_id).unbind();
              $("#"+form_id).bind('submit');
              if(resp==1){
                 $("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_main_image.php");  
              }else if((resp==0 || resp=="")){
                $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
              }else{
                $("#"+response_id).html(resp);
              }
            },
            error: function (request, error) {
                console.log(arguments);
                //alert(" Can't do because: " + error);
            }
      });
  });
}
function add_product_supporting_images(){
  form_id="add_product_supporting_images_form";
  response_id="add_product_supporting_images_response";
  post_url="includes_/main_handler.php";
  $.LoadingOverlay("show"); 
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
      loading(response_id);
        $.ajax({
          url: post_url, 
          
          type: "POST",
          data:  new FormData(this),
          contentType: false,
          cache: false,
          processData:false,
              success: function(resp) {
                $.LoadingOverlay("hide", true);
                $("#"+form_id).unbind();
                $("#"+form_id).bind('submit');
                if(resp==1){
                   //Uploaded and finish
                  $("#main_section").html("<p class='alert alert-success'>Operation successful. Redirecting...</p>");
                 setTimeout(function(){ 
                    $("#main_section").load("includes_/products/add_product_info.php");
                  }, 2000);  
                }else if((resp==0 || resp=="")){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
                }
              },
              error: function (request, error) {
                  $.LoadingOverlay("hide", true);
                  console.log(arguments);
                  //alert(" Can't do because: " + error);
              }
        });
    });
}

function add_miscellaneous_good_supporting_images(){
  form_id="add_miscellaneous_good_supporting_images_form";
  response_id="add_miscellaneous_good_supporting_images_response";
  post_url="includes_/main_handler.php";
  $.LoadingOverlay("show"); 
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
      loading(response_id);
        $.ajax({
          url: post_url, 
          
          type: "POST",
          data:  new FormData(this),
          contentType: false,
          cache: false,
          processData:false,
              success: function(resp) {
                $.LoadingOverlay("hide", true);
                $("#"+form_id).unbind();
                $("#"+form_id).bind('submit');
                if(resp==1){
                   //Uploaded and finish
                  $("#main_section").html("<p class='alert alert-success'>Operation successful. Redirecting...</p>");
                 setTimeout(function(){ 
                    $("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_info.php");
                  }, 2000);  
                }else if((resp==0 || resp=="")){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
                }
              },
              error: function (request, error) {
                  $.LoadingOverlay("hide", true);
                  console.log(arguments);
                  //alert(" Can't do because: " + error);
              }
        });
    });
}



function remove_product_supporting_image(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to remove this image?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function remove_miscellaneous_good_supporting_image(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to remove this image?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function add_more_product_supporting_images(p_id){
    var form_id="add_more_product_supporting_images_form";
    var response_id="add_more_product_supporting_images_response";
    var post_url="includes_/main_handler.php";
    $.LoadingOverlay("show");
    
    $("#"+form_id).change(function(e) {
      e.preventDefault();
      loading(response_id);
        $.ajax({
          url: post_url, 
          
          type: "POST",
          data:  new FormData(this),
          contentType: false,
          cache: false,
          processData:false,
              success: function(resp) {
                $.LoadingOverlay("hide", true); 
                $("#"+form_id).unbind();
                $("#"+form_id).bind('submit');
                if(resp==1){  
                  $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                  $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  view_product_supporting_images(p_id)
                }else if(resp==0){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
                }else if(resp=="exists"){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, record already exist</p>");
                }else{
                  $("#"+response_id).html(resp);
                }
              },
              error: function(xhr, status, error) {
                
                //alert(error.Message);
              }
        });
    });
}

function add_more_miscellaneous_good_supporting_images(mg_id){
    var form_id="add_more_miscellaneous_good_supporting_images_form";
    var response_id="add_more_miscellaneous_good_supporting_images_response";
    var post_url="includes_/main_handler.php";
    $.LoadingOverlay("show");
    
    $("#"+form_id).change(function(e) {
      e.preventDefault();
      loading(response_id);
        $.ajax({
          url: post_url, 
          
          type: "POST",
          data:  new FormData(this),
          contentType: false,
          cache: false,
          processData:false,
              success: function(resp) {
                $.LoadingOverlay("hide", true); 
                $("#"+form_id).unbind();
                $("#"+form_id).bind('submit');
                if(resp==1){  
                  $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                  $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  view_miscellaneous_good_supporting_images(mg_id)
                }else if(resp==0){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, try again later</p>");
                }else if(resp=="exists"){
                  $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation failed, record already exist</p>");
                }else{
                  $("#"+response_id).html(resp);
                }
              },
              error: function(xhr, status, error) {
                
                //alert(error.Message);
              }
        });
    });
}

function remove_miscellaneous_good(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to move this miscellaneous good to trash?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-warning text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function remove_product(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to move this product to trash?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-warning text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function remove_contact_us(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to move this message to trash?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-warning text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function remove_blog(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to move this blog to trash?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-warning text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function restore_product(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to restore this product?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-success text-center'>Restored</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}



function restore_contact_us(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to restore this message?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-success text-center'>Restored</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}

function restore_blog(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to restore this blog post?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-success text-center'>Restored</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}

function restore_miscellaneous_good(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to restore this miscellaneous good?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-success text-center'>Restored</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}

function delete_product(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("All data related to this product will be permanently deleted.Are you sure you want to delete this product?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function delete_contact_us(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to delete this message?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Message Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function delete_blog(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("All data related to this blog post will be permanently deleted.Are you sure you want to delete this blog post?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function delete_blog_post_comment(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("All data related to this blog post comment will be permanently deleted.Are you sure you want to delete this blog post comment?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function delete_blog_post_comment_reply(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to delete this blog post comment reply?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-right'>Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}


function delete_miscellaneous_good(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("All data related to this miscellaneous good will be permanently deleted.Are you sure you want to delete this miscellaneous good?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}

function delete_blog_category(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("All data related to this blog category will be permanently deleted.Are you sure you want to delete this blog category?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
              error: function(xhr, status, error) {
                //var err = eval("(" + xhr.responseText + ")");
                //alert(error.Message);
              }
          });
        }
    });
}


function add_product_supporting_images_view(){
	loading("main_section")
	$("#main_section").load("includes_/products/add_product_supporting_images.php")
}
function view_product_supporting_images(p_id){
	loading("supporting_images_container")
	$("#supporting_images_container").load("includes_/products/product_supporting_images.php",{
    p_id:p_id
  })
}
function edit_product_view(p_id){
	loading("main_section")
	$("#main_section").load("includes_/products/edit_product.php",{
    p_id:p_id
  })
}
function products_trash_view(){
	loading("main_section")
	$("#main_section").load("includes_/products/products_trash.php",{
    view_type:"all"
  })
}

function add_miscellaneous_good_info_view(){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_info.php")
}
function add_miscellaneous_good_main_image_view(){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_main_image.php")
}
function add_miscellaneous_good_supporting_images_view(){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_supporting_images.php")
}
function view_miscellaneous_good_supporting_images(mg_id){
	loading("supporting_images_container")
	$("#supporting_images_container").load("includes_/miscellaneous_goods/miscellaneous_good_supporting_images.php",{
    mg_id:mg_id
  })
}
function edit_miscellaneous_good_view(mg_id){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods/edit_miscellaneous_good.php",{
    mg_id:mg_id
  })
}
function miscellaneous_goods_trash_view(){
	loading("main_section")
	$("#main_section").load("includes_/miscellaneous_goods/miscellaneous_goods_trash.php")
}

function add_blog_info_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/add_blog_post_info.php")
}
function add_blog_category_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/add_blog_category.php")
}
function edit_blog_category_view(b_category_id){
	loading("main_section")
	$("#main_section").load("includes_/blogs/edit_blog_category.php",{
    b_category_id:b_category_id
  })
}
function add_blog_main_image_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/add_blog_post_main_image.php")
}
function add_blog_supporting_images_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/add_blog_supporting_images.php")
}
function view_blog_supporting_images(){
	loading("supporting_images_container")
	$("#supporting_images_container").load("includes_/blogs/blog_supporting_images.php")
}
function edit_blog_view(b_id){
	loading("main_section")
	$("#main_section").load("includes_/blogs/edit_blog_post.php",{
    b_id:b_id
  })
}
function blogs_trash_view(){
	loading("main_section")
	$("#main_section").load("includes_/blogs/blog_posts_trash.php",{
    view_type:"all"
  })
}
function blogs_trash_viewII(){
  var selected_view_type=$('#blogs_view_type option:selected').val()
  loading("main_section")
  $("#main_section").load("includes_/blogs/blog_posts_trash.php",{
    view_type:selected_view_type
  })
}
function blog_post_comments_view(b_id){
	loading("main_section")
	$("#main_section").load("includes_/blogs/blog_post_comments.php",{
    b_id:b_id
  })
}
function blog_post_comment_reply_view(bc_id){
	loading("main_section")
	$("#main_section").load("includes_/blogs/blog_post_comment_reply.php",{
    bc_id:bc_id
  })
}
function blog_comment_replies_content_view(bc_id){
  loading("blog_comment_replies_block")
  $("#blog_comment_replies_block").load("includes_/blogs/blog_post_comment_replies_content.php",{
    bc_id:bc_id
  })
}

function refresh_notifications_count(){
  $.ajax({
        url: "includes_/main_handler.php", 
        type: "POST",
        data:  {reflesh_notifications_count_note:""},
            success: function(resp) {
                $('#notification_count_id1').html(resp)
                $('#notification_count_id2').html(resp)
            },
            error: function(xhr, status, error) {
              //alert(error.Message);
            }
      });
}

//LOGIN
function login() {
  var form_id="user_signin_form";
  var response_id="user_signin_response";
  var post_url="includes_/main_handlerII.php";
  $("#"+form_id).submit(function(e) {
    e.preventDefault();
    loading(response_id);
      $.ajax({
        url: post_url, 
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
            success: function(resp) {
                $("#signin_form").unbind();
                $("#signin_form").bind('submit');

                if(parseInt(resp)==1){
                    window.location.href= "index.php";
                }else{
                  $("#"+response_id).html(resp);
                }
                
            },
            error: function(xhr, status, error) {
              //alert(error.Message);
            }
      });
  });
}

//SETUP ADMIN ACCOUNT
function setup_admin_account(){
  $("#admin_setup_form").submit(function(e) {
    e.preventDefault();
      $.ajax({
        url: 'includes_/main_handlerII.php', 
        
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
            success: function(resp) {
              	if(resp==1){  
	              $("#admin_setup_response").html("<p id='admin_setup_responseMin' class='alert alert-success'>Admin Account created. Redirecting to login...</p>");
	              $("#admin_setup_responseMin").fadeOut(5000,"swing",null)

	                setTimeout(function(){ 
	                	window.location.href= "index.php";
	                }, 4000);
	            }else if(resp==0){
	              $("#admin_setup_response").html("<p class='alert alert-warning'>Failed to create admin account</p>");
	            }else if(resp=="exists"){
	              $("#admin_setup_response").html("<p class='alert alert-warning'>The email you entered already registred</p>");
	            }else{
	              $("#admin_setup_response").html(resp);
	            }

	            $("#admin_setup_form").unbind();
                $("#admin_setup_form").bind('submit');
            },
           error: function(xhr, status, error) {
            //alert(error.Message);
          }
      });
  });
}

//LOGOUT
function logout(){
  r=confirm("Are you sure you want to logout?")
  if(r==true){
    $.ajax({
      url: "includes_/main_handler.php", 
      type: "POST",
      data:  {
        user_signout_note:""
      },
          success: function(resp) {
              if(parseInt(resp)==1){
                window.location.href= "login.php";
              }else{
                alert("We could not log you out, try again");
              }
          },
          error: function(xhr, status, error) {
            //alert(error.Message);
          }
    });
  }
}
function delete_user(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to move this user to trash?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-warning text-center'>Removed</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}
function restore_user(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to restore this user?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-success text-center'>Restored</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p class='alert alert-warning'>Sorry operation faled, try again later</p>");
                  }else{
                    $("#"+response_id).html(resp);
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}
function permanently_delete_user(form_id,element_id,response_id){
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        r=confirm("Are you sure you want to permanently delete this user?")
        if(r==true){
          loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    $("#"+element_id+"Dbtn").html("<p class='text-danger text-center'>Permanently Deleted</p>");
                  }else if(resp==0){
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>User not deleted, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }else{
                    //$("#"+response_id).html(resp);
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>User not deleted, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
        }
    });
}
//change password
function change_password(){
  loading("changePassResponse");
  var Cpassword=document.getElementById("Cpassword").value;
  var Npassword=document.getElementById("Npassword").value;
  var Rpassword=document.getElementById("Rpassword").value;
  $("#changePassResponse").load("includes_/profile/profile_handler.php",{
    Cpassword:Cpassword,
    Npassword:Npassword,
    Rpassword:Rpassword,
    change_password:""
  });
}
/*..........*/
function admin_reset_password(){
  universal_post("reset_password_form","reset_password_response","includes_/main_handlerII.php");
}
function admin_reset_password_(){
  universal_post("reset_password_form","reset_password_response","../includes_/main_handlerII.php");
}
//update profile
function update_profile(){
	universal_post("edit_profile_form","edit_profile_response","includes_/profile/profile_handler.php");
}
function add_user(){
  universal_post("add_user_form","add_user_response","includes_/main_handler.php");
}
function edit_user(){
  universal_post("edit_user_form","edit_user_response","includes_/main_handler.php");
}

function edit_product(){
  universal_post("edit_product_form","edit_product_response","includes_/main_handler.php");
}
function edit_blog(){
  universal_post("edit_blog_form","edit_blog_response","includes_/main_handler.php");
}
function edit_miscellaneous_good(){
  universal_post("edit_miscellaneous_good_form","edit_miscellaneous_good_response","includes_/main_handler.php");
}
function add_blog_category(){
  universal_post("add_blog_category_form","add_blog_category_response","includes_/main_handler.php");
}
function edit_blog_category(){
  universal_post("edit_blog_category_form","edit_blog_category_response","includes_/main_handler.php");
}




function add_blog_comment_reply(bc_id){
  var form_id="add_blog_comment_reply_form";
  var response_id="add_blog_comment_reply_response";
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful, reloading...</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    setTimeout(function(){ 
                      blog_comment_replies_content_view(bc_id)
                      $("html, body").animate({ scrollTop: $(document).height()+10000 }, 1000);
                    }, 2000); 
  
                  }else if(resp==0){
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>Operation failed, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }else{
                    //$("#"+response_id).html(resp);
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>Operation failed, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
    });
}

function edit_blog_comment_reply(bc_id){
  var form_id="edit_blog_comment_reply_form";
  var response_id="edit_blog_comment_reply_response";
  $("#"+form_id).submit(function(e) {
      e.preventDefault();
        loading(response_id);
          $.ajax({
            url: "includes_/main_handler.php", 
            
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
                success: function(resp) {
                  $("#"+form_id).unbind();
                  $("#"+form_id).bind('submit');
                  if(resp==1){  
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Operation successful, reloading...</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                    setTimeout(function(){ 
                      blog_post_comment_reply_view(bc_id)
                      $("html, body").animate({ scrollTop: $(document).height()+10000 }, 1000);

                      loading("edit_blog_comment_reply_block")
                      $("#edit_blog_comment_reply_block").html("")
                      $("#blog_comment_replies_block").show()
                    }, 2000); 
                      
  
                  }else if(resp==0){
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>Operation failed, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }else{
                    //$("#"+response_id).html(resp);
                    $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-warning'>Operation failed, try again later</p>");
                    $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  }
                },
                error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
          }
          });
    });
}