<!--
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

//1. consultas y reclamos
//2. Contratos de Productos
//3. Transparencia en tasas y comisiones
//4. ¿Informacion del sistema financiero?
//5. Estadistica de reclamos de los clientes
//menus_array = new Array ('ddReclamos','ddContratos','ddTransparencia','ddInformacion');
menus_array = new Array ('ddTarjeta','ddRapicash','ddSupercash', 'ddCreditos','ddAutomotriz','ddHipotecario','ddVivienda','ddDepositos', 'ddRecargas');
//menus_array1 = new Array ('ddSupercash', 'ddRapicash', 'ddAutomotriz', 'ddCreditos', 'ddDepositos','ddEstadoCuenta');
menus_status_array = new Array ();

function showHideSwitch (theid) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[theid] != 'show') {
      switch_id.className = 'showSwitch';
	  menus_status_array[theid] = 'show';
	  document.cookie = theid+'=show';
    }else{
      switch_id.className = 'hideSwitch';
	  menus_status_array[theid] = 'hide';
	  document.cookie = theid+'=hide';
    }
  }
}
function resetMenu () {
  if (document.getElementById) {
    for (var i=0; i<menus_array.length; i++) {
      var idname = menus_array[i];
      var switch_id = document.getElementById(idname);
      var imgid = idname+'Button';
      var button_id = document.getElementById(imgid);
      if (getCookie(idname) == 'show') {
        switch_id.className = 'showSwitch';
	    menus_status_array [idname] = 'show';
	  }else{
        switch_id.className = 'hideSwitch';
	    menus_status_array [idname] = 'hide';
	  }
    }
  }
}
function resetMenu1() {
  if (document.getElementById) {
    for (var i=0; i<menus_array1.length; i++) {
      var idname = menus_array1[i];
      var switch_id = document.getElementById(idname);
      var imgid = idname+'Button';
      var button_id = document.getElementById(imgid);
      if (getCookie(idname) == 'show') {
        switch_id.className = 'showSwitch';
	    menus_status_array [idname] = 'show';
	  }else{
        switch_id.className = 'hideSwitch';
	    menus_status_array [idname] = 'hide';
	  }
    }
  }
}
  function imprimir(){ 
        parent.ifrm.focus(); 
        parent.ifrm.print(); }
function AbreSPF()
{  
    ventana=window.open('http://sisdmz01.sagafalabella.com.pe/productosfinancieros/','Simulador','width=640,height=380,resizable=no,scrollbars=yes,left=50,top=100, status=yes')	
	  ventana.focus
  }

   function enviar(){
     document.inicio.submit() 
  }
  function AbreVentana(url)
{  
    ventana=window.open(url,'Simulador','width=635,height=700,resizable=no,scrollbars=no,left=200,top=0, status=no')	
	  ventana.focus;
  }
   function AbreVentana1(url)
{  
    ventana=window.open(url,'Simulador','width=780,height=700,resizable=no,scrollbars=no,left=200,top=0, status=no')	
	  ventana.focus;
  }
  
     function AbreVentana2(url)
{  
    //ventana=window.open(url,'Simulador','width=400,height=550,resizable=no,scrollbars=yes,left=200,top=0, status=no')	
    ventana=window.open(url,'Simulador','width=420,height=630,resizable=no,scrollbars=yes,left=200,top=0, status=no')	
	  ventana.focus;
  }


function verifica_tar()
{
max=0;

if(document.inicio.TD.value=='E' || document.inicio.TD.value=='X'){
  max=8;
}
  cad = document.inicio.NUMDOC.value;
  if(document.inicio.TD.value=='E'){      
	if (cad.length < max   ||   cad.length >max  || (cad.length>max  &&  cad.length<max ))
  {
  return false;
  }}

        for (var i=0;i < cad.length;i++)
        {
                var letra=cad.substring(i,i+1)
                if (letra < "0" || letra > "9")
                {
                        return false;
                }
        }
        return true;
}




