/*
//=================================================================
//
// Copyright 2000 Novasoft Servicios Informáticos S.A.
//             Todos los derechos reservados
// MODULO:
//   Fechas
//
// DESCRIPCIÓN:
//   Contiene métodos para procesamiento y validación de fechas en
// JScript cliente.
//
// CREADO:
//   19/12/2000  ARS
//=================================================================
*/

/*
//=================================================================
// FUNCIÓN:
//   fec_is_valid_date
//
// DESCRIPCIÓN:
//  Comprueba si la cadena dada tiene el formato MM/DD/YYYY.
// Sólo comprueba si tiene el formato y no la validez de la fecha 
// en sí misma.
//
// ENTRADAS:
//	Cadena a comprobar si es una fecha váldida.
//
// SALIDAS:
//  True si la cadena tiene el formato MM/DD/YYYY.
//  False en otro caso.
//
// CREADO:
//   19/12/2000  ARS. 
//
//=================================================================
*/        
function fec_is_valid_date(s)
{
 var date_regex = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

// ^ indicates start of expression
// \d{1,2} - the \d means digits and {1,2} means 1 or 2 digits
// $ indicates end f expression

 if (!date_regex.test(s))
 {
  return(false);
 }

 return(true);
}

/*
//=================================================================
// FUNCIÓN:
//   fec_is_date_string
//
// DESCRIPCIÓN:
//  this function does not handle BC dates or dates past 12/31/9999
//  Comprueba si la cadena dada es una fecha válida con el formato
//  DD$MM$YYYY, MM$DD$YYYY, YYYY$MM$DD o YYYY$DD$MM. 
//  Siendo $ el delimitador "-", "/" o " ".
//
// ENTRADAS:
//	Cadena a comprobar si es una fecha válida.
//
// SALIDAS:
//  True si la cadena tiene el formato MM/DD/YYYY.
//  False en otro caso.
//
// CREADO:
//   19/12/2000  ARS. 
//
//=================================================================
*/        
function fec_is_date_string(stringValue) {

	// create a String object
	var theString = new String(stringValue);

	// determine the delimiter character (must be "/" "-" or space)
	var delimiterCharacter
	
	if ( theString.indexOf('/') > 0 )
					delimiterCharacter = '/';
	else
		if ( theString.indexOf('-') > 0 )
						delimiterCharacter = '-';
		else
			if ( theString.indexOf(' ') > 0 )
							delimiterCharacter = ' ';
			else
							return false;

			// split the string into an array of tokens
			var theTokens = theString.split(delimiterCharacter);

			// there must be either two or three tokens
			if ( theTokens.length < 2 || theTokens.length > 3 )
							return false;

			// convert the tokens to String objects, which will be needed later,
			// stripping a single leading 0
			var tokenIndex;
			for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {
							theTokens[tokenIndex] = new String(theTokens[tokenIndex])
							if ( theTokens[tokenIndex].charAt(0) == '0' )
											theTokens[tokenIndex] = theTokens[tokenIndex].substring(1, theTokens[tokenIndex].length);
			}
			
			// all of the tokens must be positive integers
			for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {
							if ( ! isNonnegativeInteger(theTokens[tokenIndex]) )
											return false;
			}

			// we need to identify the year, month, and day tokens
			var numericValue;
			var yearTokenIndex = -1;
			var monthTokenIndex = -1;
			var dayTokenIndex = -1;
			for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {

					// convert the value
					numericValue = parseInt(theTokens[tokenIndex], 10);

					// could this token be a month?
					if ( numericValue <= 12 ) {

						// yes; do we already have a month?
						if ( monthTokenIndex == -1 ) {

										// no; assign this token to the month and continue
										monthTokenIndex = tokenIndex;
										continue;
						}
						else {

							// we already have a month; this token could
							// also be the day; do we already have a day?
							if ( dayTokenIndex == -1 ) {

											// no; assign this token to the day and continue
											dayTokenIndex = tokenIndex;
											continue;
							}
							else {

								// we already have a day; this token could
								// also be the year; do we alreay have a year?
								if ( yearTokenIndex == -1 ) {

												// no; assign this token to the year and continue
												dayTokenIndex = tokenIndex;
												continue;
								}
							}
					  }
					}
					else {

						// the value is too large for a month;
						// could this token be a day?
						if ( numericValue <= 31 ) {

							// yes; do we already have a day?
							if ( dayTokenIndex == -1 ) {

											// no; assign this token to the day and continue
											dayTokenIndex = tokenIndex;
											continue;
							}
							else {

								// we already have a day; this token could
								// also be the year; do we alreay have a year?
								if ( yearTokenIndex == -1 ) {

												// no; assign this token to the year and continue
												dayTokenIndex = tokenIndex;
												continue;
								}
							}
						}		
						else {

							// the value is too large for a day;
							// could this token be a year?
							if ( numericValue <= 9999 ) {

								// yes; do we already have a year?
								if ( yearTokenIndex == -1 ) {

												// no; assign this token to the year
												yearTokenIndex = tokenIndex;
								}
							}
						}
					}
      } // end of for loop

			// evaluate, based on the number of tokens
			if ( theTokens.length == 2 ) {

				// two tokens can be either a month/year combination or a month/day
				// combination with the current year assumed; either way, we must have
				// a month
				if ( monthTokenIndex == -1 )

								// no month
								return false;

				// do we have a year?
				if ( ! (yearTokenIndex == -1) ) {

								// yes; month/year combination; must be okay
								return true;
				}
				else

						// no year; do we have a day?
						if ( ! (dayTokenIndex == -1) ) {

										// yes; month/day combination; get the current year
										var today = new Date();
										var currentYear = today.getYear();

										// make sure it's a valid date (we were testing days using
										// 31, and that might be too many for the month)
										return isDate(currentYear, theTokens[monthTokenIndex], theTokens[dayTokenIndex]);
						}
						else

										// we have neither a year nor a day
										return false;
      }
			else {

				// three tokens; we should have found tokens for year, month, and day
				if ( yearTokenIndex == -1 || monthTokenIndex == -1 || dayTokenIndex == -1 )

								// missing one or more
								return false;
				else

					// found all; however, VBScript can only handle the following sequences
					if ( monthTokenIndex == 0 ) {

									// must be m/d/y
									if ( dayTokenIndex != 1 || yearTokenIndex != 2)
													return false;
					}
					else
						if ( dayTokenIndex == 0 ) {

										// must be d/m/y
										if ( monthTokenIndex != 1 || yearTokenIndex != 2)
														return false;
						}
						else
										if ( yearTokenIndex == 0 ) {

														// must be y/m/d
														if ( monthTokenIndex != 1 || dayTokenIndex != 2)
																		return false;
										}
										else
														// something is wrong
														return false;
														
						// make sure it's a valid date (we were testing days using a value
						// of 31, and that might be too many for the actual month)
						return isDate(theTokens[yearTokenIndex], theTokens[monthTokenIndex], theTokens[dayTokenIndex]);
			}
}


