

<script>
var resizefunc = [];
</script>

<!-- jQuery  -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/tether.min.js"></script><!-- Tether for Bootstrap -->
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/waves.js"></script>
<script src="assets/js/jquery.nicescroll.js"></script>
<script src="assets/plugins/switchery/switchery.min.js"></script>


<!-- validation -->    
<script src="assets/plugins/validation/jquery.validate.js" type="text/javascript"></script> 
<script src="assets/plugins/validation/additional-methods.js" type="text/javascript"></script> 
         
<!-- Required datatable js -->
<script src="assets/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
<!-- Buttons examples -->
<script src="assets/plugins/datatables/dataTables.buttons.min.js"></script>
<script src="assets/plugins/datatables/buttons.bootstrap4.min.js"></script>
<script src="assets/plugins/datatables/jszip.min.js"></script>
<script src="assets/plugins/datatables/pdfmake.min.js"></script>
<script src="assets/plugins/datatables/vfs_fonts.js"></script>
<script src="assets/plugins/datatables/buttons.html5.min.js"></script>
<script src="assets/plugins/datatables/buttons.print.min.js"></script>
<script src="assets/plugins/datatables/buttons.colVis.min.js"></script>
<!-- Responsive examples -->
<script src="assets/plugins/datatables/dataTables.responsive.min.js"></script>
<script src="assets/plugins/datatables/responsive.bootstrap4.min.js"></script>


<!-- Sweet Alert js -->
<script src="assets/plugins/bootstrap-sweetalert/sweet-alert.min.js"></script>
<script src="assets/pages/jquery.sweet-alert.init.js"></script>

<!-- Modal-Effect -->
<script src="assets/plugins/custombox/js/custombox.min.js"></script>
<script src="assets/plugins/custombox/js/legacy.min.js"></script>


<!-- Selectbox search Plugins js-->
<script type="text/javascript" src="assets/plugins/multiselect/js/jquery.multi-select.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-quicksearch/jquery.quicksearch.js"></script>
<script src="assets/plugins/select2/js/select2.full.min.js" type="text/javascript"></script>

<!-- Date and Date time pickers Plugins js -->
<script src="assets/plugins/moment/moment.js"></script>
<script src="assets/plugins/timepicker/bootstrap-timepicker.min.js"></script>
<script src="assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="assets/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>


<!-- iCheck -->      
<link type="text/css" href="assets/plugins/iCheck/square/blue.css" rel="stylesheet" />     
<script src="assets/plugins/iCheck/icheck.min.js" type="text/javascript"></script> 
		
<!-- App js -->
<!--<script src="assets/js/jquery.core.js" type="text/javascript"></script>
<script src="assets/js/jquery.app.js" type="text/javascript"></script>-->

<!-- Autocomplete -->
<!--<script src="assets/autocomplete/js/jquery.easy-autocomplete.js" type="text/javascript"></script>-->
 
   

<script type="text/javascript">

var sucmsg = 'has been added successfully';
var exsmsg = 'Already Exists';
var upmsg  = 'has been updated successfully';
var reqmsg = 'Required fields should not be empty';
var delmsg = 'Deleted successfully';
var statusmsg= 'Status updated successfully';
var exsmsg_email = 'Email ID already exists. Please try with other email ID to create account.';
var exsmsg_phone = 'Mobile number already exists. Please try with other mobile number create account.';
var exsmsg_reference = 'Reference exists with other data. Cannot be deleted.';
var oldpass_reference = 'Old Password doesn`t match. Please enter right password.';
var othmsg = 'Opps!!@ Server Error. Please retry again.';
var exsmsg_refstats = 'Reference exists with other data. Cannot Perform the action.';
var dataGridHdn; 


 $(function () {    
	$('input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
    });
	
	
	$(".select2").select2();
 });
  
  
  $(".date-picker-month").datepicker( {
    format: "mm-yyyy",
    startView: "months", 
    minViewMode: "months",
    orientation: "top",
    autoclose: true
});


