var Hoy=new Date();
arrDia = new Array();
arrDia[0] = new Array(7);
arrDia[0][0] = "Domingo";
arrDia[0][1] = "Lunes";
arrDia[0][2] = "Martes";
arrDia[0][3] = "Mi?rcoles";
arrDia[0][4] = "Jueves";
arrDia[0][5] = "Viernes"; 
arrDia[0][6] = "S?bado";

function complexQueryByPrice() {
	with (document.RgAvailability) {
	flag.value='complexmpavail';
	(DEPARTURE_DESC_LOC_C1.value=='' && B_LOCATION_IN_C1.value!='' )?B_LOCATION_C1.value=B_LOCATION_IN_C1.value:B_LOCATION_C1.value=DEPARTURE_DESC_LOC_C1.value;
    (ARRIVAL_DESC_LOC_C1.value=='' && B_LOCATION_IN_C1.value!='' ) ? E_LOCATION_C1.value=E_LOCATION_IN_C1.value:E_LOCATION_C1.value=ARRIVAL_DESC_LOC_C1.value;
    (DEPARTURE_DESC_LOC_C2.value=='' && B_LOCATION_IN_C2.value!='' )?B_LOCATION_C2.value=B_LOCATION_IN_C2.value:B_LOCATION_C2.value=DEPARTURE_DESC_LOC_C2.value;
    (ARRIVAL_DESC_LOC_C2.value=='' && B_LOCATION_IN_C2.value!='' ) ? E_LOCATION_C2.value=E_LOCATION_IN_C2.value:E_LOCATION_C2.value=ARRIVAL_DESC_LOC_C2.value;
    (DEPARTURE_DESC_LOC_C3.value=='' && B_LOCATION_IN_C3.value!='' ) ?B_LOCATION_C3.value=B_LOCATION_IN_C3.value:B_LOCATION_C3.value=DEPARTURE_DESC_LOC_C3.value;
    (ARRIVAL_DESC_LOC_C3.value=='' && B_LOCATION_IN_C3.value!='' ) ? E_LOCATION_C3.value=E_LOCATION_IN_C3.value:E_LOCATION_C3.value=ARRIVAL_DESC_LOC_C3.value;
    (DEPARTURE_DESC_LOC_C4.value=='' && B_LOCATION_IN_C4.value!='' ) ?B_LOCATION_C4.value=B_LOCATION_IN_C4.value:B_LOCATION_C4.value=DEPARTURE_DESC_LOC_C4.value;
    (ARRIVAL_DESC_LOC_C4.value=='' && B_LOCATION_IN_C4.value!='' )  ? E_LOCATION_C4.value=E_LOCATION_IN_C4.value:E_LOCATION_C4.value=ARRIVAL_DESC_LOC_C4.value;

	feC1dia='';
	feC2dia='';
	feC3dia='';
	feC4dia='';
	feC1dia=fe_dia_C1.value;
	if (feC1dia.length==1) feC1dia = "0"+feC1dia;
	feC2dia=fe_dia_C2.value;
	if (feC2dia.length==1) feC2dia = "0"+feC2dia;
	feC3dia=fe_dia_C3.value;
	if (feC3dia.length==1) feC3dia = "0"+feC3dia;
	feC4dia=fe_dia_C4.value;
	if (feC4dia.length==1) feC4dia = "0"+feC4dia;

	feC1hour="0000";
	if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='MORNING') {
		feC1hour="1000";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='AFTERNOON') {
		feC1hour="1600";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='EVENING') {
		feC1hour="2000";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value!='') {
		feC1hour=D_HOUR_C1[D_HOUR_C1.selectedIndex].value;
		B_ANY_TIME_C1.value="false";
	}

	feC4hour="0000";
	if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='MORNING') {
		feC4hour="1000";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='AFTERNOON') {
		feC4hour="1600";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='EVENING') {
		feC4hour="2000";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value!='') {
		feC4hour=D_HOUR_C4[D_HOUR_C4.selectedIndex].value;
		B_ANY_TIME_C4.value="false";
	}

	feC3hour="0000";
	if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='MORNING') {
		feC3hour="1000";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='AFTERNOON') {
		feC3hour="1600";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='EVENING') {
		feC3hour="2000";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value!='') {
		feC3hour=D_HOUR_C3[D_HOUR_C3.selectedIndex].value;
		B_ANY_TIME_C3.value="false";
	}

	feC2hour="0000";
	if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='MORNING') {
		feC2hour="1000";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='AFTERNOON') {
		feC2hour="1600";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='EVENING') {
		feC2hour="2000";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value!='') {
		feC2hour=D_HOUR_C2[D_HOUR_C2.selectedIndex].value;
		B_ANY_TIME_C2.value="false";
	}

    if (feC1dia!='' && feC1dia!='' && B_LOCATION_C1!='' && E_LOCATION_C1!='') B_DATE_C1.value=fe_mesanyo_C1.value+feC1dia+feC1hour;
    if (feC2dia!='' && feC2dia!='' && B_LOCATION_C2!='' && E_LOCATION_C2!='') B_DATE_C2.value=fe_mesanyo_C2.value+feC2dia+feC2hour;
    if (feC3dia!='' && feC3dia!='' && B_LOCATION_C3!='' && E_LOCATION_C3!='') B_DATE_C3.value=fe_mesanyo_C3.value+feC3dia+feC3hour;
    if (feC4dia!='' && B_LOCATION_C4!='' && E_LOCATION_C4!='') B_DATE_C4.value=fe_mesanyo_C4.value+feC4dia+feC4hour;
	document.RgAvailability.TRIP_TYPE[0].checked=true;
	return 0;
	}
}

