/***************************************************************************************************************/
/***********************************    FUNCIONES CERTIFICADO PAE     ******************************************/
/***********************************    Creador: Manuel Aviles        ******************************************/
/***********************************    Fecha: 23.09.2008             ******************************************/
/***********************************    maviles@signos.cl             ******************************************/
/***************************************************************************************************************/
/*
Function AspectosDetalle(num,destino) : Muestra el Nombre de el Aspecto marcado (1 a 14) y Muestra La información en el Campo Destino
Function MostrarDIV() : Despliega la Caja Negra con la imagen del Preload. Gatilla la funcion Mostrar(id)
Function OcultarDIV() : Oculta la Caja Negra y la imagen del Preload. Gatilla la funcion Ocultar(id)
Function Mostrar(id) : Realiza la aparicion y aplica el filtro para oscurecer el DIV del Parámetro id.
Function Ocultar(id) :  Realiza la desaparición y aplica el filtro inverso de oscurecer al DIV del Parámetro id.
Function movimientoMouse(ev) : en el DIV Observacion (Flotante), lo despliega en las cordenadas del Mouse x = mousePos.y - 90 || y = mousePos.x - 5;
Function ocultarObservacion() : Oculta el div flotante Observacion. hidden
Function mouseCoords(ev) :  Retorna las cordenadas X e Y del Mouse.
Function Redimensionar() : Sin USo - Redimensionara la página cuando se realice un onResize.
Function XYWin() : Retorna el espacio utilizado en la ventana X e Y para abarcar todo el espacio.
Function MuestraFoto(div,foto) : Sin Uso - Despliega una imagen en el div según su nombre. buscandola en la ruta "../img/"+foto
Function VaciarDiv(div) :  Sin Uso - Vacia un div indicando el id como parametro "div"
Function dzIncreaseFontSize(idElemento) : Aumenta de tamaño la fuente seleccionada
Function dzDecreaseFontSize(idElemento) : Disminuye el tamaño de la fuente seleccionada
Function dzResetFontSize(idElemento) : Restaura el tamaño original de la fuente
Function acceptNum(evt) : Solo permite el ingreso de numeros
Function sumaRacionesDesayuno() : Suma las Raciones Servidas Completas, Servidas Incompletas y No Servidas durante el desayuno
Function sumaRacionesAlmuerzo() : Suma las Raciones Servidas Completas, Servidas Incompletas y No Servidas durante el almuerzo
Function SumaBeneficiados(ids,destino)  :
Function ValidarHoras(id) :
Function ResolucionXY()  :  Obtiene la Resolucion de Ventana.
*/
/***************************************************************************************************************/
/****************************************************************************************************************************************************/
/******************************* MOSTRAR INFORMACIÓN DEPENDIENDO DE ASPECTO (CUADRO INGRESO DIARIO) ****************************************/
function AspectosDetalle(num,div)
{
	var dato = new Array();
	dato[1] = "Aspecto 1: Asistencia Personal";
	dato[2] = "Aspecto 2: Combustible";
	dato[3] = "Aspecto 3: Programaci&oacute;n Minuta";
	dato[4] = "Aspecto 4: Estado Cocina y Lavaplatos";
	dato[5] = "Aspecto 5: Estado y Cantidad de Vajillas";
	dato[6] = "Aspecto 6: Higiene y Elementos del Personal";
	dato[7] = "Aspecto 7: Higiene Servicio de Alimentaci&oacute;n"; 
	dato[8] = "Aspecto 8: Productos Qu&iacute;micos Servicio de Alimentaci&oacute;n";
	dato[9] = "Aspecto 9: Materia Prima y/o Preparaciones sin R&oacute;tulo";
	dato[10] = "Aspecto 10: Materia Prima y/o Preparaciones No Aptas Consumo";
	dato[11] = "Aspecto 11: Estado y Cantidad de Equipamiento y Mobiliario";
	dato[12] = "Aspecto 12: Linea de Fr&iacute;o y Tratamiento T&eacute;rmico";
	dato[13] = "Aspecto 13: Capacitaci&oacute;n Persona del Servicio de Alimentaci&oacute;n";
	dato[14] = "Aspecto 14: Materias Primas, preparaciones y/o Insumos Pendientes";
	document.getElementById(div).innerHTML = dato[num];
}