jQuery(document).ready(function($){
	var currentPath  = window.location.pathname;	
	var splitPath = currentPath.split('/');
	var cPath = splitPath[splitPath.length-1];	
	if(cPath.indexOf('_') != -1){		
		var cPathSplit = cPath.split('_');       	
		if(cPathSplit[0].length > 0){		
			$('.navigation-menu li').removeClass('active');		
			$('.navigation-menu a').each(function(){				
				var href = $.trim($(this).attr('href'));
				var hrefSplit = href.split('_');					
				if(hrefSplit[0] == cPathSplit[0]){					
					$(this).closest('li').addClass('active');
					$(this).closest('ul').parent().addClass('active');				
				}
			});
		}
	}
});
 

//Accept Number only function - START
 function isNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
//Accept Number only function - END


function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
   return true;
}


//Data table all page display grid common function - START		
 function datatblCal(hdnFld)
	{	  	   	
	    var i=0;	    
        var dataTable = $('#tblresult').dataTable( {		
		initComplete: function () {
			if(typeof hdnFld !='undefined'){				
			}	
			unloading(); 
        },	
			"order":[[0,"desc"]],
            "processing": true,
			//aoColumnDefs: [ { bSortable: true, aTargets: [ '_all' ] },{ bSortable: true, aTargets: [0] }],
			"columnDefs": [ { "targets": remove_sorting_columns(), "orderable": false } ],
			"destroy" : true,
            "serverSide": true,
			"stateSave": true,
			"bStateSave" : false,
			"language": { "processing": loading() },
            "ajax":{
                url :"display-grid-data.php?finaltab="+$('#disptblname').val(), // json datasource
                type: "post",  // method  , by default get
                error: function(){  // error handling                  
                    $("#tblresult").append('<tbody class="employee-grid-error"><tr><th colspan="4">No data found in the server</th></tr></tbody>');
					unloading(); 
                }
            } 
           }); 
}

 function datatblCalExport(hdnFld)
	{	  	   	
	    var i=0;	    
        var dataTable = $('#tblresult').dataTable( {		
		initComplete: function () {
			if(typeof hdnFld !='undefined'){				
			}	
			unloading(); 
        },	
			"order":[[0,"desc"]],
            "processing": true,
			//aoColumnDefs: [ { bSortable: true, aTargets: [ '_all' ] },{ bSortable: true, aTargets: [0] }],
			"columnDefs": [ { "targets": remove_sorting_columns(), "orderable": false } ],
			"destroy" : true,
            "serverSide": true,
			"stateSave": true,
			"bStateSave" : false,
			"language": { "processing": loading() },
            "ajax":{
                url :"display-grid-data.php?finaltab="+$('#disptblname').val(), // json datasource
                type: "post",  // method  , by default get
                error: function(){  // error handling                  
                    $("#tblresult").append('<tbody class="employee-grid-error"><tr><th colspan="4">No data found in the server</th></tr></tbody>');
					unloading(); 
                }
            },            			
			dom: 'lBfrtip',			
	        buttons: [
				{
				extend: 'excel', 
				exportOptions: { modifier: { page: 'all', search: 'none' } },
				text: 'Export to Excel',
				footer: true,
				filename: function(){
						var d = new Date();
						var n = d.getTime();
						return 'report_'+n;
					}
				}
			]
        } ); 
}


//Data table all page display grid common function - START		
 function datatblCalAdvanceSearch(hdnFld,)
	{
 	   var iColumns = $('#tblresult thead th').length;  // count all column length
	   var sortrmvcloumn1 = parseInt(iColumns-2); // sorting remove to action column
	   var sortrmvcloumn2 = parseInt(iColumns-1); // sorting remove to status column
	   
	console.log($("#search").serializeArray());
	    var i=0;
        var dataTable = $('#tblresult').dataTable( {		
		initComplete: function () {
			if(typeof hdnFld !='undefined'){				
			}	
			unloading(); 
        },					
            "processing": true,
			//aoColumnDefs: [ { bSortable: true, aTargets: [ '_all' ] },{ bSortable: true, aTargets: [0] }],
			"columnDefs": [ { "targets": [sortrmvcloumn1,sortrmvcloumn2], "orderable": false } ],
			"destroy" : true,
            "serverSide": true,
			"stateSave": false,
			//"bStateSave" : false,
			"language": { "processing": loading() },
            "ajax":{
                url :"display-grid-data.php?"+$("#search").serialize()+"&finaltab="+$('#disptblname').val(), // json datasource
                type: "post",  // method  , by default get
				data : $("#search").serializeArray(),
                error: function(){  // error handling                  
                    $("#tblresult").append('');
					unloading(); 
                }
            },
			

        } ); 
}
//Data table all page display grid common function - END

