// JS CALENDAR
// Programado por: Sebastian J. Ponzio - 12/2003
// e-mail: zfksis@uol.com.ar
// Probado en los siguientes navegadores: Mozilla Firebird 0.7, Internet Explorer 6.0, Opera 7.0
// No lo probe personalmente, pero deberia funcionar en: Netscape, Konqueror.
//
// Para una descripcion de los eventos, metodos y propiedades, lea el archivo README.txt
//----------------------------------------------------------------------------------------------

if (navigator.appName == "Netscape") {
	document.captureEvents(Event.MOUSEDOWN);
}

// Here is where you can change the months & days captions to your language.
// Starting day is Sunday. If you want to change it, you must change the "get_dayofweek" method.
var gl_calendar_today = "<font color=\"#D6AB29\"><strong>Today:</strong></font>";
var gl_calendar_meses = Array("January","February","March","April","May","June","July","August","September","October","November","December");
var gl_calendar_dias = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"/calendar/calendar.css\">');

var isIE = (navigator.appName == "Microsoft Internet Explorer") ? true: false;
var isKo = (navigator.appName == "Konqueror") ? true: false;
var isOp = (navigator.appName == "Opera") ? true: false;

function jscalendar() {
	// PROPIEDADES PUBLICAS
	this.name = "calendar"; // Default name.
	this.dateformat = "mm/dd/yyyy";	// Default dateformat, change to your locale.
	this.day = 0;
	this.month = 0;
	this.year = 0;
	this.value = "";
	this.dayofweek = 0;
	this.calendar_visibility = "hidden";
	this.posLeft = -1;
	this.posTop = -1;
	this.main_shadow = true;
	this.month_shadow = true;
	this.activateImage = "/calendar/calendar_images/calendar_activate.gif"	

	// PROPIEDADES PRIVADAS
	this.daypos = 0;
	this.daylength = 0;
	this.monthpos = 0;
	this.monthlength = 0;
	this.yearpos = 0;
	this.yearlength = 0;
	this.prevday = 0;
	this.prevmonth = 0;
	this.prevyear = 0;
	this.today_day = 0;
	this.today_month = 0;
	this.today_year = 0;
	this.init_day = 0;
	this.init_month = 0;
	this.init_year = 0;
	this.initalized = false;
	this.calendar_visible = false;
	
	// METODOS PUBLICOS
	this.parse_dateformat = new Function("for(i=0;i < this.dateformat.length;i++){if(this.dateformat.charAt(i) == 'd'){this.daypos = i;this.daylength = 1;if(this.dateformat.charAt(i + 1) == 'd'){this.daylength = 2;i++;continue;}}if(this.dateformat.charAt(i) == 'm'){this.monthpos = i;this.monthlength = 1;if(this.dateformat.charAt(i + 1) == 'm'){this.monthlength = 2;i++;continue;}}if(this.dateformat.charAt(i) == 'y'){this.yearpos = i;this.yearlength = 1;if(this.dateformat.charAt(i + 1) == 'y'){this.yearlength = 2;i++;if(this.dateformat.charAt(i + 1) == 'y'){this.yearlength = 3;i++;if(this.dateformat.charAt(i + 1) == 'y'){this.yearlength = 4;i++;continue;}}}}}");
	this.set_value = set_value;
	this.set_valuebystring = set_valuebystring;
	this.date_move = date_move;
	this.display = display;
	this.expand = expand;
	this.compress = new Function('this.monthselector_compress(); document.getElementById("CALLYR_" + this.name).style.visibility = "hidden"; document.getElementById("CALLYR_" + this.name + "_SHADOW").style.visibility = "hidden"; this.yearswitch_show_hide(true); this.calendar_visible = false; this.showWindowedObjects(true); this.onCompress();');
	
	// METODOS PRIVADOS
	this.parse_date = parse_date;
	// Retorna: 0=Domingo, 1=Lunes
	// Returns: 0= Sunday, 1= Monday
	this.get_dayofweek = new Function("day","month","year","var a = parseInt((14 - month)/12); var y = year - a; var m = month + 12*a - 2; var d = (day + y + parseInt(y/4) - parseInt(y/100) + parseInt(y/400) + parseInt((31*m)/12)) % 7; return d;");
	this.update_properties = new Function("document.getElementById(this.name + '_date').value = this.value; document.getElementById(this.name + '_Year').value = this.day; document.getElementById(this.name + '_Month').value = this.month; document.getElementById(this.name + '_Day').value = this.year; this.dayofweek = this.get_dayofweek(this.day,this.month,this.year); this.onPropertiesUpdated(); this.draw();");
	this.graphic_setup = graphic_setup;
	this.draw = draw;
	this.textbox_key = textbox_key;
	this.yearswitch_show_hide = new Function("forced","var arrow_up = document.getElementById(this.name + '_arrow_up');	var arrow_dn = document.getElementById(this.name + '_arrow_dn'); if (arrow_up.style.visibility != 'hidden' || forced == true) { arrow_up.style.visibility = 'hidden';	arrow_dn.style.visibility = 'hidden'; } else {	arrow_up.style.visibility = 'visible'; arrow_dn.style.visibility = 'visible';	}");
	this.getMyXY = new Function("var obj = document.getElementById(this.name + '_date'); for(var sumTop = 0, sumLeft = 0; obj != document.body; sumTop += obj.offsetTop,sumLeft += obj.offsetLeft, obj = obj.offsetParent); this.posLeft = sumLeft; this.posTop = sumTop;");
	this.monthselector_expand = monthselector_expand;
	this.monthselector_compress = new Function ("document.getElementById('CALLYR_' + this.name + '_MESES').style.visibility = 'hidden'; document.getElementById('CALLYR_' + this.name + '_MESES_SHADOW').style.visibility = 'hidden';");
	this.showWindowedObjects = showWindowedObjects;
	this.isLeapYear = new Function("year","var year_diff = (Math.floor(year) - 2000) / 4; var ret = false; if (parseInt(year_diff) == year_diff) { ret = true; } return ret;");
	this.max_days_month = new Function("month", "year", "var arr = Array(31,28,31,30,31,30,31,31,30,31,30,31); if (this.isLeapYear(year)) { arr[1] = 29; } return arr[month - 1];");
	this.make_date = new Function("month", "day", "year", "day = parseInt(day); month = parseInt(month); year = parseInt(year); if (day < 1) {month--;if (month == 0) { month = 12; year--;} day = (this.max_days_month(month,year) + day); } if (day > this.max_days_month(month,year)) { day = (day - this.max_days_month(month,year)); month++;if (month > 12) { month = 1; year++;} } year = (year < 200) ? (year + 2000) : year; return new Date(month.toString() + '/' + day.toString() + '/' + year.toString());");

	// EVENTOS
	this.onCreate = new Function("");
	this.onExpand = new Function("");
	this.onCompress = new Function("");
	this.onPropertiesUpdated = new Function("");
	this.onYearSwitchClick = new Function("");
	this.onMonthSwitchClick = new Function("");
	this.onValueChange = new Function("");
	this.onDayClick = new Function("");
	
}

