function user_stat(stat)
{
  var id = new Array('pas2','nam','eml');
  if(stat != 'new')
    for(i=0; i<id.length; i++)
	  document.getElementById(id[i]).style.display = 'none';
  else
    for(i=0; i<id.length; i++)
	  document.getElementById(id[i]).style.display = 'block';

}
var c = 0;
function addPhoto()
{
  var table = document.getElementById('tbl');
  if(c == 9)
  {
	alert('Добавление не возможно');
  }
  else
  {
    c += 1;
	var input = document.createElement('input');
    var input2 = document.createElement('input');
    var txt = document.createTextNode('Путь к фото');
    var txt2 = document.createTextNode('Название фото');
    var br = document.createElement('br');
    var br2 = document.createElement('br');
    input.setAttribute('type','file');
    input.setAttribute('name','foto'+c);
    input2.setAttribute('type','text');
    input2.setAttribute('name','foto_title'+c);
    input2.setAttribute('size','40');
    table.insertRow(table.rows.length);
    table.rows[table.rows.length - 1].insertCell(0);
    table.rows[table.rows.length - 1].cells[0].className = 'photo_txt';
    table.rows[table.rows.length - 1].insertCell(0);
    table.rows[table.rows.length - 1].cells[0].className = 'photo_txt';
    table.rows[table.rows.length - 1].cells[0].appendChild(txt);
    table.rows[table.rows.length - 1].cells[0].appendChild(br);
    table.rows[table.rows.length - 1].cells[0].appendChild(input);
    table.rows[table.rows.length - 1].cells[1].appendChild(txt2);
    table.rows[table.rows.length - 1].cells[1].appendChild(br2);
    table.rows[table.rows.length - 1].cells[1].appendChild(input2);
  }
}
function delPhoto()
{
  var table = document.getElementById('tbl');
  if(c == 0)
  {
	alert('Удаление не возможно');
  }
  else
  {
    table.deleteRow(table.rows.length - 1);
	c -= 1;
  }
}

function create_select()
{
  this.model = function(values,titles)
  {
    var model = document.getElementById('model');
    var opt_length = model.options.length;
    for(var c=0; c<=opt_length; c++)
      if(model.hasChildNodes())
	    model.removeChild(model.lastChild);
    for(var i in values)
    {
	  var opt = document.createElement('option');
	  var txt = document.createTextNode(titles[i]);
	  opt.appendChild(txt);
	  opt.setAttribute('value',values[i]);
	  model.appendChild(opt);
    }
  }
}

var sel_class = new create_select();

function doLoad(id,part,value)
{
  var req = new JsHttpRequest();
  req.onreadystatechange = function()
  {
    if (req.readyState == 4)
	{
	  if(val)
	    if(typeof val == "Array")
		{
		  var val = [];
		  val.length = 0;
		}

	  if(names)
	    if(typeof names == "Array")
		{
		  var names = [];
		  names.length = 0;
		}

	  eval(req.responseText);
	  sel_class[part](val,names);
	}
  }
  req.open(null, 'ajax.php?id='+id, true);
  req.send( { page: value } );
}
