function ifChn(b,id,html){
        if (b){
                 var obj=document.getElementById(id);
                 if(obj){
                  var parent=obj.parentNode;
                  var odiv=document.createElement('span');
                  parent.replaceChild(odiv, obj);
                  odiv.innerHTML=html;
                 }
        }
}


function getCookieVal (offset){
         var endstr = document.cookie.indexOf (";", offset);
         if (endstr == -1)
         endstr = document.cookie.length;
         return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
        break;
        }
        return null;
}


function SetCookie (name, value, period) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        now= new Date();
        var expires = (period==null) ? "" : new Date(now.getMonth()+1+'-'+(now.getDate()+period)+'-'+now.getYear()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds());
        var path = (3 < argc) ? argv[3] : null;
        var domain = (4 < argc) ? argv[4] : null;
        var secure = (5 < argc) ? argv[5] : false;


        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}


function CheckForm (Frm) {
        var i;
        for (i=0; i<Frm.length; i++) {
                 k=Frm.elements[i].value;
                 if ((Frm.elements[i].value == "" )&&(Frm.elements[i].id!="")&&(Frm.elements[i].id.indexOf('!!')==-1)) {
                          alert('Пожалуйста, введите ' + Frm.elements[i].id);
                          Frm.elements[i].focus();
                          return false;
                  }else
                         if ((k.length<2)&&(Frm.elements[i].id!="")&&(Frm.elements[i].id.indexOf('!!')==-1)){
                          alert(Frm.elements[i].id + ' введено некорректно.');
                          Frm.elements[i].focus();
                          return false;
                  }
        }
        return true;
}

function openPopupS(url,w,h) {
         if (zzcms_new_popup2) zzcms_new_popup2.close();

         w=(w)?w:550;
         h=(h)?h:550;

         pl=(document.all)?top.screenLeft:top.screenX;
         pt=(document.all)?top.screenTop:top.screenY;
         ph=(document.all)?document.body.offsetHeight:top.outerHeight;
         pw=(document.all)?document.body.offsetWidth:top.outerWidth;
         l=pl+(pw/2)-(w/2);
         t=pt+(ph/2)-(h/2);

         var posy= (document.body.offsetWidth)/2-275;
         var posx=(document.body.offsetHeight)/2-215;
         var zzcms_new_popup2=window.open(url,'big','width='+w+',height='+h+', toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,left='+l+',top='+t)
         zzcms_new_popup2.focus();
}


 var site_new_popup

 function openImagePopup(url,title,w,h) {
        if (site_new_popup) site_new_popup.close();
         pl=(document.all)?top.screenLeft:top.screenX;
         pt=(document.all)?top.screenTop:top.screenY;
         ph=(document.all)?document.body.offsetHeight:top.outerHeight;
         pw=(document.all)?document.body.offsetWidth:top.outerWidth;
         l=pl+(pw/2)-(w/2);
         t=pt+(ph/2)-(h/2);

        w=(w)?w:550;
        h=(h)?h:550;

        if (w>pw) w=pw;
        if (h>ph) h=ph;

        var posy= (document.body.offsetWidth)/2-275;
        var posx=(document.body.offsetHeight)/2-215;
        var site_new_popup=window.open(url,'big','width='+w+',height='+h+', toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,left='+l+',top='+t)

         popuphtml='<html><head><title>';
         popuphtml+=title;
         popuphtml+='</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head><body style="padding:0px; margin:0px;" onclick="self.close()" style="overflow:auto">';
         popuphtml+='<img alt="'+title+'" src="'+url+'">';
         popuphtml+='</body></html>';

         site_new_popup.document.open();
         site_new_popup.document.write(popuphtml);
         site_new_popup.document.close();

        site_new_popup.focus();
}


var IE = (navigator.userAgent && (navigator.userAgent.indexOf("MSIE") != -1));
var FF = (navigator.userAgent && (navigator.userAgent.indexOf("Firefox") != -1));
var OP = (navigator.userAgent && (navigator.userAgent.indexOf("Opera") != -1));

