//BUSQUEDA DE TABMONVIS
var contenedorTABMONVIS = null;
var panelTABMONVIS = null, panelTABCATRUT = null;
var GridStoreTABMONVIS = null, gridEjercicios = null;
var strIdConsultaGral = "";

function TABMONVIS_Constructor(){
	
	strEjercicioForMsg = "";
		
	idTab = 'TABMONVIS';

	var txtBoton = "";

	var sHeight = '80%';
	var sHeightContenedor = 740;
	
	$("#divMonitorConsultas").empty();
	
	cargarPanelTABMONVIS();
	
}
	  
function cargarPanelTABMONVIS(){
	
	$.post("vistas/tabMonitorConsultas.php", function(data){
		
		$("#divMonitorConsultas").html(data);
		
	    getConsultasPendientes();
		
		if(objUsuario.tipo===3){//Monitor TV
		
		    $("#divMonitorConsultas").find("#divTitle").css( {"color":"white"} );

            setInterval(function(){ getConsultasPendientes(); }, 15000);
            
        }
    
	});
}

//var strIdConsulta = "";
function getConsultasPendientes(){
	console.log("\n getConsultasPendientes");

    var intCaso = 1, intEstatus = 1, strBgColor = "#e6ef6a", strIdConsultaLeer = "", strTextoAleer = "" ;
    
    intCaso = objUsuario.tipo;
    
    if(objUsuario.tipo===2){//Secretaria
        //intCaso = 2;
        strBgColor = "none";
    }
    
    
    $("#divLoading").css( {"display":"block"} );

    var strUrl = "data/dataConsultas.php?rnd="+ Math.random();

    var dataObject = { method: 'getConsultasPendientes'
    		 , intCaso: intCaso
    		 , intMedico: (objUsuario.id)
    		 , intEstatus: (intEstatus)
    		 , intEmpresa: (objUsuario.empresa)
    };
    
    $.post(strUrl, dataObject, function(dataNew){
    	//console.log("dataNew: "+ dataNew);
    
    	if(dataNew!=""){

			var data = $.parseJSON(dataNew);
			var arrItems = data.Items;
		 	
		 	var strItems = "";
		 	for(var i=0; i<arrItems.length; i++){
		 	    
                console.log("intCliente: "+ arrItems[i].intCliente);
                
                var strIdConsulta = arrItems[i].strIdConsulta, strBg = "#5c84de", strColor = "#ffffff";
                
            	if(intCaso===1 || intCaso===2){
            	    
    		 		strItems += "<div id='divConsulta_"+ strIdConsulta +"' style='background:"+ strBgColor +"; width: 100%; height:auto; text-align:center; margin:0px 0px 8px 0px; padding: 10px 0px 10px 0px; font-size: 16px; border: 1px solid #739608; border-radius:6px; box-sizing: border-box; ' >";
                
            	}else if(intCaso===3){ //MONITOR TV
                    
                    var intEstatus = arrItems[i].intEstatus;
                    
                    if(intEstatus==2){
                        strBgColor = "rgba(116, 217, 24, 0.9)"; //VERDE
                    }else{
                        strBgColor = "rgba(255, 255, 255, 0.9)"; //BLANCO
                    }
                    
	 		        strItems += "<div id='divConsulta_"+ strIdConsulta +"' style='background: "+ strBgColor +"; width: 100%; height:auto; text-align:center; margin:0px 0px 8px 0px; padding: 10px 0px 10px 0px; font-size: 16px; border: 1px solid #f3f3f3; border-radius:6px; box-sizing: border-box; '>";
               
                }

			 		if(intCaso===1){
                        strItems += "<a href='javascript: verExpedienteMonCon(\""+ strIdConsulta +"\", "+ arrItems[i].intCliente +");'  style='color: #5c84de;'>";
                    }
			 		
			 		strItems += arrItems[i].strCliente;
			 		strItems += "<br/>";
			 		
			 		if(intCaso===3){
			 		    strItems += "Consultorio: "+ arrItems[i].intConsultorio;
			 		    strItems += "<br/>";
			 		}
			 		
			 		strItems += arrItems[i].datFecha;
			 		
			 		if(intCaso===1){
			 		    strItems += "</a>";
			 		}  
			 		
	 		    strItems += "</div>";
	 		    
	 		    if(intCaso==3){
	 		        if(intEstatus==2){
	 		            strIdConsultaLeer = strIdConsulta;
	 		            strTextoAleer = arrItems[i].strCliente +" favor de pasar a consultorio "+ arrItems[i].intConsultorio; 
	 		            //leerDatosConsulta( strIdConsulta , strTextoAleer);
	 		        }
	 		    }
                
		 	}

		 	$("#divGridMonitorVisitas").html( strItems );
		 	$("#divLoading").css( {"display":"none"} );

		 	leerDatosConsulta( strIdConsultaLeer , strTextoAleer);

    	}
    });
    
}

