<!--
function Libreta(txt){
   libreta = txt.substr(0,(txt.length - 1));
   dlib = txt.charAt(txt.length - 1);
   var dvr = '0';
   suma = 0;
   mul  = 2;
   for (i= libreta.length -1 ; i >= 0; i--){
      suma = suma + libreta.charAt(i) * mul
      if (mul == 7)
        mul = 2;
      else    
        mul++;
    }
    res = 11 - suma % 11
    if (res > 9)
    {
      dvr = '0';
    }
    else 
    {
      dvr = res + "";
    }
    if ( dvr != dlib )
    { return false; }
    else
    { return true }
}


function getS(s){ return s.options[s.selectedIndex]; }

function getST(s){ return getS(s).text; }

function getSV(s){ return getS(s).value; }

function getSIndex(s,v){
   var idx=-1;
   for(var i=0;i<s.length;i++){
      if(s.options[i].value==v){ idx=i; break; }
   }
return idx;
}

String.prototype.limit=function(max,mas){
   var txt='';
   for(i=0;i<this.length;i++){
      if(i<max){ txt+=this.charAt(i); }
   }
   if(this.length>max){ txt+=mas; }
return txt;
};

String.prototype.alfanumerico_u=function(){
   var pat=/^[a-zA-Z]([\w|_]+)$/;
   return pat.test(this);
};

String.prototype.alfanumerico=function(){
   var pat=/^([a-zA-Z0-9]+)$/;
   return pat.test(this);
};

String.prototype.ltrim=function(){
   return this.replace(/^\s+/g,'');
};

String.prototype.rtrim=function(){
   return this.replace(/\s+$/g,'');
};

String.prototype.trim=function(){
   return this.ltrim().rtrim();
};

String.prototype.empty=function(){
   return (this.length==0)?true:false;
};

function isNum(n){
   var s=new String(n);
   if(n.length==0){return false; }
   var num=new String('0123456789');
   var bool=true;
   $A(s).each(function(v,i){
      if(num.indexOf(v)==-1){ bool=false; }
   });
return bool;

/*
   valor = parseInt(n);
   if (isNaN(valor)) {  return false; } 
   else{ return true; }
 */
}