function complexQueryByTime() {
	with (document.RgAvailability) {
	flag.value='complexairavail';
	(DEPARTURE_DESC_LOC_C1.value=='' && B_LOCATION_IN_C1.value!='' )?B_LOCATION_C1.value=B_LOCATION_IN_C1.value:B_LOCATION_C1.value=DEPARTURE_DESC_LOC_C1.value;
    (ARRIVAL_DESC_LOC_C1.value=='' && B_LOCATION_IN_C1.value!='' ) ? E_LOCATION_C1.value=E_LOCATION_IN_C1.value:E_LOCATION_C1.value=ARRIVAL_DESC_LOC_C1.value;
    (DEPARTURE_DESC_LOC_C2.value=='' && B_LOCATION_IN_C2.value!='' )?B_LOCATION_C2.value=B_LOCATION_IN_C2.value:B_LOCATION_C2.value=DEPARTURE_DESC_LOC_C2.value;
    (ARRIVAL_DESC_LOC_C2.value=='' && B_LOCATION_IN_C2.value!='' ) ? E_LOCATION_C2.value=E_LOCATION_IN_C2.value:E_LOCATION_C2.value=ARRIVAL_DESC_LOC_C2.value;
    (DEPARTURE_DESC_LOC_C3.value=='' && B_LOCATION_IN_C3.value!='' ) ?B_LOCATION_C3.value=B_LOCATION_IN_C3.value:B_LOCATION_C3.value=DEPARTURE_DESC_LOC_C3.value;
    (ARRIVAL_DESC_LOC_C3.value=='' && B_LOCATION_IN_C3.value!='' ) ? E_LOCATION_C3.value=E_LOCATION_IN_C3.value:E_LOCATION_C3.value=ARRIVAL_DESC_LOC_C3.value;
    (DEPARTURE_DESC_LOC_C4.value=='' && B_LOCATION_IN_C4.value!='' ) ?B_LOCATION_C4.value=B_LOCATION_IN_C4.value:B_LOCATION_C4.value=DEPARTURE_DESC_LOC_C4.value;
    (ARRIVAL_DESC_LOC_C4.value=='' && B_LOCATION_IN_C4.value!='' )  ? E_LOCATION_C4.value=E_LOCATION_IN_C4.value:E_LOCATION_C4.value=ARRIVAL_DESC_LOC_C4.value;

	feC1dia=fe_dia_C1.value;
	if (feC1dia.length==1) feC1dia = "0"+feC1dia;
	feC2dia=fe_dia_C2.value;
	if (feC2dia.length==1) feC2dia = "0"+feC2dia;
	feC3dia=fe_dia_C3.value;
	if (feC3dia.length==1) feC3dia = "0"+feC3dia;
	feC4dia=fe_dia_C4.value;
	if (feC4dia.length==1) feC4dia = "0"+feC4dia;

	feC1hour="0000";
	if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='MORNING') {
		feC1hour="1000";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='AFTERNOON') {
		feC1hour="1600";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value=='EVENING') {
		feC1hour="2000";
	} else if (D_HOUR_C1[D_HOUR_C1.selectedIndex].value!='') {
		feC1hour=D_HOUR_C1[D_HOUR_C1.selectedIndex].value;
	} else B_ANY_TIME_C1.value="true";
 
	feC4hour="0000";
	if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='MORNING') {
		feC4hour="1000";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='AFTERNOON') {
		feC4hour="1600";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value=='EVENING') {
		feC4hour="2000";
	} else if (D_HOUR_C4[D_HOUR_C4.selectedIndex].value!='') {
		feC4hour=D_HOUR_C4[D_HOUR_C4.selectedIndex].value;
	} else B_ANY_TIME_C4.value="true";

	feC3hour="0000";
	if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='MORNING') {
		feC3hour="1000";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='AFTERNOON') {
		feC3hour="1600";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value=='EVENING') {
		feC3hour="2000";
	} else if (D_HOUR_C3[D_HOUR_C3.selectedIndex].value!='') {
		feC3hour=D_HOUR_C3[D_HOUR_C3.selectedIndex].value;
	} else B_ANY_TIME_C3.value="true";

	feC2hour="0000";
	if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='MORNING') {
		feC2hour="1000";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='AFTERNOON') {
		feC2hour="1600";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value=='EVENING') {
		feC2hour="2000";
	} else if (D_HOUR_C2[D_HOUR_C2.selectedIndex].value!='') {
		feC2hour=D_HOUR_C2[D_HOUR_C2.selectedIndex].value;
	} else B_ANY_TIME_C2.value="true";

    if (feC1dia!='' && feC1dia!='' && B_LOCATION_C1!='' && E_LOCATION_C1!='') B_DATE_C1.value=fe_mesanyo_C1.value+feC1dia+feC1hour;
    if (feC2dia!='' && feC2dia!='' && B_LOCATION_C2!='' && E_LOCATION_C2!='') B_DATE_C2.value=fe_mesanyo_C2.value+feC2dia+feC2hour;
    if (feC3dia!='' && feC3dia!='' && B_LOCATION_C3!='' && E_LOCATION_C3!='') B_DATE_C3.value=fe_mesanyo_C3.value+feC3dia+feC3hour;
    if (feC4dia!='' && B_LOCATION_C4!='' && E_LOCATION_C4!='') B_DATE_C4.value=fe_mesanyo_C4.value+feC4dia+feC4hour;
	document.RgAvailability.TRIP_TYPE[0].checked=true;
	return 0;
	}
}

