var scrollSpeed = 2;
var scrollSpeedNow = scrollSpeed;
var notaGrid = null;
var notaFrame = null;
var notaFrameHeight = null;
var notaLength = 0;
String.prototype.trim = function () {
 str = this.replace(/^\s+/, '');
 return str.replace(/\s+$/, '');
};
function goToPage (_page) {
 var forma = document.getElementById('forma');
 forma.accion.value = '';
 forma.page.value = _page;
 forma.submit();
}
function goToAction (_page, _action) {
 var forma = document.getElementById('forma');
 forma.accion.value = _action;
 forma.page.value = _page;
 forma.submit();
}
function setValue (_form, _target, _value) {
 _form.elements[_target].value = _value;
}
function imprimir (_form) {
 _form.reset();
 _form.accion.value = '';
 _form.target = 'NEW';
 _form.action = '../sources/print.php';
 _form.submit();
 _form.target = '';
 _form.action = '../sources/index.php';
}
function editar (_form) {
 _form.accion.value = 'edit';
 _form.submit();
}
function nextStep (_form) {
 _form.accion.value = '';
 _form.submit();
}
function contactar (_form) {
 _form.accion.value = 'enviar';
 _form.submit();
}
function toStep (_form) {
 _form.accion.value = '';
 _form.submit();
}
function borrar (_form, _detail) {
 if (confirm('¿Desea eliminar el registro "'+_detail+'"?')) {
  _form.accion.value = 'delete';
  _form.submit();
 }
}
function grabar (_form) {
 _form.accion.value = 'save';
 _form.submit();
}
function cancelar (_form) {
// _form.reset();
 _form.accion.value = '';
 _form.submit();
}
function logOn (_target) {
 if (typeof(_target) == 'object') {
  if (_target.tagName == 'FORM') {
   if (_target.usuario.value.trim() == '') {
    alert('Escriba el código de usuario asignado');
    _target.usuario.focus();
   } else {
    if (_target.clave.value.trim() == '') {
     alert('Escriba la clave de acceso');
     _target.clave.focus();
    } else {
     if (ajax_create()) {
      var valores = new Array();
      valores[0] = _target.usuario.value.trim();
      valores[1] = _target.clave.value.trim();
      ajax_call('POST', '../sources/login.php', valores, 'VALIDATE', logOn);
     } else {
      _target.submit();
     }
    }
   }
  }
 } else {
  if (typeof(_target) == 'string') {
   var result = _target.split(':');
   if (result[0] == 'OK') {
    var forma = document.getElementById('forma');
    forma.usuario.value = result[1].trim();
    forma.nombre.value = result[2].trim();
    forma.perfil.value = result[3].trim();
    forma.sesion.value = result[4].trim();
    forma.page.value = 'inicio';
    forma.submit ();
   } else {
    alert("Error: " + result[1].trim());
   }
  }
 }
 return false;
}
function initializeNota () {
 notaGrid = (document.all) ? document.all.notaGrid : document.getElementById("notaGrid")
 notaFrame = (document.all) ? document.all.notaFrame : document.getElementById("notaFrame")
 notaGrid.style.top = 0;
 notaLength = notaGrid.offsetHeight;
 notaFrameHeight = notaFrame.offsetHeight;
 scrollNota();
}
function scrollNota () {
 notaGrid.style.top = parseInt(notaGrid.style.top) - scrollSpeedNow;
 if (parseInt(notaGrid.style.top) < (notaLength * (-1))) {
  notaGrid.style.top = notaFrameHeight;
 }
 setTimeout("scrollNota ()", 100);
}
