// ARCHIVO: colebioqpba.js
/*--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------*/
/* Declaraciones Globales */
/*--------------------------------------------------------------------------------------------------------------------------------------*/
// PHP que llama el Ajax donde estan las funciones
//function Iniciar_Pagina(){
//alert('hola');
var colegio = './funciones/colebioqpba.php';
var upload = './uploadarchivos.php';
// Carga la libreria prototype
//document.write("<script Language='Javascript' SRC='/js/prototype.js'></script>");
/*--------------------------------------------------------------------------------------------------------------------------------------*/



function V(objID){
	var ret = "";
	if(document.getElementById(objID)){	ret = document.getElementById(objID).value;	}
	else{ if(document.getElementsByName(objID)){	ret = document.getElementsByName(objID).value; } }
	return(ret);
}
// Definicion de funcion Ajax
// Sincronica : Espera hasta que termine la funcion que se esta ejecutando antes de mostrar el resultado. (asynchronous: true)
// Asincronica: Cuando los datos esten cargados los mostrara en la pagina. (asynchronous: false)
//
function SendHttpRequest(argumentos, serverPage, objID, ShowImage, asincronismo) {
    if(!argumentos) { alert("Error FATAL: Argumentos inexistentes"); return(false); }
    serverPage         = (!serverPage?libfunc:serverPage);
    objID                  = (!objID?'principal':objID);
    var obj             = document.getElementById(objID);
    var HTMLResp  = "";
    switch ( ShowImage ){
        case 1:
              HTMLResp = "<center><img border='0' src='/img/cargando.gif'></center>";
                break;
        case 2:
              HTMLResp = "<center><img border='0' src='/img/download_loader.gif'></center>";
                break;
        case 3:
              HTMLResp = "<center><img border='0' src='/img/cargando2.gif'></center>";
                break;
        case 4:
              HTMLResp = "<center><img border='0' src='/img/cargando4.gif'></center>";
                break;
        case 5:
              HTMLResp = "<center><img border='0' src='/img/cargando5.gif'></center>";
                break;
        case 6:
              HTMLResp = "<center><img border='0' src='/img/cargando6.gif'></center>";
                break;
        case 7:
              HTMLResp = "<center><img border='0' src='/img/cargando3.gif'></center>";
                break;
        default:
              HTMLResp = "";
              break;
    }
    obj.innerHTML = HTMLResp;
    new Ajax.Updater(objID, serverPage, {
                    method: 'post',
                                        parameters : argumentos,
                    asynchronous: asincronismo,
                    onComplete: function(resp) { new Ajax.Updater('logs', serverPage, {method: 'post',parameters : 'OPCION=SHOWLOGS'}); },
                                        onFailure : function(resp) { alert('Error:\n\nPAGE:'+serverPage+'\nARGS:'+argumentos+'\n'+resp.responseText); }
                                        });
}

function Request(serverPage, parameters, asincronismo){
	new Ajax.Request(serverPage, {
		               method: 'post',
		               asynchronous: asincronismo,
		               postBody: parameters
		               })
	}	
	
	
function IsNumber(evt){
var nav4 = window.Event ? true : false;
// Backspace = 8, Enter = 13, ‘0' = 48, ‘9' = 57, ‘.’ = 46
//var key = nav4 ? evt.which : evt.keyCode;  No funciona con IE
var key = (evt.keyCode) ? evt.keyCode : evt.which;  // Funciona con FF e IE
return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}	
	
function Abrir_Ventana(pagina){
	 window.open(pagina);
	}
	

 function cambiarDiv(div,check){
 	
  if(document.getElementById(check).checked == false){
  document.getElementById(div).style.display = "none";
  }
  else{
  document.getElementById(div).style.display = "block";
  }
}
	
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

function Iniciar_Pagina(){
	 SendHttpRequest('OPCION=NOMBRE', colegio, 'nombre' ,0,false);
	 Mostrar_Login();
	 Mostrar_Menu();
	 Mostrar_Links();
	 Mostrar_Inicio();

	}

