var nav4 = window.Event?true:false;

function MM_findObj(n, d) { 
    //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}
function MM_swapImage() { 
    //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
		}
}

function MM_swapImgRestore() { 
    //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { 
    //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
    }
}
function muevemes(mes,anio){
	frmc=window.document.frm;
	pag="curso_prof1.php";
	frmc.mes.value=mes;
	frmc.ano.value=anio;
	frmc.submit();
}
function galeria(doc){
	frmc=window.document.frm;
	frmc.action="gal_01.php";
	frmc.doc.value=doc
	frmc.submit();
}
function novedad(doc){
	frmc=window.document.frm;
	frmc.action="nov.php";
	frmc.doc.value=doc
	frmc.submit();
}
function curso(doc,tipo){
	if(tipo==1){
		pag="curso_com1.php";
	}else{
		pag="curso_prof1.php";
	}
	frmc=window.document.frm;
	frmc.action=pag;
	frmc.doc.value=doc
	frmc.submit();
}
function inscripcioncurso(dd,mm,yy,id){
	frmc=window.document.frm;
	frmc.action="form.php";
	frmc.ano.value=yy;
	frmc.mes.value=mm;
	frmc.dia.value=dd;
	frmc.doc.value=id;
	frmc.submit();
}

function valida_email(field){

  //------------------------------

  with (field)

  {

      if (field.value.length==0) {

          return true;

      }

      apos=value.indexOf("@");

      dotpos=value.lastIndexOf(".");

      if (apos<1||dotpos-apos<2) {

          alert("El correo no es valido");

          field.value="";

          field.focus();

          return false;

      }

      else {

          return true;

      }

  }

}



function valida_string_extendido(objeto,largo,descripcion){       

    //-----------------------------

    var i;

    var allowedac;

    var retorno;

    var cadena = objeto.value;

    retorno = true;

    allowedac = "0123456789-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \n.():;/!?@+*,#&$";

    for ( i=0; i < cadena.length; i++ ){

        if (allowedac.indexOf(cadena.charAt(i)) < 0 && (cadena.charAt(i)!=String.fromCharCode(13) && cadena.charAt(i)!= String.fromCharCode(209) && cadena.charAt(i)!=String.fromCharCode(241))){

            retorno = false;

        }

    }

    if(cadena.length==0){

        alert("Debe ingresar el campo "+descripcion);

        return false;

    }

    if (cadena.length<largo && cadena.length>0) {

        retorno = false;

    }

    if (!retorno) {

        alert('En el campo '+descripcion+' puede ingresar solo caracteres alfanumericos y largo minimo '+largo);

        objeto.value = "";

        objeto.focus();

    }

    return retorno;

}



function nuevoAjax() { 	

    var xmlhttp=false;

    try  {

        // Creacion del objeto AJAX para navegadores no IE

        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 	}

    catch(e) {

        try {

            // Creacion del objet AJAX para IE

           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

       }

       catch(E) { xmlhttp=false; }

   }

   if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }

   return xmlhttp; }

   


function acceptNum2(evt) {

    var key = nav4 ? evt.which : evt.keyCode;

    return (key <= 13 || (key >= 48 && key <= 57));}

	


function limpianumero(numero){

	var newnumero="";

	for(i=0;i<numero.length;i++){

		if(numero.charAt(i)!='.' || numero.charAt(i)!='.'){

			newnumero=newnumero+numero.charAt(i);

		}

	}

	return newnumero;

}


function checkCDV( dvr )

{

  dv = dvr + "";

  if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')

  {

	//alert("Debe ingresar un digito verificador valido.");	  

	return false;

  }

  return true;

}



//////////////////////////////////////////////////



function checkDV( crut )

{



  var error = false; 

  largo = crut.length;

  if ( largo < 2 )

  {

        error = true;

  }

  if ( largo > 2 )

    rut = crut.substring(0, largo-1);

    dv = crut.charAt(largo-1);

    checkCDV( dv );



  if ( rut == null || dv == null )

      return 0;



  var dvr = '0';



  suma = 0;

  mul  = 2;



  for (i= rut.length-1  ; i >= 0; i--)

  {

    suma = suma + rut.charAt(i) * mul;

    if (mul == 7)

      mul = 2;

    else    

      mul++;

  }

  res = suma % 11;

  if (res==1)

    dvr = 'k';

  else if (res==0)

    dvr = '0';

  else

  {

    dvi = 11-res;

    dvr = dvi + "";

  }

  if ( dvr != dv.toLowerCase() )

  {

     error = true;

  }

  if(error) {

        return false;

  }

  else {

        return true;

  } 

}



function checkRutField(camtexto)

{

  var error = false;

  texto = camtexto.value;

  if(texto == "") {

        return true;

  }

  var tmpstr = "";

  for ( i=0; i < texto.length ; i++ )

    if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )

      tmpstr = tmpstr + texto.charAt(i);

  texto = tmpstr;

  largo = texto.length;

  if ( largo > 0 && largo < 2 )

  {

    error = true;

  }

  for (i=0; i < largo ; i++ )

  { 

    if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" &&texto.charAt(i) !="k" && texto.charAt(i) != "K" ) 

    {

      error = true;

    }

  }

  if (error == false){

  	var auxtext=texto.substring(0,texto.length-1);

        var auxdv=texto.substring(texto.length-1,texto.length);

	auxtext=parseInt(auxtext,10)+0;

	texto=auxtext+auxdv;

        camtexto.value=texto;

  }

  largo = texto.length;

  if ( largo > 0 && largo < 2 )

  {

    error = true;

  }

  var invertido = "";

  for ( i=(largo-1),j=0; i>=0; i--,j++ )

    invertido = invertido + texto.charAt(i);



  var dtexto = "";

  dtexto = dtexto + invertido.charAt(0);

  if(dtexto != "") {

        dtexto = dtexto + '-';

  }

  cnt = 0;



  for ( i=1,j=2; i<largo; i++,j++ )

  {

    if ( cnt == 3 )

    {

      dtexto = dtexto + '.';

      j++;

      dtexto = dtexto + invertido.charAt(i);

      cnt = 1;

    }

    else

    { 

      dtexto = dtexto + invertido.charAt(i);

      cnt++;

    }

  }

  invertido = "";

  for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )

    invertido = invertido + dtexto.charAt(i);





  camtexto.value = invertido;  

  if(texto.length > 7 ) {

        if ( !checkDV(texto) ) {

                error = true;

        }

  }



  else {

        error = true;

  }

 		

  if(error) {

        alert("El dato ingresado no es un R.U.T valido.");

        camtexto.select();

		camtexto.value="";

		camtexto.focus();

        return false;

  }

  else {

        return true;

  }

}

