//BUSQUEDA DE TABDASH
var formaTABDASH = null;
var panelTABDASH = null;
var intMode = 100;
var idTienda = null, idProveedor=null;
var GridStoreTABDASH = null;
var strToday = "", strAnioHoy = "", strAnioAnt="";

function TABDASH_Constructor(){
	strAnioHoy = moment().format("YYYY");
	strAnioAnt = strAnioHoy-1;

	console.log("TABDASH_Constructor / strAnioHoy: "+ strAnioHoy +" / strAnioAnt: "+ strAnioAnt);
	idTab = 'TABDASH';
	var strWidth = $(document).width()-40;
	var strHeight = $(document).height()-40;

	var strUrlPro = "vistas/tabDashboard.php";
	$.post(strUrlPro, function(dataNew){

		$("#divDashboard").empty();
		$("#divDashboard").html(dataNew);

		//var strToday = moment().format("DD/MM/YYYY");
		//$("#divFiltrosDashboard").find("#txtFechaGral").val(strToday);

		getDataFamilia(1, $( "#divDashboard1" ));
		
		//getDataDashboard2();
		//setDateFn("ultimosdias",7);

		//var selObj = $("#divFiltrosDashboard").find("#selectConvenio");
		//cargarDatos(selObj);

		mouseEvent();

	});

}

//var arrItemsGral = [], arrEstudiosGral = [], arrColsGral = [];

function getDataFamilia(intCaseArg, divObjConArg){
	console.log("getDataFamilia");

	if(objUsuario.empresa!=null){
		
		divObjConArg.html("<div style='width:200px; margin-top:25px; margin-left:auto; margin-right:auto;'><img src='css/images/loading.gif'/></div>");
		
		var strUrlUsu = "data/catUsuarios.php?intEmpresa="+ objUsuario.empresa +"&rnd="+ Math.random();
		
		$.get(strUrlUsu, function(dataNew){
			if(	dataNew.toLowerCase().indexOf("error") < 0 ){		
				if(	dataNew.length > 20 ){							 
						  
					var data = $.parseJSON(dataNew);
					var arrItems = data.Items;
		
					var strHtml = "";
					
					for (var i=0; i<arrItems.length; i++) {

                		var strMiembro = arrItems[i].strNombres +' '+ arrItems[i].strApellidos ;
                
                	    strHtml += '<div id="divUsuario_'+ i +'" style="float:left; width:180px; height:200px; border:1px solid #ccc; border-radius:8px; text-align:center; margin:10px; padding:10px; font-size: 14px; background: rgb(175,217,66); background: linear-gradient(0deg, rgba(175,217,66,1) 0%, rgba(107,172,10,1) 100%); ">';
                	    strHtml += '<i class="fa fa-user" style="color: #ffffff; font-size: 60px; "></i><br/><br/>';
                	    strHtml += strMiembro ;
                            strHtml += '<div style="float:left; width:100%; height:50px; border:0px solid #ccc; margin: 10px 0 0 0; padding: 3px; text-align: left; ">';
                            
                                var arrRecetas = arrItems[i].arrRecetas;
                                if(arrRecetas.length>0){
                   	                strHtml += "Última receta<br/><br/>";
                   	                strHtml += "<a href='https://sofmedi.com/exxmed/pdfs-recetas/"+ arrRecetas[0].strPdf +"' target='_blank' style='color: #445cab !important;'>"+ arrRecetas[0].datFecha +"</a>";
                                }
 
                	        strHtml += '</div>';
                	    strHtml += '</div>';
                
                	}
                	
                	divObjConArg.html(strHtml);
	
				}else{
					divObjConArg.html("<p align='center' style='margin-top:100px;'>No hay registros para esta consulta</p>");
				}
			}else{
				divObjConArg.html("<p align='center' style='margin-top:100px;'>Existe un error: "+ dataNew +"</p>");
			}
		});
		
	}else{
		alert("Todos los campos son requeridos");
	}
}

function getDataDashboard1(){
	console.log("getDataFamilia / getDataFamilia");

	if(1==1){
		
		$("#divDashboard1").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');
		$("#divDashboard2").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');

		var strFechas = $("#divDashboard").find("#txtFechaGral").val();

		var strUrl = "data/dataDashboard.php?method=getFamilia&strFechas="+ strFechas;
		
		/*var selectTipo = $("#divFiltrosDashboard").find("#selectTipo").val();
		if(selectTipo!="" && selectTipo!=null){
			strUrl += "&selectTipo="+ selectTipo;
		}*/
		
		var objJson = { method:'getfamilia', intUsuario: objUsuario.id };
		
		$.post(strUrl, objJson, function(dataNew){

			$("#divDashboard1").empty();
			$("#divDashboard2").empty();

			var data = $.parseJSON(dataNew);
			var arrItemsArg = data.Items;
			var arrItemsxDiaArg = data.ItemsxDia;

			if(arrItemsArg.length>0){
							
				var arrFieldsArg = [ 
					{name: 'strClave', type: 'string'}, {name: 'strSucursal', type: 'string'}
					,{name: 'pctPacientes', type: 'string'}, {name: 'intPacientes1', type: 'int'}, {name: 'intPacientes2', type: 'int'}
					,{name: 'pctSumas', type: 'string'}, {name: 'intSumas1', type: 'int'}, {name: 'intSumas2', type: 'int'}
				]; 

				var arrColumnsArg =  [
			      
				  { header: "Clave", width: 40, dataIndex: 'strClave', sortable: true,  align:'center',
					  renderer: function (value, metaDat, record) {
						var newValue = "";
						var strThisValue = value;
						//newValue += "<a href='javascript: InsEdiVerAli(1,3,"+ record.data["intProducto"] +");' style='font-size: 15px; color:#C60; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</a>";
						newValue += "<div style='font-size: 12px; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</div>";

						return newValue;
					}
				  }
				  
				  ,{ header: "Sucursal", width: 120, dataIndex: 'strSucursal', sortable: true }
			      ,{ header: "Factura Promedio", width: 120, dataIndex: 'pctPacientes', sortable: true, align: 'center'
					,renderer: function (value, metaDat, record) {
				  	  	var intSumas = record.data["intSumas1"];
				  	  	var intPacientes = record.data["intPacientes1"];

		                var newValue = intSumas / intPacientes;
		                newValue = "$ "+ addCommas(newValue.toFixed(2));
						return newValue;

					}
			      }
			      ,{ header: "% Pac + -", width: 70, dataIndex: 'pctPacientes', sortable: true, align: 'center' }
			      ,{ header: "Pac. "+ strAnioHoy, width: 70, dataIndex: 'intPacientes1', sortable: true, align: 'center' }
			      ,{ header: "Pac. "+ strAnioAnt, width: 70, dataIndex: 'intPacientes2', sortable: true, align: 'center' }
			      ,{ header: "% Ventas + -", width: 80, dataIndex: 'pctPacientes', sortable: true, align: 'center' }
			      ,{ header: "Ventas "+ strAnioHoy, width: 80, dataIndex: 'intSumas1', sortable: true, align: 'center'
					,renderer: function (value, metaDat, record) {
				  	  	
		                var newValue = "";
		                newValue = "$ "+ addCommas(value);
						
						return newValue;

					}

			      }
			      ,{ header: "Ventas "+ strAnioAnt, width: 80, dataIndex: 'intSumas2', sortable: true, align: 'center' 
					,renderer: function (value, metaDat, record) {
				  	  	
		                var newValue = "";
		                newValue = addCommas(value);
						return newValue;

					}
			      }
				  
				];
				
				setTimeout(function(){ console.log("linea 174"); drawChart(1, "divDashboard1", arrItemsxDiaArg); }, 1000);

				$("#divDashboard").find("#divDashboard1").css({"display":"block"});
				$("#divDashboard").find("#divDashboard1").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

				makeGridExtJs("divDashboard2", arrFieldsArg, arrColumnsArg, arrItemsArg, 150, 'Ventas');

				$("#divDashboard").find("#divDashboard2").css({"display":"block"});
				$("#divDashboard").find("#divDashboard2").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

			}else{

				$("#divDashboard1").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );
				$("#divDashboard2").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );

			}

		});

	}

}