function Mostrar_Login(){
	SendHttpRequest('OPCION=MOSTRAR_LOGIN', colegio, 'login',0,true);
	}	
	
function Mostrar_Menu(){
	SendHttpRequest('OPCION=MOSTRAR_MENU', colegio, 'menu',0,true);
	}	
	
function Mostrar_Links(){
	SendHttpRequest('OPCION=MOSTRAR_LINKS', colegio, 'linksint',0,true);
	}	
	
function Mostrar_Inicio(){
	Resumen_Cursos("");
	SendHttpRequest('OPCION=MOSTRAR_INICIO', colegio, 'principal' ,0,true);
	}

function Mostrar_Datos(){
	SendHttpRequest('OPCION=MOSTRAR_DATOS', colegio, 'principal' ,0,true);
	}
	
function Crear_Administrador(){
	SendHttpRequest('OPCION=CREAR_ADMINISTRADOR', colegio, 'principal' ,0,true);
	}
	
function Ocultar_Password(tilde,pass){

 var check = $(tilde).checked;
 var primero = $(pass);
 var valor=$(pass).value;
 var ides=$(pass).id;
 var clase = $(pass).className;
 var seg= document.createElement('input');
     seg.setAttribute('value',valor);
     seg.setAttribute('id',ides);
     seg.setAttribute('class',clase);
	 if(!check){
	 	  seg.setAttribute('type','text');
      primero.parentNode.replaceChild(seg,primero);
	 	  
	 	}else{
	 		 seg.setAttribute('type','password');
       primero.parentNode.replaceChild(seg,primero);
	 		
	 		}
	
	}
	
function Nuevo_Administrador(chequeo){
//	var chequeo = $('contrasenaadmin').value;
	SendHttpRequest('OPCION=NUEVO_ADMINISTRADOR&CHEQUEO='+chequeo, colegio, 'principal' ,0,true);
	}	
	
function Nuevo_Usuario(){
//	var chequeo = $('contrasenaadmin').value;
	SendHttpRequest('OPCION=NUEVO_USUARIO', colegio, 'principal' ,0,false);
	//Img_Seguridad();
	}

function Img_Seguridad(){
	 SendHttpRequest('OPCION=IMG_SEGURIDAD', colegio, 'imgseg' ,0,false);
	 document.getElementById('imagenseguridad').reload;//contentDocument.location.reload(true);
	}
	
function Cancelar(){
	var cantidad = document.getElementsByClassName('usuario').length;
	for (var i=0; i < cantidad; i++){
		 document.getElementsByClassName('usuario')[i].value = '';
		}
	
	}	
	
function Prueba_Usuario(valor){
		SendHttpRequest('OPCION=PRUEBA_USUARIO&VALOR='+valor, colegio, 'estanombre' ,0,false);
		if ($('pasa').value == 1){
			 $('nombreusuario').value = '';
			}
	}
	