//=================================================================
// FUNCIÓN:
//   fec_formatea_fecha
//
// DESCRIPCIÓN:
//  Normaliza la cadena dada al formato dd/mm/aaaa
//
// ENTRADAS:
//	Cadena a aplicar el formato
// 	Formatos válidos de entrada: aaaammdd
//								 dd$mm$aaaa, con $='/' ó '-'
//								 d$m$aa
//								 combinaciones de los dos últimos
//
// SALIDAS:
// Array: 
//		la_resultado: la_resultado[0]: Código de éxito (0) o error (-1)
//					  la_resultado[1]: cadena con la fecha formateada
//
// CREADO:
//   31/01/2001  MJJL. 
//
//=================================================================

	function fec_formatea_fecha(as_fecha)
	{
		var la_fecha = new Array();	
		var ls_substring = "";
		var ls_separador;
		var ls_mes;
		var ls_dia;
		var ls_year;
		var ls_fecha = '';
		var ls_fecha_valid = '';
		var lb_resultado = true;
		
		if (as_fecha == "")
		{
			lb_resultado = false;
		}
		else
		{
			var la_resultado = new Array();	
			la_fecha = fec_get_diamesyear(as_fecha);
			if (la_fecha[0] == 0)
			{
				ls_dia = la_fecha[1];
				ls_mes = la_fecha[2];
				ls_year = la_fecha[3];
				
				ls_fecha = la_fecha[1] + '/' + la_fecha[2] + '/' + la_fecha[3];
				ls_fecha_valid = la_fecha[2] + '/' + la_fecha[1] + '/' + la_fecha[3];
			}
			else
			{
				lb_resultado = false;
			}
		}
		
		if (lb_resultado == true)			
		{
			lb_resultado = fec_is_date_string(ls_fecha_valid);
		}
		
		if (lb_resultado == true)			
		{
			la_resultado[0] = 0;
			la_resultado[1] = ls_fecha;
		}
		else
		{
			la_resultado[0] = -1;
		}
		return la_resultado;
	}

