<!-- Calendar ver. 0.1 @ planetagongo.ru
function Calendar(obj, loc, target){
	
	var prefix = obj;
	var self = this;
	var today = new Date();

	this.d = today.getDate();
	this.m = today.getMonth();
	this.y = today.getFullYear();
	
	var curDate = new Date(this.y,this.m,this.d);
	
	var rusWeek = new Array('Воскресенье','Понедельник','Вторник','Среда','Четверг','Пятница','Суббота');
	var rusMonth = Array('Января','Февраля','Марта','Апреля','Мая','Июня','Июля','Августа','Сентября','Октября','Ноября','Декабря');
	var month = Array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');

	this.isLeapYear = function() { return this.y % 4 == 0 && this.y % 100 != 0 || this.y % 400 == 0; } //высок. год или нет
	
	this.getDays = function() { //Для определения количества дней в месяце
			curDate = new Date(this.y,this.m,1); //
			this.daysInMonth = new Array (31, 100, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
			this.isLeapYear() ? this.daysInMonth[1] = 29 : this.daysInMonth[1] = 28;
			this.days = this.daysInMonth[this.m];	
	}

	
	this.hideCalendar = function(){ 
		clearInterval(this.intervalID); this.hide_intervalID = setInterval(function(){ self.hideOpacity() },30)
	}
	
	
	var opacity = 0 // функция задекжки
	this.hideOpacity = function(){ 
	var Obj = $(obj); 
	Obj.style.opacity = 1
		if(opacity > 10) { clearInterval(this.hide_intervalID); Obj.parentNode.removeChild(Obj) }
		Obj.style.opacity -= opacity/10; 
		opacity++  
	}
	
	
	this.createCalendar = function() { 
		
		if(!$(obj)) {
			var cBox = document.createElement('div')
			with(cBox){
			id = obj
			className = 'calendar'
			style.width = '17em'
			style.position = 'absolute'
			style.zIndex = '100'
		//	style.cursor = 'move'
			}
			loc.appendChild(cBox)
	
			//dragObj.target(cBox,1);		
		}else{
		$(obj).className = 'calendar'
		}
	}
	
	
	this.renderHead = function(){
		this.date = this.d+' '+rusMonth[self.m]+' '+this.y+'<br />'+rusWeek[curDate.getDay()];
		
		if(loc) this.head = "<div class='hide'><a href='javascript:void(0)' id='"+prefix+"_hide' title='Закрыть'>&nbsp;</a></div>"; else this.head = '';

		this.head += '<div id="'+obj+'_date" class="calendar_date"><div id="'+obj+'_time" class="calendar_time"></div>'+this.date+'</div><table cellspacing="3"><tr><td><a href="javascript:void(0)" id="'+prefix+'_prev_year"><<</a></td><td><a href="javascript:void(0)" id="'+prefix+'_prev_month"><</a></td><td colspan="3"><div id="'+prefix+'_head"></div></td><td><a href="javascript:void(0)" id="'+prefix+'_next_month">></a></td><td><a href="javascript:void(0)" id="'+prefix+'_next_year">>></a></td></tr></table><table class="week"><tr><td>Пн</td><td>Вт</td><td>Ср</td><td>Чт</td><td>Пт</td><td>Сб</td><td>Вс</td></tr></table><div id="'+obj+'_content" class="calendar_content"></div>';
		$(obj).innerHTML = this.head;
	}
	
	this.renderTime = function(){
		var now = new Date()
		var H = now.getHours() < 10 ? "0"+now.getHours() : now.getHours();
		var i = now.getMinutes() < 10 ? "0"+now.getMinutes() : now.getMinutes();
		var s = now.getSeconds() < 10 ? "0"+now.getSeconds() : now.getSeconds();
		var time = ''+H +':'+i+':'+s+'';
		var Obj =  $(obj+'_time'); if(Obj) Obj.innerHTML = time; 
		} 

	this.renderCalendar = function () {					
		this.getDays(); 
		
		var iday = 0;	
		var rusDays = Array(6,0,1,2,3,4,5);
		this.dClick = Array();
		this.curMonth = Array();
	
		var result ='<table><tr>'; for(var d=0; d < rusDays[curDate.getDay()];d++){  iday++; result += '<td>&nbsp;</td>' }
		
		//дни месяца
		for(var day=1; day <= this.days; day++){ iday++
		
		this.dClick[day] = prefix+'_'+day+'-'+(1*this.m+1)+'-'+this.y;
		
		var m = 1*this.m+1; m = m < 10 ? "0"+m : m; 
		var d = day < 10 ? "0"+day : day;
		
		this.curMonth[this.dClick[day]] = d+'-'+m+'-'+this.y;
		
		var curDay = (day == today.getDate() && this.m == today.getMonth() && this.y == today.getFullYear()) ? " style='border:1px dotted #999; font-weight:bold' " : '';
		var weekend = iday > 5 ? ' class="weekend" ' : ' ';
			
		result += '<td><a id="'+this.dClick[day]+'" href="javascript:void(0)"'+weekend+''+curDay+' title="'+this.curMonth[this.dClick[day]]+'">'+day+'</a></td>';
	
		if(iday==7) { result +='</tr><tr>'; iday = 0 } }
		
		result += '</tr></table>';
	
		$(obj+'_head').innerHTML = month[this.m]+' '+this.y;
		$(obj+'_content').innerHTML = result;
	
		for(var i = 1; i <= this.days; i++){ $(this.dClick[i]).onclick = function() { self.dayClick(this) } }
		self = this;
	}
			
	this.switchCalendar = function(operation,type){
		switch(type){
			case 'y':
				switch(operation){
					case '--': if (this.y < 1900 ) this.y = 1899; else this.y--; break
					case '++': if (this.y > 2099 ) this.y = 2100; else this.y++; break
				}
			break
			case 'm':
				switch(operation){
					case '--': if (this.m < 1 ){ this.m = 11; this.y-- }else{ this.m-- } break
					case '++': if (this.m > 10 ){ this.m = 0; this.y++ }else{ this.m++ } break
				}
			break
		}
		self.renderCalendar();
	}
	
	this.createCalendar(); this.renderHead(); this.renderTime(); this.renderCalendar();
	
	if(loc) $(prefix+'_hide').onclick = function() { 
		fadeObj.target($(obj))
	//self.hideCalendar() 
	}

	$(prefix+'_prev_year').onclick = function() {self.switchCalendar('--','y')};
	$(prefix+'_next_year').onclick = function() {self.switchCalendar('++','y')};
	$(prefix+'_prev_month').onclick = function() {self.switchCalendar('--','m')};
	$(prefix+'_next_month').onclick = function() {self.switchCalendar('++','m')};
	
	this.dayClick = function(obj){
		for(var i = 1; i <= this.days; i++){ var Obj = $(this.dClick[i]); if(Obj.className == 'hover') Obj.removeAttribute('class') }
		obj.className = 'hover'; var t = $(target); if(t){ t.value = this.curMonth[obj.id] } 	
	fadeObj.target($(prefix))
	}
	
	this.intervalID = setInterval(function(){ self.renderTime() },1000);
	
}
//-->