function display() {
	this.parse_dateformat();
	document.write('<table style=\"border-collapse: collapse; \" border=\"0\" width=\"95px\" cellpadding=\"0\" cellspacing=\"0\">');
	document.write('<tr>');
	document.write('<td align=\"right\" width=\"76%\"><input onKeyDown=\"' + this.name + '.textbox_key(event);\" size=\"11\" maxlength=\"10\" class=\"CALENDAR_TXTBOX\" onChange=\"' + this.name + '.parse_date();\" type=\"text\" name=\"' + this.name + '_date\" id=\"' + this.name + '_date\" value=\"' + this.value + '\">');
	document.write('<input type="hidden" id="' + this.name + '_Year" name="' + this.name + '_Year" value="">');
	document.write('<input type="hidden" id="' + this.name + '_Month" name="' + this.name + '_Month" value="">');
	document.write('<input type="hidden" id="' + this.name + '_Day" name="' + this.name + '_Day" value="">');
	document.write('</td>');
	document.write('<td align=\"center\" valign=\"middle\" width=\"24%\">');
	var img = "<img onMouseDown=\"" + this.name + ".expand();\" style=\"cursor: hand;\" border=\"0\" src=\"" + this.activateImage + "\" name=\"" + this.name + "_CMD\" id=\"" + this.name + "_CMD\">";
	document.write(img);
	document.write('</td></tr>');
	document.write('</table>');
	document.write('<div class=\"CALENDAR_DIV_CALLYR\" name=\"CALLYR_' + this.name + '\" id=\"CALLYR_' + this.name + '\"></div>');
	document.write('<div class=\"CALENDAR_DIV_CALLYR_SHADOW\" name=\"CALLYR_' + this.name + '_SHADOW\" id=\"CALLYR_' + this.name + '_SHADOW\"></div>');
	document.write('<div class=\"CALENDAR_DIV_MESES\" name=\"CALLYR_' + this.name + '_MESES\" id=\"CALLYR_' + this.name + '_MESES\"></div>');
	document.write('<div class=\"CALENDAR_DIV_MESES_SHADOW\" name=\"CALLYR_' + this.name + '_MESES_SHADOW\" id=\"CALLYR_' + this.name + '_MESES_SHADOW\"></div>');
	this.graphic_setup();
	this.onCreate();
}

