/************************************************************
                        created by @bystra 
                             08.05.2004  
************************************************************* */
var NoweOkno;
var DataField;

function kal(form){

DataField = form;
var v_data = form.value;

if (v_data.substring(0,1)==0) {var v_d = v_data.substring(1,2)}
else {var v_d = v_data.substring(0,2)};

if (v_data.substring(3,4)==0) {var v_m = v_data.substring(4,5)}
else {var v_m = v_data.substring(3,5)};

var v_y = v_data.substring(6,10);


window.document.forms[0].u_dzien.value = v_d;
window.document.forms[0].u_miesiac.value = v_m;
window.document.forms[0].u_rok.value = v_y;

if (NoweOkno && !NoweOkno.closed) 
{
NoweOkno.focus()
}
else
{
var h = 0;
if (!ie()) { if (fx()) h=190; else h=275} else h=190;
NoweOkno=window.open("","NoweOkno", 'titlebar=0,scrollbar=0,toolbar=0,menubar=0,locationbar=0,personalbar=0,statusbar=0, resizable=0,height='+h+',width=290,left=140,top=50');


if (NoweOkno.opener == null) {NoweOkno.opener = self};
}

kod(NoweOkno, v_d, v_m, v_y);
}


function odswiez(v_dzien){
kod( NoweOkno, v_dzien,
window.document.forms[0].u_miesiac.value,
window.document.forms[0].u_rok.value);
}



function kod(v_okno,v_d,v_m,v_y){

var s = '<html><head>';
s += '<meta http-equiv="content-type" content="text/html;charset=ISO-8859-2">';
s += '<title>Kalendarz</title>';
s += '<link href="style/kal.css" rel="stylesheet" type="text/css">';
s += '<script language="javascript">';
s += 'var podw = false; var timeoutID;';
s += 'function poj(v_dzien) {';
s += '';
s += '  if (!podw) {timeoutID = setTimeout("opener.odswiez("+v_dzien+")",300) };';
s += '  podw = false}';
s += 'function pod(v_dzien) {';
s += '  podw = true;';
s += '  opener.wybierz(v_dzien)}</script>';

s += '</head><body class="kalendarz"><center>';

/********* pola ukryte formularza *********/
s += '<form name="ukryty">';
s += '<input type="hidden" name="u_dzien" value="'+v_d+'">';
s += '<input type="hidden" name="u_miesiac" value="'+v_m+'">';
s += '<input type="hidden" name="u_rok" value="'+v_y+'">';


var miesiace = new Array("styczeń","luty","marzec","kwiecień","maj","czerwiec","lipiec","sierpień","wrzesień","pa¼dziernik","listopad","grudzień");

var dni_t = new Array("Pn","Wt","¦r","Cz","Pi","So","Nd");

// liczba_dni_miesiaca
var v_ldm = new Array("31","29","31","30","31","30","31","31","30","31","30","31");

if (v_y%4) {v_ldm[1]=28};


s += '<table border=0 width="250px" cellpadding=0 cellspacing=0 align=center>';

s += '<tr height="30px">';
s += '<td class="naglowek_miesiac" width="125px" colspan=2>'+tlumacz(miesiace[v_m-1])+'</td>';
s += '<td class="naglowek_rok" width="125px" colspan=2>'+v_y+'</td>';
s += '</tr>';

s += '<tr><td colspan=4>';

s += '<table class="kalendarz" border=0 width="250px" cellpadding=0 cellspacing=0 align=center>';
s += '<tr class="nazwy_dni">';
s += '<td width="35px" class="dzien_p">Pn</td>';
s += '<td width="35px" class="dzien_p">Wt</td>';
s += '<td width="35px" class="dzien_p">'+tlumacz(dni_t[2])+'</td>';
s += '<td width="35px" class="dzien_p">Cz</td>';
s += '<td width="35px" class="dzien_p">Pi</td>';
s += '<td width="35px" class="sobota">So</td>';
s += '<td width="35px" class="niedziela">Nd</td></tr>';
s += '<tr height="5px"><td colspan=7 ></td></tr>';


var v_dni_tygodnia = new Array("1","2","3","4","5","6","0");

var v_d_date = new Date(v_y,v_m-1,01);
var v_pdm = parseInt(v_d_date.getDay());
var v_max_d = parseInt(v_ldm[v_m-1]);
var v_dzien = 0;
var klasa;


for (j=1; j<7; j++)
{
 s += '<tr class="wiersz">';
 for (i=0; i<7; i++)
 {
 if (parseInt(v_dni_tygodnia[i]) == v_pdm || (v_dzien > 0 && v_dzien < v_max_d))
  {

   v_pdm = -1;
   v_dzien += 1;
   if (i<5) {klasa="dzien_p"}
   else {
    if (i==5) {klasa="sobota"}
    else {klasa="niedziela"}};


   if (v_dzien==1 && v_m==1) {klasa="niedziela"};
   if ((v_dzien==1 || v_dzien==3) && v_m==5) {klasa="niedziela"};
   if (v_dzien==15 && v_m==8) {klasa="niedziela"};
   if ((v_dzien==1 || v_dzien==11) && v_m==11) {klasa="niedziela"};
   if ((v_dzien==25 || v_dzien==26) && v_m==12) {klasa="niedziela"};

   if (v_dzien == v_d ) {klasa="wyroznienie"};

   s += '<td width="30px" class="'+klasa+'">';

   s += '<a href="javascript:void(0)" onClick="poj('+v_dzien+')" ondblclick="pod('+v_dzien+')" class="'+klasa+'">'+v_dzien+'</td>';

  }
  else
  {
   s += '<td width="30px" class="dzien_p">&nbsp</td>';
  }
 }
 s += '</tr>';
}
s += '</table>';
s += '</td></tr>';

/******* przyciski nawigacji ******** */
s += '<tr height="25px" valign=bottom><td align=left>';
s += '<input type="button" onClick="opener.m(-1)" class="nawigacja" value="<<"></td>';
s += '<td align=center><input type="button" onClick="opener.wybierz(ukryty.u_dzien.value)" class="akcja" value="Wybierz"></td>';
s += '<td align=center><input type="button" onClick="window.close()" class="akcja" value="Anuluj"></td>';
s += '<td align=right>';
s += '<input type="button" onClick="opener.m(1)" class="nawigacja" value=">>"></td>';
s += '</tr>';

s += '</table>';
s += '</form>';
s += '</center></html>';

v_okno.document.open();
v_okno.document.write(s);
v_okno.document.close();
}