function Oferta(cod, oid,airline) {
	if (cod.substring(0,1) == "F" && airline=="XX" ){
		DS(secureConn+"sb/sb000fof.jsp", {promoTypeNo:'0',id:cod},'_self');
	} else {
		DS("../sb/sb009pro.jsp", {promoTypeNo:'0',promoOID:oid},'_self');
	}
}

function DayOfWeek(pais, mesyear, dia, dayofweek){
	lang = 0;
	year=mesyear.value.substring(0,4);
	mes=mesyear.value.substring(4);
	var c = new Date( year,(mes-1),dia.value );
	var dayOfWeek = c.getDay();
	if (-1!=(mes-1) && (mes-1)<=12 &&-1!=dia.value && dia.value<=31 ) {
		diaSemana = arrDia[lang][dayOfWeek];
		dayofweek.value = diaSemana;
	}
}

function queryByPrice(){
	document.RgAvailability.D_DATE.value=document.RgAvailability.fe_mesanyo.value+fedia+fehour;
	document.RgAvailability.R_DATE.value=document.RgAvailability.fs_mesanyo.value+fsdia+fshour;
	document.RgAvailability.flag.value='mpavailability';
	if (document.RgAvailability.CABIN.options[document.RgAvailability.CABIN.selectedIndex].value=="R") document.RgAvailability.CABIN.options[4].value="E";
	return 0;
}

function queryByTime(){
	document.RgAvailability.flag.value='airavailability';
	document.RgAvailability.B_DATE_1.value=document.RgAvailability.fe_mesanyo.value+fedia+fehour;
	document.RgAvailability.B_LOCATION_1.value=document.RgAvailability.B_LOCATION_IN.value;
	document.RgAvailability.E_LOCATION_1.value=document.RgAvailability.E_LOCATION_IN.value;
	if (document.RgAvailability.TRIP_TYPE[0].checked){//Si esta marcado el radio para ida y vuelta
		document.RgAvailability.B_DATE_2.value=document.RgAvailability.fs_mesanyo.value+fsdia+fshour;
		document.RgAvailability.B_LOCATION_2.value=document.RgAvailability.E_LOCATION_IN.value;
		document.RgAvailability.E_LOCATION_2.value=document.RgAvailability.B_LOCATION_IN.value;
	}
	if (document.RgAvailability.CABIN.selectedIndex==0) document.RgAvailability.CABIN.options[0].value="X";
	return 0;
}