//=================================================================
// FUNCIÓN:
//   fec_comprueba_periodo
//
// DESCRIPCIÓN:
//  Comprueba si una fecha (dada como cadena) está incluida en el periodo formado 
// por otras dos. Si alguno de los parámetros es vacío, se ignorará
//
// ENTRADAS:
//	ls_fecha      	fecha que deberá estar incluida en el periodo
//	ls_fecha_ini	fecha inicial del periodo
//	ls_fecha_fin	fecha final del periodo
//	al_periodo		periodo máximo permitido en días
//
// SALIDAS:
//	ll_resultado: código de resultado:
//  		0   --> OK 
//			-1  --> error obteniendo día, mes, año
//			-2  --> error: la fecha inicial es posterior a la final
//			-3  --> error: se supera el periodo máximo establecido
//			-4  --> error: la fecha no está incluida en el periodo dado
//
// CREADO:
//   31/01/2001  MJJL. 
//
//=================================================================

	function fec_comprueba_periodo(ls_fecha, ls_fecha_ini, ls_fecha_fin, al_periodo)
	{
		var ld_fecha_fin;
		var ld_fecha_ini;
		var ld_fecha;
		var lldia;
		var llmes;
		var llyear;
		var lsopcion;
		var lb_resultado = true;
		var ll_resultado = 0;
		
		var la_fecha = new Array();
		var la_fecha_ini = new Array();
		var la_fecha_fin = new Array();
		
		if (ls_fecha != '')
		{
			la_fecha = fec_get_diamesyear(ls_fecha);
			if (la_fecha[0] == 0)
			{
				ld_fecha = new Date(la_fecha[3], la_fecha[2] - 1, la_fecha[1]);
			}
			else
			{
				lb_resultado = false;
				ll_resultado = -1;
			}
		}
		
		if (ls_fecha_ini != '')
		{
			la_fecha_ini = fec_get_diamesyear(ls_fecha_ini);

			if (la_fecha_ini[0] == 0)
			{
				ld_fecha_ini = new Date(la_fecha_ini[3], la_fecha_ini[2] - 1, la_fecha_ini[1]);
			}
			else
			{
				lb_resultado = false;
				ll_resultado = -1;
			}
		}

		if (ls_fecha_fin != '')
		{
			la_fecha_fin = fec_get_diamesyear(ls_fecha_fin);
			if (la_fecha_fin[0] == 0)
			{
				ld_fecha_fin = new Date(la_fecha_fin[3], la_fecha_fin[2] - 1, la_fecha_fin[1]);
			}
			else
			{
				lb_resultado = false;
				ll_resultado = -1;
			}
		}
		if ((ls_fecha_ini != '') && (ls_fecha_fin != '') && (lb_resultado == true))
		{
			if (ld_fecha_fin < ld_fecha_ini)
			{
				lb_resultado = false;
				ll_resultado = -2;
			}
			else
			{
				if ((al_periodo != '') && (al_periodo > 0))
				{
					var ll_periodo = ld_fecha_fin.getTime()  - ld_fecha_ini.getTime()
					ll_periodo = ll_periodo/(24 * 60 * 60 * 1000)

					if (ll_periodo > al_periodo)
					{
						lb_resultado = false;
						ll_resultado = -3
					}
				}
			}	
		}
		
		if ((ls_fecha != '') && (ls_fecha_ini != '') && (lb_resultado == true))
		{
			if (ld_fecha < ld_fecha_ini)
			{
				lb_resultado = false;
				ll_resultado = -4;
			}
		}
		
		if ((ls_fecha != '') && (ls_fecha_fin != '') && (lb_resultado == true))
		{
			if (ld_fecha > ld_fecha_fin)
			{
				lb_resultado = false;
				ll_resultado = -4
			}
		}

		return ll_resultado;
    }