function remove_sorting_columns(){
	var iColumns = $('#tblresult thead th').length;  // count all column length
	var sortrmvcloumn1 = parseInt(iColumns-2); // sorting remove to action column
	var sortrmvcloumn2 = parseInt(iColumns-1); // sorting remove to status column   	
	disptblclumn = $('#disptblname').val();
	var temprow=[];		
	var rmvfilterclumn = 0;	

	if(disptblclumn == "purchase" || disptblclumn == "amenities"){
		rmvfilterclumn = $('#rmv_sort_clm').val();
	}	
		
	if(rmvfilterclumn == 0){
		temprow.push(sortrmvcloumn1,sortrmvcloumn2);	 
		return temprow;	
	}
	else{
		var row = rmvfilterclumn.split(",").map(Number);				
		$.each(row, function( index, value ) {	
		  temprow.push(parseInt(value));			  
		});	
		
		temprow.push(sortrmvcloumn1,sortrmvcloumn2);	 
		return temprow;
	}
}

//Data table all page display grid common function - END




//Save data to db all page common function - START		
function funSubmt($frm,$urll,$acts,$stats,$lodlnk)
{
	if ($('#'+$acts).valid()) {
		$("button").attr('disabled',true);

		var disabled = $('#'+$acts).find(':input:disabled').removeAttr('disabled');
		var formdatas = $("#"+$acts).serialize();	
		disabled.attr('disabled','disabled');

		$.ajax({
			url        : $urll,
			method     : 'POST',
			dataType   : 'json',
			data       : formdatas,
			beforeSend: function() {
				loading();
 			},
			success: function(response){ 
			
			    if(response.rslt == "1"){
					swal("Success!", $stats +' '+ sucmsg, "success");										
					$("#"+$acts)[0].reset();
					$(location).attr('href', $lodlnk);
				}
				else if(response.rslt == "2"){
					swal("Update!", $stats +' '+ upmsg, "success");
					$("#"+$acts)[0].reset();
					$(location).attr('href', $lodlnk);
				}			
			    else if(response.rslt == "3"){
					swal("Failure!", $stats +' '+ exsmsg, "warning");
				}
				else if(response.rslt == "4"){
					swal("Failure!", $stats +' '+ reqmsg, "warning");
				}
				else{
					swal("Failure!", othmsg, "warning");
				}		
			
				unloading();
				$("button").attr('disabled',false); 
				
			}
		});
	}	
}
//Save data to db all page common function - END	

