﻿//TEXTO QUE SE MUESTRA EN EL STATUS DEL EXPLORER
function showStatus() {
  // colaboracion Juan Daniel Enero 10 2008
  var empresa = 'CNB WEB - SERVICIOS EN LINEA';
  //debugger;
  window.status = empresa + '';
  window.defaultStatus = empresa + '';
  window.setTimeout('showStatus()', 50);
}

//showStatus();    
function backButtonOverride() {
  // Work around a Safari bug
  // that sometimes produces a blank page
  var PaginaActual = history.current;
  var PaginaTotal = history.length;
  if (PaginaActual < PaginaTotal) {
    // Es un back en browser
  }
  setTimeout("backButtonOverrideBody()", 0);
  if (history.length > 0) history.forward(history.length + 1);
}

function backButtonOverrideBody() {
  // Works if we backed up to get here
  try {
    if (history.length > 0) history.go(history.length + 1);
    //history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 0);
}


function ReplaceLocation() {
  var sURL = unescape(window.location.pathname);
  window.location.replace(sURL);
  //parent.location = sURL;
  window.location.replace(sURL);
  setTimeout("replaceLocation()", 2 * 10000);
  window.location.href = sURL;
  window.location.reload(false);
}

function ReplaceLocation1() {
  var url = '';
  url = 'http://' + window.location.host + '/';
  url += 'Default.aspx';
  window.location.replace(url);
  return true;
}

function masterFunctions() {
  //debugger;
  //backButtonOverride();
  //replaceLocation();
  showStatus();
}

function masterFunctions1() {
  //debugger;
  //backButtonOverride();
  //replaceLocation();
  //location.replace (este);
  //window.history.clear;
  showStatus();
}


//FUNCION QUE MANEJA EL ENTER DE LA PAGINA
function noenter(e) {

  var key;
  var evento;

  if (window.event) // IE
  {
    key = event.keyCode;
    evento = event;
  }
  else if (e.which) // Netscape/Firefox/Opera
  {
    key = e.which;
    evento = e;
  }

  //alert("keyCode for the key pressed: " + key + "\n");
  //debugger;
  //alert(evento.keyCode);

  //showKeyCode(e);
  //|| (event.shift && (event.keyCode < 65 || event.keyCode > 90) )
  //|| ((event.keyCode >= 113)&& (event.keyCode <= 123))  
  // && (event.keyCode < 97 || event.keyCode > 121) Teclado numerico extendido y teclas de funciones del f1 al f10
  //|| (event.keyCode == 116) F5 //  (evento.altKey)  ||

  if ((evento.altKey && (evento.keyCode == 37 || evento.keyCode == 39))
	 	        || ((evento.keyCode == 8) && (evento.srcElement.type != "text" && evento.srcElement.type != "textarea" && evento.srcElement.type != "password"))
	 			|| ((evento.keyCode == 13) && (evento.srcElement.type != "textarea" && evento.srcElement.type != "password"))
	 			|| ((evento.ctrlKey) && ((evento.keyCode == 78) || (evento.keyCode == 82) || (evento.keyCode == 86)))
	 			|| ((evento.keyCode < 65 || evento.keyCode > 90)
	 			     && (evento.keyCode < 96 || evento.keyCode > 111)
	 			     && (evento.keyCode < 46 || evento.keyCode > 57)
	 			     && (evento.keyCode < 35 || evento.keyCode > 40)
	 			     && (evento.keyCode < 8 || evento.keyCode > 9)
	 			     && (evento.keyCode != 32)
	 		      )
	 	    ) {
    prevKey = evento.keyCode;
    if (evento.keyCode > 111 && evento.keyCode < 123) {
      if (window.event) // IE
      {
        evento.keyCode = 0;
      }
      else {
        return false;
      }
    }
    if ((evento.keyCode == 64) || (evento.keyCode == 190) || (evento.keyCode == 192) || (evento.keyCode == 189)) {
      //evento.returnValue = true;
      return true;
    }
    else {
      //evento.returnValue = false;
      return false;
    }
  }
}

//FUNCION QUE MANEJA EL MOUSE CLICK
var message1 = "Los sentimos, esta página web está bajo acuerdo de derechos de autor!";
document.onmousedown = derecha
document.onkeydown = noenter

function derecha(e) {

  var key;

  if (window.event) // IE
  {
    key = event.button;
  }
  else if (e.which) // Netscape/Firefox/Opera
  {
    key = e.which;
  }

  if (navigator.appName == 'Netscape' && (key == 2 || key == 3)) {
    alert(message1)
    return false;
  }
  else if (navigator.appName == 'Microsoft Internet Explorer' && (key == 2)) {
    alert(message1)
  }
}


function num_letra(e) {
  var key;

  if (window.event) // IE
  {
    key = e.keyCode;
  }
  else if (e.which) // Netscape/Firefox/Opera
  {
    key = e.which;
  }
  alert(e);
  if ((key < 65 || key > 90) && (key < 97 || key > 111) && (key < 48 || key > 57)) {
    if (event.keyCode > 111 && event.keyCode < 123) {
      event.keyCode = 0;
    }
    event.returnValue = false;
  }
}

function showKeyCode(e) {
  alert("keyCode for the key pressed: " + e.keyCode + "\n");
}

function validateDate(oSrc, args) {
  var iDay, iMonth, iYear;
  var arrValues;

  arrValues = args.Value.split("/");

  iDay = arrValues[0];
  iMonth = arrValues[1];
  iYear = arrValues[2];
  //debugger;
  var testDate = new Date(iYear, iMonth - 1, iDay);
  if ((testDate.getDate() != iDay) ||
        (testDate.getMonth() != iMonth - 1) ||
        (testDate.getFullYear() != iYear) ||
        (testDate.getFullYear() < 1900)) {
    args.IsValid = false;
    return;
  }
  return true;
}

function validateDateTelerik(oSrc, args) {
  var iDay, iMonth, iYear;
  var arrValues;

  arrValues = args.Value.split("-");

  iYear = arrValues[0];
  iMonth = arrValues[1];
  iDay = arrValues[2];
  //debugger;
  var testDate = new Date(iYear, iMonth - 1, iDay);
  if ((testDate.getDate() != iDay) ||
        (testDate.getMonth() != iMonth - 1) ||
        (testDate.getFullYear() != iYear) ||
        (testDate.getFullYear() < 1900)) {
    args.IsValid = false;
    return;
  }
  return true;
}

var gAutoPrint = true;

function ImprimirRecibo() {
  if (document.getElementById != null) {
    var html = "<HTML><BODY><TABLE align=center border=1 cellpadding=0 cellspacing=0 width=800px style='font-size:7pt; font-family:Arial'>";

    var printReadyElem = document.getElementById("TablaRecibo");

    if (printReadyElem != null) {
      html += printReadyElem.innerHTML;
    } else {
      alert("No se encuentra el texto a imprimir en el codigo HTML");
      return;
    }

    html += "</TABLE></BODY></HTML>";

    var printWin = window.open("", "ImprimirRespuesta", "width=800,height=500,scrollbars=YES,Resizable=NO,Directories=NO,Location=NO,Menubar=NO,Status=NO,Titlebar=NO,Toolbar=NO");

    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
    if (gAutoPrint)
      printWin.print();
  } else {
    alert("Lo sentimos, pero su navegador no soporta esta opción.");
  }
}

function puntitos(donde, caracter) {
  valor = donde.value;
  valor = valor.toString().replace(/\$|\,/g, '');
  crtr = true;
  cents = "0";

  if (isNaN(caracter) && !(caracter == ".")) {
    if (caracter == "\\") {
      carcter = new RegExp("\\" + caracter, "g");
    }
    else {
      carcter = new RegExp(caracter, "g");
    }
    valor = valor.replace(carcter, "");
    donde.value = valor;
  }
  else {
    varpunto = valor.indexOf(".");

    if (varpunto >= 0) {
      if (varpunto < 4) {
        crtr = false;
      }
      if ((valor.split(/\./).length) == 1) {
        valor = valor.split(/\./)[0]
      }
      else {
        cents = valor.split(/\./)[1]
        valor = valor.split(/\./)[0]
      }
      //valor = Math.floor(valor*100+0.50000000001);
      //cents = valor%100;
      //valor = Math.floor(valor/100).toString();
      //if(cents < 10){
      //	cents = "0" + cents;
      //}
    }
  }
  if (!(isNaN(valor))) {
    largo = valor.length;
    var cad1 = "", cad2 = "", tres = 0
    if (largo > 3 && crtr == true) {
      for (k = valor.length - 1; k >= 0; k--) {
        cad1 = valor.charAt(k);
        cad2 = cad1 + cad2;
        tres++;
        if ((tres % 3) == 0) {
          if (k != 0) {
            cad2 = "," + cad2;
          }
        }
      }
    }
    else {
      cad2 = valor;
    }
    if (cents > 0) {
      donde.value = cad2 + '.' + cents;
    }
    else {
      donde.value = cad2;
      if (varpunto > 0) {
        donde.value = cad2 + '.';
      }
    }
  }
}
function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g, '');
  if (isNaN(num))
    num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num * 100 + 0.50000000001);
  cents = num % 100;
  num = Math.floor(num / 100).toString();
  if (cents < 10)
    cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
    num = num.substring(0, num.length - (4 * i + 3)) + ',' +
		num.substring(num.length - (4 * i + 3));
  return (((sign) ? '' : '-') + num + '.' + cents);
}