function validaForm(form){
   if (!form.TRIP_TYPE[2].checked){ //Si no se ha elegido multiples itinerarios
	//Origen
	if (form.B_LOCATION_IN.value=="" ){
		form.B_LOCATION_IN.value=form.DEPARTURE_DESC_LOC.value;
	}
	//Destino
	if (form.E_LOCATION_IN.value=="") {
		form.E_LOCATION_IN.value=form.ARRIVAL_DESC_LOC.value;
	}
	//Origen y destino
	if (form.B_LOCATION_IN.value=="" || form.E_LOCATION_IN.value=="") {
		alert(alert_location);
		return -1
	}
	if (form.B_LOCATION_IN.value==form.E_LOCATION_IN.value) {
		alert(alert_sameloc);
		return -1
	}
	//fechas
	today =today_Date();
	diah=parseInt(today.substring(0,today.indexOf('/')),10);
	mesh=parseInt(today.substring(today.indexOf('/')+1,today.indexOf('/',3)),10);
	anyh=parseInt(today.substring(today.indexOf('/',3)+1,today.length),10);
	diae=parseInt(form.fe_dia[form.fe_dia.selectedIndex].value,10);
	mese=1*(form.fe_mesanyo[form.fe_mesanyo.selectedIndex].value.substring(4,6));
	anye=parseInt(form.fe_mesanyo[form.fe_mesanyo.selectedIndex].value.substring(0,4),10);
	dateHoy	= new Date(anyh, (mesh-1), diah);
	dateComboe = new Date(anye, (mese-1), diae);
	if (((anye>anyh) || (anye==anyh && mese>mesh)) || ((anye==anyh && mese==mesh) && diae>=diah)){
		dias=parseInt(form.fs_dia[form.fs_dia.selectedIndex].value,10);
		mess=1*(form.fs_mesanyo[form.fs_mesanyo.selectedIndex].value.substring(4,6));
		anys=parseInt(form.fs_mesanyo[form.fs_mesanyo.selectedIndex].value.substring(0,4),10);
		dateComboss	= new Date(anys, (mess-1), dias);
		if (((dateComboe - dateHoy)/86400000)<3 ) {
			alert(alert_date72);
		}
	} else {
		alert(alert_dateorder);
		return -1;
	}
	if (form.TRIP_TYPE[0].checked){//Si esta marcado el radio para ida y vuelta
		if (((anys>anye) || (anys==anye && mess>mese)) || ((anys==anye && mess==mese) && dias>=diae)) {
		} else {
			alert(alert_dateorder);  
			return -1;
		}
	}
	//pasajeros
	if (parseInt(form.N_INFANT.value)>(parseInt(form.N_ADULT.value)+parseInt(form.N_YOUTH.value)+parseInt(form.N_SENIOR.value)+parseInt(form.N_STUDENT.value))) {
		alert(alert_paxes);
		return -1
	}
  }
}

function search() {
	res = validaForm(document.RgAvailability);
	if (res==-1) return;
	if (document.RgAvailability.DNS.checked) {
		document.RgAvailability.DIRECT_NON_STOP.value = "true";
	} else {
		document.RgAvailability.DIRECT_NON_STOP.value = "false";
	}
	price = '0';
	time = '0';
	if (document.RgAvailability.DEPARTURE_DESC_LOC_C4.value!=''){
		document.RgAvailability.SEARCH_FLAG[1].checked=true;
		document.RgAvailability.SEARCH_FLAG[0].checked=false;
    }
	if (document.RgAvailability.D_HOUR.selectedIndex==0) document.RgAvailability.B_ANY_TIME_1.value = "true";
	else document.RgAvailability.B_ANY_TIME_1.value = "false";
	if (document.RgAvailability.R_HOUR.selectedIndex==0) document.RgAvailability.B_ANY_TIME_2.value = "true";
	else document.RgAvailability.B_ANY_TIME_2.value = "false";

	fehour="0000";
	if (document.RgAvailability.D_HOUR[document.RgAvailability.D_HOUR.selectedIndex].value=='MORNING') {
		fehour="1000";
	} else if (document.RgAvailability.D_HOUR[document.RgAvailability.D_HOUR.selectedIndex].value=='AFTERNOON') {
		fehour="1600";
	} else if (document.RgAvailability.D_HOUR[document.RgAvailability.D_HOUR.selectedIndex].value=='EVENING') {
		fehour="2000";
	} else if (document.RgAvailability.D_HOUR[document.RgAvailability.D_HOUR.selectedIndex].value!='') {
		fehour=document.RgAvailability.D_HOUR[document.RgAvailability.D_HOUR.selectedIndex].value;
		document.RgAvailability.B_ANY_TIME_1.value="false";
	}

	fshour="0000";
	if (document.RgAvailability.R_HOUR[document.RgAvailability.R_HOUR.selectedIndex].value=='MORNING') {
		fshour="1000";
	} else if (document.RgAvailability.R_HOUR[document.RgAvailability.R_HOUR.selectedIndex].value=='AFTERNOON') {
		fshour="1600";
	} else if (document.RgAvailability.R_HOUR[document.RgAvailability.R_HOUR.selectedIndex].value=='EVENING') {
		fshour="2000";
	} else if (document.RgAvailability.R_HOUR[document.RgAvailability.R_HOUR.selectedIndex].value!='') {
		fshour=document.RgAvailability.R_HOUR[document.RgAvailability.R_HOUR.selectedIndex].value;
		document.RgAvailability.B_ANY_TIME_2.value="false";
	}

	fsdia=document.RgAvailability.fs_dia.value;
	if (fsdia.length==1) fsdia = "0"+fsdia;
	fedia=document.RgAvailability.fe_dia.value;
	if (fedia.length==1) fedia = "0"+fedia;
	if (document.RgAvailability.TRIP_TYPE[2].checked){
		if (document.RgAvailability.SEARCH_FLAG[0].checked) {//Masterpricer
			price = complexQueryByPrice();
		} else {
			time = complexQueryByTime();
		}
	} else {
		if (document.RgAvailability.TRIP_TYPE[0].checked) {}
		if (document.RgAvailability.SEARCH_FLAG[0].checked) {//Masterpricer
			price = queryByPrice() ;
		} else {
			time = queryByTime();
		}
	}
	document.RgAvailability.submit();
}

