function blogs_view(){
	loading("blogs_container")
	$("#blog_details_container").html("")
	$("#blogs_container").show()
	$("#blogs_container").load("includes_/blogs.php");
}
function blogs_view_by_category(b_category_id){
	loading("blogs_container")
	$("#blog_details_container").html("")
	$("#blogs_container").show()
	$("#blogs_container").load("includes_/blogs.php",{
		b_category_id:b_category_id
	});
}

function view_blogs_special(page){  
	loading("blogs_container")
    var getCount=document.getElementById("count_select");
    if($('#count_select')[0].selectedIndex<=0){
      getCount=5;
    }else{
        var getCount=getCount.options[getCount.selectedIndex].value;
    }
    
    $("#blogs_container").load( "includes_/blogs.php",{view_blogs_display_guider:"view_blogs_display_guider",count:getCount,page:page});
}
function search_blog(){
	loading("blogs_container")
  var searchData=document.getElementById('blog_search_data').value;
  if(searchData!=""){
    $("#blogs_container").load( "includes_/main_handler.php",{search_blog: searchData,search_value:searchData});
  }else{
    view_blogs_special(null);
  }
}

function load_blog_comments(b_id){
	loading("single-post-comments")
	$("#single-post-comments").load("includes_/blog/blog_comments.php",{
		b_id:b_id
	});
}

function load_specific_comment_replies(bc_id,specific_comment_replies_id){
	loading(specific_comment_replies_id)
	$("#"+specific_comment_replies_id).load("includes_/blog/specific_blog_comment_replies.php",{
		bc_id:bc_id
	});
}






function blog_details_view(b_id){
	loading("blog_details_container")
	$("#blogs_container").hide()
	$("#blog_details_container").load("includes_/blog/blog_details.php",{
		b_id:b_id
	});

	setTimeout(function() {
		$('html, body').animate({
	        scrollTop: $("#blogs_main_container").offset().top
	    }, 1000);
    }, 100);
}
function back_to_blogs(){
	$("#blogs_container").show()
	$("#blog_details_container").html("");

		
	setTimeout(function() {
		$('html, body').animate({
	        scrollTop: $("#blogs_main_container").offset().top
	    }, 1000);
    	
    }, 100);

}
function food_product_list_view(){
	loading("products_container")
	$("#products_container").load("includes_/products/food_product_list.php");
}
function food_product_details_view(p_id){
	loading("products_container")
	$("#products_container").load("includes_/products/food_product_details.php",{
		p_id:p_id
	});
}

function chemical_product_list_view(){
	loading("products_container")
	$("#products_container").load("includes_/products/chemical_product_list.php");
}
function chemical_product_details_view(p_id){
	loading("products_container")
	$("#products_container").load("includes_/products/chemical_product_details.php",{
		p_id:p_id
	});
}

function tech_product_list_view(){
	loading("products_container")
	$("#products_container").load("includes_/products/tech_product_list.php");
}
function tech_product_details_view(p_id){
	loading("products_container")
	$("#products_container").load("includes_/products/tech_product_details.php",{
		p_id:p_id
	});
}

function miscellaneous_goods_list_view(){
	loading("miscellaneous_goods_container")
	$("#miscellaneous_goods_container").load("includes_/miscellaneous_goods/miscellaneous_goods_list.php");
}
function miscellaneous_good_details_view(mg_id){
	loading("miscellaneous_goods_container")
	$("#miscellaneous_goods_container").load("includes_/miscellaneous_goods/miscellaneous_good_details.php",{
		mg_id:mg_id
	});
}

function contact_us(){
	$.LoadingOverlay("show");
	var form_id="contact_us_form";
	var response_id="contact_us_response";
	var post_url="includes_/main_handler.php";
	$("#"+form_id).submit(function(e) {
      e.preventDefault();
      
        $.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){  
                  $("#contact_us_form_inner").html("<p class='alert alert-success text-center'>We received your message.Thank  you for contacting us.</p>");
                  document.getElementById("contacts_").scrollIntoView();
                }else if(resp==0){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your message could not be sent, please try again later</p>");
                }else if(resp=="exists"){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your message could not be sent, please try again later</p>");
                }else{
                  $("#"+response_id).html(resp);
                }
              },
              error: function(xhr, status, error) {
              	$.LoadingOverlay("hide", true);
                //var err = eval("(" + xhr.responseText + ")");
                //alert(err.Message);
              }
        });
    });
}

function add_blog_comment(b_id){
	var form_id="add_comment_form";
	var response_id="add_comment_response";
	var post_url="includes_/main_handler.php";
	$("#"+form_id).submit(function(e) {
      e.preventDefault();
      	loading("add_comment_response")
        $.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){  
                  $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Comment posted.</p>");
                  $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  load_blog_comments(b_id)
                  $("#"+form_id).trigger('reset')
                  document.getElementById("add_comment_form").scrollIntoView();
                }else if(resp==0){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your comment could not be posted, please try again later</p>");
                }else if(resp=="exists"){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your comment could not be posted, please try again later</p>");
                }else{
                  $("#"+response_id).html(resp);
                }
              },
              error: function(xhr, status, error) {
              	
                //var err = eval("(" + xhr.responseText + ")");
                //alert(err.Message);
              }
        });
    });
}

function add_blog_comment_reply(form_id,response_id,bc_id,form_container_id,specific_comment_replies_id){
	var 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){  
                  $("#"+response_id).html("<p id='"+response_id+"Min"+"' class='alert alert-success'>Reply posted.</p>");
                  $("#"+response_id+"Min").fadeOut(5000,"swing",null)
                  load_specific_comment_replies(bc_id,specific_comment_replies_id)
                  $("#"+form_id).trigger('reset')
                  setTimeout(function() {
						$("#"+form_container_id).hide()
				    }, 2000);
                  
                  //document.getElementById("add_comment_form").scrollIntoView();
                }else if(resp==0){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your comment could not be posted, please try again later</p>");
                }else if(resp=="exists"){
                  $("#"+response_id).html("<p class='alert alert-warning text-center'>Sorry your comment could not be posted, please try again later</p>");
                }else{
                  $("#"+response_id).html(resp);
                }
              },
              error: function(xhr, status, error) {
              	
                //var err = eval("(" + xhr.responseText + ")");
                //alert(err.Message);
              }
        });
    });
}