function Funcion_Ajax_Obtener_formulario_acceso()
{
  if (document.getElementById("acceso2").style.display=="none")   
  {
    document.getElementById("acceso2").style.display="block";
  }
  else
  {
    document.getElementById("acceso2").style.display="none";
  }
}

function Funcion_Ajax_Obtener_contacto_fichas()
{
  if (document.getElementById("contacto_ficha").style.display=="none")   
  {
    document.getElementById("contacto_ficha").style.display="block";
  }
  else
  {
    document.getElementById("contacto_ficha").style.display="none";
  }
}


function irA2(url)
{
	document.location.href=url.value;
} 


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(access_fix);

function access_fix()
{
	// Fix para link de ayuda en el formulario de "Area Privada"
	var el = document.getElementById("opciones_acceso");
	if(el) el.innerHTML = '<li><a href="http://www.imtrust.com/es/ayuda/ayuda_privada.html" title="ayuda para acceder al sitio">No puedo acceder</a></li><li><a href="http://www.imtrust.com/es/contactanos/contacto3.aspx" title="Crea tu clave">Solicitar clave</a></li>';

	// Fix para "action" en el formulario de "Area Privada"
	el = document.getElementById("form_acceso_intern");
	if(!el) el = document.getElementById("form_acceso");
	// Cambiar ruta script acceso a intralgo.
	if(el) el.action = "http://imtrust.corredordebolsa.cl/sitioprivado/";
	
}



    function formatea_rut(){
    var tmpstr = "";
    var intlargo = document.acceso.In_usuario.value

     if (intlargo.length > 0){ 	

    	    cRut = document.acceso.In_usuario.value
    	    largo = cRut.length;

        if ( largo < 2 )
        {
            alert('Debe ingresar su rut completo');
            document.acceso.In_usuario.focus();
            return false;
        }
        for ( i=0; i < cRut.length ; i++ )
          if ( cRut.charAt(i) != ' ' && cRut.charAt(i) != '.' && cRut.charAt(i) != '-' )
          {
               tmpstr = tmpstr + cRut.charAt(i);
          }
          Rut = tmpstr;
          cRut=tmpstr;
          largo = cRut.length;

          if ( largo > 2 )
            Rut = cRut.substring(0, largo - 1);
          else
            Rut = cRut.charAt(0);

            dv = cRut.charAt(largo-1);

            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() )
        {
	      alert('El rut ingresado es incorrecto');
	      document.acceso.In_usuario.focus();
	      document.acceso.In_usuario.value = ""	
          return false;
        }

    // Limpio los guiones
    out = "-"; // replace this
    add = ""; // with this
    temp = "" + (document.acceso.In_usuario.value); // temporary holder

    while (temp.indexOf(out)>-1) {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add + 
    temp.substring((pos + out.length), temp.length));
    }

    // Limpio los puntos
//    out2 = "."; // replace this
    out2 = "."; // replace this
    add2 = ""; // with this
    temp2 = "" + temp; // temporary holder

    while (temp2.indexOf(out2)>-1) {
    pos2= temp2.indexOf(out2);
    temp2 = "" + (temp2.substring(0, pos2) + add2 + 
    temp2.substring((pos2 + out2.length), temp2.length));
    }

    // Cambio la k por K
    out3 = "k"; // replace this
    add3 = "K"; // with this
    temp3 = "" + temp2; // temporary holder

    while (temp3.indexOf(out3)>-1) 
    {
      pos3= temp3.indexOf(out3);
      temp3 = "" + (temp3.substring(0, pos3) + add3 + 
      temp3.substring((pos3 + out3.length), temp3.length));
    }

     // **********************************
     // texto = camtexto.value;
      texto = temp3;
      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;
     
      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 + '.';
          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);
     
      document.acceso.In_usuario.value = invertido
      // ***********************************
     }  
    }  
      