var periodo = 100;
var n= 0;
var auxn = 1;
function cambiaNum() {
	document.buscando.buscando.value = n;
	var td1=document.getElementById("td1");
	var td2=document.getElementById("td2");
	var td3=document.getElementById("td3");
	if (auxn==1 ) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','rumbo4'); //IE
		td2.setAttribute('class','rumbo4'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn++;
	} else if (auxn==2) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','flight'); //IE
		td2.setAttribute('class','flight'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn++;
	} else if (auxn==3) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','flight'); //IE
		td2.setAttribute('class','flight'); //MO
		td3.setAttribute('className','flight'); //IE
		td3.setAttribute('class','flight'); //MO
		auxn++;
	} else if (auxn==4) {
		td1.setAttribute('className','rumbo4'); //IE
		td1.setAttribute('class','rumbo4'); //MO
		td2.setAttribute('className','rumbo4'); //IE
		td2.setAttribute('class','rumbo4'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn=1;
	}
	setTimeout("cambiaNum()",periodo);
	n++;
	if (n==500) n=1;
}

function convert(datefrom){
	return ((datefrom.substring(0, datefrom.indexOf("T"))).replace(/-/gi,"")+"0000");
}

function Sort(criteria){
	document.availthenfare.flag.value="reviewmp";
	document.availthenfare.WORKFLOW_NAME.value="RGSORT";
	document.availthenfare.submit();
}

function Prev(thispage){
	document.availthenfare.flag.value="reviewmp";
	document.availthenfare.WORKFLOW_NAME.value="RGSUBSET";
	document.availthenfare.RECOMM_PAGE_INDICATOR.value=parseInt(thispage)-15;
	document.availthenfare.submit();
}

function Next(thispage){
	document.availthenfare.flag.value="reviewmp";
	document.availthenfare.WORKFLOW_NAME.value="RGSUBSET";
	document.availthenfare.RECOMM_PAGE_INDICATOR.value=value=parseInt(thispage)+15;
	document.availthenfare.submit();
}

