
var my_window =1;

var timer_id;

// INICIO CUENTA REGRESIVA

//I chose a div as the container for the timer, but
//it can be an input tag inside a form, or anything
//who is displayed content can be changed through
//client-side scripting.
function countdown_clock(year, month, day, hour, minute, format){
html_code = '<div id=\"countdown\"></div>';
document.write(html_code);
countdown(year, month, day, hour, minute, format);                
}
         
function countdown(year, month, day, hour, minute, format){
Today = new Date();
Todays_Year = Today.getFullYear() - 2000;
Todays_Month = Today.getMonth() + 1;                  
         
//Convert both today's date and the target date into miliseconds.                           
Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
         
//Find their difference, and convert that into seconds.                  
Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
if(Time_Left < 0)
   Time_Left = 0;

switch(format){
case 0:
     //The simplest way to display the time left.
     document.getElementById("countdown").innerHTML = Time_Left + ' segundos';
     break;
case 1:
     //More datailed.
     days = Math.floor(Time_Left / (60 * 60 * 24));
     Time_Left %= (60 * 60 * 24);
     hours = Math.floor(Time_Left / (60 * 60));
     Time_Left %= (60 * 60);
     minutes = Math.floor(Time_Left / 60);
     Time_Left %= 60;
     seconds = Time_Left;
     
     dps = 's'; hps = 's'; mps = 's'; sps = 's';
     //ps is short for plural suffix.
     if(days == 1) dps ='';
     if(hours < 10) hps ='0';
     if(minutes < 10) mps ='0';
     if(seconds < 10) sps ='0';
     
     document.getElementById("countdown").innerHTML = days + ' día' + dps + ' ';
     document.getElementById("countdown").innerHTML += hours + ':';
     document.getElementById("countdown").innerHTML += minutes + ':';
     document.getElementById("countdown").innerHTML += seconds;
//     document.getElementById("countdown").innerHTML += hours + ' hora' + hps + ' ';
//     document.getElementById("countdown").innerHTML += minutes + ' minuto' + mps + ' y ';
//     document.getElementById("countdown").innerHTML += seconds + ' segundo' + sps;
     break;
default: 
     document.getElementById('countdown').countdown.innerHTML = Time_Left + ' segundos';
}
      
//Recursive call, keeps the clock ticking.
setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

// FIN CUENTA - REGRESIVA

function scroll_iframe(frm,inc,dir) {
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm]) {
    if (dir == "v") window.frames[frm].scrollBy(0, inc);
    else window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
  }
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }

function changeto(highlightcolor){
source=event.srcElement
source.style.backgroundColor=highlightcolor
}

function changeback(originalcolor){
source.style.backgroundColor=originalcolor
}

function framePrint(whichFrame){
parent[whichFrame].focus();
parent[whichFrame].print();
}

function contar() {
var cont = 0; 
for (var i=0;i < document.forms[0].elements.length;i++)
{ if (document.forms[0].elements[i].checked) {
	cont = cont + 1;
  }
};
document.form.contador.value = cont
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2)
eval(args[i]+".location='"+args[i+1]+"'");
}

function confirma(msgStr) { //v1.0

var agree=confirm(msgStr);
if (agree)  parent.close(); 

}

function cierra() { //v1.0

opener.parent.location.reload();
self.close(); 

}

function cierra_ventana(msgStr) { //v1.0
self.close()
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status = msgStr;
  document.MM_returnValue = true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  my_window = window.open(theURL,winName,features);
  my_window.focus();
}

function abrirventana (href,target,ancho,alto,resizable,scrollbars) {
	var x, y;

	if (ancho != null && alto != null) {
		x = (screen.width - ancho) / 2;
		y = (screen.height - alto) / 2.5;
	}

	ventana = window.open(href,
						  target,
						  "width=" + ancho +
						  ",height=" + alto +
						  ",resizable=" + resizable +
						  ",scrollbars=" + scrollbars +
						  ",status=1" +
						  ",left=" + x +
						  ",top=" + y);

	ventana.focus();
	return ventana

}

function closepopup()
{	if(false == my_window.closed)
	{
	my_window.close();
	}
}

function aviso()
{ alert('Esta sesión será cerrada en un minuto, si Ud. está modificando este formulario, proceda a grabar en este momento');
}

function temporizador(tiempo)
{
timeout = setTimeout('aviso()',tiempo);
}

