function dump( variable ){
  result = variable + '\n';
  for (member in variable) {
    if( variable.member ){
      result += member+':'+variable.member+'\n';
    }
  }
  alert( result );
}


function toggle( form ){
  for(i=0;i<form.elements.length;i++){
    if( form.elements[i].checked == true ){
      form.elements[i].checked = false;
    }else{
      form.elements[i].checked = true;
    }
  }
}

//use onclick="return blank(href)" instead of target=_blank as this isn't valid strict html
function blank( href ){
  //mac ie needs the toobars explicitly turned on
  window.open(href, 'newwindow', 'fullscreen=no,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,directories=yes,location=yes');
  //return false so that the link isn't followed in the main window
  //link still points to href but javascript stops it, but browsers with javascript rurned off should still get there
  return false;
}

//use onclick="return blank(href)" instead of target=_blank as this isn't valid strict html
function popup( href, width, height ){
  //mac ie needs the toobars explicitly turned on
  //don't bother specifying height, just allow them to resize
  if( height ){
    width += ',height='+height;
  }
  window.open(href, 'newwindow', 
    'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width='+width);
  //return false so that the link isn't followed in the main window
  //link still points to href but javascript stops it, but browsers with javascript rurned off should still get there
  return false;
}

months = Array();
months['01'] = 'January';
months['02'] = 'February';
months['03'] = 'March';
months['04'] = 'April';
months['05'] = 'May';
months['06'] = 'June';
months['07'] = 'July';
months['08'] = 'August';
months['09'] = 'September';
months['10'] = 'October';
months['11'] = 'November';
months['12'] = 'December';

function switch_recurring(){
  if( document.getElementById( 'RECURRING_OFFER_YES' ) ){
    if( !document.getElementById( 'RECURRING_OFFER_YES' ).checked ){
      document.getElementById( 'RECURRING_WRAPPER' ).style.color = '#AAAAAA';
      
      document.getElementById( 'RECURRING_FREQUENCY' ).disabled = true;

      document.getElementById( 'RECURRING_END_DATE-day' ).disabled = true;
      document.getElementById( 'RECURRING_END_DATE-month' ).disabled = true;
      document.getElementById( 'RECURRING_END_DATE-year' ).disabled = true;
    }else{
      //enable recurring_frequency
      //fill recurring_end_date with value from departure_date
      //enable recurring_end_date and fill with value from departure date if value has not already been changed, need a flag of some sort
      //also need to make sure recurring_end_date is after start date
      document.getElementById( 'RECURRING_WRAPPER' ).style.color = '#000000';
      
      document.getElementById( 'RECURRING_FREQUENCY' ).disabled = false;

      document.getElementById( 'RECURRING_END_DATE-day' ).disabled = false;
      document.getElementById( 'RECURRING_END_DATE-month' ).disabled = false;
      document.getElementById( 'RECURRING_END_DATE-year' ).disabled = false;

      document.getElementById( 'RECURRING_START_DATE' ).innerHTML = document.getElementById( 'DEPARTURE_DATE-day' ).value +
            ' ' +months[document.getElementById( 'DEPARTURE_DATE-month' ).value] + ' ' + document.getElementById( 'DEPARTURE_DATE-year' ).value;
      
      //only update reccuring end date if the value is currently less than the departure date            
      if( ( document.getElementById( 'RECURRING_END_DATE-year' ).value < document.getElementById( 'DEPARTURE_DATE-year' ).value )
        || ( document.getElementById( 'RECURRING_END_DATE-year' ).value == document.getElementById( 'DEPARTURE_DATE-year' ).value
            && document.getElementById( 'RECURRING_END_DATE-month' ).value < document.getElementById( 'DEPARTURE_DATE-month' ).value )
        || ( document.getElementById( 'RECURRING_END_DATE-year' ).value == document.getElementById( 'DEPARTURE_DATE-year' ).value
            && document.getElementById( 'RECURRING_END_DATE-month' ).value == document.getElementById( 'DEPARTURE_DATE-month' ).value
            && document.getElementById( 'RECURRING_END_DATE-day' ).value < document.getElementById( 'DEPARTURE_DATE-day' ).value ) 
            ){
        document.getElementById( 'RECURRING_END_DATE-day' ).value = document.getElementById( 'DEPARTURE_DATE-day' ).value;
        document.getElementById( 'RECURRING_END_DATE-month' ).value = document.getElementById( 'DEPARTURE_DATE-month' ).value;
        document.getElementById( 'RECURRING_END_DATE-year' ).value = document.getElementById( 'DEPARTURE_DATE-year' ).value;
      }
      
    }
  }
}

