


	var date 	= new Date();
	var month1 	= date.getMonth();
	var year1 	= date.getFullYear();
	var textBox = "";

	var currObj	= 0;

	var obj 	= new Object();

	function Week()
	{
		this.days = new Array(7);

		this.setValue=function(day, value)
		{
			this.days[day] = new String();
			this.days[day] = value;
		};
		this.getValue=function(day)
		{
			return this.days[day];
		};
	}

	function Month(mmm, yyy)
	{
		this._year  		= yyy;
		this._month 		= mmm;

		this.setValue = function(week, day, value)
		{
			this.weeks[week].setValue(day,value);
		};

		this.getValue = function(week, day)
		{
			return this.weeks[week].getValue(day);
		};

		this.getDays = function(month,year)
		{
			this.months = new Array(31,this.isLeapYear(year),31,30,31,30,31,31,30,31,30,31);
			return this.months[month];
		};

		this.isLeapYear = function(year)
		{
			if(((year%4)===0)&&((year%100)!==0)||((year%400)===0)){
				return 29;}
			else{
				return 28;}
		};

		this.construct=function()
		{
			this._names 		= new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
			this._date   		= new Date(this._year, this._month, 1);
			this._name			= this._names[this._month];
			this._days			= this.getDays(this._month, this._year);
			this._dayOfWeek		= this._date.getDay();
			this.weeks 			= new Array(6);
			this.dayCount 		= 0;
			this.week			= 0;

			for(this.week=0; this.week < 6; this.week+=1)
			{
				this.weeks[this.week] = new Week();

				this.day =0;

				for(this.day=0;this.day<7;this.day+=1)
				{

					if(this.week == 0 && this.day < this._dayOfWeek)
					{
						this.setValue(this.week, this.day, null);
					}
					else if(this.dayCount == this._days)
					{
						this.setValue(this.week,this.day, null );
					}
					else
					{
						this.dayCount +=1;
						this.setValue(this.week,this.day, this.dayCount + '');
					}
				}
			}
		};

		this.construct();
	}

	//// ESTA FUNCION LA UTILIZA SETVALUE
	function getMonthName(myMonth)
	{
		var mm = 'Undefined';

		switch(myMonth)
		{
		    case 1 : mm = 'Enero';	break;
		    case 2 : mm = 'Febrero';	break;
		    case 3 : mm = 'Marzo';		break;
		    case 4 : mm = 'Abril';		break;
		    case 5 : mm = 'Mayo';		break;
		    case 6 : mm = 'Junio';		break;
		    case 7 : mm = 'Julio';		break;
		    case 8 : mm = 'Agosto';	break;
		    case 9 : mm = 'Septiembre';	break;
		    case 10: mm = 'Octubre';	break;
		    case 11: mm = 'Noviembre';	break;
		    case 12: mm = 'Diciembre';	break;
		}
		return mm;
	}

	//// ESTA FUNCION LA UTILIZA BUILDCALENDAR
	function setValue(d, m, y)
	{
		obj = document.getElementById(this.textBox);
		if(d<10)
			d='0'+d;
		if(m<10)
			m='0'+m;
		obj.value = d + '/' + m + '/' + y;
		hideshow('','calendar');
	}

	//// ESTA FUNCION LA UTILIZA BUILDCALENDAR
	function clearTable(obj)
	{
		var week=0,day=0;

		var table = document.getElementById('month');

		for(week=0;week<6;week+=1)
		{
			for(day=0;day<7;day+=1)
			{
				var cell = table.rows[week+1].cells[day];
				var len  = cell.childNodes.length;

				if(cell.hasChildNodes())
				{
					for(var i=len-1;i>=0;i-=1){
						cell.removeChild(cell.childNodes[i]);}
				}

				cell.appendChild(document.createTextNode(' '));
			}
		}
	}

	function buildCalendar(monthInstance, obj)
	{
		var today = new Date();
		clearTable(obj);

		this.dayOfWeek = 0;

		var week=0, day=0;

		var table = document.getElementById('month');

		for(week=0; week<6; week++)
		{

			for(this.dayOfWeek=0;this.dayOfWeek<7;this.dayOfWeek++)
			{
				day	= monthInstance.getValue(week, this.dayOfWeek);
				var cell = table.rows[week+1].cells[this.dayOfWeek];

				//En este caso no se debe de poner un link sino un espacio en blanco
				if(day === null)
				{
					cell.replaceChild(document.createTextNode(' '),cell.childNodes[0]);
				}
				else
				{
					if(monthInstance._year == today.getFullYear())
					{
						if(monthInstance._month > today.getMonth())
						{
							if (browser.isNS)
							{
								var url  	= 'javascript: setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ');';
								var link 	= document.createElement('A');
								link.setAttribute("href", url);
								link.appendChild(document.createTextNode('' + day));
								cell.replaceChild(link,cell.childNodes[0]);
							}
							else
							{
								var url  	= 'javascript:setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ')';
								var link 	= document.createElement('A');
								link.attributes.getNamedItem('href').value = url;
								link.appendChild(document.createTextNode('' + day));
								cell.replaceChild(link,cell.childNodes[0]);
							}
						}
						else if(monthInstance._month == today.getMonth())
						{
							if(day >= today.getDate())
							{
								if (browser.isNS)
								{
									var url  	= 'javascript: setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ');';
									var link 	= document.createElement('A');
									link.setAttribute("href", url);
									link.appendChild(document.createTextNode('' + day));
									cell.replaceChild(link,cell.childNodes[0]);
								}
								else
								{
									var url  	= 'javascript:setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ')';
									var link 	= document.createElement('A');
									link.attributes.getNamedItem('href').value = url;
									link.appendChild(document.createTextNode('' + day));
									cell.replaceChild(link,cell.childNodes[0]);
								}
							}
							else
							{
								cell.replaceChild(document.createTextNode('' + day),cell.childNodes[0]);
							}

						}
						else
						{
							cell.replaceChild(document.createTextNode('' + day),cell.childNodes[0]);
						}
					}
					else if(monthInstance._year > today.getYear())
					{
						if (browser.isNS)
						{
							var url  	= 'javascript: setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ');';
							var link 	= document.createElement('A');
							link.setAttribute("href", url);
							link.appendChild(document.createTextNode('' + day));
							cell.replaceChild(link,cell.childNodes[0]);
						}
						else
						{
							var url  	= 'javascript:setValue(' + day + ',' + (monthInstance._month + 1) + ',' + monthInstance._year + ')';
							var link 	= document.createElement('A');
							link.attributes.getNamedItem('href').value = url;
							link.appendChild(document.createTextNode('' + day));
							cell.replaceChild(link,cell.childNodes[0]);
						}
					}
					else
					{
						cell.replaceChild(document.createTextNode('' + day),cell.childNodes[0]);
					}
				}
			}
		}
		document.getElementById('monthName').firstChild.nodeValue	= monthInstance._year + " " + monthInstance._name; 
	}


	//// ESTA FUNCION SE UTILIZA EN EL HTML POR LA FUNCI?N inicia
	function currMonth(id, textBox)
	{
		this.textBox = textBox;
		if (id)
		{
			obj.elNode = document.getElementById(id);
		}
		else
		{
			if (browser.isIE)
				obj.elNode = window.event.srcElement;
			if (browser.isNS)
				obj.elNode = event.target;

			// If this is a text node, use its parent element.
			if (obj.elNode.nodeType == 3)
				obj.elNode = dragObj.elNode.parentNode;
		}
		var selDate = document.getElementById(textBox);
		var value = selDate.value;
		if(value != null && value.length>0 && value.indexOf("/")>0)
		{
			var today = new Date();
			var array = value.split("/");
			this.month1 = new Number(array[1])-1;
			if(isNaN(this.month1))
			{
					this.month1 = today.getMonth();
			}
			array = value.split("/");
			this.year1 = new Number(array[2]);
			if(isNaN(this.year1))
			{
				this.year1 = today.getYear();
				this.month1 = today.getMonth();
			}
		}
		buildCalendar(new Month(month1,year1), obj);
	}

	//// ESTA FUNCION LA UTILIZAN ROLLBACK Y ROLLNEXT
	function update(n, fecha)
	{
		if(n === 1)
		{
			month1	= fecha._month;
			year1	= fecha._year;
		}
		if(n === 2)
		{
			month2	= fecha._month;
			year2	= fecha._year;
		}
	}

	//// ESTA FUNCION LA UTILIZAN ROLLBACK Y ROLLNEXT
	function rollMonth(n, fecha)
	{
		var month 	= fecha._month;
		var year 	= fecha._year;

		month += n;

		if(month == -1)
		{
			month = 11; year-=1;
		}
		else if(month == 12)
		{
			month = 0;  year+=1;
		}
		else
		{}

		return new Month(month,year);
	}

	function rollYear(n, fecha)
	{
		var month 	= fecha._month;
		var year 	= new Number(fecha._year);

		if(n == -1)
		{
			year-=1;
		}
		else if(n == +1)
		{
			year+=1;
		}
		else
		{}

		return new Month(month,year);
	}


	//// ESTA FUNCION SE UTILIZA DESDE EL HTML PARA CAMBIAR DE MES HACIA ATRAS
	function rollBackMonth()
	{
			var fecha;

			fecha = rollMonth(-1, new Month(month1, new Number(year1)));
			update(1, fecha);
			buildCalendar(fecha, 1, currObj);
	}

	//// ESTA FUNCION SE UTILIZA DESDE EL HTML PARA CAMBIAR DE MES HACIA ADELANTE
	function rollNextMonth()
	{
			var fecha;

			fecha = rollMonth(+1, new Month(month1, new Number(year1)));
			update(1, fecha);
			buildCalendar(fecha, 1, currObj);
	}

	function rollBackYear()
	{
			var fecha;

			fecha = rollYear(-1, new Month(month1, new Number(year1)));
			update(1, fecha);
			buildCalendar(fecha, 1, currObj);
	}

	function rollNextYear()
	{
			var fecha;

			fecha = rollYear(+1, new Month(month1, new Number(year1)));
			update(1, fecha);
			buildCalendar(fecha, 1, currObj);
	}