/* calendarSelect.js */
var arrival = true;

arr = new Array();
arr[1]="January";
arr[2]="February";
arr[3]="March";
arr[4]="April";
arr[5]="May";
arr[6]="June";
arr[7]="July";
arr[8]="August";
arr[9]="September";
arr[10]="October";
arr[11]="November";
arr[12]="December";


function writeDate (date) {
  day = date.getDate();
  month = date.getMonth()+1;
  
  year = date.getYear();
  if (year < 1000) year+=1900;
  dateString = month + "/" + day + "/" + year;
  if (arrival) changeArrivalSelect (dateString);
  else changeDepartureSelect (dateString);
}

function changeArrivalDate() {
document.getElementById('arrivalDate').value=document.getElementById('arrivalMonth').value + '/' + document.getElementById('arrivalDay').value + '/' + document.getElementById('arrivalYear').value
}

function changeDepartureDate() {
document.getElementById('departureDate').value=document.getElementById('departureMonth').value + '/' + document.getElementById('departureDay').value + '/' + document.getElementById('departureYear').value
}

function changeArrivalSelect (text) {
  var a = text.indexOf('/');
  month = text.substr (0, a);
  dayYear = text.substr (a+1, text.length);
  a = dayYear.indexOf('/');
  day = dayYear.substr(0,a);
  year = dayYear.substr(a+1, dayYear.length);
  document.getElementById('arrivalDay').selectedIndex=parseInt(day)-1;
  document.getElementById('arrivalMonth').selectedIndex=parseInt(month)-1;
  yearOptions = document.getElementById('arrivalYear').options;

  a=0;
  while (a<yearOptions.length) {
    if (yearOptions.item(a).innerHTML == year) {
      document.getElementById('arrivalYear').selectedIndex=a;
      break;
    }
    a++;
  }
  if (a==yearOptions.length) {
     document.getElementById('arrivalYear').options[yearOptions.length] = new Option(year, year,false,false);
     document.getElementById('arrivalYear').selectedIndex=a;
  }
}


function changeDepartureSelect (text) {
  var a = text.indexOf('/');
  month = text.substr (0, a);
  dayYear = text.substr (a+1, text.length);
  a = dayYear.indexOf('/');
  day = dayYear.substr(0,a);
  year = dayYear.substr(a+1, dayYear.length);
  document.getElementById('departureDay').selectedIndex=parseInt(day)-1;
  document.getElementById('departureMonth').selectedIndex=parseInt(month)-1;
  yearOptions = document.getElementById('departureYear').options;

  a=0;
  while (a<yearOptions.length) {
    if (yearOptions.item(a).innerHTML == year) {
      document.getElementById('departureYear').selectedIndex=a;
      break;
    }
    a++;
  }
  if (a==yearOptions.length) {
     document.getElementById('departureYear').options[yearOptions.length] = new Option(year, year,false,false);
     document.getElementById('departureYear').selectedIndex=a;
  }
}

date = new Date();
date.setDate(date.getDate()+21);
date2 = new Date;
date2.setDate(date2.getDate()+22);


function getMonthSelect () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date.getMonth()+1)==i) text = " selected";
    else text="";
   html += "<option value=\"" + ((i<10)?"0"+i:i) + "\"" + text + ">" + arr[i] + "</option>\n";
 /*   html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";*/
  }
  return (html);
}

function getShortMonthSelect () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";
  }
  return (html);
}


function getMonthZeroSelect () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date.getMonth()+1)==i) text = " selected";
    else text="";
   html += "<option value=\"" + ((i<10)?"0"+(i-1):i-1) + "\"" + text + ">" + arr[i] + "</option>\n";
 /*   html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";*/
  }
  return (html);
}


function getMonthCompleteNameSelect () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date2.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + arr[i] + "\"" + text + ">" + arr[i] + "</option>\n";
  }
  return (html);
}


function getMonthSelectDeparture () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date2.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + ((i<10)?"0"+i:i) + "\"" + text + ">" + arr[i] + "</option>\n";
/* html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";*/
  }
  return (html);
}

function getShortMonthSelectDeparture () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date2.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";
  }
  return (html);
}


function getMonthZeroSelectDeparture () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date2.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + ((i<10)?"0"+(i-1):i-1) + "\"" + text + ">" + arr[i] + "</option>\n";
/* html += "<option value=\"" + i + "\"" + text + ">" + arr[i] + "</option>\n";*/
  }
  return (html);
}


function getMonthCompleteNameSelectDeparture () {
  var html="";
  for (i=1; i<13; i++) {
    if ((date2.getMonth()+1)==i) text = " selected";
    else text="";
    html += "<option value=\"" + arr[i] + "\"" + text + ">" + arr[i] + "</option>\n";
  }
  return (html);
}

function getDaySelect () {
  var html = "";
  for (i=1; i<32; i++) {
    if (date.getDate()==i) text = " selected";
    else text="";
    html += "<option value=\"" + ((i<10)?('0'+i):i) + "\"" + text + ">" + ((i<10)?('0'+i):i) + "</option>\n";
  }
  return (html);
}

function getShortDaySelect () {
  var html = "";
  for (i=1; i<32; i++) {
    if (date.getDate()==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + ((i<10)?('0'+i):i) + "</option>\n";
  }
  return (html);
}


function getDaySelectDeparture () {
  var html = "";
  for (i=1; i<32; i++) {
    if (date2.getDate()==i) text = " selected";
    else text="";
    html += "<option value=\"" + ((i<10)?('0'+i):i) + "\"" + text + ">" + ((i<10)?('0'+i):i) + "</option>\n";
  }
  return (html);
}

function getShortDaySelectDeparture () {
  var html = "";
  for (i=1; i<32; i++) {
    if (date2.getDate()==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + ((i<10)?('0'+i):i) + "</option>\n";
  }
  return (html);
}

function getShortYearSelect() {
  y = date.getYear();
  var html;
  if (y<1000) y+=1900;
  for (i=y; i<y+3; i++) {
    if (y==i) text = " selected";
    else text="";
    html += "<option value=\"" + (((i-2000)<10)?"0"+(i-2000):(i-2000)) + "\"" + text + ">" + i + "</option>";
  }
  return (html);
}


function getShortYearSelectDeparture() {
  y = date2.getYear();
  var html="";
  if (y<1000) y+=1900;
  for (i=y; i<y+3; i++) {
    if (y==i) text = " selected";
    else text="";
    html += "<option value=\"" + (((i-2000)<10)?"0"+(i-2000):(i-2000)) + "\"" + text + ">" + i + "</option>";
  }
  return (html);
}


function getLongYearSelect() {
  var html ="";
  y = date.getYear();
  if (y<1000) y+=1900;
  for (i=y; i<y+3; i++) {
    if (y==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + i + "</option>";
  }
  return (html);
}

function getLongYearCreditSelect() {
  var html ="";
  y = date.getYear();
  if (y<1000) y+=1900;
  for (i=y; i<y+10; i++) {
    if (y==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + i + "</option>";
  }
  return (html);
}


function getLongYearSelectDeparture() {
  var html ="";
  y = date2.getYear();
  if (y<1000) y+=1900;
  for (i=y; i<y+3; i++) {
    if (y==i) text = " selected";
    else text="";
    html += "<option value=\"" + i + "\"" + text + ">" + i + "</option>";
  }
  return (html);
}