function graphic_setup() {
	var ret = "";
	ret += "<table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>";
	ret += "<tr>";
	ret += "<td colspan='7'>";
	ret += "<table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>";
	ret += "<tr>";
	ret += "<td width='21' height='21' align='left' class='CALENDAR_BG_HEADER_MES_ANO'><a style='cursor: hand;' href=\"javascript: " + this.name + ".date_move('m',-1);\"><img width='21' height='21' border='0' src='/calendar/calendar_images/calendar_prev_month.gif'></a></td>";
	ret += "<td height='21' onclick=\"\" class='CALENDAR_BG_HEADER_MES_ANO' align='right' id='" + this.name + "_MONTH_LAYER' name='" + this.name + "_MONTH_LAYER'>&nbsp;</td>";
	ret += "<td height='21' class='CALENDAR_BG_HEADER_MES_ANO' align='right' id='" + this.name + "_YEAR_LAYER' name='" + this.name + "_YEAR_LAYER'>&nbsp;</td>";
	ret += "<td height='21' width='12' class='CALENDAR_BG_HEADER_MES_ANO' align='right'><img id=\"" + this.name + "_arrow_up\" name=\"" + this.name + "_arrow_up\" onClick=\"javascript: " + this.name + ".onYearSwitchClick();" + this.name + ".date_move('y',1);\" style='visibility: hidden; cursor: hand;' width='12' height='12' border='0' src='/calendar/calendar_images/calendar_section_up.gif'><br><img id=\"" + this.name + "_arrow_dn\" name=\"" + this.name + "_arrow_dn\" onClick=\"javascript: " + this.name + ".onYearSwitchClick(); " + this.name + ".date_move('y',-1);\" style='visibility: hidden; cursor: hand;' width='12' height='12' border='0' src='/calendar/calendar_images/calendar_section_dn.gif'></td>";
	ret += "<td width='21' height='21' align='right' class='CALENDAR_BG_HEADER_MES_ANO'><a style='cursor: hand;' href=\"javascript: " + this.name + ".date_move('m',1);\"><img width='21' height='21' border='0' src='/calendar/calendar_images/calendar_next_month.gif'></a></td>";
	ret += "</tr></table></td></tr>";
	ret += "<tr>";
	for(i=0;i < gl_calendar_dias.length;i++) {
		ret += "<td width='21' class='CALENDAR_BG_HEADER_DIAS_TEXT' align='center'>" + gl_calendar_dias[i] + "</td>";
	}
	ret += "</tr>";
	ret += "<tr>";
	ret += "<td colspan='7'>";
	ret += "<div id=\"CALLYR_" + this.name + "_MAIN\"></div>";
	ret += "</td>";
	ret += "<tr>";
	ret += "<tr>";
	ret += "<td height='18' colspan='7' class='CALENDAR_BOTTOM_TODAY' align='center' valign='middle' id='" + this.name + "_today' name='" + this.name + "_today'></td>";
	ret += "<tr>";
	ret += "</table>";
	document.getElementById("CALLYR_" + this.name).innerHTML = ret;
	var tmp = Array();
	var tmp_date = new Date();
	this.today_day = tmp_date.getDate();
	this.today_month = (tmp_date.getMonth() + 1);
	this.today_year = tmp_date.getFullYear();
	tmp[this.daypos] = (tmp_date.getDate().toString().length == 1) ? "0" + tmp_date.getDate().toString() : tmp_date.getDate().toString();
	tmp[this.monthpos] = ((tmp_date.getMonth() + 1).toString().length == 1) ? "0" + (tmp_date.getMonth() + 1) : (tmp_date.getMonth() + 1);
	tmp[this.yearpos] = tmp_date.getFullYear();
	var tmp_show = "";
	var tmpdatesep = "/";
	for(var x=0;x < tmp.length;x++) {
		if (x == tmp.length - 1) { tmpdatesep = ""; }
		if (tmp[x] != "" && tmp[x] != null) { tmp_show += tmp[x] + tmpdatesep; }
	}
	tmp_show = gl_calendar_today + " <a href='javascript: " + this.name + ".set_value(" + tmp_date.getDate().toString() + "," + (tmp_date.getMonth() + 1).toString() + "," + tmp_date.getFullYear() + "); " + this.name + ".compress();' class='CALENDAR_BOTTOM_LINK_TODAY'>" + tmp_show + "</a>";
	tmp_show = tmp_show + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript: " + this.name + ".compress();' class='CALENDAR_BOTTOM_LINK_TODAY'><strong>Close</strong></a>";
	document.getElementById(this.name + "_today").innerHTML = tmp_show;
	this.draw();
}

