var stat = '';


function show(q)
{
fog.style.display='block';
document.getElementById("show1").src='show.php?id='+q;
mess.style.display='block';
}


function getElementComputedStyle(elem, prop)
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  
  return "";
}

var scroll=0;
var p=0;


function scroll_up()
{
clearInterval(qq);
if (scroll>0) 
qq=setInterval('su()',1);
}


function su()
{
scroll=scroll-3; p=p-3;
document.getElementById("txt").scrollTop=scroll;
if (p==hh || scroll<=0) clearInterval(qq);
}

function scroll_dn()
{
h = getElementComputedStyle('txt','height');
//if (scroll<h) 
qq=setInterval('sd()',1);
}


function sd()
{
scroll=scroll+3; p=p+3;
document.getElementById("txt").scrollTop=scroll;
if (p==hh) clearInterval(qq);
}

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');
if (q2!=0 && s.style.display!='block')
  {
  s.innerHTML = "<img src='"+q1+"'>";

document.onmouseover = function(e){
var mCur = mousePageXY(e); 
s.style.left=mCur.x;
s.style.top=mCur.y;};

  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);
window.open('/view.php?pic='+pic,'_blank','top='+i2+', left='+i1+', width='+w+', height='+h);
}


function add_dir (q,q1)
{
st = "<form action='add_dir.php' method='post' name='add_dir'>";
st += "<b>Название</b>";
st += "<input type='hidden' name='dir' value='"+q1+"'>";
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 add_form (q1)
{
st = "<form action='add_form.php' method='post' name='add_dir'>";
st += "<b>Название</b>";
st += "<input type='hidden' name='dir' value='"+q1+"'>";
st += "<input type='hidden' name='f' value=''>";
st += "<br><input type='text' style='width: 500px;' value='' name='head'><br>";
st += "<input type='image' src='../inc/around.jpg' onclick='f.value="+'"around.txt"'+"'>";
st += "<input type='image' src='../inc/cont.jpg' onclick='f.value="+'"cont.txt"'+"'>";
st += "<input type='image' src='../inc/main.jpg' onclick='f.value="+'"main.txt"'+"'>";
st += "<input type='image' src='../inc/our_team.jpg' onclick='f.value="+'"our_team.txt"'+"'>";
st += "<input type='image' src='../inc/quality.jpg' onclick='f.value="+'"quality.txt"'+"'>";
st += "<input type='image' src='../inc/rnd.jpg' onclick='f.value="+'"rnd.txt"'+"'>";
st += "<input type='image' src='../inc/metal.jpg' onclick='f.value="+'"metal.txt"'+"'>";
st += "<input type='image' src='../inc/rf.jpg' onclick='f.value="+'"rf.txt"'+"'>";
st += "<input type='image' src='../inc/tools.jpg' onclick='f.value="+'"tools.txt"'+"'>";
st += "<br><input type='button' class='btn' onclick='fog_out();' value='Закрыть'></form>";
echo_in ('mess_in',st);
fog.style.display='block';
mess.style.top=230;
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;
}

