 
  $(document).ready(function() {
	
	
	
	// $( "#billedto" ).hide();
	 $( "#vehno" ).hide(); 
	 $( "#billno" ).hide();  
	 $( "#vendor" ).hide();
	 $( "#driver" ).hide();
	 $( "#reportdfrom" ).datepick();
	 $( "#reportdto" ).datepick();
		  
		
	
	
	$('#report_reset').click(function () {
		location.reload(true);
		
	});
	
	 $.post("reportviewfill.php",{'report_view_type':'getreporttype'},function(data){
		//  console.log(data);
		 
		 $.each(data.rows, function(i,rows){
			//console.log(rows.REPORTDESC+'->'+rows.REPORTCODE);
			$('#report_view_type').append("<option value='"+rows.REPORTCODE+"' >"+rows.REPORTDESC+"</option>");
		 })
	 },'json');
	
	
	 
	 
	 $('#report_typewise').on('click', function() {
        if($(this).val()=='all'){
			$('#billedto,#citywise,#consignee').hide();
			$('#prodcode').show();
			
			}
		else if($(this).val()=='partywise'){
			$('#billedto').show();
			$('#citywise,#prodcode,#consignee').hide();
			}
		else if($(this).val()=='partyproduct'){
			
			$('#prodcode').show();
			$('#citywise,#billedto,#consignee').hide();
			}
		else if($(this).val()=='partyconsignee'){
			$('#billedto').show();
			$('#citywise,#prodcode,#consignee').hide();
			}
		else if($(this).val()=='productconsignee'){
			$('#prodcode').show();
			$('#citywise,#billedto,#consignee').hide();
			}
		else if($(this).val()=='productorder'){
			$('#prodcode').show();
			$('#citywise,#billedto,#consignee').hide();
			}
		else if($(this).val()=='consignee'){
			$('#consignee').show();
			$('#citywise,#billedto,#prodcode').hide();
			}
		else if($(this).val()=='citywise'){
			$('#citywise').show();
			$('#billedto,#consignee,#prodcode').hide();
			}
		else if($(this).val()=='agentwise'){
			$('#billedto').show();
			$('#citywise,#consignee,#prodcode').hide();
			}
		else if($(this).val()=='distributor'){
			$('#billedto').show();
			$('#citywise,#consignee,#prodcode').hide();
			}
	
      });

	
		  $('#report_print').click(function () {
			var data = '';
			$('.dataTableContainer tr:eq(0) th,.dataTableContainer tr:not(.filtered) td').each(function(index, element) {
				if($(this).attr('name'))
				{
                data +=$(this).attr('name');
				data += '=';
				data += $(this).text()+"&";
				}
            });
			data += "reportdfrom="+$('#reportdfrom').val()+"&report_typewise="+$('#report_typewise option:selected').text()+ "&reportdto="+$('#reportdto').val()+ "&report_type="+$('#report_type option:selected').text()+"&report_view_type="+$('#report_view_type option:selected').text();
			data = 		encodeURI(data);
	
		var reptype=$('#report_view_type').val();
		var repviewtype=$('#report_type').val();
	if(reptype=='reprint_bill')
		{	
			if(repviewtype=='bill')
			{
			  var billno=$("#filter_type_value").val();	
			  // $("#filter_type_value").val((billno).substring(0,billno.length-1));
			   var temp = (billno).substring(0,billno.length-1);
			   $('#transperent').show();
				  $.post('bill_export_pdf.php?mode=reprint', {p_billno:temp,incstax:$('#incstax').prop('checked'),staxonmis:$('#staxonmis').prop('checked'),dsdetails:$('#DSDetails').prop('checked'),CmpLogo:$('#CmpLogo').prop('checked'),PrePrint:$('#PrePrint').prop('checked'),totinword:$('#totinword').val()}, function () {
		  $('#transperent').hide();
			  window.open("invoice.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
			  
		  });
			}
			else if(repviewtype=='dutyslip')
			{
				var bookid=$("#filter_type_value").val();	
				var temp = (bookid).substring(0,bookid.length-1);
				$.post('dutyslip_pdf.php?mode=reprint',{bookid:temp},function (data) {
				$('#transperent').hide();
				window.open("dutyslip.pdf",'','width=500,height=400');
				});
			}
		}

		else if(reptype=='orderinfo')
	{	
			
			$('#transperent').show();
	$.post('report_export_pdf.php?report_view_type='+reptype, data,function () {
			$('#transperent').hide();
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");

	});
		}
		else if(reptype=='bill_info')
		{	
			if($('#report_type').val()=='salesummery'){
				
				$('#transperent').show();
	$.post('summery_export_pdf.php?report_view_type='+$('#report_type').val(),data,function () {
	
				window.open("summeryview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();
	});
				}
				else{
			$('#transperent').show();
	$.post('report_export_pdf.php?report_view_type='+reptype, data,function () {
			$('#transperent').hide();
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
	});
	}

	
		}
		else if(reptype=='cov_lett')
		{
			var temp='';
			data+='&filter_type_value='+$("#filter_type_value").val();
	$('#transperent').show();
	$.post('covl_export_pdf.php',data,function () {
			$('#transperent').hide();
				window.open("cover_letter.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");

	});
			}
		
		else if(reptype=='dri_duty_det'||reptype=='book_info')
		{
			$('#transperent').show();
			
			
	$.post('report_export_pdf.php?report_view_type='+reptype,data ,function () {
	
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
	
	
		}
		
				else if(reptype=='log')
				{
					$('#transperent').show();
					$.post('report_export_pdf.php?report_view_type='+reptype, data,function () {
					
						window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
						$('#transperent').hide();
					
					});
				
				}
		
		else if(reptype=='led_det')
		{
			if($('#report_type').val()=='PEDRECEIPT'){
			$('#transperent').show();
			/*if($.trim($('#filter_type_value').val())=='')
			{
			var temp='';
						$(".dataTableContainer tr:not(.filtered) td.refno").each(function() {
                            temp+=$(this).text()+',';
                        });
						$("#filter_type_value").val(temp);
			}
			data+='&filter_type_value='+temp;*/
	$.post('report_export_pdf.php?report_view_type=PEDRECEIPT',data,function () {
	
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
			}
			
		else if($('#report_type').val()=='TrialBalance' ){
			$('#transperent').show();
	$.post('report_export_pdf.php?report_view_type=TrialBalance',data,function () {
	
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
			}
			
			
			else if($('#report_type').val()=='balancesheet' ){
			$('#transperent').show();
	$.post('report_export_pdf.php?report_view_type=balancesheet', data,function () {
	
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
			}
			
			else if($('#report_type').val()=='salepurcsummery' ){
			$('#transperent').show();
	$.post('report_export_pdf.php?report_view_type=salepurcsummery', data,function () {
	
				window.open("reportview.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
			}
			
			
			
		}
		
		
		else if(reptype=='veh_rep')
		{
			if($('#report_type').val()=='maint'){
			$('#transperent').show();
			
	$.post('fuel_export_pdf.php?report_view_type=maint',data,function () {
	
				window.open("fuelexport.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
				$('#transperent').hide();

	});
			}
			}
		
		
		
		else if(reptype=='fuel')
		{
			if($('#report_type').val()=='fuelregister'){
			$('#transperent').show();
			$.post('fuel_export_pdf.php?report_view_type=fuelregister', data,function () {
			window.open("fuelexport.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
			$('#transperent').hide();
            });
		    }
			
			
			else if($('#report_type').val()=='fuelsumm' ){
			$('#transperent').show();
			$.post('fuel_export_pdf.php?report_view_type=fuelsumm',data,function () {
			window.open("fuelexport.pdf","mywindow","menubar=1,resizable=1,width=870,height="+640+",left=250,top=80");
			$('#transperent').hide();
			});
			}
		}
		
		
		
			
		
		
		else 
		{
			jSuccess('Print Pdf Not Available');
			return;
			}
});
		  
		 $('body').on("change",'#report_view_type',function(){
			if($( "#reportdfrom" ).val()!=""&&$( "#reportdto" ).val()!="") 
		  {
			  
			if($('#report_view_type').val()=="reprint_bill")
			{
			   $('#rel_field').html("Company:");
			   $( "#billno,#vehno,#vendor,#driver,.alter_status,.sort_table,.cov_lett_show" ).hide();
			   $( "#billedto, .reprint_bill_option,#filter_type_book_info,#filter_type_value" ). val('').show(); 
			   $("#filter_type_book_info").html("<option selected='selected'>Bill No</option>");
			   $('#report_type').html("<option selected='selected' value='bill'>Bill</option><option value='dutyslip'>Duty Slip</option>");
			}
			
			else if($('#report_view_type').val()=="cov_lett")
			{
			   $('#rel_field').html("Company:");
			   $( "#billno,#vehno,#vendor,#driver,.alter_status,.sort_table" ).hide();
			   $( "#billedto, .reprint_bill_option,#filter_type_book_info,#filter_type_value,.cov_lett_show" ). val('').show(); 
			   $("#filter_type_book_info").html("<option selected='selected'>Bill No</option>");
			   $('#report_type').html("<option selected='selected'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>");
			}
			
			else if($('#report_view_type').val()=="veh_info_allduty")
			{
			  $('#rel_field').html("Veh No: <br> Vendor:");
			  $( "#billedto ,.reprint_bill_option,.alter_status,#vendor,#driver,#billno,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			 	$( "#vendor" ).show();
            	$( "#vehno" ).show();
			  $('#report_type').html("<option selected='selected' value='vendorpayout'>Vendor Payout</option><option  value='revenueshare'>Revenue Share</option>");
			}
			
			
			
			
			else if($('#report_view_type').val()=="veh_hire_inf")
			{
			  $('#rel_field').html("Vendor:");
			  $( "#billedto, .reprint_bill_option,.alter_status,#billno,#vehno,#driver,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			  $( "#vendor" ).show();
			  $('#report_type').html("<option selected='selected' value='default'>Default</option><option value='book_mis'>Booking MIS</option><option value='misbills'>Billing MIS</option><option value='vendorpofit'>Vendor Profit</option>");
			}
			
			
			else if($('#report_view_type').val()=="veh_rep")
			{
			  $('#rel_field').html("Veh No:");
			  $( "#billedto, .reprint_bill_option,.alter_status,#billno,#vendor,#driver,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			  $( "#vehno" ).show();
			  $('#report_type').html("<option selected='selected' value='inforunning'>Running Info</option><option value='infoservice'>Service Info</option><option value='avg'>Average</option><option value='jSuccesss'>jSuccesss</option><option value='book_mis'>Booking MIS</option><option value='maint'>Maintainances</option><option value='vehiclemis'>Vehicle MIS</option>");
			}
			

				else if($('#report_view_type').val()=="master")
			{
			  $('#rel_field').html("Employee:");
			  $( "#billedto, .reprint_bill_option,.alter_status,#billno,#vendor,#driver,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			  $( "#vehno" ).show();
			  $('#report_type').html("<option selected='selected' value='empinfo'>Employee info</option>");
			}
			
			
			else if($('#report_view_type').val()=="fuel")
			{
			  $('#rel_field').html("Veh No:");
			  $( "#billedto, .reprint_bill_option,.alter_status,#billno,#vendor,#driver,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			  $( "#vehno" ).show();
			  $('#report_type').html("<option selected='selected' value='fuelregister'>Fuel register</option><option value='fuelsumm'>Fuel Summery</option>");
			}


			else if($('#report_view_type').val()=="log")
			{
			  $('#rel_field').html("Company:");
			  $( "#vehno, .reprint_bill_option,.alter_status,#billno,#vendor,#driver,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
			  $( "#billedto" ).show();
			  $('#report_type').html("<option selected='selected' value='all'>All</option><option  value='smslog'>SMS LOG</option>");
			}
			
			else if($('#report_view_type').val()=="orderinfo")
			{
				if(sessionStorage.design=='SUADMIN')
					$('#report_type').html("<option selected='selected' value='allorders'>All Orders</option><option value='pending'>Pending</option><option value='dispatched'>Dispatched</option><option value='inprocess'>In Production</option>");
				
				else
					$('#report_type').html("<option selected='selected' value='allorders'>All Orders</option><option value='pending'>Pending</option><option value='dispatched'>Dispatched</option><option value='inprocess'>In Production</option>");
				
				
				//$('#rel_field').html("Company:");
				$( "#vehno ,.reprint_bill_option,.alter_status,#vendor,#driver,#billno,.cov_lett_show" ).hide();
				$( "#filter_type_book_info,#filter_type_value,#billedto,.sort_table" ).show();
								$('#sort_value').html("<option selected='selected' value=''>-select-</option>            <option value='bookid'>Bookid</option>            <option value='dutydate,bookid'>Book Date, Bookid</option>            <option value='billedto,dutydate,bookid'>Billed To,Book Date, Bookid</option>            <option value='status'>Status</option>            <option value='status,bookid'>Status, Bookid</option>            <option value='billedto,status,bookid'>Billed To,Status,Bookid</option>");
								$("#filter_type_book_info").html("<option value='' selected='selected'>-select filter-</option> <option value='bookedby'>Booked By</option>  <option value='usedby'>Guest</option>   <option value='city'>City</option>   <option value='package'>Package</option>     <option value='dutytype'>Duty Type</option>  <option value='vehicle'>Vehicle Type</option>");



				}
		else if($('#report_view_type').val()=="Invoiceinfo")
			{
				
				$('#report_type').html("<option selected='selected' value='allinv'>All Invoice</option><option value='pendinginv'>Pending Invoice</option><option value='paidinv'>Paid Invoice</option>");
				//$('#rel_field').html("Company:");
				$( "#vehno,.reprint_bill_option,.alter_status,#billno,#driver,#vendor,#filter_type_book_info,#filter_type_value,.cov_lett_show" ).hide(); 
				$( "#billedto,.sort_table" ).show();
				$('#sort_value').html("<option selected='selected' value=''>-select-</option><option value='srno'>SR No.</option><option value='billdate'>Bill Date</option><option value='billdate,srno'>Bill Date,Sr No.</option><option value='billto,srno'>Billed To,Sr No.</option><option value='expst'>Expst</option><option value='expst,srno'>Expst,Sr No.</option>");
				}
				
			else if($('#report_view_type').val()=="jobreg")
				{
				//$('#rel_field').html("Driver:");
				$( "#vehno, .reprint_bill_option,.alter_status,#billno,#vendor,#billedto,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide();
				$( "#billedto" ).show();
				$('#report_type').html("<option selected='selected' value='alljobs'>ALL JOBS</option><option value='Pendingjobs'>PENDING JOBS</option><option value='compltjobs'>COMPLEATED JOBS</option>");
				}
				
		else if($('#report_view_type').val()=="led_det")
			{
				
				$('#rel_field').html("Company");
			  $( ".prodcode,#report_typewise,#subreport_type" ).hide();
			 	$( "#billedto" ).show();
            	
				$('#report_type').html("<option selected='selected' value='SALES'>Sales</option><option value='PURCHASE'>Purchase</option><option value='PAYMENT'>Payments</option><option value='RECEIPT'>Receipt</option><option value='JOURNAL'>Journal</option><option value='CONTRA'>Contra</option><option value='PEDRECEIPT'>Outstanding Report</option><option value='PEDPAYMENT'>Outstanding Payment</option><option value='servicetax'>Service Tax Report</option><option value='tdsreport'>TDS Report</option><option value='tdssummery'>TDS Summery</option><option value='PEDPAYMENT'>Pending Payments</option><option value='salesummery'>Sales  Summery</option><option value='salepurcsummery'>Sales Purc Summery</option><option value='outstandsummery'>Outstanding Summery</option><option value='debtorssummery'>Debtors Summery</option><option value='creditorssummery'>Creditors Summery</option><option value='expensesummery'>Expense Summery</option><option value='cashbanksummery'>CashBank Summery</option><option value='servicestaxsummery'>Services Tax Summery</option><option value='tdssummerypay' hidden>TDS Summery Payable</option><option value='tdssummeryrecd' hidden>TDS Summery Recived</option><option value='TrialBalance' hidden>Trial Balance</option><option value='balancesheet' hidden>Balance Sheet</option><option value='PNLSTATEMEMT' hidden>P&L Statement</option><option value='cashbank' hidden>Cash Bank Book</option><option value='CREDITREPORT' hidden>Credit Report</option>");
				$('#rel_field').html("Company:");
				$( "#billedto" ).show();
				//$( "#billedto,.alter_status" ).show();
				$( "#vehno, .reprint_bill_option,#billno,#driver,#vendor,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show" ).hide(); 
				
				}
			
			
			else
			{
			  $('#rel_field').html("Company:");
			  $("#vehno ,.reprint_bill_option,#billno,#driver,#vendor,#filter_type_book_info,#filter_type_value,.sort_table,.cov_lett_show").hide(); 
			  $( "#billedto" ).show();
			  $('#report_type').html("<option selected='selected'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>");
			 
			
			}
		  }
			
		});
		
		//$('body').on('blur','#report_type'
		
		$('#report_type').click(function(){
			
			if($(this).val()=='PEDRECEIPT')
			{
				$("#filter_type_book_info").html("<option selected='selected' value='acc'>Account</option><option value='age'>Aging</option>");
				$('#filter_type_book_info,#filter_type_value').show();
				$('#filter_type_book_info').val('vchno');
				
				$('#sort_value').html("<option value='cf' selected='selected'>CF</option>            <option value='none'>Without CF</option>");
				$('#sort_value').show();
				$('.cov_lett_show').show(); 
			}
			else if($(this).val()=='bill'||$(this).val()=='dutyslip')
		  	{
				 $('#filter_type_book_info,#filter_type_value').show();
			}
			else
		  	{
				 $('#filter_type_book_info,#filter_type_value').hide();
				 $('#sort_value').hide();

			}
			
		});
		
		
		$('#report_view').click(function(){
			$('#transperent').show();

			$('#select_all').prop('checked',false);
		 $.post("reportviewfill.php",$('.form_report_view').serialize(),function(data){
			 console.log(data);
			 
			 if(data.error)
			 {
				 jError(data.error);
				 $('#transperent').hide();
				 return false;
			 }
			 
			 var jsonHtmlTable = ConvertJsonToTable(data, 'jsonTable', null);
			 $('#div_reportview').html(jsonHtmlTable);
			
			
		/*	var target = $("#div_reportview"); // <== Getting raw element
  $("#div_reportview1").scroll(function() {
   target.prop("scrollTop", this.scrollTop)
          .prop("scrollLeft", this.scrollLeft);
  });*/
  
  
			
		
		var rows = data.total_rows;
  $('select.pagesize').find('option:contains("All")').val(rows);
  //$('select.pagesize').val(rows);
		
		  // Add expected results to the cell
  var resultIndex = 0,
    expectedResults = [ 6, 100, 60, 5, 20, 4, 2, "1 & 2", 8, 2.25, 1.5, 2.7, 1.64, 150, 1200 ],
    resultLen = expectedResults.length;
		
		//without fixed footer
		
		 // define pager options
  pagerOptions = {
    container   : '#pager',       // target the pager markup (wrapper)
			  cssFirst       : '.first',       // go to first page arrow
			  cssPrev        : '.prev',        // previous page arrow
			  cssNext        : '.next',        // next page arrow
			  cssLast        : '.last',        // go to last page arrow
			  cssgotoPage    : '.gotoPage',    // go to page selector - select dropdown that sets the current page
			  csspageDisplay : '.pagedisplay', // location of where the "output" is displayed
			  csspageSize    : '.pagesize',     // page size selector - select dropdown that sets the "size" option
  };
		
		
		$("#div_reportview table").tablesorter({
			theme: 'default',
			widthFixed : false,
			showProcessing: true,
			//headerTemplate : '{content} {icon}', // Add icon for various themes

			widgets: ['filter', 'zebra', 'stickyHeaders','math'/*,'resizable'*/],
    		widgetOptions : {
			filter_searchDelay: 300,
			stickyHeaders_attachTo : '#div_reportview',	
			// resizable: true,
			
			
			math_data     : 'math', // data-math attribute
      		math_ignore   : [0],
      		math_mask     : '#,##0.#',
      		math_complete : function($cell, wo, result) {
        		var txt = result;
        		// mode will return an array if there is a tie
        		return $.isArray(result) ? 'Tie: ' + txt : txt;
      			}
			
		}
			})
			// initialize the pager plugin
    // ****************************
    .tablesorterPager(pagerOptions);
			
			
	
			//$("#div_reportview table").tableHeadFixer({'foot' : true, 'head' : false}); 
			
			totalRowCounter('.dataTableContainer');
		$('.tablesorter-filter').change(function(e) {
          totalRowCounter('.dataTableContainer')
        });
		
		if($('#report_type').val()=='vendorpayout'){
			$("#div_reportview table tbody tr").each(function(index, element) {
               
			   if($(this).find('td:eq(16)').text()==''){
			   $(this).css('color','#F00');
			   }
			    });
			}
			
			if($('#report_type').val()=='pending'){
			$("#div_reportview table tbody tr").each(function(index, element) {
				 if($(this).find('td:eq(16)').text()==''&&$(this).find('td:eq(18)').text()==''){
			   $(this).css('color','#F00');
			   }
              /* $( ".tablesorter-default tbody  tr:hover  td" ).each(function() {
               $(this).css('color','#F00');
                 });*/
			  
			    });
			}
			
			
			if($('#report_type').val()=='musterroll')
		{
			
			$('#table_report_view thead tr:eq(1) td:eq(1)').hide();
		}
			
		
		if($('#report_view_type').val()=='reprint_bill'||$('#report_view_type').val()=='cov_lett'||($('#report_view_type').val()=='led_det'&&$('#report_type').val()=='PEDRECEIPT'))
                    {
						$( "#filter_type_value" ).val('');
						
						 $("#select_all").click(function(){

							  //$("#booking_ids").val("");                   
							  if($(this).prop('checked')==true)
		  
							  {
								  var temp='';
								  $("#div_reportview .srno").each(function() {
									  temp+=$(this).text()+',';
								  });
								  $("#filter_type_value").val(temp);
							  }
							  else
							  {
								  $("#filter_type_value").val('');
								}
					
						 	});
						
						
						$("#div_reportview .srno").dblclick(function(){
							
						  var temp_id=$(this).text();
						  var billno=$("#filter_type_value").val();
						  if($.trim(billno)!='')
						  {
						  if(billno.search(temp_id)!=-1)
							  $("#filter_type_value").val($("#filter_type_value").val().replace(temp_id+",",""));
						  else
							  $("#filter_type_value").val($("#filter_type_value").val()+temp_id+",");
						  
						  }
						  else
							  $("#filter_type_value").val($("#filter_type_value").val()+temp_id+",");
						  });
                        
                    }
					else
					{ 
					
					$("#div_reportview .name").dblclick(function(){
						$('#billedto').val($(this).text());
						//$('#report_view').trigger('click');
					});
					
					$('#transperent').hide();
					return false;
					}
					
					
						
		
		$('#transperent').hide();
  		},'json');// report view post ends
		
	
		});// report view click ends
		
	$('#rep_email').click(function(){
		if($('#report_view_type').val()=='cov_lett'){
	fillEmailContent('.dataTableContainer table','#reportdfrom','#reportdto','srno=>Sr No.','.billno=>Bill No.','.billdate=>Bill Date','.usedby=>Used By','.total=> Total','.bookdate=>Book Date');		
		}
		else if($('#report_view_type').val()=='led_det'){
	fillEmailContent('.dataTableContainer table','#reportdfrom','#reportdto','srno=>Sr No.','.billno=>Bill No.','.billdate=>Bill Date','.usedby=>Used By','.total=> Total','.billbalance=>PENDING','.duedays=>DUE DAYS','');
			}
   $("#RepEmail").animate({
      width:'toggle'
    });	
});	
	
$('#SMSClose').click(function(){	
$('#RepEmail').hide(500);	
});

$('#billedto').change(function(){
	var billto = $.trim($('#billedto').val());	
if(billto!=''){
	$('#rep_email').show(500);
}
else{
	$('#rep_email').hide(500);
}
});

$('#excel_dump').click(function(e) {
	var temp =$('#report_view_type').val();
    window.open('../admin/export.php?reportdto='+$('#reportdto').val()+'&reportdfrom='+$('#reportdfrom').val()+'&billedto='+$('#billedto').val()+'&reptype='+temp+'&report_type='+$('#report_type').val());
});



$('body').on('dblclick','.billdet_view',function(){
	 var report_view_type = $('.report_view_type').val();
	 var report_type = $('#report_type').val();
	 var reportdfrom = $('.reportdfrom').val();
	 var reportdto = $('.reportdto').val();
	 var billed_to = $.trim($(this).html());
	 
	$.post('report_billdetail.php',{reportviewtype:$('.report_view_type').val(),reporttype:$('#report_type').val(),repfrom:$('.reportdfrom').val(),repto:$('.reportdto').val(),billedto:billed_to} ,function (data) {
		console.log(data);
		 if(data.error)
			 {
				 jError(data.error);
				 $('#transperent').hide();
				 return false;
			 }
				
				//searchTable($('#vehno').val())
				var jsonHtmlTable = ConvertJsonToTable(data, 'jsonTable', 'jSuccesss');
			 $('#billdet').html(jsonHtmlTable);
			 //$('#veh_avail').html(result);
			
			/// $("div#billdetails:first-child").append("<input type='button' class='close button' id='detclose' value='CLOSE'  /> ");
			
			$("#billdet table").tablesorter({
			theme: 'default',
			widthFixed: false,
			showProcessing: true,
			//headerTemplate : '{content} {icon}', // Add icon for various themes

			widgets: ['filter',  'stickyHeaders','zebra','math'  ],
    		widgetOptions : {
			filter_searchDelay: 300,
			stickyHeaders_attachTo : '#billdetailsrep',
			
			math_data     : 'math', // data-math attribute
      		math_ignore   : [0],
      		math_mask     : '#,##0.#',
      		math_complete : function($cell, wo, result) {
        		var txt = result;
        		// mode will return an array if there is a tie
        		return $.isArray(result) ? 'Tie: ' + txt : txt;
      			}
			}
			});
			
			totalRowCounter('.billdet');
			$('.tablesorter-filter').change(function(e) {
          	totalRowCounter('.billdet')
        	});
				
				$('#billdetailsrep').slideToggle("slow");
				
			},'json');
			
	
	});

$('body').on('click','#detclose',function(){
	
$('#billdetailsrep').hide();	
});
  });//document ends
  


 
	  function getCSVData(){
		// $("#table_report_view tr:eq(1)").hide();
 var csv_value=$('.dataTableContainer table:eq(0)').table2CSV({delivery:'value'});
csv_value=csv_value.replace(/<br\s*\/?>/mg,"\n");
 //Commented bcoz not working and replaced 
//csv_value=csv_value.replace(/\&amp;/g, "&");
 $("#csv_text").val(csv_value);	
 
  $("#table_report_view tr:eq(1)").show();
}


var winPop;

function positionedPopup(url,width,height){
	
	 if(winPop&&!winPop.closed&&winPop.document.location.href!=url){  //checks to see if window is open  
    winPop.close();  
  } 
 winPop =window.open (url,"mywindow","menubar=1,resizable=1,width="+width+",height="+height+",left=250,top=0");
  if(winPop&&winPop.document.location.href==url)
winPop.focus();


}

function totalRowCounter(container)
{
	  $(container).scrollTop(0);
	var scrollHeight = $(container).prop('scrollHeight');
	var containerHeight = $(container).height();
	var scrollTop = $(container).scrollTop();
	var padding	=	0;
	if($(container).prop('scrollWidth') > Number($(container).width())+10)
	//padding =10 ;   //adjust footer position
	
	$(container+' table tfoot td').css('bottom',Number(scrollHeight)-Number(containerHeight)-scrollTop+padding);
	$(container).scroll(function(){
		
		scrollHeight = $(container).prop('scrollHeight');
		scrollTop	= $(container).scrollTop();
		$(container+' table tfoot td').css('bottom',Number(scrollHeight)-Number(containerHeight)-scrollTop+padding);
	});

}



