var LinkDivActive = 0;
var onDiv;
var timeOnDiv;
var layerRef;
var styleRef;
var showVar;
var hideVar;
var timeOnSel;
var monthes=new Array('Январь', "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
var gmonth=new Array('января', "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");



layerRef="document.getElementById('";
styleRef="').style";
showVar="'visible'";
hideVar="'hidden'";
ShkafVersion = navigator.appVersion.substring(0,1);



if ((navigator.appName == "Netscape")&&(ShkafVersion < 5)) {
 layerRef="document.";
 styleRef="";
 showVar="'show'";
 hideVar="'hide'";
}
/* else {
 layerRef="document.all.";
 styleRef=".style";
 showVar="'visible'";
 hideVar="'hidden'";
}
*/

function hideDiv(divn) {
eval(layerRef+divn+styleRef+'.visibility = '+hideVar);
}

function showDiv(divn) {
eval(layerRef+divn+styleRef+'.visibility = '+showVar);
}



function sbm_ou(o,f)
{
	f_ = document.getElementById(f);

	eval("L=f_."+o+"_l");
	eval("R=f_."+o+"_r");
	B=document.getElementById(o+"_b");

	L.src='/img/subm_u_l.gif';
	R.src='/img/subm_u_r.gif';
	B.className='submit';
}
function sbm_ov(o,f)
{
	f_ = document.getElementById(f);

	eval("L=f_."+o+"_l");
	eval("R=f_."+o+"_r");
	B=document.getElementById(o+"_b");

	L.src='/img/subm_v_l.gif';
	R.src='/img/subm_v_r.gif';
	B.className='submit1';
}


function showLinkDiv(divn) {
if (timeOnDiv != null) {
clearTimeout(timeOnDiv);
hideDiv(onDiv);
}
showDiv(divn);
onDiv = divn;
}

function divTimer() {
 timeOnDiv = setTimeout("divOut()",1000)
}

function divOut() {
 if (LinkDivActive == 0) {
  hideDiv(onDiv);
 }
}

function LinkDivOver() {
 LinkDivActive = 1;
 clearTimeout(timeOnDiv);
}

function LinkDivOut() {
 LinkDivActive = 0;
 timeOnDiv = setTimeout("divOut()",1000)
}

function chb(o, f, v)
{

	o1=o;

	if (o.charAt(o.length-2)=='[' && o.charAt(o.length-1)==']')
	{
	o1=o.substr(0,o.length-2);
	}

	f_ = document.getElementById(f);

	eval("cht=f_.all['"+o+"']");

	eval ("imt=f_."+o1+"_img_"+v);

	cht_a=cht;

	if (cht.length)
	{
		for (i=0; i<cht.length; i++)
		{
			if (cht[i].value==v) cht_a=cht[i]
		}
	}

	cht=cht_a;

	if (cht.checked)
	{
		imt.src='/img/ch0.gif';
		cht.checked=false;
	}
	else
	{
		imt.src='/img/ch1.gif';
		cht.checked=true;
	}


}


function opb(o, f, v)
{

	f_ = document.getElementById(f);

	eval("oo=f_."+o);

	for (i=0; i<oo.length; i++)
	{

	eval("oi=f_."+o+"_img_"+oo[i].value);
		if (v==oo[i].value)
		{
			oo[i].checked=true;
			oi.src='/img/op1.gif';
		}
		else
		{
			oo[i].checked=false;
			oi.src='/img/op0.gif';
		}
	}
}

function ov(x)
{
 if (x.className=='o0') 
	x.className='o1'
	else
	x.className='o10'
}

function ou(x)
{
 if (x.className=='o1') 
	x.className='o0'
	else
	x.className='o00'
}

function sv(a, b, f)
{

f_ = document.getElementById(f);

eval("o1=f_."+a+".value");

bz = document.getElementById(a+"_"+o1);

if (o1!="")
	{
	bz.className='o0';
	}
zz=document.getElementById(a+"_"+b);
zz.className='o00';
eval("f_."+a+".value="+b);
dfd = document.getElementById(a+"_t");
dfs = document.getElementById(a+"_"+b);

dfd.innerHTML=dfs.innerHTML;

dfe = document.getElementById(a+"_m");
dfe.style.display='none';

dfl = document.getElementById(a+"_l");
dfb = document.getElementById(a+"_b");

dfl.src='/img/input_l.gif';
dfb.src='/img/sel_but.gif';
}

function selscrlup(m, z)
{
 o=document.getElementById(m+"_scrl");
 sl=document.getElementById(m+"_slider");
 o.scrollTop-=z;
 da=o.scrollHeight-100;
 if (da<1) return true;
 perc=o.scrollTop/da;
 sl.style.top=perc*60;

 timeOnSel=setTimeout("selscrlup('"+m+"', "+z+")", 50);
}

function selscrldn(m, z)
{
 o=document.getElementById(m+"_scrl");
 sl=document.getElementById(m+"_slider");
 o.scrollTop+=z;
 da=o.scrollHeight-100;
 if (da<1) return true;
 perc=o.scrollTop/da;
 sl.style.top=perc*60;
 if (z<=29) timeOnSel=setTimeout("selscrldn('"+m+"', "+z+")", 50);
}

function onv(a, f)
{
bz=document.getElementById(a+"_m");
bz.style.display='block';
eval("ooo="+a+"_is_ok");
if (ooo!="")
{

 eval (ooo);
 eval (a+"_is_ok=''");
}

f_ = document.getElementById(f);


eval("f_."+a+"_l.src='/img/sel_on_l.gif'");
eval("f_."+a+"_b.src='/img/sel_but_off.gif'");

eval("o1=f_."+a+".value");
if (o1!="")
	{

//	eval(a+"_"+o1+".scrollIntoView(true)");
	selscrldn(a, 0);
	}

return false;
}
function offv(a, f)
{
bz=document.getElementById(a+"_m");
bz.style.display='none';

f_ = document.getElementById(f);

eval("f_."+a+"_l.src='/img/input_l.gif'");
eval("f_."+a+"_b.src='/img/sel_but.gif'");
return false;
}


function xo(o)
{
	if (o.className=='day0')
	{
		o.className='day1'
	} else
	{
		o.className='day10'
	}
}
function xu(o)
{
	if (o.className=='day1')
	{
		o.className='day0'
	} else
	{
		o.className='day00'
	}
}
function xc(n, o, fr, tm)
{
	eval('curdate='+o+'_obj');
	curdate.setDate(n);
	offv(o, fr);
	make_calendar(o, tm, fr);
}

function setyear(o, tm, fr, x)
{
	eval('curdate='+o+'_obj');
	y=curdate.getYear()+x;
	if (y<1900) y+=1900;
	curdate.setYear(y);

	make_calendar(o, tm, fr);
}

function setmonth(o, tm, fr, x)
{
	eval('curdate='+o+'_obj');
	m=curdate.getMonth()+x;
	if (m<0) {m=11; curdate.setYear(curdate.getYear()-1)};
	if (m>11) {m=0; curdate.setYear(curdate.getYear()+1)};
	curdate.setMonth(m);

	make_calendar(o, tm, fr);
}

function sethour(o, tm, fr, x)
{
	eval('curdate='+o+'_obj');
	m=curdate.getHours()+x;
	if (m<0) m=23;
	if (m>23) m=0;
	curdate.setHours(m);

	make_calendar(o, tm, fr);
}

function setmin(o, tm, fr, x)
{
	eval('curdate='+o+'_obj');
	m=curdate.getMinutes()+x;
	x=0;
	if (m<0) {m=50; x=-1};
	if (m>59) {m=0; x=1};
	curdate.setMinutes(m);

	sethour(o,tm,fr,x);

	make_calendar(o, tm, fr);
}

function make_calendar(o, tm, fr)
{
	lst= document.getElementById(o+'_days');
	eval('curdate='+o+'_obj');


	f_=document.getElementById(fr);

	y=curdate.getYear();
	if (y>1900 && y<2000) {
		y-=1900;
		curdate.setYear(y);
		}

	m=curdate.getMonth();
	d=curdate.getDate();
	h=curdate.getHours();
	min=curdate.getMinutes();

	min=Math.floor(min/10)*10;
	curdate.setMinutes(min);

	tmp=new Date((m==11)?(y+1):(y), (m==11)?(0):(m+1), 1);
	tmp2=new Date(y, m, 1);


	firstnext=tmp.getDay();
	firstcur=tmp2.getDay();


	if (firstnext==0) firstnext=7;
	if (firstcur==0) firstcur=7;

	s="<table cellspacing=1 cellpadding=1 border=0 style='width:140px'><tr>";
	s+='<td class=day_t>пн</td>';
	s+='<td class=day_t>вт</td>';
	s+='<td class=day_t>ср</td>';
	s+='<td class=day_t>чт</td>';
	s+='<td class=day_t>пт</td>';
	s+='<td class=day_t>сб</td>';
	s+='<td class=day_t>вс</td></tr><tr>';
	for (i=1; i<firstcur; i++)
	{
		s+="<td class=day>&nbsp;</td>";
	}

	for (j=1; j<=31; j++)
	{
		if (i==1) s+="<tr>";
		s+="<td onmouseover='xo(this)' onmouseout='xu(this)' onclick='xc("+j+",\""+o+"\",\""+fr+"\", "+tm+")' class=day"+(d==j ? "1>" : "0>")+j+"</td>";
		i++;
		if (i==8) {i=1; s+='</tr>'};
		if (firstnext==i && j>27) break;
	}

	if (i!=1)
	{
		for (i1=i; i<8; i++)
		{
			s+="<td class=day>&nbsp;</td>";
		}
	}

	s+="</tr></table>";



	lst.innerHTML=s;

	oyt = document.getElementById(o+"_year_text");
	omta = document.getElementById(o+"_month_text");

	oyt.innerHTML = curdate.getYear()+(curdate.getYear()<1900 ? 1900 : 0);
	omta.innerHTML=monthes[curdate.getMonth()];

	if (tm==1)
	{
		timeIfPresent=", "+curdate.getHours()+":"+(curdate.getMinutes()<10 ? "0" : "")+curdate.getMinutes();

		oht = document.getElementById(o+"_hour_text");
		oit = document.getElementById(o+"_min_text");

		oht.innerHTML=curdate.getHours();
		oit.innerHTML=(curdate.getMinutes()<10 ? "0" : "")+curdate.getMinutes();

		f_ = document.getElementById(fr);

		eval("f_."+o+"_hour.value=h");
		eval("f_."+o+"_min.value=min");
	}
	else timeIfPresent="";

	oot = document.getElementById(o+"_t");

	oot.innerHTML=curdate.getDate()+" "+gmonth[curdate.getMonth()]+" "+(curdate.getYear()+(curdate.getYear()<1900 ? 1900 : 0))+timeIfPresent;

	eval("f_."+o+"_year.value=y+(y<1900 ? 1900 : 0)");
	eval("f_."+o+"_month.value=m");
	eval("f_."+o+"_day.value=d");
}

function resetall(o, tm, fr)
{
	f_ = document.getElementById(fr);

	eval("f_."+o+"_year.value=''");
	eval("f_."+o+"_month.value=''");
	eval("f_."+o+"_day.value=''");
	if (tm==1)
	{
	eval("f_."+o+"_hour.value=''");
	eval("f_."+o+"_min.value=''");
	}
	oot = document.getElementById(o+"_t");
	oot.innerHTML='';
	offv(o,fr);
}

function setnow(o, tm, fr)
{
	eval(o+'_obj=new Date()');
	offv(o,fr);
	make_calendar(o, tm, fr);
}


function _dialog(a, c)
{
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
c = "scrolling=no,status=no," + c;
if (win_ie_ver >= 5.5) {
		while (c.match(/=/))
		{
			c=c.replace(/=/, ':');
		};
		while (c.match(/,/))
		{
			c=c.replace(/,/, ';');
		};
		var r=showModalDialog(a, window,c);
	}
	else
	{
	w=open(a,"diag",c);
	}
}


function show_dialog(n, f, m)
{
  att='?f='+f+'&n='+m;
  if (n=='_smile') _dialog("/dialogs/smiles.php"+att, "resizable=no,help=no,status=no,scrollbars=no,width=550,height=400,maximize=no");
  if (n=='_image') _dialog("/dialogs/image.php"+att, "resizable=no,help=no,status=no,scrollbars=no,width=340,height=100,maximize=no");
  if (n=='image_browse') _dialog("/dialogs/image_browse.php"+att, "resizable=no,help=no,status=no,scrollbars=no,width=550,height=360,maximize=no");
  if (n=='_preview') {
	w=(screen.width-400)/2;
	h=(screen.height-300)/2;
	prewindow=open("", 'pwn', "width=400,height=300,toolbar=no,status=no,scrollbars=yes,resizable=yes,left="+w+",top="+h);
	eval ("document.preview_form.message.value=document."+f+"."+m+".value");
	document.preview_form.submit();
		}
}

function showHelp(n)
{ w=450; h=300;
 hw= _dialog("/help/help.php?id="+n, "resizable=yes,help=no,status=no,scroll=yes,width=450,height=300,maximize=yes");

}


function instag(tag, frm, named, row)
{
var parameters="";
if (tag.match(/=/))
	{
		parameters=tag.replace(/.*?(=.*?)/, "$1");
		tag=tag.replace(/(.*?)[=].+/, "$1");
	}
	eval ("var cur_editor=document."+frm+"."+named);
	cur_editor.focus();

	var s=document.selection.createRange().text;

	if (s=="")
	{
		eval("ca=mode_"+tag);
		if (ca) 
			{
			document.selection.createRange().text+="[/"+tag+"]"; 
			eval("mode_"+tag+"=false");
			row.style.backgroundImage="url(/img/butn_u.gif)";
			}
			else
			{
				if (tag=="color" && parameters=="")
				{
				att='?f='+frm+'&n='+named;
				_dialog("/dialogs/color.php"+att, "resizable=no,help=no,status=no,scroll=no,width=200,height=150,maximize=no");
				}
			else
			{
				document.selection.createRange().text+="["+tag+parameters+"]"; 
				eval("mode_"+tag+"=true");
				row.style.backgroundImage="url(/img/butn_d.gif)";
			}
			}
			
	}
	else
	{

				if (tag=="color" && parameters=="")
				{
				att='?f='+frm+'&n='+named;
				_dialog("/dialogs/color.php"+att, "resizable=no,help=no,status=no,scroll=no,width=200,height=150,maximize=no");
				}
			else
				{
				s=document.selection.createRange().text;
				document.selection.createRange().text="["+tag+parameters+"]"+s+"[/"+tag+"]";
				}
	}

cur_editor.focus();
}


function p_s( frm, named, tag)
{

	eval ("var cur_editor=document."+frm+"."+named);
	cur_editor.focus();
	var s=document.selection.createRange().text;
	if (s=="")
	{
			document.selection.createRange().text+=tag; 
	}

cur_editor.focus();
}


function putimg(u, align)
{
	if (u.match(/http:/))
	{
	  src_path="http://zchat.infobox.ru/inc/preview.php?type=middle&path="+u;
	  u="http://zchat.infobox.ru/inc/preview.php?type=full&path="+u;
	}
	else
	{
	  src_path="http://127.0.0.205/images/"+u+"_pre.jpg";
		u = "http://127.0.0.205/images/"+u+".jpg";
	}

	document.write ("<img src='"+src_path+"'"+align+" style='cursor: hand' onClick='openpic("+'"'+u+'"'+")'>");
}

function openpic(u)
{
  picc = open(u, '', 'toolbar=no, resizable=yes, scrollbars=auto');
}

function cite(frm, named, n)
{
	cite_text = document.selection.createRange();

	c = cite_text.text;

/*	h = cite_text.htmlText;
	h1 = h;

	h = h.replace(/[\s| ]/g, "");
	h = h.replace(/[\s| |\r|\n]/g, "");

	if (h=='') return "";

	h = h1;
*/
	cite_text = "[b]"+n+" пишет:[/b][quote]" + c + "[/quote]";

	p_s(frm, named, cite_text);
}