var step = true;
var nCal = 0;
var milength = 0;
var fixedX = -1;
var fixedY = -1;
var startAt = 0;
var showWeekNumber = 0;
var showToday = 1;		
var imgDropCal,imgDropCalMov,imgCloseCal,imgCloseCalMov,imgLeftCal,imgLeftCalMov,imgRightCal,imgRightCalMov,imgUpCal;
var gotoString = 'Va al mes actual';
var todayString = 'Hoy es ';
var scrollLeftMessage = 'Clic para desplegar el mes anterior.';
var scrollRightMessage = 'Clic para desplegar el mes siguiente.';
var selectMonthMessage = 'Clic para seleccionar un mes.';
var selectYearMessage = 'Clic para seleccionar un a\u00f1o.';
var selectDateMessage = 'Selecciona [date] como fecha.'; // No eliminar [date], se usa para reemplazar la fecha.
var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue,ctlToPlaceValue1,ctlToPlaceValue2, ctlNow, dateFormat, nStartingYear;
var bPageLoaded=false;
var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;
var today = new Date();
var dateNow = today.getDate();
var monthNow = today.getMonth();
var yearNow = today.getYear();
var maxYear, MinYear;
var bShow = false;
var HolidaysCounter = 0;
var Holidays = new Array();
var monthName =	new	Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
var monthName2 = new Array('ENE','FEB','MAR','ABR','MAY','JUN','JUL','AGO','SEP','OCT','NOV','DIC');
var styleAnchor='text-decoration:none; color:black;'; //estilo del dia no seleccionado
var styleLightBorder='border-style:solid; border-width:1px; border-color:#CB3131;'; //estilo del dia seleccionado
imgDropCal='/Content/images/Calendario/DropCal.gif';
imgDropCalMov='/Content/images/Calendario/DropCalMov.gif';
imgCloseCal='/Content/images/Calendario/CloseCal.gif';
imgCloseCalMov='/Content/images/Calendario/CloseCalMov.gif';
imgLeftCal='/Content/images/Calendario/LeftCal.gif';
imgLeftCalMov='/Content/images/Calendario/LeftCalMov.gif';
imgRightCal='/Content/images/Calendario/RightCal.gif';
imgRightCalMov='/Content/images/Calendario/RightCalMov.gif';
imgUpCal='/Content/images/Calendario/UpCal.gif';

if(dom)
{
	//tabla de afuera que encierra todo el calendario
	document.write('<div onclick="bShow=true" id="calendar" style="z-index:+999; position:absolute; visibility:hidden;">');
	document.write('<table width="'+((showWeekNumber==1)?230:215)+'px" style="font-family:Tahoma; font-size:11px; border-width:0px; border-style:solid; border-color:#a0a0a0; font-family:Tahoma; font-size:11px" bgcolor="#ffffff">');
	document.write('<tr bgcolor="#809BB5"><td>');
	document.write('<table width="'+((showWeekNumber==1)?228:213)+'px"><tr><td style="padding:2px; font-family:Tahoma; font-size:11px;"><font color="#ffffff"><B><span id="caption"></span></B></font></td><td align="right"><a href="#" onclick="javascript:hideCalendar()" onmouseover="document.getElementById(\'IMGCLOSECALENDAR\').src=imgCloseCalMov;" onmouseout="document.getElementById(\'IMGCLOSECALENDAR\').src=imgCloseCal;"><IMG id="IMGCLOSECALENDAR" SRC="'+imgCloseCal+'" WIDTH="15" HEIGHT="15" BORDER="0" ALT="Cerrar el Calendario"></a></td></tr></table>');
	document.write('</td></tr>');
	document.write('<tr><td style="padding:5px;" bgcolor="#D5DDE6"><span id="content"></span></td></tr>'); 

	if(showToday==1)
		document.write('<tr bgcolor=#f0f0f0><td style="padding:5px" align=center><span id="lblToday"></span></td></tr>');
	document.write('</table></div><div id="selectMonth" style="z-index:+999; position:absolute; visibility:hidden;"></div><div id="selectYear" style="z-index:+999; position:absolute; visibility:hidden;"></div>');
}

if(startAt==0)
	dayName = new Array	('Dom','Lun','Mar','Mie','Jue','Vie','Sab');
else
	dayName = new Array	('Lun','Mar','Mie','Jue','Vie','Sab','Dom');