function volver()
{
  if (history.length > 0)
    {history.back()};
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function cambia()
{
  document.form.patron.value=document.form.patron.value.toUpperCase();

  if (document.form.patron.value.length < 3 )
  {  alert('El patrón ingresado debe tener más de 2 caracteres !!');
     return false;
  }
  else
  {
  return true ;
  }
}

function volver() {
timeout = setTimeout('javascript:back()',2000);
}

function enlace(seleccion, ventana)
{
if (seleccion.selectedIndex > 0)
{ ventana.location.href = seleccion.options[seleccion.selectedIndex].value}
}

function NoIngresaObservacion()
{
return confirm('Ud. no ha ingresado sus observaciones a las calificaciones. De todas formas las acepta ...')
}

function graba()
{
return confirm('Seguro de Grabar información ?')
}

function elimina()
{
return confirm('Seguro de Eliminar información ?')
}

function eliminaOpinion(){
	return confirm('Seguro de eliminar su opinión del foro ?')
}

function GrabarConfiguracionCurso()
{
return confirm('Desea Grabar la Configuración del Curso?, Observ.: La distribución uniforme de las evaluaciones serán recalculados, para que usted modifique tal distribución posteriormente')
}

function SeleccionarTodos(chkbox)
{
	var mensaje = '';
	for (var i=0;i < document.forms[0].elements.length;i++)
	{
		var elemento = document.forms[0].elements[i];
		if (elemento.type == 'checkbox')
		{
			elemento.checked = true;
		};
	};
}

function SeleccionarNada(chkbox)
{
	var mensaje = '';
	for (var i=0;i < document.forms[0].elements.length;i++)
	{
		var elemento = document.forms[0].elements[i];
		if (elemento.type == 'checkbox')
		{
			elemento.checked = false; //chkbox.checked
		};
	};
}

function SeleccionarAll(chkbox)
{
	var mensaje = '';
	for (var i=0;i < chkbox.elements.length;i++)
	{
		var elemento = chkbox.elements[i];
		if (elemento.type == 'checkbox')
		{
			elemento.checked = true;
		};
	};
}

function SeleccionarNone(chkbox)
{
	var mensaje = '';
	for (var i=0;i < chkbox.elements.length;i++)
	{
		var elemento = chkbox.elements[i];
		if (elemento.type == 'checkbox')
		{
			elemento.checked = false; //chkbox.checked
		};
	};
}

function revisaCheckbox(f) {
// Creado por: Freddy Castro (freddy76@gmail.com)
// Descripción: revisa que todos al menos un campo checkbox de un form esté chequeado.
// Modo de uso: onClick='return revisaCheckbox(document.nombreForm)'
// Salida: retorna TRUE (cuando se chequeo al menos una checkbox) o FALSE (si no hay ninguna chequeada)
var msg = 0;
var i;
for(i=0;i<f.elements.length;i++){
	var elemento = f.elements[i];
	if(elemento.type == 'checkbox' && elemento.checked == true){ 
		// Si el elemento es checkbox y está chequeado, acumulamos.
		msg++;
	}
}
if(msg == 0){
	alert('Debe seleccionar al menos un elemento de la lista.');
	return false;	
}
return true;
}

function deshabilita(chkbox)
{
	var mensaje = '';
	for (var i=0;i < document.forms[0].elements.length;i++)
	{
	   var elemento = document.forms[0].elements[i];
	   if (elemento.type == 'checkbox')
		{
		  elemento.disabled = true; 
		};
	};
}

function chequea_campo(formulario,campo){
if (Empty(document.forms[formulario].elements[campo].value))
{    alert('El campo está vacío!!');
     document.forms[formulario].elements[campo].focus();    
     return false;	
}
return true;
}

function abrirCerrarTit(tr,ver) {
  var filaTr = eval('document.all.' + tr);
  if (ver.checked) {
    filaTr.style.display = 'block';
  }else{
    filaTr.style.display = 'none';
  }
}

function abrirCerrar(tr,img) {
  var filaTr = eval('document.all.' + tr);
  if (filaTr.style.display=='block' || filaTr.style.display=='' ) {
    filaTr.style.display='none';
    img.children[1].children[0].src='/intranet/imagenes/PLUS.GIF';
  }else{
    filaTr.style.display='block';
    img.children[1].children[0].src='/intranet/imagenes/MINUS.GIF';
  }
}

function abrirCerrarAnuncio(tr,img) {
  var filaTr = eval('document.all.' + tr);
  if (filaTr.style.display=='block' || filaTr.style.display=='' ) {
    filaTr.style.display='none';
    img.children[1].children[0].src='/intranet/imagenes/PLUS.GIF';
  }else{
    filaTr.style.display='block';
    img.children[1].children[0].src='/intranet/imagenes/MINUS.GIF';
  }
}

function ieExecWB( intOLEcmd, intOLEparam )
{         var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
          document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
          if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || ( intOLEparam > 1) )
           intOLEparam = 1;
          WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
          WebBrowser1.outerHTML = "";
}

