//Script to generate select box option calendar
var oldBrowser = 0;
if (navigator.appVersion.charAt(0) == "2") {
   if (navigator.appName != "Microsoft Internet Explorer") {
      oldBrowser=1;
   }
}


//Check for Numeric Dates - added 26/06/2006
var reNumeric = /^[0-9]+$/
function isNumeric(s)
{ 
	return reNumeric.test(s);
}


// Months array for HKZH - added 14/02/2006
var month_hkzh = new Array(12);
month_hkzh[0] = "1";
month_hkzh[1] = "2";
month_hkzh[2] = "3";
month_hkzh[3] = "4";
month_hkzh[4] = "5";
month_hkzh[5] = "6";
month_hkzh[6] = "7";
month_hkzh[7] = "8";
month_hkzh[8] = "9";
month_hkzh[9] = "10";
month_hkzh[10] = "11";
month_hkzh[11] = "12";


var month = new Array(12);
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";

var curDate = new Date();
var curDay =  curDate.getDate() + 21;
var curMonth = curDate.getMonth();
var flexiCurMonth = curMonth;
var curYear = curDate.getYear();

function findDaysInMonth(theMonth) {
    var thisYear;
    if (arguments.length>1) {
	thisYear = arguments[1];
	} else {
	var thisDate = new Date();
	thisYear = thisDate.getYear();
	}
    //the month index starts from zero and need to be incremented with 1
	timeA = new Date(thisYear, theMonth+1, 1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	return noOfDaysInMonth = timeB.getDate();
}

while (curDay>findDaysInMonth(curMonth,curYear)) {
    curDay-=findDaysInMonth(curMonth,curYear);
    curMonth+=1;
    if (curMonth>11) {
        curMonth=0;
        curYear++;
    }
}
var nextDate = curDate;
nextDate.setDate(curDate);
var nextDay = curDay + 4;
var nextMonth = curMonth;
var nextYear = curYear;
if (nextDay>findDaysInMonth(nextMonth,nextYear)) {
    nextDay-=findDaysInMonth(nextMonth,nextYear);
    nextMonth+=1;
    if (nextMonth>11) {
        nextMonth=0;
        nextYear++;
    }
}

function findYearForCalendar(firstMonth) {
    var calDate = new Date();
	var calYear = calDate.getYear();
	var calMonth = calDate.getMonth();
 if (arguments.length>1) {
   var secondMonth = arguments[1];
   var firstMonthDate = arguments[2];
   var secondMonthDate = arguments[3];
   if (eval(secondMonth)<eval(firstMonth) || 
       (eval(secondMonth)==eval(calMonth+1) && eval(secondMonthDate)<eval(firstMonthDate)) ||
       (eval(secondMonth)>=eval(firstMonth) && eval(calMonth+1)>eval(firstMonth))) {	
	  calYear++;	
	}
  } else {
    if (eval(calMonth+1)>eval(firstMonth)) {	
	  calYear++;	
	}
  }
  return calYear;
}

function refreshDates(refreshYear,refreshMonth,objectFormFieldDay,selectIndexOrder) {
	//the month index starts from zero and need NOT to be incremented with 1
	//as the value have been received correctly
    generateDates(refreshYear,refreshMonth,objectFormFieldDay,selectIndexOrder);
}

function populateDates(givenMonth,objectFormFieldDay,selectIndexOrder) {
    var theDate = new Date();
	var givenYear = theDate.getYear();
    if (arguments.length>3 && eval(givenMonth)<eval(arguments[3])) {	
	  givenYear++;	
	} 	
	//the month index starts from zero and need NOT to be incremented with 1
	//as the value have been received correctly
    generateDates(givenYear,givenMonth,objectFormFieldDay,selectIndexOrder);
}

function generateDates(genYear,genMonth,objFormFieldDay,selectIndex) {
   	timeFirstDayOfMonth = new Date(genYear, genMonth, 1);
	timeDifference = timeFirstDayOfMonth - 86400000;
	timeLastDayOfMonth = new Date(timeDifference);
	daysInMonth = timeLastDayOfMonth.getDate();
	
	for(var i=0;i < objFormFieldDay.length;i++) {
		objFormFieldDay.options[i] = null;
	}

	for (i = 0; i < daysInMonth; i++) {	
		objFormFieldDay.options[i]= new Option(i+1);
		objFormFieldDay.options[i].value= objFormFieldDay.options[i].text;
	}
	if (selectIndex>=daysInMonth) {
		objFormFieldDay.options[0].selected = true;
	} else {
		objFormFieldDay.options[selectIndex].selected = true;
	}
}

function writeOption(myNum, myValue, mySelected) {
   if (oldBrowser == 0) {
      if (mySelected == 1) {
         document.write ("<option value='" + myNum + "' selected>" + myValue );
      } else {
         document.write ("<option value='" + myNum + "'>" + myValue );
      }
   }
}

function writeOptionString(myValue, mySelected) {
   if (oldBrowser == 0) {
      if (mySelected == 1) {
         document.write ("<option value='" + myValue + "' selected>" + myValue );
      } else {
         document.write ("<option value='" + myValue + "'>" + myValue );
      }
   }
}

//Show Month Function for HKZH - added 13/02/2006
function showHKZHMonth(toSelect) {
   for (var i=0; i < 12; i++ ) {
      if (i == toSelect) {
         writeOption(i+1, month_hkzh[i], 1);
      } else {
         writeOption(i+1, month_hkzh[i], 0);
      }
   }
}

function showMonth(toSelect) {
   for (var i=0; i < 12; i++ ) {
      if (i == toSelect) {
         writeOption(i+1, month[i], 1);
      } else {
         writeOption(i+1, month[i], 0);
      }
   }
}

function showMonthString(toSelect) {
   for (var i=0; i < 12; i++ ) {
      if (i == toSelect) {
         writeOptionString(month[i], 1);
      } else {
         writeOptionString(month[i], 0);
      }
   }
}

function showDay(toSelect, myMonth, myYear) {
   for (i=1; i <= findDaysInMonth(myMonth,myYear); i++) {
      if (i == toSelect) {
         writeOption(i, i, 1);
      } else {
         writeOption(i, i, 0);
      }
   }
}

function showTime() {
	var time_choices = ["12:00am", "1:00am", "2:00am", "3:00am", "4:00am", "5:00am", "6:00am", "7:00am", "8:00am", "9:00am", "10:00am", "11:00am", "12:00pm", "1:00pm", "2:00pm", "3:00pm", "4:00pm", "5:00pm", "6:00pm", "7:00pm", "8:00pm", "9:00pm", "10:00pm", "11:00pm", "Morning", "Afternoon", "Evening", "Anytime"];
	for (j=0; j<time_choices.length; j++) {
		if (time_choices[j] == "Anytime") {
			writeOption(time_choices[j], time_choices[j], 1);
		} else {
			writeOption(time_choices[j], time_choices[j], 0);
		}
	}
}

function showCountries() {
	var country_choices = ["", "All Other Countries", "AG", "Antigua & Barbuda", "AW", "Aruba", "AU", "Australia", "AT", "Austria", "BS", "Bahamas", "BB", "Barbados", "BE", "Belgium", "BM", "Bermuda", "ANB", "Bonaire", "BR", "Brazil", "CA", "Canada", "KY", "Cayman Islands", "CN", "China", "ANC", "Curacao", "CZ", "Czech Republic", "DK", "Denmark", "DO", "Dominican Republic", "GBE", "England", "FI", "Finland", "FR", "France", "DE", "Germany", "GR", "Greece", "VC", "Grenadines", "HK", "Hong Kong", "HU", "Hungary", "IE", "Ireland", "IT", "Italy", "JM", "Jamaica", "MX", "Mexico", "NL", "Netherlands", "KNN", "Nevis", "NZ", "New Zealand", "NO", "Norway", "PL", "Poland", "PT", "Portugal", "PR", "Puerto Rico", "ANS", "Saba", "GBS", "Scotland", "SG", "Singapore", "ES", "Spain & Canary Isl.", "GP", "St. Barths", "ANE", "St. Eustatius", "KN", "St. Kitts", "LC", "St. Lucia", "AN", "St. Martin/Maarten", "SE", "Sweden", "CH", "Switzerland", "TW", "Taiwan", "TH", "Thailand", "TT", "Trinidad & Tobago", "TC", "Turks & Caicos Isl.", "GB", "United Kingdom", "US", "United States", "VG", "Virgin Isl. British", "VI", "Virgin Isl. US", "", "All Other Countries"];
	for (j=0; j<country_choices.length; j+=2) {
		if (country_choices[j] == "SG") {
			writeOption(country_choices[j], country_choices[j+1], 1);
		} else {
			writeOption(country_choices[j], country_choices[j+1], 0);
		}
	}
}

function changeReturnMonth(selectfieldprefix1, selectfieldprefix2) {
	document.book["select_" + selectfieldprefix2 + "_month"].selectedIndex = document.book["select_" + selectfieldprefix1 + "_month"].selectedIndex;
	changeReturnDay(selectfieldprefix1, selectfieldprefix2);
} // changeReturnMonth	Flights and Cars

function changeReturnDay(selectfieldprefix1, selectfieldprefix2) {	
	// plus 1 for auto return date, i.e one day out
	var out_date = document.book["select_" + selectfieldprefix1 + "_day"].selectedIndex + 4;
	var out_month = document.book["select_" + selectfieldprefix1 + "_month"].selectedIndex;
	
	var tempDate = new Date();
	var yearAssumed = tempDate.getYear();
	
	while (out_date>=findDaysInMonth(out_month,yearAssumed)) {
    	out_date-=findDaysInMonth(out_month,yearAssumed);
    	out_month+=1;
    	if (out_month>=12) {
        	out_month=0;
    	}
	}
	
	document.book["select_" + selectfieldprefix2 + "_month"].selectedIndex = out_month;	
	//document.book["select_" + selectfieldprefix2 + "_day"].selectedIndex = out_date;
	populateDates(eval(out_month+1),document.book["select_" + selectfieldprefix2 + "_day"],out_date,document.book["select_" + selectfieldprefix1 + "_month"].options[document.book["select_" + selectfieldprefix1 + "_month"].selectedIndex].value);	
	
} // changeReturnDay Flights and Cars

function changeCheckOutMonth() {
	document.book.dateReturningMonth.selectedIndex = document.book.dateLeavingMonth.selectedIndex;
	changeCheckOutDay();
} // changeCheckOutMonth	for Hotel

function changeCheckOutDay() {	
	// plus 1 for auto return date, i.e one day out
	var depart_date = document.book.dateLeavingDay.selectedIndex +2;
	var leave_month = document.book.dateLeavingMonth.selectedIndex;
	
	var tempDate = new Date();
	var yearAssumed = tempDate.getYear();
	
	while (depart_date>=findDaysInMonth(leave_month,yearAssumed)) {
    	depart_date-=findDaysInMonth(leave_month,yearAssumed);
    	leave_month+=1;
    	if (leave_month>=12) {
        	leave_month=0;
    	}
	}
	
	document.book.dateReturningMonth.selectedIndex = leave_month;
	//document.book.dateReturningDay.selectedIndex = depart_date;
	populateDates(eval(leave_month+1),document.book.dateReturningDay,depart_date,document.book.dateLeavingMonth.options[document.book.dateLeavingMonth.selectedIndex].value);
	
	calNumberOfNights();
	
} // changeCheckOutDay Hotel
		
function calNumberOfNights() {
	var curDate = new Date();
	var curDay =  curDate.getDate() + 7;
	var curMonth = curDate.getMonth();
	var curYear = curDate.getYear();
	var date1=new Date();//check in
        var date2=new Date();//check out
	
	varmsg001030='The maximum number of nights cannot exceed 30.';
	varmsg001033='Atleast one night is required.';

	day1 = document.book.dateLeavingDay.selectedIndex;
        month1 = document.book.dateLeavingMonth.selectedIndex;
        year1 = curYear;
        
    if(month1 < curMonth){
        year1 = eval(year1) + 1;
    }
    //document.book.year1.value = year1;
	
    day2= document.book.dateReturningDay.selectedIndex;
    month2 = document.book.dateReturningMonth.selectedIndex;
    year2 = curYear;

    if(month2 < curMonth ){
        year2 = eval(year2) + 1;
    }
    //document.book.year2.value = year2;
    
    date1.setDate(day1+1);
    date1.setMonth(month1);
    date1.setFullYear(year1);
    
    date2.setDate(day2+1);
    date2.setMonth(month2);
    date2.setFullYear(year2);
    
    var milli = date2 - date1;
    var seconds = milli/1000;
    var mins = seconds/60;
    var hrs = mins/60;

    var days = hrs/24;

    if(days <=0 ) {
        //alert(varmsg001033);
        //return false;
    }

    //var nights = days;
    //selNight.value=nights;
	document.book.night_cnt.value = days;
	//document.book.airport.value = date1;

    if(days > 30){
        //alert(varmsg001030);
        //return false;
    }
	
    return true;

}

//DHTML wait search page
function calWaitPage() {
	showWaitMessage('waitDivHotel','dispDiv', 1, 0);
    return true;
}

DHTML = (document.getElementById || document.all || document.layers);
function getObj(name) {
	if (document.getElementById) { 
		return document.getElementById(name).style; 
	} else if (document.all) { 
		return document.all[name].style;
	} else if (document.layers) { 
		return document.layers[name]; 
	}
}

function showWaitMessage(div,div2,flag,flag2) { 
	if (!DHTML)
	return; 
	var x = getObj(div); 
	var y = getObj(div2); 
	var xpageX = x;
	var xpageY = x;
	x.visibility = (flag) ? 'visible':'hidden'	
	x.display = (flag) ? 'inline':'none'
	y.visibility = (flag2) ? 'visible':'hidden'
	y.display = (flag2) ? 'inline':'none'
	window.scrollTo(0,0);
	if(document.layers) {
		xpageX.document.width = window.innerWidth-16;
		xpageY.document.height = window.innerHeight;
	} else {
		xpageX.width = document.body.offsetWidth-20;
		xpageY.height = document.body.offsetHeight;
	}
}


//Image swapping scripts 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//search section dhtml design scripts
tab_Flight_Date = "Exact";
tab_Hotel_Country = "Country";
tab_CarsRail = "Cars";
breakstate = true; //added 12/07/2006 - to tell if someone clicks on the tabs before the page loads.

function initPage() {
    if (breakstate) {	
        if (document.location.href.indexOf("index.html") != -1) {
		//document.book.mode[0].checked = true;
		document.book.module[0].checked = true;
		document.book.trip_option[0].checked = true;

                //added 12/07/2006 - if breakstate = true; switch radio buttons back to default selections. 
                changeMode("Flights");
                changeFlightDate("Exact");
                field_disable(false, 'select_flightreturn_time', 'select_flightreturn_day', 'select_flightreturn_month');

	}
	if (document.location.href.indexOf("flights.html") != -1) {
		document.book.module[0].checked = true;
		document.book.trip_option[0].checked = true;
	}
	//if (document.location.href.indexOf("carsrail.html") != -1) {
		//document.book.mode[0].checked = true;
		//document.book.trip_option[1].checked = true;
		//field_disable(true, 'select_railreturn_time', 'select_railreturn_day', 'select_railreturn_month');
	//}
    }
}

function moreSearchOptions() {
	if (document.book.mode[0].checked) {
		document.location.href = "flights.html";
	}
	if (document.book.mode[1].checked) {
	    if (arguments.length>0 && arguments[0] == "ZUJINZ") {
       	  document.location.href = "http://zuji.co.nz/hotel_guru.asp";
	   } else {
	   	  document.location.href = "hotels.html";
	   }		
	}
	if (document.book.mode[2].checked) {
		document.location.href = "packages.html";
	}
}

function changeMode(strMode) {
	var arrModes = new Array("Flights", "Hotels", "Cars");
        
        //added 12/07/2006 - breakstate turns false if someone clicks on the tabs after the page is loaded.
        breakstate=false; 

	for (var i = 0; i < arrModes.length; i++) {
		if (arrModes[i] == strMode) {
			document.getElementById('span'+arrModes[i]).className = "selected";
			document.getElementById('header'+arrModes[i]).className = "modeheader_selected";
		}
		else {
			document.getElementById('span'+arrModes[i]).className = "deselected";
			document.getElementById('header'+arrModes[i]).className = "modeheader_deselected";
		}
	}

	// 6/6/06 Added tab_cars_searchbtn to hide searchbutton for Simple Cars Tab
	switch (strMode) {
		case "Flights": 
			MM_showHideLayers('flight','','show','tab_flight_exact','','show','tab_flight_flexible','','hide','hotel','','hide','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','car','','hide','tab_cars_searchbtn','','show');
			changeFlightDate(tab_Flight_Date);
			break;
		case "Hotels": 
			MM_showHideLayers('flight','','hide','tab_flight_exact','','hide','tab_flight_flexible','','hide','hotel','','show','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','car','','hide','tab_cars_searchbtn','','show'); 
			changeHotelDestDetails(tab_Hotel_Country);
			break;
		case "Cars": 
			MM_showHideLayers('flight','','hide','tab_flight_exact','','hide','tab_flight_flexible','','hide','hotel','','hide','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','car','','show','tab_cars_searchbtn','','hide'); 
			break;
	}
}

// Revised cannonball tab scripts with Packages tab - added:18/01/07 
function changeMode_wPKG(strMode) {
	var arrModes = new Array("Flights", "Hotels", "Packages", "Cars");
        
        //added 12/07/2006 - breakstate turns false if someone clicks on the tabs after the page is loaded.
        breakstate=false; 

	for (var i = 0; i < arrModes.length; i++) {
		if (arrModes[i] == strMode) {
			document.getElementById('span'+arrModes[i]).className = "selected";
			document.getElementById('header'+arrModes[i]).className = "modeheader_selected";
		}
		else {
			document.getElementById('span'+arrModes[i]).className = "deselected";
			document.getElementById('header'+arrModes[i]).className = "modeheader_deselected";
		}
	}

	// 6/6/06 Added tab_cars_searchbtn to hide searchbutton for Simple Cars Tab
	switch (strMode) {
		case "Flights": 
			MM_showHideLayers('flight','','show','tab_flight_exact','','show','tab_flight_flexible','','hide','hotel','','hide','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','package','','hide','car','','hide','tab_cars_searchbtn','','show');
			changeFlightDate(tab_Flight_Date);
			break;
		case "Hotels": 
			MM_showHideLayers('flight','','hide','tab_flight_exact','','hide','tab_flight_flexible','','hide','hotel','','show','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','package','','hide','car','','hide','tab_cars_searchbtn','','show'); 
			changeHotelDestDetails(tab_Hotel_Country);
			break;
		case "Packages":
			MM_showHideLayers('flight','','hide','tab_flight_exact','','hide','tab_flight_flexible','','hide','hotel','','hide','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','package','','show','car','','hide','tab_cars_searchbtn','','show'); 
			break;
		case "Cars": 
			MM_showHideLayers('flight','','hide','tab_flight_exact','','hide','tab_flight_flexible','','hide','hotel','','hide','tab_hotel_countries','','hide','tab_hotel_us','','hide','tab_hotel_ca','','hide','package','','hide','car','','show','tab_cars_searchbtn','','hide'); 
			break;
	}
}


function changeFlightDate(strFlightDate) {

        //added 12/07/2006 - breakstate turns false if someone clicks on the tabs after the page is loaded.
        breakstate=false; 

	if (strFlightDate == 'Flexible') {
		document.getElementById('td_Flight_Exact').bgColor='#B3E1F0';
		document.getElementById('td_Flight_Flexible').bgColor='#DFF2F9';
		document.getElementById('flight_tabcorner').src = "http://www.zuji.com/Image_Library/Website_images/tabcorner_left.gif";
		MM_showHideLayers('tab_flight_exact','','hide','tab_flight_flexible','','show');
	} else {
		document.getElementById('td_Flight_Exact').bgColor='#DFF2F9';
		document.getElementById('td_Flight_Flexible').bgColor='#B3E1F0';
		document.getElementById('flight_tabcorner').src = "http://www.zuji.com/Image_Library/Website_images/tabcorner_right.gif";
		MM_showHideLayers('tab_flight_exact','','show','tab_flight_flexible','','hide');
	}
	tab_Flight_Date = strFlightDate;
}

function changeHotelDestDetails(strCountry) {
	if (strCountry == "US") {
		MM_showHideLayers('tab_hotel_countries','','hide', 'tab_hotel_us','','show', 'tab_hotel_ca','','hide'); 
	} else if (strCountry == "CA") {
		MM_showHideLayers('tab_hotel_countries','','hide', 'tab_hotel_us','','hide', 'tab_hotel_ca','','show'); 
	} else {
		MM_showHideLayers('tab_hotel_countries','','show', 'tab_hotel_us','','hide', 'tab_hotel_ca','','hide'); 
	}
	tab_Hotel_Country = strCountry;
}

function changeCarsRail(strCarsRail) {
	if (strCarsRail == 'Rail') {
		document.getElementById('td_CarsRail_Cars').bgColor='#B3E1F0';
		document.getElementById('td_CarsRail_Rail').bgColor='#DFF2F9';
		document.getElementById('carsrail_tabcorner').src = "http://www.zuji.com/Image_Library/Website_images/tabcorner_left.gif";
		MM_showHideLayers('tab_carsrail_cars','','hide','tab_carsrail_rail','','show'); 
	} else {
		document.getElementById('td_CarsRail_Cars').bgColor='#DFF2F9';
		document.getElementById('td_CarsRail_Rail').bgColor='#B3E1F0';
		document.getElementById('carsrail_tabcorner').src = "http://www.zuji.com/Image_Library/Website_images/tabcorner_right.gif";
		MM_showHideLayers('tab_carsrail_cars','','show','tab_carsrail_rail','','hide'); 
	}
	tab_CarsRail = strCarsRail;
}

function field_disable() {
	var args=field_disable.arguments;
	for (temp=1; temp<args.length; temp++) {
		document.book[args[temp]].disabled = args[0];
	}
    if (arguments.length>0 && arguments[0] == "true" & arguments[1] == "select_flightreturn_time" && arguments[2] == "select_flightreturn_day" & arguments[3] == "select_flightreturn_month") {
       document.write('<input type="hidden"  name="returnMonth" value="">');
	}	
}

//Pop up window for infant page
function launchWindow( url, HT, WD ) {
	var windowOptions
	var myLocation = url
	var WN = "newWindow"
	var AR = "yes"
	var TB = "no"
	var LC = "no"
	var SB = "no"
	var DR = "no"
	var ST = "no"
	var MB = "no"
	var RS = "yes"
	var CH = "yes"
	var PX = ""
	var PY = ""
	switch( arguments.length ) {
		case 16:
		case 15: PY = arguments[14];
		case 14: PX = arguments[13];
		case 13: CH = arguments[12];
		case 12: RS = arguments[11];
		case 11: MB = arguments[10];
		case 10: ST = arguments[9];
		case  9: DR = arguments[8];
		case  8: SB = arguments[7];
		case  7: LC = arguments[6];
		case  6: TB = arguments[5];
		case  5: AR = arguments[4];
		case  4: WN = arguments[3];
	}

	windowOptions  = "height="
	windowOptions += HT
	windowOptions += ",width="
	windowOptions += WD
	windowOptions += ",alwaysRaised="
	windowOptions += AR
	windowOptions += ",toolbar="
	windowOptions += TB 
	windowOptions += ",location="
	windowOptions += LC 
	windowOptions += ",scrollbars="
	windowOptions += SB 
	windowOptions += ",directories="
	windowOptions += DR 
	windowOptions += ",status="
	windowOptions += ST
	windowOptions += ",menubar="
	windowOptions += MB 
	windowOptions += ",resizable="
	windowOptions += RS 
	windowOptions += ",copyhistory="
	windowOptions += CH
	windowOptions += ",screenX="
	windowOptions += PX
	windowOptions += ",screenY="
	windowOptions += PY
	windowOptions += ",left="
	windowOptions += PX
	windowOptions += ",top="
	windowOptions += PY

	var w=window.open(myLocation, "Infants_popup", windowOptions);
	w.focus();
}

//Citylist Pop-up scripts
function PopUpSearch(OutputVar) {
 jumpof = window.open("/web/content/common/en_citylist/citylist.html", OutputVar, "location=no,menubar=no,resizable=no,width=300,height=150,scrollbars=no,left=530,top=0")
};

function PopUpSearchHKZH(OutputVar) {
 jumpof = window.open("/web/content/common/hkzh_citylist/citylist.html", OutputVar, "location=no,menubar=no,resizable=no,width=445,height=150,scrollbars=no,left=530,top=0")
};

function ActivateMiddle() {
 var ie=(document.all)?1:0;

 if (ie) parent.frames.midle.location = "citylist-drop.html?"+document.forms[0].dropdown.value;
 else {
  IndexSelect = document.forms["MyForm"].dropdown.selectedIndex;
  NameSelect  = document.forms["MyForm"].dropdown[IndexSelect].value;
  parent.midle.location = "citylist-drop.html?" + NameSelect;
 }
};

function ActivateBottom() {
 var ie=(document.all)?1:0;

 if (ie) parent.frames.botle.location=
  "citylist-drop.html?"+document.forms[0].dropdown.value
 else {
  IndexSelect = document.forms["MyForm"].dropdown.selectedIndex;
  NameSelect  = document.forms["MyForm"].dropdown[IndexSelect].value;
  parent.botle.location = "citylist-drop.html?" + NameSelect;
 }
};

function ClearBottom() {
 var ie=(document.all)?1:0;
 if (ie) parent.frames.botle.location = "citylist-drop.html?init"
 else {
  parent.botle.location = "citylist-drop.html?init";
 }
};

function PushBack() {
 var ie=(document.all)?1:0;
 if (ie) dummyvar=document.forms[0].dropdown.value
 else {
  IndexSelect = document.forms["MyForm"].dropdown.selectedIndex;
  NameSelect  = document.forms["MyForm"].dropdown[IndexSelect].value; 
 }
 if (ie) parent.frames.footle.location = "footer.html?"  + document.forms[0].dropdown.value
 else {
  parent.footle.location = "footer.html?" + escape(NameSelect);
 }
};


function ltrim(argvalue) {
  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }
  return argvalue;
};

