var stat = '';


function spoiler (q)
{
obj = document.getElementById(q);
if (obj.style.display=='block') obj.style.display='none';
else
obj.style.display='block';
}


function mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}


function prev_s1 (q1,q2)
{
s = document.getElementById('prev_s');
s.style.position="absolute";
if (q2!=0 && s.style.display!='block')
  {
  s.innerHTML = "<img src='"+q1+"'>";

document.onmouseover = function(e){
var mCur = mousePageXY(e);
//alert('x='+mCur.x+' y='+mCur.y); 
s.style.left=mCur.x+'px';
s.style.top=mCur.y+'px';};

  s.style.display='block';
  }
  else
  s.style.display='none';
}


function echo_in (div_name, text)
{
document.getElementById(div_name).innerHTML=text;
}

function copy_check()
{
q = document.getElementById('copy').innerHTML;
if (q != 'Создание: студия <A href="http://yaweb.ru">WebGraphic</A>')
{
alert ('Рекомендуется вернуть на место копирайт следующего содержания: \n Создание: студия <A href="http://yaweb.ru">WebGraphic</A>');
window.location.replace('http://yaweb.ru');
}
}


function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}



function preview(pic,w,h)
{
 i1 = Math.round(getClientWidth()/2 - w/2);
 i2 = Math.round(getClientHeight()/2 - h/2);
w=window.open('/view.php?pic='+pic,'new','top='+i2+', left='+i1+', width='+w+', height='+h);
}


function add_dir (q,q1,q2)
{
st = "<form action='add_dir.php' method='post' name='add_dir'>";
if (q==0)
st += "<b>Создать новый раздел</b>";
else
st += "<b>Создать галерею</b>";
st += "<input type='hidden' name='dir' value='"+q1+"'>";
st += "<input type='hidden' name='num' value='"+q2+"'>";
st += "<input type='hidden' name='type' value='"+q+"'>";
st += "<br><input type='text' style='width: 500px;' value='' name='head'>&nbsp;";
st += "<br><br><input type='submit' value='Создать' class='btn'>";
st += "<input type='button' class='btn' onclick='fog_out();' value='Закрыть'></form>";
echo_in ('mess_in',st);
fog.style.display='block';
mess.style.display='block';
	obj = document.forms['add_dir'].head;
  obj.focus();
}


function fog_out()
{
fog.style.display='none';
mess.style.display='none';
echo_in ('mess_in','');
mess.style.top='50%';
}


function ch_head(q,q1,q2)
{
st2 = document.getElementById(q2+'_head_'+q);
st1 = st2.value;
st = "<input type='text' style='width:428px; height: 15px;' value='"+st1+"' onBlur='chHsave("+q+","+q1+",\""+q2+"\");' id='"+q2+"_head1_"+q+"'>";
echo_in (q2+'_'+q,st);
t=document.getElementById(q2+'_head1_'+q);
t.focus();
}

function chHsave(q,q1,q2)
{
st2 = document.getElementById(q2+'_head_'+q);
st1 = document.getElementById(q2+'_head1_'+q);
st2.value = st1.value;
st = "<a href='admin.php?dir="+q1+"'>"+st1.value+"</a>";
echo_in ('dir_'+q,st);
}

function Tch_head(q,q1,q2)
{
st2 = document.getElementById('txt_head_'+q2);
st1 = st2.value;
st = "<input type='text' style='width:350px; height: 15px;' value='"+st1+"' onBlur='TchHsave(\""+q+"\","+q1+","+q2+");' id='txt_head1_"+q2+"'>";
echo_in ('txt_'+q2,st);
t=document.getElementById('txt_head1_'+q2);
t.focus();
}

function TchHsave(q,q1,q2)
{
st2 = document.getElementById('txt_head_'+q2);
st1 = document.getElementById('txt_head1_'+q2);
st2.value = st1.value;
st = "<a href='text_ed.php?id="+q+"&dir="+q1+"' target='_blank'>"+st1.value+"</a>";
echo_in ('txt_'+q2,st);
}



function Pch_head(q)
{
st2 = document.getElementById('head_'+q);
st3 = document.getElementById('dir_'+q);
st3.style.display='block';

st4 = document.getElementById('ico_'+q);
st4.style.display='none';

st1 = st2.value;
st = "<textarea style='width: 340px; height:50px;' onBlur='PchHsave("+q+");' id='head1_"+q+"'>"+st1+"</textarea>";
echo_in ('dir_'+q,st);
t=document.getElementById('head1_'+q);
t.focus();
}


