function fGetDate_DD_MM_YYYY(sObject, sCode) {
var sDate;
if (sCode == null) {
    sCode = 'fSetDate_DD_MM_YYYY("' + sObject + '"); ';
    };
sDate = "sDate = document.forms." + sObject + "_day.options[document.forms." + sObject + "_day.selectedIndex].value" + " + '-' + " + "document.forms." + sObject + "_month.options[document.forms." + sObject + "_month.selectedIndex].value" + " + '-' + " + "document.forms." + sObject + "_year.value";

eval(sDate);
sObject = "document.forms." + sObject + "_date.value";
showCalendar(sDate, sObject, sCode)
}

function fSetDate_DD_MM_YYYY(sObject) {
var sDate = "sDate = document.forms." + sObject + "_date.value";
eval(sDate);
var a = new fStrToDate(sDate);
a[1] = a[1] + 1;

sDate = "document.forms." + sObject + "_year.value = a[2]";
eval(sDate);
sDate = "document.forms." + sObject + "_month.selectedIndex = a[1]";
eval(sDate);
sDate = "document.forms." + sObject + "_day.selectedIndex = a[0]";
eval(sDate);
sDate = "document.forms." + sObject + "_year.focus()";
eval(sDate);
}

function showCalendar(sDate, sObject, sCode){
if (sCode == null) { sCode = ""; };
var Calendar=layer('idCalendar');
var y;
if (mouseY > 15) { y = mouseY - 12; }
else { y = 5; };
Calendar.move(mouseX, y);
fDrawCal(sDate, sObject, sCode);
Calendar.show();
}

function fDaysInYear(iYear){
var aDays = new Array(12);
aDays[0] = 31;
aDays[1] = 28;
aDays[2] = 31;
aDays[3] = 30;
aDays[4] = 31;
aDays[5] = 30;
aDays[6] = 31;
aDays[7] = 31;
aDays[8] = 30;
aDays[9] = 31;
aDays[10] = 30;
aDays[11] = 31;
if (((iYear % 4 == 0) && (iYear % 100 != 0)) || (iYear % 400 == 0)) aDays[1] = 29;
return aDays;
}

function fStrToDate(s){
var x = "";
var i = 0;
var c = 0;
var l = s.length-1;
var symbol = "";
var a = new Array(3);
var d = new Date();
a[0] = d.getDate();
if (a[0] >= 28) { a[0] = 28; d.setDate(a[0]); };
a[1] = d.getMonth();
a[2] = d.getFullYear();
a[1]++;
for (i=0; i<=l; i++) {
symbol = s.charAt(i);
if ((symbol == ".") || (symbol == "/") || (symbol == "-")) { if (x != "") { a[c] = x; }; c++; x=""; }
else if ((symbol == "1") || (symbol == "2") || (symbol == "3") || (symbol == "4") || (symbol == "5") || (symbol == "6") || (symbol == "7") || (symbol == "8") || (symbol == "9")) { x += symbol; }
else if (symbol == "0") { if (x.length >= 1) { x += symbol; }; };
if (c >= 3) { i=l+1; };
}
if (x != "") { a[c] = x; };
if (a[2] < 10) { a[2] = parseInt(a[2]) + 2000; };
if (a[2] < 100) { a[2] = parseInt(a[2]) + 1900; };
d.setFullYear(a[2]);
if (a[1] > 12) { a[1] = 12; }; d.setMonth(a[1]-1);
var aDays = fDaysInYear(a[2]);
if (a[0] > aDays[a[1]-1]) { a[0] = aDays[a[1]-1]; }; d.setDate(a[0]);
a[0] = d.getDate();
a[1] = d.getMonth();
a[2] = d.getFullYear();
return a;
}