function verExpedienteMonCon(strIdConsulta, intCliente){
    console.log("\n verExpedienteMonCon / strIdConsulta: "+ strIdConsulta +" / intCliente: "+ strIdConsulta);
    strIdConsultaGral = strIdConsulta;
    
    getDataTABCATCLI(3, intCliente, irExpedienteMonCon);
}

function irExpedienteMonCon(intCliente, strPaciente, strUrlImg){
    console.log("\n irExpedienteMonCon");
	verExpediente(1, intCliente);
}

function leerDatosConsulta(strIdDivConsultaArg, strTextoArg){
    console.log("leerDatosConsulta / strTextoArg: "+ strTextoArg);
    
    //var strIdDiv = "divConsulta_"+ strIdDivConsultaArg;
    var strDiv = "#divConsulta_"+ strIdDivConsultaArg;
    console.log("leerDatosConsulta / strDiv: "+ strDiv);

    var objDiv = $("#divGridMonitorVisitas").find( strDiv );
    
    objDiv.animate({
        opacity: 0
        
      }, 500, function() {
        // Animation complete.
        objDiv.animate({
            opacity: 1
            
          }, 500, function() {
            // Animation complete.
            
            objDiv.animate({
                opacity: 0
                
              }, 500, function() {
                // Animation complete.
                objDiv.animate({
                    opacity: 1
                    
                  }, 500, function() {
                    // Animation complete.
                    
                    objDiv.animate({
                        opacity: 0
                        
                      }, 500, function() {
                        // Animation complete.
                        objDiv.animate({
                            opacity: 1
                            
                          }, 500, function() {
                            // Animation complete.
                            
                        });
                        
                    });
                    
                });
                
            });
            
        });
        
    });
      
	if ('speechSynthesis' in window) {
		var strTexto = strTextoArg;

		var msg = new SpeechSynthesisUtterance();
		var voices = window.speechSynthesis.getVoices();
		//msg.voice = voices[16]; // 0 - Paulina, 16 - Juan es-MX Note: some voices don't support altering params
		msg.voice = voices[0]; // 0 - Paulina, 16 - Juan es-MX Note: some voices don't support altering params
		
		msg.voiceURI = 'native';
		msg.volume = 1; // 0 to 1
		//msg.rate = 1; // 0.1 to 10
		//msg.pitch = 2; //0 to 2
		//msg.text = 'Hello World';
		//strTexto = "Danae lavate los dientes por favor o te voy a castigar";
		msg.text = strTexto;
		msg.lang = 'es-MX';

		msg.onend = function(e) {
		  //console.log('Finished in ' + event.elapsedTime + ' seconds.');
		};

		speechSynthesis.speak(msg);
		//window.speechSynthesis.speak(msg);
	}else{
		console.log("No soporta speechSynthesis");
	}

    //var synth = window.speechSynthesis;
    //console.log(synth);
    //console.log(synth.getVoices());
  
	//msg.voice = speechSynthesis.getVoices().filter(function(voice) { return voice.name == 'Whisper'; })[0];

}