function draw() {
	if (this.calendar_visibility != "visible") { return; }
	if (this.prevday == this.day && this.prevmonth == this.month && this.prevyear == this.year) { return; }
	var ret = "";
	var lyr_month = document.getElementById(this.name + "_MONTH_LAYER");
	lyr_month.innerHTML = "<a href=\"javascript: " + this.name + ".monthselector_expand();\" class='CALENDAR_HEADER_LINK'>" + gl_calendar_meses[this.month - 1] + "</a>";
	var lyr_year = document.getElementById(this.name + "_YEAR_LAYER");
	lyr_year.innerHTML = "<a class='CALENDAR_HEADER_LINK' href=\"javascript: " + this.name + ".yearswitch_show_hide();\">" + this.year.toString() + "</a>";
	ret += "<table border='0' width='100%' cellpadding='0' cellspacing='0'>";
	var intmonth = this.month;
	var intyear = this.year;
	var strmonth = intmonth.toString();
	var stryear = intyear.toString();
	
	var tmp_day = 0;
	var tmp_date = this.make_date(strmonth, 1, stryear);
	var tmp_last_day = this.max_days_month(intmonth,intyear);
	var f = 0;
	var tmp_class1 = "";
	var tmp_class2 = "";
	var tmp_link = "";
	var init_day = this.get_dayofweek(1,intmonth,intyear);
	if (init_day != 0) {
		tmp_date = this.make_date(strmonth, 0, stryear);
		var tmp = 0;
		for(i=1;i < init_day;i++) {
			tmp = tmp_date.getDate() - 1;
			tmp_date = this.make_date((tmp_date.getMonth() + 1), tmp, tmp_date.getFullYear());
		}
	}
	ret += "<tr>";
	var tmp_next_year = 0;
	var tmp_next_month = 0;
	var tmp_prev_year = 0;
	var tmp_prev_month = 0;
	var tmp_show = "";
	var tmp_month = 0;
	var tmp_year = 0;
	tmp_next_year = intyear;
	tmp_prev_year = intyear;
	tmp_prev_month = intmonth - 1;
	tmp_next_month = intmonth + 1;
	if (tmp_prev_month == 0) { tmp_prev_month = 12; tmp_prev_year--; }
	if (tmp_next_month == 13) { tmp_next_month = 1; tmp_next_year++; }
	tmp_next_year = tmp_next_year.toString();
	tmp_prev_year = tmp_prev_year.toString();
	tmp_next_month = tmp_next_month.toString();
	tmp_prev_month = tmp_prev_month.toString();
	for(x=0;x < 42;x++) {
		if (f == 7) { f = 0; ret += "</tr><tr>"; } f = (f + 1) % 8;
		tmp_day = tmp_date.getDate();
		tmp_month = (tmp_date.getMonth() + 1);
		tmp_year = tmp_date.getFullYear();
		tmp_class1 = "CALENDAR_DIAS_LINK";
		tmp_class2 = "CALENDAR_DIAS_LINK_TD";
		tmp_link = "javascript: " + this.name + ".set_value(" + tmp_day.toString() + "," + strmonth + "," + stryear + "); " + this.name + ".compress(); " + this.name + ".onDayClick();";
		if ((tmp_month < intmonth || tmp_year < intyear) && tmp_day > 1)  {
			tmp_class1 = "CALENDAR_DIAS_OTRO_MES";
			tmp_link = "javascript: " + this.name + ".set_value(" + tmp_day.toString() + "," + tmp_prev_month + "," + tmp_prev_year + "); " + this.name + ".compress(); " + this.name + ".onDayClick();";
			tmp_nocalcular = 1;
		}
		if ((tmp_month > intmonth || tmp_year > intyear) && tmp_day < tmp_last_day - 7) {
			tmp_class1 = "CALENDAR_DIAS_OTRO_MES";
			tmp_link = "javascript: " + this.name + ".set_value(" + tmp_day.toString() + "," + tmp_next_month + "," + tmp_next_year + "); " + this.name + ".compress(); " + this.name + ".onDayClick();";
		}
		if (tmp_day == this.today_day && tmp_month == this.today_month && tmp_year == this.today_year) { tmp_class2 = "CALENDAR_DIAS_LINK_TD_TODAY"; tmp_class1 = "CALENDAR_DIAS_LINK_TODAY"; }
		if (tmp_day == this.day && tmp_month == this.month && tmp_year == this.year) { tmp_class2 = "CALENDAR_DIAS_LINK_TD_DIA_SELECCIONADO"; tmp_class1 = "CALENDAR_DIAS_LINK_DIA_SELECCIONADO"; }
		if (this.get_dayofweek(tmp_day,tmp_month,tmp_year) == 0) { tmp_class1 += "_SUN"; tmp_class2 += "_SUN"; }
		if (tmp_month == intmonth)
			ret += "<td class='" + tmp_class2 + "' align='center'><a href=\"" + tmp_link + "\" class=" + tmp_class1 + ">" + tmp_day.toString() + "</a></td>";
		else
			ret += "<td class='" + tmp_class2 + "' align='center'>&nbsp;</td>";
		tmp_day++;
		tmp_date = this.make_date(tmp_month, tmp_day, tmp_year);
	}
	ret += "</tr>";
	//ret += "<tr><td class='CALENDAR_DIAS_LINK_TD_SUN' height='11px'><td height='11px' colspan='6'></td></tr>";
	ret += "</table>";
	document.getElementById("CALLYR_" + this.name + "_MAIN").innerHTML = ret;
	this.prevday = this.day;
	this.prevmonth = intmonth;
	this.prevyear = intyear;
	ret = "<table align='center' border='0' width='70px' cellpadding='1' cellspacing='0'>";
	for(var y=0;y < gl_calendar_meses.length;y++) {
		ret += "<tr>";
		ret += "<td align=\"center\"><a class=\"CALENDAR_DIV_LINK\"  href=\"javascript: " + this.name + ".set_value(" + this.day + "," + (y + 1).toString() + "," + this.year + "); " + this.name + ".onMonthSwitchClick();" + this.name + ".monthselector_compress();\">" + gl_calendar_meses[y] + "</a></td>";
		ret += "</tr>";
	}
	ret += "</table>";
	var obj1 = document.getElementById("CALLYR_" + this.name + "_MESES");
	var obj2 = document.getElementById("CALLYR_" + this.name + "_MESES_SHADOW");
	obj1.innerHTML = ret;
}

