
// escaping from frame
function changePage() {
  // http://www.weethet.nl/english/html_breakout.php
  if (self.parent.frames.length != 0)
    self.parent.location = location; //"http://www.somewhere.com";
}

function escapeFromFrame() {
  //http://www.cambiaresearch.com/c4/bea3f67f-6c06-482c-9551-88dff655af8f/How-Do-I-Keep-My-Website-From-Being-Viewed-In-a-Frame.aspx
  //if (top != self) top.location = location;

  //http://www.webreference.com/js/column36/escaping.html
  //if (window != top) top.location.href = location.href;

  //http://www.weethet.nl/english/html_breakout.php
  setTimeout ("changePage()", 1000);
}
// /escaping from frame


// redirect browser to specified URL
function goToURL(url) { 
  window.location = url;
  // e.g.:
  //<form>
  //<input type=button value="My Place" onClick="goToURL("http://www.myplace.50g.com")">
  // </form> ; 
  //
}

// uncheck, check or toggle all checkboxes of chb (mode=0,1,2 respectively)
function checkBoxCheckAll(field, mode) {
    if (!field.length) {
      if (mode == 0) {
        field.checked = false;
        return "Check All";
      } else if (mode == 1) {
        field.checked = true;
        return "Uncheck All";   
      } else {
        field.checked = ! field.checked;
        return "Toggle All";
      }
    }
    
    if (mode == 0) {
        for (i = 0; i < field.length; i++) {
            field[i].checked = false;
        }   
        return "Check All"; 
    } else if (mode == 1) {
        for (i = 0; i < field.length; i++) {
            field[i].checked = true; 
        }
        return "Uncheck All"; 
    } else {
        for (i = 0; i < field.length; i++) {
            field[i].checked = ! field[i].checked; 
        }
        return "Toggle All"; 
    }
}
// return True if at least something is checked
function checkBoxChecked(field) {
    //alert(getObjProps(field));

    var cnt = 0;
    if (!field.length) {
       if (field.checked) cnt++;
    } else {
        for (i = 0; i < field.length; i++) {
            if (field[i].checked) cnt++;
        }
    }   
    return cnt;
}

// Return false if none of the checkboxes is checked and report it to the user.
// If there is just one checkbox and it is unchecked, it can be forced to checked
// state (and returning true without error message) by setting checkIfJustOne
// parameter true. (This probably should not be used for destructive actions.)
function reportUncheckedBoxes(fld, checkIfJustOne, askconfirm) {
  if (!checkBoxChecked(fld)) {
     if (!fld.length && checkIfJustOne) {
       checkBoxCheckAll(fld)
       return true;       
     }
     /*alert('Vyberte (zaškrtnutím) nejdříve nějaký záznam.'); */
     alert('Select some records first (use the checkboxes).');
     return false;
  } else {
    if ((askconfirm === undefined) || (askconfirm == "")) {
        // confirmation of the action is not required 
        return true;
    } else {
        //
        if (confirm(askconfirm)) {
           return true;
        } else {
           return false;
        }
    }
  }
}


function reportUncheckedBoxesOrSubmit(fld, checkIfJustOne) {
  if (reportUncheckedBoxes(fld.form.ids, checkIfJustOne)) {
    if (fld.form.action_key) {
      fld.form.action_key.value = fld.name;
    };
    fld.form.submit();
    return true;
  } else {
    return false;
  };
}


// handling keypress
function onKeyPressInit() {
    document.onkeypress = onKeyPress;
}
function onKeyPressDone() {
    document.onkeypress = null;
}

function onKeyPress () {
    var keycode;
    if (window.event) 
        keycode = window.event.keyCode;
    else if (e) 
        keycode = e.which;
    else 
        return true;
    if (keycode == 13) {
        alert("Please Click on the Submit button to send this");
        return false
    }
    return true
}

