﻿			
			var CronoID = null;
			var CronoEjecutandose = false;
			var decimas, segundos, minutos,horas;
			var control;

			function DetenerCrono ()
			{
				//confirm('El tiempo se ha terminado desea guardar?');
				if(CronoEjecutandose)
				clearTimeout(CronoID);
				CronoEjecutandose = false;
			}

			function InicializarCrono (control) 
			{
				if(document.getElementById(control).value != '')
				{
					var arreglo = document.getElementById(control).value.split(':');
					
					decimas = arreglo[3];
					segundos = (arreglo[2] <10)?arreglo[2].substr(1,2):arreglo[2];
					minutos = (arreglo[1] <10)?arreglo[1].substr(1,2):arreglo[1];
					horas	= (arreglo[0] <10)?arreglo[0].substr(1,2):arreglo[0];
				}
				else
				{
					decimas = 0;
					segundos = 0;
					minutos = 0;
					horas	= 0;
					document.getElementById(control).value ='00:00:00:00';
					
					var arr = document.getElementById('Tiempo_Limite').value.split(':');
					var sec = arr[2];
					var min = arr[1];
					var hor	= arr[0];
					var time = document.getElementById('Tiempo_Limite').value;
					var sh, sm, ss;
					sh = (hor == '01')?' hora ':' horas ';
					sm = (min == '01')?' minuto ':' minutos ';
					ss = (sec == '01')?' segundo ':' segundos. ';
					
					if(hor != '00' || min != '00' || sec != '00'){	
						//window.showModalDialog('../AplicarExamenes/Instrucciones.aspx', 'Instrucciones', 'left=200,top=100,width=650,height=450,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no').focus();			
						alert('Tiempo límite: \n' + hor + sh + min + sm + 'y ' + sec + ss );
					}
				}
			}

			function MostrarCrono (control) {
				//incrementa el reloj
				//decimas++;arivera
				//if ( decimas > 9 ) {
					//decimas = 0;
					segundos++;
					if ( segundos > 59 ) {
						segundos = 0;
						minutos++;
						if ( minutos > 59 ) {
							segundos = 0;
							minutos = 0;
							horas ++;
							if(horas > 24)
								alert('Fin de Dia')
								DetenerCrono()
								return true
						}
					}
				//}
				//configura la salida
				var ValorCrono = ""
				ValorCrono = (horas < 10) ? "0" + horas : horas;
				ValorCrono += (minutos < 10) ? ":0" + minutos : ":" + minutos;
				ValorCrono += (segundos < 10) ? ":0" + segundos : ":" + segundos;
				//ValorCrono += ":" + decimas;
				document.getElementById(control).value = ValorCrono;
				
				
				//Aqui colocar detener el examen 
				if(ValorCrono +':00' == document.getElementById('Tiempo_Limite').value) //+':00'
				{
					CronoEjecutandose = false;
					document.getElementById('Tiempo_Limite').value='';
					GuardarDatos();//funcion en Pagina AplcarExamenes
				}
				else
				{
					CronoID = setTimeout("MostrarCrono(control)", 1000)//100
					CronoEjecutandose = true;
				}
				//RETURN TRUE;
				return CronoEjecutandose;
			}

			function IniciarCrono (controlHtml)
			{
				if(document.getElementById('Tiempo_Limite').value !=null && document.getElementById('Tiempo_Limite').value !='')
				{
					control = controlHtml;
					InicializarCrono(control);
					DetenerCrono();
					MostrarCrono(control);
					//ShowChronus(control);
				}
			}
/*********************************************************************************************************/			
function ShowChronus (control) {
	//incrementa el reloj
	var uno = document.getElementById(control).value;
	var dos = document.getElementById('Tiempo_Limite').value;
	var arr;
	if(uno == '00:00:00:00'){
		uno = dos;
		arr = uno.split(':');
	}else{
		//arr  = document.getElementById('Tiempo_Limite').value.split(':');
		arr = uno.split(':');
	}
	
	var sec = arr[2];
	var min = arr[1];
	var hor	= arr[0];	
	var Hour   = hor;
	var Minute = min;
	var Second = sec; 
	var Sec    = parseInt(Second,10);
	var Min    = parseInt(Minute,10);
	var Hor    = parseInt(Hour,10);
	if(Sec == 0){
		Sec = 59;
		Second = Sec.toString();
		if(Min == 0){
			Min = 59;
			Minute = Min.toString();
			Hour = Hor.toString();
			if(Hor == 0 && Min == 0 && Sec ==0){
				alert('El tiempo se ha terminado');
				DetenerCrono()
				return true
			}
			else if(Hor != 0){
				Hor--;
				Hour = Hor.toString();
			}
		}else{
			Min--;
			Minute = Min.toString();
		}
	}else{
		Sec--;
		Second = Sec.toString();
	}
	if(Hor < 10){Hour = "0" + Hor.toString();}
	if(Min < 10){Minute = "0" + Min.toString();}
	if(Sec < 10){Second = "0" + Sec.toString();}
	//configura la salida
	var ValorCrono = ""
	ValorCrono = Hour + ":" + Minute + ":" + Second;
	//ValorCrono += ":" + decimas;
	document.getElementById(control).value = ValorCrono;
	//Aqui colocar detener el examen CALLBACK's
	if(ValorCrono == "00:00:00" ){
		CronoEjecutandose = false;
		document.getElementById('Tiempo_Limite').value='';
		GuardarDatos();
	}
	else{
		CronoID = setTimeout("ShowChronus(control)", 1000)//100
		CronoEjecutandose = true;
	}
	//RETURN TRUE;
	return CronoEjecutandose;
}


function hora(){
	if (!document.all){
		return;
	}
	if (ControlEtiquetaFecha != ""){	
		var etiqutaTiemp = document.all[ControlEtiquetaFecha];
	}
	if (etiqutaTiemp != null){
		var Digital = new Date();
		var horas = Digital.getHours();
		var minutos = Digital.getMinutes();
		var segundos = Digital.getSeconds();
		var dn = "a.m.";
		if (horas > 12){
			dn = "p.m.";
			horas = horas - 12;
		}
		if (horas == 0)
			horas = 12;
		if (horas<=9)
			horas = "0" + horas;
		if (minutos<=9)
			minutos = "0" + minutos;
		if (segundos <= 9)
			segundos = "0" + segundos;
			mrelog = horas + ":" + minutos + ":" + segundos + " " + dn + "";
		etiqutaTiemp.innerHTML = mrelog;
	}
	setTimeout("hora()", 1000);
}

var ControlEtiquetaFecha = "";
hora();



