
function Calendar(objName, pIdioma)
{    
	// Propiedades
	this.idioma = "es"
	if ((pIdioma) && (pIdioma != ""))
	    this.idioma = pIdioma
	
	this.name = objName;			// Nombre objecto
	this.aplicacion = "logitravel"	// Directorio base	
	this.txt = "Fechas en oferta"	// Texto de los días a resaltar
	this.txtClass = "verdana6rojoBold"  // Fuente y color del texto de los días a resaltar
	this.squareColor = "Bbeig"		// Color del fondo de los días a resaltar
 	this.titleFont = "verdana9rojoBold" 	// Fuente y color del nombre de mes y 
	this.daysFont = "verdana7blanco"		// Fuente y color del nombre de los días de la semana
	this.daysBackgroundColor = "fondo"		// Color de fondo de los días de la semana
	this.backgroundColor = "Bazulflojo"		// Color de fondo de los días
	this.weekendBackgroundColor	="Bazul"	// Color de fondo de los días de un fin de semana
	this.daysNumberFont = "verdana7"		// Fuente de los días 
	this.daysPreviosNumberFont = "verdana7gris"		//Fuente de los días previos a hoy - no seleccionables
	this.tableColor = "#FAAF05"				// Color de la tabla donde está el mes y 
	this.outerTableColor = "#FAAF05"		// Color de la tabla que envuelve al calendario
	this.innerTableColor = "white"			// Color de la tabla interna del calendario
	this.todayFont = "verdana7rojoBold	"	// Fuente y color de hoy
	this.todayBackgroundColor = ""	// Fuente y color de hoy
	this.offSetX = 0						// Desplazamiento relativo a la posición x
	this.offSetY = 0						// Desplazamiento relativo a la posición y
	this.flechaIzq = "/"+ this.aplicacion+"/images/flecharojaizq.gif"	// Imagen correspondiente a la flecha izquierda
	this.flechaDer = "/"+ this.aplicacion+"/images/flecharojader.gif"	// Imagen correspondiente a la flecha derecha
    this.imagenCerrar = ""	// Imagen de cerrar calendario
    this.claseCerrar = "verdana6bold";  //Fuente del texto 'cerrar'
    
	this.fontface = "verdana";		// tipo de fuente en modo 
	this.fontsize = 8;				//  de fuente en modo 
	this.gNow = new Date();			// fecha actual
	this.gMin = new Date();			// fecha máxima a ensear en el calendario
	this.gMax = new Date();			// fecha mínima a ensear en el calendario
	this.ggWinContent="";
	this.ggPosX = -1;				// posición x
	this.ggPosY = -1;				// posición y
	this.gYear = "";
	this.gMonth ="";
	this.gMonthName	="";
	this.gYearly = false;	
	this.gFormat = "";
	this.gReturnItem = "";
	this.returnFunction = null
	this.tdId = null;    // id del td, si se va a incrustar dentro de una tabla
	this.mesMayuscula = false;  //Que el mes salga en mayuscula	
	
									// meses del 
	switch (this.idioma)
	{
	    case "pt":
	        this.Months = ["Janeiro", "Fevereiro", "Marco", "Abril", "Maio", "Junho","Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
	        break;
	    case "es":
        	this.Months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio","Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
        	break;
    }
	
									// Días de los meses en aos no bisiestos
	this.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
									// Días de los meses en aos bisiestos
	this.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	
	this.listaFechas;				// fechas a destacar


	
	// Metodos
		this.calendarMethod = fCalendarMethod;
		this.calendarGetMonth = fCalendarGetMonth;
		
		this.calendar_get_daysofmonth = fCalendar_get_daysofmonth;
		this.calendar_calc_month_year = fCalendar_calc_month_year;
		this.getMonthlyCalendarCode = fGetMonthlyCalendarCode;
		this.show = fShow;
		this.showY = fShowY;
		this.getDia = fGetDia;
		this.cal_header = fCal_header;
		this.cal_data = fCal_data;
		this.format_day = fFormat_day;
		this.format_css = fFormat_css;
		this.write_weekend_string = fWrite_weekend_string;
		this.write_today_string = fWrite_today_string;
		this.format_data = fFormat_data;
		this.Build = fBuild;
		this.show_yearly_calendar = fShow_yearly_calendar;
		this.show_calendar = fShow_calendar;	
		
}

// Devuelve un mes en concreto
function fCalendarGetMonth(num) {

	if (this.mesMayuscula)
		return this.Months[num].toUpperCase();
	else
		return this.Months[num];
}

// crea calendario con los datos pasados
function fCalendarMethod(p_item, p_month, p_year, p_format) {

	if ((p_month == null) && (p_year == null))	return;

	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = this.calendarGetMonth(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gReturnItem = p_item;

}

// Devuelve días de un mes segun el ano.
function fCalendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/	
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return this.DOMonth[monthNo];
	
		return this.lDOMonth[monthNo];
	} else
		return this.DOMonth[monthNo];
		
}