function getDataDashboard2(){
	console.log("getDataDashboard2 / getDataDashboard2");

	if(1==1){
		
		$("#divDashboard3").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');
		$("#divDashboard4").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');

		var strFechas = $("#divDashboard").find("#txtFechaGral").val();

		var strUrl = "data/dataDashboard.php?method=getProduccion&strFechas="+ strFechas;
		
		var selectConvenio = $("#divFiltrosDashboard").find("#selectConvenio").val();
		if(selectConvenio!="" && selectConvenio!=null){
			strUrl += "&selectConvenio="+ selectConvenio;
		}

		$.post(strUrl, function(dataNew){

			$("#divDashboard3").empty();
			$("#divDashboard4").empty();

			var data = $.parseJSON(dataNew);
			var arrItemsArg = data.Items;
			var arrItemsxDiaArg = data.ItemsxDia;

			if(arrItemsArg.length>0){
				
				//console.log("getDataDashboard / arrItems.length: "+ arrItems.length);
			
				var arrFieldsArg = [ 
					{name: 'strClaEst', type: 'string'}, {name: 'strEstudio', type: 'string'}, 
					{name: 'pctEstudios', type: 'string'}, {name: 'intEstudios1', type: 'int'}, {name: 'intEstudios2', type: 'int'}
				]; 

				var arrColumnsArg =  [
			      
			      /*{ header: "Id", width: 35, dataIndex: 'intOrdenCompra', sortable: true }*/
			      { header: "", width: 35, dataIndex: 'strClaEst', sortable: true 
			  		,renderer: function (value, metaDat, record) {
			  			var strChkChecked = " ";
			  			
			  			var intEstudiosThis = record.data["intEstudios1"];

			  			//console.log("intEstudiosThis: "+ intEstudiosThis);
			  			if(intEstudiosThis>4){
							strChkChecked = " checked ";
						}			  			
						var newValue = "";
						newValue += "<div style='padding-left:2px; overflow:hidden; '>";
						newValue += "<input type='checkbox' id='chk_"+ value +"' "+ strChkChecked +" style='width:14px; height:14px;' class='clsChkEstudio' onclick='graficarEstudios()'/>";
						newValue += "</div>";

						return newValue;
					}
				  },

				  { header: "Clave", width: 56, dataIndex: 'strClaEst', sortable: true,  align:'center',
					  renderer: function (value, metaDat, record) {
						var newValue = "";
						var strThisValue = value;
						//newValue += "<a href='javascript: InsEdiVerAli(1,3,"+ record.data["intProducto"] +");' style='font-size: 15px; color:#C60; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</a>";
						newValue += "<div style='font-size: 12px; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</div>";

						return newValue;
					}
				  }
				  
				  ,{ header: "Estudio", width: 200, dataIndex: 'strEstudio', sortable: true }
			      ,{ header: "% + -", width: 70, dataIndex: 'pctEstudios', sortable: true, align: 'center' }
			      ,{ header: "Est. "+ strAnioHoy, width: 70, dataIndex: 'intEstudios1', sortable: true, align: 'center' }
			      ,{ header: "Est. "+ strAnioAnt, width: 70, dataIndex: 'intEstudios2', sortable: true, align: 'center' }				  

				];

				setTimeout(function(){ /*console.log("linea 269");*/ drawChart(4, "divDashboard3", arrItemsxDiaArg); }, 1000);

				$("#divDashboard").find("#divDashboard3").css({"display":"block"});
				$("#divDashboard").find("#divDashboard3").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

				makeGridExtJs("divDashboard4", arrFieldsArg, arrColumnsArg, arrItemsArg, null, 'Producción');
				
				$("#divDashboard").find("#divDashboard4").css({"display":"block"});
				$("#divDashboard").find("#divDashboard4").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				  	graficarEstudios();
				});

			}else{

				$("#divDashboard3").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );
				$("#divDashboard4").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );

			}

		});

	}

}