function Grabar_Usuario(clase, mail, mail2, cont, cont2){
	/*   var codigo = $('codigoseg').value;
	   if (codigo != pass){
	   	  alert('El código de Seguridad es incorrecto.');
	   	  return;
	   	}
	 */
	  var cantidad = document.getElementsByClassName(clase).length;
    //primero chequeo que no esten en blanco..
	  for (var i=0; i < cantidad; i++){
        var valor = document.getElementsByClassName(clase)[i].value;
        var ides = document.getElementsByClassName(clase)[i].id;
        if (valor == ""){
        	  alert('falta algun dato');
        	  return;
        	}
   //ahora chequea que la direccion de email este bien escrita..
       /* if (ides == mail){
	       	         var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
                   if (!filter.test(valor)){
                     alert("La dirección de email es incorrecta."); 
                     return;
                }
                	      
        }*/// del chequeo del mail
                          
	  	}//del chequeo
	  var conto = $(cont).value;
	  var contc = $(cont2).value;
	  if (conto != contc){
	  	  alert('Las contraseñas no coinciden!!!');
	  	  return;
	  	}
	  var mailo = $(mail).value;
	  var mailc = $(mail2).value;
	  if (mailo != mailc){
	  	  alert('Los mails no coinciden!!!');
	  	  return;
	  	}
	  var usuario = $('nombreusuario').value;
	  var contrasena = $('contrasena').value;
	  var mail = $('email').value;
	  var nombre = $('nombrereal').value;
	  var apellido = $('apellido').value;
	  var ciudad = $('ciudad').value;
	  var tipo = $('tipousuario').value;
	  var titulo = $('titulo').value;
	  var matricula = $('matricula').value;
  
	  	SendHttpRequest('OPCION=GRABAR_USUARIO&USUARIO='+usuario+'&CONT='+contrasena+'&MAIL='+mail+'&NOMBRE='+nombre+'&APELLIDO='+apellido+'&CIUDAD='+ciudad+'&TITULO='+titulo+'&MATRICULA='+matricula+'&TIPO='+tipo, colegio, 'principal' ,0,true);
		
	  //	Request(colegio,'OPCION=GRABAR_USUARIO&USUARIO='+usuario+'&CONT='+contrasena+'&MAIL='+mail+'&NOMBRE='+nombre+'&APELLIDO='+apellido+'&CIUDAD='+ciudad+'&TITULO='+titulo+'&MATRICULA='+matricula+'&TIPO='+tipo,true);
	  	// falta el php de esto
	  //	Mostrar_Inicio();
	  	
	}// de la funcion
	
function Log_In(){
	 var nombre = $('nomusuario').value;
	 var cont = $('cont').value;
	 SendHttpRequest('OPCION=LOG_IN&USUARIO='+nombre+'&CONT='+cont, colegio, 'login' ,0,false);
	 SendHttpRequest('OPCION=NOMBRE', colegio, 'nombre' ,0,false);
	}

function Log_In_Sec(func,arg1,arg2){
   var nombre = $('nombresec').value;
	 var cont = $('passsec').value;
	 SendHttpRequest('OPCION=LOG_IN&USUARIO='+nombre+'&CONT='+cont, colegio, 'login' ,0,false);
	 SendHttpRequest('OPCION=NOMBRE', colegio, 'nombre' ,0,true);
	 SendHttpRequest('OPCION='+func+'&'+arg1+'='+arg2, colegio, 'principal' ,0,false);
	}

function Log_Off(){
	  Request( colegio,'OPCION=LOG_OFF',false);
	  Iniciar_Pagina();
	}
	
function Nuevo_Curso(){
	  SendHttpRequest('OPCION=NUEVO_CURSO', colegio, 'principal' ,0,false);
	  
	}

	

function Nueva_Charla(){
	  SendHttpRequest('OPCION=NUEVA_CHARLA', colegio, 'principal' ,0,false);
	  
	}

function Prueba_Curso(valor){
		SendHttpRequest('OPCION=PRUEBA_CURSO&VALOR='+valor, colegio, 'estacurso' ,0,false);
		if ($('pasa').value == 1){
			 $('nombrecurso').value = '';
			}
	}
	
function Crear_Curso(){
	  var nombre = $('nombrecurso').value;
	  var cont = $('contrasena').value;
	  var fechai = $('fechainicio').value;
	  var fechaf = $('fechafinaliza').value;
	  var duracion = $('duracion').value;
	  var costo = $('costo').value;
	  var descripcion = $('descripcion').value;
	  var inscripcion = $('inscripcion').value;
	 
	  SendHttpRequest('OPCION=CREAR_CURSO&NOMBRECURSO='+nombre+'&CONT='+cont+'&FECHAINICIO='+fechai+'&FECHAFINALIZA='+fechaf+'&DURACION='+duracion+'&COSTO='+costo+'&DESCRIPCION='+descripcion+'&INSCRIPCION='+inscripcion, colegio, 'principal' ,0, false);
	    Subir_Archivos(4);
	  
	}		