function parse_date() {
	this.value = document.getElementById(this.name + "_date").value;
	var scleanstring = this.value;
	scleanstring = scleanstring.replace(/\./gi,"/");
	scleanstring = scleanstring.replace(/\-/gi,"/");
	scleanstring = scleanstring.replace(/\\/gi,"/");
	this.value = scleanstring;

	var tmp_date2 = Date.parse(this.value);
	if (isNaN(tmp_date2)) {
		var tmp = Array();
		tmp[this.daypos] = this.init_day.toString();
		tmp[this.monthpos] = this.init_month.toString();
		tmp[this.yearpos] = this.init_year.toString();
		var sep = "/";
		this.value = '';
		for(var y=0;y < tmp.length;y++) {
			if (y == (tmp.length - 1)) {sep = "";}
			if (tmp[y] != '' && tmp[y] != null) {
					this.value += tmp[y] + sep;
			}
		}
	}

	var tmp_day = "";
	var tmp_month = "";
	var tmp_year = "";

	var sDate = this.value;
	
	var iFirstSlash = sDate.indexOf("/");
	var iLastSlash = sDate.lastIndexOf("/");

	var FirstPos = sDate.substring(0,iFirstSlash);
	var SecondPos = sDate.substring(iFirstSlash + 1,iLastSlash);
	var ThirdPos = sDate.substring(iLastSlash + 1);

	switch (parseInt(this.daypos)) {
		case 0 :
			tmp_day = FirstPos;
			break; 
		case 3 :
			tmp_day = SecondPos;
			break;
		case 5 :
			tmp_day = SecondPos;
			break;
		case 6 :
			tmp_day = ThirdPos;
			break;
		case 8 :
			tmp_day = ThirdPos;
			break;
	}

	switch (parseInt(this.monthpos)) {
		case 0 :
			tmp_month = FirstPos;
			break; 
		case 3 :
			tmp_month = SecondPos;
			break;
		case 5 :
			tmp_month = SecondPos;
			break;
		case 6 :
			tmp_month = ThirdPos;
			break;
		case 8 :
			tmp_month = ThirdPos;
			break;
	}

	switch (parseInt(this.yearpos)) {
		case 0 :
			tmp_year = FirstPos;
			break; 
		case 3 :
			tmp_year = SecondPos;
			break;
		case 5 :
			tmp_year = SecondPos;
			break;
		case 6 :
			tmp_year = ThirdPos;
			break;
		case 8 :
			tmp_year = ThirdPos;
			break;
	}


	if (!isNaN(parseInt(tmp_day))) { this.day = parseInt(tmp_day-0); }
	if (!isNaN(parseInt(tmp_month))) { this.month = parseInt(tmp_month-0); }
	if (!isNaN(parseInt(tmp_year))) { this.year = parseInt(tmp_year-0); }

	this.date_move('d',0);
}