function ValidaUsuario() {
  //debugger; 
  var IdUsuario = document.getElementById('ctl00_ContentPlaceHolder1_IngresoBack1_IdUsuario').value;
  var ClaveUsuario = document.getElementById('ctl00_ContentPlaceHolder1_IngresoBack1_ClaveUsuario').value;
  var IdCliente = document.getElementById('IdCliente');
  var Clave = document.getElementById('Clave');
  IdCliente.value = IdUsuario;
  Clave.value = ClaveUsuario;
}

ClosingVar = true;
var even = null;
var fue_unload = false;
var micierre = false;

//window.onbeforeunload = ConfirmarCierre;


function ConfirmarCierre() {

  //debugger;
  micierre = false;
  if (window.ActiveXObject) { //para evento en iexplore
    if (event.clientY < 0) {
      setTimeout('micierre = false', 100);
      micierre = true;
      //Salida();
      //var url = '';
      //url = 'http://' + window.location.host + '/';
      //url += window.location.pathname.toString().split('/')[1];
      //url += 'closeSession.aspx'
      //alert(url);
      //window.open(url,null,'menubar=no, toolbar=no, location=no, resizable=no, scrollbars=yes, status=yes, width=1, height=1');
    }
  }
  else if (window.XMLHttpRequest) {
    //alert ('estamos en firefox');  
    if (!even) {
      setTimeout('micierre = false', 100);
      micierre = true;
      //Salida();
      //var url = '';
      //url = 'http://' + window.location.host + '/';
      //url += window.location.pathname.toString().split('/')[1];
      //url += 'closeSession.aspx'
      //alert(url);
      //openRequestedPopup();
      //parent.location = url;
      //open("http://www.google.com.co","");
      //window.open('www.google.com.co', '', 'fullscreen=yes, scrollbars=auto'); 
      //window.open(url,null,'menubar=no, toolbar=no, location=no, resizable=no, scrollbars=yes, status=yes, width=1, height=1');
    }
    else fue_unload = true;
  }
}


