var msg;
monthnames = new Array("Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień");
daynames = new Array("Nie","Pon","Wto","Śro","Czw","Pią","Sob");
monthdays = new Array(12);
monthdays[0]=31;monthdays[1]=28;monthdays[2]=31;monthdays[3]=30;monthdays[4]=31;monthdays[5]=30;monthdays[6]=31;monthdays[7]=31;monthdays[8]=30;monthdays[9]=31;monthdays[10]=30;monthdays[11]=31;

function op(vDate,vField,vForm){
reg=/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/;
//reg.test(vDate);
//if (vDate=='data'){
if (!(reg.test(vDate))){
cDate=new Date();
vDay=cDate.getDate();
vMonth=cDate.getMonth();
vYear=cDate.getYear();
if (vYear<1000) {
vYear+=1900;
}
}
else{
//alert(vDate);

//vDay=vDate.substr(0,2);
//vMonth=vDate.substr(3,2);
//vYear=vDate.substr(6,4);
vYear=vDate.substr(0,4);
vMonth=vDate.substr(5,2);
vDay=vDate.substr(8,2);
if (vMonth>0) vMonth--;
}

txt=getcal(vYear,vMonth,vDay,vField,vForm);
msg=open("","cal","toolbar=no,directories=no,menubar=no, width=280, height=180");
msg.document.open();
msg.document.write(txt);
msg.document.close();
//setTimeout('msg.focus()',500);
msg.focus();
}

function getcal(vYear,vMonth,vDay,vField,vForm)
{
todayDate=new Date(vYear,vMonth,vDay);
thisday=todayDate.getDay();
thismonth=todayDate.getMonth();
thisyear=todayDate.getYear();
thisdate=todayDate.getDate();
thisyear = thisyear % 100;
thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear));
if (((thisyear % 4 == 0) && !(thisyear % 100 == 0)) ||(thisyear % 400 == 0)) {
monthdays[1]=29;
}
else{
monthdays[1]=28;
};
startspaces=thisdate;
while (startspaces > 7) startspaces-=7;
startspaces = thisday - startspaces + 1;
if (startspaces < 0) startspaces+=7;

if(vMonth == 0) { prevm=12; prevy=vYear-1;}
else { prevm=vMonth; prevy=vYear; };

if(vMonth == 11) { nextm=1; nexty=parseInt(vYear)+1;} 
else {nextm=vMonth+2;nexty=vYear;};
curry=parseInt(vYear);
currm=vMonth+1;
if (prevm < 10) prevm="0"+prevm;
if (currm < 10) currm="0"+currm;
if (nextm < 10) nextm="0"+nextm;

caltext = "";
caltext += "<html><head><title>Zespół ogłoszeniowy DTK & W - www.oferty-biznesowe.pl</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\"><link rel=\"stylesheet\" href=\"stile.css\" type=\"text/css\"></head>";
caltext += "<body bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">";

caltext += "<table width=\"100%\" align=\"center\" border=0 cellpadding=\"0\"";
//caltext += "<table align=\"center\" border=0 cellpadding=1 bgcolor=\"#CCCCCC\" color=\"#000066\"";
caltext += ">";
caltext += "<tr><td style=\"color: #000000; background: #F7F7F7\" colspan=7><center><strong>"; 
caltext = caltext + monthnames[thismonth] + " " + thisyear; 
caltext += "</strong></center></td></tr>";