function graficarEstudios(objThis){
	var strMsg = "", strMsg2 = "", strItems = "", strUrl1 = "";

	if(objThis!=null){
		if(objThis.checked){
			$('.clsChkEstudio').each(function () {
				//console.log("CHECKBOX ", this, this.id);
				this.checked = true;
			});
		}else{
			$('.clsChkEstudio').each(function () {
				//console.log("CHECKBOX ", this, this.id);
				this.checked = false;
			});
		}
	}

	$('.clsChkEstudio').each(function () {
		//console.log("CHECKBOX ", this, this.id);
		var checked = this.checked;
		if(checked){
			var id = this.id.replace("chk_","");
			strItems += id +",";	
		}
	});
	if(strItems!=""){
		strItems = strItems.substring(0, strItems.length-1);
		strUrl1 += "&strPaquetes="+ strItems;
	}else{
		//strMsg = "Debe seleccionar al menos un estudio.";
		strMsg = "Para graficar estudios por día debe seleccionar al menos un estudio.";
		strMsg2 = "Para tabular estudios por día debe seleccionar al menos un estudio.";
	}
	
	console.log("graficarEstudios / strItems: "+ strItems);
	
	if(strMsg==""){

		$("#divDashboard4_1").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');
		$("#divDashboard4_2").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');

		var strFechas = $("#divDashboard").find("#txtFechaGral").val();

		var strUrl = "data/dataDashboard.php?method=getEstudiosProduccion&strFechas="+ strFechas;

		if(strItems!="" && strItems!=null){
			strUrl += "&strItems="+ strItems;
		}

		$.post(strUrl, function(dataNew){

			//$("#divDashboard4_1").empty();

			var data = $.parseJSON(dataNew);
			//var arrItemsArg = data.Items;
			var arrItemsxDiaArg = data.ItemsxDia;

			if(arrItemsxDiaArg.length>0){
				
				setTimeout(function(){ drawChart(6, "divDashboard4_1", arrItemsxDiaArg); }, 1000);

				$("#divDashboard").find("#divDashboard4_1").css({"display":"block"});
				$("#divDashboard").find("#divDashboard4_1").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

				var arrFieldsArg = [ ]; 

				var arrColumnsArg = [ ];
				
				var jsonObject0 = arrItemsxDiaArg[0];

				var keys = Object.keys(jsonObject0);
				var f = 1;
			    keys.forEach(function(key){
			        //console.log("key: "+ key);
			        //console.log("jsonObject0[key]: "+ jsonObject0[key]);
			        
		        	//data.addColumn('number', key);

		        	if(key=="DIA"){ 
						arrFieldsArg.push( {name: key, type: 'date'} );
						arrColumnsArg.push( { header: key, width: 120, dataIndex: key , sortable: true
							,renderer: function (value, metaDat, record) {
								var strThisValue = value.toString().substring(4,11);
								//console.log("strThisValue: "+ strThisValue);
								
								return strThisValue;

							}
						 } );

		        	}else{
						arrFieldsArg.push( {name: key, type: 'number'} );
						arrColumnsArg.push( { header: key, width: 80, dataIndex: key , sortable: true } );
					}
			    });

				makeGridExtJs("divDashboard4_2", arrFieldsArg, arrColumnsArg, arrItemsxDiaArg, null, 'Tabla de Estudios por Días');
					
				$("#divDashboard").find("#divDashboard4_2").css({"display":"block"});
				$("#divDashboard").find("#divDashboard4_2").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

			}else{

				$("#divDashboard4_1").html( "<h2 style='text-align:center; margin:120px 0 120px 0;'>No se encontraron registros para esta consulta.</h2>" );
				$("#divDashboard4_2").html( "<h2 style='text-align:center; margin:120px 0 120px 0;'>No se encontraron registros para esta consulta.</h2>" );

			}

		});	

	}else{
		//alert(strMsg);
		$("#divDashboard4_1").html("<h2 style='text-align:center; margin:120px 0 120px 0;'>"+ strMsg +"</h2>");
		$("#divDashboard4_2").html("<h2 style='text-align:center; margin:120px 0 120px 0;'>"+ strMsg2 +"</h2>");
	}
}

function getDataDashboard3(){
	console.log("getDataDashboard3 / getDataDashboard3");
	//return;

	if(1==1){
		
		$("#divDashboard5").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');

		var strFechas = $("#divDashboard").find("#txtFechaGral").val();

		var strUrl = "data/dataDashboard.php?method=getCotizaciones&strFechas="+ strFechas;
		
		$.post(strUrl, function(dataNew){

			//$("#divDashboard5").empty();

			var data = $.parseJSON(dataNew);
			var arrItemsArg = data.Items;

			var arrItemsxDiaArg = data.ItemsxDia;

			if(arrItemsArg.length>0){
							
				setTimeout(function(){ console.log("linea 174"); drawChart(5, "divDashboard5", arrItemsArg); }, 1000);
				$("#divDashboard").find("#divDashboard5").css({"display":"block"});

				$("#divDashboard").find("#divDashboard5").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});
				
				/* ------------------- */

				var arrFieldsArg = [ 
					{name: 'strDia', type: 'string'}, {name: 'strOrigen', type: 'string'}, {name: 'intCotizaciones', type: 'int'}
				]; 

				var arrColumnsArg =  [
			      		      
				  { header: "Día", width: 80, dataIndex: 'strDia', sortable: true }
				  ,{ header: "Origen", width: 120, dataIndex: 'strOrigen', sortable: true }
			      ,{ header: "Cotizaciones", width: 100, dataIndex: 'intCotizaciones', sortable: true, align: 'center' }
				  
				];

				makeGridExtJs("divDashboard6", arrFieldsArg, arrColumnsArg, arrItemsxDiaArg, 350, 'Cotizaciones PRUEBAS');
				$("#divDashboard").find("#divDashboard6").css({"display":"block"});

				$("#divDashboard").find("#divDashboard6").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

			}else{

				//$("#divDashboard5").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );
				$("#divDashboard5").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>Gráfica de cotizaciones generadas según origen.<br/><br/>No se encontraron registros para esta consulta.</h2>" );

			}

		});

	}

}