function ManejadorCierre() {
  //debugger;
  if (micierre == true) {
    //alert ('llamo a startRequest');
    Salida();
  }
}


//FUNCIONES QUE MANEJAN EL BACK Y FORWARD DEL INTERNET EXPLORER
function backPage() {
  history.back();
}

function forwardPage() {
  history.forward();
}

//FUNCION QUE SE EJECUTA CUANDO CIERRAN EL EXPLORADOR
//window.onunload = ManejadorCierre;
//window.onunload = closeSession;

function closeSession(e) {
  var key;
  var evento;

  if (window.event) // IE
  {
    evento = event;
  }
  else {
    debugger;
    if (e == "unload") // Netscape/Firefox/Opera
    {
      evento = e;
    }
  }
  debugger;
  if (evento.type == "unload" && evento.clientY < 0) { //!= null && evento.clientX < 0 && evento.clientY < 0
    var url = '';
    url = 'http://' + window.location.host + '/';
    //url += window.location.pathname.toString().split('/')[1];
    url += 'Salir.aspx'
    //alert(url);
    window.open(url, null, 'menubar=no, toolbar=no, location=no, resizable=no, scrollbars=yes, status=yes, width=1, height=1');
  }
}
// FUNCION QUE EJECUTA LA SALIDA Y CIERRE DEL BROWSER
function Salida() {
  var url = '';
  url = 'http://' + window.location.host + '/';
  //url += window.location.pathname.toString().split('/')[1] + '/';
  //if (window.location.pathname.toString().split('/')[1] != window.document.activeElement.pathname){
  //    url += window.location.pathname.toString().split('/')[1] + '/';
  //}
  //url += 'closeSession.aspx';
  url += 'Salir.aspx';
  //alert(url);
  win = open(url, 'Salida', 'menubar=no, toolbar=no, location=no, resizable=no, scrollbars=yes, status=yes', false);
  //parent.location = url;
}


// FUNCIONES QUE RESALTAN LA FILA DE LA GRILLA
function Resaltar_On(GridView) {
  if (GridView != null) {
    GridView.originalBgColor = GridView.style.backgroundColor;
    GridView.style.backgroundColor = "#f2f2f2";
  }
}

function Resaltar_Off(GridView) {
  if (GridView != null) {
    GridView.style.backgroundColor = GridView.originalBgColor;
  }
}

