$(document).ready(function () {	
	$(".tabLinkBlock:first").removeClass("hide");
	$(".tabLink:first").addClass("activeLink"); 
	$(".right_icon").click(function () {
		$(this).next().toggle();
		$(this).toggleClass("pane_expand");
	});
	$(".tabLink").click(function(){
		if($(".tabLinkBlock").length>1)
		{
			var indexVar =  $(".tabLink").index(this);
			$(".tabLink").removeClass("activeLink");
			$(this).addClass("activeLink");
			$(".tabLinkBlock").addClass("hide");
			$('.tabLinkBlock:eq('+indexVar+')').removeClass("hide");
		}	
		return false;	  
	});
});	
 $(function () {
	var d 	= new Date();
	var nd 	= new Date(d.getFullYear(),d.getMonth(),d.getDate()+1,d.getHours()-1,d.getMinutes(),d.getSeconds());
	var erDate 	= new Date(d.getFullYear()-3,d.getMonth(),d.getDate(),d.getHours(),d.getMinutes(),d.getSeconds());

	if($('#daterange').length>0){
	$('#daterange').daterangepicker({
			arrows: false,
			dateFormat: datePickerDateFormat,
			earliestDate:erDate,
			latestDate:nd
	});
	}			
  });		   
$(".custom-btnt").click(function() {
	
  if($(".dropdiv").is(':visible'))
  {
	  $(".dropdiv").slideUp();
  }
  else
  {
  	$(".dropdiv").slideDown();   
	$(this).addClass("active");
  }
});
$(document).mouseup(function (e)
{
    var container = $(".dropdiv");

    if (container.has(e.target).length === 0)
    {
        container.slideUp();
		 $(".custom-btnt").removeClass("active");
    }
	
});
$(".sumry-tble td").last().css("border-right", "0")

$("#submit").click(function(){ 

    var selectedID	=	0;
    var daterange=$('#daterange').val(); 
	if(daterange){	
		var dateString	=	daterange.split(' - ');	
	}
     if (dateString[0] == '') {
        selectedID = 1;
    }
    if (selectedID == 1) {       
            jAlert(errDate);
            return false;
    }	
    var pattern = /\//g; 
	if(daterange){
		daterange = daterange.replace(pattern,"+");
	}
	$.ajax({
	url:GLOBAL_BASE_PATH+"/index/ajaxGraph/date/"+daterange+"/",
	beforeSend : function ()
	  {   
	  		if($(".show-pane").is(':visible'))
			{ $(".right_icon").toggleClass("pane_expand");
	  			$(".show-pane").slideUp();	
			}
	  },
	success:function(data){ //alert(data); 
		var obj=jQuery.parseJSON(data);
		$('#placeholder').empty();
		$('#sales-amount').empty();
		$('#sales-count').empty(); 	
		$('#graph-label').empty();		
		$('#sales-avg').empty();
		$('#placeholder').append(obj.graph);
		$('#sales-amount').append(obj.salesAmount);
		$('#sales-avg').append(obj.avg);
		$('#sales-count').append(obj.salesCount);
		$('#graph-label').append(obj.orderLabel);	
	  }

	})
});
$(document).mouseup(function(e){ 
    var container = $(".show-pane");
	var container2 = $(".ui-daterangepickercontain");
	var container3 = $(".ui-multiselect-menu");
    if (container.has(e.target).length === 0 && container2.has(e.target).length === 0 && container3.has(e.target).length === 0){
        container.slideUp();
    }
});	