function getDataDashboard4(){
	console.log("getDataDashboard4 / getDataDashboard4");
	return;

	if(1==1){
		
		$("#divDashboard4").html('<div style="width:100%; text-align:center;"><img src="images/loading1.gif" style="margin:50px auto 50px auto; width:60px;"/></div>');

		var strFechas = $("#divDashboard").find("#txtFechaGral").val();

		var strUrl = "data/dataDashboard.php?method=getVentas&strFechas="+ strFechas;
		
		var selectTipo = $("#divFiltrosDashboard").find("#selectTipo").val();
		if(selectTipo!="" && selectTipo!=null){
			strUrl += "&selectTipo="+ selectTipo;
		}
		
		var selectSexo = $("#divFiltrosDashboard").find("#selectSexo").val();
		if(selectSexo!="" && selectSexo!=null){
			strUrl += "&selectSexo="+ selectSexo;
		}

		var txtEdadIni = $("#divFiltrosDashboard").find("#txtEdadIni").val();
		if(txtEdadIni!="" && txtEdadIni!=null){
			strUrl += "&txtEdadIni="+ txtEdadIni;
		}
		var txtEdadFin = $("#divFiltrosDashboard").find("#txtEdadFin").val();
		if(txtEdadFin!="" && txtEdadFin!=null){
			strUrl += "&txtEdadFin="+ txtEdadFin;
		}

		var txtHoraIni = $("#divFiltrosDashboard").find("#txtHoraIni").val();
		if(txtHoraIni!="" && txtHoraIni!=null){
			strUrl += "&txtHoraIni="+ txtHoraIni;
		}
		var txtHoraFin = $("#divFiltrosDashboard").find("#txtHoraFin").val();
		if(txtHoraFin!="" && txtHoraFin!=null){
			strUrl += "&txtHoraFin="+ txtHoraFin;
		}

		$.post(strUrl, function(dataNew){

			$("#divDashboard4").empty();

			var data = $.parseJSON(dataNew);
			var arrItemsArg = data.Items;
			var arrItemsxDiaArg = data.ItemsxDia;

			if(arrItemsArg.length>0){

				$("#divDashboard4").html('');		
			
				var arrFieldsArg = [ 
					{name: 'strClave', type: 'string'}, {name: 'strSucursal', type: 'string'}
					,{name: 'pctPacientes', type: 'string'}, {name: 'intPacientes1', type: 'int'}, {name: 'intPacientes2', type: 'int'}
					,{name: 'pctSumas', type: 'string'}, {name: 'intSumas1', type: 'int'}, {name: 'intSumas2', type: 'int'}
				]; 

				var arrColumnsArg =  [
			      
			      /*{ header: "Id", width: 35, dataIndex: 'intOrdenCompra', sortable: true }*/
			      
				  { header: "Clave", width: 40, dataIndex: 'strClave', sortable: true,  align:'center',
					  renderer: function (value, metaDat, record) {
						var newValue = "";
						var strThisValue = value;
						//newValue += "<a href='javascript: InsEdiVerAli(1,3,"+ record.data["intProducto"] +");' style='font-size: 15px; color:#C60; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</a>";
						newValue += "<div style='font-size: 12px; padding-left:2px; overflow:hidden; '>"+ strThisValue +"</div>";

						return newValue;
					}
				  }
				  
				  ,{ header: "Sucursal", width: 120, dataIndex: 'strSucursal', sortable: true }
			      ,{ header: "% Pac + -", width: 70, dataIndex: 'pctPacientes', sortable: true, align: 'center' }
			      ,{ header: "Pac. "+ strAnioHoy, width: 70, dataIndex: 'intPacientes1', sortable: true, align: 'center' }
			      ,{ header: "Pac. "+ strAnioAnt, width: 70, dataIndex: 'intPacientes2', sortable: true, align: 'center' }
			      ,{ header: "% Ventas + -", width: 80, dataIndex: 'pctPacientes', sortable: true, align: 'center' }
			      ,{ header: "Ventas "+ strAnioHoy, width: 80, dataIndex: 'intSumas1', sortable: true, align: 'center'
					,renderer: function (value, metaDat, record) {
				  	  	
		                var newValue = "";
		                /*if(value<5){
		              		newValue += "<div style='padding:0 3px 0 3px; font-weight:bold; font-size:12px; background-color:red; color: white; text-align:center; '>"+ value +" días</div>";
		                }else if(value>=5 && value<10){
		              		newValue += "<div style='padding:0 3px 0 3px; font-weight:bold; font-size:12px; background-color:yellow; text-align:center; '>"+ value +" días</div>";
		                }else if(value>=10){
		              		newValue += "<div style='padding:0 3px 0 3px; font-weight:bold; font-size:12px; background-color:green; color: white; text-align:center; '>"+ value +" días</div>";
		                }*/
		                newValue = addCommas(value);
						
						return newValue;

					}

			      }
			      ,{ header: "Ventas "+ strAnioAnt, width: 80, dataIndex: 'intSumas2', sortable: true, align: 'center' 
					,renderer: function (value, metaDat, record) {
				  	  	
		                var newValue = "";
		                newValue = addCommas(value);
						return newValue;

					}
			      }
				  
				];

				//makeGridExtJs("divDashboard1", arrFieldsArg, arrColumnsArg, arrItemsArg, 150, 'Ventas');
				
				setTimeout(function(){ console.log("linea 174"); drawChart(1, "divDashboard4", arrItemsxDiaArg); }, 1000);

				$("#divDashboard").find("#divDashboard4").css({"display":"block"});

				$("#divDashboard").find("#divDashboard4").animate({
				    opacity: 1,
				    left: "+=50"
				  }, 500, function() {
				});

			}else{

				$("#divDashboard4").html( "<h2 style='text-align:center; margin:200px 0 200px 0;'>No se encontraron registros para esta consulta.</h2>" );

			}

		});

	}

}



function makeGridExtJs(strDivContArg, arrFieldsArg, arrColsArg, arrItemsArg, heightDivArg, strTitleArg){
	var heightDiv = "", GridStore = "";

	//var objDiv = $( "#"+ strDivContArg ); 
	//heightDiv = objDiv.css("height");
	//heightDiv = $(window).height()-100;
	if(heightDivArg==null){
		//heightDivArg = $(window).height()-100;
		heightDivArg = parseInt( $( "#"+ strDivContArg ).css("height").replace("px","") );
	}
	console.log("makeGridExtJs / heightDivArg: "+ heightDivArg);
	
	//if(heightDiv!=null){

		//heightDiv = parseInt( heightDiv.toString().replace("px","") ) ;
		
		GridStore = new Ext.data.JsonStore({
		  root: 'Items',
		  fields: arrFieldsArg,
		  data: { Items: arrItemsArg }
		});   
								
		var gridN = new Ext.grid.GridPanel({
			title: strTitleArg,
			frame: false,
			width:'100%',
			height: heightDivArg,
			fbar : [ new Ext.Toolbar.TextItem('<font size=2>'+ arrItemsArg.length + ' registros</font>')],
			store: GridStore,
			columns: arrColsArg
			,collapsed:true
		});

		//if(strTitleArg!==null){
		//if(strTitleArg!==''){
		//	gridN.setTitle(strTitleArg);
		//}	

		//console.log("makeGridExtJs / strTitleArg: " + strTitleArg );

		$( "#"+ strDivContArg ).html("");
		gridN.render( document.getElementById(strDivContArg) ); 
		
		//setTimeout(function(){ alert("heyy"); gridN.updateBox( document.getElementById(strDivContArg) ) ; },500);
		setTimeout(function(){ gridN.toggleCollapse( true ); },50);
			
	//}
}