function rtrim(argvalue) {
  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }
  return argvalue;
};

function trim(argvalue) {
  argvalue = argvalue.substring(1, argvalue.length);
  argvalue = argvalue.substring(0, argvalue.length - 1);
  return argvalue;

};


function PushBack2(inp) {
 var ie=(document.all)?1:0;
 if (ie) parent.opener.document.forms[2].elements[parent.name].value=unescape(inp)
 else {
  parent.opener.document.forms[2].elements[parent.name].value=unescape(inp);
 }
};

//Advanced Search scripts
function setRadioBtn (theForm,radioObjName,valOfBtnToSet) {
 for (var i = 0; i < theForm[radioObjName].length; i++) {
  if (theForm[radioObjName][i].value == valOfBtnToSet)
   theForm[radioObjName][i].checked=true;
 }
}

function submitAir( myForm ) {
	if( (myForm.inp_dep_arp_cd_1.value.length < 3) || (myForm.inp_dep_arp_cd_1.value.length > 25) ) {
               if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/flights.html")) {
                   var tempV = document.createElement('div');
                   tempV.innerHTML = "&#20986;&#30332;&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                   alert(tempV.innerHTML);
               } else {
                   alert("Enter a departure city of 3 to 25 characters.");
               }
		myForm.inp_dep_arp_cd_1.focus()
		return false;
	} else {
		if( (myForm.inp_arr_arp_cd_1.value.length < 3) || (myForm.inp_arr_arp_cd_1.value.length > 25) ) {
                        if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/flights.html")) {
                            var tempV = document.createElement('div');
                            tempV.innerHTML = "&#25269;&#36948;&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                            alert(tempV.innerHTML);
                        } else {
                            alert("Enter an arrival city of 3 to 25 characters.");
                        }			
			myForm.inp_arr_arp_cd_1.focus()
			return false;
		} else {
        	if(myForm.self_trav.value == "")  {
				alert("Please select if you are one of the travellers on this booking");
				return false;
			} else {
            	if((myForm.inp_pax_cnt.selectedIndex + 1) + myForm.chld_pax_cnt.selectedIndex > 6) {
                	alert("Reservations must not include more than six travellers");
                	return false;
				} else {
					//work around for return journey date, when the trip option is Oneway
					if( myForm.trip_option[0].checked == true ) {
						myForm.returnMonth.value = myForm.returnMonth1.value;
						myForm.inp_ret_dep_dt_dy.value = myForm.inp_ret_dep_dt_dy1.value;
						myForm.inp_ret_dep_tm.value = myForm.inp_ret_dep_tm1.value;
					} else {
						myForm.returnMonth.value = "";
						myForm.inp_ret_dep_dt_dy.value = "";
						myForm.inp_ret_dep_tm.value = "";
					}
                                        
                                        //hide the div elements of dates and deals
					document.getElementById("tab_flight_flexible").style.visibility = "hidden";
    				        document.getElementById("tab_flight_flexible").style.display = "none";
    				        document.getElementById("tab_flight_exact").style.visibility = "hidden";
    				        document.getElementById("tab_flight_exact").style.display = "none";	
					document.getElementById("deals").style.visibility = "hidden";
    				        document.getElementById("deals").style.display = "none";

					//check if layer name provided in the argument
	   				if (arguments.length>1) {
       					showWaitMessage(arguments[1],'dispDiv', 1, 0);
	   				} else {
	   					showWaitMessage('waitDiv','dispDiv', 1, 0);
	   				}
					return true;
				}
			}
		}
	}
} // submitAir

