function setDateRange(selectedFrom,selectedTo){
  
  dateDashOffset = 0
    if(document.theForm.fromDay.options[0].value == '1'){
    dateDashOffset = -1
  }
  if(selectedFrom.indexOf('-') != -1){
    selFrom = selectedFrom.split('-')
    selFromDay = selFrom[0]
    selFromMonth = selFrom[1]
    selFromYear = selFrom[2]
    var yearbegin = startyear
    if(startyear < (whenyear - maxyears + 1)) yearbegin = whenyear - maxyears + 1
    document.theForm.fromDay.options.selectedIndex = parseInt(selFromDay, 10) + dateDashOffset
    document.theForm.fromMonth.options.selectedIndex = parseInt(selFromMonth, 10) + dateDashOffset
    document.theForm.fromYear.options.selectedIndex = parseInt(selFromYear - yearbegin + 1, 10) + dateDashOffset
  }
  if(selectedTo.indexOf('-') != -1){
    selTo = selectedTo.split('-')
    selToDay = selTo[0]
    selToMonth = selTo[1]
    selToYear = selTo[2]
    var yearbegin = startyear
    if(startyear < (whenyear - maxyears + 1)) yearbegin = whenyear - maxyears + 1
    document.theForm.toDay.options.selectedIndex = parseInt(selToDay, 10) + dateDashOffset
    document.theForm.toMonth.options.selectedIndex = parseInt(selToMonth, 10) + dateDashOffset
    document.theForm.toYear.options.selectedIndex = parseInt(selToYear - yearbegin + 1, 10) + dateDashOffset
  }
  if(selectedFrom != '' && selectedTo != ''){
    resetPeriod()
  }
}

function returnCorrectDate(fromYear,fromMonth,fromDay,toYear,toMonth,toDay){
  validFromDate = verifyDate(fromYear,fromMonth,fromDay)
  validToDate = verifyDate(toYear,toMonth,toDay)
  if(validFromDate == 'future'){
    document.theForm.fromDay.focus()
    sendErrorMsg('The from date is in the future');
    return false;
  } else if(validToDate == 'future'){
    document.theForm.toDay.focus()
    sendErrorMsg('The to date is in the future');
    return false;
  } else if(validFromDate && validToDate){
    startDate = new Date(startyear,startmonth,startday)
    fromDate = new Date(fromYear,fromMonth,fromDay)
    if(fromDate < startDate) {
      fromDay = startday;
      fromMonth = startmonth;
      fromyear = startyear;
    }
    from = zeroPad(fromDay) + '-' + zeroPad(fromMonth) + '-' + fromYear;
    toDate = new Date(toYear,toMonth,toDay)
    if(toDate < startDate) {
      toDay = startday;
      toMonth = startmonth;
      toyear = startyear;
    }
    to = zeroPad(toDay) + '-' + zeroPad(toMonth) + '-' +  toYear;
    if(fromDate < toDate){
      return '&from=' + from + '&to=' + to;
    } else {
      return '&from=' + to + '&to=' + from;
    }
  } else if(!validFromDate){
    document.theForm.fromDay.focus()
    sendErrorMsg('The from date is not valid');
    return false;
  } else if(!validToDate){
    document.theForm.toDay.focus()
    sendErrorMsg('The to date is not valid');
    return false;
  }
}