// open new browser window
function windowOpen(url, name, params) {
  if (!url) url = "";
  if (!name) name = "msg";
  if (!params) params = ""; //"height=200,width=400,left=80,top=80"; 
  msg = window.open(url, name, params);
  if (!url) {
    msg.document.write("<html><title>Windows!</title>");
    msg.document.write("<body bgcolor='white' onblur=window.close()>");
    msg.document.write("<center> page content here</center>");
    msg.document.write("</body></html><p>");
  }                           
  return msg
// If you just want to open an existing HTML page in the 
// new window, you can replace win()'s coding above with:
// window.open("page.html","","height=200,width=200,left=80,top=80");

}

function random(max) {
    return 1+Math.round(Math.random()* max);   // a = random number between 1-max
}

//browserInfo
// create part of the document containing info about browser using inline script tag, that is calling
// this function
function browserInfoWrite() {
    var 
        ary = new Array("appCodeName", "appName", "appVersion", "mimeTypes", "plugins", "userAgent", "javaEnabled()+''", "X", "width+''", "height+''", "colorDepth+''", "X", "history.length+''");
        box = new Array("<input type='text' size=30 value='","'>", "<select onchange='browserInfoMore(this,this.form);'>", "", "<input type='text' size=6 value='","'>");
        cnt = 0; 
        fmtcnt = 0; 
        bgn = new Array("navigator","screen","window");
        
    for(i = 0; i < ary.length - 2; i++) {
        b = 0; 
        if(ary[i + cnt] == "X") cnt++;
        val = eval(bgn[cnt]+"."+ary[i+cnt]); 
        fmt="<br>\n";
        l=val.length; 
        if(l>0) {
            if(val.toString().indexOf('Array',0)>-1) {
                val=""; 
                b=2; 
                box[3] = "</select>" + box[4] + eval(bgn[cnt] + "." + ary[i + cnt] + ".length") + box[5];
                for (j = 0; j < l ; j++)
                    val+="<option value="+i+">"+eval(bgn[cnt]+"."+ary[i+cnt]+"["+j+"].description").substring(0,30); 
            };
            if(ary[i+cnt].indexOf("+''",0)>0) {
                b=4; 
                fmtcnt = (fmtcnt + 1) % 3;
                if(fmtcnt>0) fmt="\n";
                ary[i+cnt]=ary[i+cnt].substring(0,escape(ary[i+cnt]).indexOf('%')-1); 
            };
            document.write(ary[i+cnt]+":"+box[b]+val+box[b+1]+fmt);
        }
    }
}

function browserInfoMore(sel, frm) {
    frm.ta.value=""; 
    cnt = 1; 
    nm = navigator.mimeTypes; 
    ssi = sel.selectedIndex;
    if (browserInfoDisplay(sel,frm,nm,ssi)==1)
    for (k = 0; k < nm.length; k++)
        if (isPluginEnabled(k))
            if (isPluginEnabled(k).name == navigator.plugins[ssi].name) {
                frm.ta.value+=cnt+")."; cnt++
                broserInfoDisplay(frm.elements[3],frm,nm,k);
            }
}

function browserInfoDisplay(sel,frm,nm,ssi) {
    which=sel.options[ssi].value-3;
    var prms=new Array();
    prms[0]=new Array("mimeTypes","description","suffixes","type","enabledPlugin.name");
    prms[1]=new Array("plugins","description","filename","length","name");
    ln=5; if(which==0) if(!isPluginEnabled(ssi)) ln=4;
    for(i=1;i<ln;i++)
    frm.ta.value+=prms[which][i]+":"+eval("navigator."+prms[which][0]+"["+ssi+"]."+prms[which][i])+"\n";
    return which;
}

function isPluginEnabled(n) {
    return navigator.mimeTypes[n].enabledPlugin;
}
///browserInfo