//=================================================================
// FUNCIÓN:
//   fec_get_diamesyear
//
// DESCRIPCIÓN:
//  Dada una cadena de fecha (en el formato dd$mm$aaaa, d$m$aa, o cualquiera
// de sus combinaciones), devuelve un array conteniendo el día, mes y año
//
// ENTRADAS:
//	cadena de fecha
//
// SALIDAS:
//  array: 	la_resultado[0] --> 0 si éxito, -1 si error
//			la_resultado[1] --> día
//			la_resultado[2] --> mes
//			la_resultado[3] --> año
//
// CREADO:
//   31/01/2001  MJJL. 
//
//=================================================================
	function fec_get_diamesyear(as_fecha)
	{
		var la_resultado = new Array();
		var la_fecha = new Array();
		var ls_substring = "";
		var ls_separador = '';
		var ll_mes;
		var ll_dia;
		var lb_resultado = true;
		
		if (as_fecha != "")
		{
			lb_resultado = str_valid_value(as_fecha, "'0', '1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'/','-'", 0);
			
			if (lb_resultado == true)
			{
				for (var i = 0;(i < as_fecha.length); i++)
				{
					ls_substring = as_fecha.substr(i, 1);
					if ((ls_substring == "/") || (ls_substring == "-"))
					{
						ls_separador = ls_substring;
					}
				}
				if (ls_separador == '')
				{
					if (as_fecha.length == 8)
					{
						la_fecha[0] = as_fecha.substr(6, 2);
						la_fecha[1] = as_fecha.substr(4, 2);
						la_fecha[2] = as_fecha.substr(0, 4);
					}
					else
					{
						lb_resultado = false;
					}
				}
				else
				{
					la_fecha = as_fecha.split(ls_separador);
					if (la_fecha.length != 3)
					{
						lb_resultado = false;
					}
					else
					{					
						if (la_fecha[0].length > 2)
						{
							lb_resultado = false;
						}
						else
						{					
							if (la_fecha[0].length == 1)
							{
								la_fecha[0] = "0" + la_fecha[0];
							}
						}
						if (la_fecha[1].length > 2)
						{
							lb_resultado = false;
						}
						else
						{
							if (la_fecha[1].length == 1)
							{
								la_fecha[1] = "0" + la_fecha[1];
							}
						}
						if ((la_fecha[2]== '') || (la_fecha[2].length == 0))
						{
							lb_resultado = false;
						}
						else
						{
							if (la_fecha[2].length == 2)
							{
								ll_agno = parseInt(la_fecha[2], 10);
								if (ll_agno > 90)
								{
									la_fecha[2] = "19" + la_fecha[2];
								}
								else
								{
									la_fecha[2] = "20" + la_fecha[2];
								}
							}
							else
							{
								if (la_fecha[2].length != 4)
								{
									lb_resultado = false;
								}
							}
						}
					}
				}
			}
		}

		if (lb_resultado == true)
		{
			if ((la_fecha[0] > 31) || (la_fecha[1] > 12))
			{
				lb_resultado = false;
			}
		}
		
		if (lb_resultado == true)
		{
			la_resultado[0] = 0;
			la_resultado[1] = la_fecha[0];
			la_resultado[2] = la_fecha[1];
			la_resultado[3] = la_fecha[2];
		}
		else
		{
			la_resultado[0] = -1;
		}
		return la_resultado;
	}



