function InputEnter(event, boton)
{
    if (event.which || event.keyCode)
    {
        if ((event.which == 13) ||(event.keyCode == 13))
        {
            document.getElementById(boton).click();
            return false;
        }
    } 
    else 
    {
        return true
    };
}

// Pone el tamaņo total de la pantalla en el div de ocultacion de AJAX
function CapaAjaxCompleta() {
    divAjax = document.getElementById('divAjaxOcultar');

    if (window.screen.height < document.body.clientHeight)
        divAjax.style.height = document.body.clientHeight+50;
    else
        divAjax.style.height = window.screen.height;
}

// Abre un calendario
function AbreCalendario(campoFecha)
{    
    document.getElementById(campoFecha).value = showModalDialog('/WebPortal/Pronovias/Paginas/popup/Calendario.page','', 'dialogTop=100px; dialogLeft=250px; dialogWidth=268px; dialogHeight=350px; center=yes; help=no; status=no; menubar=no; resizable=no; border=thin;' );
}

// Abre un calendario del Plan de Servicio
function AbreCalendarioPlanServicio(version, cantidad, talla, campoFecha, campoTipoPedido, campoPrecio, campoRecargo, hiddenFecha, hiddenPrecio, hiddenRecargo, txtFechaCompare) {
    datos = showModalDialog('/WebPortal/Pronovias/Paginas/popup/CalendarioPlanPedido.page?idVersion=' + version + '&cantidad=' + cantidad + '&idTalla=' + talla,'', 'dialogTop=80px; dialogLeft=220px; dialogWidth=350px; dialogHeight=380px; center=yes; help=no; status=no; menubar=no; resizable=no; border=thin');
    if (datos[0] != null && datos[0] != 'undefined') {
        if (document.all)
        {
            document.getElementById(campoFecha).innerText = datos[0];
        }else{
            document.getElementById(campoFecha).textContent = datos[0];
        }
        document.getElementById(hiddenFecha).value = datos[0];
        document.getElementById(txtFechaCompare).value = datos[0];        
    }
    if (datos[1] != null && datos[1] != 'undefined') {
        document.getElementById(campoTipoPedido).value = datos[1];
    }
    if (datos[2] != null && datos[2] != 'undefined') {
        if (document.all)
        {
            document.getElementById(campoPrecio).innerText = datos[2];
        }else{
            document.getElementById(campoPrecio).textContent = datos[2];
        }        
        document.getElementById(hiddenPrecio).value = datos[2];
    }
    if (datos[3] != null && datos[3] != 'undefined') {
        if (document.all)
        {
            document.getElementById(campoRecargo).innerText = datos[3];
        }else{
            document.getElementById(campoRecargo).textContent = datos[3];
        } 
        document.getElementById(hiddenRecargo).value = datos[3];
    }
}

// Abre un calendario del Plan de Servicio
function AbreListadoVersion(pagina,campohref,campoModelo,campoVersion) {
    document.getElementById(campohref).href = pagina + '?idModelo=' + document.getElementById(campoModelo).value + "&campoModelo="+ campoModelo + "&campoVersion="+ campoVersion  +"&TB_iframe=true&keepThis=true";
    return true;
}

// Abre un calendario del Plan de Servicio
function AbreCalendarioPlanServicioConsulta(version) {
    showModalDialog('/WebPortal/Pronovias/Paginas/popup/CalendarioPlanPedido.page?idVersion=' + version,'', 'dialogTop=80px; dialogLeft=220px; dialogWidth=350px; dialogHeight=380px; center=yes; help=no; status=no; menubar=no; resizable=no; border=thin');
}

// Abre un popup con una pantalla para asignar un cliente
function AbreAsignadorCliente(campoTalla, subgama, idGrupo) {
    datos = showModalDialog("/WebPortal/Pronovias/Paginas/popup/AsignarClienteTalla.page?campoTalla=" + campoTalla + "&subgama=" + subgama + "&idGrupo=" + idGrupo,"", "dialogTop=80px; dialogLeft=220px; dialogWidth=300px; dialogHeight=320px; center=yes; help=no; status=no; menubar=no; resizable=no; border=thin");
}

// Abre un popup con una pantalla para modificar una talla
function ModificarTalla(campoTalla, subgama, idGrupo) {
    datos = showModalDialog("/WebPortal/Pronovias/Paginas/popup/ModificarTalla.page?campoTalla=" + campoTalla + "&subgama=" + subgama + "&idGrupo=" + idGrupo,"", "dialogTop=80px; dialogLeft=220px; dialogWidth=300px; dialogHeight=400px; center=yes; help=no; status=no; menubar=no; resizable=no; border=thin");
}

// Abre un popup con una pantalla para ver el log de ejecuciones de un proceso
function AbreLogEjecucion(idEjecucion) {
    datos = window.open("/WebPortal/Repository/Pronovias/Grids/Paginas/popup/ConsultarLogEjecucion.aspx?idEjecucion=" + idEjecucion,"","toolbar=no,status=yes,scrollbars=yes,resize=no,width=650,height=350,left=220,top=80");
//"toolbar=no,status=yes,scrollbars=no,resize=no,width=650,height=350,left=220,top=80"
}