function buy(){
//Valido que todos los campos (obligatorios) se rellenen
	if (document.BookTripPlan.CC_NUMBER.value=="")	 { //Teclea nombre y apellidos de la tarjeta
		if ((document.BookTripPlan.OWNER_SURNAME1.value.length + document.BookTripPlan.OWNER_NAME.value.length) >= 28){
			document.BookTripPlan.OWNER_NAME.value = document.BookTripPlan.OWNER_NAME.value.substring(0,(26-document.BookTripPlan.OWNER_SURNAME1.value.length))
			document.BookTripPlan.OWNER_SURNAME2.value= "";
		} else {
			document.BookTripPlan.OWNER_SURNAME2.value=document.BookTripPlan.OWNER_SURNAME2.value.substring(0,(25-(document.BookTripPlan.OWNER_SURNAME1.value.length + document.BookTripPlan.OWNER_NAME.value.length)));
		}
	}
	if (typeof(document.BookTripPlan.MAILING_ADDRESS_REGION)!='undefined')	 {
		document.BookTripPlan.MAILING_ADDRESS_REGION.value=document.BookTripPlan.MAILING_ADDRESS_REGION_d.value;
	}
	document.BookTripPlan.INVOICE_REGION.value=document.BookTripPlan.INVOICE_REGION_d.value;

	for (k=0; k<document.BookTripPlan.elements.length; k++) {
		if (document.BookTripPlan.elements[k].type=="text" && document.BookTripPlan.elements[k].value=="")	{
			 if (document.BookTripPlan.elements[k].name.indexOf("INVOICE_")==-1 ) {
				 if (document.BookTripPlan.CC_NUMBER.value=="" &&document.BookTripPlan.elements[k].name!="OWNER_SURNAME2") {
					alert(getFieldsError());
					return;
				 } else if (document.BookTripPlan.elements[k].name!="OWNER_SURNAME1" &&document.BookTripPlan.elements[k].name!="OWNER_SURNAME2"){
					alert(getFieldsError());
					return;
				 }
			 } else {
				if (document.BookTripPlan.checkINV.checked) {
					alert(getFieldsError());
					return;
				 }
			 }
		}
	}
	 FecTarjeta= new RegExp("^((0[0-9])|(1[0-2]))\/?[0-1][0-9]$");
	 if ( document.BookTripPlan.CC_NUMBER.value=="" && (!luhnCheck(document.BookTripPlan.ACCOUNT_NUMBER.value) || !FecTarjeta.test(document.BookTripPlan.EXPIRY_DATE_MMYY.value))){
	 	alert(getCreditCardError());
	    return;
	 }
	fecha = document.BookTripPlan.EXPIRY_DATE_MMYY.value;
	if (fecha.length==4){
		document.BookTripPlan.EXPIRY_DATE.value = "20"+fecha.substring(2,4)+"-"+fecha.substring(0,2)+"-28T00:00:00.000Z";
	} else {
		document.BookTripPlan.EXPIRY_DATE.value =  "20"+fecha.substring(3,5)+"-"+fecha.substring(0,2)+"-28T00:00:00.000Z";
	}
	//Compruebo si el titular de la tarjeta viaja
	for (i=1;i<document.BookTripPlan.length;i++) {
		//Busco si el OWNER_SURNAME1 est? contenido dentro del nombre de alguno de los pasajeros.
		if (document.BookTripPlan.elements[i].name.indexOf("PAX_")==0){
			if (document.BookTripPlan.elements[i].value.toUpperCase().indexOf(document.BookTripPlan.OWNER_SURNAME1.value.toUpperCase())!=-1){
				document.BookTripPlan.buyerNotPax.value="false";
				break;
			}
		}
	}
	if (CheckCC =='1'&& document.BookTripPlan.buyerNotPax.value=="true" && document.BookTripPlan.CC_NUMBER.value=="")	{ //No es cliente o s? lo es pero no introduce contrase?a
		    //Si no viaja el titular de la tarjeta, antes de sacarle el alert hay qeu ver si TODOS los pasajeros
			//son pasajeros autorizados. En caso de que hay alguno que no lo sea, mostramos el div con el mensaje
			//de aviso y damos la opci?n de autorizar a los que no est?n autorizados.
			showAuthPaxes ("AUTHPAXES","SUSTITUIR");
			PaxAuth();
			return;
	} else if (CheckCC =='1'&& document.BookTripPlan.CC_NUMBER.value!="") { //Utiliza una tarjeta de las qe tiene registradas
		//Compruebo si el titular de la tarjeta viaja
		for  ( i=1;i<document.BookTripPlan.length;i++) {
			//Busco si el apellido de alg?n pax est? contenido dentro del nombre de la tarjeta.
			document.BookTripPlan.buyerNotPax.value="true";
			if (document.BookTripPlan.elements[i].name.indexOf("PAX_")==0){
				if (document.BookTripPlan.OWNER_NAME.value.toUpperCase().indexOf(document.BookTripPlan.elements[i].value.substring(0,document.BookTripPlan.elements[i].value.indexOf("/")).toUpperCase())!=-1){
					document.BookTripPlan.buyerNotPax.value="false";
					break;
				}
			}
		}
		//PROVISIONAL: en este caso asumimos siempre que el pago es ok
		document.BookTripPlan.buyerNotPax.value="false";
		//Si no viaja el titular, compruebo si es pasajero autorizado
		if (document.BookTripPlan.buyerNotPax.value=="true"){
			PaxAuth(); //Marca como checked los pasajeros seg?n est?n autorizados o no
			for (s=0; s< document.dd.elements.length; s++){
				if (document.dd.elements[s].value!="T") {
						document.BookTripPlan.buyerNotPax.value="true";
						showAuthPaxes("AUTHPAXES","SUSTITUIR");
						return;
				} else	document.BookTripPlan.buyerNotPax.value="false";
			}
		}
	} else if (CheckCC=='1' && parseFloat(document.BookTripPlan.preciototal.value)>=parseFloat(PriceLimit) &&document.BookTripPlan.currency.value ==CurrencyLimit && document.BookTripPlan.CC_NUMBER.value=="" ) {
		alert(getMoreThan600());
	}
	document.BookTripPlan.OWNER_SURNAME.value = document.BookTripPlan.OWNER_SURNAME1.value+" "+document.BookTripPlan.OWNER_SURNAME2.value;
	cambia_puntos();
	if (ALREADY_SUBMITED!="true"){
		document.BookTripPlan.submit();
	}
	ALREADY_SUBMITED="true";
}

