/************************************************************************************
Simple DHTML popup calendar made by Maxim Korepanov from http://www.nca.pt
Home Page: http://max.far.ru
Please keep this notice in the code if you use it. Thanks.
dhtml-pop-calendar ver 1
************************************************************************************/
var init   = new Date();
var day   = init.getDate();
var objField = null;
var oPopup;
if (navigator.appName=="Microsoft Internet Explorer")
{
	oPopup = window.createPopup();
	var html="";
	html = "<DIV style='position:absolute; top:0; left:0; width:100%; height:100%; background:#cccccc; border:1px solid threeddarkshadow; border-top:1px solid buttonface; border-left:1px solid buttonface;'>";
	html +="<DIV style='position:absolute; top:0; left:0; width:100%; height:100%; background:buttonface; border:1px solid buttonshadow; border-top:1px solid buttonhighlight; border-left:1px solid white; padding:5px;  font:normal 10pt tahoma; padding-left:5px '><CENTER>";
	html +="<SELECT ID=month class=control onchange=parent.displayCalendar(this.selectedIndex,year.selectedIndex+1900)>";
	html +="<OPTION>ßíâàðü<OPTION>Ôåâðàëü<OPTION>Ìàðò<OPTION>Àïðåëü<OPTION>Ìàé<OPTION>Èþíü<OPTION>Èþëü<OPTION>Àâãóñò<OPTION>Ñåíòÿáðü<OPTION>Îêòÿáðü<OPTION>Íîÿáðü<OPTION>Äåêàáðü</SELECT>&nbsp;";
	html +="<SELECT  ID=year class=control onchange=parent.displayCalendar(month.selectedIndex,this.selectedIndex+1900)>";
	for (var i=1900; i<2100; i++) html += "<OPTION>"+i+"</OPTION>";
	html +="</SELECT>";
	html +="&nbsp;<INPUT TYPE=BUTTON class=control VALUE='OK'    onClick=parent.eventHandlerDblClick()><BR>";
	html +="<style type=text/css>";
	html +="<!--";
	html +=".control {  font-size: xx-small; height: 18px}";
	html +=".day_off_header {  background-color: #FF3333; height: 14px; width: 20px; font-size: xx-small; font-weight: bold; color: #FFFFFF; text-align: center; cursor: default; border: 1px #FFFFFF outset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +=".day_header {  background-color: #666666; height: 14px; width: 20px; font-size: xx-small; font-weight: bold; color: #FFFFFF; text-align: center; cursor: default; border: 1px #FFFFFF outset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +=".day {  font-size: xx-small; font-weight: bold; background-color: buttonface; height: 14px; width: 20px; text-align: center; cursor: default; border: 1px #FFFFFF outset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +=".day_selected {  font-size: xx-small; font-weight: bold; background-color: #FFFFCC; height: 12px; width: 18px; text-align: center; cursor: default; border: 1px #CCCCCC inset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +=".day_off { font-size: xx-small; font-weight: bold; background-color: buttonface; height: 14px; width: 20px; text-align: center ; color: #FF0000 ; cursor: default; border: 1px #FFFFFF outset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +=".day_mouseover { font-size: xx-small; font-weight: bold; color: #990000; background-color: buttonface; height: 14px; width: 20px; text-align: center; cursor: default; border: 1px #FFFFFF outset; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	html +="-->";
	html +="</style>";
	html +="<table ID=CalTable border=0  cellspacing=1>";
	html +="<tr> ";
	html +="<td class=day_header>Ïí</td><td class=day_header>Âò</td><td class=day_header>Ñð</td><td class=day_header>×ò</td><td class=day_header>Ïò</td><td class=day_header>Ñá</td><td class=day_off_header>Âñ</td>";
	html +="</tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	html +="</table>";
	html +="<INPUT TYPE=BUTTON class=control VALUE='<<'    onClick=parent.setYear(-1) id=BUTTON2 name=BUTTON2>";
	html +="&nbsp;<INPUT TYPE=BUTTON class=control VALUE='<'    onClick=parent.setMonth(-1) id=BUTTON2 name=BUTTON2>";
	html +="&nbsp;<INPUT TYPE=BUTTON class=control VALUE='Ñåãîäíÿ'    onClick=parent.setToday() id=BUTTON2 name=BUTTON2>";
	html +="&nbsp;<INPUT TYPE=BUTTON class=control VALUE='>'    onClick=parent.setMonth(1) id=BUTTON2 name=BUTTON2>";
	html +="&nbsp;<INPUT TYPE=BUTTON class=control VALUE='>>'    onClick=parent.setYear(1) id=BUTTON2 name=BUTTON2>";
	html +="</CENTER></DIV></DIV>";

	oPopup.document.body.innerHTML =html;
}
function openCalendar(id,value,obj)
{
	if (navigator.appName!="Microsoft Internet Explorer")
	{
		oPopup=window.open("/calendar2.php?obj="+id,"oPopup","height=200px,width=265px,resizable=0,scrollbars=0,statusbar=0,titlebar=0,menubar=0,toolbar=0");
		oPopup.focus();
		return (false);
	}
	else{
		if(obj){
			var x_day=parseInt(obj.value.substr(0,2));
			var x_month=parseInt(obj.value.substr(3,2));
			var x_year=parseInt(obj.value.substr(6,4));
		}
		oPopup.show(0, 20, 180, 157, obj);
		if (x_day > 0 && x_day <= getDaysInMonth(x_month,x_year) && x_month  > 0 && x_month < 13 && x_year > 1899 && x_year < 2100){
		day=x_day;
		oPopup.document.getElementById("month").selectedIndex=x_month-1;
		oPopup.document.getElementById("year").selectedIndex=x_year-1900;
		displayCalendar(x_month-1,x_year,x_day);
		} 
		else{
			setToday();
		}
		objField=obj;
	}
}

function eventHandlerOver(anEvObj) {
if (this.className!="day_selected")
this.className="day_mouseover";
}
function eventHandlerOut(anEvObj) {
if (this.className!="day_selected")
(this.cellIndex<6) ? this.className="day":this.className="day_off";
}
function eventHandlerDblClick(anEvObj) {
var str_day ="";
var str_month =oPopup.document.getElementById("month").selectedIndex+1;
var str_year=oPopup.document.getElementById("year").selectedIndex+1900;
(day.length==1)? str_day="0"+day : str_day=day;
if (str_month<10) str_month="0"+str_month;
objField.value=str_day + "-" + str_month + "-" + str_year;
 if(typeof parent.getCost == 'function') { 
  parent.getCost(); 
   }
oPopup.hide();
}

function eventHandlerClick(anEvObj) {
for (i=0; i<42; i++)
(oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].cellIndex<6) ? oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].className="day":oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].className="day_off";
this.className="day_selected";
day=this.innerHTML;
}


