var cal19 = new CalendarPopup();
			cal19.showYearNavigation();
			cal19.showYearNavigationInput();
		
		function popUp(msg)
		{
			var oPopBody = oPopup.document.body;
			oPopBody.style.backgroundColor = "#666666";
			oPopBody.style.font = "14px Tahoma";
			oPopBody.style.border = "solid #000000 2px";
			oPopBody.innerHTML = msg;
			oPopBody.style.margin = "4px";
		// oPopup.show(px right, px down, width, height, document.body);            
		//     oPopup.show(event.clientX + document.body.scrollLeft, event.clientY + document.body.scrollTop, 250, 25, document.body);
			oPopup.show(event.clientX, event.clientY, 180, 180, document.body);
		// oPopup.show(250, 250, 250, 25, document.body);
		}

function dateAdd( start, interval, number ) {
	
    // Create 3 error messages, 1 for each argument. 
    var startMsg = "Sorry the start parameter of the dateAdd function\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( start ) ;
	
    // check that the start parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    return new Date( buffer + number ) ;
}


function dateDiff( start, end, interval, rounding ) 
{

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}

function in_array(vector, valor)
{
	for(i=0; i < vector.length; i++)
	{
		if(vector[i] == valor)
			return true;
	}
	return false;
}

function validarFechas2(fecha1, fecha2, intervaloMin, intervaloMax)
{
	var errores="";
	now = new Date();
	date = new Date();

	now = new Date(now.getYear(),now.getMonth(),now.getDate());


	var vecFeriados	= new Array('2004-01-01', '2004-01-19', '2004-02-16', '2004-05-31', '2004-07-05', '2004-09-06', '2004-10-11', '2004-11-11', '2004-11-25', '2004-12-25', '2005-01-01', '2005-01-17', '2005-02-21', '2005-05-30', '2005-07-04', '2005-09-05', '2005-10-10', '2005-11-11', '2005-11-24', '2005-12-26', '2006-01-02', '2006-01-16', '2006-02-20', '2006-05-29', '2006-07-04', '2006-09-04', '2006-10-09', '2006-11-11', '2006-11-23', '2006-12-25', '2007-01-01', '2007-01-15', '2007-02-19', '2007-05-28', '2007-07-04', '2007-09-03', '2007-10-08', '2007-11-12', '2007-11-27', '2007-12-25', '2008-01-01', '2008-01-21', '2008-02-18', '2008-05-26', '2008-07-04', '2008-09-01', '2008-10-13', '2008-11-11', '2008-11-25', '2008-12-25');

	var vecFecha1 	= fecha1.split('-');
	var oFecha1 	= new Date(vecFecha1[2], vecFecha1[0] - 1, vecFecha1[1]);
	if((oFecha1.getDay() == 0) || (oFecha1.getDay() == 6))
		errores += "First pay day can't fall in a weekend\n";

	var vecFecha2 	= fecha2.split('-');
	var oFecha2 	= new Date(vecFecha2[2], vecFecha2[0] - 1, vecFecha2[1]);


	var difference = (oFecha1 - now)/1000/60/60/24;
	if (difference > intervaloMin)	errores += "Next pay day must be within " + intervaloMin + " days\n";		
	
	
	if(oFecha2.getTime() - oFecha1.getTime() <= 0)
		errores += "Second pay day must be previous to first date\n";		
		
	if((oFecha2.getDay() == 0) || (oFecha2.getDay() == 6))
		errores += "Second pay day can't fall in a weekend\n";

	if(in_array(vecFeriados, vecFecha1[2] + '-' + vecFecha1[0] + '-' + vecFecha1[1]))
		errores += "First pay day chosen falls in a holiday\n";

	if(in_array(vecFeriados, vecFecha2[2] + '-' + vecFecha2[0] + '-' + vecFecha2[1]))
		errores += "Second pay day chosen falls in a holiday\n";

	var fecha1Aux = vecFecha1[0] + '/' + vecFecha1[1] + '/' + vecFecha1[2];
	var fecha2Aux = vecFecha2[0] + '/' + vecFecha2[1] + '/' + vecFecha2[2];
	var diferencia = dateDiff(fecha1Aux, fecha2Aux, 'd');

	var errorIntervalo = false;
	var ultimaFecha			= dateAdd(oFecha1, 'd', parseInt(intervaloMax));
	var ultimaFechaPosible 	= ultimaFecha
	var strUltimaFecha 		= ultimaFechaPosible.getFullYear() + '-' + right('00' + (ultimaFechaPosible.getMonth() + 1), 2) + '-' + right('00' + ultimaFechaPosible.getDate(), 2);
	var str2UltimaFecha 	= right('00' + (ultimaFechaPosible.getMonth() + 1), 2) + '/' + right('00' + ultimaFechaPosible.getDate(), 2) + '/' + ultimaFechaPosible.getFullYear();
	while((ultimaFechaPosible.getDay() == 0) || (ultimaFechaPosible.getDay() == 6) || in_array(vecFeriados, strUltimaFecha))
	{
		ultimaFechaPosible 	= dateAdd(ultimaFechaPosible, 'd', 1);
		strUltimaFecha 	= ultimaFechaPosible.getFullYear() + '-' + right('00' + (ultimaFechaPosible.getMonth() + 1), 2) + '-' + right('00' + ultimaFechaPosible.getDate(), 2);
		str2UltimaFecha = right('00' + (ultimaFechaPosible.getMonth() + 1), 2) + '/' + right('00' + ultimaFechaPosible.getDate(), 2) + '/' + ultimaFechaPosible.getFullYear();
	}

	var ultimaFechaAnt		= dateAdd(oFecha1, 'd', parseInt(intervaloMin));
	var strUltimaFechaAnt 	= ultimaFechaAnt.getFullYear() + '-' + right('00' + (ultimaFechaAnt.getMonth() + 1), 2) + '-' + right('00' + ultimaFechaAnt.getDate(), 2);
	var str2UltimaFechaAnt	= right('00' + (ultimaFechaAnt.getMonth() + 1), 2) + '/' + right('00' + ultimaFechaAnt.getDate(), 2) + '/' + ultimaFechaAnt.getFullYear();
	while((ultimaFechaAnt.getDay() == 0) || (ultimaFechaAnt.getDay() == 6) || in_array(vecFeriados, strUltimaFechaAnt))
	{
		ultimaFechaAnt 		= dateAdd(ultimaFechaAnt, 'd', -1);
		strUltimaFechaAnt 	= ultimaFechaAnt.getFullYear() + '-' + right('00' + (ultimaFechaAnt.getMonth() + 1), 2) + '-' + right('00' + ultimaFechaAnt.getDate(), 2);
		str2UltimaFechaAnt 	= right('00' + (ultimaFechaAnt.getMonth() + 1), 2) + '/' + right('00' + ultimaFechaAnt.getDate(), 2) + '/' + ultimaFechaAnt.getFullYear();
	}

	if( (parseInt(diferencia) < parseInt(intervaloMin)) && (fecha2Aux!=str2UltimaFecha) && (fecha2Aux!=str2UltimaFechaAnt))
	{
		errorIntervalo = true
	}

	if(dateDiff(fecha1Aux, fecha2Aux, 'd', 1) < intervaloMin)
	{
		errorIntervalo = (fecha2Aux!=str2UltimaFecha) && (fecha2Aux!=str2UltimaFechaAnt);
	}
	
	//diferencia = dateDiff(fecha1Aux, str2UltimaFecha, 'd', 1);
	if(dateDiff(fecha1Aux, fecha2Aux, 'd', 1) > intervaloMax)
	{
		errorIntervalo = (fecha2Aux!=str2UltimaFecha) && (fecha2Aux!=str2UltimaFechaAnt);
	}

	//if((parseInt(diferencia) > parseInt(intervaloMax) ) && (fecha2Aux!=str2UltimaFecha) && (fecha2Aux!=str2UltimaFechaAnt))
	//{
	//	errorIntervalo = true
	//}
	
	if(errorIntervalo)
		errores += "Dates chosen don't match the interval selected\n";
	return errores;
}

function calcularEdad(yr, mon, day, unit, decimal, round)
{
	today=new Date()
	var pastdate=new Date(yr, mon-1, day)
	var countunit=unit
	var decimals=decimal
	var rounding=round
	finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
	decimals=(decimals<=0)? 1 : decimals*10
	if (unit!="years")
	{
		if (rounding=="rounddown")
			return Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit;
		else
			return Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit;
	}
	else
	{
		yearspast=today.getFullYear()-yr-1
		tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
		pastdate.setFullYear(today.getFullYear())
		pastdate2=new Date(today.getFullYear()-1, mon-1, day)
		tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
		return yearspast+tail;
	}
}