var loc_count = 30; var loc_array = new Array(3); loc_array[0] = new Array('yyc','yyz','yul','lir','sjo','dub','mbj','kin','mid','tul1','czm','cun','pvr','cme','sxm','sju','anc','phx','lax','den','fll','idr','ksm','mco','mia','pbi','tpa','atl','dfw','sea'); loc_array[1] = new Array(); loc_array[2] = new Array(); function populateDaysOfMonth(objSource,objTarget){ var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var month = parseInt(objSource.value); var htmlCode = ""; var tarValue = objTarget.value; //if month is february if (month == 2){ //determine year var d = new Date(); var year = (objSource.value < d.getMonth()+1) ? d.getFullYear()+1 : d.getFullYear(); //if is it a leap year make february have 29 days if (isLeapYear(year)) daysInMonth[1] = 29; } clearDropdown(objTarget); //loop thru the number of days for the month for (var i=1; i <= daysInMonth[month-1]; i++) appendOption(objTarget,i,i); objTarget.selectedIndex = getOptionIndex(objTarget,tarValue); } //clears the passed dropdown list function clearDropdown(obj){ //clear the dropdown list for (var i=obj.options.length-1; i >= 0 ; i--) obj.remove(i); } //add option to dropdown object function appendOption(obj,value,text){ //create new option object var newOption = document.createElement("option"); newOption.value = value; newOption.text = text; //append new option element to the end of the dropdown list try { obj.add(newOption, null); // standards compliant; doesn't work in IE }catch(ex){ obj.add(newOption); // IE only } } //determines if the year is a leap year, returns true if leap year function isLeapYear(year){ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true; else return false; } function changeHours(obj,tar){ var loc_code = obj.value; var index = 0; var tarValue = tar.value; while (loc_array[0][index] != loc_code && index < loc_count) index++; if (index != loc_count) populateHoursOfDay(tar,loc_array[1][index],loc_array[2][index]); tar.selectedIndex = getOptionIndex(tar,tarValue); } function populateHoursOfDay(obj,open,close){ var tmp_hour, tmp_min, close_hour, close_min, tmp_array; tmp_array = open.split(":"); tmp_hour = parseInt(tmp_array[0]); tmp_min = parseInt(tmp_array[1]); tmp_array = close.split(":"); close_hour = parseInt(tmp_array[0]); close_min = parseInt(tmp_array[1]); clearDropdown(obj); do{ appendOption(obj,getTimeStr(tmp_hour,tmp_min),getTimeStr(tmp_hour,tmp_min)); tmp_min = add30Min(tmp_min); if (tmp_min < 30) tmp_hour++; }while( parseInt(get2DigStr(tmp_hour)+get2DigStr(tmp_min)) <= parseInt(get2DigStr(close_hour)+get2DigStr(close_min)) ) } //returns 2 digit string, if length of num is 1 append a '0' to the beginning. ex 4 -> '04' function get2DigStr(num){ num = num.toString(); if (num.length == 1) num = "0" + num; return num; } //takes numerical hour ("16") and returns hour string ("4:00 PM") function getTimeStr(hour,min){ if (min == 0) min = "00"; return chg24To12HourClock(hour) + ":" + min +" "+ returnAMOrPM(hour); } //converts from 24 hour clock to 12 hour clock, 16 to 4 function chg24To12HourClock(hour){ return (hour % 12 == 0) ? 12 : hour % 12; } //returns AM or PM string function returnAMOrPM(hour){ return (isAM(hour)) ? "AM" : "PM" } //returns true if time is AM, false if PM function isAM(hour){ return (hour >= 12) ? false : true; } //returns passed minutes + 30 function add30Min(min){ return (min + 30) % 60; } //seaches options in dropdown (obj) for passed value (str) //returns selected index or false function getOptionIndex(obj,str){ var options = obj.options; for (var i=0; i < options.length; i++) if (options[i].value == str) return i; return false; }