// Devueleve un array con el siguiente/anterior mes y ano 
function fCalendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
	
}
// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
//new Calendar();

// Devuelve el código HTML del calendario a ensenar
function fGetMonthlyCalendarCode() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode += ("<div align=center valign=top><TABLE width=98% cellpadding=1 cellspacing=1 BORDER=0 BGCOLOR=\"" + this.innerTableColor + "\" class=verdana7>");
	vCode +=("<TR><TD><img src='/"+this.aplicacion+"/images/shim.gif' height=2></TD></TR>")
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode += (vHeader_Code + vData_Code);
	vCode +=("<TR><TD><img src='/"+this.aplicacion+"/images/shim.gif' height=2></TD></TR>")
	vCode += "</TABLE>"
	vCode +=("<TABLE width='100%' cellpadding=0 cellspacing=0><TR class='grisFuerte' height='20'><TD align=left class="+ this.txtClass +">"+ this.txt +"</TD><td align='right'><a href='javascript: var a= cClick()'><span class='" + this.claseCerrar + "'>Cerrar</span>")
	if (this.imagenCerrar != ""){
	    vCode += ("&nbsp;<img src='"+this.imagenCerrar+"' border=0>&nbsp;")
	}
	
	vCode += ("</a></td></TR></TABLE>")
	vCode += "</div>";
	return vCode;	
	
}

function fShow() {
	var vCode = "";

	// build content into global var ggWinContent
	//ggWinContent += ("<FONT FACE='" + fontface + "' ><B>");
	//ggWinContent += (this.gMonthName + " " + this.gYear);
	//ggWinContent += "</B><BR>";


	// Show navigation buttons
	var prevMMYYYY = this.calendar_calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = this.calendar_calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
		
	var width;
	//Si el mes va en mayuscula, todo junto
	if (!this.mesMayuscula)
		width = "WIDTH='100%'"
		
	this.ggWinContent += ("<TABLE " + width + " BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR="+ this.tableColor +" style='font-size:" + this.fontsize + "pt;'><TR><TD width=15% ALIGN=center>");
	this.ggWinContent += ("<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\" return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\""+ this.name + ".Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><img border=0 src=' " + this.flechaIzq + "'><\/A></TD>")
	this.ggWinContent += ("<TD  width=70% ALIGN=center class="+ this.titleFont + ">");
	this.ggWinContent += (this.gMonthName + " " + this.gYear);
	this.ggWinContent += ("</TD><TD  width=15% ALIGN=center>");
	this.ggWinContent += ("<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\""+ this.name + ".Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><img border=0 src='" + this.flechaDer + "'><\/A></TD></TR>"+
		"</TABLE>");
	// Get the complete calendar code for the month, and add it to the
	//	content var
	vCode = this.getMonthlyCalendarCode();
	this.ggWinContent += vCode;	
}