if (IE || OP){
           document.attachEvent("onkeydown",globalKeyCatch);
}else{
           document.addEventListener("keypress",globalKeyCatch,true);
}


function globalKeyCatch(e) {
        var code;
        elem = (!e)?window.event.srcElement:e.target;
        if (!e) e = window.event;

        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;

        if (!elem || (elem.tagName!="INPUT" && elem.tagName!="TEXTAREA")){

	        if ((code == 37) && (e.ctrlKey == true)) {
	                var destination = document.getElementById('previous_page');
	                if (destination) location.href = destination.href;
	        }
	        if ((code == 39) && (e.ctrlKey == true)) {
	                var destination = document.getElementById('next_page');
	                if (destination) location.href = destination.href;
	        }
        }
}


function insertFlash(bnFlash,bnW,bnH,flashV,params,nocashe,transp){
        var rnd = Math.round(Math.random()*1048576);
        var flashID=bnFlash;
        if (bnFlash.indexOf('/')!=-1){
                flashID=bnFlash.split('/');
                flashID=flashID[flashID.length-1];
        }
        flashID=flashID.split('.');
        flashID=flashID[0];

        var flashHtm='';
        flashHtm+='<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+bnW+'" height="'+bnH+'" id="'+flashID+'" align="middle">';
        flashHtm+='<param name="allowScriptAccess" value="sameDomain" />';
        flashHtm+=(nocashe)?'<param name="movie" value="'+bnFlash+'?rnd='+rnd+'" />':'<param name="movie" value="'+bnFlash+'" />';
        flashHtm+='<param name="quality" value="high" />';
        flashHtm+='<param name="flashVars" value="'+params+'" />';
        flashHtm+='<param name="bgcolor" value="#ffffff" />';
        if (!transp) flashHtm+='<param name="wmode" value="transparent" />';
        if (!transp)
        flashHtm+='<embed src="'+bnFlash+'" wmode="transparent" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        else
        flashHtm+='<embed src="'+bnFlash+'" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        flashHtm+='</object>';
        document.write(flashHtm);
}



function insertFlash2(bnFlash,bnW,bnH,flashV,params,nocashe,bgcolor){
        var rnd = Math.round(Math.random()*1048576);
        var flashID=bnFlash;
        if (bnFlash.indexOf('/')!=-1){
                flashID=bnFlash.split('/');
                flashID=flashID[flashID.length-1];
        }
        flashID=flashID.split('.');
        flashID=flashID[0];

        var flashHtm='';
        flashHtm+='<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+bnW+'" height="'+bnH+'" id="'+flashID+'" align="middle">';
        flashHtm+='<param name="allowScriptAccess" value="sameDomain" />';
        flashHtm+=(nocashe)?'<param name="movie" value="'+bnFlash+'?rnd='+rnd+'" />':'<param name="movie" value="'+bnFlash+'" />';
        flashHtm+='<param name="quality" value="high" />';
        flashHtm+='<param name="flashVars" value="'+params+'" />';
        if (!bgcolor){
             flashHtm+='<param name="wmode" value="transparent" />';
             flashHtm+='<embed src="'+bnFlash+'" wmode="transparent" flashVars="'+params+'" quality="high" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        }else{
             flashHtm+='<param name="bgcolor" value="'+bgcolor+'" />';
             flashHtm+='<embed src="'+bnFlash+'" flashVars="'+params+'" quality="high" bgcolor="'+bgcolor+'" width="'+bnW+'" height="'+bnH+'" name="'+flashID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        }
        flashHtm+='</object>';
        document.write(flashHtm);
}








//Функция отправки запроса на удаленный URL методом GET. 2й параметр - ф-ия после выполнения запроса

var ajaxReq=false;

function loadXMLDoc(url,func,params) {
	ajaxReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	ajaxReq.onreadystatechange = func;
	ajaxReq.open("POST",url, true);
	ajaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxReq.setRequestHeader("Accept-Charset", "windows-1251");
	ajaxReq.setRequestHeader("Content-Length",params.length);
	ajaxReq.send(params);
}