/*function verifica_pin()
{
        contlet=0;
        cad = document.inicio.sClave.value;
        cad = cad.toUpperCase();
        if (cad.length < 6)
                return false;
        for (var i=0;i < 4;i++)
        {
                var letra=cad.substring(i,i+1)
                if (letra < "0" || letra > "9")
                {
                        return false;
                }
        }
        for (var i=3;i < cad.length;i++)
        {
                var letra=cad.substring(i,i+1)
                if ((letra < "0"  || letra >"9") && (letra < "A"  || letra > "Z"))
                {
                        return false;
                }
                else
                        if (letra >= "A"  && letra <= "Z")
                        {
                                contlet++;
                        }
        }
        if (contlet > 1 )
                return true;
        else
                return false;
        return true;


} */


function verifica_pin()
{
        contlet=0;
        cad = document.inicio.PINSEG.value;
        cad = cad.toUpperCase();
        if (cad.length < 4 || cad.length>4)
                return false;
        for (var i=0;i < 4;i++)
        {
                var letra=cad.substring(i,i+1)
                if (letra < "0" || letra > "9")
                {
                        return false;
                }
        }


    	document.inicio.sClave.value = cad.substring(0,4)
        return true;


}




function verifica()
  {
        if (document.inicio.NUMDOC.value=="" && document.inicio.sClave.value=="")
        {
                alert("Por favor, ingrese su Nro. de Documento y Clave");
                document.inicio.NUMDOC.focus();
        }
        else
                if (document.inicio.NUMDOC.value=="")
                {
                        alert("Por favor, ingrese su Nro. de Documento");
                        document.inicio.NUMDOC.focus();
                }
                else
                        if (document.inicio.sClave.value=="")
                        {
                                alert("Por favor, ingrese su Clave");
                                document.inicio.sClave.focus();
                        }
                        else
                        {
                                                        if (!verifica_tar(document.inicio.NUMDOC.value))
                                                        {       alert("El Nro. de Documento ingresado no es válido");
                                                                document.inicio.NUMDOC.focus();
                                                        }
                                                        else
                                                                if (!verifica_pin(document.inicio.NUMDOC.value))
                                                                {       alert("La clave ingresada no es válida");
                                                                        document.inicio.PINSEG.focus();
                                                                }
                                                                else
                                                                {   //document.inicio.sClave.value = document.inicio.PINSEG.value;
                                                                        document.inicio.submit();
                                                                }
                                                }
  }


function AbrePopUp()
{ // AQUI ESTA EL POP DEL VHS ventana=open('/te_html/popvhs.htm','ventana1','width=320,height=230,noresize,scrollbars=no,menubar=no,toolbar=no')
}

// -------- Avant: Inicio Funcionalidad PinPad


function fToggleColor(myElement) {
var toggleColor = "#333333";
if (myElement.id == "setPass" || myElement.id == "cleanPass") {
if (myElement.color == toggleColor) {
myElement.color = "";
} else {
myElement.color = toggleColor;
   }
} else if (myElement.id == "calCell") {
for (var i in myElement.children) {
if (myElement.children[i].id == "setPass" || myElement.children[i].id == "cleanPass") {
if (myElement.children[i].color == toggleColor) {
myElement.children[i].color = "";
} else {
myElement.children[i].color = toggleColor;
            }
         }
      }
   }
}


function fSetPass(myElement){
    //alert(myElement);
    //alert("0");
    if(myElement.children["cleanPass"]!=null)
    { 
        //alert("1");
        if(myElement.children["cleanPass"].innerHTML=="Limpiar")
      {
        document.inicio.PINSEG.value =""
      }
    }
    else
    {
        //alert("e1");
        document.inicio.PINSEG.value = document.inicio.PINSEG.value + myElement.children["setPass"].innerHTML;

    }
}


