function checkValidity() {
    var v1= document.forms[0].startvdate;
    var v2= document.forms[0].stopvdate;
    var v, a;
    if (typeof(v1)=="undefined") {
        return true;
    }
    if (typeof(v2)=="undefined") {
        return true;
    }
    v = v1.value.split("-");
    a = v2.value.split("-");
    var vy = parseInt(v[2]);
    var ay = parseInt(a[2]);
    if (vy > ay) return false;
    if (vy < ay) return true;
    var vm = parseInt(v[0]);
    var am = parseInt(a[0]);
    if (vm > am) return false;
    if (vm < am) return true;
    var vd = parseInt(v[1]);
    var ad = parseInt(a[1]);
    if (vd > ad) return false;
    return true;
} // checkValidity()

function DoCalRet( returnValue ) {
    if (returnValue!="") {
        var p = doCalTarget.value;
        doCalTarget.value = returnValue;
        if (doCalTarget.onchange) {
          doCalTarget.onchange();
        }
//      if (checkValidity() == false) {
//          doCalTarget.value = p;
//          alert("Nem érvényes dátumválasztás\nAz érvényesség kezdete nem lehet korábban a végénél!");
//      }
     }
} //DoCalRet

function DoCal(elTarget) {
    doCalTarget = elTarget;
    var w = new modalWindow(390,237);
    w.onclose = DoCalRet;
    w.open("html/portal/calendar.htm","");
} // DoCal

function getDays(month, year) {
    // Test for leap year when February is selected.
    if (1 == month)
        return ((0 == year % 4) && (0 != (year % 100))) ||
               (0 == year % 400) ? 29 : 28;
     else
        return daysInMonth[month];
}

function getToday() {
    // Generate today's date.
    this.now = new Date();
    this.year = this.now.getFullYear();
    this.month = this.now.getMonth();
    this.day = this.now.getDate();
}

function newCalendar() {
    today = new getToday();
    var parseYear = parseInt(document.getElementById('year')
    [document.getElementById('year').selectedIndex].text);
    var newCal = new Date(parseYear,
    document.getElementById('month').selectedIndex, 1);
    var day = -1;
    var startDay = newCal.getDay() -1;
    // Atforditjuk a napot a magyar formara
    if (startDay==-1) startDay=6;
    var daily = 0;
    if ((today.year == newCal.getFullYear()) &&
       (today.month == newCal.getMonth()))
        day = today.day;
    // Cache the calendar table's tBody section, dayList.
    var tableCal = document.getElementById('dayList');
    var intDaysInMonth = getDays(newCal.getMonth(), newCal.getFullYear());
    for (var intWeek = 0; intWeek < tableCal.rows.length; intWeek++) {
        for (var intDay = 0; intDay < tableCal.rows[intWeek].cells.length; intDay++) {
             var cell = tableCal.rows[intWeek].cells[intDay];
             // Start counting days.
             if ((intDay == startDay) && (0 == daily))
             daily = 1;

             // Highlight the current day.
             cell.className = (day == daily) ? "today" : "";

             // Output the day number into the cell.
             if ((daily > 0) && (daily <= intDaysInMonth))
                 cell.innerHTML = daily++;
              else
                  cell.innerHTML = "";
         }
     }
}

function getDate(event) {
    var sDate, month, day;
    // This code executes when the user clicks on a day in the calendar.
    if ("TD" == event.tagName) {
        // Test whether day is valid.
        if ("" != event.innerHTML) {
            month = document.getElementById('month').value;
            if (month<10) {
                month = "0" + month;
            }
            day = event.innerHTML;
            if (day<10) {
                day = "0" + day ;
            }
            sDate = document.getElementById('year').value + "-" + month + "-" + day;
            window.returnValue = sDate;
            window.close();
        }
     }
}

function Cancel() {
    window.returnValue = "";
    window.close();
}

window.returnValue = "";

var doCalTarget = null;

window.returnValue = "";

// Initialize arrays.
var months = new Array("január", "február", "március", "április", "május", "június", "július", 
                        "augusztus", "szeptember", "október", "november", "december");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array("hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat", "vasárnap");

// Start with a calendar for today.
var today = new getToday();