function processReqChange() {
	if (ajaxReq){
	    abort = window.setTimeout("ajaxReq.abort();", 10000);
	    if (ajaxReq.readyState == 4) {
	        clearTimeout(abort);
	        if (ajaxReq.status == 200) {
				alert(ajaxReq.responseText);
	        } else {
	            alert("Неудачный запрос серверу:n" + ajaxReq.statusText);
	        }
	    }
    }
}

//------Упрощенная функция отправки запроса (Адрес, ID контейнера, Параметры)
var sajaxReq=false;   //Объект упрощенного аякс запроса
var sajaxReqHTMLid=""; //Глобальная переменная идентификатора контейнера

function sXMLSendReq(url,id,params){
     (sajaxReq)?sajaxReq.abort():null;
     sajaxReqHTMLid=id;
	sajaxReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	sajaxReq.onreadystatechange = sXMLgetReq;
	sajaxReq.open("POST",url, true);
	sajaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	sajaxReq.setRequestHeader("Accept-Charset", "windows-1251");
	sajaxReq.setRequestHeader("Content-Length",params.length);
	sajaxReq.send(params);
}

function sXMLgetReq(){
     if (sajaxReq){
		if (sajaxReq.readyState == 4){
		     if (sajaxReq.status == 200 && document.getElementById(sajaxReqHTMLid)) {
		          document.getElementById(sajaxReqHTMLid).className="";
		        	document.getElementById(sajaxReqHTMLid).innerHTML=sajaxReq.responseText;
	          }else{
//			     alert("К сожалению, сервер не вернул ответа на посланный запрос. Повторите попутку позднее. " + sajaxReq.statusText);
		    }
	     }
     }
}



function objectHTMLById(objectHTMLByIdid,objectHTMLByIdtext){
	if ((objectHTMLByIdobj=document.getElementById(objectHTMLByIdid)) && (objectHTMLByIdtext))		objectHTMLByIdobj.innerHTML=objectHTMLByIdtext;
}

function getObjectHTML(wid){
	if (getObjectHTMLobj=document.getElementById(wid))
		return (getObjectHTMLobj.innerHTML);
	else
	     return false;
}

function objectById(objectByIdid){
	return document.getElementById(objectByIdid);
}

//*------------Крнец функций AJAX



function cfm(prt,url) { //v2.0
  if (confirm(prt))
  {
        location.href=url;

  };
}



/*

Версия 1.4 (10.02.2009)

Внедрение

var calendar=new tСalendar('datetime',true,1211468200);
Где:
	datetime - идентификатор элемента ввода
	true - Отображение времени
	1211468200 - DateStamp в формате UNIX
*/

Function.prototype.bind=function(object){
  var method=this;
  var arg=arguments;
  return function(arg){return method.apply(object,arguments);}
}

