/*
	_Date.js : Funciones de Fecha

	Autor: 
*/

// --------------------------------------------------------
// --- Datos


// --------------------------------------------------------
// Funciones para Fechas

// Estas variables tienen que estar declaradas  e iniciadas en Top
//var m_LocalDate  = new Date();
//var m_ServerDate = new Date( <xsl:value-of select="//Server_Date/@value" /> );

// ------------------------------------
// DsDt_GetCurDate : Obtiene una hora buena
function DsDt_GetCurDate()
{
	var DateDif = (GetTopWnd().m_LocalDate-GetTopWnd().m_ServerDate);
	return new Date( ((new Date())/1) + DateDif);
}

// ------------------------------------
// DsDt_GetCurZeroDate : Obtiene una Fecha buena
function DsDt_GetCurZeroDate()
{
	var pDate = DsDt_GetCurDate();
	return new Date( pDate.getFullYear(), pDate.getMonth(), pDate.getDate(), 0, 0, 0, 0 );
}

// ------------------------------------
// DsDt_ZeroDate : Pasa una Fecha a DDMMYY
function DsDt_ZeroDate( dt )
{
	return new Date( dt.getFullYear(), dt.getMonth(), dt.getDate(), 0, 0, 0, 0 );
}

// ------------------------------------
// DsDt_CopyDate
function DsDt_CopyDate( dt )
{
	return new Date( dt );
}

// ------------------------------------
// DsDt_CopyZeroDate
function DsDt_CopyZeroDate( dt )
{
	return new Date( dt.getFullYear(), dt.getMonth(), dt.getDate(), 0, 0, 0, 0 );
}

// ------------------------------------
// DsDt_Str2Date : Cadena a Fecha
function DsDt_Str2Date( sValue )
{
	var re = /^(\d+)\/(\d+)\/(\d+)/;
	var dt = null;
	
	if ( !re.exec(sValue) )
		alert( "Formato de Fecha no válido: "+ sValue );
	else
		dt = new Date( RegExp.$3, RegExp.$2-1, RegExp.$1 );
		
	return dt;
}

// ------------------------------------
// DsDt_Date2Str
function DsDt_Date2Str( dt )
{
	return new String( dt.getDate() + "/" + (dt.getMonth()+1) + "/" + dt.getFullYear() );
}

// --------------------------------
// DsDt_DaysSpan : Diferencia de Fechas en días
function DsDt_DaysSpan( dtEnd, dtStart )
{
	var nMiliSecs  = (24*60*60*1000);
	var	dtTmpEnd   = DsDt_ZeroDate( dtEnd );
	var	dtTmpStart = DsDt_ZeroDate( dtStart );
	
	return ( (dtTmpEnd-dtTmpStart)/nMiliSecs );
}