function set_valuebystring(sdate,cancelevent) {
	var day = "";
	var month = "";
	var year = "";

	sdate = sdate.replace(/\./gi,"/");
	sdate = sdate.replace(/\-/gi,"/");
	sdate = sdate.replace(/\\/gi,"/");

	var iFirstSlash = sdate.indexOf("/");
	var iLastSlash = sdate.lastIndexOf("/");

	var FirstPos = sdate.substring(0,iFirstSlash);
	var SecondPos = sdate.substring(iFirstSlash + 1,iLastSlash);
	var ThirdPos = sdate.substring(iLastSlash + 1);
	
	switch (parseInt(this.daypos)) {
		case 0 :
			day = FirstPos;
			break; 
		case 3 :
			day = SecondPos;
			break;
		case 5 :
			day = SecondPos;
			break;
		case 6 :
			day = ThirdPos;
			break;
		case 8 :
			day = ThirdPos;
			break;
	}

	switch (parseInt(this.monthpos)) {
		case 0 :
			month = FirstPos;
			break; 
		case 3 :
			month = SecondPos;
			break;
		case 5 :
			month = SecondPos;
			break;
		case 6 :
			month = ThirdPos;
			break;
		case 8 :
			month = ThirdPos;
			break;
	}

	switch (parseInt(this.yearpos)) {
		case 0 :
			year = FirstPos;
			break; 
		case 3 :
			year = SecondPos;
			break;
		case 5 :
			year = SecondPos;
			break;
		case 6 :
			year = ThirdPos;
			break;
		case 8 :
			year = ThirdPos;
			break;
	}


	this.day = parseInt(day-0);
	this.month = parseInt(month-0);
	year = parseInt(year-0);
	this.year = (year < 200) ? (year + 2000) : year;
	if (this.initalized == false) {
		this.initalized = true;	
		this.init_day = (!isNaN(day)) ? day : new Date().getDate();
		this.init_month = (!isNaN(month)) ? month : new Date().getMonth() + 1;
		this.init_year = (!isNaN(year)) ? year : new Date().getFullYear();
	}
	var tmp_array = Array();
	var tmp_day = this.day.toString();
	var tmp_month = this.month.toString();
	var tmp_year = this.year.toString();
	tmp_array[this.daypos] = (tmp_day.length < 2) ? '0' + tmp_day : tmp_day;
	tmp_array[this.monthpos] = (tmp_month.length < 2) ? '0' + tmp_month : tmp_month;
	tmp_array[this.yearpos] = tmp_year;
	var ret = '';
	for(i=0;i < tmp_array.length;i++) {
		if (tmp_array[i] != '' && tmp_array[i] != null) {
			ret += tmp_array[i] + "/";
		}
	}
	ret += 'RP';
	ret = ret.replace('/RP', '');
	this.value = ret;
	this.update_properties();
	if(cancelevent != true) { this.onValueChange(); }
	document.getElementById(this.name + "_date").focus();
}