function tСalendar(id,show_time,time_stamp){
	//Проверка параметров
	this.show_time=show_time;
	this.time_stamp=time_stamp;

	this.obj=document.getElementById(id);
	this.id=this.obj.id;
	if (!this.obj) return false;
	
	//Проверка на Браузры
	this.IE = (navigator.userAgent && (navigator.userAgent.indexOf("MSIE") != -1));
	this.FF = (navigator.userAgent && (navigator.userAgent.indexOf("Firefox") != -1));
	this.OP = (navigator.userAgent && (navigator.userAgent.indexOf("Opera") != -1));

	this.chtml = "<DIV id=cal_body style='position:absolute; top:0; left:0; width:175; height:169;'>";
	this.chtml +="<DIV style='font-family:Arial; position:absolute; top:0; left:0; width:100%; height:100%; background:#fff; border:1px solid #A5ACB2;'>";
	this.chtml +="<DIV style='text-align:center; white-space:nowrap; background:#E0E0EB; position:relative; left:0px; margin:4px; width:162px; height:23px; padding:2px;'><SELECT style='font-size:11px' ID="+this.id+"month>";
	this.chtml+="<OPTION>Январь<OPTION>Февраль<OPTION>Март<OPTION>Апрель<OPTION>Май<OPTION>Июнь<OPTION>Июль<OPTION>Август<OPTION>Сентябрь<OPTION>Октябрь<OPTION>Ноябрь<OPTION>Декабрь</SELECT>&nbsp;";
	this.chtml +="<SELECT style='font-size:10px' ID="+this.id+"year class=control>";
	
	dt = new Date();
	this.start_year=dt.getFullYear()-90; 
	this.end_year=dt.getFullYear()+5; 
	for (var i=this.start_year; i<this.end_year+1; i++) 
		this.chtml += "<OPTION>"+i;
	this.chtml +="</SELECT>";
	this.chtml +="<span class=hand style='font-family: sans-serif; margin-left:6px; font-size:11px; cursor:hand' id="+this.id+"close>x</span>";
	this.chtml +="<span class=hand style='font-family: sans-serif; margin-left:2px; font-size:9px; cursor:hand' id="+this.id+"ok>OK</span>";

	this.chtml +="</DIV>";
	this.chtml +="<style>";
	this.chtml +=".control {  font-size: 9px; height: 18px}";
	this.chtml +=".control1 {  font-size: 9px; height: 18px; width: 35px;}";
	this.chtml +=".oShield {position:absolute; top:0; left:0; width:0; height:0;}";
	this.chtml +=".day_off_header {padding-bottom:3px; border-bottom:1px solid #A5ACB2; height: 14px; width: 20px; font-size: 11px; color: #636C76; text-align: center;}";
	this.chtml +=".day_header {padding-bottom:3px; border-bottom:1px solid #A5ACB2; height: 14px; width: 20px; font-size: 11px;  color: #000; text-align: center; cursor: default; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".day_disabled {  font-size: 11px; color:#ddd; height: 14px; width: 20px; text-align: center; cursor: default; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".day {  font-size: 11px; background-color: #FFFFFF; height: 14px; width: 20px; text-align: center; cursor: default;  padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".day_selected { font-size: 11px;  background-color: #FBC84F; height: 12px; width: 18px; text-align: center; cursor: default; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".day_off { font-size: 11px;  height: 14px; width: 20px; text-align: center ; color: #636C76 ; cursor: default; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".day_mouseover { font-size: 11px;  color: #000000; background-color: #DEDEDE; height: 14px; width: 20px; text-align: center; cursor: default; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px}";
	this.chtml +=".hand {cursor:hand; cursor:pointer}";
	this.chtml +=".calendar_button { font-size:11px; cursor:hand; cursor:pointer; border-bottom:1px dashed #A5ACB2; text-decoration: none; color:#A5ACB2}";
	this.chtml +="-->";
	this.chtml +="</style>";
	this.chtml +="<table width=140 style='border-bottom:1px solid #A5ACB2; margin-left:16px' ID="+this.id+"CalTable border=0 cellpadding=2 cellspacing=0>";
	this.chtml +="<tr> ";
	this.chtml +="<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><td class=day_off_header>Вс</td>";
	this.chtml +="</tr>";
	for (var i=0; i<7; i++) 
		this.chtml +="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
	this.chtml +="</table>";
	this.chtml +="<DIV style='width:166px; margin-left:4px; text-align:center'>";
	if (this.show_time) this.chtml +="<span class=calendar_button ID="+this.id+"time>Время</span>&nbsp;&nbsp;";
	this.chtml +="<span class=calendar_button ID="+this.id+"today>Cегодня</span>";
	this.chtml +="&nbsp;&nbsp;<span class=calendar_button ID="+this.id+"clear value=''>Очистить</span>";
	this.chtml +="</DIV>";
	this.chtml +="</CENTER></DIV></DIV>";
	
	this.showDate=function(){ //Отображает дату в value объекта
		month=this.date.getMonth()+1;
		d=this.date.getDate();
		d=((d<10)?'0':'')+d;
		this.obj.value=d+'.'+((month<10)?"0":"")+month+'.'+(this.date.getFullYear());
		if (this.show_time){
			this.obj.value+=' ';
			h=this.date.getHours();
			m=this.date.getMinutes();
			s=this.date.getSeconds();
			h=((h<10)?'0':'')+h;
			m=((m<10)?'0':'')+m;
			s=((s<10)?'0':'')+s;
			this.obj.value+=h+':'+m+':'+s;
		}
	}
	
	this.showTime=function(obj){ //Отображает время на календаре
		h=this.date.getHours();
		m=this.date.getMinutes();
		s=this.date.getSeconds();
		h=((h<10)?'0':'')+h;
		m=((m<10)?'0':'')+m;
		s=((s<10)?'0':'')+s;
//		this.time_object.value+=h+':'+m+':'+s;
		this.time_object.innerHTML=h+':'+m+':'+s;
	}
	
	this.get_time=function(){ //Парсит время в дату из календаря
		time_string=this.time_object.innerHTML;
	
		h=time_string.substr(0,2);
		mi=time_string.substr(3,2);
		s=time_string.substr(6,2);
		if(h>=0 && h<24 && mi>=0 && mi<60 && s>=0 && s<60){
			this.date.setHours(h);
			this.date.setMinutes(mi);
			this.date.setSeconds(s);
		}
	}
	
	this.parseDate=function(date){ //Добавляет в дату удобные поля для работы
		if (!date) return false;
		ret=date;
		month=date.getMonth()+1;
		ret.d=date.getDate();
		ret.m=((month<10)?"0":"")+month;
		ret.y=date.getFullYear();
		ret.h=date.getHours();
		ret.mi=date.getMinutes();
		ret.s=date.getSeconds();
		return ret;
	}
	
	this.eventHandlerClick=function () { //Клик на день
		if (this.IE){
			var sobj=window.document.selection;
			var Range = sobj.createRange();
			var parent = Range.parentElement();
		}else{
			var selection = getSelection();
			range = selection.getRangeAt(0);
			parent = range.commonAncestorContainer;
		}
		while (parent && parent.tagName!="TD")
			parent=parent.parentNode;
		
		if (parent.tagName=="TD"){
			anEvObj=parent;
			this.day=parent.innerHTML;
			this.date.setDate(this.day);
			this.submit_calendar();			
		}
	}
	
	this.getDaysInMonth=function(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 (this.isLeapYear(x_year)) { days=29; }
			else { days=28; }
		}
		return (days);
	}
	
	this.isLeapYear=function(){
		if (((this.x_year % 4)==0) && ((this.x_year % 100)!=0) || ((this.x_year % 400)==0)) {
			return (true);
		}else{ 
			return (false); }
	}

	this.displayCalendar=function(x_month, x_year, x_day) {
		x_month = parseInt(x_month);
		x_year = parseInt(x_year);
		var days = this.getDaysInMonth(x_month+1,x_year);
		if (x_month > 1) 
			var days_before = this.getDaysInMonth(x_month,x_year);
		else 
			var days_before = this.getDaysInMonth(12,x_year-1);
		if (this.day > days) 
			this.day=days;
		if (!x_day) 
			x_day=this.day;
		var curr_day = 0;
		var firstOfMonth = new Date (x_year, x_month, 1);
		var startingPos = firstOfMonth.getDay();
		startingPos=(startingPos==0)?7:startingPos;
		
		for (i=0; i<42; i++){
			curr_day=i-startingPos+2;
			curr_cell_obj=this.table_object.rows[Math.floor(i/7)+1].cells[i%7];
			(curr_cell_obj.cellIndex<5) ? curr_cell_obj.className="day":curr_cell_obj.className="day_off";

			if (curr_day <= 0 ) {
				curr_cell_obj.innerHTML=curr_day + days_before;
				curr_cell_obj.className="day_disabled";
				curr_cell_obj.onmouseover="";
				curr_cell_obj.onmouseout="";
			}


			else if (curr_day > 0 && curr_day <= days) {
				curr_cell_obj.innerHTML=curr_day;
				curr_cell_obj.onmouseover=function(){if (this.className!="day_selected") this.className="day_mouseover";};
				curr_cell_obj.onmouseout=function(){if (this.className!="day_selected") (this.cellIndex<5) ? this.className="day":this.className="day_off";};
			}

			else if (curr_day > days) {
				this.table_object.rows[Math.floor(i/7)+1].cells[i%7].innerHTML=curr_day-days;
				curr_cell_obj.className="day_disabled"
				curr_cell_obj.onmouseover="";
				curr_cell_obj.onmouseout="";
			}

			curr_cell_obj.onclick=function(){this.eventHandlerClick()}.bind(this);
			curr_cell_obj.ondblclick=function(){this.eventHandlerDblClick()}.bind(this);

			if (curr_day==x_day) 
				this.table_object.rows[Math.floor(i/7)+1].cells[i%7].className="day_selected";
		}
	}
	
	this.setToday=function() {
		this.date=new Date();
		this.submit_calendar();	
	}
 
	this.calcTop=function(zzz){
		t=0;
		while ((zzz)&&(zzz.tagName!='BODY')){
               t+=zzz.offsetTop;
			zzz=zzz.offsetParent;
		}
		return (t+25);
	}

	this.calcLeft=function(zzz){
		l=0;		
		while ((zzz)&&(zzz.tagName!='BODY')){
               l+=zzz.offsetLeft;
			zzz=zzz.offsetParent;
		}
		return (l+1);
	}

	this.open=function(){  //Открыть календарь
		if (this.show) return;
		this.show=true;
		this.undo_date = new Date(this.date);//Дата перед началом модификаций
		this.init   = new Date();
		this.day   = this.init.getDate();
		this.oDiv = document.createElement("DIV");
		this.oShield= document.createElement("DIV");
		this.oShield.className="oShield";
		this.oShield.onclick=function(){this.close()}.bind(this);

		this.oDiv.innerHTML=this.chtml;
		this.oDiv.style.position="absolute";
		this.oDiv.style.zIndex=301;
		this.oShield.style.zIndex=300;
		document.body.appendChild(this.oShield);
		document.body.appendChild(this.oDiv);

		this.oDiv.style.left=this.calcLeft(this.obj);
		this.oDiv.style.top=this.calcTop(this.obj);
		
		
		this.month_input_object=document.getElementById(this.id+"month");
		this.year_input_object=document.getElementById(this.id+"year");
		this.close_object=document.getElementById(this.id+"close");
		this.table_object=document.getElementById(this.id+"CalTable");
		this.today_object=document.getElementById(this.id+"today");
		this.clear_object=document.getElementById(this.id+"clear");
		this.time_object=document.getElementById(this.id+"time");
		this.ok_object=document.getElementById(this.id+"ok");

		this.date=this.parseDate(this.date);
		
		this.month_input_object.onchange=function(){this.date.setMonth(this.month_input_object.selectedIndex); this.displayCalendar(this.month_input_object.selectedIndex,this.year_input_object.value)}.bind(this);
		this.year_input_object.onchange=function(){this.date.setFullYear(this.year_input_object.selectedIndex+this.start_year); this.displayCalendar(this.month_input_object.selectedIndex,this.year_input_object.value)}.bind(this);
		
		if (this.time_object) this.time_object.onclick=function(){this.block_close=true; if (time_str=prompt("Введите время в формате (чч:мм:сс)",this.time_object.innerHTML)) { this.time_object.innerHTML=time_str	; this.get_time();} setTimeout(function(){this.block_close=false;}.bind(this),100); }.bind(this);
		
		this.close_object.onclick=function(){this.date=this.undo_date; this.close()}.bind(this);//Отмена и закрытие
		this.ok_object.onclick=function(){this.submit_calendar()}.bind(this);//Отмена и закрытие
		this.today_object.onclick=function(){this.setToday()}.bind(this);
		this.clear_object.onclick=function(){this.obj.value=''; this.close()}.bind(this);
		
		this.month_input_object.selectedIndex=this.date.m-1;
		this.year_input_object.selectedIndex=this.date.y-this.start_year;
		
		if (this.show_time)
			this.showTime(); 
		
		this.displayCalendar(this.date.m,this.date.y,this.date.d);

		this.oDiv.onmouseover=function(){this.global_mouseon=1;}.bind(this);
		this.oDiv.onmouseout=function(){this.global_mouseon=2;}.bind(this);
		
		this.global_mouseon=0;
		this.block_close=false;
		
		document.onclick=function(){
			if (this.global_mouseon==2 && !this.block_close) this.close();
		}.bind(this);	
		
		setTimeout(function(){
			if (this.global_mouseon==0) this.global_mouseon=2;
		}.bind(this),100);		
	}	
	
	this.submit_calendar=function(){ //Подтверждение правильности задания даты и времени
		this.showDate();
		this.obj_value.value=Math.floor(this.date.valueOf()/1000);
		this.close();
	}
	
	this.close=function(){ //Закрыть календарь
		//fade._out(this.oDiv.id, 1, 0); 
		document.body.removeChild(this.oDiv);
		document.body.removeChild(this.oShield);
		this.show=false;
		this.global_mouseon=0;
	}	

	this.submit=function(){ //Событие при субмите формы
		this.obj_value.value=Math.floor(this.date.valueOf()/1000);
//		this.close();
	}

	this.init=function(){ //Инициализация объекта
		if (this.time_stamp){ //Вычисляем дату из таймстампа если он передан
			js_time_stamp = this.time_stamp * 1000;
			this.date = new Date(js_time_stamp);
			this.date.d=this.date.getDate();
			this.showDate();
		}else{
			this.date = new Date();
			if (this.obj.value!=''){
				d=this.obj.value.substr(0,2);
				m=this.obj.value.substr(3,2);
				y=this.obj.value.substr(6,4);

				if (d > 0 && d <= this.getDaysInMonth(m,y) && m  > 0 && m < 13 && y > 1899 && y < 2100){
					this.date.setDate(d);
					this.date.setMonth(m-1);
					this.date.setFullYear(y);
					
					if (this.show_time){
						h=this.obj.value.substr(11,2);
						mi=this.obj.value.substr(14,2);
						s=this.obj.value.substr(17,2);
						if(h>=0 && h<24 && mi>=0 && mi<60 && s>=0 && s<60){
							this.date.setHours(h);
							this.date.setMinutes(mi);
							this.date.setSeconds(s);
						}
					}
				}
			}
		}
		
		//Поиск формы
		var tmp_frm=this.obj.parentNode;
		while((tmp_frm) && (tmp_frm.nodeName!='FORM'))
			tmp_frm=tmp_frm.parentNode;
		if (tmp_frm){
			this.form=tmp_frm;
			old_name=this.obj.name; //Создаем дополнительный объект, заменяем имя
			this.obj.name=old_name+'_text';
			this.obj_value= document.createElement("input");
			this.obj_value.type='Hidden';
			this.obj_value.name=old_name;
			this.form.appendChild(this.obj_value);
			this.obj_value.value=Math.floor(this.date.valueOf()/1000);
		}else{
			alert("JavaScript tСalendar error: Не найдена форма.");
		}


		//Настройка событий

		this.obj.onclick=function(){this.open()}.bind(this);
		this.form.onsubmit=function(){this.submit()}.bind(this);
	
	}

	
	if (this.IE)
		    window.attachEvent("onload",function(){this.init()}.bind(this));
	else
		    window.addEventListener("load",function(){this.init()}.bind(this),true);
	
		
}//Конец объекта