var pto="";
var contpto = 0;
function cambia_puntos() {
	if (contpto==15) document.p.p.value = pto;
	contpto++;
	setTimeout("cambia_puntos()",(1/100000));
	pto = document.p.p.value + ".";
	if (contpto==16 ) {
		pto="";
		contpto=0;
	}
	if (document.p.p.value.length ==80) document.p.p.value="";
}

function showAuthPaxes (display,hide){
	if (document.all){
		document.all[hide].style.display="none";
		document.all[display].style.display="";
	}else if (document.layers){
		document.all[hide].display="none";
		document.layers[display].display="";
	}else{
		document.getElementById(hide).style.display="none";
		document.getElementById(display).style.display="";
	}
}

function cancelPNR(RecLoc){
	document.CancelPNR.RECORD_LOCATOR.value=RecLoc;
	document.CancelPNR.submit();
}

function set(asiento, newim){
	for (i=1;i<=parseInt(opener.document.AddElementsOutput2.NUM_PAX.value);i++){
	if (document.getElementById("PAX_"+i).value=='') {
		if (eval("newim == document.im"+asiento.replace(" ","")+".src")){
			alert(alert_sameseat);
			return;
		}
		eval("document.im"+asiento.replace(" ","")+".src=\""+newim+"\"");
		document.getElementById("PAX_"+i).value=asiento;
		break;
		}
	}
}

function Paxes() {
	for(i=1;i<=parseInt(opener.document.AddElementsOutput2.NUM_PAX.value);i++){
		var inp = document.createElement('INPUT');
		inp.id = 'PAX_'+i;
		inp.name =  'PAX_'+i;
		inp.type="text";
		inp.size="3";
		inp.setAttribute('className','disabled'); //IE
		inp.setAttribute('class', 'disabled'); //MO
		var radio = document.createElement("INPUT");
		radio.setAttribute('name','radiopax');
		radio.setAttribute("type","radio");
		radio.setAttribute("value",i);
		radio.setAttribute("id","radiopax");
		var tabpaxes = document.createElement('table');
		var div=document.getElementById('tabpaxes');
		div.appendChild(tabpaxes);
		var trpaxes = document.createElement("tr");
		trpaxes.valign="baseline";
		var td = document.createElement("td");
		td.setAttribute('className','rumbo4'); //IE
		td.setAttribute('class', 'rumbo4'); //MO
	    var txt = document.createTextNode(eval("opener.document.AddElementsOutput2.PAX_"+i+".value")+"   ");
		var tbody = document.createElement('tbody');
		tabpaxes.appendChild(tbody);
		tbody.appendChild(trpaxes);
		trpaxes.appendChild(td);
		td.appendChild(txt);
		td.appendChild(inp);
	}
	document.write('<table>');
	document.write('<tr>');
	document.write('<td height="1" class="RUMBO1"></td>');
	document.write('</table>');
}

function hideInvoice() {
	if (document.all){
		document.all["INVOICE"].style.display="none";
	} else if (document.layers){
		document.all["INVOICE"].display="none";
	} else {
		document.getElementById("INVOICE").style.display="none";
	}
}

function showInvoice() {
	if (!document.BookTripPlan.checkINV.checked){
		hideInvoice();
		return;
	}
	if (document.all){
		document.all["INVOICE"].style.display="";
	} else if (document.layers){
		document.layers["INVOICE"].display="";
	} else {
		document.getElementById("INVOICE").style.display="";
	}
}

function hideDiv(id) {
	if (document.all){
		document.all[id].style.display="none";
	} else if (document.layers){
		document.all[id].display="none";
	} else{
		document.getElementById(id).style.display="none";
	}
}

function showDiv(id){
	if (document.all){
		document.all[id].style.display="";
	} else if (document.layers){
		document.layers[id].display="";
	} else{
		document.getElementById(id).style.display="";
	}
}

/* DTORESIDENTE */
function showDtoRes(num) {
	if (!eval('document.availthenfare.checkDtoRes_'+num+'.checked')){
		hideDiv("DTORESIDENTE_"+num);
		return;
	}
	showDiv("DTORESIDENTE_"+num);
}