function set_value(day,month,year,cancelevent) {

	this.day = parseInt(day);
	this.month = parseInt(month);
	year = parseInt(year);
	this.year = (year < 200) ? (year + 2000) : year;
	if (this.initalized == false) {
		this.initalized = true;	
		this.init_day = (!isNaN(day)) ? day : new Date().getDate();
		this.init_month = (!isNaN(month)) ? month : new Date().getMonth() + 1;
		this.init_year = (!isNaN(year)) ? year : new Date().getFullYear();
	}
	var tmp_array = Array();
	var tmp_day = this.day.toString();
	var tmp_month = this.month.toString();
	var tmp_year = this.year.toString();
	tmp_array[this.daypos] = (tmp_day.length < 2) ? '0' + tmp_day : tmp_day;
	tmp_array[this.monthpos] = (tmp_month.length < 2) ? '0' + tmp_month : tmp_month;
	tmp_array[this.yearpos] = tmp_year;
	var ret = '';
	for(i=0;i < tmp_array.length;i++) {
		if (tmp_array[i] != '' && tmp_array[i] != null) {
			ret += tmp_array[i] + "/";
		}
	}
	ret += 'RP';
	ret = ret.replace('/RP', '');
	this.value = ret;
	this.update_properties();
	if(cancelevent != true) { this.onValueChange(); }
	document.getElementById(this.name + "_date").focus();
}

function expand() {
	var obj_Calendar = document.getElementById("CALLYR_" + this.name);
	var obj_CalendarSH = document.getElementById("CALLYR_" + this.name + "_SHADOW");
	if (obj_Calendar.style.visibility != "visible") {
		if (this.posLeft == -1 && this.posTop == -1) { this.getMyXY(); }
		var clX = this.posLeft;
		var clY = this.posTop;
		if (isIE || isKo) {
			obj_Calendar.style.posLeft = clX + 10;
			obj_CalendarSH.style.posLeft = clX + 13;
			obj_Calendar.style.posTop = clY + 34;
			obj_CalendarSH.style.posTop = clY + 42;
		} else {
			obj_Calendar.style.left = clX - 1;
			obj_CalendarSH.style.left = clX + 5;
			obj_Calendar.style.top = clY + 19;
			obj_CalendarSH.style.top = clY + 24;
		}
		this.showWindowedObjects(false);
		obj_Calendar.style.visibility = "visible";
		if (this.main_shadow == true) {	obj_CalendarSH.style.visibility = "visible"; }
		this.calendar_visible = true;
	} else {
		this.compress();		
	}
	this.calendar_visibility = obj_Calendar.style.visibility;
	this.draw();
	this.onExpand();
}