function setYear(val) {
x_year=oPopup.document.getElementById("year").selectedIndex+1900;
x_year= Number(x_year) + val;
if (x_year < 1900) x_year = 1900;
if (x_year > 2099) x_year = 2099;
oPopup.document.getElementById("year").selectedIndex = x_year-1900;
displayCalendar(oPopup.document.getElementById("month").selectedIndex, oPopup.document.getElementById("year").selectedIndex+1900);
}

function setMonth(val) {
var i = 0;
var x_month = oPopup.document.getElementById("month").selectedIndex;
i=x_month + val;
x_month=i%12;
if (x_month < 0) x_month = x_month + 12;
oPopup.document.getElementById("month").selectedIndex = x_month;
setYear(Math.floor(i/12));
displayCalendar(oPopup.document.getElementById("month").selectedIndex, oPopup.document.getElementById("year").selectedIndex+1900);	
}

function setToday() {
var now   = new Date();
var x_day   = now.getDate();
var x_month = now.getMonth();
var x_year  = now.getYear();
day=x_day;
//if (x_year < 2000) x_year = x_year + 1900; 
oPopup.document.getElementById("month").selectedIndex = x_month;
oPopup.document.getElementById("year").selectedIndex = x_year-1900;
displayCalendar( oPopup.document.getElementById("month").selectedIndex, oPopup.document.getElementById("year").selectedIndex+1900, x_day);
}

function getDaysInMonth(x_month,x_year)  {
var days;
if (x_month==1 || x_month==3 || x_month==5 || x_month==7 || x_month==8 || x_month==10 || x_month==12)  days=31;
else if (x_month==4 || x_month==6 || x_month==9 || x_month==11) days=30;
else if (x_month==2)  {
if (isLeapYear(x_year)) { days=29; }
else { days=28; }
}
return (days);
}
function isLeapYear (x_year) {
if (((x_year % 4)==0) && ((x_year % 100)!=0) || ((x_year % 400)==0)) {
return (true);
} else { return (false); }
}

function displayCalendar(x_month, x_year, x_day) {
x_month = parseInt(x_month);
x_year = parseInt(x_year);
var days = getDaysInMonth(x_month+1,x_year);
if (day > days) day=days;
if (!x_day) x_day=day;
var curr_day = 0;
var firstOfMonth = new Date (x_year, x_month, 1);
var startingPos = firstOfMonth.getDay()-1;
if (startingPos<0){ startingPos = 6;}
for (i=0; i<42; i++){
curr_day=i-startingPos+1;
(oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].cellIndex<6) ? oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].className="day":oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].className="day_off";
if (curr_day > 0 && curr_day <= days){
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].innerHTML=curr_day;
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onmouseover=parent.eventHandlerOver;
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onmouseout=parent.eventHandlerOut;
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onclick=parent.eventHandlerClick;
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].ondblclick=parent.eventHandlerDblClick;
} else {
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].innerHTML="";
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onmouseover="";
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onmouseout="";
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].onclick="";
oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].ondblclick="";
}
if (curr_day==x_day) oPopup.document.getElementById("CalTable").rows[Math.floor(i/7)+1].cells[i%7].className="day_selected";
}
}