/*
function makeGrid( i, strClaveEmpresaArg, strEmpresaArg, arrEstudiosArg, bInicio ){
	//console.log( "makeGrid / bInicio: "+ bInicio );

	var strHtmlGrid = "", sum1 = 0, sum2 = 0;
	var intItems = arrEstudiosArg.length;

	var strHtmlTable = "";

	strHtmlTable += "<div id='divTitle' style='padding:10px 0px 10px 3px;'>"+ strEmpresaArg +"</div>";				

	strHtmlTable += "<div id='divData"+ strClaveEmpresaArg +"' class='clsDivData'>";

	    strHtmlTable += "<table id='tblData_"+ i +"' class='clsTblProGral'  border='1' style=''>"; 
	     strHtmlTable += "<tbody id='tbodyData_"+ i +"'>"; 

		 for (var j=0; j<arrEstudiosArg.length; j++) { ///recorre registros

		   if(j==0){

			   strHtmlTable += "<tr id='trData_"+ j +"'>";
			   for (var a=0; a<arrColsGral.length; a++) {

			   		var strTitle = arrColsGral[a].title ;
			   		var strWidth = arrColsGral[a].width ;
			   		var strClass = arrColsGral[a].class_header ;
			   		var strCss = arrColsGral[a].css_header ;

			   		var strCellClass = "";
			   		if(a==2){
			   			strCellClass = "clsCellDown";
			   		}
			   		if(!bInicio){
			   			strCellClass = "";
			   		}

					strHtmlTable += "<th id='cellHeader_"+ i +"_"+ a +"' class='"+ strClass +"' style='width:"+ strWidth +"; "+ strCss +"'>";
						strHtmlTable += "<a id='link_"+ i +"_"+ a +"' href='javascript: ordenarArray(\""+ strClaveEmpresaArg +"\","+ i +","+ a +", "+ arrColsGral.length +");' class='clsCellA "+ strCellClass +"'>"+ strTitle +"</a>"; 
					strHtmlTable += "</th>"; 

			   }
			   strHtmlTable += "</tr>";

		   }

		   var strClaEst = arrEstudiosArg[j].strClaEst;
		   var strEstudio = arrEstudiosArg[j].strEstudio;
		   
		   var pctEstudios = arrEstudiosArg[j].pctEstudios;
		   //if( isNumber(pctEstudios) && pctEstudios!="" ){
		   if( pctEstudios!="" ){
 		   	pctEstudios = parseFloat(pctEstudios).toFixed(2);
		   }

		   var intEstudios = parseInt(arrEstudiosArg[j].intEstudios);
		   var intEstudios0 = parseInt(arrEstudiosArg[j].intEstudios0);

		   sum1 += parseInt(intEstudios);
		   sum2 += parseInt(intEstudios0);

		   strHtmlTable += "<tr id='trData_"+ j +"'>";

		   for (var a=0; a<arrColsGral.length; a++) {

		   		var strWidth = arrColsGral[a].width ;
		   		var strClass = arrColsGral[a].class_cell ;
		   		var strCss = arrColsGral[a].css_cell ;

		   		var strColor = "gray";
				if(a==2){ 
					if(isNumber(pctEstudios)){
						if(pctEstudios>0){
							strColor = "green";
						}else{
							strColor = "red";
						}

						pctEstudios = addCommas(pctEstudios) +"%";

					}
				};

				strHtmlTable += "<td id='divCell-"+ a +"' class='"+ strClass +"' style='width:"+ strWidth +"; "+ strCss +" color:"+ strColor +"; '>";
					
					if(a==0){ strHtmlTable += strClaEst; };
					if(a==1){ strHtmlTable += strEstudio; };
					
					if(a==2){ strHtmlTable += pctEstudios ; };
					
					if(a==3){ strHtmlTable += addCommas(intEstudios); };
					if(a==4){ strHtmlTable += addCommas(intEstudios0); };

				strHtmlTable += "</td>"; 
		   
		   }
		   
		   strHtmlTable += "</tr>"; 

		 }

		 strHtmlTable += "</tbody>"; //CIERRA tBody

		 /////////////////// FOOT    FOOT    FOOT    FOOT    FOOT    FOOT    FOOT    FOOT    FOOT 

		 strHtmlTable += "<tfoot id='trFoot_"+ j +"'>";
			   strHtmlTable += "<tr style='background-color:#a3a4a5;'>";
					strHtmlTable += "<td id='divCellFoot-0' class='clsCellFoot' style='' colspan='2'>";
						strHtmlTable += arrEstudiosArg.length +" estudios";
			   		strHtmlTable += "</td>"; 

			   		var strColor = "black";
		   			var pct1 = ((sum1 * 100) / sum2 ) - 100;
		   			
					if(isNumber(pct1)){
						if(pct1>0){
							strColor = "green";
						}else{
							strColor = "red";
						}

						pct1 = addCommas(pct1.toFixed(2)) +"%";

					}

					strHtmlTable += "<td id='divCellFoot-1' class='clsCellFoot' style='text-align:center; color:"+ strColor +";' >";
						if(pct1!="Infinity" && pct1!="0.00%"){
							strHtmlTable += pct1;
						}
			   		strHtmlTable += "</td>"; 					

					strHtmlTable += "<td id='divCellFoot-1' class='clsCellFoot' style='text-align:center;' >";
						strHtmlTable += addCommas(sum1); 
			   		strHtmlTable += "</td>"; 					

			   		strHtmlTable += "<td id='divCellFoot-1' class='clsCellFoot' style='text-align:center;' >";
						strHtmlTable += addCommas(sum2);
			   		strHtmlTable += "</td>"; 

			   strHtmlTable += "</tr>"; 
		   strHtmlTable += "</tfoot>"; 

		strHtmlTable += "</table>"; //CIERRA divTABLE

	strHtmlTable += "</div>"; //CIERRA divDATA

	return strHtmlTable;
	
}
*/
function isNumber(n) {
     return !isNaN(parseFloat(n)) && isFinite(n);
}