//Save data to db Image upload page common function - START		
function funSubmtWithImg($frm,$urll,$acts,$stats,$lodlnk)
{    	
//alert($stats)
	if ($('#'+$acts).valid()) {
		$("button").attr('disabled',true);
		
		var m_data = new FormData();
		var disabled = $('#'+$acts).find(':input:disabled').removeAttr('disabled');
		
		var formdatas = $("#"+$acts).serializeArray();	
		disabled.attr('disabled','disabled');		
		
		$.each( formdatas, function( key, value ) {
			 m_data.append( value.name, value.value);							 
		});
		if($stats == 'user'){			
			m_data.append( 'user_photo', $('input[name=user_photo]')[0].files[0]);			
		}
		else if($stats == 'company'){			
			m_data.append( 'company_logo', $('input[name=company_logo]')[0].files[0]);			
		}	
		else if($stats == 'supplier'){			
			m_data.append( 'supplier_logo', $('input[name=sup_company_logo]')[0].files[0]);	
			m_data.append( 'supplier_img', $('input[name=sup_image]')[0].files[0]);
		}
		else if($stats == 'customer'){			
			m_data.append( 'customer_logo', $('input[name=cus_company_logo]')[0].files[0]);	
			m_data.append( 'customer_img', $('input[name=cus_image]')[0].files[0]);
		}
		
		$.ajax({
			url        : $urll,
			type	   : 'POST',
			dataType   : 'json',
			processData: false,
            contentType: false,
			data       : m_data,
			beforeSend: function() {
				loading();
 			},
			success: function(response){ 
			
			    if(response.rslt == "1"){
					swal("Success!", $stats +' '+ sucmsg, "success");										
					$("#"+$acts)[0].reset();
					$(location).attr('href', $lodlnk);
				}
				else if(response.rslt == "2"){
					swal("Update!", $stats +' '+ upmsg, "success");
					$("#"+$acts)[0].reset();
					$(location).attr('href', $lodlnk);
				}			
			    else if(response.rslt == "3"){
					swal("Failure!", $stats +' '+ exsmsg, "warning");
				}
				else if(response.rslt == "4"){
					swal("Failure!", $stats +' '+ reqmsg, "warning");
				}
				else{
					swal("Failure!", othmsg, "warning");
				}		
			
				unloading();
				$("button").attr('disabled',false); 
				
			}
		});
	}	
}
//Save data to db Image upload page common function - END	


//Active / inactive change all page common function - START
function funchangestatus(t,$frm,$par){
	swal({
		title: "Are you sure?",
        text: "Sure You want to change the status?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, Change it!",
        closeOnConfirm: false,
		closeOnCancel: true
    },
	function () {
		$.ajax({		
			url        : $frm,
			method     : 'POST',
			dataType   : 'json',
			data       : $par,
			beforeSend: function() {
				loading();
 			},
			success: function(response){ 
				unloading();
				if(response.rslt == '6')
				{					
					swal("Success!", statusmsg, "success");	
					datatblCal(dataGridHdn);
				}
				else if(response.rslt == '7')
				{					
					if(response.ermsg){
						swal("Failure!", response.ermsg, "warning");
					}
					else{
						swal("Failure!", exsmsg_refstats, "warning");
					}				
				}
				else{
					swal("Failure!", othmsg, "warning");
				}	
			}		
		});	
    }); 
}
//Active / inactive change all page common function - END


//Delete data all page common function - START
function funStats(t,$frm,$par){
	swal({
		title: "Are you sure?",
        text: "You will not be able to recover this details!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        closeOnConfirm: false,
		closeOnCancel: true
    },
    function () {
		$.ajax({		
			url        : $frm,
			method     : 'POST',
			dataType   : 'json',
			data       : $par,
			beforeSend: function() {
				loading();
 			},
			success: function(response){
				unloading();
				if(response.rslt == '5')
				{					
					swal("Success!", delmsg, "success");	
					datatblCal(dataGridHdn);
				}
				else if(response.rslt == '7')
				{
					if(response.ermsg){
						swal("Failure!", response.ermsg, "warning");
					}
					else{
						swal("Failure!", exsmsg_refstats, "warning");	
					}	
				}
				else{
					swal("Failure!", othmsg, "warning");
				}
			}		
		});	
	 
    }); 	 
 }
//Delete data all page common function - END

 
//Cancel all page common function - START	 
function funCancel($frm,$acts,$stats,$lodlnk)
{  
	swal({
		title: "Are you sure?",
		text: "Are you sure to cancel?",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: "#DD6B55",
		confirmButtonText: "Ok",
		closeOnConfirm: true
	},
	function (isConfirm) { 
		if (isConfirm) {			
			$("#"+$acts)[0].reset();
			$(location).attr('href', $lodlnk);
		}
	});
}
//Cancel all page common function - END
function downloadcsv(tagname)
	  {
		 
		  $(location).attr('href','<?php echo public1_url; ?>common_download.php?act='+tagname+'&'+$("#search").serialize());
	  }
 
</script>		
		