function ReIngresarActa(fecha,estrato,programa,fec,tipo,id)
{
	MostrarDIV()
	if (confirm("Va a reingresar el acta nuevamente. \n Desea Continuar?")){
		RevisarActaDiario(fec,estrato,programa,tipo,id);
	}else{
		OcultarDIV();
	}
}


/**************************************************************************************************************************************/
/********************************* MUESTRA DIV QUE TAPA EL FONDO Y MUESTRA RELOJ DE CARGA *********************************************/
function MostrarDIV()
{
	//document.body.scroll = 'no';
	document.getElementById('cargar').style.display='block';
	//var dim = XYWin();
	var dim = ResolucionXY();
	document.getElementById('cargar').style.width  = dim.x+"px";
	document.getElementById('cargar').style.height = dim.y+"px";
	document.getElementById("cargar").style.opacity="0";
	document.getElementById("cargar").style.filter="alpha(opacity=0)";
	var id = "cargar";
	clearInterval(hilo);
	opacidad=0;
	hilo=setInterval("Mostrar('"+id+"')",100);
        
}
// Variables de MostrarDIV() y OcultarDIV()
var opacidad=0; 
var hilo; 
/**************************************************************************************************************************************/
/********************************* OCULTA DIV QUE TAPA EL FONDO Y MUESTRA RELOJ DE CARGA *********************************************/
function OcultarDIV()
{
	document.body.scroll = 'yes';
	var id = "cargar";
	document.getElementById('cargado').style.display='none';
	document.getElementById('CalendarioJavascript').style.visibility='hidden';
	clearInterval(hilo);
	opacidad=80;
	hilo=setInterval("Ocultar('"+id+"')",100);
	
}

/***********************************************************************************************************************************/
/***********************************   OCULTAR Y MOSTRAR DIV  (Efecto de Opacidad)  ************************************************/
/***********************************************************************************************************************************/
function Mostrar(id) {
	opacidad += 10;  
	var opacidadFireFox=opacidad/100;  
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";
	if (opacidad>79) {
		clearInterval(hilo);
		document.getElementById(id).style.opacity=".80";
		document.getElementById(id).style.filter="alpha(opacity=80)";
		//document.getElementById("cargar").innerHTML = '<br><br><br><br><br><br><br><br><br><img src=\"../img/loading_4.gif\" id="c4g"/>';
	var selects = document.getElementsByTagName("select");
	for(var i=0;i<selects.length;i++)
	selects[i].style.visibility = "hidden";
	var selects = document.getElementById("cargado");
	var selectsShow = selects.getElementsByTagName("select");
	for(var i=0;i<selectsShow.length;i++)
	selectsShow[i].style.visibility = "visible";


		return;
	}
} 
function Ocultar(id) {
	opacidad -= 10;
	var opacidadFireFox=opacidad/100;  
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";  
	if (opacidad<1) {
		clearInterval(hilo);
		document.getElementById(id).style.opacity=".0";
		document.getElementById(id).style.filter="alpha(opacity=0)";
		document.getElementById(id).style.display='none';
	var selects = document.getElementsByTagName("select");
	for(var i=0;i<selects.length;i++)
	selects[i].style.visibility = "visible";
		return;
	}
}
/***********************************************************************************************************************************/
/****************************************  VENTANA DESLIZANTE DTZ (Cuadro de Dialogo)  *********************************************/
/***********************************************************************************************************************************/

// CONTROLA EL MOVIMIENTO DEL MOUSE
function movimientoMouse(ev){
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);
	x = mousePos.y - 90;
	y = mousePos.x - 5;
	document.getElementById("observacion").style.visibility = "visible";
	document.getElementById("observacion").style.top = x +"px";
	document.getElementById("observacion").style.left = y +"px";
}
function ocultarObservacion(){document.getElementById("observacion").style.visibility = "hidden";}
// OBTIENE CORDENADAS DEL MOUSE
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}
/************************************************************************************************************************************/
// SIN USO
function Redimensionar()
{
	var cor = XYWin();
	document.getElementById("cargar").style.width  = cor.x+"px";
	document.getElementById("cargar").style.height = cor.y+"px";
}
/***********************************************************************************************************************************/
/***********************************     DIMENSIONES DE LA VENTANA    **************************************************************/
/***********************************************************************************************************************************/
function XYWin(){
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// Todos Excepto Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 mas Menos
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // Otro Explorador
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	return{x:windowWidth,y:windowHeight};
}
/***************************************************************************************************************************/
/************************************               SIN USO              ***************************************************/
/***************************************************************************************************************************/
function MuestraFoto(div,foto){document.getElementById(div).innerHTML = '<img src="../img/'+foto+'" width="399" height="251" border="1"/>';}
function VaciarDiv(div){document.getElementById(div).innerHTML = '';}
/***********************************************************************************************************************************/
/***********************************************  AUMENTO Y DISMINUCION DE TAMAÑO DE LETRAS ****************************************/
/***********************************************************************************************************************************/
var max_size = 150;
var min_size = 80;
var tamagnoLetras = 100;
function dzIncreaseFontSize(idElemento) {
	if (document.all || document.getElementById) {    
		var elemento = document.all ? document.all[idElemento] : document.getElementsByTagName(idElemento);
		if (elemento) {  // el valor est&aacute; indicado en porcentaje:
			if(tamagnoLetras >= max_size){
				alert("No es posible aumentar m\u00E1s el texto")
			}else{
				tamagnoLetras += 10;
				if (elemento.length)
					for (i=0; i<elemento.length; i++) {
						elemento[i].style.fontSize = (tamagnoLetras+'%');
					}
				else
					elemento.style.fontSize = (tamagnoLetras+'%');    
			}
		}
	}
}

