// [init]
var adt_number = "";
var chd_number = "";
var infants_number = "";
var member_no = "";
if (JLJS02.site.lang.isEN) {
	adt_number = "Adultes (\u00e2g\u00e9s de 12 ans et plus le jour du d\u00e9part sur un vol international)";
	chd_number = "Enfants (\u00e2g\u00e9s de 2 \u00e0 11 ans le jour du d\u00e9part sur un vol international et b\u00e9b\u00e9s occupant un si\u00e8ge)";
	infants_number =
			"B\u00e9b\u00e9s (\u00e2g\u00e9s de moins de 2 ans le jour du d\u00e9part sur un vol international et n'occupant pas de si\u00e8ge)";
	member_no = '<img src="/common/img/icon_balloon_001.gif" width="52" height="30" alt="">Membership Number<br>(7 or 9 digits)'	
}else{
	adt_number = "\u5927\u4eba(12\u624d\u4ee5\u4e0a)&nbsp;&nbsp;&nbsp;&nbsp;(\u6d77\u5916\u65c5\u884c\u958b\u59cb\u65e5\u306e\u5e74\u9f62)";
	chd_number = "\u5c0f\u5150(2\u624d~11\u624d)&nbsp;&nbsp;&nbsp;&nbsp;(\u6d77\u5916\u65c5\u884c\u958b\u59cb\u65e5\u306e\u5e74\u9f62)&nbsp;&nbsp;&nbsp;&nbsp;(\u304a\u3088\u3073\u5ea7\u5e2d\u3092\u3054\u5229\u7528\u306e\u5e7c\u5150)";
	infants_number =
			"\u5e7c\u5150(0\u624d~1\u624d)&nbsp;&nbsp;&nbsp;&nbsp;(\u6d77\u5916\u65c5\u884c\u958b\u59cb\u65e5\u306e\u5e74\u9f62)&nbsp;&nbsp;&nbsp;&nbsp;(\u4f46\u3057\u3001\u5ea7\u5e2d\u3054\u5229\u7528\u306e\u5e7c\u5150\u3092\u9664\u304f)";
	member_no = '<img src="/common/img/icon_balloon_001.gif" width="52" height="30" alt="">\u304a\u5f97\u610f\u69d8\u756a\u53f7<br>(7\u6841\u304b9\u6841)'
}

var JLJS_InfoBalloonData = {
	'member_no' : member_no,
	'FIELD_ADT_NUMBER1' : adt_number,
	'FIELD_CHD_NUMBER1' : chd_number,
	'FIELD_INFANTS_NUMBER1' : infants_number//,
};

JLJS.addOnload( function() {

	var defaultAreaSlctSet1 = null;
	var defaultAreaSlctSet2 = null;;
	var defaultArea1 = "FRA_02";
	var defaultArea2 = "JPN_08";
	var defaultCity1 = "PAR";
	var defaultCity2 = null;
	var onLineOnly1 = 0;
	var onLineOnly2 = 0;
	var onLineSeparatingView_Off1 = 1;
	var onLineSeparatingView_Off2 = 0;
	var noAreaSelection1 = 1;
	var noAreaSelection2 = 1;
	var noGroup1 = 1;
	var noGroup2 = 1;
	var noDevide1 = 1;
	var noDevide2 = 0;
	var defaultDay_Outbound = 1;
	var defaultDay_Inbound = defaultDay_Outbound + 5;

	JLJS_TicketModuleSetup_Fp( [
		{ "areaSlctSet" : defaultAreaSlctSet1, "default" : [ defaultArea1, defaultCity1 ], "AMD" : 1, "onLineOnly" : onLineOnly1, "noAreaSelection" : noAreaSelection1, "onLineSeparatingView_Off" : onLineSeparatingView_Off1, "noGroup" : noGroup1, "noDevide" : noDevide1, "EN" : ( JLJS02.site.lang.isEN ) ? 1 : 0 },
		{ "areaSlctSet" : defaultAreaSlctSet2, "default" : [ defaultArea2, defaultCity2 ], "AMD" : 1, "onLineOnly" : onLineOnly2, "noAreaSelection" : noAreaSelection2, "onLineSeparatingView_Off" : onLineSeparatingView_Off2, "noGroup" : noGroup2, "noDevide" : noDevide2, "EN" : ( JLJS02.site.lang.isEN ) ? 1 : 0 },
		{ "default" : [ "today+" + defaultDay_Outbound, "today+" + defaultDay_Inbound ] },
		{ "EN" : ( JLJS02.site.lang.isEN ) ? 1 : 0, "isJumpingToOJPage" : 1, "OJ_URL" : "/en/flight_planning/reservation/oj/", "method" : "get" }
	] );

	for (var i=0;i<JLJS_AMDs.length;i++) {
		JLJS_AMDs[i].controlDirectNonStop();
		JLJS.addEvent( JLJS_AMDs[i].formNode["B_LOCATION_1"], "change", function( e ) {
				e.target.form._TM_instance_.controlDirectNonStop();
		} );
		JLJS.addEvent( JLJS_AMDs[i].formNode["E_LOCATION_1"], "change", function( e ) {
				e.target.form._TM_instance_.controlDirectNonStop();
		} );
	}

	if (JLJS02.site.lang.isEN){
		JLJS_AMDCAL.lang = "fr";
	}else{
		JLJS_AMDCAL.lang = "ja";
	}
	JLJS_AMDCAL.url = "/world/fp/common/html/ticketModuleCalendar.html";


} );

