/*
 * JS Calendar - Comarch S.A. 
 * Kriszot - 2004 
 */


var monthList = ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'];
var curDate = new Date();
curDate.setDate(1); 
var format = "yyyy.MM.dd";
var time = false;

curDate.getTheYear = curDate.getFullYear ? curDate.getFullYear : curDate.getYear;

var CurrDay=(new Date()).getDate();
var CurrMon=curDate.getMonth()+1;
var CurrYear=curDate.getTheYear();

var oDoc;

function openCalendar(e,dateField) 
{
	
	
	var sX = 0, sY = 0;
	if( !e ) { 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; }
	sY += yOffset;
    if(navigator.appName=="Netscape") { doReDraw(500,400); }
    else {	doReDraw(sX,sY); }
	
	this.dateField = dateField;
}

function openCalendarEx(e,dateField,newFormat) 
{	
	format = newFormat;
	openCalendar(e,dateField)
}

function openCalendarEx2(e,dateField,dateFieldName) 
{	
	this.dateFieldName=dateFieldName
	openCalendar(e,dateField)
}

function openCalendarTime(e,dateField) 
{	
	time = true;
	openCalendar(e,dateField)
}

function MWJ_setYear(sYear) { curDate.setYear(sYear); doReDraw(); }
function MWJ_setMonth(sMonth) { curDate.setMonth(sMonth); doReDraw(); }


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><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=1995;yr<=curDate.getTheYear()+2;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="/static/img/bo/invis.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#ffffff" height="2px"><img src="/static/img/bo/invis.gif" alt="" width="1" height="1" border="0"></td></tr>'+
		'<tr><td bgcolor="#FFFFFF" nowrap style="color:#2A2E65" class="left_pad">Dzisiaj jest: '+CurrDay+'.'+CurrMon+'.'+CurrYear+'</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="/static/img/bo/invis.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="/static/img/bo/invis.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);
	theContent += '</tr></table></td></tr></table>';
	
	oDoc = window.open('', 'MWJ_TOFR', 'left='+sX+',top='+sY+',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( !window.onunload ) { window.onunload = function () { if( window.MWJwinStore && !window.MWJwinStore.closed ) { window.MWJwinStore.close(); } }; }


function formatDate( oDay, oMonth, oYear ) {	
	var result = this.format.replace(/MM/,oMonth);
	result = result.replace(/yyyy/,oYear);
	result = result.replace(/dd/,oDay);
	result = result.replace(/HH/,"00");
	result = result.replace(/kk/,"01");
	result = result.replace(/mm/,"00");
	result = result.replace(/ss/,"00");
	return result;	
}

function datePickerReturn( oDay, oMonth, oYear ) {
	
	
	if (oDay<=9)
		oDay="0"+oDay;
		
	if (oMonth<=9)
		oMonth="0"+oMonth;
		
	//oYear+"."+oMonth+"."+oDay;	
	if (time) {
		now = new Date();
		hours = now.getHours();
		min = now.getMinutes();
	
		if (hours < 10) {
			hours = "0" + hours;
		}
	
		if (min < 10) {
			min = "0" + min;
		}
		this.dateField.value = formatDate( oDay, oMonth, oYear )+" "+hours+":"+min;
		if (this.dateFieldName!=undefined&&this.dateFieldName!=null)
		{
			window.parent.validujPole(this.dateFieldName);
		}
	} else
	{
		this.dateField.value = formatDate( oDay, oMonth, oYear );
		if (this.dateFieldName!=undefined&&this.dateFieldName!=null)
		{
			window.parent.validujPole(this.dateFieldName);
		}
	}
}

var xOffset = 0;
var yOffset = 0;






