
var monthList = ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'];
var curDate = new Date();

curDate.setDate(1);
curDate.getTheYear = curDate.getFullYear ? curDate.getFullYear : curDate.getYear;


	
var CurrDay=(new Date()).getDate();
var CurrMon=curDate.getMonth()+1;
var CurrYear=curDate.getTheYear();

var MWJNS4 = document.layers && !document.all && navigator.mimeTypes['*'];
var opOrEscape = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );


var oDoc;
/////////// nowe funkcje
function MWJ_setYear(sYear) 
{
	//alert(sYear)
	curDate.setYear(sYear); doReDrawOpen(); 
	
}

function MWJ_setMonth(sMonth) 
{
	//alert(sMonth)
	curDate.setMonth(sMonth); doReDrawOpen(); 
	
}

/////////// koniec nowe funkcje

function openCalendar(e,day,mon,year) {

if(oDoc)
{
if(oDoc.closed!=true){
oDoc.close();}

}
	var sX = 0, sY = 0;
        if( !e ) { e = window.event; }
//        alert(e);
	if( e && ( e.screenX || e.screenY ) && screen.availWidth ) { sX = e.screenX; sY = e.screenY; }
	if( sX > screen.availWidth - 0 ) { sX = screen.availWidth - 0; }
	if( sY > screen.availHeight - 0 ) { sY = screen.availHeight - 0; }
	
	
	
	
	doReDraw(sX,sY);
	
	this.CDay = day;
	this.CMon = mon;
	this.CYear = year;
	
	
}

function openCalendarWP(day_mon_year) {

if(oDoc)
{
if(oDoc.closed!=true)
{
oDoc.close();
}

}
	var sX = 0, sY = 0;
         e = window.event;

	if( e && ( e.screenX || e.screenY ) && screen.availWidth ) { sX = e.screenX; sY = e.screenY; }
	if( sX > screen.availWidth - 0 ) { sX = screen.availWidth - 0; }
	if( sY > screen.availHeight - 0 ) { sY = screen.availHeight - 0; }



	
	doReDraw(sX,sY);	
	this.dmy=day_mon_year;
	
//	CurrDay = day_mon_year.value.substr(8,2);
//	CurrMon = day_mon_year.value.substr(5,2);
//	CurrYear= day_mon_year.value.substr(0,4);	
	
//	this.CDay = day_mon_year.substr(0,4);
//	this.CMon = day_mon_year.substr(5,2);
//	this.CYear = day_mon_year.substr(8,2);

//	doReDraw(sX,sY);
	
}

function MWJ_dropYear() { curDate.setYear( curDate.getTheYear() - 1 ); doReDraw(); }
function MWJ_raiseYear() { curDate.setYear( curDate.getTheYear() + 1 ); doReDraw(); }
function MWJ_dropMonth() { if( curDate.getMonth() ) { curDate.setMonth( curDate.getMonth() - 1 ); } else { curDate.setMonth(11); curDate.setYear( curDate.getTheYear() - 1 ); } doReDraw(); }
function MWJ_raiseMonth() { if( curDate.getMonth() < 11 ) { curDate.setMonth( curDate.getMonth() + 1 ); } else { curDate.setMonth(0); curDate.setYear( curDate.getTheYear() + 1 ); } doReDraw(); }
function resetDate() { curDate.setTime((new Date()).getTime()); }