function Crear_Charla(){
	  var nombre = $('nombrecharla').value;
	  var fecha = $('fecha').value;
	  var hora = $('horario').value;
	  var disertante = $('disert').value;
	  var lugar = $('lugar').value;
	
	  SendHttpRequest('OPCION=CREAR_CHARLA&NOMBRECHARLA='+nombre+'&FECHA='+fecha+'&HORA='+hora+'&DISERTANTE='+disertante+'&LUGAR='+lugar, colegio, 'principal' ,0, false);
	  
	}		
	
function Borrar_Curso(codigo,nombre){
	if (confirm('Escta seguro que desea Borrar el curso:\n'+nombre+'')){
  //SendHttpRequest('OPCION=BORRAR_CURSO&CODIGO='+codigo, colegio, 'principal' ,0,false);
  Request( colegio,'OPCION=BORRAR_CURSO&CODIGO='+codigo,false);
  Mostrar_Login();
  Todos_Cursos();
  }
  
}

function Borrar_Charla(codigo,nombre){
	if (confirm('Escta seguro que desea Borrar el curso:\n'+nombre+'')){
  //SendHttpRequest('OPCION=BORRAR_CURSO&CODIGO='+codigo, colegio, 'principal' ,0,false);
  Request( colegio,'OPCION=BORRAR_CHARLA&CODIGO='+codigo,false);
  Charlas_Actuales();
  }
}

function Check_All(clase,todas){
	 var cant = document.getElementsByClassName(clase).length;
	// var todas = document.getElementsById('checkall').checked;
	 for (var i = 0; i <= cant; i++){
	 	  if (todas != false){
	 	  document.getElementsByClassName(clase)[i].checked = true;
	 	 }else{
	 	 	 document.getElementsByClassName(clase)[i].checked = false;
	 	 	}
	 	}
	}

function Borrar_Usuario(clase){
	  var cant = document.getElementsByClassName(clase).length;
	  // var todas = document.getElementsById('checkall').checked;
	  for (var i = 0; i < cant; i++){
	 	  if (document.getElementsByClassName(clase)[i].checked == true){
	 	    var usu = document.getElementsByClassName(clase)[i].value;
	 	    Request( colegio,'OPCION=BORRAR_USUARIO&USUARIO='+usu,false);
	 	 	}
	 	}
	 	Ver_Usuarios();
	}

function Cambiar_Inscripcion(codigo,num){
	  Request( colegio,'OPCION=CAMBIAR_INSCRIPCION&CODIGO='+codigo+'&NUM='+num,false);
	  Todos_Cursos();
	}

function Subir_Imagen(tipo,nombre){
	 if (tipo > 3){
	 	  window.open('./funciones/uploadimagen.php?NOMBRE='+nombre,'subidaimagen',"width=500,height=400,scrollbars=NO, top=400, left=400, Resizable=NO, Directories=NO, Titlerar=NO, Toolbar=NO");
	 	} 
	}

function Subir_Archivos(tipo){
	 if (tipo > 3){
	 	  window.open('./funciones/uploadarchivos.php','subida',"width=500,height=400,scrollbars=NO, top=200, left=400, Resizable=NO, Directories=NO, Titlerar=NO, Toolbar=NO");
	 	} 
	} 

function Mostrar_Clases(curso){
	curso = document.getElementById('codigocurso').value;
	SendHttpRequest('OPCION=MOSTRAR_CLASES&CURSONUM='+curso, upload, 'radios' ,0,false);
	}
	
function Nueva_Clase(){
	SendHttpRequest('OPCION=NUEVA_CLASE', upload, 'radios' ,0,false);
	}
	