function valEmail(email){
   var patron= /^([a-zA-Z0-9_ñÑ\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return patron.test(email);
}

function ResetForm(frm){
   Form.reset(frm);
}

var CONTENBack="";

function valRut(rut){
   var Rut=new RUT(rut);
   if(Rut.Error()){
      alert(Rut.getError());
      return false;
   }
   else{
      if(!Rut.valida()){
         alert('Rut es Incorrecto');
         return false;
      }
   }
return Rut.get();
}

function UNDefined(el){
   return (typeof(el)=='undefined')?true:false;
}

function SwapBGC(obj,bg,c){
   if(!(typeof(obj)=='object')) return
   if(!UNDefined(bg)){ obj.style.backgroundColor=bg;  }
   if(!UNDefined(c)){ obj.style.color=c; }
   //alert(bg);
return
}

function checked(id){
   return $(id).checked=true;
}

function SWImage(idImg, img){
   $(idImg).src=img;
}

function showLoad(id){
   id=(typeof(id)=='undefined')?'DContent':id;
   $(id).innerHTML='<IMG src="'+js_NIVEL_SINAB+'img/load.gif" />';
return
}

function showMiniLoad(id,anadir,pos){
   var img='<IMG src="'+js_NIVEL_SINAB+'img/mini_load.gif" />';
   id=(typeof(id)!='undefined')?id:-1;
   if(id==-1) return
   if(pos==1)
   $(id).innerHTML=((anadir==1)?$(id).innerHTML:'')+img;
   else
   $(id).innerHTML=img+((anadir==1)?$(id).innerHTML:'');
return
}

function CargaLogin(){
   showLoad();
   url=js_NIVEL_BECAS+'php/login.php';
   pars='';
   var myAjax = new Ajax.Request(url,
   { 
     method: 'post',
     parameters: pars,
     onComplete:function(t)
     {
                   $('DContent').innerHTML=t.responseText+'\n<DIV id="Clear"></DIV>';
     }
   });
}


function displayGroup(id,ini,estado){
   for(var i=ini;$(id+''+i);i++){
      if(estado==0) $(id+''+i).hide();
      if(estado==1) $(id+''+i).show();
   }
return true;
}

function msjF(obj){
   alert(obj.m);
   if(typeof(obj.o)!='undefined' && obj.o){ obj.o.focus(); }
   if(typeof(obj.s)!='undefined' && obj.s){ obj.o.select(); }
return false;
}

function buscaAlumno(CRut){
   url=js_NIVEL_BECAS+'php/getAlumno.php';
   var Rut=new RUT($F(CRut));
   if(Rut.Error()){
      alert(Rut.getError());
	$(CRut).focus();
      return false;
   }
   else{
      if(!Rut.valida()){
         alert('Rut es Incorrecto');
	   $(CRut).focus();
	   $(CRut).select();
         return false;
      }
   }   
   var pars="rut="+Rut.get();
   var b=true;
   showMiniLoad('loadRut',1,1);
   var myAjax = new Ajax.Request(url,
   {
     method: 'post',
     parameters: pars,
     onComplete:function(t)
     {
	  $('loadRut').innerHTML='';
        var n=((t.responseText));
	  if(n==0){	
		var txt='Estudiante no Registrado... ';
		txt+='<A href="registra_estudiante.php?rut='+Rut.get()+'&dv='+Rut.getDv()+'" >';
		txt+='<STRONG>Registrar Aqu&iacute;</STRONG></A>';
		$('loadRut').innerHTML=txt;
	  }
	  else if(n==-1){	alert('Error'); }
	  else{
		$('loadRut').innerHTML=n;
        }
     }
   });
return false;
}

function EnvioRegistrarEstudiante(Rut,Dv){
   var c=confirm('Confirmar envio');
   if(!c){ return false; }
   return window.location.href="registra_estudiante.php?rut="+Rut+"&dv="+Dv;
}

function AsignaEstudiante(frm){
   var frm=$(frm);
   var r=false;
   var Rut=new RUT($F(frm.RutPostulante));
   if(Rut.Error()){
      alert(Rut.getError());
	frm.RutPostulante.focus();
      return false;
   }
   else{
      if(!Rut.valida()){
         alert('Rut es Incorrecto');
         return false;
      }
   }
   for(var i=0;i<frm.modalidad.length;i++){
      if(frm.modalidad[i].checked){ break; }
   }

   if($F(frm.discapacidad)=='-'){ return msjF({m:'Debes Indicar el Discapacidad',o:frm.discapacidad}); }
   if($F(frm.nivel)=='-'){ return msjF({m:'Debes Indicar el Nivel',o:frm.nivel}); }
   frm.RutPostulante.value=Rut.get();
   frm.DvPostulante.value=Rut.getDv();
   var T=new Array('Postulación','Renovación');
   var S=new Array('Primer Semestre','Segundo Semestre');
   var txt='¿Está seguro de ingresar el Formulario\?\n';
   txt+='Datos:\n';
   txt+='Modalidad : '+T[parseInt($F(frm.modalidad[i]))-1].toUpperCase()+'\n';
   txt+='Discapacidad : '+getST(frm.discapacidad).toUpperCase()+'\n';
   txt+='Nivel : '+getST(frm.nivel).toUpperCase()+'\n';
   var c=confirm(txt);
   if(!c){ return false; }
   frm.action='confirmar_crea_formulario.php';
   frm.method='post';
return true;
}

function Display(id){
   if(String($(id).innerHTML).length==0){ $(id).innerHTML=('<P>&nbsp;</P>'); }
   Effect.toggle($(id),'appear');
return Element.visible(id);
}

function DShow(id,m){
   if(m){ $(id).show(); }
   else{ $(id).hide(); }
return true;
}


function ShowPuntajes(idC){
   if(!Display(idC)){
      showLoad(idC);
      var url=js_NIVEL_BECAS+'php/puntos.php';
      var pars='';
      var myAjax = new Ajax.Request(url,
      {
        method: 'post',
        parameters: pars,
        onComplete:function(t)
        {
          $(idC).innerHTML=t.responseText;
        }
      });
   return true;
   }
}

function valFORMBeca(frm){
   frm=$(frm);
   var b1=$(frm.Beca);
   if($F(b1)=='-'){ return msjF({m:'Debes Seleccionar una Beca',o:b1}); }
   frm.action=js_NIVEL_BECAS+'php/graba_beca.php';
   frm.method="post";

   	   
return true;
}


function valFORMExcep(frm){
   frm=$(frm);
   if($F(frm.estado)=='-'){ return msjF({m:'Debes Indicar Estado de Excepción',o:frm.estado}); }
   if(!UNDefined(frm.primer_mes) && $F(frm.estado)==13 && $F(frm.primer_mes)=='-'){ return msjF({m:'Debes Indicar Primer mes de Práctica',o:frm.primer_mes}); }
   if(!UNDefined(frm.meses_practica) && $F(frm.estado)==13 && $F(frm.meses_practica)=='-'){ return msjF({m:'Debes Indicar Número de mes de Práctica',o:frm.meses_practica}); }
   frm.action=js_NIVEL_BECAS+'php/graba_excepcion.php';
   frm.method="post";
return true;
}


















/*+---------------------------------------------------------------------------------------------+*\
+--------------------------------------------------------------------------------------------------+



	Class		: RUT
	Parametros	: String, texto que representa rut, acepta '.', '-', y ' '

	METODOS QUE SE DEBEN UTILIZAR ( % = sin parametros )

	1) format()	: %, rotorna el rut formateado a xx.xxx.xxx-dv
	2) Error()		: %, retorna true en caso de existir error de formato en el rut
	3) getNError()	: %, retorna el número del error, -1 = no errores
	4) getError()	: %, retorna un error descriptivo
	5) getOriginal()	: %, retorna el rut original, el que es pasado como parametro
	6) get()		: %, retorna el cuerpo del rut, ej: xx.xxx.xx-dv => retorna xxxxxxxx
	7) getDv()	: %, retorna el dv correcto del rut
	8) valida()	: %, retorna true si el rut es valido

	USO
		var Rut=new RUT('11111111-1');
		if(Rut.Error()){
		   alert(Rut.getError());
		}
		else{
		   if(Rut.valida()){
		      //Rut valido
		   }
		   else{
		      //Rut no valido
                             }
		}


+--------------------------------------------------------------------------------------------------+
 \*+--------------------------------------------------------------------------------------------+*/


var RUT=Class.create();

RUT.prototype={
   initialize:function(rut){
       this.Orut=new String(rut);
       this.Dvs=new String("123456789K0");
       this.error=false;
       this.nerror=-1;
       this.prepara()
       this.valFormato();
   },
   prepara:function(){
      var cr=this.Orut;
      if(cr!=""){
         cr=cr.replace(/[\.|\-|\s]+/g,"");
         cr=cr.replace(/[<]+/g,"&lt;");
         cr=cr.replace(/[>]+/g,"&gt;");
         this.rut=cr.substr(0,cr.length-1);
         this.dv=new String(cr.substr(cr.length-1,cr.length)).toUpperCase();
      }
      if(String(this.rut)=='undefined') this.rut="";
      if(String(this.dv)=='undefined') this.dv='-1';
      return this.rut;
   },
   clear:function(){ return this.rut; },
   valFormato:function(){
      if(this.rut.length==0){ this.error=true; return this.nerror=0; }
      if(this.rut.length!=String(parseInt(this.rut)).length){ this.error=true; return this.nerror=1; }
      if(this.Dvs.indexOf(this.dv)==-1){ this.error=true; return this.nerror=2; }
   },
   format:function(){
      this.prepara();
      var r=$A(new String(this.rut));
      var temp="";
      var c=0;
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
         if(((++c)<r.length) && (c%3)==0) temp+=".";
      });
      r=$A(temp);
      temp="";
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
      });
      return temp+"-"+this.dv;
   },
   Error:function(){
     return this.error
   },
   getNError:function(){
      return this.nerror;
   },
   getError:function(){
      if(this.nerror==-1) return "No se han identificado errores";
      var errores=new Array();
      errores[errores.length]="Ingrese Rut";
      errores[errores.length]="Rut '"+this.rut+"' contiene caracteres no validos";
      errores[errores.length]="Digito Verificador '"+this.dv+"' no es un caracter correcto";
      return errores[this.nerror];
   },
   getOriginal:function(){
      return this.Orut;
   },
   get:function(){
      return this.rut;
   },
   getDv:function(){
      if(this.error){ return -1; }
      var r=parseInt(this.rut);
      var m=1;
      var suma=0;
      do{
         suma+=(r%10)*(m=(m<7)?++m:2);
         r=parseInt(r/10);
      }while(r!=0);
      return this.Dvs.charAt(10-(suma%11));  
   },
   valida:function(){
      if(this.error){ return false; }
      return (this.getDv()==this.dv)?true:false;
   }
}

//End-->