function monthselector_expand() {
	var obj1 = document.getElementById("CALLYR_" + this.name + "_MESES");
	var obj2 = document.getElementById("CALLYR_" + this.name + "_MESES_SHADOW");
	if (this.posLeft == -1 && this.posTop == -1) { this.getMyXY(); }
	var clX = this.posLeft;
	var clY = this.posTop;
	obj1.style.height = 170;
	obj2.style.height = 170;
	if (isOp) {
		obj1.style.width = 80;
		obj2.style.width = 70;
	} else {
		obj1.style.width = 70;
		obj2.style.width = 70;
	}
	
	if (isIE || isKo) {
		obj1.style.posLeft = clX + 30;
		obj2.style.posLeft = clX + 44;
		obj1.style.posTop = clY - 47;
		obj2.style.posTop = clY - 35;
	} else {
		obj1.style.left = clX + 30;
		obj2.style.left = clX + 44;
		obj1.style.top = clY - 47;
		obj2.style.top = clY - 33;
	}
	obj1.style.visibility = "visible";
	if (this.month_shadow == true) { obj2.style.visibility = "visible";}
}

function showWindowedObjects(show) {
	// Esta function no es de mi autoria, fue obtenido en un foro, no conozco el autor :(
	// This function isn't mine, was downloaded of a forum, i don't know the author's name.
	if (isIE || isKo) {
		var windowedObjectTags = new Array("SELECT", "OBJECT","APPLET","EMBED","IFRAME");
		var windowedObjects = new Array();
		var j=0;
		for (var i = 0; i < windowedObjectTags.length; i++) {
			var tmpTags = document.all.tags(windowedObjectTags[i]);
			if (tmpTags.length > 0) {
				for (var k=0; k < tmpTags.length; k++) {
					windowedObjects[j++] = tmpTags[k];
				}
			}
		}
		for (var i = 0; i < windowedObjects.length; i++) {
			windowedObjects[i].visBackup = "";
			if (!show)
				windowedObjects[i].visBackup = (windowedObjects[i].style.visibility == null) ? "visible" : windowedObjects[i].style.visibility;
				windowedObjects[i].style.visibility = (show) ? windowedObjects[i].visBackup : "hidden";
		}
	}
}

function date_move(part,cantidad) {
	
	cantidad = parseInt(cantidad);
	switch (part) {
		case 'd': case 'D':
			this.day += cantidad;
			break;
		case 'm': case 'M':
			if (cantidad < 0 && this.month == 1) {
				this.month = 12;this.year--;
			} else {
				this.month += cantidad;
				if (this.month > 12) {
					this.month = this.month - 12;
					this.year++;	
				}
			}
			break;
		case 'y': case 'Y':
			this.year += cantidad;
			break;
	}
	var tmp = this.make_date(this.month, this.day, this.year);
	this.day = tmp.getDate();
	this.month = (tmp.getMonth() + 1);
	this.year = tmp.getFullYear();
	this.set_value(this.day,this.month,this.year);
}

function textbox_key(evt) {

	var a = evt.keyCode;
	var tmp_expand = false;
	switch (a) {
		case 13:
			this.parse_date();
			this.expand();
			break;
		case 27:
			this.compress();
			break;
		case 40: case 57386:
			if (this.calendar_visible == true) { this.date_move("d",7); } tmp_expand = true;
			break;
		case 38: case 57385:
			if (this.calendar_visible == true) { this.date_move("d",-7); } tmp_expand = true;
			break;
		case 39: case 57388:
			if (this.calendar_visible == true) { this.date_move("d",1); } tmp_expand = true;
			break;
		case 37: case 57387:
			if (this.calendar_visible == true) { this.date_move("d",-1); } tmp_expand = true;
			break;
	}
	if (tmp_expand == true && this.calendar_visible != true) { this.expand(); }
}