function getRandomNumber()
{
   var numcheck = new Array(9);
   var resultnum = new Array();

   for (w = 0; w < 10; )
   {
      randomn = Math.random() ;
      rand1 = Math.round( 9 * randomn) ;
   if(numcheck[rand1]!=null)
   {
	if(numcheck[rand1]!="*")
	{
	   numcheck[rand1]= "*";
	   resultnum[w] = rand1;
	   w++;

	}
   }else
   {
	numcheck[rand1]= "*";
	resultnum[w] = rand1;
	w++;
   }

   }

   return resultnum;
}


function fMakePads(iCellWidth, iCellHeight, sNumTextSize, sNumTextWeight){

var randomnumbers;
randomnumbers = getRandomNumber()

//inicio de contador de numeros de 0 a 9
numero = 0;

document.write("<table border='0' cellpadding=0 cellspacing=1  >");

//creacion de trs
for (w = 1; w < 5; w++) {
document.write("<tr>")

//creacion de tds
for (d = 0; d < 3; d++) {


if(w==4 && d==1)	
{
document.write("<td align='center' class='fondo-limpiar'  colspan='2' " +  "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetPass(this) >");
  document.write("<font id=cleanPass onMouseOver='fToggleColor(this)' style='CURSOR:Hand; CURSOR: pointer ;FONT-FAMILY:Arial;FONT-SIZE:" + sNumTextSize + ";FONT-WEIGHT:" + sNumTextWeight + "' onMouseOut='fToggleColor(this)' >Limpiar</font>");
  d=4
}
else{
document.write("<td align='center'  width='" + iCellWidth + "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetPass(this)  class='fondo-digito' >");
document.write("<font  id=setPass onMouseOver='fToggleColor(this)' style='CURSOR:Hand; CURSOR:pointer ;FONT-FAMILY:Arial;FONT-SIZE:" + sNumTextSize + ";FONT-WEIGHT:" + sNumTextWeight + "' onMouseOut='fToggleColor(this)' >" + randomnumbers[numero] + "</font>");
}
document.write("</td>")
numero = numero + 1

}
document.write("</tr>");
}
document.write("</table>")
}  

//*************************************//

function validacorreo(buzon){
  tokens = StringTokenizer(buzon, '@')
  if ( tokens.length != 2 )
    return false
  else {
    if ( tokens[1].length == 0 ){
      return false
    } else {
      return true
    }
  }
}
/*
  Recibe el nombre del archivo y la extension a validar
  Retorna un True o False dependiendo si el nombre el valido o No
*/
function validanombrearchivo(nombre, ext){
  tokens = StringTokenizer(nombre, '.');
  if ( tokens.length>1 ){
    if ( tokens[tokens.length-1].toLowerCase() != ext ){
      return false
    }
  } else {
    return false
  }
  return true
}
/*
  Recibe una cadena y la separa basado en el caracter de la variable delim.
  Retorna un Array de cadenas
*/
function StringTokenizer(cad, delim){
  var cads = new Array();
  var n = cad.length;
  var j = 0;
  var ic = 0;
  for (i=0;i<n;i++){
    if ( cad.charAt(i)==delim ){
      cads[j] = cad.substring(ic, i);
      ic = i+1;
      j++;
    }
  }
  cads[j] = cad.substring(ic, n);
  return cads;
}
/*
  Retorna el mes en Letras
  Donde mes es el numero del mes en el rango 1 hasta al 12
        may 1 o 0 para MAYUSCULAS o minusculas
        cap 1 o 0 para poner en mayusculas la primera letra o no
*/
function mesenletras(mes, may, cap){
  if ( !esnumero(mes) ){
    return "-";
  }
  var imes = parseInt(mes, 10);
  var tmes = "";
  if ( imes == 1 ){
    tmes = "enero";
  } else if ( imes == 2 ){
    tmes = "febrero";
  } else if ( imes == 3 ){
    tmes = "marzo";
  } else if ( imes == 4 ){
    tmes = "abril";
  } else if ( imes == 5 ){
    tmes = "mayo";
  } else if ( imes == 6 ){
    tmes = "junio";
  } else if ( imes == 7 ){
    tmes = "julio";
  } else if ( imes == 8 ){
    tmes = "agosto";
  } else if ( imes == 9 ){
    tmes = "setiembre";
  } else if ( imes == 10 ){
    tmes = "octubre";
  } else if ( imes == 11 ){
    tmes = "noviembre";
  } else if ( imes == 12 ){
    tmes = "diciembre";
  }
  if ( may == 1){
    tmes = tmes.toUpperCase();
  }
  if ( cap == 1){
    tmes = tmes.substring(0,1).toUpperCase() + tmes.substring(1, tmes.length() - 1);
  }
  return tmes;
}

