//////////////////////////////////////////////////////////////////
//                    - DAWCONS ASOCIADOS -                     //
//                    -- DESARROLLO 2005 --                     //
//                             ---                              //
// Sección de Funciones y objetos de JavaScript para uso de     //
// fechas y validación de rangos.                               //
//                                                              //
//////////////////////////////////////////////////////////////////

var oFecFecha = null;
var fecWin = null;
function fecAbrirCalendario(obj_txt)
{
	obj_txt.blur();
	try
	{
		fecWin.close();
	}catch(ex){}
	fecWin = window.open("../../generales/gen_calendario.aspx?fecha=" + obj_txt.value, "", 'left='+(screen.availWidth-270)/2+',top='+(screen.availHeight-280)/2+',width=270,height=300,status=yes, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, titlebar=no, toolbar=no')
	oFecFecha = obj_txt;
} // fecAbrirCalendario

function fecSetFech(fecha)
{
	if(oFecFecha)
	{
		if(oFecFecha.value != fecha)
		{
			oFecFecha.value=fecha
			oFecFecha.fireEvent("onchange");
		}
		oFecFecha.blur();
	}
}//fecSetFech
// Comparación de Fechas...
function fecComparar(pFecha1, pFecha2)
{
	// Se convierten a Fechas...
	var dFec1 = fecToDate(pFecha1);
	var dFec2 = fecToDate(pFecha2);
	var iDif = dFec2 - dFec1;
	return(iDif/1000/60/60/24);
}// fecComparar
function fecToString(pFecha, pHora)
{
	var sFecha = "";
	sFecha = pFecha.getDate() + "/" + (pFecha.getMonth() + 1) + "/" + pFecha.getFullYear();
	if(pHora)
	{
		// Se anexa la Hora si se especifica...
		sFecha += " " + pFecha.getHours() + ":" + pFecha.getMinutes() + ":" + pFecha.getSeconds();
	}
	return(sFecha);
}// fecToString
function fecToDate(pFecha)
{
	// Se convierte a fecha del formato 'dd/MM/yyyy' ó 'dd/MM/yyyy HH:mm:ss'...
	var iAnio = pFecha.substr(6, 4);
	var iMes = pFecha.substr(3, 2) - 1;
	var iDia = pFecha.substr(0, 2);
	var oFec;
	if(pFecha.length > 11)
	{
		// Se agrega la hora si se especifica...
		var iHor = pFecha.substr(11, 2);
		var iMin = pFecha.substr(14, 2);
		var iSeg = pFecha.substr(17, 2);
		oFec = new Date(iAnio, iMes, iDia, iHor, iMin, iSeg);
	}
	else
	{
		oFec = new Date(iAnio, iMes, iDia);
	}
	return(oFec);
}// fecToDate