function fShowY()
{
	var vCode = "";
	var i;

	this.ggWinContent += "<FONT FACE='" + this.fontface + "' ><B>"
	this.ggWinContent += ("Ano : " + this.gYear);
	this.ggWinContent += "</B><BR>";

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.ggWinContent += ("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0' style='font-size:" + this.fontsize + "pt;'><TR><TD ALIGN=center>");
	this.ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Retroceder un ano'; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"" + this.name +".Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<\Ano<\/A>]</TD><TD ALIGN=center>");
	this.ggWinContent += "       </TD><TD ALIGN=center>";
	this.ggWinContent += ("[<A HREF=\"javascript:void(0);\" " +
		"onMouseOver=\"window.status='Avanzar un ano';return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"" + this.name +".Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">Ano>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month.
	// start a table and first row in the table
	this.ggWinContent += ("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=5 style='font-size:" + this.fontsize + "pt;'><TR>");
	var j;
	for (i=0; i<12; i++) {
		// start the table cell
		this.ggWinContent += "<TD ALIGN='center' VALIGN='top'>";
		this.gMonth = i;
		this.gMonthName = this.calendarGetMonth(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.ggWinContent += (this.gMonthName + "/" + this.gYear + "<BR>");
		this.ggWinContent += vCode;
		this.ggWinContent += "</TD>";
		if (i == 3 || i == 7) {
			this.ggWinContent += "</TR><TR>";
			}

	}

	this.ggWinContent += "</TR></TABLE></font><BR>";
}

function fGetDia(oFecha){
	var aux=oFecha.getDay()
	switch(aux){
		case 0:
			return 7
		default:
			return aux
	}
}

function fCal_header()
{
	var vCode = "";
	
	vCode = vCode + "<TR  class=" + this.daysFont +">";
	switch(this.idioma)
	{
	    case "es":
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Lu</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Ma</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Mi</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Ju</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Vi</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Sa</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='16%'>Do</TD>";
	        break;
	     case "pt":
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>2</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>3</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>4</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>5</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>6</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='14%'>Sa</TD>";
	        vCode = vCode + "<TD align=center class=" + this.daysBackgroundColor +" WIDTH='16%'>Do</TD>";
	        break;
	 }
	 vCode = vCode + "</TR>";
	
	return vCode;
}

function fCal_data() {    
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=this.getDia(vDate)//vDate.getDay();
	//alert(vDate)
	var vDay=1;
	var vLastDay=this.calendar_get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/
	//alert(vDay)
	
	vCode = vCode + "<TR>";
	
	for (i=1; i<vFirstDay; i++) {	    
		vCode = vCode + "<TD align=center  WIDTH='14%' " + this.write_weekend_string(i) + "></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<=7; j++) {

		if(this.format_day(vDay) =="-1"){
			vCode = vCode + "<TD align=center  WIDTH='14%'" + this.write_weekend_string(j) + 
			"><FONT class='" + this.daysPreviosNumberFont + "'>" + vDay + "</FONT></TD>";
		}else{
			if(this.format_day(vDay) !=""){
			
	vDate.setDate(vDay);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);
				vCode = vCode + "<TD " + this.write_today_string(vDay) + "  align='center' " + this.format_css(vDay,vDate) +" WIDTH='14%' " + this.write_weekend_string(j) + ">" + 					
					"<A HREF='javascript:void(0);' " +
						"onMouseOver=\"return true;\" " +
						"onMouseOut=\"window.status=' '; return true;\" " 
						if (this.returnFunction!=null)
						{
							vCode += "onClick=\"" + this.returnFunction + "('" + 
							this.format_data(vDay) + 
							"');";
							
							if (this.tdId != null && this.tdId != ""){
								vCode += "\"";
							}else{
								vCode += "this.ggPosX=-1;this.ggPosY=-1;nd();nd();\"";
							}
						}
						vCode += ">" + 
						this.format_day(vDay) + 
						"</A>" + 
						"</TD>";
			}else{
				vCode = vCode + "<TD " + this.write_today_string(vDay) + "  align=center WIDTH='14%' " + this.write_weekend_string(j) + ">" + 
					"<A HREF='javascript:void(0);' " +
						"onMouseOver=\"return true;\" " +
						"onMouseOut=\"window.status=' '; return true;\" " 
						if (this.returnFunction!=null)
						{
							vCode += "onClick=\"" + this.returnFunction + "('" + 
							this.format_data(vDay) + 
							"')";
							if (this.tdId != null && this.tdId != ""){
								vCode += "\"";
							}else{
								vCode += "this.ggPosX=-1;this.ggPosY=-1;nd();nd();\"";
							}
						}	
						vCode += ">" + 
						vDay + 
						"</A>" + 
						"</TD>";
			}
		}
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";	
	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=1; j<=7; j++) {
			if(this.format_day(vDay) =="-1"){
				vCode = vCode + "<TD align=center  WIDTH='14%'" + this.write_weekend_string(j) + 
				"><FONT class='" + this.daysPreviosNumberFont + "'>" + vDay + "</FONT></TD>";
			}else{
				if(this.format_day(vDay) !=""){
	vDate.setDate(vDay);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);					
					vCode = vCode + "<TD " + this.write_today_string(vDay) + " align=center "+this.format_css(vDay,vDate)+" WIDTH='14%'" + this.write_weekend_string(j) + ">" + 
						"<A HREF='javascript:void(0);' " +
							"onMouseOver=\"return true;\" " +
							"onMouseOut=\"window.status=' '; return true;\" " 							
							if (this.returnFunction!=null)
							{
								vCode += "onClick=\"" + this.returnFunction + "('" + 
								this.format_data(vDay) + 
								"');" 
								if (this.tdId != null && this.tdId != ""){
									vCode += "\"";
								}else{
									vCode += "this.ggPosX=-1;this.ggPosY=-1;nd();nd();\"";
								}
							}
							vCode += ">" + 
							this.format_day(vDay) + 
						"</A>" + 
						"</TD>";
				}else{
					vCode = vCode + "<TD " + this.write_today_string(vDay) + "  align=center  WIDTH='14%'" + this.write_weekend_string(j) + ">" + 
						"<A HREF='javascript:void(0);' " +
							"onMouseOver=\"return true;\" " +
							"onMouseOut=\"window.status=' '; return true;\" " 
							if (this.returnFunction!=null)
							{
								vCode += "onClick=\"" + this.returnFunction + "('" + 
								this.format_data(vDay) + 
								"');";
								if (this.tdId != null && this.tdId != ""){
									vCode += "\"";
								}else{
									vCode += "this.ggPosX=-1;this.ggPosY=-1;nd();nd();\"";
								}
							}
							vCode += ">" + 
							vDay + 
							"</A>" + 
							"</TD>";
				}
			}
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 7)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<=(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD align=center WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"></TD>";
		else
			vCode = vCode + "<TD align=center WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT FACE='" + this.fontface + "' COLOR='red'>" + "&nbsp;" + "</FONT></TD>";
	}
	//alert(vCode)
	return vCode;
}