init();

if(ie)
	document.attachEvent('onclick', hideCalendarDoc);
else
	document.addEventListener('click', hideCalendarDoc,false);

function hideCalendarDoc()
{
	if(!bShow)
		hideCalendar();
	bShow = false;
}
function esNumero(e)
{
	if((ie && e.keyCode == 8)||(!ie && (e.which == 8||e.which==0)))
		return true;
	else
		return /\d/.test(String.fromCharCode(ie?e.keyCode:e.which));
}
function validarDia(e,objFecha,txtDia,txtMes,txtAnyo)
{
	if(parseInt(txtDia.value,10)>31)
		txtDia.value='';
	if(txtDia.value.length == 2)
	{
		validarFecha(objFecha,txtDia,txtMes,txtAnyo); 
		if(txtDia.value.length == 2 && step)
		{
			step=false;
			milength=1;
			if((ie && e.keyCode != 37 && e.keyCode != 8)||(!ie && e.which != 37 && e.which != 8))
				txtMes.focus();
		}
	}
	else
		objFecha.value='';
	step=true;
}
function pinte(obj)
{
	if(ie)
	{
		var txtsel = obj.createTextRange();
		txtsel.select();
	}
	else
		obj.setSelectionRange(0,obj.value.length);
}
function validarMes(e,objFecha,txtDia,txtMes,txtAnyo)
{
	step=false;
	milength++;
	if(milength>2)
		step=true;
	if(parseInt(txtMes.value,10)>12)
		txtMes.value='';
	if(txtMes.value.length == 2)
	{
		validarFecha(objFecha,txtDia,txtMes,txtAnyo);
		if(txtMes.value.length == 2 && step)
			if((ie && e.keyCode != 37 && e.keyCode != 8)||(!ie && e.which != 37 && e.which != 8))
				txtAnyo.focus();
	}
	else if(txtMes.value.length == 1) 
	{ 
		if(parseInt(txtMes.value,10)>1)
		{
			txtMes.value= '0' + txtMes.value; 
			validarFecha(objFecha,txtDia,txtMes,txtAnyo); 
			if((ie && e.keyCode != 37 && e.keyCode != 8)||(!ie && e.which != 37 && e.which != 8))
				txtAnyo.focus();
		}
	}
	else
		objFecha.value='';
	step=true;
}
function validarAnio(e,objFecha,txtDia,txtMes,txtAnyo)
{
	objFecha.value='';
	switch(txtAnyo.value.length)
	{
		case 1:
			if(txtAnyo.value == 0)
				txtAnyo.value = '';
			break;
		case 2:
			if(txtAnyo.value < 19)
				txtAnyo.value = '';
			break;
		case 4:
			if(txtAnyo.value < 1900)
				txtAnyo.value = '';
			else
				validarFecha(objFecha,txtDia,txtMes,txtAnyo);
			break;
	}
}
function validarFecha(objFecha,txtDia,txtMes,txtAnyo)
{
	validarCamposCompletos(txtDia,txtMes,txtAnyo);

	var dia = parseInt(txtDia.value,10);
	var mes = parseInt(txtMes.value,10);
	var anyo = parseInt(txtAnyo.value,10);
	
	if(txtMes.value.length>0 && txtDia.value.length>0)
		if(mes==2 && dia > 28)
			txtDia.value =28;
		if((mes==4||mes==6||mes==9||mes==11) && dia > 30)
			txtDia.value =30;
	if(txtMes.value.length > 0 && txtDia.value.length > 0 && txtAnyo.value.length == 4)
	{
		if(mes==2)
		{
			if((anyo % 4 == 0) && (anyo % 100 != 0) || (anyo % 400 == 0))
				if(dia > 29)
					txtDia.value=29;
			else if(dia > 28)
					txtDia.value=28;
		}
		objFecha.value = txtDia.value.toString() + '/' + txtMes.value.toString() + '/' + txtAnyo.value.toString();
	}
	else
		objFecha.value = '';
}
function validarCamposCompletos(txtDia,txtMes,txtAnyo)
{
	if(parseInt(txtDia.value,10)==0)
		txtDia.value ='';
	if(parseInt(txtMes.value,10)==0)
		txtMes.value ='';
	if(parseInt(txtAnyo.value,10)==0)
		txtAnyo.value ='';
}
function hideElement( elmID, overDiv )
{
	if( ie )
	{
		for( i = 0; i < document.all.tags( elmID ).length; i++ )
		{
			obj = document.all.tags( elmID )[i];
			if( !obj || !obj.offsetParent )
				continue;
			// Find the element's offsetTop and offsetLeft relative to the BODY tag.
			objLeft = obj.offsetLeft;
			objTop = obj.offsetTop;
			objParent = obj.offsetParent;

			while( objParent.offsetParent!=null&&objParent.tagName.toUpperCase() != 'BODY' )
			{
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}

			objHeight = obj.offsetHeight;
			objWidth = obj.offsetWidth;

			if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft );
			else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
			else if( overDiv.offsetTop >= ( objTop + objHeight ));
			else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
			else
				obj.style.visibility = 'hidden';
		}
	}
}
function showElement(elmID)
{
	if(ie)
	{
		for( i = 0; i < document.all.tags( elmID ).length; i++ )
		{
			obj = document.all.tags( elmID )[i];
			if( !obj || !obj.offsetParent )
				continue;
			obj.style.visibility = '';
		}
	}
}
function HolidayRec (d, m, y, desc)
{
	this.d = d;
	this.m = m;
	this.y = y;
	this.desc = desc;
}
function init()
{
	if(!ns4)
	{
		if(!ie&&!window.opera)
			yearNow += 1900;

		crossobj=(dom)?document.getElementById('calendar').style : ie? document.all.calendar : document.calendar;
		hideCalendar();
		crossMonthObj=(dom)?document.getElementById('selectMonth').style : ie? document.all.selectMonth	: document.selectMonth;
		crossYearObj=(dom)?document.getElementById('selectYear').style : ie? document.all.selectYear : document.selectYear;
		monthConstructed=false;
		yearConstructed=false;

		if(showToday==1)
			document.getElementById('lblToday').innerHTML =	todayString + '<a onmousemove="javascript:window.status=\''+gotoString+'\'" onmouseout="javascript:window.status=\'\'" title="'+gotoString+'" style="'+styleAnchor+'" href="#" onclick="javascript:monthSelected=monthNow; yearSelected=yearNow; constructCalendar();">'+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+', ' + dateNow + ' ' + monthName[monthNow].substring(0,3)+ '	' +	yearNow	+ '</a>';

		sHTML1 ='<span id="spanLeft"  style="border-style:solid; border-width:1px; border-color:#3366FF; cursor:pointer;" onmouseover="javascript: document.getElementById(\'changeLeft\').src=imgLeftCalMov;   this.style.borderColor=\'#88AAFF\'; window.status=\''+scrollLeftMessage+'\'"  onclick="javascript:decMonth();" onmouseout="javascript:clearInterval(intervalID1); document.getElementById(\'changeLeft\').src=imgLeftCal; this.style.borderColor=\'#3366FF\'; window.status=\'\'" onmousedown="javascript:clearTimeout(timeoutID1); timeoutID1=setTimeout(\'StartDecMonth()\',500)" onmouseup="javascript:clearTimeout(timeoutID1); clearInterval(intervalID1)">&nbsp<IMG id="changeLeft" SRC="'+imgLeftCal+'" width="10" height="11" BORDER="0">&nbsp</span>&nbsp;';
		sHTML1+='<span id="spanRight" style="border-style:solid; border-width:1px; border-color:#3366FF; cursor:pointer;" onmouseover="javascript: document.getElementById(\'changeRight\').src=imgRightCalMov; this.style.borderColor=\'#88AAFF\'; window.status=\''+scrollRightMessage+'\'" onmouseout="javascript:clearInterval(intervalID1); document.getElementById(\'changeRight\').src=imgRightCal; this.style.borderColor=\'#3366FF\'; window.status=\'\'" onclick="javascript:incMonth();" onmousedown="javascript:clearTimeout(timeoutID1); timeoutID1=setTimeout(\'StartIncMonth()\',500)" onmouseup="javascript:clearTimeout(timeoutID1); clearInterval(intervalID1)">&nbsp<IMG id="changeRight" SRC="'+imgRightCal+'"	width="10" height="11" BORDER="0">&nbsp</span>&nbsp';
		sHTML1+='<span id="spanMonth" style="border-style:solid; border-width:1px; border-color:#3366FF; cursor:pointer;"	onmouseover="javascript: document.getElementById(\'changeMonth\').src=imgDropCalMov;  this.style.borderColor=\'#88AAFF\'; window.status=\''+selectMonthMessage+'\'" onmouseout="javascript: document.getElementById(\'changeMonth\').src=imgDropCal; this.style.borderColor=\'#3366FF\'; window.status=\'\'" onclick="javascript:popUpMonth();"></span>&nbsp;';
		sHTML1+='<span id="spanYear"  style="border-style:solid; border-width:1px; border-color:#3366FF; cursor:pointer;" onmouseover="javascript: document.getElementById(\'changeYear\').src=imgDropCalMov; this.style.borderColor=\'#88AAFF\'; window.status=\''+selectYearMessage+'\'" onmouseout="javascript: document.getElementById(\'changeYear\').src=imgDropCal;  this.style.borderColor=\'#3366FF\'; window.status=\'\'" onclick="javascript:popUpYear();"></span>&nbsp;';
		document.getElementById('caption').innerHTML  =	sHTML1;
		bPageLoaded=true;
	}
}
function hideCalendar()
{
	crossobj.visibility='hidden';
	if(crossMonthObj != null)
		crossMonthObj.visibility='hidden';
	if(crossYearObj !=	null)
		crossYearObj.visibility='hidden';
	showElement('SELECT');
	showElement('APPLET');
}
function padZero(num)
{
	return (num < 10)? '0' + num : num ;
}
function constructDate(d,m,y)
{
	var sTmp;		
	sTmp = dateFormat;
	sTmp = sTmp.replace('dd','<e>');
	sTmp = sTmp.replace('d','<d>');
	sTmp = sTmp.replace('<e>',padZero(d));
	sTmp = sTmp.replace	('<d>',d);
	sTmp = sTmp.replace	('mmmm','<p>');
	sTmp = sTmp.replace	('mmm','<o>');
	sTmp = sTmp.replace	('mm','<n>');
	sTmp = sTmp.replace	('m','<m>');
	sTmp = sTmp.replace	('<m>',m+1);
	sTmp = sTmp.replace	('<n>',padZero(m+1));
	sTmp = sTmp.replace	('<o>',monthName[m]);
	sTmp = sTmp.replace	('<p>',monthName2[m]);
	sTmp = sTmp.replace	('yyyy',y);
	return sTmp.replace ('yy',padZero(y%100));
}
function closeCalendar()
{
	var dia,mes;
	monthSelected++;
	dia=dateSelected.toString();
	if(dia.length == 1)
		dia = '0' + dia;
	mes=monthSelected.toString();
	if(mes.length == 1)
		mes = '0' + mes;
	hideCalendar();
	ctlToPlaceValue.value = dia;
	ctlToPlaceValue1.value = mes;
	ctlToPlaceValue2.value = yearSelected;
	document.getElementById(ctlToPlaceValue.id.replace('_Dia','')).value = ctlToPlaceValue.value.toString() + '/' + ctlToPlaceValue1.value.toString() + '/' + ctlToPlaceValue2.value.toString();
}
function StartDecMonth()
{
	intervalID1=setInterval('decMonth()',80);
}
function StartIncMonth()
{
}
function incMonth () 
{ 
	if( !(monthSelected == 11 && yearSelected == maxYear) )
	{ 
		monthSelected++;
		if(monthSelected>11)
		{
			monthSelected=0;
			yearSelected++;
		}
		constructCalendar();
	}
}
function decMonth()
{
	if(!(monthSelected == 0 && yearSelected == minYear))
	{  
		monthSelected--;
		if(monthSelected<0)
		{
			monthSelected=11;
			yearSelected--;
		}
		constructCalendar();
	}
}
function constructMonth()
{
	popDownYear();
	if(!monthConstructed)
	{
		sHTML =	'';
		for(i=0; i<12;	i++) 
		{
			sName =	monthName[i];
			if(i==monthSelected)
				sName =	'<B>' +	sName +	'</B>';
			
			sHTML += '<tr><td id="m' + i + '" onmouseover="javascript:this.style.backgroundColor=\'#FFCC99\'" onmouseout="javascript:this.style.backgroundColor=\'\'" style="cursor:pointer;" onclick="javascript:monthConstructed=false; monthSelected=' + i + '; constructCalendar(); popDownMonth(); event.cancelBubble=true">&nbsp;' + sName + '&nbsp;</td></tr>';
		}
		document.getElementById('selectMonth').innerHTML = '<table width="70" style="font-family:Tahoma; font-size:11px; border-width:1px; border-style:solid; border-color:#a0a0a0;" bgcolor="#FFFFDD" cellspacing="0" onmouseover="javascript:clearTimeout(timeoutID1);" onmouseout="javascript:clearTimeout(timeoutID1); timeoutID1=setTimeout(\'popDownMonth()\',100); event.cancelBubble=true;">' + sHTML + '</table>';
		monthConstructed=true;
	}
}
function popUpMonth()
{
	constructMonth();
	crossMonthObj.visibility = (dom||ie)? 'visible'	: 'show';
	crossMonthObj.left = parseInt(crossobj.left) + 50 + 'px';
	crossMonthObj.top = parseInt(crossobj.top) + 26 + 'px';
	hideElement( 'SELECT', document.getElementById('selectMonth') );
	hideElement( 'APPLET', document.getElementById('selectMonth') );			
}
function popDownMonth()
{
	crossMonthObj.visibility= 'hidden';
}
function incYear()
{
	if(nStartingYear + 7 <= maxYear) 
	{ //agregado para el anyo maximo y minimo
		for(i=0; i<7; i++)
		{
			newYear	= (i+nStartingYear)+1;
			if(newYear==yearSelected)
				txtYear = '&nbsp;<B>' + newYear + '</B>&nbsp;';
			else
				txtYear ='&nbsp;' + newYear + '&nbsp;';
			document.getElementById('y'+i).innerHTML = txtYear;
		}
		nStartingYear ++;
	}
	bShow=true;
}
function decYear()
{
	if(nStartingYear - 1 >= minYear)
	{
		for(i=0; i<7; i++)
		{
			newYear	= (i+nStartingYear)-1;
			if(newYear==yearSelected)
				txtYear = '&nbsp;<B>'+ newYear + '</B>&nbsp;';
			else
				txtYear ='&nbsp;' + newYear + '&nbsp;';
			document.getElementById('y'+i).innerHTML = txtYear;
		}
		nStartingYear --;
	}
	bShow=true;
}
function selectYear(nYear)
{
	yearSelected=parseInt(nYear+nStartingYear);
	yearConstructed=false;
	constructCalendar();
	popDownYear();
}
function constructYear()
{
	popDownMonth();
	sHTML =	'';
	if(!yearConstructed) 
	{
		sHTML =	'<tr><td align="center" onmouseover="javascript:this.style.backgroundColor=\'#FFCC99\'" onmouseout="javascript:clearInterval(intervalID1); this.style.backgroundColor=\'\'" style="cursor:pointer;" onmousedown="javascript:clearInterval(intervalID1); intervalID1=setInterval(\'decYear()\',30)" onmouseup="javascript:clearInterval(intervalID1)"><IMG id="aumMes" SRC="'+imgUpCal+'" WIDTH="12" HEIGHT="10" BORDER="0"></td></tr>';
		j =	0;
		nStartingYear =	yearSelected-3;
		if(nStartingYear < minYear)
			nStartingYear = minYear;  //agregado para el anyo maximo y minimo		
		if(nStartingYear+6 > maxYear)
			nStartingYear = maxYear-6;  //agregado para el anyo maximo y minimo		
		
		for(i=(nStartingYear); i<=(nStartingYear+6); i++)
		{  //modificado para el anyo maximo y minimo
			sName =	i;
			if(i==yearSelected)
				sName =	'<B>' +	sName +	'</B>';
			sHTML += '<tr><td id="y' + j + '" onmouseover="javascript:this.style.backgroundColor=\'#FFCC99\'" onmouseout="javascript:this.style.backgroundColor=\'\'" style="cursor:pointer;" onclick="javascript:selectYear('+j+'); event.cancelBubble=true;">&nbsp;' + sName + '&nbsp;</td></tr>';
			j ++;
		}
		
		sHTML += '<tr><td align="center" onmouseover="javascript:this.style.backgroundColor=\'#FFCC99\'" onmouseout="javascript:clearInterval(intervalID2); this.style.backgroundColor=\'\'" style="cursor:pointer;" onmousedown="javascript:clearInterval(intervalID2); intervalID2=setInterval(\'incYear()\',30)"	onmouseup="javascript:clearInterval(intervalID2)"><IMG id="aumMes" SRC="'+imgDropCal+'" WIDTH="12" HEIGHT="10" BORDER="0"></td></tr>';
		document.getElementById('selectYear').innerHTML	= '<table width="44" style="font-family:Tahoma; font-size:11px; border-width:1px; border-style:solid; border-color:#a0a0a0;" bgcolor="#FFFFDD" onmouseover="javascript:clearTimeout(timeoutID2);" onmouseout="javascript:clearTimeout(timeoutID2); timeoutID2=setTimeout(\'popDownYear()\',100);" cellspacing="0">'+ sHTML + '</table>';
		yearConstructed	= true;
	}
}
function popDownYear()
{
	clearInterval(intervalID1);
	clearTimeout(timeoutID1);
	clearInterval(intervalID2);
	clearTimeout(timeoutID2);
	crossYearObj.visibility= 'hidden';
}
function popUpYear()
{
	var leftOffset;
	constructYear();
	crossYearObj.visibility = (dom||ie)? 'visible' : 'show';
	leftOffset = parseInt(crossobj.left) + document.getElementById('spanYear').offsetLeft;
	if(ie)
		leftOffset += 6;
	crossYearObj.left = leftOffset + 'px';
	crossYearObj.top = parseInt(crossobj.top) + 26 + 'px';
}
function constructCalendar()
{
	var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);
	var dateMessage;
	var startDate = new Date (yearSelected,monthSelected,1);
	var endDate;
	if(monthSelected==1)
	{
		endDate	= new Date (yearSelected,monthSelected+1,1);
		endDate	= new Date (endDate	- (24*60*60*1000));
		numDaysInMonth = endDate.getDate();
	}
	else
		numDaysInMonth = aNumDays[monthSelected];

	datePointer	= 0;
	dayPointer = startDate.getDay() - startAt;

	if(dayPointer<0)
		dayPointer = 6;
	sHTML =	'<table border="0" style="font-family:Tahoma; font-size:11px;"><tr>';

	for(i=0; i<7; i++)	
		sHTML += '<td width="24" align="right"><B>'+ dayName[i]+'</B></td>';

	sHTML +='</tr><tr>';

	for(var i=1; i<=dayPointer;i++ )
		sHTML += '<td>&nbsp;</td>';
		
	for( datePointer=1; datePointer<=numDaysInMonth; datePointer++)
	{
		dayPointer++;
		sHTML += '<td align="right">';
		sStyle=styleAnchor;
		if((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
			sStyle+=styleLightBorder;
		sHint = '';

		for(k=0;k<HolidaysCounter;k++)
		{
			if((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
			{
				if((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
				{
					sStyle+='background-color:#FFDDDD;';
					sHint+=sHint==''?Holidays[k].desc:'\n'+Holidays[k].desc;
				}
			}
		}

		var regexp= /\'/g;
		sHint=sHint.replace(regexp,'&quot;');
		dateMessage = 'onmousemove="javascript:window.status=\''+selectDateMessage.replace('[date]',constructDate(datePointer,monthSelected,yearSelected))+'\'" onmouseout="javascript:window.status=\'\'" ';
		
		if((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
			sHTML += '<b><a '+dateMessage+' title="' + sHint + '" style="'+sStyle+'" href="#" onclick="javascript:dateSelected='+datePointer+'; closeCalendar();"><font color="#CB3131">&nbsp;' + datePointer + '</font>&nbsp;</a></b>';
		else if(dayPointer % 7 == (startAt * -1)+1)
			sHTML += '<a '+dateMessage+' title="' + sHint + '" style="'+sStyle+'" href="#" onclick="javascript:dateSelected='+datePointer + '; closeCalendar();">&nbsp;<font color="#738FAC">' + datePointer + '</font>&nbsp;</a>';
		else 
			sHTML += '<a '+dateMessage+' title="' + sHint + '" style="'+sStyle+'" href="#" onclick="javascript:dateSelected='+datePointer + '; closeCalendar();">&nbsp;' + datePointer + '&nbsp;</a>';
		
		sHTML += '';
		
		if((dayPointer+startAt) % 7 == startAt)
			sHTML += '</tr><tr>';
		
	}

	document.getElementById('content').innerHTML = sHTML;
	document.getElementById('spanMonth').innerHTML = '&nbsp;' +	monthName[monthSelected] + '&nbsp;<IMG id="changeMonth" SRC="'+imgDropCal+'" WIDTH="12" HEIGHT="10" BORDER="0">';
	document.getElementById('spanYear').innerHTML =	'&nbsp;' + yearSelected	+ '&nbsp;<IMG id="changeYear" SRC="'+imgDropCal+'" WIDTH="12" HEIGHT="10" BORDER="0">';
}
function popUpCalendar(ctl,txtDia,txtMes,txtAnyo,format,MinAnio,maxAnio)
{
	var leftpos=0;
	var toppos=0;
	maxYear=maxAnio;
	minYear=MinAnio;
	if(bPageLoaded)
	{
		if(crossobj.visibility == 'hidden' )
		{
			ctlToPlaceValue = txtDia;
			ctlToPlaceValue1 = txtMes;
			ctlToPlaceValue2 = txtAnyo;
			dateFormat = format;
			formatChar = ' ';
			aFormat = dateFormat.split(formatChar);
			if(aFormat.length<3)
			{
				formatChar = '/';
				aFormat = dateFormat.split(formatChar);
				if(aFormat.length<3)
				{
					formatChar = '.';
					aFormat = dateFormat.split(formatChar);
					if(aFormat.length<3)
					{
						formatChar = '-';
						aFormat = dateFormat.split(formatChar);
						if(aFormat.length<3)
							formatChar='';
					}
				}
			}
			tokensChanged = 0;
			if(formatChar != '')
			{
				var fecha_temp = txtDia.value + '/' + txtMes.value + '/' + txtAnyo.value;
				aData = fecha_temp.split(formatChar);

				for(i=0;i<3;i++)
				{
					if((aFormat[i]=='d') || (aFormat[i]=='dd'))
					{
						dateSelected = parseInt(aData[i], 10);
						tokensChanged ++;
					}
					else if((aFormat[i]=='m') || (aFormat[i]=='mm'))
					{
						monthSelected =	parseInt(aData[i], 10) - 1;
						tokensChanged ++;
					}
					else if(aFormat[i]=='yyyy')
					{
						yearSelected = parseInt(aData[i], 10);
						tokensChanged ++;
					}
					else if(aFormat[i]=='mmm')
					{
						for(j=0; j<12;	j++)
						{
							if(aData[i]==monthName[j])
							{
								monthSelected=j;
								tokensChanged ++;
							}
						}
					}
					else if(aFormat[i]=='mmmm')
					{
						for(j=0; j<12;	j++)
							if(aData[i]==monthName2[j])
							{
								monthSelected=j;
								tokensChanged ++;
							}
					}
				}
			}
			if((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
			{
				dateSelected = dateNow;
				monthSelected = monthNow;
				yearSelected = yearNow;
			}
			odateSelected=dateSelected;
			omonthSelected=monthSelected;
			oyearSelected=yearSelected;
			aTag = ctl;
			do
			{
				aTag = aTag.offsetParent;
				leftpos	+= aTag.offsetLeft;
				toppos += aTag.offsetTop;
			} while(aTag.offsetParent!=null&&aTag.tagName!='BODY');

			crossobj.left = (fixedX==-1 ? ctl.offsetLeft + leftpos - 75 : fixedX)+ 'px' ;
			if( crossobj.left.toString().replace('px','') > (window.document.body.offsetWidth - 206) )
				crossobj.left = window.document.body.offsetWidth - 206 ;
			//crossobj.top = fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 0 : fixedY; //el 0 es el offset con el boton 
			//Modificar acá el problema del desbordamiento del calendario.
			crossobj.top = ctl.offsetTop + toppos + ctl.offsetHeight + 0 + 'px';
			constructCalendar (1, monthSelected, yearSelected);
			crossobj.visibility=(dom||ie)? 'visible' : 'show';
			hideElement( 'SELECT', document.getElementById('calendar') );
			hideElement( 'APPLET', document.getElementById('calendar') );
			bShow = true;
		}
		else
		{
			hideCalendar();
			if(ctlNow!=ctl)
				popUpCalendar(ctl,txtDia,txtMes,txtAnyo,format,MinAnio,maxAnio);
		}
		ctlNow = ctl;
	}
}