function submitNZHotel( myForm ) {
	if ((myForm.city1.value == "") || (myForm.city1.value.length < 3) || (myForm.city1.value.length > 25))  {
	  alert("Enter the city of 3 to 15 characters of the Country.");
	   myForm.city1.focus();
	   return false;
	}
	myForm.airport.value = myForm.city1.value;
	//attach only if affiliate cookie exists
	if(getcookie('affiliateId')){
	   myForm.affiliateId.value =getcookie('affiliateId');
           //alert("affiliateId : "+myForm.affiliateId.value);
        }
	return true;
} //submitNZHotel

function submitHotel( myForm ) {
    if ((myForm.cityCountryCode.value =="US") && ((myForm.city2.value == "") || (myForm.city2.value.length < 3) || (myForm.city2.value.length > 25))) {
	       if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/hotels.html")) { 
                   var tempV = document.createElement('div');
                   tempV.innerHTML = "&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                   alert(tempV.innerHTML);
               } else {
                   alert("Enter the city of 3 to 15 characters of United States.");
               }
               myForm.city2.focus();
	       return false;
	} else if ((myForm.cityCountryCode.value =="CA") && ((myForm.city3.value == "") || (myForm.city3.value.length < 3) || (myForm.city3.value.length > 25))) {
	       if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/hotels.html")) { 
                   var tempV = document.createElement('div');
                   tempV.innerHTML = "&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                   alert(tempV.innerHTML);
               } else {
                   alert("Enter the city of 3 to 15 characters of Canada.");
               }
	       myForm.city3.focus();
	       return false;
	} else if (((myForm.city1.value == "") || (myForm.city1.value.length < 3) || (myForm.city1.value.length > 25)) && ((myForm.cityCountryCode.value !="US") && (myForm.cityCountryCode.value !="CA"))) {
	       if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/hotels.html")) { 
                   var tempV = document.createElement('div');
                   tempV.innerHTML = "&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                   alert(tempV.innerHTML);                
               } else {
                   alert("Enter the city of 3 to 15 characters of the Country.");
	       }
               myForm.city1.focus();
	       return false;
	} else {
	   if ((myForm.cityCountryCode.value =="US") && (myForm.city2.value != "")) {
	     myForm.city.value = myForm.city2.value
	   } else if ((myForm.cityCountryCode.value =="CA") && (myForm.city3.value != "")) {
	     myForm.city.value = myForm.city3.value
	   } else if (myForm.city1.value != "" && ((myForm.cityCountryCode.value !="US") && (myForm.cityCountryCode.value !="CA"))) {
	     myForm.city.value = myForm.city1.value
	   }
	   //check if layer name provided in the argument
	   if (arguments.length>1) {
       	//showWaitMessage(arguments[1],'dispDiv', 1, 0);
	   } else {
	   	//showWaitMessage('waitDiv','dispDiv', 1, 0);
	   }
	   //attach only if affiliate cookie exists
	   if(getcookie('affiliateId')){
	       myForm.affiliateId.value =getcookie('affiliateId');
           //alert("affiliateId : "+myForm.affiliateId.value);
       }
       //return true; wait for date check
	}


       // check dates simple filled in - 26/06/06
	if	(myForm.leavingDate.value != "") {
		lD_dateArr = myForm.leavingDate.value.split("/");
		lD_dd=lD_dateArr[0];
		lD_mm=lD_dateArr[1];
		lD_yyyy=lD_dateArr[2];

		if (!isNumeric(lD_dd) || lD_dd>31 || !isNumeric(lD_mm) || lD_mm>12 || !isNumeric(lD_yyyy)) {
			alert ("Please enter a valid Check-in Date or choose one from the Calendar.");
			myForm.leavingDate.focus();
			return false;
		}
	} else {
		alert ("Please enter a valid Check-in Date or choose one from the Calendar.");
		myForm.leavingDate.focus();	
		return false;
	}
	
	if (myForm.returningDate.value != "") {
		rD_dateArr = myForm.returningDate.value.split("/");
		rD_dd=rD_dateArr[0];
		rD_mm=rD_dateArr[1];
		rD_yyyy=rD_dateArr[2];
		
		if (!isNumeric(rD_dd) || rD_dd>31 || !isNumeric(rD_mm) || rD_mm>12 || !isNumeric(rD_yyyy)) {
			alert ("Please enter a valid Check-out Date or choose one from the Calendar.");
			myForm.returningDate.focus();
			return false;
		}	
	} else {
		alert ("Please enter a valid Check-out Date or choose one from the Calendar.");
		myForm.returningDate.focus();	
		return false;
	}
	
	// check ages, not empty - 27/06/06
	if (myForm.child1.selectedIndex > 0) {
		// ROOM NUM
		i_numRooms = myForm.numRooms.value;
		// CHILD NUM
		for(var i=0;i<i_numRooms;i++){	
			o_children = document.getElementById("f_child"+(i+1))
			// Number of Children for a Room	
			i_ages = o_children.selectedIndex;
			if(i_ages>0){
				// Check age filled in
				o_childrow = document.getElementById("childroom"+(i+1))
				a_select = o_childrow.getElementsByTagName("select");
				o_numAges = o_children.selectedIndex;
				for(var j=0;j<i_ages;j++){
					o_childAge = a_select[j].value;
					if (o_childAge.length < 1) {
						alert("Please enter a Child Age.");
						a_select[j].focus();
						return false;
					}
				}
			}
		}
	}
       
        //Redirection to upgrading page - added:01/09/2006
        //this.location.href=("http://www.zuji.com.sg/web/content/sg/upgrading.html");
        //return false;

	//check if layer name provided in the argument
	if (arguments.length>1) {
       	   showWaitMessage(arguments[1],'dispDiv', 1, 0);
        } else {
	   showWaitMessage('waitDivHotels','dispDiv', 1, 0);
	}

        return true;


} // submitHotel