function fFormat_day(vday)
{
	var vNowDay = this.gNow.getDate();
	var vNowMonth = this.gNow.getMonth();
	var vNowYear = this.gNow.getFullYear();
	var aux = this.gMonth+1

	var oFec = parseDate(vday+"/"+aux+"/"+this.gYear)
	oFec.setHours(0)
	
	if(oFec<gMin)
		return "-1";
	
	if(this.listaFechas==null)
	{
		if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		{
				return ("<FONT class=" + this.todayFont + ">" + vday + "</FONT>");
		}		
		return "<FONT class=" + this.daysNumberFont + ">" + vday + "</FONT>";
	}
	else{
		var ok=false
		var dia,mes,any;
		for (var i=0; i<this.listaFechas.length; i++)
		{
			n = this.listaFechas[i];
			//alert(n)
			dia = n.substring(0,2);
			mes = parseInt(n.substring(3,5),10);
			
			if ((mes<tmonth) && (tmonth-1!=mes))
		      any = tyear + 1;
			else
		      any = tyear;
		    odate = new Date(any, mes-1, dia)
			//alert(odate)
			//alert(((odate-hoy)/1000/60/60/24))
			if((oFec.getDate()==odate.getDate()) && (oFec.getMonth()==odate.getMonth()) && (oFec.getFullYear()==odate.getFullYear())){
				ok=true
			}
		}		
	
		if(!ok){
				return "<FONT class=" + this.daysNumberFont + ">" + vday + "</FONT>";
		}else{
			//return ("<FONT class=verdana9verde>" + vday + "</FONT>");
			return ("<FONT class='verdana7rojoBold'>" + vday + "</FONT>")
		}
	}
}