function dzDecreaseFontSize(idElemento) {
	if (document.all || document.getElementById) {    
		var elemento = document.all ? document.all[idElemento] : document.getElementsByTagName(idElemento);
		if (elemento) {   // el valor est&aacute; indicado en porcentaje:
			if(tamagnoLetras <= min_size){
				alert("No es posible disminuir m\u00E1s el texto")
			}else{
				tamagnoLetras -= 10;
				if (elemento.length)
					for (i=0; i<elemento.length; i++) {
						elemento[i].style.fontSize = (tamagnoLetras+'%');
					}
				else
					elemento.style.fontSize = (tamagnoLetras+'%');    
			}
		}
	}
}

function dzResetFontSize(idElemento) {
	var elemento = document.all ? document.all[idElemento] : document.getElementsByTagName(idElemento);
	//document.body.style.fontSize = '';//elemento.body.style.fontSize = '100%';    
	for (i=0; i<elemento.length; i++) {
	 elemento[i].style.fontSize = "";
	}
}
/***********************************************************************************************************************************/
/***********************************************  SOLO NUMEROS *********************************************************************/
/***********************************************************************************************************************************/

function acceptNum(evt){	
	var tecla = String.fromCharCode(evt.which || evt.keyCode);
	if ( !/[\d.\b\r]/.test(tecla) ) return false;
	return true;

}

function sumaRacionesDesayuno(){
	var servidasCompletas = parseInt(document.getElementById("dsc").value);
	if (document.getElementById("dsc").value == "")
		servidasCompletas=0;
	var servidasIncompletas = parseInt(document.getElementById("dsi").value);
	if (document.getElementById("dsi").value == "")
		servidasIncompletas=0;
	var noServidas = parseInt(document.getElementById("dns").value);
	if (document.getElementById("dns").value == "")
		noServidas=0;
	var totalRaciones;
	totalRaciones = servidasCompletas + servidasIncompletas + noServidas;
	document.getElementById("dtr").value = totalRaciones;
}
function sumaRacionesAlmuerzo(){
	var servidasCompletas = parseInt(document.getElementById("asc").value);
	if (document.getElementById("asc").value == "")
		servidasCompletas=0;
	var servidasIncompletas = parseInt(document.getElementById("asi").value);
	if (document.getElementById("asi").value == "")
		servidasIncompletas=0;
	var noServidas = parseInt(document.getElementById("ans").value);
	if (document.getElementById("ans").value == "")
		noServidas=0;
	var totalRaciones;
	totalRaciones = servidasCompletas + servidasIncompletas + noServidas;
	document.getElementById("atr").value = totalRaciones;
}

/*************************************************************************************************************************************************/
/****************************  REALIZA LA SUMA DE LOS INPUT DE ids Y DESPLIEGA EL RESULTADO en destino  ******************************************/
function SumaBeneficiados(ids,destino)
{
	var id = ids.split(",");
	var resultado = 0;       
	for(var i=0;i<id.length;i++){
    	var valor = document.getElementById(id[i]).value == "" ? 0 : parseInt(document.getElementById(id[i]).value);
	var resultado = resultado + valor; }
	document.getElementById(destino).value = resultado;	  
}
/*************************************************************************************************************************************************/
/****************************  VALIDA QUE EL CAMPO DEL id SEA EN FORMATO HORA hh:mm **************************************************************/
function ValidarHoras(id){
	var valor=document.getElementById(id).value;
	var patron=/^[0-9]{2,2}\:[0-9]{2,2}$/;
	var test2=valor.split(':');
	var hok=parseInt(test2[0])>=0 && parseInt(test2[0])<24;
	var mok=parseInt(test2[1])>=0 && parseInt(test2[1])<60;
	if(patron.test(valor) && hok && mok){}
	else{
		alert("Debe Ingresar la Hora con Formato hh:mm");
		document.getElementById(id).focus();
		return false;
	}
}