//browserInfo2
function browserInfo2() {
    var agt=navigator.userAgent.toLowerCase()
    this.major = parseInt(navigator.appVersion)
    this.minor = parseFloat(navigator.appVersion)
    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
    && (agt.indexOf('compatible') == -1)))
    this.nav2 = (this.nav && (this.major == 2))
    this.nav3 = (this.nav && (this.major == 3))
    this.nav4 = (this.nav && (this.major == 4))
    this.nav4up = this.nav && (this.major >= 4)
    this.navonly  = (this.nav && (agt.indexOf(";nav") != -1))
    this.ie   = (agt.indexOf("msie") != -1)
    this.ie3  = (this.ie && (this.major == 2))
    this.ie4  = (this.ie && (this.major == 4))
    this.ie4up  = this.ie  && (this.major >= 4)
    this.opera = (agt.indexOf("opera") != -1)
    if (this.nav2 || this.ie3) this.js = 1.0
    else if (this.nav3 || this.opera) this.js = 1.1
    else if (this.nav4 || this.ie4) this.js = 1.2
    else if ((this.nav && (this.minor > 4.05)) || (this.ie && (this.major > 4)))
     this.js = 1.2
    else this.js = 0.0
    this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) )
    this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1))
    this.win16 = ((agt.indexOf("win16")!=-1)
       || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1)
       || (agt.indexOf("windows 16-bit")!=-1) )
    
    this.win31 = (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
     (agt.indexOf("windows 16-bit")!=-1)
    this.win98 = ((agt.indexOf("win98")!=-1)||(agt.indexOf("windows 98")!=-1))
    this.winnt = ((agt.indexOf("winnt")!=-1)||(agt.indexOf("windows nt")!=-1))
    this.win32 = this.win95 || this.winnt || this.win98 ||
     ((this.major >= 4) && (navigator.platform == "win32")) ||
     (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1)
    this.os2   = (agt.indexOf("os/2")!=-1)
     || (navigator.appVersion.indexOf("os/2")!=-1)
     || (agt.indexOf("ibm-webexplorer")!=-1)
    this.mac= (agt.indexOf("mac")!=-1)
    this.mac68k = this.mac && ((agt.indexOf("68k")!=-1) ||
       (agt.indexOf("68000")!=-1))
    this.macppc = this.mac && ((agt.indexOf("ppc")!=-1) ||
       (agt.indexOf("powerpc")!=-1))
    this.sun   = (agt.indexOf("sunos")!=-1)
    this.sun4  = (agt.indexOf("sunos 4")!=-1)
    this.sun5  = (agt.indexOf("sunos 5")!=-1)
    this.suni86= this.sun && (agt.indexOf("i86")!=-1)
    this.irix  = (agt.indexOf("irix") !=-1)// sgi
    this.irix5 = (agt.indexOf("irix 5") !=-1)
    this.irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1))
    this.hpux  = (agt.indexOf("hp-ux")!=-1)
    this.hpux9 = this.hpux && (agt.indexOf("09.")!=-1)
    this.hpux10= this.hpux && (agt.indexOf("10.")!=-1)
    this.aix   = (agt.indexOf("aix")  !=-1)  // ibm
    this.aix1  = (agt.indexOf("aix 1")  !=-1)
    this.aix2  = (agt.indexOf("aix 2")  !=-1)
    this.aix3  = (agt.indexOf("aix 3")  !=-1)
    this.aix4  = (agt.indexOf("aix 4")  !=-1)
    this.linux = (agt.indexOf("inux")!=-1)
    this.sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1)
    this.unixware = (agt.indexOf("unix_system_v")!=-1)
    this.mpras= (agt.indexOf("ncr")!=-1)
    this.reliant  = (agt.indexOf("reliantunix")!=-1)
    this.dec   = (agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1)
       || (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1)
       || (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)
    this.sinix = (agt.indexOf("sinix")!=-1)
    this.freebsd = (agt.indexOf("freebsd")!=-1)
    this.bsd = (agt.indexOf("bsd")!=-1)
    this.unix  = (agt.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux ||
     this.sco ||this.unixware || this.mpras || this.reliant ||
     this.dec || this.sinix || this.aix || this.linux || this.freebsd
    this.vms   = (agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1)
}

var  browserInfo2;
     isie3mac = false;

function browserInfo2Write() {  
    if ((navigator.appVersion.indexOf("mac")!=-1) && (navigator.userAgent.indexOf("msie")!=-1) && 
       (parseInt(navigator.appVersion)==3))
        isie3mac = true;
    else   
    browserInfo2 = new browserInfo2();    

    document.write("browser info:  ");
    for (var propname in browserInfo2) {
        if (browserInfo2[propname] == 1) { document.write(propname + ' '); }
    }
    document.write(" ...  ");
    for (var propname in browserInfo2) {
        if (browserInfo2[propname] != 0 && browserInfo2[propname] != 1) {
            document.write(propname + ' = ' + browserInfo2[propname] + '  ');
        }
    }
}
///browserInfo2