/*
function makeArrayJson(intIArg){
	//var arrJson = [{strClaEst: "PITS", strEstudio: "PERFIL ITS 1 (INFECCIONES TRANSMITIDAS SEXUALMENTE)", intEstudios: 1},{}];
	//var strTabla = "tblData_"+ intIArg;
	var arrJson = [];

	var i = 0;
	$("#tbodyData_"+ intIArg).children().each(function(){

		if(i>0){
			var kid = $(this);
			var kidId = kid.attr('id');
			//console.log("kidId: "+ kidId);

			try {

			    //if(kidId.indexOf("RENGLON")>0){   /// VERIFICO QUE SEA RENGLON
					var strClaEstV = kid.children()[0].innerHTML;
					var strEstudioV = kid.children()[1].innerHTML;
					
					var pctEstudiosV = kid.children()[2].innerHTML;
					
					var intEstudiosV = kid.children()[3].innerHTML;
					var intEstudiosV0 = kid.children()[4].innerHTML;

					var objJson = {strClaEst: strClaEstV , strEstudio: strEstudioV , pctEstudios:  (pctEstudiosV), intEstudios:  parseInt(intEstudiosV), intEstudios0:  parseInt(intEstudiosV0) };					
					arrJson.push(objJson);

				//}	

			}catch(err) {

				  console.log(err.message);

			}
		}

		i++;

	});

	return arrJson;

}

var strOrder = "desc";
function ordenarArray(strClaveEmpresaArg, intIArg, intCampoArg, intCamposArg){
	console.log("ordenarArray / strClaveEmpresaArg: "+ strClaveEmpresaArg +" / intIArg: "+ intIArg +" / intCampoArg: "+ intCampoArg +" / strOrder: "+ strOrder);

	for (var i=0; i<arrItemsGral.length; i++) {

		var strClaveEmpresa = arrItemsGral[i].strClaveEmpresa ;

		if(strClaveEmpresa==strClaveEmpresaArg){

			var strEmpresa = arrItemsGral[i].strEmpresa ;

			var arrEstudios = makeArrayJson(intIArg);

			var idLink = 'link_'+ intIArg +'_'+ intCampoArg;
			console.log("idLink: "+ idLink);

			if(strOrder=="desc"){
				strOrder = "asc";
			}else if(strOrder=="asc"){
				strOrder = "desc";
			}

			intCampoOrdenar = intCampoArg;
			
			//console.log("antes de sort / strOrder: "+ strOrder   );
			arrEstudios.sort(sort);

			//console.log("\n \n __________    2    ___________");
			//console.log(arrEstudios);	

			$("#divDashboard2").find("#divCon_"+ strClaveEmpresaArg ).html( makeGrid(intIArg, strClaveEmpresaArg, strEmpresa, arrEstudios, false ) );

			//LO PONGO AL REVES POR QUE el strOrder lo cambie en las lineas arriba
			if(strOrder=="asc"){
				$("#"+idLink).addClass("clsCellUp");
			}else if(strOrder=="desc"){
				$("#"+idLink).addClass("clsCellDown");
			}
		}

	}
}

var intCampoOrdenar = "";
function sort(a,b){

	//console.log("sort / intCampoOrdenar: "+ intCampoOrdenar +" / strOrder: "+ strOrder   );

	if(intCampoOrdenar==0){
		a = a.strClaEst; b = b.strClaEst;
	}else if(intCampoOrdenar==1){
		a = a.strEstudio; b = b.strEstudio;
	
	}else if(intCampoOrdenar==2){
		a = a.pctEstudios; b = b.pctEstudios;
	
	}else if(intCampoOrdenar==3){
		a = a.intEstudios; b = b.intEstudios;
	}else if(intCampoOrdenar==4){
		a = a.intEstudios0; b = b.intEstudios0;
	}
	
	//console.log("sort1 / a: "+ a +" / b: "+ b );

	if(strOrder=="desc"){
		//console.log("ENTRA DESC");
		if(a < b) {
			return 1;
		} else if (a > b) {
			return -1;
		}
	}else if(strOrder=="asc"){
		//console.log("ENTRA ASC");

		if(a > b) {
			return 1;
		} else if (a < b) {
			return -1;
		}
	}

	return 0;
}
*/
function abrirDialogVerPdfs(){
	var strUrl = "verificarpdfs.php";
	$.post(strUrl, function(dataNew){

		$("#dialog-verificar-pdfs").empty();
		$("#dialog-verificar-pdfs").html(dataNew);

		$( "#dialog-verificar-pdfs" ).dialog("open");

	});

}

function setBgTr(i, strBackground){
	var strBg = $("#tr_"+i).css("background-color");
	//console.log("setBgTr / i: "+ i + " / strBg: "+ strBg);

	//if(strBg==="rgb(255, 165, 0)"){
	if(strBg==="orange"){
		//$("#tr_"+i).css("background-color", "rgb(127, 255, 0)");			
		$("#tr_"+i).css("background-color", strBackground);			
	}else{
		$("#tr_"+i).css("background-color","orange");			
	}
}

//var materialOptions;