/***********************************************************************************************************************************************/
/*************************************** TOMA RESOLUCION DE VENTANA COMPLETA  ******************************************************************/
function ResolucionXY(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // Explorer 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer 6, Mozilla y Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// Todos Los Navegadores Excepto Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // Otras Versiones de Explorer
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// Para Paginas Pequeñas con el height menos al height del viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// Para Paginas Pequeñas con el width menos al width del viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	return{x:pageWidth,y:pageHeight};
}

function colocarOpcion(id,valor){
	document.getElementById(id).innerHTML = valor;
	document.getElementById(id).style.position = "static";
	document.getElementById(id).style.zIndex  = "1";
}
function borrarOpcion(id){
	document.getElementById(id).innerHTML = "&nbsp;";
	document.getElementById(id).style.position = "static";
	document.getElementById(id).style.zIndex  = "1";
}
/******************************************************************************************************************************************/
/******************************************************************************************************************************************/
/******************************************************************************************************************************************/
/******************************************************************************************************************************************/
/******************************************************************************************************************************************/
/**************************************************************************************************************************************/
/********************************* MUESTRA DIV QUE TAPA EL FONDO Y MUESTRA RELOJ DE CARGA *********************************************/
function MostrarDIV2()
{
	//document.body.scroll = 'no';
	document.getElementById('cargar2').style.display='block';
	//var dim = XYWin();
	var dim = ResolucionXY();
	document.getElementById('cargar2').style.width  = dim.x+"px";
	document.getElementById('cargar2').style.height = dim.y+"px";
	document.getElementById("cargar2").style.opacity="0";
	document.getElementById("cargar2").style.filter="alpha(opacity=0)";
	var selects = document.getElementById("cargado");
	var selectsShow = selects.getElementsByTagName("select");
	for(var i=0;i<selectsShow.length;i++)
	selectsShow[i].style.visibility = "hidden";
	var id = "cargar2";
	clearInterval(hilo);
	opacidad=0;
	hilo=setInterval("Mostrar2('"+id+"')",20);
}
// Variables de MostrarDIV() y OcultarDIV()
var opacidad=0; 
var hilo; 
/**************************************************************************************************************************************/
/********************************* OCULTA DIV QUE TAPA EL FONDO Y MUESTRA RELOJ DE CARGA *********************************************/
function OcultarDIV2()
{
	document.body.scroll = 'yes';
	var id = "cargar2";
	document.getElementById('cargado2').style.display='none';
	document.getElementById('CalendarioJavascript').style.visibility='hidden';
	clearInterval(hilo);
	opacidad=80;
	hilo=setInterval("Ocultar2('"+id+"')",20);
}

/***********************************************************************************************************************************/
/***********************************   OCULTAR Y MOSTRAR DIV  (Efecto de Opacidad)  ************************************************/
/***********************************************************************************************************************************/
function Mostrar2(id) {
	opacidad += 10;  
	var opacidadFireFox=opacidad/100;  
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";
	if (opacidad>79) {
		clearInterval(hilo);
		document.getElementById(id).style.opacity=".80";
		document.getElementById(id).style.filter="alpha(opacity=80)";
	//var selects = document.getElementsByTagName("select");
	//for(var i=0;i<selects.length;i++)
	//selects[i].style.visibility = "hidden";
	return;
	}
} 
function Ocultar2(id) {
	opacidad -= 10;  
	var opacidadFireFox=opacidad/100;  
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";  
	if (opacidad<1) {
		clearInterval(hilo);
		document.getElementById(id).style.opacity=".0";
		document.getElementById(id).style.filter="alpha(opacity=0)";
		document.getElementById(id).style.display='none';
	var selects = document.getElementById("cargado");
	var selectsShow = selects.getElementsByTagName("select");
	for(var i=0;i<selectsShow.length;i++)
	selectsShow[i].style.visibility = "visible";
		return;
	}
}