//windowSizes
//function windowSizes() {
//    if (navigator.userAgent.indexOf("MSIE") > 0) {
//        this.clientWidth = document.body.clientWidth;
//        this.clientHeight = document.body.clientHeight;
//    } else {
//        this.clientWidth = window.outerWidth;
//        this.clientHeight = window.outerHeight;
//    }
//    this.screenwidth = screen.width;
//    this.screenheight = screen.height;
//}


//function windowSizesWrite() {
//  var ws = new windowSizes();
//  objWrite(ws, "")
//}

///windowSizes


function getObjProps(obj) {
  res = '';
  for (var pn in obj) {
     pv = obj[pn];
     res = res + pn + '="' + pv + '" ';
  }
  return res;
}

function objWrite(doc, obj, indent, recursive) {
    if (!indent) indent = '';
    if (indent == '') {
        doc.write('<pre>');
    }
    for (var pn in obj) {
        pv = obj[pn];
        doc.write(indent + pn + " = " + pv + "\n");
        if (recursive) {
            if (pv == "[object]") {
                objWrite(pv, indent + '  ');
            }
        }
    }
    if (indent == '') {
        doc.write("</pre>");
    } 
}

function writeNamedObjProps(objname) {
    w = windowOpen(); 
    obj = eval(objname);
    objWrite(w.document, obj);
}

//windowInfo
function windowInfoWrite(){
  objWrite(document, window, '', false);
  //for (var pn in window) {
  //  document.write(pn + " = " + window[pn] + " ");
  //}
}
///windowInfo



//datePicker - calendar
var firstDOW = 0; // 0 (sunday) for USA; 1 (monday for Euro) - not working
var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

//SCalendar.Months = ["January", "February", "March", "April", "May", "June",
//"July", "August", "September", "October", "November", "December"];
SCalendar.Months = ["Leden", "Únor", "Březen", "Duben", "Květen", "Červen",
"Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"];

// Non-Leap year Month days..
SCalendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
SCalendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function SCalendar(p_item, p_WinCal, p_month, p_year, p_format) {
    if ((p_month == null) && (p_year == null))  return;

    if (p_WinCal == null)
        this.gWinCal = ggWinCal;
    else
        this.gWinCal = p_WinCal;
    
    if (p_month == null) {
        this.gMonthName = null;
        this.gMonth = null;
        this.gYearly = true;
    } else {
        this.gMonthName = SCalendar.get_month(p_month);
        this.gMonth = new Number(p_month);
        this.gYearly = false;
    }

    this.gYear = p_year;
    this.gFormat = p_format;
    this.gBGColor = "white";
    this.gFGColor = "black";
    this.gTextColor = "black";
    this.gHeaderColor = "black";
    this.gReturnItem = p_item;
}

SCalendar.get_month = Calendar_get_month;
SCalendar.get_daysofmonth = Calendar_get_daysofmonth;
SCalendar.calc_month_year = Calendar_calc_month_year;
SCalendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
    return SCalendar.Months[monthNo];
}

function Calendar_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 SCalendar.DOMonth[monthNo];
    
        return SCalendar.lDOMonth[monthNo];
    } else
        return SCalendar.DOMonth[monthNo];
}

function Calendar_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;
}

function Calendar_print() {
    ggWinCal.print();
}

function Calendar_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 SCalendar();

SCalendar.prototype.getMonthlyCalendarCode = function() {
    var vCode = "";
    var vHeader_Code = "";
    var vData_Code = "";
    
    // Begin Table Drawing code here..
    vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
    
    vHeader_Code = this.cal_header();
    vData_Code = this.cal_data();
    vCode = vCode + vHeader_Code + vData_Code;
    
    vCode = vCode + "</TABLE>";
    
    return vCode;
}