function doReDraw(sX,sY) {
	
	
		var theContent = '<html><head><title>Kalendarz</title>\n'
		+'<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">'
		+'<style type="text/css"><!--\n'+
		'.left_pad { padding-left:8px }\n'+
		'OPTION,.selCal{font-family: \'Verdana\', Times, Serif; font-size: 10px;color:#2A2E65;BACKGROUND-COLOR: #F4FAFA; }\n'+
		'a { text-decoration: none; color:2A2E65; font-size: 10px;}\n'+
		'td{ font-family: \'Verdana\', Times, Serif; font-size: 11px;color:#2A2E65 }\n'+
		'th { font-family: \'Verdana\', Times, Serif; font-size: 11px; color:#2A2E65}\n'+
		'a.MWJCAL { display: block; width: 100%; font-weight: bold;}\n'+
		'body { margin-left:0px; margin-top:0px; margin-width:0px; margin-height:0px;}\n--></style></head>'+
		'<body bgcolor="#ffffff" text="#757575" link="#00007f" alink="#00007f" vlink="#00007f" marginleft="0px" margintop="0px" marginwidth="0px" marginheight="0px">'+
		'<form onsubmit="return false;">'+
		
		'<table border="0" cellpadding="0" cellspacing="0" width="191" align="center">'+
		
		'<tr><td height="26" bgcolor="#F3F7FF"  class="left_pad"><select name=""  onchange="window.opener.MWJ_setYear(this.options[selectedIndex].value)" class="selCal">';
				
				for(yr=1901;yr<=CurrYear+50;yr++)
				{
					if(yr==(curDate.getTheYear()))
					{
					theContent+='<option value="'+yr+'" selected>'+yr+'</option>';
					}
					else
					{
					theContent+='<option value="'+yr+'">'+yr+'</option>';
					}
					
				}
				
		theContent+='</select>&nbsp;&nbsp;'+
		'<select name="" onchange="window.opener.MWJ_setMonth(this.options[selectedIndex].value)" class="selCal">';
		
				for(mr=0;mr<12;mr++)
				{
					if(mr==(curDate.getMonth()))
					{
					theContent+='<option value="'+mr+'" selected>'+monthList[mr]+'</option>';
					}
					else
					{
					theContent+='<option value="'+mr+'">'+monthList[mr]+'</option>';
					}
					
				}
		


		theContent+='</select></td></tr>'+
		
		
		'<tr><td bgcolor="#B9C5CF" height="1px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#ffffff" height="2px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#FFFFFF" nowrap style="color:#2A2E65" class="left_pad"><a href="javascript:if( window.opener && window.opener.datePickerReturn ) {void(window.opener.setTimeout(\'datePickerReturn('+CurrDay+','+CurrMon+','+CurrYear+');\',1)); window.close(); } else { window.alert( \'Error:\\nCould not communicate with opening window.\' ); }"><font color="#2A2E65">&nbsp;<strong>&raquo;</strong>&nbsp;Dzisiaj jest: '+CurrDay+'-'+CurrMon+'-'+CurrYear+'&nbsp;<strong>&laquo;</strong></font></a></td>'+
		'</table>'+
		'<table border="0" cellpadding="0" cellspacing="0" width="191" align="center"><tr><td>'+
		'<table border="0" cellpadding="0" cellspacing="1" width="159" align="left" style="margin-left:7px;">'+
		'<tr><td bgcolor="#ffffff" height="4px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><th bgcolor="#ffffff">Pn</th><th bgcolor="#ffffff">W</th><th bgcolor="#ffffff">S</th><th bgcolor="#ffffff">C</th><th bgcolor="#ffffff">Pt</th><th bgcolor="#ffffff">So</th><th bgcolor="#ffffff"><font color="#ff0000">N</font></th></tr>'
	;
	
	for( var x = 1; x <= [31,((!( curDate.getTheYear() % 4 ) && ( ( curDate.getTheYear() % 100 ) || !( curDate.getTheYear() % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][curDate.getMonth()]; x++ ) {
		curDate.setDate(x);
		if( x == 1 && (curDate.getDay()-1) )
		{ 
		tmp=(curDate.getDay()-1);
		if(tmp==-1)
		tmp=6;
		theContent += '<tr><td bgcolor="#ffffff" colspan="'+tmp+'"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td>'; 
		}
		theContent += ( ( !(curDate.getDay()-1) ) ? '<tr>' : '' ) + '<td align="center" bgcolor="#'+((curDate.getMonth()==(new Date()).getMonth()&&curDate.getYear()==(new Date()).getYear()&&x==(new Date()).getDate())?'D8E8F5':((!curDate.getDay()||curDate.getDay()==6)?'ffffff':'ffffff'))+'"><a href="javascript:if( window.opener && window.opener.datePickerReturn ) { void(window.opener.setTimeout(\'datePickerReturn('+x+','+(curDate.getMonth()+1)+','+curDate.getTheYear()+');\',1)); window.close(); } else { window.alert( \'Error:\\nCould not communicate with opening window.\' ); }"><font color="#'+((curDate.getMonth()==(new Date()).getMonth()&&curDate.getYear()==(new Date()).getYear()&&x==(new Date()).getDate())?'2A2E65"'+ ' style="font-weight:bold"':((!curDate.getDay()||curDate.getDay()==7)?'FF0000':'2A2E65'))+'">'+x+'<font></a></td>';
	} 
	curDate.setDate(1);
	//if ((curDate.getDay()+x)!=36){
	//theContent += '<td bgcolor="#ffffff" colspan="7"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td>';}
	theContent += '</tr></table></td></tr></table>';
	

	// koniec generowania kalendarza
	
	
	oDoc = window.open( ( opOrEscape ? 'blank.html' : 'blank.html' ), 'MWJ_TOFR', 'width=190,height=150','resizable=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0' );

	oDoc.document.open(); oDoc.document.write(theContent); oDoc.document.close(); window.MWJwinStore = oDoc;
	
	if( oDoc.focus ) { oDoc.focus(); } if( ( sX || sY ) && oDoc.moveTo ) { oDoc.moveTo(sX,sY); }
}

if( !window.onunload ) { window.onunload = function () { if( window.MWJwinStore && !window.MWJwinStore.closed ) { window.MWJwinStore.close(); } }; }



function doReDrawOpen()
{

    var theContent = '<html><head><title>Kalendarz</title>\n'
		+'<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">'
		+'<style type="text/css"><!--\n'+
		'.left_pad { padding-left:8px }\n'+
		'OPTION,.selCal{font-family: \'Verdana\', Times, Serif; font-size: 10px;color:#2A2E65;BACKGROUND-COLOR: #F4FAFA; }\n'+
		'a { text-decoration: none; color:2A2E65; font-size: 10px;}\n'+
		'td{ font-family: \'Verdana\', Times, Serif; font-size: 11px;color:#2A2E65 }\n'+
		'th { font-family: \'Verdana\', Times, Serif; font-size: 11px; color:#2A2E65}\n'+
		'a.MWJCAL { display: block; width: 100%; font-weight: bold;}\n'+
		'body { margin-left:0px; margin-top:0px; margin-width:0px; margin-height:0px;}\n--></style></head>'+
		'<body bgcolor="#ffffff" text="#757575" link="#00007f" alink="#00007f" vlink="#00007f" marginleft="0px" margintop="0px" marginwidth="0px" marginheight="0px">'+
		'<form onsubmit="return false;">'+
		
		'<table border="0" cellpadding="0" cellspacing="0" width="191" align="center">'+
		
		'<tr><td height="26" bgcolor="#F3F7FF"  class="left_pad"><select name=""  onchange="window.opener.MWJ_setYear(this.options[selectedIndex].value)" class="selCal">';
				
				for(yr=1901;yr<=CurrYear+50;yr++)
				{
					if(yr==(curDate.getTheYear()))
					{
					theContent+='<option value="'+yr+'" selected>'+yr+'</option>';
					}
					else
					{
					theContent+='<option value="'+yr+'">'+yr+'</option>';
					}
					
				}
				
		theContent+='</select>&nbsp;&nbsp;'+
		'<select name="" onchange="window.opener.MWJ_setMonth(this.options[selectedIndex].value)" class="selCal">';
		
				for(mr=0;mr<12;mr++)
				{
					if(mr==(curDate.getMonth()))
					{
					theContent+='<option value="'+mr+'" selected>'+monthList[mr]+'</option>';
					}
					else
					{
					theContent+='<option value="'+mr+'">'+monthList[mr]+'</option>';
					}
					
				}
		
		
		theContent+='</select></td></tr>'+
		
		
		'<tr><td bgcolor="#B9C5CF" height="1px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#ffffff" height="2px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#FFFFFF" nowrap style="color:#2A2E65" class="left_pad"><a href="javascript:if( window.opener && window.opener.datePickerReturn ) {void(window.opener.setTimeout(\'datePickerReturn('+CurrDay+','+CurrMon+','+CurrYear+');\',1)); window.close(); } else { window.alert( \'Error:\\nCould not communicate with opening window.\' ); }"><font color="#2A2E65">&nbsp;<strong>&raquo;</strong>&nbsp;Dzisiaj jest: '+CurrDay+'-'+CurrMon+'-'+CurrYear+'&nbsp;<strong>&laquo;</strong></font></a></td>'+
		'</table>'+
		'<table border="0" cellpadding="0" cellspacing="0" width="191" align="center"><tr><td>'+
		'<table border="0" cellpadding="0" cellspacing="1" width="159" align="left" style="margin-left:7px;">'+
		'<tr><td bgcolor="#ffffff" height="4px"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><th bgcolor="#ffffff">Pn</th><th bgcolor="#ffffff">W</th><th bgcolor="#ffffff">S</th><th bgcolor="#ffffff">C</th><th bgcolor="#ffffff">Pt</th><th bgcolor="#ffffff">So</th><th bgcolor="#ffffff"><font color="#ff0000">N</font></th></tr>'
	;
	
	for( var x = 1; x <= [31,((!( curDate.getTheYear() % 4 ) && ( ( curDate.getTheYear() % 100 ) || !( curDate.getTheYear() % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][curDate.getMonth()]; x++ ) {
		curDate.setDate(x);
		if( x == 1 && (curDate.getDay()-1) )
		{ 
		tmp=(curDate.getDay()-1);
		if(tmp==-1)
		tmp=6;
		theContent += '<tr><td bgcolor="#ffffff" colspan="'+tmp+'"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td>'; 
		}
		theContent += ( ( !(curDate.getDay()-1) ) ? '<tr>' : '' ) + '<td align="center" bgcolor="#'+((curDate.getMonth()==(new Date()).getMonth()&&curDate.getYear()==(new Date()).getYear()&&x==(new Date()).getDate())?'D8E8F5':((!curDate.getDay()||curDate.getDay()==6)?'ffffff':'ffffff'))+'"><a href="javascript:if( window.opener && window.opener.datePickerReturn ) { void(window.opener.setTimeout(\'datePickerReturn('+x+','+(curDate.getMonth()+1)+','+curDate.getTheYear()+');\',1)); window.close(); } else { window.alert( \'Error:\\nCould not communicate with opening window.\' ); }"><font color="#'+((curDate.getMonth()==(new Date()).getMonth()&&curDate.getYear()==(new Date()).getYear()&&x==(new Date()).getDate())?'2A2E65"'+ ' style="font-weight:bold"':((!curDate.getDay()||curDate.getDay()==7)?'FF0000':'2A2E65'))+'">'+x+'<font></a></td>';
	} 
	curDate.setDate(1);
	//if ((curDate.getDay()+x)!=36){
	//theContent += '<td bgcolor="#ffffff" colspan="7"><img src="./img/p.gif" alt="" width="1" height="1" border="0"></td>';}
	theContent += '</tr></table></td></tr></table>';
	

	// koniec generowania kalendarza
	
	

	oDoc.document.open(); oDoc.document.write(theContent); oDoc.document.close(); window.MWJwinStore = oDoc;
	
   }

if( !window.onunload ) { window.onunload = function () { if( window.MWJwinStore && !window.MWJwinStore.closed ) { window.MWJwinStore.close(); } };


}



function datePickerReturn( oDay, oMonth, oYear )
{

var xDay='';
var xMonth='';
var xYear='';
	
	if (oDay<=9){xDay="0"+oDay} else xDay=oDay;
	if (oMonth<=9){xMonth="0"+oMonth} else xMonth=oMonth;
	xYear=oYear;
	dmy.value=xYear+'-'+xMonth+'-'+xDay;
	
if (dmy.onchange)
{

    eval("dmy.onchange();");
}	

}
	


function moveObject(objectId, newXCoordinate, newYCoordinate)
{
   
   objectId.moveTo(newXCoordinate,newYCoordinate);
	
}

if (navigator.appName == "Microsoft Internet Explorer")
{
var xOffset = -250;
var yOffset = -215;
}

if (navigator.userAgent.indexOf("Opera")>-1) 
 {
  var xOffset = -250;
  var yOffset = -365;
 } 

 if (navigator.userAgent.indexOf("Netscape")>-1) 
 {
  var xOffset = -250;
  var yOffset = -215;
 } 

function showPopup (targetObjectId, eventObj) {
    
	
	if(eventObj) {
	
	eventObj.cancelBubble = true;
	
//	var newXCoordinate = (eventObj.screenX)?eventObj.screenX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:10);
//	var newYCoordinate = (eventObj.screenY)?eventObj.screenY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	
        var newXCoordinate = eventObj.x +document.body.scrollLeft;
        var newYCoordinate = eventObj.y +document.body.scrollTop +200;
        moveObject(targetObjectId, newXCoordinate, newYCoordinate);
       // moveObject(targetObjectId, 300, 300);
	//alert(newXCoordinate);
	
} 

}

