// JavaScript Document
<!-- 

$(document).ready(function() {
	$('.info-icon img').hide();
	$('#depart').change(function() {
		setCHDAge();   
	});
						   
	$('#return').change(function() {
		checkHKG();
		checkLHR();
	});
	
	$('[name=ADT]').change(function() {
		checkChildAllowed();	
	});
	$('[name=chAge1]').change(function() {
		checkChildAllowed();					 
	});
	$('[name=chAge2]').change(function() {
		checkChildAllowed();					 
	});
	$('[name=chAge3]').change(function() {
		checkChildAllowed();					 
	});
	$('[name=chAge4]').change(function() {
		checkChildAllowed();					 
	});
	$('[name=chAge5]').change(function() {
		checkChildAllowed();					 
	});
	$('[name=chAge6]').change(function() {
		checkChildAllowed();					 
	});
						
});


if (window != window.top) 
  top.location.href = location.href; 

function promowin(filename)
{
   window.open(filename,"programwindow","scrollbars=yes,menubar=no,resizable=no,width=500,height=400");
}

function promowin2(filename)
{
   window.open(filename,"programwindow","scrollbars=yes,menubar=no,resizable=no,width=605,height=400");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function CheckBookingForm(){

if(document.airSearch.elements["INF"]!=null){
var totPaxNo = parseInt(document.airSearch["ADT"].value) + parseInt(document.airSearch["CHD"].value) + parseInt(document.airSearch["INF"].value);
}
if(document.airSearch.elements["IFS"]!=null){
var totPaxNo = parseInt(document.airSearch["ADT"].value) + parseInt(document.airSearch["CHD"].value) + parseInt(document.airSearch["IFS"].value);
}

if ((document.airSearch["departCity"].value) == "")
{
//alert("Invalid flight. Please select a departure city.")
$('#book-error').html("Invalid flight. Please select a departure city.");
$('#book-error').fadeIn("slow");
return false;
};

if (document.airSearch["returnCity"].value == "")
{
//alert("Invalid flight. Please select an arrival city.")
$('#book-error').html("Invalid flight. Please select an arrival city.");
$('#book-error').fadeIn("slow");
return false;
};

if (document.airSearch["departCity"].value == document.airSearch["returnCity"].value)
{
//alert("Invalid flight. Please select a different arrival city.")
$('#book-error').html("Invalid flight. Please select a different arrival city.");
$('#book-error').fadeIn("slow");
return false;
};

if (document.airSearch["depDay"].value == '' || document.airSearch["depMonth"].value == '')
{
//alert("Please complete your Departure Date.")
$('#book-error').html("Please complete your Departure Date.");
$('#book-error').fadeIn("slow");
return false;
};

if (document.airSearch.direction[0].checked == true && (document.airSearch["retDay"].value == '' || document.airSearch["retMonth"].value == ''))
{
//alert("Please complete your Return Date.")
$('#book-error').html("Please complete your Return Date.");
$('#book-error').fadeIn("slow");
return false;
};

if (document.airSearch.elements["Children"].selectedIndex > 0)
{
	if(document.airSearch["ADT"].value=='0'){
		$('#book-error').html("Invalid combination. Please include an Adult.");
		$('#book-error').fadeIn("slow");
		return false;	
	}
		for (i = 1; i <= document.airSearch["CHD"].value; i++) {
			//if (i <= j("chAge"+i).selectedIndex) {
			if (j("chAge"+i).selectedIndex != 0) {
				/*$("chAge"+i).style.display = "block";
				$("spacerChildDateBirth"+i).style.display = "block";
				} else {
				$("childDOB"+i).style.display = "none";
				$("spacerChildDateBirth"+i).style.display = "none";
				}*/
			}else{
				//alert("test "+i);
				$('#book-error').html("Please complete your Child's age.");
				$('#book-error').fadeIn("slow");
				return false;
			}
		}
};

if(document.airSearch.elements["IFS"]!=null){
if (document.airSearch.elements["IFS"].selectedIndex > 0){
	if(document.airSearch["ADT"].value=='0'){
		$('#book-error').html("Invalid combination. Please include an Adult.");
		$('#book-error').fadeIn("slow");
		return false;	
	}
}
};

if(document.airSearch.elements["INF"]!=null){
if (document.airSearch.elements["INF"].selectedIndex > 0){
	if(document.airSearch["ADT"].value=='0'){
		$('#book-error').html("Invalid combination. Please include an Adult.");
		$('#book-error').fadeIn("slow");
		return false;	
	}
}
};

//AU/NZ
checkChildAllowed();

if (totPaxNo>6){
	$('#book-error').html("Maximum of 6 passengers allowed.");
	$('#book-error').fadeIn("slow");
	return false;	
};




//get the user time
//setUserTime();

return true;

}

//added 11MAR10
function checkHKG(){
if (document.airSearch["departCity"].value=='HKG'||document.airSearch["returnCity"].value=='HKG'){
	$('#notice-form-1').html("Flights from Hong Kong are subject to a HKD33 Government Security Charge which is inclusive in the final fare.");
	$('#notice-form-1').fadeIn("slow");
	//alert("HKG!!!");
	return false;
/*} else if (document.airSearch["departCity"].value=='LON'||document.airSearch["returnCity"].value=='LON'){
	$('#notice-form').html("<a href=\"http://www.bruneiair.com/notice/terminal.asp\" target=\"_blank\">RBA relocates to Terminal 4 in Heathrow effective 9th March 2010</a>");
	$('#notice-form').fadeIn("slow");
	return false;*/
}else{
   $('#notice-form-1').hide();
}
}

function checkLHR(){
if (document.airSearch["departCity"].value=='DXB'||document.airSearch["returnCity"].value=='DXB'){
	$('#notice-form-2').hide();
	return false;
}
if (document.airSearch["departCity"].value=='LHR'||document.airSearch["returnCity"].value=='LHR'){
	$('#notice-form-2').html("Flights between Brunei and London will experience a short transit in Dubai.");
	$('#notice-form-2').fadeIn("slow");
	return false;
}
$('#notice-form-2').hide();
}

function setCHDAge(){
	if (document.airSearch["departCity"].value=='BNE'||document.airSearch["departCity"].value=='PER'||document.airSearch["departCity"].value=='SYD'){
		$('#childtxt').html("2-15");
		$('.info-icon img').show();
		$('.info-icon').attr('href', 'http://www.bruneiair.com/faqs/#booking_aus');
		createChildsAge(2,15);
	}else if (document.airSearch["departCity"].value=='AKL'){
		$('#childtxt').html("2-15");
		createChildsAge(2,15);
		$('.info-icon img').show();
		$('.info-icon').attr('href', 'http://www.bruneiair.com/faqs/#booking_nz');
	}else{
		$('#childtxt').html("2-11");
		createChildsAge(2,11);
		$('.info-icon').attr('href', 'http://www.bruneiair.com/faqs');
		$('.info-icon img').hide();
	}
}

function checkChildAllowed(){
	var noADT = 0;
	var noCHDAbove12 = 0;
	var ratio;
	var v1 = document.airSearch["chAge1"].value;
	var v2 = document.airSearch["chAge2"].value;
	var v3 = document.airSearch["chAge3"].value;
	var v4 = document.airSearch["chAge4"].value;
	var v5 = document.airSearch["chAge5"].value;
	var v6 = document.airSearch["chAge6"].value;
	if (document.airSearch["departCity"].value=='BNE'||document.airSearch["departCity"].value=='PER'||document.airSearch["departCity"].value=='SYD'||document.airSearch["departCity"].value=='AKL'){
		noADT = document.airSearch["ADT"].value;
		if(v1>=12) {
			noCHDAbove12++;
		}
		if(v2>=12) {
			noCHDAbove12++;
		}
		if(v3>=12) {
			noCHDAbove12++;
		}
		if(v4>=12) {
			noCHDAbove12++;
		}
		if(v5>=12) {
			noCHDAbove12++;
		}
		if(v6>=12) {
			noCHDAbove12++;
		}
		ratio = noADT/noCHDAbove12;
		if (ratio < 0.5){
			//alert('ratio: '+ratio+'\n'+'noCHDAbove12: '+noCHDAbove12+'\n'+'noADT: '+noADT);
			$('#book-error').html("Maximum of 2 children over age of 11 years old are permitted per adult paying passenger.");
			$('#book-error').fadeIn("slow");
			return false;
		}else{
			$('#book-error').fadeOut("slow");
		}
	}
}

function createChildsAge(minAge,maxAge) {
var v1 = document.airSearch["chAge1"];
var v2 = document.airSearch["chAge2"];
var v3 = document.airSearch["chAge3"];
var v4 = document.airSearch["chAge4"];
var v5 = document.airSearch["chAge5"];
var v6 = document.airSearch["chAge6"];
v1.options.length = 0;
v2.options.length = 0;
v3.options.length = 0;
v4.options.length = 0;
v5.options.length = 0;
v6.options.length = 0;
v1.options[v1.options.length] = new Option("","");
v2.options[v2.options.length] = new Option("","");
v3.options[v3.options.length] = new Option("","");
v4.options[v4.options.length] = new Option("","");
v5.options[v5.options.length] = new Option("","");
v6.options[v6.options.length] = new Option("","");
for(i=minAge;i<maxAge+1;i++) {
/*if(i==2){
v1.options[v1.options.length] = new Option("","");
v2.options[v2.options.length] = new Option("","");
v3.options[v3.options.length] = new Option("","");
v4.options[v4.options.length] = new Option("","");
v5.options[v5.options.length] = new Option("","");
v6.options[v6.options.length] = new Option("","");
}*/
v1.options[v1.options.length] = new Option(i,i);
v2.options[v2.options.length] = new Option(i,i);
v3.options[v3.options.length] = new Option(i,i);
v4.options[v4.options.length] = new Option(i,i);
v5.options[v5.options.length] = new Option(i,i);
v6.options[v6.options.length] = new Option(i,i);
}
}


function updatedate() {
  var day1 = document.airSearch.elements["depDay"].selectedIndex;
  var month1 = document.airSearch.elements["depMonth"].selectedIndex;
 
  var day2 = document.airSearch.elements["retDay"].selectedIndex;
  var month2 = document.airSearch.elements["retMonth"].selectedIndex;
 

  if ( month1 > month2 ) {
    document.airSearch.elements["retDay"].value = document.airSearch.elements["depDay"].value;
    document.airSearch.elements["retMonth"].value = document.airSearch.elements["depMonth"].value;
  } else if ( (day1 >=  day2) && (month1 == month2) ) {
    document.airSearch.elements["retDay"].value = document.airSearch.elements["depDay"].value;
    document.airSearch.elements["retMonth"].value = document.airSearch.elements["depMonth"].value;
  }
 if ( month1 < month2 ) {
    document.airSearch.elements["retDay"].value = document.airSearch.elements["depDay"].value;
    document.airSearch.elements["retMonth"].value = document.airSearch.elements["depMonth"].value;
  } else if ( (day1 <=  day2) && (month1 == month2) ) {
    document.airSearch.elements["retDay"].value = document.airSearch.elements["depDay"].value;
    document.airSearch.elements["retMonth"].value = document.airSearch.elements["depMonth"].value;
  }
  
  
}

function ShowBooking() {
document.getElementById('booking').style.display = "block";
document.getElementById('checkIn').style.display = "none";
$("#bookingState").removeClass("selected");
$("#checkinState").addClass("selected");
/*document.getElementById('bookingState').style.background = "none";
document.getElementById('bookingState').style.backgroundColor = "#FCC618";
document.getElementById('checkinState').style.backgroundColor = "#FDE15E";*/

}
function ShowCheckIn() {
document.getElementById('checkIn').style.display = "block";
document.getElementById('booking').style.display = "none";
/*document.getElementById('checkinState').style.background = "none";
document.getElementById('checkinState').style.backgroundColor = "#FCC618";
document.getElementById('bookingState').style.backgroundColor = "#FDE15E";
document.getElementById('bookingState').style.color = "#555555";*/
$("#bookingState").addClass("selected");
$("#checkinState").removeClass("selected");
buttonState(true);
}

function checkCheckIn(){
//resetForm();
var firstName = document.getElementById('cFirstName').value;
var lastName = document.getElementById('cLastName').value;
var deptFrom = document.getElementById('cDeptFrom').value;
var flightNo = document.getElementById('cFlightNo').value;
var bookingReff = document.getElementById('cBookingReff').value;
if(lastName == ''){
$('#error').html("Please enter Last Name");
$("#error").fadeIn("slow");
document.getElementById('cLastName').style.borderColor = "#FF0000";
return false;
}else{
document.getElementById('cLastName').style.borderColor = "";
}
if(firstName == ''){
$('#error').html("Please enter First Name");
$("#error").fadeIn("slow");
document.getElementById('cFirstName').style.borderColor = "#FF0000";
return false;
}else{
document.getElementById('cFirstName').style.borderColor = "";
}
if(deptFrom == ''){
$('#error').html("Please enter Departure From");
$("#error").fadeIn("slow");
document.getElementById('cDeptFrom').style.borderColor = "#FF0000";
return false;
}else{
document.getElementById('cDeptFrom').style.borderColor = "";
}

/*
if(bookingReff == ''){
document.getElementById('error').style.display = "block";
document.getElementById('errorMessage').innerHTML = 'Please enter a six-letter Booking Reference(PNR)';
document.getElementById('cBookingReff').style.borderColor = "#FF0000";
return false
}else{
document.getElementById('cFlightNo').style.borderColor = "";
}

if(flightNo == '' && bookingReff == ''){
document.getElementById('error').style.display = "block";
document.getElementById('errorMessage').innerHTML = 'Please enter a six-letter Booking Reference(PNR) OR Flight Number';
document.getElementById('cFlightNo').style.borderColor = "#FF0000";
document.getElementById('cBookingReff').style.borderColor = "#FF0000";
return false
}else{
document.getElementById('cFlightNo').style.borderColor = "";
document.getElementById('cBookingReff').style.borderColor = "";
}*/

if(flightNo == ''){
$('#error').html("Please enter Flight Number");
$("#error").fadeIn("slow");
document.getElementById('cFlightNo').style.borderColor = "#FF0000";
return false
}else{
document.getElementById('cFlightNo').style.borderColor = "";
}

if(firstName == '' || lastName == '' || deptFrom == '' && (flightNo == '' && bookingReff == '')){
return false;
}else{
document.getElementById('checkinForm').style.display = "none";
document.getElementById('loading').style.display = "block";
}
}


       /* function showCouponInputBox(form)  {
            var kk = 0;
            var mm = 0;
            var disindex = 0;
            var totalCouponInputBox = 0; // number of coupon number text box displayed
            var strListName = "";
            var strLabelName = "";
            var elemLabel;
            var minstrdivv;
            var totalPax = 0;
            if (document.airSearch.ADT != null && document.airSearch.ADT != undefined) {
                var numOfAdult=document.airSearch.ADT.options[document.airSearch.ADT.selectedIndex].value;
                totalPax += parseInt(numOfAdult);
            }
            if (document.airSearch.CHD != null && document.airSearch.CHD != undefined) {
                var numOfChild=document.airSearch.CHD.options[document.airSearch.CHD.selectedIndex].value;
                totalPax += parseInt(numOfChild);
            }
            if (document.airSearch.IFS != null && document.airSearch.IFS != undefined) {
                var numOfIfs=document.airSearch.IFS.options[document.airSearch.IFS.selectedIndex].value;
                totalPax += parseInt(numOfIfs);
            }
            if (document.airSearch.YTH != null && document.airSearch.YTH != undefined) {
                var numOfYouth=document.airSearch.YTH.options[document.airSearch.YTH.selectedIndex].value;
                totalPax += parseInt(numOfYouth);
            }
            if (document.airSearch.SCR != null && document.airSearch.SCR != undefined) {
                var numOfSenior=document.airSearch.SCR.options[document.airSearch.SCR.selectedIndex].value;
                totalPax += parseInt(numOfSenior);
            }
            if (document.airSearch.STU != null && document.airSearch.STU != undefined) {
                var numOfStudent=document.airSearch.STU.options[document.airSearch.STU.selectedIndex].value;
                totalPax += parseInt(numOfStudent);
            }
            if (document.airSearch.MIL != null && document.airSearch.MIL != undefined) {
                var numOfMilitary=document.airSearch.MIL.options[document.airSearch.MIL.selectedIndex].value;
                totalPax += parseInt(numOfMilitary);
            }
            if (document.airSearch.UMNR != null && document.airSearch.UMNR != undefined ) {
                var numOfMinors=document.airSearch.UMNR.options[document.airSearch.UMNR.selectedIndex].value;
                totalPax += parseInt(numOfMinors);
            }
            if (document.airSearch.STR != null && document.airSearch.STR != undefined ) {
                var numOfSTR=document.airSearch.STR.options[document.airSearch.STR.selectedIndex].value;
                totalPax += parseInt(numOfSTR);
            }
            if (document.airSearch.EMI != null && document.airSearch.EMI != undefined ) {
                var numOfEMI=document.airSearch.EMI.options[document.airSearch.EMI.selectedIndex].value;
                totalPax += parseInt(numOfEMI);
            }
            if (document.airSearch.DIS != null && document.airSearch.DIS != undefined ) {
                var numOfDIS=document.airSearch.DIS.options[document.airSearch.DIS.selectedIndex].value;
                totalPax += parseInt(numOfDIS);
            }
            //alert(totalPax);
            if(totalPax == 0)
            {
                totalCouponInputBox = 1;
            }
            else if(totalPax > 6)
            {
                totalCouponInputBox = 6;
            }
            else
            {
                totalCouponInputBox = totalPax;
            }

            minstrdivv = document.getElementById("lblCouponInstr");
            minstrdivv.style.display = "";

            //enable coupon Input box controls

            for (kk = 1; kk <= totalCouponInputBox; kk++) {
                strListName = "couponNumber" + kk;
                strLabelName = "lblCouponNumber" + kk;
                form.elements[strListName].disabled = false;
                form.elements[strListName].style.display = "";
                elemLabel = document.getElementById(strLabelName);
                elemLabel.style.display = "";
            }
            if(totalCouponInputBox > 1)
            {
             form.elements["applyToAll"].style.display = "";
             elemLabelApplyToAll = document.getElementById("lblApplyCouponToAll");
             elemLabelApplyToAll.style.display = "";
            }
            else
            {
                form.elements["applyToAll"].style.display = "none";
            }
            //disable Input box controls
            disindex = parseInt(totalCouponInputBox) + 1;
            for (mm = disindex; mm <= maxPassenger; mm++) {
              strListName = "couponNumber" + mm;
              strLabelName = "lblCouponNumber" + mm;
              form.elements[strListName].disabled = true;
              form.elements[strListName].style.display = "none";
              elemLabel = document.getElementById(strLabelName);
              elemLabel.style.display = "none";
            }
            if(totalCouponInputBox == 1)
            {
             elemLabelApplyToAll = document.getElementById("lblApplyCouponToAll");
             elemLabelApplyToAll.style.display = "none";
            }
        }*/
		

function childrenDropdownValueChanged() {
	//alert();
	if (j("Children").selectedIndex === 0) {
		j("childDOBTxt").style.display = "none";
		j("spacerChildDescription").style.display = "none";
		j("spacerInfants").style.display = "none";
		j("infants").style.styleFloat="left";

	} else {
		j("childDOBTxt").style.display = "block";
		//$("infants").style.clear = "left";
		j("spacerInfants").style.display = "block";
		j("spacerChildDescription").style.display = "block";
	}
		for (i = 1; i <= 6; i++) {
			if (i <= j("Children").selectedIndex) {
				j("childDOB"+i).style.display = "block";
				j("spacerChildDateBirth"+i).style.display = "block";
			} else {
				j("childDOB"+i).style.display = "none";
				j("spacerChildDateBirth"+i).style.display = "none";
			}
		}
				j("childDOB").style.display = "block";
}//end function

				
function j(obj) {
try {
return document.getElementById(obj);
} catch (e) {}			
}//end function



function resetForm() {
document.getElementById('errorMessage').innerHTML = '';
document.getElementById('cFirstName').style.borderColor = "";
document.getElementById('cLastName').style.borderColor = "";
document.getElementById('cDeptFrom').style.borderColor = "";
document.getElementById('cFlightNo').style.borderColor = "";
document.getElementById('cBookingReff').style.borderColor = "";
document.getElementById('checkinForm').style.display = "block";
document.getElementById('loading').style.display = "none";
}



function buttonState(state){
document.getElementById('agree').checked = false;
document.getElementById('checkinBtn').disabled = true;
} 
function checkform () {
if (!document.getElementById('agree').checked) {
document.getElementById('checkinBtn').disabled = true;
}
if (document.getElementById('agree').checked) {
document.getElementById('checkinBtn').disabled = false;
}
}

function setUserTime () {
var usertime = new Date();
//usertime.setMinutes(usertime.getMinutes() + 10);
usertime.setHours(usertime.getHours() + 1);
var curHour = usertime.getHours()
var curMin = "0";
//var curMin = usertime.getMinutes();
var curTime = ((curHour < 10) ? "0" : "") + curHour + ((curMin < 10) ? "0" : "") + curMin
document.airSearch.elements["depTime"].value = curTime;
document.airSearch.elements["retTime"].value = curTime;

}
// -->