function printAll()
{	ieExecWB(6,-1); 
}

function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// Función creada por: Freddy Castro
// Esta función revisa si los campos ingresados en el ingreso a la Intranet están vacíos
function chequeaCamposVacios(login,pass){
var msg;
var error1;
var error2;
error1 = 0;
error2 = 0;
msg = "";
if(Empty(login)){
	error1 = 1;
	msg += "\nEl campo USUARIO está vacío\n";
}
if(!isInteger(login)){
	error1 = 1;
	msg += "\nEl campo USUARIO debe ser numérico\n\nUse su RUT sin puntos ni digito verificador.\n";
}
if(Empty(pass)){
	error2 = 1;
	msg += "\nEl campo CLAVE está vacío\n";
}
if(msg == ""){
	return true;
}
alert(msg);
if(error1 == 0 && error2 == 1){
	document.form1.pass.value = "";
	document.form1.pass.focus();
}else{
	document.form1.usuario.value = "";
	document.form1.pass.value = "";
	document.form1.usuario.focus();
}
return false;
}	

function detectaBrowser(){
	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring='';
	var msg = '';
	
	if (checkIt('konqueror',detect)){
		browser = "Konqueror";
		OS = "Linux";
		thestring = "konqueror"
	}
	else if (checkIt('safari',detect)){ browser = "Safari"; thestring = "safari" }
	else if (checkIt('omniweb',detect)){ browser = "OmniWeb"; thestring = "omniweb" }
	else if (checkIt('opera',detect)){ browser = "Opera"; thestring = "opera" }
	else if (checkIt('webtv',detect)){ browser = "WebTV"; thestring = "webtv" }
	else if (checkIt('icab',detect)){ browser = "iCab"; thestring = "icab" }
	else if (checkIt('msie',detect)){ browser = "Internet Explorer"; thestring = "msie" }
	else if (!checkIt('compatible',detect)){
		browser = "Netscape Navigator";
		version = detect.charAt(8);
		thestring = "compatible"
	}
	else browser = "An unknown browser";
	
	if (!version) 
		version = detect.charAt(place + thestring.length);
	
	if (!OS){
		if (checkIt('linux',detect)) OS = "Linux";
		else if (checkIt('x11',detect)) OS = "Unix";
		else if (checkIt('mac',detect)) OS = "Mac"
		else if (checkIt('win',detect)) OS = "Windows"
		else OS = "Sistema Operativo no registrado en nuestra base de datos.";
	}
	if(((thestring == 'msie') && (version < 6)) || (thestring != 'msie')){
		document.write("<BR><TABLE WIDTH='60%' class='sideblock02' BORDER='0' ALIGN='CENTER'>");
		document.write("<TR><TD><BR><U>Información Importante</U><BR></TD></TR>");
		msg = "<TR><TD>Ud. está usando " + browser + " " + version + "(" + OS + ")<BR><BR>Se recomienda usar Internet Explorer 6.02 o superior.<BR></TD></TR>";
		document.write(msg);	
		document.write("<TR><TD>Bájelo acá</TD></TR>");
		document.write("</TABLE>");
	}
}

function checkIt(string,detect)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function verificaRut(T,d,f){
	var M=0,S=1;
	var digito;
	if(isAlpha(d)){
		d = d.toUpperCase();	
	}
	if(!Empty(T)&&!Empty(d)){
		for(;T;T=Math.floor(T/10)) 
		S =(S+T%10*(9-M++%6))%11;
		digito = S?S-1:'K';
		if(digito != d){
			alert('RUT ERRONEO, VERIFIQUE');
			return false;	
		}
	}else{
		if(Empty(T)){
			alert('Debe ingresar el RUT');
		}else{
			alert('Debe ingresar el dígito verificador');
		}
		return false;
	}
	return true;
}

function verificaRutARAregis(T,f){
	var M=0,S=1;
	var digito;
	if(!Empty(T)){
		for(;T;T=Math.floor(T/10)) 
		S =(S+T%10*(9-M++%6))%11;
		digito = S?S-1:'K';
		document.form.admdv.value = digito;
	}else{
		document.form.admdv.value = '';
		document.form.admrut.focus();
	}
}
function checkCampoRut(rut,dv){
	   	var msg = '';
	   	if(Empty(rut)){
	   		msg += 'Debe ingresar el rut\n';
	   	}
	   	if(!isInteger(rut)){
	   		msg += 'El rut debe ser numérico\n';
	   	}
	   	if(Empty(dv)){
	   		msg += 'Debe ingresar el dígito verificador\n';
	   	}
	   	if(msg != ''){ alert(msg);return false; }
	   	return true;
	   }