function Submit(aform)
{
   aform.submit();
}

function Cargar()
{
    if (document.getElementById("mostrar_menores"))
        {
        for (i = 0; i < 9; i++)
        {
            if (i < document.getElementById("mostrar_menores").value)
            {
                document.getElementById("div_edad_menor_0" + (i + 1)).style.display = 'inline';
            }
            else
            {
                document.getElementById("div_edad_menor_0" + (i + 1)).style.display = 'none';
                document.getElementById("menor_0" + (i + 1)).value = '';
            }
        }

        for (i = 0; i < 9; i++)
        {
            if (i < document.getElementById("mostrar_bebes").value)
            {
                document.getElementById("div_edad_bebe_0" + (i + 1)).style.display = 'inline';
            }
            else
            {
                document.getElementById("div_edad_bebe_0" + (i + 1)).style.display = 'none';
                document.getElementById("div_edad_bebe_0" + (i + 1)).value = '';
            }
        }

        document.getElementById("mostrar_menores").disabled = false;
        document.getElementById("mostrar_bebes").disabled = false;
        document.getElementById("caja_menores").style.display = 'inline';
        document.getElementById("caja_bebes").style.display = 'inline';
    }
}

function Activar()
{
    if (document.getElementById("adultos").value == '0')
    {
        for (i = 0; i < 9; i++)
        {
            document.getElementById("menor_0" + (i + 1)).value = '';
        }
        document.getElementById("mostrar_menores").disabled = true;      
        document.getElementById("mostrar_bebes").disabled = true;  

        document.getElementById("caja_menores").style.display = 'none';       
        document.getElementById("caja_bebes").style.display = 'none';  

        document.getElementById("mostrar_menores").value = '0';      
        document.getElementById("mostrar_bebes").value = '0';  
    }
    else
    {
        document.getElementById("mostrar_menores").disabled = false;      
        document.getElementById("mostrar_bebes").disabled = false;      
    }
}


function ActivarVuelta(iValor)
{
    if (iValor == 1)   
    {
        document.getElementById("fregreso").disabled = false;
        document.getElementById("hregreso").disabled = false;
    }
    else
    {     
        document.getElementById("fregreso").value = ''; 
        document.getElementById("hregreso").value = '28'; 
        document.getElementById("fregreso").disabled = true;
        document.getElementById("hregreso").disabled = true;
    }
}


// Funciones para desplegar y plegar divs
$(function()
{

 
    $("#mostrar_menores").change(

        function(event)   
        {
            // Borra todos los input text                    
                for (i = 0; i < 9; i++)
                {
                    if (i < this.value)
                    {
                        document.getElementById("div_edad_menor_0" + (i + 1)).style.display = 'inline'; 
                    }
                    else
                    {
                        document.getElementById("div_edad_menor_0" + (i + 1)).style.display = 'none'; 
                        document.getElementById("menor_0" + (i + 1)).value = '';
                    }
                }
              

                event.preventDefault();
                $("#caja_menores").slideDown("fast");
            
        }
    );   

    $("#mostrar_bebes").change(
    
        function(event){
     
            // Borra todos los input text  
            for (i = 0; i < 9; i++)
            {

                if (i < this.value)
                {
                    document.getElementById("div_edad_bebe_0" + (i + 1)).style.display = 'inline';
                }
                else
                {
                    document.getElementById("div_edad_bebe_0" + (i + 1)).style.display = 'none';
                    document.getElementById("bebe_0" + (i + 1)).value = '';
                }

            }


            event.preventDefault();
            $("#caja_bebes").slideDown("fast");
        }
    );      
    
/*    
    $("#mostrar_bebes").click
    (
        function(event) 
        {
               event.preventDefault();
               $("#caja_bebes").slideToggle("fast");
        }
    );    
*/
 
    $("#caja_menores a").click
    (
        function(event) 
        {
        event.preventDefault();
        $("#caja_menores").slideUp("fast");
        }
    );
    
    $("#caja_bebes a").click
    (
        function(event) 
        {
        event.preventDefault();
        $("#caja_bebes").slideUp("fast");
        }
    );    
}
);

function mostrar_desglose(divXXX)
{
    
    var divsub = document.getElementById(divXXX);
    
    divsub.style.display = 'inline';
    
}

function ocultar_desglose(divYYY)
{     
    var divsub = document.getElementById(divYYY);
    
    divsub.style.display = 'none';  
    
}

function MostrarFechasVuelos(fecha,divFechaIdaVuelta,texto)
{
    dia = fecha.substr(0,2);
    mes = fecha.substr(2,2);
    any = fecha.substr(4,2);

    var dias = new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado");
    var meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
    
    var dt = new Date(20+any+'/'+mes+'/'+dia); 
    var y = dt.getYear();
    if (y < 1000) y +=1900;

    if (texto == 'Ida')
    {
        document.getElementById(divFechaIdaVuelta).innerHTML = "<span style='color:#fadb86;'><b>IDA</b></span> <img src='img/vuelos_ida.gif' /> " + dias[dt.getDay()] + ", " + dia + " de " + meses[dt.getMonth()] + " del " + y;
    }
    else
    {
        document.getElementById(divFechaIdaVuelta).innerHTML = "<span style='color:#fadb86;'><b>VUELTA</b></span> <img src='img/vuelos_vuelta.gif' /> " + dias[dt.getDay()] + ", " + dia + " de " + meses[dt.getMonth()] + " del " + y;
    }
}