SCalendar.prototype.show = function() {
    var vCode = "";
    
    this.gWinCal.document.open();

    // Setup the page...
    this.wwrite("<html>");
    this.wwrite("<head><title>Calendar</title>");
    this.wwrite("</head>");

    this.wwrite("<body " + 
        "link=\"" + this.gLinkColor + "\" " + 
        "vlink=\"" + this.gLinkColor + "\" " +
        "alink=\"" + this.gLinkColor + "\" " +
        "text=\"" + this.gTextColor + "\">");
    this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
    this.wwriteA(this.gMonthName + " " + this.gYear);
    this.wwriteA("</B><BR>");

    // Show navigation buttons
    var prevMMYYYY = SCalendar.calc_month_year(this.gMonth, this.gYear, -1);
    var prevMM = prevMMYYYY[0];
    var prevYYYY = prevMMYYYY[1];

    var nextMMYYYY = SCalendar.calc_month_year(this.gMonth, this.gYear, 1);
    var nextMM = nextMMYYYY[0];
    var nextYYYY = nextMMYYYY[1];
    
    this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
        ");" +
        "\"><<<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\"><<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\">><\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
        ");" +
        "\">>><\/A>]</TD></TR></TABLE><BR>");

    // Get the complete calendar code for the month..
    vCode = this.getMonthlyCalendarCode();
    this.wwrite(vCode);

    this.wwrite("</font></body></html>");
    this.gWinCal.document.close();
}

SCalendar.prototype.showY = function() {
    var vCode = "";
    var i;
    var vr, vc, vx, vy;     // Row, Column, X-coord, Y-coord
    var vxf = 285;          // X-Factor
    var vyf = 200;          // Y-Factor
    var vxm = 10;           // X-margin
    var vym;                // Y-margin
    if (isIE)   vym = 75;
    else if (isNav) vym = 25;
    
    this.gWinCal.document.open();

    this.wwrite("<html>");
    this.wwrite("<head><title>SCalendar</title>");
    this.wwrite("<style type='text/css'>\n<!--");
    for (i=0; i<12; i++) {
        vc = i % 3;
        if (i>=0 && i<= 2)  vr = 0;
        if (i>=3 && i<= 5)  vr = 1;
        if (i>=6 && i<= 8)  vr = 2;
        if (i>=9 && i<= 11) vr = 3;
        
        vx = parseInt(vxf * vc) + vxm;
        vy = parseInt(vyf * vr) + vym;

        this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
    }
    this.wwrite("-->\n</style>");
    this.wwrite("</head>");

    this.wwrite("<body " + 
        "link=\"" + this.gLinkColor + "\" " + 
        "vlink=\"" + this.gLinkColor + "\" " +
        "alink=\"" + this.gLinkColor + "\" " +
        "text=\"" + this.gTextColor + "\">");
    this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
    this.wwrite("Year : " + this.gYear);
    this.wwrite("</B><BR>");

    // Show navigation buttons
    var prevYYYY = parseInt(this.gYear) - 1;
    var nextYYYY = parseInt(this.gYear) + 1;
    
    this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\">>><\/A>]</TD></TR></TABLE><BR>");

    // Get the complete calendar code for each month..
    var j;
    for (i=11; i>=0; i--) {
        if (isIE)
            this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
        else if (isNav)
            this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

        this.gMonth = i;
        this.gMonthName = SCalendar.get_month(this.gMonth);
        vCode = this.getMonthlyCalendarCode();
        this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
        this.wwrite(vCode);

        if (isIE)
            this.wwrite("</DIV>");
        else if (isNav)
            this.wwrite("</LAYER>");
    }

    this.wwrite("</font><BR></body></html>");
    this.gWinCal.document.close();
}

SCalendar.prototype.wwrite = function(wtext) {
    this.gWinCal.document.writeln(wtext);
}

SCalendar.prototype.wwriteA = function(wtext) {
    this.gWinCal.document.write(wtext);
}

SCalendar.prototype.cal_header = function() {
 
   var vCode = "";
    
    vCode = vCode + "<TR>";
    if (firstDOW == 0)
       vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Ne</B></FONT></TD>";        
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Po</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Út</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>St</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Čt</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Pá</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>So</B></FONT></TD>";
    if (firstDOW != 0)
       vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Ne</B></FONT></TD>";        
    
    vCode = vCode + "</TR>";
    
    return vCode;
}