function drawChart(intCaseArg, strDivArg, arrItemsxDiaArg) {
    console.log("drawChart / intCaseArg: "+ intCaseArg);
    
    var data = new google.visualization.DataTable();
    
    var strTitle ="", strSubtitle = "", strDiv = "";
    
    if(intCaseArg==1){
        
        strTitle ="Ventas";
        strSubtitle = "";

	    var objSeries = {
	          // Gives each series an axis name that matches the Y-axis below.
	          0: {axis: 'Ventas'},
	          1: {axis: 'Pacientes'}
	    };
	    var objAxes = {
	      // Adds labels to each axis; they don't have to match the axis names.
	      y: {
	        Ventas: {label: 'Ventas', format: 'decimal'},
	        Pacientes: {label: 'Pacientes', format: 'number'}
	      }
	    };
		

        data.addColumn('string', 'Días');
        data.addColumn('number', 'Ventas');
        data.addColumn('number', 'Pacientes');      

		if(arrItemsxDiaArg.length>0){
			
			var arrData = [];
			for(var i=0; i<arrItemsxDiaArg.length; i++){
				//arrData.push( [arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].intSumas1] );
				arrData.push( [arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].intSumas1, arrItemsxDiaArg[i].intPacientes1] );
			}

			data.addRows(arrData);

		} 
        
    }else if(intCaseArg==2){
        
        /*
        strTitle ="Sucursal Alfonso Reyes";
        strSubtitle = "";
        //strDiv = 'divDashboard3';
        
        data.addColumn('number', '2021');
        data.addColumn('number', '2020');

        data.addRows([
        [1,  4.2,  4.2],
        [2,  4.8,  5.6],
        [3,  8.4,  9.8],
        [4,  4.7,  3.2],
        [5, 12.8,  13.5],
        [6,  16.9,  15.1],
        [7,  29.2,  25.3],
        [8,  12.3,  15.8],
        [9,  13.6,  14.2],
        [10,  17.6,  19.5],
        [11,  18.8,  14.9]
        ]);
		*/
    }else if(intCaseArg==3){
        /*
        strTitle ="Departamentos";
        strSubtitle = "";
        strDiv = 'divDashboard3';
        
        data.addColumn('number', 'Lacteos');
        data.addColumn('number', 'Carnes Frías');
        data.addColumn('number', 'Abarrotes');
        data.addColumn('number', 'Carnes Rojas');
        data.addColumn('number', 'Bebidas');

        data.addRows([
        [1,  26000,  54504, 25454, 16465, 27245],
        [2,  48488,  65454, 21214, 24451, 32453],
        [3,  84545,  35455, 38845, 35555, 47151],
        [4,  74547,  39852, 48446, 41354, 57841],
        [5,  84545,  55156, 54540, 57841, 64415],
        [6,  96874,  58481, 64654, 67415, 71344],
        [7,  89254,  65514, 54484, 74513, 68878],
        [8,  92545,  75584, 67156, 64122, 81345]
        ]);
        */
    }else if(intCaseArg==4){
        
        strTitle ="Producción";
        strSubtitle = "";

	    var objSeries = {
	          // Gives each series an axis name that matches the Y-axis below.
	          0: {axis: 'Estudios'}
	          /*,1: {axis: 'Pacientes'}*/
	    };
	    var objAxes = {
	      // Adds labels to each axis; they don't have to match the axis names.
	      y: {
	        Estudios: {label: 'Estudios', format: 'decimal'}
	        /*,Pacientes: {label: 'Pacientes', format: 'number'}*/
	      }
	    };

        data.addColumn('string', 'Días');
        data.addColumn('number', 'Estudios');
        //data.addColumn('number', 'Pacientes');      

		if(arrItemsxDiaArg.length>0){
			
			var arrData = [];
			for(var i=0; i<arrItemsxDiaArg.length; i++){
				//arrData.push( [arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].intSumas1] );
				arrData.push( [arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].intEstudios] );
			}

			data.addRows(arrData);

		} 

	}else if(intCaseArg==5){
        
        strTitle ="Cotizaciones PRUEBAS";
        strSubtitle = "";

	    var objSeries = {
	          // Gives each series an axis name that matches the Y-axis below.
	          0: {axis: 'Cotizaciones'}
	          /*,1: {axis: 'Pacientes'}*/
	    };
	    var objAxes = {
	      // Adds labels to each axis; they don't have to match the axis names.
	      y: {
	        Estudios: {label: 'Cotizaciones', format: 'number'}
	        /*,Pacientes: {label: 'Pacientes', format: 'number'}*/
	      }
	    };

        data.addColumn('string', 'Días');
        //data.addColumn('string', 'Origen');
        data.addColumn('number', 'Cotizaciones');

		if(arrItemsxDiaArg.length>0){
			
			var arrData = [];
			for(var i=0; i<arrItemsxDiaArg.length; i++){
				//arrData.push( [ arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].strOrigen, arrItemsxDiaArg[i].intCotizaciones ] );
				arrData.push( [ arrItemsxDiaArg[i].strDia, arrItemsxDiaArg[i].intCotizaciones ] );
			}

			data.addRows(arrData);

		} 
	
	}else if(intCaseArg==6){
        
        console.log("ENTRO drawChart / intCaseArg 6");
        //console.log("arrItemsxDiaArg", arrItemsxDiaArg);

        strTitle ="Estudios por día";
        strSubtitle = "";

	    /*var objSeries = {
	          // Gives each series an axis name that matches the Y-axis below.
	          0: {axis: 'Estudios'}
	          //,1: {axis: 'Pacientes'}
	    };
	    var objAxes = {
	      // Adds labels to each axis; they don't have to match the axis names.
	      y: {
	        Estudios: {label: 'Estudios', format: 'decimal'}
	        //,Pacientes: {label: 'Pacientes', format: 'number'}
	      }
	    };*/

        /*
        data.addColumn('string', 'Días');
        data.addColumn('string', 'Clave');
        data.addColumn('number', 'Estudios');
        */
        var jsonObject0 = arrItemsxDiaArg[0];
        var h = 0;

		var keys = Object.keys(jsonObject0);
	    keys.forEach(function(key){
	        //console.log("key: "+ key);
	        //console.log("jsonObject0[key]: "+ jsonObject0[key]);
	        
	        if(h==0){
        		data.addColumn('string', key);
		    }else{
        		data.addColumn('number', key);
		    }

	        h++;
	    });

        //data.addColumn('number', 'Pacientes');      

		if(arrItemsxDiaArg.length>0){
			
			var arrData = [];
			for(var i=0; i<arrItemsxDiaArg.length; i++){
				
				var jsonObjectN = arrItemsxDiaArg[i];

				var arrObj = [];
				
				var keys = Object.keys(jsonObjectN);
				keys.forEach(function(key){
			        var objValor = jsonObjectN[key];

			        //console.log("2 key: "+ key +" / objValor: "+ objValor);
			        arrObj.push( objValor );

			    });

				arrData.push( arrObj );

			}

			data.addRows(arrData);

		} 

    }
    
    var intWidthWindow = $( window ).width(), legendPosition = "top", intHeight = 280;
    if(intWidthWindow<500){
    	legendPosition = "none";
    	intHeight = 220;
    	$( "#"+ strDivArg ).css("height",intHeight+50);
    }

    //var heightDiv = parseInt($( "#divVentasGrid1" ).css("height").toString().replace("px",""))-10;
    var intWidth = parseInt($( "#"+ strDivArg ).css("width").toString().replace("px","")) - 10;
    //console.log("\n\n intWidth: "+ intWidth +" / intWidthWindow: "+ intWidthWindow +" / intCaseArg: "+ intCaseArg);
    
    /*
    var options = {
        legend: { position: legendPosition, alignment: 'start', format: 'decimal'}, / *, maxLines: '6'* /
        / *chart: {
          title: strTitle,
          subtitle: strSubtitle
        },
        titleTextStyle: {bold: true, color: 'black', fontSize: 24, fontName: 'Arial'},
        * /
    	
        chartArea:{left:0, top:0, width:"100%"},
        curveType: 'function',
        width: intWidth,
        height: intHeight
        / * ,axes: {
          x: {
            0: {side: 'bottom'}
          }
          ,y: {
            0: {side: 'bottom'}
          }
          ,format: '$0.00'
        } * /
        // * ,vaxis: {format:'$0.00'}
        ,haxis: {format:'$0.00'}* /
       	,series: {
		  0:{color: 'blue', visibleInLegend: true, pointShape:'circle', pointSize:10}
		  ,1:{color: 'red', visibleInLegend: true}
		  // *,{color: 'red', visibleInLegend: true} * /
		}
    };
    */

	var arrColors = ['#CD5C5C','green','#FF0000','gray','black','#FFA07A','orange','purple','#808000','brown','gold','#008000','#000080','#FF00FF','#800000','#C0C0C0','#008080','#00FF00','#f34e4e','#11d61b'];

    /*var objSeries = {
          // Gives each series an axis name that matches the Y-axis below.
          0: {axis: 'Ventas'},
          1: {axis: 'Pacientes'}
    };
    var objAxes = {
      // Adds labels to each axis; they don't have to match the axis names.
      y: {
        Ventas: {label: 'Ventas', format: 'decimal'},
        Pacientes: {label: 'Pacientes', format: 'number'}
      }
    };*/

    var materialOptions = {
        legend: { position: legendPosition, alignment: 'start', format: 'decimal'}, /*, maxLines: '6'*/
        chart: {
          title: '' /*Ventas y Pacientes*/
        },
        width: intWidth,
        height: intHeight,
        colors: arrColors,
        series: objSeries,
        axes: objAxes,
        vAxis: {format: 'decimal'}

      };

    var objDiv = document.getElementById(strDivArg);
    
    var chart = new google.charts.Line(objDiv);
    chart.draw(data, google.charts.Line.convertOptions(materialOptions /*options*/));


    var strDivHeaderChart = "<div style='width:100%; height:26px; margin-bottom:20px; background: #e3e3e3; border: 1px solid #dfdcdc; border-radius: 4px; padding:5px; box-sizing:border-box; '>";
    strDivHeaderChart += "<div style='width:40%; float:left; font-weight: bold; color: black; font-size: 11px; font-family: tahoma,arial,verdana,sans-serif;'>"+ strTitle +"</div>";
   
    var strChk1 = "hideVentas_"+ intCaseArg , strChk2 = "hidePacientes_"+ intCaseArg ;
    strDivHeaderChart += "<div style='width:60%; float:right; text-align:right;'>";
    
    //strDivHeaderChart += "<input type='button' value='Ver datos' style='padding:0 5px 0 5px; margin:0 5px 0 0;'/>";
    if(intCaseArg==1){
    	strDivHeaderChart += "<input id='"+ strChk1 +"' type='checkbox' style='padding:0 5px 0 5px; margin:0 5px 0 0;' checked/><label id='lblOcuVen_"+ intCaseArg +"' for='"+ strChk1 +"' style='vertical-align: top;'>Ventas</label>&nbsp;&nbsp;&nbsp;";
    	strDivHeaderChart += "<input id='"+ strChk2 +"' type='checkbox' style='padding:0 5px 0 5px; margin:0 5px 0 0;' checked/><label id='lblOcuPac_"+ intCaseArg +"' for='"+ strChk2 +"' style='vertical-align: top;'>Pacientes</label></div>";
    }

    strDivHeaderChart += "</div>";
    $("#"+ strDivArg).prepend(strDivHeaderChart);
    

    if(intCaseArg==1){

    	var strBtnVen = "hideVentas_"+ intCaseArg, lblOcuVen = "lblOcuVen_"+ intCaseArg;
	    var hideVen = document.getElementById(strBtnVen);

		hideVen.onclick = function(){
		  //var strValBtnVen = $("#"+ strBtnVen).val();
		  var strChk1Checked = $("#"+ strChk1).attr("checked");
		  var strChk2Checked = $("#"+ strChk2).attr("checked");
		  //console.log("1 strChk1Checked: "+ strChk1Checked +" / strChk2Checked: "+ strChk2Checked);

	      view = new google.visualization.DataView(data);

		  if(strChk1Checked && strChk2Checked){
   	  	    view.setColumns([0,1,2]);
		  }else if(strChk1Checked && !strChk2Checked){
	  	    view.setColumns([0,1]);
		  }else if(!strChk1Checked && strChk2Checked){
	  	    view.setColumns([0,2]);
		  }
	      
	      chart.draw(view, materialOptions /*options*/);
		}
		
    	var strBtnPac = "hidePacientes_"+ intCaseArg, lblOcuPac = "lblOcuPac_"+ intCaseArg;
		var hidePac = document.getElementById(strBtnPac);

	    hidePac.onclick = function(){
		  var strChk1Checked = $("#"+ strChk1).attr("checked");
		  var strChk2Checked = $("#"+ strChk2).attr("checked");
		  console.log("2 strChk1Checked: "+ strChk1Checked +" / strChk2Checked: "+ strChk2Checked);

	      view = new google.visualization.DataView(data);
		  
		  if(strChk1Checked && strChk2Checked){
   	  	    view.setColumns([0,1,2]);
		  }else if(strChk1Checked && !strChk2Checked){
	  	    view.setColumns([0,1]);
		  }else if(!strChk1Checked && strChk2Checked){
	  	    view.setColumns([0,2]);
		  }
	
		  chart.draw(view, materialOptions /*options*/);
	    }

	}

}