function MostrarFechasVuelosConfirmada(fecha,divFechaIdaVuelta,texto)
{
    //alert(fecha);
    dia = fecha.substr(0,2);
    mes = fecha.substr(2,2);
    any = fecha.substr(4,2);

    var dias = new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado");
    var meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
    
    var dt = new Date(20+any+'/'+mes+'/'+dia); 
    var y = dt.getYear();
    if (y < 1000) y +=1900;

    if (texto == 'Ida')
    {
        document.getElementById(divFechaIdaVuelta).innerHTML = dias[dt.getDay()] + ", " + dia + " de " + meses[dt.getMonth()] + " del " + y;
    }
    else
    {
        document.getElementById(divFechaIdaVuelta).innerHTML = dias[dt.getDay()] + ", " + dia + " de " + meses[dt.getMonth()] + " del " + y;
    }
}


function redondeo2decimales(numero)
{
    var original=parseFloat(numero);
    var result=Math.round(original*100)/100 ;
    return result;
}

function MostrarSeguroVuelos(total,gastos_emision)
{

    if (iGetRadioButtonSelectedValue(document.frm_reserva_vuelo.rbt_seguro) == 'S')
    {
         porcentaje_seguro=document.getElementById('por_seguro').value/100;
         seguro = redondeo2decimales(total*porcentaje_seguro);
         seguro_formateado = seguro;

         seguro_formateado = seguro_formateado.toString();
         seguro_formateado = seguro_formateado.replace('.',',');
       
         total = total + seguro + gastos_emision;
    }
    else
    {
         seguro_formateado = '0,00';
         total = total+gastos_emision;
    }

     total = redondeo2decimales(total);
    //convertio a cadena para reemplazar el punto por la coma
     total=total.toString();
     //Reemplazo la coma por el punto a cadena
     total = total.replace('.',',');
     
     document.getElementById('divSeguroPrecio').innerHTML = seguro_formateado+'&nbsp;&euro;';
     document.getElementById('divTotalSeguroPrecio').innerHTML = '<b>'+total+'&nbsp;&euro;</b>';
}


function MostrarTotalBilletes(total,seguro)
{
     v_total = total.toString();
     v_total = v_total.replace(',','.');
     v_total = parseFloat(v_total);
     
     if (seguro == 0)
     {
        seguro_calculo = 0;
     }
     else
     {
        seguro_calculo = v_total*seguro/100;
     }
     
     v_total = v_total + seguro_calculo + 9; 
         
     v_total = redondeo2decimales(v_total);
     v_total = v_total.toString();
     v_total = v_total.replace('.',',');

     document.getElementById('divTotal').innerHTML = '<b>'+v_total+'</b>';         
}

function vuelos_HaPulsadoPagar()
{  
    window.location="index.php?mod=vuelos&cod=HaPulsadoPagar";

    vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');

    document.frmProcesoPago.submit();
}

/*********************************************************************************************************/
            
function vuelos__mostrarOrigenesDestinos(div,trayectoria)
{
    $.get("functions/func_vuelos.php", { func: "func_vuelos__OrigenesDestinos", param1: div, param2: trayectoria },
        function(data){
            vuelos__call_mostrarOrigenesDestinos(data);
            });
}

function vuelos__call_mostrarOrigenesDestinos(str)
{
     aValores    = str.split('|');
          
     div = removeChar(aValores[0]);
     document.getElementById(div).innerHTML = aValores[2];
     document.getElementById(div).style.visibility='visible';
     document.getElementById(div).style.zIndex=4;
     document.getElementById(div).style.position='absolute';
     //document.getElementById(div).style.left='270px';
     //document.getElementById(div).style.top='175px';
    var wi_w,wi_h;
    if(window.innerHeight!=undefined)
        {
        wi_w= window.innerWidth;
        wi_h= window.innerHeight;
        }
    else{
        var d= document.documentElement;
        if(d)
            {
            wi_w= d.clientWidth;
            wi_h= d.clientHeight;
            }
        }
    $("#"+div).css('top',((wi_h/2)-(400/2))+'px');
    $("#"+div).css('left',((wi_w/2)-(680/2))+'px');
}


