/*
	Long Dates Functions
	Pack a Date to format yyyymmdd
	Copyright (C) 2002 by Cinematica Producciones Ltda.
*/

var YEAR_FACTOR = 10000;
var MONTH_FACTOR = 100;

function CP_PackLDate(iYear, iMonth, iDay) {
  return((iYear * YEAR_FACTOR) + (iMonth * MONTH_FACTOR) + (iDay * 1)); // * 1 ???
}

function CP_GetLYear(dtDate) {
  return( Math.floor(dtDate / YEAR_FACTOR) );
}

function CP_GetLMonth(dtDate) {
  var ny = Math.floor(dtDate / YEAR_FACTOR);
  return( Math.floor((dtDate - (ny * YEAR_FACTOR)) / MONTH_FACTOR) );
}

function CP_GetLDay(dtDate) {
  var ny = Math.floor(dtDate / YEAR_FACTOR);
  var nm = Math.floor((dtDate - (ny * YEAR_FACTOR)) / MONTH_FACTOR);
  return( Math.floor(dtDate - (ny * YEAR_FACTOR) - (nm * MONTH_FACTOR)) );
}

// Retorna true si los componentes de una fecha están correctos
function CP_IsGoodDate(iYear, iMonth, iDay) {
  var iNewYear, iNewMonth, iNewDay;
  var aDate = new Date();
  aDate.setFullYear(iYear, iMonth - 1, iDay);
  iNewYear = aDate.getFullYear();
  iNewMonth = aDate.getMonth() + 1;
  iNewDay = aDate.getDate();
  return((iYear == iNewYear) && (iMonth == iNewMonth) && (iDay == iNewDay));
}

function CP_LDateToDate(aLDate) {
  var iYear, iMonth, iDay;
  var dtDate;

  dtDate = new Date(CP_GetLYear(aLDate), (CP_GetLMonth(aLDate)-1), CP_GetLDay(aLDate));
  return dtDate;
}