function PchHsave(q)
{
st2 = document.getElementById('head_'+q);
st1 = document.getElementById('head1_'+q).innerText;
st3 = document.getElementById('dir_'+q);
st3.style.display='inline';

st4 = document.getElementById('ico_'+q);
st4.style.display='inline';

st4 = document.getElementById('tmp_'+q).value;
st2.value = st1;
st3.innerHTML = "<a href='javascript:preview("+st4+");'>"+st1+"</a>";
}



function Fch_head(q)
{
st2 = document.getElementById('head_'+q);
st3 = document.getElementById('dir_'+q);
st3.style.display='block';

st4 = document.getElementById('ico_'+q);
st4.style.display='none';

st1 = st2.value;
st = "<textarea style='width: 370px; height:50px;' onBlur='FchHsave("+q+");' id='head1_"+q+"'>"+st1+"</textarea>";
st3.innerHTML = st;
t=document.getElementById('head1_'+q);
t.focus();
}


function FchHsave(q)
{
st2 = document.getElementById('head_'+q);
st1 = document.getElementById('head1_'+q).innerText;
st3 = document.getElementById('dir_'+q);
st3.style.display='inline';

st4 = document.getElementById('ico_'+q);
st4.style.display='inline';

st4 = document.getElementById('tmp_'+q).value;
st2.value = st1;
st3.innerHTML = "<a href='"+st4+"' target='_blank'>"+st1+"</a>";
}




function user(q1,q2,q3,q4,q5,q6,q7,q8)
{
st = "<form action='add_user.php' method='post' style='text-align: center; width: 100%;'><table border=0 align=center>";
st += "<tr><td>Логин</td><td><input type='text' style='width: 300px' value='"+q1+"' name='login'></td></tr>";
st += "<tr><td>Пароль</td><td><input type='text' style='width: 300px' value='"+q2+"' name='pass'></td></tr>";
st += "<tr><td>e-mail</td><td><input type='text' style='width: 300px' value='"+q7+"' name='mail'></td></tr>";
st += "<tr><td>Доп.инф.</td><td><textarea style='width: 300px; height: 50px' name='info'>"+q3.replace(/<br>/g,"\r\n")+"</textarea></td></tr>";

if (q4=='0')
{ st1 = ' selected'; st2 = ''; st3 = ''; }
if (q4=='2')
{ st3 = ' selected'; st2 = ''; st1 = ''; }
if (q4=='1')
{ st2 = ' selected'; st1 = ''; st3 = ''; }
st += "<tr><td>Права</td><td><select size=1 style='width: 300px' name='type'><option value=0"+st1+">Администратор</option><option value=1"+st2+">Пользователь</option><option value=2"+st3+">Модератор</option></select></td></tr>";

if (q6!='0') st1 = 'checked'; else st1='';
st += "<tr><td>Доступ в ПУ</td><td><input type='checkbox' style='border: none;' name='cms' "+st1+"></td></tr>";

if (q8!='0') st1 = 'checked'; else st1='';
st += "<tr><td>Актив.</td><td><input type='checkbox' style='border: none;' name='active' "+st1+"></td></tr>";

if (q5!='0')
st += "<tr><td>Удалить</td><td><input type='checkbox' style='border: none;' name='del'></td></tr>";

st += "<tr><td></td><td><input type='hidden' value='"+q5+"' name='id'><input type='submit' value='Сохранить' class='btn'>";
st += "<input type='button' class='btn' onclick='fog_out();' value='Закрыть'></td></tr></table></form>";
echo_in('mess_in',st);
fog.style.display='block';
mess.style.display='block';
}


function cod (q1,q2)
{
q = document.getElementById(q1);
if (q2==0) q.style.height='80px'; else q.style.height='20px';
}


function ch_all(q)
{
st = parseFloat(document.getElementById(q+'_total').value);

for (i=0; i<st; i++)
  {
  st1 = q+'_ch_'+i;
  if (document.getElementById(st1).checked!=true)
  document.getElementById(st1).checked=true;
  else
  document.getElementById(st1).checked=false;
  }
}


function new_win(q,w,h)
{
 i1 = Math.round(getClientWidth()/2 - w/2);
 i2 = Math.round(getClientHeight()/2 - h/2);
w=window.open(q,'new','top='+i2+', left='+i1+', width='+w+', height='+h+',scrollbars=1');
}


function pop_up(q,w,h)
{
 i1 = Math.round(getClientWidth()/2 - w/2);
 i2 = Math.round(getClientHeight()/2 - h/2);
document.getElementById(q).style.left=i1;
document.getElementById(q).style.top=i2;
}