function m(v_liczba){

var v_ldm = new Array("31","29","31","30","31","30","31","31","30","31","30","31");

if (parseInt(window.document.forms[0].u_rok.value)%4) {v_ldm[1]=28};

window.document.forms[0].u_miesiac.value = parseInt(window.document.forms[0].u_miesiac.value) + parseInt(v_liczba);

if (v_ldm[parseInt(window.document.forms[0].u_miesiac.value)-1] < parseInt(window.document.forms[0].u_dzien.value))
{
window.document.forms[0].u_dzien.value = v_ldm[parseInt(window.document.forms[0].u_miesiac.value)-1];
}

if (parseInt(window.document.forms[0].u_miesiac.value) < 1)
{ window.document.forms[0].u_rok.value = parseInt(window.document.forms[0].u_rok.value) -1;
  window.document.forms[0].u_miesiac.value = 12;
}

if (parseInt(window.document.forms[0].u_miesiac.value) > 12)
{ window.document.forms[0].u_rok.value = parseInt(window.document.forms[0].u_rok.value) +1;
  window.document.forms[0].u_miesiac.value = 1;
}

kod(NoweOkno, window.document.forms[0].u_dzien.value, window.document.forms[0].u_miesiac.value, window.document.forms[0].u_rok.value);

}




function wybierz(v_dzien) {
v_dzien += "";
if (v_dzien.length < 2) {v_dzien = "0" + v_dzien};

if (window.document.forms[0].u_miesiac.value < 10) 
 {window.document.forms[0].u_miesiac.value = "0" + parseInt(window.document.forms[0].u_miesiac.value)};

//window.document.forms[0].data.value = 
DataField.value = 
v_dzien+"."+window.document.forms[0].u_miesiac.value+"."+window.document.forms[0].u_rok.value;

NoweOkno.close();
return true
}


function tlumacz(tresc) {
var Lwin = new Array('¹','','','','„'); //'ź','ę','³','æ',
var Liso = new Array('±','¶','¦','¼','”');
var i, j;

// wersja eksploratora
var IEversion = parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+5,3));
if  (IEversion < 6) {
for(i=0; i<Liso.length; i++) {
 while (tresc.indexOf(Liso[i])!=-1) {
   tresc = tresc.replace(Liso[i],Lwin[i]);
 };
}};
return tresc
}

function ie() {
if (navigator.appVersion.indexOf('MSIE')!=-1) return true
else return false;
}

function fx() {
if (!ie()) {
 if (navigator.userAgent.indexOf('Firefox')!=-1) return true
 else return false;
};
return false;
}

