﻿function ImprimirPagina(bImprimir)
{
  if (bImprimir && window.print) window.print();
}

function ShowHideCustomizationWindow(aGrid)
{
  if (aGrid == null) return;
  if (aGrid.IsCustomizationWindowVisible()) aGrid.HideCustomizationWindow();
  else aGrid.ShowCustomizationWindow();
}

var ipage = -1;
function CorrigePaginaGrid(aGrid)
{
  if (ipage > -1 && aGrid.pageCount > 1 && aGrid.GetPopupEditForm() == null) aGrid.GotoPage(ipage);
  ipage = -1;
}
function EditarRowGrid(aGrid, aRow) {
  ipage = aGrid.pageIndex;
  aGrid.StartEditRow(aRow.visibleIndex);
}

function ToolBarProcess(cControl, sComando, bEstado)
{
  if (cControl == null || sComando == null) return;
  if (sComando == 'eventAbrir') ipage = cControl.pageIndex;
  switch (sComando)
  {
    case 'eventNuevo': if (bEstado == 'client') cControl.AddNewRow()
                       else cControl.PerformCallback(sComando); break;
    case 'eventProcesar': if (confirm('¿Está seguro de procesar el documento seleccionado?'))
        cControl.PerformCallback(sComando); break;
    case 'eventAnular': if (confirm('¿Está seguro de anular el registro seleccionado?'))
        cControl.PerformCallback(sComando); break;
    case 'eventClonar': if (confirm('¿Está seguro de clonar el registro seleccionado?'))
        cControl.PerformCallback(sComando); break;
    case 'eventEliminar': if (confirm('¿Está seguro de eliminar el registro seleccionado?'))
        cControl.PerformCallback(sComando); break;
    case 'gridSelectCols': ShowHideCustomizationWindow(cControl); break;
    default: cControl.PerformCallback(sComando + ':' + bEstado); break;
  }
}

function ValidarOnSave(s, e)
{
  if (e.item.name == 'eventGuardar')
  {
    e.processOnServer = ASPxClientEdit.ValidateEditorsInContainer(null);
    if (!e.processOnServer)
      alert('Faltan completar algunos datos requeridos.');
  }
}

function MapSetCenter(id, lat, lon)
{
  subgurim_GMap1.setZoom(14);
  subgurim_GMap1.setCenter(new GLatLng(lat, lon));
  var marker = getGMapElementById(subgurim_GMap1, 'mk_' + id.toString());
  if (marker != null)
  {
    subgurim_GMap1.setZoom(17);
    subgurim_GMap1.panTo(marker.getPoint());
    GEvent.trigger(marker, 'click');
  }
}

/// UBIGEO
function OnDepartamentosChanged(cbComboBox)
{
  bProvincias = window.cbProvincias ? true : false;
  bDistritos = window.cbDistritos ? true : false;
  bCiudades = window.cbCiudades ? true : false;
  if (cbComboBox == window.cbDepartamentos)
  {
    if (bCiudades) window.cbCiudades.ClearItems();
    if (bDistritos) window.cbDistritos.ClearItems();
    if (bProvincias) window.cbProvincias.PerformCallback(cbComboBox.GetValue().toString());
  }
  else if (cbComboBox == window.cbProvincias)
  {
    if (bCiudades) window.cbCiudades.ClearItems();
    if (bDistritos) window.cbDistritos.PerformCallback(cbComboBox.GetValue().toString());
  }
  else if (cbComboBox == window.cbDistritos)
  {
    if (bCiudades) window.cbCiudades.PerformCallback(cbComboBox.GetValue().toString());
  }
}

/// IGLESIAS POR CAMPO
function OnCamposChanged(cbComboBox)
{
  bDepartamentos = window.cbDepartamentos ? true : false;
  bIglesias = window.cbIglesias ? true : false;
  if (bDepartamentos)
  {
    window.cbCiudades.ClearItems();
    window.cbDistritos.ClearItems();
    window.cbProvincias.ClearItems();
    window.cbDepartamentos.PerformCallback(cbComboBox.GetValue().toString());
  }
  if (bIglesias) window.cbIglesias.PerformCallback(cbComboBox.GetValue().toString());
}

/// lookupGrid
function AceptarGridLookup(lookup)
{
  lookup.ConfirmCurrentSelection();
  lookup.HideDropDown();
}

var sTempo = 0;
function CambioGridLookup(s, e)
{
  var iRow = e.visibleIndex;
  if (iRow < 0 || sTempo != 0)
    return;
  aKey = s.GetRowKey(iRow);
  if (aKey == -1)
  {
    if (e.isSelected)
      s.SelectAllRowsOnPage();
    else s.UnselectAllRowsOnPage();
  }
  else
  {
    sTempo = 1;
    s.SelectRow(1, false, false);  /// Si existe key=-1 .....
    sTempo = 0;
  }
}

/// Funciones NO USADAS.,  pruebas
function ChangeIGV(s, e) {
  COS_IGV.SetNumber(s.GetNumber() * 0.19);
  ChangeTOTAL(s, e);
}

function ChangeTOTAL(s, e) {
  COS_TOTAL.SetNumber(COS_BASIMP.GetNumber() + COS_IGV.GetNumber() + COS_ISC.GetNumber() + COS_OTROS.GetNumber());
}