caltext += "<tr><td style=\"color: #000000; background: #F7F7F7\" colspan=2>"; 
caltext += "<input type=\"button\" name=\"b1\" title=\"\" value=\"<<\" onclick=\"opener.op('"+(curry-1)+"-"+currm+"-01','"+vField+"','"+vForm+"');\">";
caltext += "<input type=\"button\" name=\"b2\" value=\"<\" onclick=\"opener.op('"+prevy+"-"+prevm+"-01','"+vField+"','"+vForm+"');\">";
//caltext += "<input type=\"button\" name=\"b1\" title=\"\" value=\"<<\" onclick=\"opener.op('01-"+currm+"-"+(curry-1)+"','"+vField+"','"+vForm+"');\">";
//caltext += "<input type=\"button\" name=\"b2\" value=\"<\" onclick=\"opener.op('01-"+prevm+"-"+prevy+"','"+vField+"','"+vForm+"');\">";
caltext += "</td>";
caltext += "<td style=\"color: #000000; background: #F7F7F7\" colspan=3><center><strong>"; 
caltext = caltext + monthnames[thismonth]; 
caltext += "</strong></center></td>";
caltext += "<td style=\"color: #000000; background: #F7F7F7\" colspan=2 align=\"right\">"; 
caltext += "<input type=\"button\" name=\"b3\" value=\">\" onclick=\"opener.op('"+nexty+"-"+nextm+"-01','"+vField+"','"+vForm+"');\">";
caltext += "<input type=\"button\" name=\"b4\" value=\">>\" onclick=\"opener.op('"+(curry+1)+"-"+currm+"-01','"+vField+"','"+vForm+"');\">";
//caltext += "<input type=\"button\" name=\"b3\" value=\">\" onclick=\"opener.op('01-"+nextm+"-"+nexty+"','"+vField+"','"+vForm+"');\">";
//caltext += "<input type=\"button\" name=\"b4\" value=\">>\" onclick=\"opener.op('01-"+currm+"-"+(curry+1)+"','"+vField+"','"+vForm+"');\">";
caltext += "</td></tr>\n";

caltext += "<tr>";
//caltext = caltext + "<td><font color='#b60000'>"+daynames[0]+"</font></td>\n";
//caltext = caltext + "<td>"+daynames[1]+"</td>\n";
//caltext = caltext + "<td>"+daynames[2]+"</td>\n";
//caltext = caltext + "<td>"+daynames[3]+"</td>\n";
//caltext = caltext + "<td>"+daynames[4]+"</td>\n";
//caltext = caltext + "<td>"+daynames[5]+"</td>\n";
//caltext = caltext + "<td>"+daynames[6]+"</td>\n"; 
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center><font color='#b60000'>"+daynames[0]+"</font></td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[1]+"</td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[2]+"</td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[3]+"</td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[4]+"</td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[5]+"</td>\n";
caltext = caltext + "<td style=\"color: #000000; background: #F7F7F7\" align=center>"+daynames[6]+"</td>\n"; 
caltext += "</tr>\n";
caltext += "<tr>";

for (s=0;s<startspaces;s++) {
caltext += "<td style=\"color: #000000; background: #F7F7F7\" > </td>";
}
count=1;

while (count <= monthdays[thismonth]) {
if (count>1) caltext += "<tr>";
sun=0;
for (b = startspaces;b<7;b++) {
caltext += "<td style=\"color: #000000; background: #F7F7F7\"  >";
currd=count;
if (currd < 10){
currd="0"+currd;
}

if (count <= monthdays[thismonth]) {
caltext = caltext + "<a title=\"" + currd + "-" + currm + "-" + thisyear +"\"href=\"javascript:opener.document.getElementById('"+vForm+"')."+vField+".value='" + thisyear + "-" + currm + "-" + currd +"'; window.close();\">";
//caltext = caltext + "<a title=\"" + currd + "-" + currm + "-" + thisyear +"\"href=\"javascript:opener."+vForm+"."+vField+".value='" + currd + "-" + currm + "-" + thisyear +"'; window.close();\">";
}
else {
caltext += " ";
}

if (count==thisdate) {
caltext += "<font color='000000'><strong>";
if (startspaces==0) sun=1;
}
else if ((startspaces==0) && (sun==0)) {
caltext += "<font color='b60000'><strong>";
sun=1;
}

if (count <= monthdays[thismonth]) {
caltext += count;
}
else {
caltext += " ";
}

if ((count==thisdate) || (startspaces==0)) {
caltext += "</strong></font>";
}

if (count <= monthdays[thismonth]) {
caltext += "</a>";
}
else {
caltext += " ";
}

caltext += "</td>\n";
count++;
}
caltext += "</tr>\n";
startspaces=0;
}
caltext += "<tr><td colspan=\"7\"><br>\n";
caltext = caltext + "<a title=\"Wyczyść\" href=\"javascript:opener.document.getElementById('"+vForm+"')."+vField+".value=''; window.close();\">";
caltext += "Wyczyść</a>";
caltext += "</tr></td>\n";
caltext += "</table></p>";
caltext += "</body></html>";
return caltext;
}