SCalendar.prototype.cal_data = function() {
    var vDate = new Date();
    vDate.setDate(1);
    vDate.setMonth(this.gMonth);
    vDate.setFullYear(this.gYear);

    var vFirstDay=vDate.getDay();
    var vDay=1;
    var vLastDay=SCalendar.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. 
    */

    vCode = vCode + "<TR>";
    for (i=0; i<vFirstDay; i++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
    }

    // Write rest of the 1st week
    for (j=vFirstDay; j<7; j++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
            "<A HREF='#' " + 
                "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
                this.format_data(vDay) + 
                "';window.close();\">" + 
                this.format_day(vDay) + 
            "</A>" + 
            "</FONT></TD>";
        vDay=vDay + 1;
    }
    vCode = vCode + "</TR>";

    // Write the rest of the weeks
    for (k=2; k<7; k++) {
        vCode = vCode + "<TR>";

        for (j=0; j<7; j++) {
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
                "<A HREF='#' " + 
                    "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
                    this.format_data(vDay) + 
                    "';window.close();\">" + 
                this.format_day(vDay) + 
                "</A>" + 
                "</FONT></TD>";
            vDay=vDay + 1;

            if (vDay > vLastDay) {
                vOnLastDay = 1;
                break;
            }
        }

        if (j == 6)
            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 WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
        else
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
    }
    
    return vCode;
}

SCalendar.prototype.format_day = function(vday) {
    var vNowDay = gNow.getDate();
    var vNowMonth = gNow.getMonth();
    var vNowYear = gNow.getFullYear();

    if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
        return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
    else
        return (vday);
}

SCalendar.prototype.write_weekend_string = function(vday) {
    var i;

    // Return special formatting for the weekend day.
    for (i=0; i<weekend.length; i++) {
        if (vday == weekend[i])
            return (" BGCOLOR=\"" + weekendColor + "\"");
    }
    
    return "";
}

SCalendar.prototype.format_data = function(p_day) {
    var vData;
    var vMonth = 1 + this.gMonth;
    vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
    var vMon = SCalendar.get_month(this.gMonth).substr(0,3).toUpperCase();
    var vFMon = SCalendar.get_month(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 "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;
        case "DD.MM.YYYY":
            vData = vDD + "." + vMonth + "." + vY4;
            break;

        default :
            vData = vMonth + "\/" + vDD + "\/" + vY4;
    }

    return vData;
}

function Build(p_item, p_month, p_year, p_format) {
    var p_WinCal = ggWinCal;
    gCal = new SCalendar(p_item, p_WinCal, p_month, p_year, p_format);

    // Customize your SCalendar here..
    gCal.gBGColor="white";
    gCal.gLinkColor="black";
    gCal.gTextColor="black";
    gCal.gHeaderColor="darkgreen";

    // Choose appropriate show function
    if (gCal.gYearly)   gCal.showY();
    else    gCal.show();
}

function xshow_calendar() {
    /* 
        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.
    */

    p_item = arguments[0];
    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 = "DD.MM.YYYY"; //p_format = "MM/DD/YYYY";
    else
        p_format = arguments[3];

    vWinCal = window.open("", "Calendar", 
        "width=250,height=250,status=no,resizable=no,top=200,left=200");
    vWinCal.opener = self;
    ggWinCal = vWinCal;

    Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
    // Load the defaults..
    if (p_year == null || p_year == "")
        p_year = new String(gNow.getFullYear().toString());
    if (p_format == null || p_format == "")
        p_format = "DD.MM.YYYY";//"MM/DD/YYYY";

    var vWinCal = window.open("", "Calendar", "scrollbars=yes");
    vWinCal.opener = self;
    ggWinCal = vWinCal;

    Build(p_item, null, p_year, p_format);
}
///datePicker


// HTML5 (see http://diveintohtml5.org/detect.html#canvas )
function supports_canvas() {
  return !!document.createElement('canvas').getContext;
}

///HTML5
