var depDate = new Date();
var arrDate = new Date();


/**
 *
 * @access public
 * @return void
 **/
function createNights(arrival,departure){

}

/**
 *
 * @access public
 * @return void
 **/
function createDeparture(arrival,nights){
	return new Date(arrival.getTime() + (nights)*24*60*60*1000);
}

/**
 *
 * @access public
 * @return void
 **/
function setArrival(formObj){

	  if(formObj.arrival_month.value){
      	arrDate.setMonth(parseInt(formObj.arrival_month.value)-1);
      }
      if(formObj.arrival_year.value){
      	arrDate.setFullYear(parseInt(formObj.arrival_year.value));
      }
      if(formObj.arrival_date.value){
      	arrDate.setDate(parseInt(formObj.arrival_date.value));
      }
}

 /**
  *
  * @access public
  * @return void
  **/
 function setDeparture(formObj){
      if(formObj.departure_month.value){
      	depDate.setMonth(parseInt(formObj.departure_month.value)-1);
	  }
	  if(formObj.departure_year.value){
      	depDate.setFullYear(parseInt(formObj.departure_year.value));
      }
      if(formObj.departure_date.value){
      	depDate.setDate(parseInt(formObj.departure_date.value));
      }

}

/**
 *
 * @access public
 * @return void
 **/

 /**
  *
  * @access public
  * @return void
  **/
 function changeDeparts(formObj,nights){
      //alert(depDate.toString());
      if (! typeof nights == 'number') {
      	var nights = new Number(parseInt(formObj.nights.value));
      }
 	  depDate = createDeparture(arrDate,nights.valueOf());

      formObj.departure_year.value = depDate.getFullYear();
      formObj.departure_date.value = depDate.getDate();
      var m =depDate.getMonth()+1;
      if(m<10){
	   m = new String('0'+m);
	  }
      formObj.departure_month.value = m;
 }

function generateDateValues(formObj){
	   setArrival(formObj);
       setDeparture(formObj);
       changeDeparts(formObj,parseInt(formObj.nights.value));
}