function fFormat_css(vday,vdate) 
{
	var vNowDay = this.gNow.getDate();
	var vNowMonth = this.gNow.getMonth();
	var vNowYear = this.gNow.getFullYear();
	var aux = this.gMonth+1

	var oFec = parseDate(vday+"/"+aux+"/"+this.gYear)
	oFec.setHours(0)
	
	if(oFec<gMin)
		return "-1";

	if(this.listaFechas==null){
		return this.write_weekend_string(this.getDia(vdate))
	}
		
	var ok=false
	var dia,mes,any;
	for (var i=0; i<this.listaFechas.length; i++)
	{
		n = this.listaFechas[i];
		//alert(n.text)
		dia = n.substring(0,2);
		
		mes = parseInt(n.substring(3,5),10);
		
		if ((mes<tmonth) && (tmonth-1!=mes))
	      any = tyear + 1;
		else
	      any = tyear;
		
	    odate = new Date(any, mes-1, dia)
		//alert(odate)
		//alert(((odate-hoy)/1000/60/60/24))
		if((oFec.getDate()==odate.getDate()) && (oFec.getMonth()==odate.getMonth()) && (oFec.getFullYear()==odate.getFullYear())){			
			ok=true
		}
	}		

	//if(!ok)
		return this.write_weekend_string(this.getDia(vdate))					
	/*else
		return ("class='" + this.squareColor + "1'");*/
}

function fWrite_today_string(vday) 
{
	if (this.todayBackgroundColor != "") {
		var vNowDay = this.gNow.getDate();
		var vNowMonth = this.gNow.getMonth();
		var vNowYear = this.gNow.getFullYear();
		var aux = this.gMonth+1
	
		if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
			{
					return (" class = " + this.todayBackgroundColor);
			}	
		else
			{
					return "";
			}	
	}	
	return ""
}

function fWrite_weekend_string(vday) {
	var x;
	
	// Return special formatting for the weekend day.
	for (x=0; x<2; x++) 
	{
		 if ((vday == 6) || (vday == 7))
		{
			return (" class = " + this.weekendBackgroundColor);
		}
		else
		{
			return (" class = " + this.backgroundColor );
		}
	}
}