// [/init]

// [setHiddenPrm]
JLJS_ticketModule_Fp.prototype.setHiddenPrm = function(){
	this.formNode.action = this.formAction;
	this.formNode["amadeusAction"].value = this.amadeusAction;
	
	this.formNode["EMBEDDED_TRANSACTION"].value = "FlexPricerAvailability";
	this.formNode["SITE"].value = "BCFRBCFR";
	this.formNode["TRIP_FLOW"].value = "YES";
	this.formNode["DIRECT_LOGIN"].value = "NO";
	this.formNode["ARRANGE_BY"].value = "E";
	this.formNode["REFRESH"].value = "0";
	this.formNode["EXTERNAL_ID"].value = "JAL_ER_FR";
	this.formNode["PRICING_TYPE"].value = "O";
	this.formNode["DATE_RANGE_VALUE_1"].value = "3";
	this.formNode["DATE_RANGE_VALUE_2"].value = "3";
	this.formNode["DATE_RANGE_QUALIFIER_1"].value = "C";
	this.formNode["DATE_RANGE_QUALIFIER_2"].value = "C";
	this.formNode["SO_SITE_OFFICE_ID"].value = "PARJL18AA";
	this.formNode["SO_GL"].value = "";	//"SO_GL" is made in a "imprtant notice" page.
	this.formNode["SO_LANG_SITE_AGENCY_LINE2"].value = "";	//"SO_LANG_SITE_AGENCY_LINE2" is made in a "imprtant notice" page.
	this.formNode["SO_SITE_EXT_PSPURL"].value = this.ogoneParam;
	this.formNode["SO_SITE_TRANSFER_LINK"].value = this.transferLinkFlg ? "https://www.5931.jal.co.jp/rsvInter/OsAutoEtAmaAccept.do" : "https://163.211.252.10/rsvInter/OsAutoEtAmaAccept.do";
	this.formNode["SO_SITE_MIN_AVAIL_DATE_SPAN"].value = "H24";
	this.formNode["SO_SITE_MINIMAL_TIME"].value = "H24";
	this.formNode["SO_SITE_MINIMAL_TIME_MODIF"].value = "H24";

	if (this.EN){
		this.formNode["LANGUAGE"].value = "FR";
	}else{
		this.formNode["LANGUAGE"].value = "JP";	
	}

	this.formNode["B_ANY_TIME_1"].value = "TRUE";

	if (this.tripType == "R") {
		this.formNode["B_ANY_TIME_2"].value = "TRUE";
		this.formNode["B_LOCATION_2"].value = this.formNode["E_LOCATION_1"].value;
		this.formNode["E_LOCATION_2"].value = this.formNode["B_LOCATION_1"].value;
	}
	if (this.formNode["IS_FLEXIBLE"].checked) {
		this.formNode["DISPLAY_TYPE"].value = "1";
	}else{
		this.formNode["DISPLAY_TYPE"].value = "2";
	}

	while( this.additionalParameterBlock.firstChild ){
		this.additionalParameterBlock.removeChild( this.additionalParameterBlock.firstChild );
	}
	
	for( var i = 0; i < this.ADT; i ++ ) {
		var newINPUT = document.createElement( 'input' );
		newINPUT.type = "hidden";
		newINPUT.name = "TRAVELLER_TYPE_" + ( i + 1 );
		newINPUT.value = "ADT";
		this.additionalParameterBlock.appendChild( newINPUT );
	}
	
	for( var i = this.ADT; i < this.ADT + this.CHD; i ++ ) {
		var newINPUT = document.createElement( 'input' );
		newINPUT.type = "hidden";
		newINPUT.name = "TRAVELLER_TYPE_" + ( i + 1 );
		newINPUT.value = "CHD";
		this.additionalParameterBlock.appendChild( newINPUT );
	}
	
	for( var i = 0; i < this.INF; i ++ ) {
		var newINPUT = document.createElement( 'input' );
		newINPUT.type = "hidden";
		newINPUT.name = "HAS_INFANT_" + ( i + 1 );
		newINPUT.value = "TRUE";
		this.additionalParameterBlock.appendChild( newINPUT );
	}
}
// [/setHiddenPrm]