function submitCar( myForm ) {
	if( (myForm.cr_pck_up_cty_name.value == "") || (myForm.cr_pck_up_cty_name.value.length < 3) || (myForm.cr_pck_up_cty_name.length > 36) ) {
	       if ((this.location.href == "http://www.zuji.com.hk/web/content/hkzh/index.html") || (this.location.href == "http://www.zuji.com.hk/web/content/hkzh/carsrail.html")) { 
                   var tempV = document.createElement('div');
                   tempV.innerHTML = "&#22478;&#24066;&#27424;&#32570;&#24517;&#38920;&#36664;&#20837;&#30340;&#36039;&#26009;";
                   alert(tempV.innerHTML);
               } else {
                   alert("Enter a pick-up city of 3 to 36 characters.");
               }
		myForm.cr_pck_up_cty_name.focus();
		return false;
	} else {
	   //check if layer name provided in the argument
	   if (arguments.length>1) {
       	showWaitMessage(arguments[1],'dispDiv', 1, 0);
	   } else {
	   	showWaitMessage('waitDiv','dispDiv', 1, 0);
	   }
		return true;
	}	
} // submitCar

function submitHome( myForm ) {
	if( myForm.mode[0].checked == true ) {
		myForm.action = "http://res.zuji.com:80/cannonball.ctl";
        //default layer Air waiting to be displayed, so no arguments needed.
		return submitAir( myForm );
	} else if (myForm.mode[1].checked == true) {
		myForm.action = "http://go.zuji.travelpn.com/hotel/HotelCobrand.do";
		if (myForm.Service.value == "ZUJIHKZH") {
                        myForm.action = "http://apps.zuji.com/veedu_net/ZUJIHKWS/HotelsAvailability.do";
                        return submitHotel( myForm,'waitDivHotels' );
		} else if (myForm.Service.value == "ZUJINZ") {
			myForm.action = "http://zuji.co.nz/confirm_selection.asp";
			return submitNZHotel( myForm,'waitDivHotel' );
		}
	   	return submitHotel( myForm , 'dispDiv');
                
	} else if (myForm.mode[2].checked == true) {             
                getTotalDateString(document.getElementById ('select_packagedepart_month'),document.getElementById ('select_packagedepart_day'),findYearForCalendar(document.getElementById ('select_packagedepart_month').options[document.getElementById ('select_packagedepart_month').selectedIndex].value),document.getElementById ('select_packagereturn_month'),document.getElementById ('select_packagereturn_day'),findYearForCalendar(document.getElementById ('select_packagereturn_month').options[document.getElementById ('select_packagereturn_month').selectedIndex].value));
                goUrl();
                return false;
	} else {
      	alert("An Error Occured. No product search is selected.");
		return false;
	}
} // submitHome