/*
function cargarDatosCli(){
	var strUrl1 = "data/catClientes.php?method=consultar";
	strUrl1 += "&intEmpresa="+ objUsuario.empresa;
	strUrl1 += "&rnd="+ Math.random();

	console.log(strUrl1);
	
	$.post(strUrl1, function(dataNew){
		//console.log(dataNew);

		var data = $.parseJSON(dataNew);
		var arrItems = data.Items;

		if(arrItems.length>0){
			var strNombre = arrItems[0].CON_DES;
			//var strLogin = arrItems[0].strLogin;
			var strPwd = arrItems[0].CON_PASS;
		
			$("#div1").find("#txtUsuario").val(strNombre);
			$("#div1").find("#txtContrasena").val(strPwd);
			$("#div1").find("#txtReContrasena").val(strPwd);
		}

	});

}

function actContra(){
	
	var strMsg = "";

	var intMode = 4;
	var strContrasena = $("#div1").find("#txtContrasena").val();
	if(strContrasena==""){ strMsg += "Falta agregar la contraseña.\n"; }

	var strReContrasena = $("#div1").find("#txtReContrasena").val();
	if(strReContrasena==""){ 
		strMsg += "Falta confirmar la contraseña.\n"; 
	}else{
		if(strContrasena!==strReContrasena){
			strMsg += "Las contraseñas no coinciden.\n"; 
		}
	}

	if(strMsg==""){
		
		var strUrl1 = "data/catClientes.php?method=abc&intMode="+ intMode;
		strUrl1 += "&intEmpresa="+ objUsuario.empresa;
		strUrl1 += "&strContrasena="+ strContrasena;
		strUrl1 += "&rnd="+ Math.random();

		console.log(strUrl1);
		
		$.get(strUrl1, function(dataNew){
			//console.log(dataNew);

			var data = $.parseJSON(dataNew);
			
			//alert(data.exito);
			if(data.exito=="si"){
			
				showNoti("Contraseña actualizada con éxito!", "#17d1ee", "#000000");
				
			}else{
				alert("Error al actualizar la contraseña. Favor de escribir a soporte@pgmlab.com");
			}
		
		});

	}else{
		alert(strMsg);
	}
}
*/