/*
  Retorna
   -1: en caso de errores de formatos
    1: en caso de que fecha1 sea mayor a la fecha2
    2: en caso de que fecha1 sea menor a la fecha2
    0: en caso de que fecha1 sea igual a la fecha2
*/
function comparafecha(fecha1, fecha2){
  if ( !checkdate(fecha1) || !checkdate(fecha2) ){
    return -1
  }
  dia = fecha1.substring(0,2) //dia
  mes = fecha1.substring(3,5) //mes
  anho = fecha1.substring(6,10) //anho
  fecha1x = anho + mes + dia

  dia = fecha2.substring(0,2) //dia
  mes = fecha2.substring(3,5) //mes
  anho = fecha2.substring(6,10) //anho
  fecha2x = anho + mes + dia
  
  if ( fecha1x > fecha2x ){
    return 1
  } else if ( fecha1x < fecha2x ){
    return 2
  } else {
    return 0
  }
}

function nada(){
}

function corta(campo, longitud, cars) {
  if (campo.value.length>longitud)
   campo.value=campo.value.substring(0,longitud);
  cuenta(campo, cars);
}

function cuenta(campo, cars) {
  cars.value=campo.value.length;
}

/*
*/
function rellena(dato, caracter, tamanho){
  dato_trim = trim(dato)
  len = dato_trim.length
  dato_fill = ""
  for (var i=0;i<tamanho-len;i++){
    dato_fill = dato_fill + caracter;
  }
  dato_fill = dato_fill + dato_trim;
  return dato_fill;
}

/*
-------------------------------
Validacion de fecha
-------------------------------
-------------------------------
*/

function checkdate(fecha){
  var err=0
  if ( fecha.length != 10) err=1
  dia = fecha.substring(0,2) //dia
  slash1 = fecha.substring(2,3) // '/'
  mes = fecha.substring(3,5) //mes
  slash2 = fecha.substring(5,6) // '/'
  anho = fecha.substring(6,10) //anho

  // chequeo de errores basicos
  if ( dia<1 || dia>31) err = 1
  if ( slash1 != '/' ) err = 1
  if ( mes<1 || mes>12) err = 1
  if ( slash1 == '/' && slash2 != '/' ) err = 1
  if ( anho < 0 || anho > 2200 ) err = 1

  // verificacion avanzada
  // meses con 30 dias
  if ( mes == 4 || mes == 6 || mes == 9 || mes == 11 ){
    if (dia==31) err=1
  }
  // febrero
  if (mes == 2){
    var g = parseInt(anho/4)
    if (isNaN(g)){
      err = 1
    }
    if (dia >29) err =1
    if (dia ==29 && ((anho/4)!=parseInt(anho/4))) err=1
  }
  if (err==1){
    return false
  } else {
    return true
  }
}

function esnulo(campo){
  if ( campo == null ){
    return true
  } else {
    return false
  }
}

function esnulooguion(campo){
  if ( esnulo( campo ) ){
    return true
  } else {
    if ( trim( campo ) == "-" ) {
	  return true
	} else {
      return false
	}
  }
}