// Abre un popup con una pantalla para ver el log de ejecuciones de un proceso
function AbreAlertasEjecucion(idEjecucion) {
    datos = window.open("/WebPortal/Repository/Pronovias/Grids/Paginas/popup/ConsultarAlertasProceso.aspx?idEjecucion=" + idEjecucion,"","toolbar=no,status=yes,scrollbars=yes,resize=no,width=580,height=350,left=220,top=80");
//"toolbar=no,status=yes,scrollbars=no,resize=no,width=580,height=350,left=220,top=80"
}

function GuardarIdProceso(idProceso)
{
    document.getElementById('innhProcesoSeleccionado').value = idProceso;
}

function ConfirmaDesasignar(pais) {
    return window.confirm('Esta seguro que desea desasignar las tallas de los clientes con codigo de pais '+ pais);
}

function AbreCalendarioPlanServicio(pagina, campohref, campoCantidad, campoTalla, campos, validador, hollow) {
    var hth = '';
    try
    {
        hth = document.getElementById(hollow).value;
    } catch (Exception) {}
    document.getElementById(campohref).href = pagina + '&hollow=' + hth + '&cantidad=' + document.getElementById(campoCantidad).options[document.getElementById(campoCantidad).selectedIndex].value + '&idTalla=' + document.getElementById(campoTalla).options[document.getElementById(campoTalla).selectedIndex].value + campos + '&valFechaServicio=' + validador + "&TB_iframe=true&keepThis=true";
    return true;
}

function AbreHollowToHem(pagina, campohref, campoTalla) {
    document.getElementById(campohref).href = pagina + '&idTalla=' + document.getElementById(campoTalla).options[document.getElementById(campoTalla).selectedIndex].value + '&textTalla=' + document.getElementById(campoTalla).options[document.getElementById(campoTalla).selectedIndex].text + "&TB_iframe=true&keepThis=true";
    return true;
}

function ValidaCantidad(campoCantidad, btnPlanServicio) {
//alert(wwwe);
    if (document.getElementById(campoCantidad).value != '' && !isNaN(document.getElementById(campoCantidad).value) && document.getElementById(campoCantidad).value != 0) {
        document.getElementById(btnPlanServicio).disabled = '';
        document.getElementById(btnPlanServicio).className = 'calendario';
        document.getElementById(btnPlanServicio).className = document.getElementById(btnPlanServicio).className + ' ' + 'thickbox';
        tb_init(btnPlanServicio);
//////        document.getElementById(btnPlanServicio).className = 'calendario';
//////        document.getElementById(btnPlanServicio+'2').className = '';
//        document.getElementById(btnPlanServicio+'2').disabled = false;
    } else {
        document.getElementById(btnPlanServicio).disabled = 'disabled';
        document.getElementById(btnPlanServicio).className = 'calendario';      
////////        document.getElementById(btnPlanServicio).className = 'thickbox';      
////////        document.getElementById(btnPlanServicio+'2').className = 'calendario';
//        document.getElementById(btnPlanServicio+'2').disabled = true;
    }
}

function ChangeImage(originalIMG, controlID, order)
{
    var aux;
    if (OriginalUrlArray == null){
        OriginalUrlArray = new Array();
        for (i=0; i<UrlArray.length; i++)
        {
            OriginalUrlArray[i] = UrlArray[i];
        }
    }
    
    
    aux = UrlArray[1];
    UrlArray[1] = UrlArray[order-1];
    UrlArray[order-1] = aux;
    document.getElementById(controlID).src = UrlArray[1];
    document.getElementById(originalIMG).src = aux;
    
    for (i=0; i<OriginalUrlArray.length; i++)
    {
        if (OriginalUrlArray[i] != undefined){
            vaux = OriginalUrlArray[i].split('/');
            vaux2 = document.getElementById(controlID).src.split('/');
            if (unescape(vaux[vaux.length-1]) == unescape(vaux2[vaux2.length-1]))
            {
                order = i + 1;
            }
        }
    }
    document.getElementById('selPhoto').value = order;
    return false;
}

function ConfirmarBorrarPedidosAnulados(strMssg, controlID)
{
    if (window.confirm(strMssg))
    {
        document.getElementById(controlID).click();
    }
}

function Delay(controlID)
{
    setTimeout("document.getElementById('"+controlID+"').click();",3000);
}

function setFocus(controlName)
{ 
    if (document.getElementById(controlName) != null) {
        document.getElementById(controlName).focus(); 
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function validarteclaPost(control) {
    tecla = (document.all) ? event.keyCode : event.which;
    if (tecla==13){   
        window.location.href = document.getElementById(control).href;
    }
}

function validarteclaPost(control) {
    tecla = (document.all) ? event.keyCode : event.which;
    if (tecla==13){   
        eval(control);
    }
}

function Display(id){
    if (document.getElementById(id).style.display == 'block'){
        document.getElementById(id).style.display = 'none';
    }else{
        document.getElementById(id).style.display = 'block';
    }
    
    $('#scroll-pane_1').jScrollPane({showArrows:true, scrollbarWidth: 9, arrowSize: 6});
}