function Agrega_Clase(){
 	   curso = document.getElementById("codigocurso").value;
 	   nombre = document.getElementById("nomclase").value;
 	   disertante = document.getElementById("disert").value;
 	   info = document.getElementById("info").value;
 	   fecha = document.getElementById("fecha").value;
 	  //SendHttpRequest('OPCION=AGREGA_CLASE&CURSO='+curso+'&NOMBRE='+nombre+'&DISERTANTE='+disertante+'&INFO='+info+'&FECHA='+fecha, upload, 'radios' ,0,false);
 	  Request(upload,'OPCION=AGREGA_CLASE&CURSO='+curso+'&NOMBRE='+nombre+'&DISERTANTE='+disertante+'&INFO='+info+'&FECHA='+fecha,false);
 	  Mostrar_Clases();
 	}
	
function alertaprueba(){
	alert('hola es una prueba');
	}
	
function Resumen_Cursos(opcion){
	  SendHttpRequest('OPCION='+opcion, colegio, 'informes' ,0,false);
	}	

function Resumen_Charlas(opcion){
	  SendHttpRequest('OPCION='+opcion, colegio, 'informes' ,0,false);
	}
	
function Cursos_Actuales(){
	  Resumen_Cursos("RESUMEN_CURSOS");
	  SendHttpRequest('OPCION=CURSOS_ACTUALES', colegio, 'principal' ,0,false);
	  
	}	

function Ver_Usuarios(){
   	SendHttpRequest('OPCION=VER_USUARIOS', colegio, 'principal' ,0,false);
	}

function Charlas_Actuales(){
	  Resumen_Charlas("RESUMEN_CHARLAS");
	  SendHttpRequest('OPCION=CHARLAS_ACTUALES', colegio, 'principal' ,0,false);
	}	

function Todos_Cursos(){
	  SendHttpRequest('OPCION=TODOS_CURSOS', colegio, 'principal' ,0,false);
	  
	}	

function Proximos_Cursos(){
	  Resumen_Cursos("RESUMEN_CURSOS");
	  SendHttpRequest('OPCION=PROXIMOS_CURSOS', colegio, 'principal' ,0,false);
	  
	}	

function Inscripcion_Curso(codigo){
	//alert(codigo);
	  SendHttpRequest('OPCION=INSCRIPCION_CURSO&CODIGO='+codigo, colegio, 'principal' ,0,false);
	}	
	
function Matricular_Curso(codigo){
	  var cont = $('contcurso').value;
	  SendHttpRequest('OPCION=MATRICULAR_CURSO&CODIGO='+codigo+'&CONTCURSO='+cont, colegio, 'principal' ,0,false);
	  Mostrar_Login();
	}

function Ver_Material_Extra(){
	  SendHttpRequest('OPCION=VER_MATERIAL_EXTRA', colegio, 'principal' ,0,false); 
	}
	
function Eliminar_arch(directorio,segunda){
	if (confirm('Escta seguro que desea Borrar este Archivo?')){
	  Request(colegio,'OPCION=ELIMINAR_DIR&DIRECTORIO='+directorio,false);
	  SendHttpRequest('OPCION='+segunda, colegio, 'principal' ,0,false);
	 }
	}
	
function Eliminar_mat_extra(directorio,segunda,archivo){
	  if (confirm('Escta seguro que desea Borrar este Archivo?')){
	    Request(colegio,'OPCION=ELIMINAR_MAT_EXT&ARCHIVO='+archivo,false);
	    Request(colegio,'OPCION=ELIMINAR_DIR&DIRECTORIO='+directorio,false);
	    SendHttpRequest('OPCION='+segunda, colegio, 'principal' ,0,false);
	  }
	}
	
function Mostrar_Autoridades(){
	  SendHttpRequest('OPCION=MOSTRAR_AUTORIDADES', colegio, 'guia' ,0,false);
	  showdiv('guia');
	}
	
function hidediv(div) {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(div).style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.div.visibility = 'hidden';
}
else { // IE 4
document.all.div.style.visibility = 'hidden';
}
}
}

function showdiv(div) {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(div).style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.div.visibility = 'visible';
}
else { // IE 4
document.all.div.style.visibility = 'visible';
}
}
} 