function esnumero(campo){
  if ( isNaN( campo ) ){
    return false
  } else {
    return true
  }
}

function longitudcorrecta( campo, len ){
  if ( campo != null ){
    if ( campo.length == len ){
      return true
    } else {
      return false
    }
  } else {
    return false
  } 
}

function mayuscula(campo){
  return campo.toUpperCase()
}
function minuscula(campo){
  return campo.toLowerCase()
}
function eslongrucok(ruc){
/*
Cambio el 04/01/2000 por modificacion de longitud del ruc
if ( ruc.length == 8 || ruc.length == 11 ){
*/
  if ( ruc.length == 11 ){
    return true
  } else {
    return false
  }
}
function eslongcontrasenhaok(contrasenha){
  if ( contrasenha.length < longcontrasenhaok() ){
    return false
  } else {
    return true
  }
}
function longcontrasenhaok(){
  return 6
}
function esnegativo(valor){
  if (valor < 0){
    return true
  } else {
    return false
  }
}
function esrucok(ruc){
  if ( esnulo(ruc) || !esnumero(ruc) || !eslongrucok(ruc) || !valruc(ruc) ){
    return false
  } else {
    return true
  }
}
function valruc(valor){
  valor = trim(valor)
  if ( esnumero( valor ) ) {
    if ( valor.length == 8 ){
      suma = 0
      for (i=0; i<valor.length-1;i++){
        digito = valor.charAt(i) - '0';
        if ( i==0 ) suma += (digito*2)
        else suma += (digito*(valor.length-i))
      }
      resto = suma % 11;
      if ( resto == 1) resto = 11;
      if ( resto + ( valor.charAt( valor.length-1 ) - '0' ) == 11 ){
        return true
      }
    } else if ( valor.length == 11 ){
      suma = 0
      x = 6
      for (i=0; i<valor.length-1;i++){
        if ( i == 4 ) x = 8
        digito = valor.charAt(i) - '0';
        x--
        if ( i==0 ) suma += (digito*x)
        else suma += (digito*x)
      }
      resto = suma % 11;
      resto = 11 - resto
      
      if ( resto >= 10) resto = resto - 10;
      if ( resto == valor.charAt( valor.length-1 ) - '0' ){
        return true
      }      
    }
  }
  return false
}

function longitudmayor( campo, len ){
  if ( campo != null ){
    if ( campo.length > len ){
      return true
    } else {
      return false
    }
  } else {
    return false
  } 
}

function estaentre(campo, inicio, fin){
  if ( campo != null ){
    if ( campo.length >= inicio && campo.length <= fin ){
      return true
    } else {
      return false
    }
  } else {
    return false
  }
}

function abreventana(i, j) {
  window.open(i, j, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width=600,height=450")
}
/*
impresion 
*/
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(frame, arg) {
  if (frame == window) {
    printThis();
  } else {
    link = arg; // variable global 
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Disculpe, su browser no soporta esta aplicacion.");
  }
}

function trim(cadena){
  cadena2 = "";
  len = cadena.length;
  for ( var i=0; i <= len ; i++ ){
  	if ( cadena.charAt(i) != " " ){
	  cadena2 = cadena2 + cadena.charAt(i);
	}
  }
  return cadena2;
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function AbrePuntos()
  { 
  ventana=open('http://www.cmr.com.pe/te_html/cmrpuntos/home.html','CMRPuntos','width=780,height=520,noresize,scrollbars=no')
//    ventana=open('http://cmrtest/te_html/cmrpuntos/home.html','CMRPuntos','width=780,height=520,noresize,scrollbars=no')
	
  }
 /*Funcion que valida que solo se ingresen campos numericos*/ 
function esTeclaNumeroSinComa(e) {
  var valid = "0123456789";
  var key = String.fromCharCode(event.keyCode);
    if (valid.indexOf("" + key) == "-1") return false;
}