function changeModeCars(strMode) {
	var arrModeCars = new Array("Simple", "Flexible");
	for (var i = 0; i < arrModeCars.length; i++) {
		if (arrModeCars[i] == strMode) {
			document.getElementById('span'+arrModeCars[i]).className = "selected";
			document.getElementById('header_cars_'+arrModeCars[i]).className = "modeheader_cars_selected";
		}
		else {
			document.getElementById('span'+arrModeCars[i]).className = "deselected";
			document.getElementById('header_cars_'+arrModeCars[i]).className = "modeheader_cars_deselected";
		}
	}
	switch (strMode) {
		case "Simple":
			MM_showHideLayers('tab_cars_flexible','','hide','tab_cars_simple','','show','tab_cars_searchbtn','','hide');
			//changeFlightDate(tab_Flight_Date);
			break;
		case "Flexible": 
			MM_showHideLayers('tab_cars_flexible','','show','tab_cars_simple','','hide','tab_cars_searchbtn','','show'); 
			//changeHotelDestDetails(tab_Hotel_Country);
			break;
	}
}

//retrieve cookie from client
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}//retrieve cookie from client

//5/6/06 HOTEL - MULTIPLE 

function multirooms(s_rooms){
	o_rooms = document.getElementById(s_rooms);
	i_rooms = parseInt(o_rooms.options[o_rooms.selectedIndex].text);
	i_maxrooms = parseInt(o_rooms.options[o_rooms.options.length-1].text);	
	for(var i=0;i<i_maxrooms;i++)document.getElementById("room"+(i+1)).style.display="none";
	for(var i=0;i<i_rooms;i++)document.getElementById("room"+(i+1)).style.display="block";
	if(document.getElementById("multichildroom"))multiroomchild(i_rooms,i_maxrooms);
}

function multiroomchild(i_rooms,i_maxrooms){
	o_childrooms = document.getElementById("multichildroom");
	o_childrooms.style.display = "none";
	o_childrooms1 = document.getElementById("childalert");
	o_childrooms1.style.display = "none";
	o_childrooms2 = document.getElementById("agechildroom");
	o_childrooms2.style.display = "none";
	for(var i=1;i<=i_maxrooms;i++)document.getElementById("childroom"+i).style.display="none";
	for(var i=0;i<i_rooms;i++){
		o_children = document.getElementById("f_child"+(i+1))
		i_ages = o_children.selectedIndex;
		o_childrow = document.getElementById("childroom"+(i+1))
		if(i_ages>0){
			o_childrooms.style.display = "block";
			o_childrooms1.style.display = "block";
			o_childrooms2.style.display = "block";	
			o_childrow = document.getElementById("childroom"+(i+1))
			a_select = o_childrow.getElementsByTagName("select");
			for(var j=0;j<o_children.options.length-1;j++){
				a_select[j].parentNode.style.display = (j<i_ages)?"block":"none";
			}
			o_childrow.style.display = "block";
		}else o_childrow.style.display = "none";
	}
}