function vuelos_ColocarCiudad(ciudad,trayecto,divOrig_Dest,cod_iata)
{    
    ciudad = ciudad.replace(/_/g,' ');//chapuzilla para que no pete el javascript
    if(trayecto=='O')
    {
        //document.getElementById('origen_visible').value= ciudad;
        document.getElementById('txtOrigenVuelos').value= ciudad;
        document.getElementById('origen').value= cod_iata;
        
        
        document.getElementById(divOrig_Dest).style.visibility='hidden';
    }
    else if(trayecto=='D') 
    {
        //document.getElementById('destino_visible').value= ciudad;
        document.getElementById('txtDestinoVuelos').value= ciudad;
        document.getElementById('destino').value= cod_iata;
        document.getElementById(divOrig_Dest).style.visibility='hidden';
    }
}








function vuelos__cerrar(div,trayecto)
{
    if(trayecto=='O')
    {
        document.getElementById(div).style.visibility='hidden';
    }
    else if(trayecto=='D') 
    {
        document.getElementById(div).style.visibility='hidden';    
    }
}
/*********************************************************************************************************/
// PROBAR ESTA FUNCION
//funcion que permite redondear y formatear un numero
function oNumero(numero)
{
	//Propiedades 
	this.valor = numero || 0
	this.dec = -1;
	//M�todos 
	this.formato = numFormat;
	this.ponValor = ponValor;

	//Definici�n de los m�todos 
	function ponValor(cad)
	{
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		if (cad.indexOf('.') >=0)
			this.valor = parseFloat(cad);
		else 
			this.valor = parseInt(cad);
	} 

	function numFormat(dec, miles)
	{
		var num = this.valor, signo=3, expr;
		var cad = ""+this.valor;
		var ceros = "", pos, pdec, i;
		for (i=0; i < dec; i++)
		ceros += '0';
		pos = cad.indexOf('.')
		if (pos < 0)
			cad = cad+"."+ceros;
		else
			{
			pdec = cad.length - pos -1;
			if (pdec <= dec)
				{
				for (i=0; i< (dec-pdec); i++)
					cad += '0';
				}
			else
				{
				num = num*Math.pow(10, dec);
				num = Math.round(num);
				num = num/Math.pow(10, dec);
				cad = new String(num);
				}
			}
		pos = cad.indexOf('.')
		if (pos < 0) pos = cad.lentgh
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
			   signo = 4;
		if (miles && pos > signo)
			do{
				expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
				cad.match(expr)
				cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
				}
			while (cad.indexOf(',') > signo)
		
			if (dec<0) cad = cad.replace(/\./,'')
				return cad;
	}
}

/** vuelos_RellenarListaCiudades(pais,selectboxId)
* rellena un selectbox pasado como parametro con las ciudades del pais pasado como parametro
* @param pais con las ciudades
* @param selectboxId a rellenar con las ciudades del pais pasado como parametro
*/
function vuelos_RellenarListaCiudades(selectboxId,pais){
    $.get("functions/func_vuelos.php", { func: "func_vuelos__RellenarComboCiudades", param1: selectboxId, param2: pais },
        function(data){
            vuelos__call_RellenarComboCiudades(data.replace(/[\n\r\t]/g,''));
            });
}

/**  vuelos_RellenarListaAeropuertos(selectboxId,ciudad)
* rellena un selectbox pasado como parametro con las ciudades del pais pasado como parametro
* @param ciudad con los aeropuertos
* @param selectboxId a rellenar con los aeropuertos de la ciudad pasada como parametro
*/
function vuelos_RellenarListaAeropuertos(selectboxId,ciudad){
    $.get("functions/func_vuelos.php", { func: "func_vuelos__RellenarComboAeropuertos", param1: selectboxId, param2: ciudad },
        function(data){
            vuelos__call_RellenarComboAeropuertos(data.replace(/[\n\r\t]/g,''));
            });
}
/**  vuelos__call_RellenarCombo(str)
* rellena un selectbox
* @param str cadena de texto con la forma
* "[id del selectbox]|[html para rellenar dentro del <select></select>]"
*/
function vuelos__call_RellenarComboCiudades(str)
{
     aValores    = str.split('|');
     var selectbox = aValores[0];
     $('#'+selectbox).html(aValores[1]);
}
function vuelos__call_RellenarComboAeropuertos(str)
{
     aValores    = str.split('|');
     var selectbox = aValores[0];
     $('#'+selectbox).html(aValores[1]);
}


/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Vers�o: 2.1 - 04/09/2007
* Autor: Micox - N�iron Jos� C. Guimar�es - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
function select_innerHTML(objeto,innerHTML){
    objeto.innerHTML = "";
    var selTemp = document.createElement("micoxselect");
    var opt;
    selTemp.id="micoxselect1";
    document.body.appendChild(selTemp);
    selTemp = document.getElementById("micoxselect1");
    selTemp.style.display="none";
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se n�o � option eu converto
        innerHTML = "<option>" + innerHTML + "</option>";
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span");
    selTemp.innerHTML = innerHTML;


    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];

        if(spantemp.tagName){
            opt = document.createElement("OPTION")

   if(document.all){ //IE
    objeto.add(opt);
   }else{
    objeto.appendChild(opt);
   }

   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value");
   opt.text = spantemp.innerHTML;
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  }
 }
 document.body.removeChild(selTemp);
 selTemp = null;
}