/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function grabarArchivo(Curso, Clase, Arch) {
  var ventana;

  alert("Curso " + Curso + "\n" +
        "Clase " + Clase + "\n" +
        "Archivo " + Arch);

  ventana = "grabarArchivo.php?nCur=" + Curso + "&nCla=" + Clase + "&sArc=" + Arch;
  window.open(ventana, "miventana", "width=500, height=500, menubar=no");
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function CalCtrl(nombre) {
  var i, inps;

  inps = document.getElementsByTagName("INPUT");
  for (i in inps) {
    if (i.match("CHKBF") != null) {
      if (inps[i].value != nombre.value) {
        inps[i].checked = (inps[i].checked ? false : false);
      }
    }
  }
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function crearEvento(el, evento, funcion) {
  if (el.addEventListener) {
    el.addEventListener(evento, funcion, false);
    return true;
  }
  else if (el.attachEvent) {
    var r = el.attachEvent("on"+evento, funcion);
    return r;
  }
  else {
    alert("Handler could not be attached");
  }
} 

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function cambiaCalendario(Tab, Input) {
  var padre, div, tbl, tb, tr, td;
// Borrar todos los hijos
  padre = document.getElementById("divide");
  while (padre.firstChild) {
//      alert('[' + padre.innerHTML + ']');
    padre.removeChild(padre.firstChild);
  }

//    alert('[' + Tab + '][' + Input + ']');

  nomArr = "TbCalCur" + Tab;
  if (nomArr == "TbCalCurnull")
    return;

  var TbCalCur = new Array();
  TbCalCur = eval(nomArr);

//    alert('[' + nomArr + '][' + TbCalCur.length + ']');

  div = document.createElement("div");
  div.className="CalVer";
  div.id="CalVer";
  padre.appendChild(div);

  var divTit = document.createElement("div");
  divTit.className="CalVerTit";
  divTit.innerHTML="Calendario";
  div.appendChild(divTit);

  tbl = document.createElement("table");
  tbl.className="CalVerTab";
  tbl.id="TablaCalendario";

  tb = document.createElement("tbody");
  tbl.appendChild(tb);

  tr = document.createElement("tr");
  tr.className="CalVerFilTit";
  tb.appendChild(tr);

  td = document.createElement("td"); td.className="CalVerCol1"; td.innerHTML="Fecha Inicio"; tr.appendChild(td);
  td = document.createElement("td"); td.className="CalVerCol1"; td.innerHTML="Fecha Fin"; tr.appendChild(td);

  if (Input) {
    td = document.createElement("td"); td.className="CalVerCol1"; td.innerHTML=" "; tr.appendChild(td);
  }

  i = 0;
  fil = 0;
  while (true) {
    if (i > TbCalCur.length - 1)
      break;

    tr = document.createElement("tr");
    if (fil % 2 == 0) {
      tr.className = "CalVerFilPar";
    }
    else {
      tr.className = "CalVerFilImpar";
    }
    tb.appendChild(tr);

    td = document.createElement("td"); td.className = "CalVerCol1"; td.innerHTML = TbCalCur[i]; tr.appendChild(td);
    i = i + 1;
    td = document.createElement("td"); td.className = "CalVerCol1"; td.innerHTML = TbCalCur[i]; tr.appendChild(td);
    i = i + 1;

    if (Input) {
/* <input name="CHKBF0" type="checkbox" value="01/08/2008_25/08/2008" onClick="CalCtrl(this);" */
      td = document.createElement("td"); td.className = "CalVerCol2"; tr.appendChild(td);

      var inp = document.createElement("input");
      inp.type = "checkbox";
      inp.value = TbCalCur[i-2] + '_' + TbCalCur[i-1];
      inp.id = 'CHKBF' + fil;
      inp.name = 'CHKBF' + fil;
/*
        alert('[' + inp.value + '][' + inp.id + ']');
 */
      crearEvento(inp, "click", function(){CalCtrl(window.event.srcElement);});
/*
        crearEvento(inp, "click", function() { alert(inp.value); } );
*/
      td.appendChild(inp);
    }

    fil = fil + 1;
  }

  div.appendChild(tbl);

  return;
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function gi(eleName){
  if (document.getElementById && document.getElementById(eleName))
    return document.getElementById(eleName) 
  else if(document.all && document.all(eleName))
    return document.all(eleName)
  else if(document.layers && document.layers[eleName])
    return document.layers[eleName]
  else return false
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function mostrarClases(cant) {
  var padre, tbl, tb, tr, td, imt, imf, imb;
  var i, nuevo, tope;

/* Borrar todos los hijos */
  padre = document.getElementById("divClases");
  while (padre.firstChild) {
    padre.removeChild(padre.firstChild);
  }
  
/* Crea las filas de titulos de la tabla */
  tbl = document.createElement("table"); tbl.id="Tabla"; tbl.className="Clases";
  tb = document.createElement("tbody");  tbl.appendChild(tb);

  tope = (cant != 0 ? cant : TbClases.length);
  nuevo = (TbClases.length == 0 ? 1 : 0);

  for (i=0; i<tope; i++) {
/*
    frm = document.createElement("form"); 
    frm.action="cursoAlta.php"; frm.name="upform"; frm.method="post"; frm.enctype="multipart/form-data";
    tb.appendChild(frm);
*/
    tr = document.createElement("tr"); tb.appendChild(tr);
    td = document.createElement("td");
    td.className="lineaCampo"; td.innerHTML="Clase " + (i + 1) + " -> ";
    tr.appendChild(td);

    td = document.createElement("td");
    imt = document.createElement("input");
    imt.type="text"; imt.size=30; imt.readOnly=true;
    imt.value=(nuevo == 0 ? (TbClases[i] != undefined ? TbClases[i] : " " ) : " "); 
    imt.name="viejo_" + (i + 1);
    td.appendChild(imt);
    tr.appendChild(td);

    td = document.createElement("td");
    imf = document.createElement("input"); 
    imf.type="file"; imf.size=50;
    imf.name="nuevo_" + (i + 1);
    td.appendChild(imf);
    tr.appendChild(td);
/*
    td = document.createElement("td");
    imb = document.createElement("input"); 
    imb.type="submit"; imb.value=" Cargar "; imb.name="boton_" + (i + 1);
    td.appendChild(imb);
    tr.appendChild(td);
*/
  }

//  alert("[" + Datos.length + "][" + Datos[0][0] + "]");
//  alert('[' + lista + '][' + codigo + ']');

  padre.appendChild(tbl);

  return;
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectCursos(nombre, selec) {
  var sel, opt, txt;

  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option"); 
  txt = document.createTextNode("Seleccionar cursos");
  opt.appendChild(txt);
  opt.setAttribute("value", "-1");
  sel.appendChild(opt);

  for (i=0; i<TbCursos.length; i++) {
    opt = document.createElement("option"); 
    txt = document.createTextNode(TbCursos[i][1]);
    opt.appendChild(txt);
    opt.setAttribute("value", TbCursos[i][0]);
    if (selec == TbCursos[i][0])
      opt.setAttribute("selected", true);
    sel.appendChild(opt);
  }
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectPreg(nombre, curso, selec) {
  var sel, opt, txt;
  
  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option");
  txt = document.createTextNode("Seleccionar pregunta");
  opt.appendChild(txt);
  opt.setAttribute("value", "-1");
  sel.appendChild(opt);

  for (i=0; i<TbPregs.length; i++) {
    if (curso == TbPregs[i][0]) {
      opt = document.createElement("option"); 
      txt = document.createTextNode(TbPregs[i][2]);
      opt.appendChild(txt);
      opt.setAttribute("value", TbPregs[i][1]);
      if (selec == TbPregs[i][1])
        opt.setAttribute("selected", true);
      sel.appendChild(opt);
    }
  }
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectPais(nombre, selec) {
  var sel, opt, txt;

  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option"); 
  txt = document.createTextNode("Seleccionar país");
  opt.appendChild(txt);
  opt.setAttribute("value", "X");
  sel.appendChild(opt);

  for (i=0; i<TbPaises.length; i++) {
    opt = document.createElement("option"); 
    txt = document.createTextNode(TbPaises[i][1]);
    opt.appendChild(txt);
    opt.setAttribute("value", TbPaises[i][0]);
    if (selec == TbPaises[i][0])
      opt.setAttribute("selected", true);
    sel.appendChild(opt);
  }
}

/*----------------------------------------------------------------------*/
/* usuarioAlta.php                                                      */
/* EDFuncs.php                                                          */
/*----------------------------------------------------------------------*/
function selectDeptos(donde, nombre, pais, selec) {
  var sel, cmp, opt, txt;

  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  sel.disabled = (pais != 'UY');
  sel.readOnly = (pais != 'UY');

  opt = document.createElement("option"); 
  txt = document.createTextNode("Seleccionar departamento/provincia/estado");
  opt.appendChild(txt);
  opt.setAttribute("value", "X");
  sel.appendChild(opt);

  for (i=0; i<TbDeptos.length; i++) {
    if (pais == TbDeptos[i][0]) {
      opt = document.createElement("option"); 
      txt = document.createTextNode(TbDeptos[i][2]);
      opt.appendChild(txt);
      opt.setAttribute("value", TbDeptos[i][1]);
      if (selec == TbDeptos[i][1])
        opt.setAttribute("selected", true);
      sel.appendChild(opt);
    }
  }

  if (donde == 2) {
    cmp = document.getElementById('deptoNo');
    cmp.disabled = (pais == 'UY');
    cmp.readOnly = (pais == 'UY');

    cmp = document.getElementById('localNo');
    cmp.disabled = (pais == 'UY');
    cmp.readOnly = (pais == 'UY');

    if (pais != 'UY') {
      if (document.getElementById)
        document.getElementById('deptoNo').focus();
    }
  }
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectLocals(nombre, pais, depto, selec) {
  var sel, cmp, opt;
  
  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option");
  txt = document.createTextNode("Seleccionar localidad/municipio");
  opt.appendChild(txt);
  opt.setAttribute("value", "-1");
  sel.appendChild(opt);

  sel.disabled=(pais != 'UY');
  sel.readOnly=(pais != 'UY');

  for (i=0; i<TbLocals.length; i++) {
    if (pais == TbLocals[i][0] && depto == TbLocals[i][1]) {
      opt = document.createElement("option"); 
      txt = document.createTextNode(TbLocals[i][3]);
      opt.appendChild(txt);
      opt.setAttribute("value", TbLocals[i][2]);
      if (selec == TbLocals[i][2])
        opt.setAttribute("selected", true);
      sel.appendChild(opt);
    }
  }
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectInstitucion(nombre, selec) {
  var sel, opt, txt;

  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option"); 
  txt = document.createTextNode("Seleccionar institución");
  opt.appendChild(txt);
  opt.setAttribute("value", "X");
  sel.appendChild(opt);

  for (i=0; i<TbInst.length; i++) {
    opt = document.createElement("option"); 
    txt = document.createTextNode(TbInst[i][1]);
    opt.appendChild(txt);
    opt.setAttribute("value", TbInst[i][0]);
    if (selec == TbInst[i][0])
      opt.setAttribute("selected", true);
    sel.appendChild(opt);
  }
}


/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function selectCodigos(tabla, mostrar, nombre, selec) {
  var sel, opt, txt;

  var nomArr = "TbCodigos_" + tabla;
  var TbCodigos = new Array();
  TbCodigos = eval(nomArr);

  sel = document.getElementById(nombre);
  while (sel.firstChild) {
    sel.removeChild(sel.firstChild);
  }

  opt = document.createElement("option"); 
  txt = document.createTextNode("Sel. " + mostrar);
  opt.appendChild(txt);
  opt.setAttribute("value", "X");
  sel.appendChild(opt);

  for (i=0; i<TbCodigos.length; i++) {
    opt = document.createElement("option"); 
    txt = document.createTextNode(TbCodigos[i][1]);
    opt.appendChild(txt);
    opt.setAttribute("value", TbCodigos[i][0]);
    if (selec == TbCodigos[i][0])
      opt.setAttribute("selected", true);
    sel.appendChild(opt);
  }
}

/*----------------------------------------------------------------------*/
/* Fin del archivo funcsED.js                                           */
/*----------------------------------------------------------------------*/