/*
//=================================================================
// FUNCIÓN:
//   fec_is_time_string
//
// DESCRIPCIÓN:
//  Comprueba si la cadena dada es una hora válida con el formato
//  HH:MM o HH:MM:SS o HH:MM AM o HH:MM:SS AM o HH:MM PM o HH:MM:SS PM.
//
// ENTRADAS:
//	Cadena a comprobar si es una hora válida.
//
// SALIDAS:
//  True si la cadena tiene el formato adecuado.
//  False en otro caso.
//
// CREADO:
//   19/12/2000  ARS. 
//
//=================================================================
*/        
function fec_is_time_string(stringValue) {

				// this function is designed to mimic the "time" portion of the
				// VBScript IsDate() function, allowing times to be validated
				// with JavaScript in browsers before you run into a problem
				// in ASP pages with date database columns or the VBScript
				// CDate() function

				// you obviously want to strip the comments from production scripts
				// and place this function in the library file

				// create a String object
				var theString = new String(stringValue);

				// the string must have either two (hours and minutes) or three
				// (hours, minutes and seconds) tokens, delimited by ":";
				// split the string into an array of tokens
				var theTokens = theString.split(':');
				if ( theTokens.length < 2 || theTokens.length > 3 )
								return false;

				// convert the tokens to String objects, which will be needed later,
				// stripping whitespace
				var firstToken = new String(theTokens[0])
				firstToken = trim(firstToken);
				var middleToken;
				if ( theTokens.length == 3 ) {
								middleToken = new String(theTokens[1])
								middleToken = trim(middleToken);
				}
				var lastToken = new String(theTokens[theTokens.length - 1])
				lastToken = trim(lastToken);

				// the first token (hours) must be an integer between 0 and 23
				if ( ! isInteger(firstToken) )
								return false;
				if ( ! isIntegerInRange(firstToken, 0, 23) )
								return false;

				// are there three tokens?
				if ( theTokens.length == 3 ){

								// the middle token (minutes) must be an integer between 0 and 59
								if ( ! isInteger(middleToken) )
												return false;
								if ( ! isIntegerInRange(middleToken, 0, 59) )
												return false;
				}

				// the first one or two characters of the last token (either minutes
				// and optional am/pm indicator or seconds and am/pm indicator) must
				// be digits
				if ( ! isDigit(lastToken.charAt(0)) )
								return false;

				// the first character is a digit; split the last token into the minutes
				// or seconds value and the indicator; depending on the second character
				var lastValue;
				var ampmIndicator;
				if ( isDigit(lastToken.charAt(1)) ) {
								lastValue = new String(lastToken.substring(0, 2));
								if ( lastToken.length >= 3 )
												ampmIndicator = new String(trim(lastToken.substring(2, lastToken.length)));
								else
												ampmIndicator = new String();
				}
				else {
								lastValue = new String(lastToken.substring(0, 1));
								if ( lastToken.length >= 2 )
												ampmIndicator = new String(trim(lastToken.substring(1, lastToken.length)));
								else
												ampmIndicator = new String();
				}
				ampmIndicator = ampmIndicator.toUpperCase();

				// the last value must be between 0 and 59
				if ( ! isIntegerInRange(lastValue, 0, 59) )
								return false;

				// check the am/pm indicator, if there is one
				if ( ampmIndicator.length > 0 )
								if ( ! ( ampmIndicator == "AM" || ampmIndicator == "PM" ) )
												return false;

				// valid time
				return true;
}

        // most of the following was derived from Netscape's FormChek.js
        // library, which should be reviewed for documentation and comments

        var daysInMonth = makeArray(12);
        daysInMonth[1] = 31;
        daysInMonth[2] = 29;
        daysInMonth[3] = 31;
        daysInMonth[4] = 30;
        daysInMonth[5] = 31;
        daysInMonth[6] = 30;
        daysInMonth[7] = 31;
        daysInMonth[8] = 31;
        daysInMonth[9] = 30;
        daysInMonth[10] = 31;
        daysInMonth[11] = 30;
        daysInMonth[12] = 31;

        var whitespace = " \t\n\r";

        function charInString(c, s) {
                for (i = 0; i < s.length; i++) {
                        if (s.charAt(i) == c)
                                return true;
            }
            return false
        }

        function daysInFebruary(year) {
            return ( ((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
        }

        function isDate(year, month, day) {
            if ( ! ( isYear(year) && isMonth(month) && isDay(day) ) ) return false;
            var intYear = parseInt(year);
            var intMonth = parseInt(month);
            var intDay = parseInt(day);
            if ( intDay > daysInMonth[intMonth] ) return false;
            if ( ( intMonth == 2 ) && ( intDay > daysInFebruary(intYear) ) ) return false;
            return true;
        }

        function isDay(s) {
            return isIntegerInRange(s, 1, 31);
        }

        function isDigit(c) {
                return ( ( c >= "0" ) && ( c <= "9" ) )
        }

        function isInteger(s) {
                var i;
            for ( i = 0; i < s.length; i++ )
            {
                var c = s.charAt(i);
                if ( ! isDigit(c) ) return false;
            }
            return true;
        }

        function isIntegerInRange(s, a, b) {
            if ( ! isInteger(s) ) return false;
            var num = parseInt (s);
            return ( ( num >= a ) && ( num <= b ) );
        }

        function isMonth(s) {
            return isIntegerInRange (s, 1, 12);
        }

        function isNonnegativeInteger(s) {
            return ( isSignedInteger(s) && ( parseInt(s) >= 0 ) );
        }

        function isSignedInteger(s) {
            var startPos = 0;
            if ( ( s.charAt(0) == "-" ) || ( s.charAt(0) == "+" ) )
               startPos = 1;
            return ( isInteger(s.substring(startPos, s.length)) )
        }

        function isYear(s) {
                if ( ! isNonnegativeInteger(s) ) return false;
            return ( (s.length == 2) || (s.length == 4) );
        }


        function makeArray(n) {
           for ( var i = 1; i <= n; i++ ) {
              this[i] = 0
           }
           return this
        }

        function lTrim(s) {
                var i = 0;
            while ( (i < s.length) && charInString(s.charAt(i), whitespace) )
               i++;
            return s.substring(i, s.length);
        }
        
        function rTrim(s) {
                var i = 0;
            while ( (i < s.length) && charInString(s.charAt(i), whitespace) )
               i++;
            return s.substring(i, s.length);
        }

        function trim(s) {
                return lTrim(rTrim(s));
        }




//***********************************
//Comprueba q sea un dia y mes valido
//****************************************

function fec_comprueba_fecha(dia, mes)
{
	var ll_mes;
	var ll_dia;

	ll_mes = parseInt(mes, 10);
	ll_dia = parseInt(dia, 10);

	if (ll_mes > 12)
	{
		return false;
	}
	if ((ll_dia >28) && (ll_mes == 2))
	{
		return false;
	}
	if ((ll_mes == 4) || (ll_mes == 6) || (ll_mes == 9) || (ll_mes == 11))
	{
		if (ll_dia > 30)
		{
			return false;
		}
	}
	else
	{
		if (ll_dia > 31)
		{
			return false;
		}
	}

	return true;
}


/*
//=================================================================
// FUNCIÓN:
//  fecha_sistema
//
// DESCRIPCIÓN:
//  Obtiene la fecha del sistema
//
// ENTRADAS:
//	Objeto del formulario
//
// SALIDAS:
//  Devuelve una cadena string con la fecha
//
// CREADO:
//   20/02/2001  STR. 
//
//=================================================================
*/        

function fecha_sistema(ao_fecha)
{
 var today;
 var ll_dia;
 var ll_mes;
 var ll_agno;
 var ls_fecha_hora;
 var ll_len_agno;
 var ls_ult_dig;	
 var ls_agno;


 today = new Date();
 ll_dia =  today.getDate();
 ll_mes = today.getMonth() + 1;
 ll_agno = today.getYear();
 
 if (ll_dia < 10)
 {
  ls_dia = '0' + ll_dia
 }
 else
 {
  ls_dia = ll_dia
 }
 
 if (ll_mes <10)
 {
  ls_mes = '0' + ll_mes;
 }
 else
 {
  ls_mes = ll_mes;
 }
 
 // Se suma 1900 debido a que en el Explorer (no en el Netscape) 
 // para años < 2001 devuelve la func. GetYear 2 dig
 // El tratamiento en Netscape y Explorer es distinto
 
 //Obtener el último digito del año
 ls_agno = ll_agno.toString(10)
 ll_len_agno = ls_agno.length;
 ls_ult_dig = ls_agno.substr((ll_len_agno - 1),1);
 //Sumar a ese dígito 100
 ll_desp_agno = 100 + parseInt(ls_ult_dig,10)
 //Comparar con el nuevo desplazamiento
 if (ll_agno <= ll_desp_agno )
 {
  ll_agno = ll_agno + 1900
 }
 
 ls_fecha = ls_dia + '/' + ls_mes + '/' + ll_agno
 
 if (document.forms.length > 0)
 {
 	ao_fecha.value=ls_fecha;
 }	
 
}

//=================================================================
// FUNCIÓN:
//   fec_compara_fechas_es_mayor
//
// DESCRIPCIÓN:
//  Nos indica si as_fecha1 es mayor que as_fecha2
//
// ENTRADAS:
//		Cadenas con las fechas que deseamos comparar
//
// SALIDAS:
//		Valor de la comparación
//
// CREADO:
//   12/02/2004		YDS
//
//=================================================================
function fec_compara_fechas_es_mayor(as_fecha1,as_fecha2)
{

	var lb_valor = true;
	var as_anyo1= "";
	var as_anyo2= "";
	var aux1 = "";
	var aux2 = "";
	var as_dia1 = "";
	var as_dia2 = "";
	//Ahora vamos a comprobar que la fecha no es mayor que la fecha del sistema
	if(lb_valor)
	{											
		as_fecha1 = as_fecha1.replace(new RegExp("/","g"),"");
		as_anyo1 = as_fecha1.substring(4,8);		
		aux1 = as_fecha1.substring(2,4);
		as_dia1 = as_fecha1.substring(0,2);

		as_fecha1 = as_anyo1 + aux1 + as_dia1;

		as_fecha2 = as_fecha2.replace(new RegExp("/","g"),"");
		as_anyo2 = as_fecha2.substring(4,8);
		aux2 = as_fecha2.substring(2,4);
		as_dia2 = as_fecha2.substring(0,2);
		as_fecha2 = as_anyo2 + aux2 + as_dia2;

		if(as_fecha2 > as_fecha1)
		{
			lb_valor = false;			
		}

	}
	return lb_valor;
}