/* DTORESIDENTEBB */
function showDtoResBB(num) {
	if (!eval('document.availthenfare.checkDtoResBB_'+num+'.checked')){
		hideDiv("DTORESIDENTEBB_"+num);
		return;
	}
	showDiv("DTORESIDENTEBB_"+num);
}

function pswCard() {
	document.pswCard.password.value  = document.BookTripPlan.password.value;
	document.pswCard.OPTION.value = "pswCard";
	document.pswCard.submit();
}

function PswRecover() {
	if (document.BookTripPlan.EMAIL_RAPTOR.value == ""){
		alert(getNoneEmail());
    } else {
		document.RaptorSrv.EMAIL_RAPTOR.value = document.BookTripPlan.EMAIL_RAPTOR.value;
		document.RaptorSrv.submit();
		alert(getPswRecovering());
	}
}

function farenotes(note) {
	document.notes.LIST_CATEGORY.value = note;
	document.notes.submit();
}

function LookupLocationAndBack(url, index){
	index_air = index;
	document.flightForm.INDEX_AIR.value=index;
	window.open(url,'Aeropuertos', 'resizable=yes,toolbars=no,scrollbars=yes,screenX=0,screenY=0,width=633,height=550');
}

function DepLoc(){
    if (document.formVueltamundo.DEPARTURE_DESC_LOC.value.indexOf("--")==-1)
        document.formVueltamundo.B_LOCATION_IN.value=document.formVueltamundo.DEPARTURE_DESC_LOC.value;
    else
        document.formVueltamundo.B_LOCATION_IN.value=document.formVueltamundo.DEPARTURE_DESC_LOC.value.substring(0,3);
}

function ArrLoc(){
    if (document.RgAvailability.ARRIVAL_DESC_LOC.value.indexOf("--")==-1)
        document.RgAvailability.E_LOCATION_IN.value=document.RgAvailability.ARRIVAL_DESC_LOC.value;
    else
        document.RgAvailability.E_LOCATION_IN.value=document.RgAvailability.ARRIVAL_DESC_LOC.value.substring(0,3);
}

function setFrequentFlyer(code) {
	companyHolder.value = code;
}

function CompanyHolder (url,element) {
	companyHolder =  element;
	window.open(url,'Aeropuertos', 'resizable=yes,toolbars=no,scrollbars=yes,screenX=0,screenY=0,width=633,height=550');
}

function Location(url, elementcode, elementname){
	locCodeHolder = elementcode;
	locDescHolder = elementname;
	window.open(url,'Aeropuertos', 'resizable=yes,toolbars=no,scrollbars=yes,screenX=0,screenY=0,width=633,height=550');
}

function setLocationCode(code) {
	locCodeHolder.value = code;
}

function setLocationDesc(code) {
	locDescHolder.value = code;
}

function getProvincia(cP){
  var rCity = "";
  var aCity = ["ALAVA","ALBACETE","ALICANTE","ALMERIA","AVILA","BADAJOZ","ISLAS BALEARES","BARCELONA","BURGOS","CACERES","CADIZ","CASTELLON","CIUDAD REAL","CORDOBA","CORU?A","CUENCA","GIRONA","GRANADA","GUADALAJARA","GUIPUZCOA","HUELVA","HUESCA","JAEN","LEON","LLEIDA","LA RIOJA","LUGO","MADRID","MALAGA","MURCIA","NAVARRA","OURENSE","ASTURIAS","PALENCIA","LAS PALMAS","PONTEVEDRA","SALAMANCA","SANTA CRUZ DE TENERIFE","CANTABRIA","SEGOVIA","SEVILLA","SORIA","TARRAGONA","TERUEL","TOLEDO","VALENCIA","VALLADOLID","VIZCAYA","ZAMORA","ZARAGOZA","CEUTA","MELILLA"];
  var aCP   = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52];
  if (!isEmptyString(cP) && cP.length == 5 && !isNaN(cP)){
	cP = cP.substring(0,2);
	for (var i=0;i<aCP.length;i++){
	  if (cP == aCP[i])
		rCity = aCity[i];
	}
  }
  return rCity;
}

function airlineToTextInput(defaultAirlineCode, defaultAirlineName) {
	var newHtml = "<input type=\"hidden\" class=\"RUMBO1\" name=\"carrier1\" value=\"" + defaultAirlineCode + "\">";
	newHtml = newHtml + "<input type=\"text\" class=\"RUMBO1\" name=\"SELECTED_AIRLINE_NAME\" value=\"" + defaultAirlineName + "\" onfocus=\"invalidateAirlineCode()\" onkeypress=\"invalidateAirlineCode()\">";
	var airSelectDiv = document.getElementById("AirlineFilterDisplay");
	airSelectDiv.innerHTML=newHtml;
}