function FechaCalendar(){	
	this.fechaCalendarioYear = document.getElementById('fechaCalendarioYear');
	this.fechaCalendarioMes = document.getElementById('fechaCalendarioMes');
	this.fechaCalendarioDia = document.getElementById('fechaCalendarioDia');
	this.fechaCalendarioSelectYear;
	
		this.fechaYearMarcar = 0;	
		this.fechaMesMarcar = 0;	
		this.fechaDiaMarcar = 0;
	
	//this.createCalendarioDia();	
}

/*
SELECT Mes 
*/
FechaCalendar.prototype.setEventoCalendario=function() {	
	this.fechaCalendarioMes.onchange = function(){
		var objFechaCalendar = new FechaCalendar();
		objFechaCalendar.crearCalendario();	
	};
	this.fechaCalendarioYear.onchange = function(){
		var objFechaCalendar = new FechaCalendar();
		objFechaCalendar.crearCalendario();	
	};
}

FechaCalendar.prototype.createCalendario=function() {
	var fecha = new Fecha(document.getElementById('fechaCalendarioYear').value,document.getElementById('fechaCalendarioMes').value);
		
	for(var i=1;i<=fecha.getMonthDays();i++){		
		
		var optionText = document.createTextNode(i);
		var option = document.createElement('option');
			option.setAttribute('value',i);
			option.appendChild(optionText);

		if(this.fechaDiaMarcar == i){
			option.setAttribute('selected','selected');
		}

		document.getElementById('fechaCalendarioDia').appendChild(option);	
	}
}

FechaCalendar.prototype.createCalendarioMes=function() {
	var fecha = new Fecha();
	var fechaCalendarioMesOption = '';
	
	for(var i=1;i<=12;i++){
		
		var optionText = document.createTextNode(fecha.NOMBRE_MES[i-1]);
		var option = document.createElement('option');
			option.setAttribute('value',i);
			option.appendChild(optionText);
			
		if(this.fechaMesMarcar == i){
			option.setAttribute('selected','selected');
		}

		document.getElementById('fechaCalendarioMes').appendChild(option);
	}
}

/*
SELECT Year
*/
FechaCalendar.prototype.createCalendarioYear=function() {	
	var fechaCalendarioActual = new Date();
	var fechaCalendarioYearOption = '';
		
	for(var i=(fechaCalendarioActual.getFullYear()-5);i>=1920;i--){
		
		var optionText = document.createTextNode(i);
		var option = document.createElement('option');
			option.setAttribute('value',i);
			option.appendChild(optionText);

		if(this.fechaYearMarcar == i){
			option.setAttribute('selected','selected');
		}

		document.getElementById('fechaCalendarioYear').appendChild(option);
	}
}


window.onload = function(){
	var objFechaCalendar = new FechaCalendar();
	objFechaCalendar.createCalendarioYear();
	objFechaCalendar.createCalendarioMes();
	objFechaCalendar.createCalendario();
	objFechaCalendar.setEventoCalendario();
};