function fFormat_data(p_day)
{
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = this.calendarGetMonth(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = this.calendarGetMonth(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "YYYY-MM-DD" :
			vData = vY4 + "-" + vMonth + "-" + vDD;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;
		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;
		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;
		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;
		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

// Construye el calendario
function fBuild(p_item, p_month, p_year, p_format) {

	this.calendarMethod(p_item, p_month, p_year, p_format);

	// initialize the content string
	this.ggWinContent = "";

	// Choose appropriate show function
	if (this.gYearly) {
		// and, since the yearly calendar is so large, override the positioning and fontsize
		// warning: in IE6, it appears that "select" fields on the form will still show
		//	through the "over" div; Note: you can set these variables as part of the onClick
		//	javascript code before you call the show_yearly_calendar function
		if (this.ggPosX == -1) this.ggPosX = 10;
		if (this.ggPosY == -1) this.ggPosY = 10;
		if (this.fontsize == 8) this.fontsize = 6;
		// generate the calendar
		this.showY();
		}
	else {
		this.show();
		}
		
	// if this is the first calendar popup, use autopositioning with an offset
	if (this.ggPosX == -1 && this.ggPosY == -1) {
	
		//Si el id del td viene informado, no lo mostramos en popup, lo incrustamos en la tabla
		if (this.tdId != null && this.tdId != ""){
			this.tdId.innerHTML = this.ggWinContent;
		}else{
		    overlib(this.ggWinContent, AUTOSTATUSCAP, STICKY, CLOSECLICK, CSSSTYLE,
				TEXTSIZEUNIT, "pt", TEXTSIZE, 8, CAPTIONSIZEUNIT, "pt", CAPTIONSIZE, 8, CLOSESIZEUNIT, "pt", CLOSESIZE, 8,
				CAPTION, "Selecciona una fecha", this.offSetX, -120 , this.offSetY, 120, BGCOLOR, this.outerTableColor);
		}
		
		// save where the 'over' div ended up; we want to stay in the same place if the user
		//	clicks on one of the year or month navigation links
		if ( (ns4) || (ie4) ) {
		        this.ggPosX = parseInt(over.left);
		        this.ggPosY = parseInt(over.top);
			} else if (ns6) {
			this.ggPosX = parseInt(over.style.left);
			this.ggPosY = parseInt(over.style.top);
			}
		p_format}
	else {
		//Si el id del td viene informado, no lo mostramos en popup, lo incrustamos en la tabla
		
		if (this.tdId != null && this.tdId != ""){
			this.tdId.innerHTML = this.ggWinContent;			
		}else{
			// we have a saved X & Y position, so use those with the FIXX and FIXY options
	 		overlib(this.ggWinContent, AUTOSTATUSCAP, STICKY, CLOSECLICK, CSSSTYLE,
				TEXTSIZEUNIT, "pt", TEXTSIZE, 8, CAPTIONSIZEUNIT, "pt", CAPTIONSIZE, 8, CLOSESIZEUNIT, "pt", CLOSESIZE, 8,
				CAPTION, "Selecciona una fecha", FIXX, this.ggPosX, FIXY, this.ggPosY);
		}
		}
		
	//window.scroll(ggPosX, ggPosY);
}

// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";

//alert(val+"**"+format)	

	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

var MONTH_NAMES=new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre','Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');
var DAY_NAMES=new Array('Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

function parseDate(val) {
//var preferEuro=(arguments.length==2)?arguments[1]:false;
generalFormats=new Array('d-M-y','d MMM y','d MMM,y','d-MMM-y','d MMM','d M y','d/MMM/y','d/MMM','dMy','dMMMy','d.M.Y','d.MMM.y');
monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d','M d','Md','M.d');
dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M','d M','dM','d.M');
var checkList=new Array('generalFormats','dateFirst','monthFirst');
var d=null;
for (var i=0; i<checkList.length; i++) {
	var l=window[checkList[i]];
	for (var j=0; j<l.length; j++) {
		d=getDateFromFormat(val,l[j]);
		if (d!=0) { return new Date(d); }
		}
	}
return null;
}

function fShow_calendar(p_item,fmin,fechas) {
	
	/* 
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/	
    this.gNow=parseDate(eval(p_item+".value"))
	
	if(this.gNow==null)
		this.gNow=new Date()
		
	gMin=parseDate(fmin);
	gMin.setHours(0);
	this.listaFechas=fechas;
	//gMax=parseDate(fmax)
	//gMax.setHours(23)
	//alert(gMin)
	//alert(gMax)
	p_format = "DD/MM/YYYY"
	p_item = arguments[0];
	p_month = new String(this.gNow.getMonth());	
	p_year = new String(this.gNow.getFullYear().toString());
	/*if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		//p_format = "YYYY-MM-DD";
		p_format = "DD/MM/YYYY"
	else
		p_format = arguments[3];
	*/

	this.Build(p_item, p_month, p_year, p_format);

}
/*
Yearly Calendar Code Starts here
*/
function fShow_yearly_calendar() {
	// Load the defaults..
	//if (p_year == null || p_year == "")
	//	p_year = new String(gNow.getFullYear().toString());
	//if (p_format == null || p_format == "")
	//	p_format = "YYYY-MM-DD";

	p_item = arguments[0];
	if (arguments[1] == "" || arguments[1] == null)
		p_year = new String(this.gNow.getFullYear().toString());
	else
		p_year = arguments[1];
	if (arguments[2] == null)
		p_format = "YYYY-MM-DD";
	else
		p_format = arguments[2];


	this.Build(p_item, null, p_year, p_format);
}