// [submitCheck]
JLJS_ticketModule_Fp.prototype.submitCheck = function() {

	this.convertMonValue();

	var errorMsg = "";

	this.depYearMon = this.formNode[ "B_MONTH" ].options[ this.formNode[ "B_MONTH" ].selectedIndex ].value;
	this.depDay = this.formNode[ "B_DAY" ].options[ this.formNode[ "B_DAY" ].selectedIndex ].value;
	this.depDay = ( this.depDay.length < 2 ) ? ( "0" + this.depDay ) : this.depDay;
	this.depTime = "0000";
	this.formNode[ "B_DATE_1" ].value = this.depYearMon + this.depDay + this.depTime;

	this.depYear = this.depYearMon.substr( 0, 4 );
	this.depMon = this.depYearMon.substr( 4, 2 );

	var errorMsg_tmp = this.checkDate( this.depMon, this.depDay, this.depYear, 0 );
	if( errorMsg_tmp ) errorMsg += errorMsg_tmp;

	var today = new Date();
	var depDate = new Date();

	depDate.setFullYear( this.depYear, eval( this.depMon ) - 1, this.depDay );

	if( this.tripType == "R" ) {
		this.rtnYearMon = this.formNode[ "E_MONTH" ].options[ this.formNode[ "E_MONTH" ].selectedIndex ].value;
		this.rtnDay = this.formNode[ "E_DAY" ].options[ this.formNode[ "E_DAY" ].selectedIndex ].value;
		this.rtnDay = ( this.rtnDay.length < 2 ) ? ( "0" + this.rtnDay ) : this.rtnDay;
		this.rtnTime = "0000";
		this.formNode[ "B_DATE_2" ].value = this.rtnYearMon + this.rtnDay + this.rtnTime;

		this.rtnYear = this.rtnYearMon.substr( 0, 4 );
		this.rtnMon = this.rtnYearMon.substr( 4, 2 );

		var errorMsg_tmp = this.checkDate( this.rtnMon, this.rtnDay, this.rtnYear, 1 );
		if( errorMsg_tmp ) errorMsg += errorMsg_tmp;

		var rtnDate = new Date();
		rtnDate.setFullYear( this.rtnYear, eval( this.rtnMon ) - 1, this.rtnDay );
		
		if( depDate.getTime() > rtnDate.getTime()){
			errorMsg +=
				! this.EN ? "- \u5E30\u56FD\u642D\u4E57\u65E5\u304C\u51FA\u767A\u65E5\u3088\u308A\u3082\u524D\u306B\u306A\u3063\u3066\u304A\u308A\u307E\u3059\u3002\n" :
				"- La date de retour doit \u00eatre ult\u00e9rieure \u00e0 la date de d\u00e9part.\n";
		}
	}

	var days_beforeDep = Math.floor(( depDate.getTime() - today.getTime()) / ( 1000 * 60 * 60 * 24 ));
	var n = null;
	if (days_beforeDep < 0){
		n = 0;
	}
	if(days_beforeDep == 0 ){/*[24 hours ago]*/
		n = 1;
	}

	var errorMsg_tmp = "";
	if( n == 0 ) {
		errorMsg_tmp =
		! this.EN ? "- \u51FA\u767A\u65E5\u304C\u672C\u65E5\u3088\u308A\u3082\u524D\u306B\u306A\u3063\u3066\u304A\u308A\u307E\u3059\u3002\n" :
		"- La date de d\u00e9part doit \u00eatre ult\u00e9rieure \u00e0 celle d'aujourd'hui.\n";
	}
	if( n == 1 ){
		errorMsg_tmp =
		! this.EN ? "- \u51FA\u767A\u65E5\u306E" + n + "\u65E5\u524D\u307E\u3067\u306B\u3054\u4E88\u7D04\u304C\u5FC5\u8981\u3067\u3059\u3002\n" : "- La date de d\u00e9part doit \u00eatre au moins " + n + " jours avant le d\u00e9part.\n";
	}

	if( errorMsg_tmp ) errorMsg += errorMsg_tmp;

	this.ADT = eval( this.formNode[ "FIELD_ADT_NUMBER" ].value );
	this.CHD = eval( this.formNode[ "FIELD_CHD_NUMBER" ].value );
	this.INF = eval( this.formNode[ "FIELD_INFANTS_NUMBER" ].value );

	if( ! this.ADT ){
		errorMsg +=
			! this.EN ? "- \u304A\u5B50\u69D8\u306E\u307F\u306E\u3054\u4E88\u7D04\u306F\u53D7\u3051\u4ED8\u3051\u3066\u304A\u308A\u307E\u305B\u3093\u3002\n" : "- Avec un passager adulte au minimum.\n";
	}
	if ( this.ADT < this.INF ){
		errorMsg +=
			! this.EN ? "- 1\u4E73\u5150\u306B\u3064\u304D\u5927\u4EBA\u4E00\u540D\u69D8\u306E\u540C\u4F34\u304C\u5FC5\u8981\u3067\u3059\u3002\n" :	"- " + this.ADT + " enfant(s) en bas \u00e2ge seulement peuvent \u00eatre r\u00e9serv\u00e9s avec " + this.ADT + " adulte(s).\n";
	}
	if( this.ADT + this.CHD > 9 ){
		errorMsg +=
			! this.EN ? "- \u5927\u4EBA\uFF0B\u5B50\u4F9B\u306E\u5408\u8A08\u304C10\u540D\u69D8\u4EE5\u4E0A\u306E\u3054\u4E88\u7D04\u306F\u51FA\u6765\u307E\u305B\u3093\u3002\n" : "- 9 passagers au maximum seulement peuvent \u00eatre r\u00e9serv\u00e9s [adulte(s) + enfant(s)].\n";
	}

	if( this.private_submitCheck()) errorMsg += this.private_submitCheck();

	if( ! errorMsg ) {
		this.setHiddenPrm();
		this.writeCookie();
		if( this.tripType == "M" && this.isJumpingToOJPage ) {
			document.location = this.OJ_URL;
			return false;
		}
		else {
			var wnd = window.open( "", "IBE_window", "resizable=yes,location=no,menubar=no,scrollbars=yes,status=yes,titlebar=yes,toolbar=no" );
			this.formNode.submit(); 
			this.reConvertMonValue();
			return true;
		}
	}
	else {
		alert( errorMsg );
		this.reConvertMonValue();
		return false;
	}
};

JLJS_ticketModule_Fp.prototype.checkDate = function( month, day, year, returning ) {
	var comp1 = ( month == "02" || month == "04" || month == "06" || month == "09" || month == "11" );
	var comp2 = ( day == "31" );
	var Y = eval( year );
	var leap_year = ( Y % 4 == 0 && Y % 100 != 0 ) || ( Y % 400 == 0 );

	if(
		( comp1 && comp2 ) ||
		( month == "02" && day == "30" ) ||
		( ! leap_year && month == "02" && day == "29" )
	) {
		if( ! returning ){
			return !this.EN ? "- \u51FA\u767A\u65E5\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093\u3002\n" : "- Date de départ est non valable.\n";
		}else{
			return !this.EN ? "- \u5E30\u56FD\u642D\u4E57\u65E5\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093\u3002\n" : "- Date de retour est non valable.\n";
		}
	}else{ return ""; }
}
// [/submitCheck]