function fDrawCal(sDate, sObject, sCode){
var iCellWidth=17;
var iCellHeight=12;
var a = new fStrToDate(sDate);
if (a[1] < 0) { a[1]=0; };
var iYear=a[2];
var iMonth=a[1];
var sImage = "/scripts/img/close.gif";
var iWImage = 16;
var iHImage = 16;
var i = 0;
var iColumn = 0;
var iDays = 0;
var Calendar = layer('idCalendar');
var dPrevDate = new Date(iYear, iMonth);
if (iYear < 1) { iYear = dCurDate.getFullYear(); };
var aDays = fDaysInYear(iYear);
var sCal = "";
var sYears = "";
var sDate = "";
var sSCode = "";
if (sCode == null) {
  sCode = "";
  }
else {
  var sCal = sCode.length;
  for (i=0; i<sCal; i++) {
    sYear = sCode.charAt(i);
    if (sYear != '"') { sSCode = sSCode + sYear; }
    else { sSCode = sSCode + "\\" + sYear; };
    }
  sCal = "";
  sYear = "";
  };
iColumn = iYear - 5;
iDays = iColumn + 10;
for (i=iColumn; i<=iDays; i++) {
if (i == iYear) { sYears = sYears + "<OPTION selected value='" + i + "'>" + i + "</OPTION>"; }
else { sYears = sYears + "<OPTION value='" + i + "'>" + i + "</OPTION>"; };
}
var dFirstDay = dPrevDate;
iColumn = 0;
dFirstDay.setDate(1);
var iStartDay = dFirstDay.getDay();
sCal = "<TABLE class='LW_BORDER' width='100%' border='0' cellspacing='1' cellpaddin='1'><TR>";
var CDate = new Date();
for (i=0; i<iStartDay; i++) {
sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>&nbsp;</TD>";
iColumn++;
}
iDays = aDays[iMonth];
aDays[0] = 0; aDays[1] = 0;
for (i=1; i<=iDays; i++) {
aDays[0] = i; aDays[1] = iMonth; aDays[1]++;
sDate = '';

if (aDays[0] <= 9) { sDate = sDate + "0" + aDays[0] + "."; }
else { sDate = sDate + "" + aDays[0] + "."; };
if (aDays[1] <= 9) { sDate = sDate + "0" + aDays[1] + "."; }
else { sDate = sDate + "" + aDays[1] + "."; };
sDate = sDate + iYear;

if ((iYear == CDate.getFullYear() && (iMonth == CDate.getMonth()) && (i == CDate.getDate())))  {
    sCal = sCal + "<TD class='LW_CURRENT_DATE' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>";
    sCal = sCal + "<A class='LW_LINKS' href='javascript:{ " + sObject + "=\"" + sDate + "\"; layer(\"idCalendar\").hide(); " + sCode + "}'><B>" + i + "</B></A>&nbsp;";
    }
else {
    sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>";
    sCal = sCal + "<A class='LW_LINKS' href='javascript:{ " + sObject + "=\"" + sDate + "\"; layer(\"idCalendar\").hide(); " + sCode + "}'>" + i + "</A>&nbsp;";
    };
iColumn++;
sCal = sCal + "</TD>";
if (iColumn == 7) {
sCal = sCal + "</TR><TR>";
iColumn = 0;
}
}
for (i=iColumn; i<=6; i++) {
sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>&nbsp;</TD>";
iColumn++;
}
sCal = sCal + "</TR></TABLE>";
for (i=0; i<=11; i++) {
aDays[i] = "";
}
aDays[iMonth]=" selected";
Calendar.write("<FORM name='frmCalendar' method='post' action=''>\
<TABLE width='150' class='LW_BORDER' border='0' cellspacing='0' cellpadding='1'>\
<TR><TD class='LW_TITLE' width='55%'>\
<SELECT class='F_SELECT' name='tbSelMonth' onchange='fDrawCal(\"" + a[2] + "\" + \".\" + (parseInt(document.forms.frmCalendar.tbSelMonth.options[document.forms.frmCalendar.tbSelMonth.selectedIndex].value) + 1) + \".\" + document.forms.frmCalendar.tbSelYear.options[document.forms.frmCalendar.tbSelYear.selectedIndex].value, \"" + sObject + "\", \"" + sSCode + "\")'>\
<OPTION" + aDays[0] + " value='0'>" + C_MONTHS[0] + "</OPTION>\
<OPTION" + aDays[1] + " value='1'>" + C_MONTHS[1] + "</OPTION>\
<OPTION" + aDays[2] + " value='2'>" + C_MONTHS[2] + "</OPTION>\
<OPTION" + aDays[3] + " value='3'>" + C_MONTHS[3] + "</OPTION>\
<OPTION" + aDays[4] + " value='4'>" + C_MONTHS[4] + "</OPTION>\
<OPTION" + aDays[5] + " value='5'>" + C_MONTHS[5] + "</OPTION>\
<OPTION" + aDays[6] + " value='6'>" + C_MONTHS[6] + "</OPTION>\
<OPTION" + aDays[7] + " value='7'>" + C_MONTHS[7] + "</OPTION>\
<OPTION" + aDays[8] + " value='8'>" + C_MONTHS[8] + "</OPTION>\
<OPTION" + aDays[9] + " value='9'>" + C_MONTHS[9] + "</OPTION>\
<OPTION" + aDays[10] + " value='10'>" + C_MONTHS[10] + "</OPTION>\
<OPTION" + aDays[11] + " value='11'>" + C_MONTHS[11] + "</OPTION>\
</SELECT>\
</TD><TD width='40%' class='LW_TITLE' align='right'>\
<SELECT class='F_SELECT' name='tbSelYear' onchange='fDrawCal(\"" + a[2] + "\" + \".\" + (parseInt(document.forms.frmCalendar.tbSelMonth.options[document.forms.frmCalendar.tbSelMonth.selectedIndex].value) + 1) + \".\" + document.forms.frmCalendar.tbSelYear.options[document.forms.frmCalendar.tbSelYear.selectedIndex].value, \"" + sObject + "\", \"" + sSCode + "\")'>" + sYears + "</SELECT>\
</TD><TD width='" + iWImage +"' class='LW_TITLE' align='right'>\
<A href='javascript:layer(\"idCalendar\").hide()'><IMG hspace='4' alt='" + C_CLOSE + "' title='" + C_CLOSE + "' border='0' src='" + sImage + "' height='" + iHImage + "' width='" + iWImage +"'></A></TD>\
</TR>\
<TR>\
<TD colspan='3'>\
<TABLE class='LW_BORDER' width='100%' border='0' cellspacing='1' cellpadding='1'><TR>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[0] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[1] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[2] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[3] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[4] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[5] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[6] + "</TD></TR>\
</TABLE>" + sCal + "</TD></TR></TABLE></FORM>");
}

function fDrawCalendar(iYear, iMonth, l){
var iCellWidth=17;
var iCellHeight=12;

iYear = parseInt(iYear, 10);
iMonth = parseInt(iMonth, 10);
if (iYear < 1) { iYear = dCurDate.getFullYear(); };
if (iMonth < 1) { iMonth = 1; };
if (iMonth > 12) { iMonth = 12; };

iMonth--;
var i = 0;
var iColumn = 0;
var iRow = 0;
var iDays = 0;
var Calendar = layer(l);
var dPrevDate = new Date(iYear, iMonth);
var aDays = fDaysInYear(iYear);
var sCal = "";
var sDate = "";
var d_class = "";
var iDay = 0;

for (i = 0; i < iMonth; i++) {
iDay = iDay + aDays[i];
}

i = 0;

var dFirstDay = dPrevDate;
iColumn = 0;
dFirstDay.setDate(1);
var iStartDay = dFirstDay.getDay();
sCal = "<TABLE class='LW_BORDER' width='100%' border='0' cellspacing='1' cellpaddin='1'><TR>";
var CDate = new Date();
for (i=0; i<iStartDay; i++) {
sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>&nbsp;</TD>";
iColumn++;
}
iDays = aDays[iMonth];
aDays[0] = 0; aDays[1] = 0;
for (i=1; i<=iDays; i++) {
aDays[0] = i; aDays[1] = iMonth; aDays[1]++;
sDate = '';

if (aDays[0] <= 9) { sDate = sDate + "0" + aDays[0] + "."; }
else { sDate = sDate + "" + aDays[0] + "."; };
if (aDays[1] <= 9) { sDate = sDate + "0" + aDays[1] + "."; }
else { sDate = sDate + "" + aDays[1] + "."; };
sDate = sDate + iYear;

iDay++;
if (YEAR[iDay] >= 1) { d_class = 'LW_DATE_ON'; } else { d_class = 'LW_DATE_OFF'; };

if ((iYear == CDate.getFullYear() && (iMonth == CDate.getMonth()) && (i == CDate.getDate()))) {
    sCal = sCal + "<TD class='" + d_class + "' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>";
    sCal = sCal + "&nbsp;<A class='LW_LINKS' style='color: white;' href='javascript:{ if (YEAR[" + iDay + "] >= 1) { YEAR[" + iDay + "] = 0; } else { YEAR[" + iDay+ "] = 1; }; fDrawCalendar(" + iYear + ", " + (iMonth + 1) + ", \"" + l + "\"); }'><B>" + i + "</B></A>&nbsp;";
    }
else {
    sCal = sCal + "<TD class='" + d_class + "' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>";
    sCal = sCal + "&nbsp;<A class='LW_LINKS' style='color: white;' href='javascript:{ if (YEAR[" + iDay + "] >= 1) { YEAR[" + iDay + "] = 0; } else { YEAR[" + iDay + "] = 1; }; fDrawCalendar(" + iYear + ", " + (iMonth + 1) + ", \"" + l + "\"); }'><B>" + i + "</B></A>&nbsp;";
    };
iColumn++;
sCal = sCal + "</TD>";
if (iColumn == 7) {
sCal = sCal + "</TR><TR>";
iColumn = 0;
iRow++;
}
}
for (i=iColumn; i<=6; i++) {
sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>&nbsp;</TD>";
iColumn++;
}
if (iRow == 4) {
    iColumn = 0;
    sCal = sCal + "</TR><TR>";
    for (i=iColumn; i<=6; i++) {
    sCal = sCal + "<TD class='LW_BODY' align='right' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "'>&nbsp;</TD>";
    iColumn++;
    iRow++;
    }
    };
sCal = sCal + "</TR></TABLE>";

Calendar.write("<FORM name='frmCalendar' method='post' action=''>\
<TABLE width='150' class='LW_BORDER' border='0' cellspacing='0' cellpadding='1'>\
<TR><TD class='LW_TITLE'>&nbsp;" + C_MONTHS[iMonth] + ", " + iYear + "&nbsp;</TD></TR>\
<TR>\
<TD>\
<TABLE class='LW_BORDER' width='100%' border='0' cellspacing='1' cellpadding='1'><TR>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[0] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[1] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[2] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[3] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[4] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[5] + "</TD>\
<TD class='LW_BORDER' align='center'>" + C_DAYS[6] + "</TD></TR>\
</TABLE>" + sCal + "</TD></TR></TABLE></FORM>");
}
