﻿function mostrarCapaAvisos(Text)
{
    var Cadena = ObtDireccion('DisplayInfoError.aspx');
    Cadena += "?Mensaje=" + Text;
    Cadena += "&TipoMensaje=0";
    
    var CapaInfo = $find('ModalInfoPopupBehavior');
    CapaInfo.show();
    
    $get(CapaInfo._PopupControlID).src = Cadena;   
    
    if (ObtPaginaActiva().toUpperCase() == 'DEFAULT')
    {
        window.document.body.parentElement.style.overflow = 'hidden';
    }
}

function getFecha() 
{
    var fecha_actual = new Date()

	var dia = fecha_actual.getDate()
	var mes = fecha_actual.getMonth() + 1
	var anio = fecha_actual.getFullYear()
	
	if (mes < 10)
		mes = '0' + mes

	if (dia < 10)
		dia = '0' + dia

	return (dia + "/" + mes + "/" + anio)   
}

function getHora()
{
    var fecha_actual = new Date()
    
    var hora = fecha_actual.getHours(); 
	var minutos = fecha_actual.getMinutes();
	
	if(hora <= 9)
	{
	    hora = "0" + hora;
	}
	
	if( minutos <= 9) 
	{
	    minutos = "0" + minutos;
	}
    return  (hora + ":" + minutos)
}

function ClientDate(fecha, hora)
{
    if($get(fecha)!=null)
    {
       $get(fecha).value = getFecha();
    }
      
    if($get(hora)!=null)
    {
       $get(hora).value = getHora();
    }
}
// JScript File

function mostrarErroresForm()    
{
  if(document.getElementById("ctl00_DescErrorOculto")!=null)
   {
       var descerror=document.getElementById("ctl00_DescErrorOculto");
         
       if(descerror.value!="SinErrores")   
       {
          //var descripcionError=document.getElementById("descripcionError");
          //descripcionError.innerHTML = "<ul><li>" + descerror.value + "</li></ul>";
          mostrarCapaAvisos(descerror.value);    
          
          //Revisar las direcciones de los distintos objetos de las páginas (ct100_.....)
          switch(pagina)
          {
              case "Disponibilidad":
              case "Calendario":
              
                 ocultarObj("ctl00_Titulo");
                 mostrarObj("ctl00_NoVuelos");
                 break;
                 
              case "Horario":
              
                 var content =document.getElementById("ctl00_contenidoHorarios");
                 content.style.height="150px";
                 ocultarObj("ctl00_leyendaHorario");
                 ocultarObj("ctl00_btnDerecha");
                 mostrarObj("ctl00_NoVuelos");
                 break;
                 
              case "InfoVuelo":
              
                 var content =document.getElementById("ctl00_contenidoInfovuelo");
                 content.style.height="150px";
                 ocultarObj("ctl00_InfoVuelo");
                 ocultarObj("ctl00_leyendaInfoVuelo");
                 mostrarObj("ctl00_NoVuelos");
                 break;                 
          }
          
          descerror.value = "SinErrores";
       }   
   }

   if(document.getElementById("ctl00_MainContentPlaceHolder_lstOrigen")!=null)
   {
       var lstOrigen=document.getElementById("ctl00_MainContentPlaceHolder_lstOrigen");
       
       if(lstOrigen!=null) 
          lstOrigen.selectedIndex=0;
   }
}
 
function habilitarBoton(boton,clase){
   boton.className = clase;
   boton.disabled = false;	
}

function deshabilitarBoton(boton,clase){
   boton.className = clase;
   boton.disabled = true;	
}

function habilitar(idObj){
	obj = document.getElementById(idObj);
	if(obj.disabled){
		obj.disabled = false;
	}
}

function deshabilitar(idObj){
	obj = document.getElementById(idObj);	
	obj.disabled = true;
}

function descripcionAviso(id,cadena){
	document.getElementById(id).innerHTML = cadena;
}

//Mostrar-Ocultar id
function mostrarObj(id){	
    if(document.getElementById(id)!=null)
	    document.getElementById(id).style.display = "block";
}
function ocultarObj(id){
    if(document.getElementById(id)!=null)
	    document.getElementById(id).style.display = "none";
}

function CerrarCapaBehaviorTop(IdCapa)
{
    var CapaInfo = window.top.$find(IdCapa);
    
    CapaInfo.hide();
    
    if (window.top.document.body.parentElement.style.overflow == 'hidden')
    {
        window.top.document.body.parentElement.style.overflow = '';
    }
}

//function mostrarCapaAvisos()
//{
//	document.getElementById("capaAvisosError").style.visibility = "visible";
//	document.getElementById("bodyCapa").style.display = "block";	
//}

function cerrarCapaAvisos(){
	document.getElementById("capaAvisosError").style.visibility = "hidden";
	document.getElementById("bodyCapa").style.display = "none";
}

function LimpiaAvisos()
{
    //Ocultamos Error y limpiamos hidden contenedor (evita problema de error cuando volvemos hacia atras)
    $get('CapaAvisosError').style.visibility = 'hidden';
    var descerror = $get("ctl00_DescErrorOculto");
    if( descerror!= null )     descerror.value = "SinErrores";
}

//Busca la descripción del error a partir del la cte
function BuscarErrorCache(event,Error)
{
    WebServicePortal._DescripcionError(Error, muestraAsincrona);     
}

function muestraAsincrona(result)
{
    if(document.getElementById("descripcionError"))
    {
        var descripcionErrorOculto=document.getElementById("ctl00_DescErrorOculto");
        var descripcionError=document.getElementById("descripcionError");
        
        if (result.substring(0, 1) == ',')
        {
            result = result.substring(1, result.length -1);
        }
        
        //descripcionError.innerHTML="<ul><li>"+result+"</li></ul>";
        //descripcionErrorOculto.value = result;
       
        mostrarCapaAvisos(result);
    }
}

function printPartOfPage(elementId)
{
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}
