//script para buscador de trenes en ws (/ofertas-tren/)

//para sacar ldate de javascript:
function TestYYYYMMDD() {
    var X;
    with (new Date) {
        X = String((getFullYear() * 100 + getMonth() + 1) * 100 + getDate());
    }
    return(X);
}
var ldate=TestYYYYMMDD()


var Hoy=new Date();
var sysdate		= new Date();
var anio 		= sysdate.getFullYear();
var mes     	= sysdate.getMonth();
var locCodeHolder = "";
var locDescHolder = "";
var index_air;
var companyHolder = "";
var numpaxes 	= 9;
var pais = 'vjres';
var ruta = '/pictures/vjres';

function flightInit_soloida(){
	if(flightForm.rrt.checked){
		flightForm.fs_dia.disabled 		= false;
        flightForm.fs_mesanyo.disabled 	= false;
        flightForm.retTime.disabled 	= false;
	}
	if(flightForm.row.checked){
		flightForm.fs_dia.disabled 		= true;
        flightForm.fs_mesanyo.disabled 	= true;
        flightForm.retTime.disabled 	= true;
	}
}

function dia_options(ini,fin,sel) {  

	var i=parseInt(ini);
	while (i<=parseInt(fin)){
		if (sel!='' && i==parseInt(sel,10))
			document.write('<option selected="selected"  value="'+decode(i-1)+'">'+decode(i-1)+'</option>');
		else			
			document.write("<option value='"+decode(i-1)+"'>"+decode(i-1)+"</option>");
		i++;
	} 
}

function mesanyo_options(ini,fin,sel,anyo,sel2,kind) {
        stanyo = anyo;
		i=parseInt(ini);
		months = fin; //pintamos 12 meses
		j=0;
		while (j<parseInt(fin)){

		if (kind!='')	{ //name of month
					 if (kind=='es')     {
						 k=0;
					 } else if (kind=='br')     {
						 k=6;
					 } else k=2;
					if (sel!='' && (sel.toString()==anyo.toString()+i.toString()))	{  document.write('<option selected="selected"  value="'+anyo+decode(i)+'">'+arrMes[k][i]+' '+decodeYear(anyo,stanyo)+'</option>');}
					else	{ document.write("<option value='"+anyo+decode(i)+"'>"+arrMes[k][i]+' '+decodeYear(anyo,stanyo)+"</option>");}
		} else {
					if (sel!='' && i==parseInt(sel,10))		document.write('<option selected="selected" value="'+i+'">'+i+'</option>');
					else document.write("<option value='"+i+"'>"+i+"</option>");
		}
		i++;
		j++;
		if (i==fin) { i=0; anyo++;}
		}
}

function decode(i) {
	if ((i+1).toString().length==1) return '0'+(i+1);
	else return (i+1);
}

function decodeYear(x,y) {
	if (x==y) return "";
	else return x;
}

function triptypeVuelos2007()
{
	if(flightForm.rrt.checked)
	{
		flightForm.fs_dia.disabled 		= false;
        flightForm.fs_mesanyo.disabled 	= false;
        flightForm.retTime.disabled 	= false;
        flightForm.fechaRetorno.disabled = false;
	}
	if(flightForm.row.checked)
	{
		flightForm.fs_dia.disabled 		= true;
        flightForm.fs_mesanyo.disabled 	= true;
        flightForm.retTime.disabled 	= true;
        flightForm.fechaRetorno.disabled = true;
	}
}

function initFechasIEVuelos(){
	var fecInicial = new Date();
	flightForm.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightForm.fe_dia.value = addcero(fecInicial.getDate());
	flightForm.fechaSalida.value = flightForm.fe_dia.value+"/"+flightForm.fe_mesanyo.value.substring(4)+"/"+flightForm.fe_mesanyo.value.substring(0,4);
	
	//fecha de vuelta
	fecInicial.setDate(fecInicial.getDate()+1);
	flightForm.fs_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightForm.fs_dia.value = addcero(fecInicial.getDate());
	flightForm.fechaRetorno.value = flightForm.fs_dia.value+"/"+flightForm.fs_mesanyo.value.substring(4)+"/"+flightForm.fs_mesanyo.value.substring(0,4);
}

function initFechasOtrosVuelos(){
	var fecInicial = new Date();
	flightForm.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightForm.fe_dia.value = addcero(fecInicial.getDate());
	
	fecInicial.setDate(fecInicial.getDate()+1);
	flightForm.fs_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightForm.fs_dia.value = addcero(fecInicial.getDate());
}


function triptypeVH2007()
{
	if(flightHotelForm.rrt.checked)
	{
		flightHotelForm.fs_dia.disabled 	= false;
        flightHotelForm.fs_mesanyo.disabled = false;
        flightHotelForm.retTime.disabled 	= false;
        flightHotelForm.fechaRetorno.disabled = false;
	}
	if(flightHotelForm.row.checked)
	{
		flightHotelForm.fs_dia.disabled 	= true;
        flightHotelForm.fs_mesanyo.disabled = true;
        flightHotelForm.retTime.disabled 	= true;
        flightHotelForm.fechaRetorno.disabled = true;
	}
}

function initFechasIEVH(){
	var fecInicial = new Date();
	flightHotelForm.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightHotelForm.fe_dia.value = addcero(fecInicial.getDate());
	flightHotelForm.fechaSalida.value = flightHotelForm.fe_dia.value+"/"+flightHotelForm.fe_mesanyo.value.substring(4)+"/"+flightHotelForm.fe_mesanyo.value.substring(0,4);
	
	fecInicial.setDate(fecInicial.getDate()+1);
	flightHotelForm.fs_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightHotelForm.fs_dia.value = addcero(fecInicial.getDate());
	flightHotelForm.fechaRetorno.value = flightHotelForm.fs_dia.value+"/"+flightHotelForm.fs_mesanyo.value.substring(4)+"/"+flightHotelForm.fs_mesanyo.value.substring(0,4);
}

function initFechasOtrosVH(){
	var fecInicial = new Date();
	flightHotelForm.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightHotelForm.fe_dia.value = addcero(fecInicial.getDate());
	
	fecInicial.setDate(fecInicial.getDate()+1);
	flightHotelForm.fs_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	flightHotelForm.fs_dia.value = addcero(fecInicial.getDate());
}


		function validateSearch(number,dep,arr,message)
		{
			var depSelect = document.getElementById(dep);
			var arrSelect = document.getElementById(arr);
			if (depSelect.value!='XXX' && arrSelect.value!='XXX' && depSelect.value!='' && arrSelect.value!='')
			{
				goSubmitBuscador2007('0');
			}
			else
			{
				alert(message);
			}
		}
		function moreLessRoutes(link)
		{
			if (moreLessRoutesStatus == 'more')
			{
				stationsJson = '/common/js/JSON/stations-full.json';
				loadStations('depCity', 'origins', '--Origen--', 'XXX', 'loadingDep');
				loadStations('arrCity', 'destinations', '--Destino--', 'XXX', 'loadingArr');
				link.innerHTML = 'Menos rutas';
				moreLessRoutesStatus = 'less';
			}
			else
			{
				stationsJson = '/common/js/JSON/stations.json';
				loadStations('depCity', 'origins', '--Origen--', 'XXX', 'loadingDep');
				loadStations('arrCity', 'destinations', '--Destino--', 'XXX', 'loadingArr');
				link.innerHTML = 'Más rutas';
				moreLessRoutesStatus = 'more';
			}
		}


