function fserialize(frm)
{
  var str = '';
  for( var i=0; i<frm.elements.length; i++)
  {
    if (!frm.elements[i].name) continue;
    switch(frm.elements[i].type)
    {
      case 'text':
      case 'password':
      case 'textarea':
      case 'hidden':
        if (frm.elements[i].value != '')
        {
          str += '&'+frm.elements[i].name+'='+encodeURIComponent(frm.elements[i].value);
        }
    	break;
      case 'select-one':
        if (frm.elements[i].selectedIndex != 0)
        {
          str += '&'+frm.elements[i].name+'='+encodeURIComponent(frm.elements[i].options[selectedIndex].value);
        }
    	break;
      case 'checkbox':
      case 'radio':
        if (frm.elements[i].checked)
        {
          str += '&' + frm.elements[i].name+'='+encodeURIComponent(frm.elements[i].value);
        }
    	break;
    }
  }
  return str;
}
function checkForm(frm, arr)
{
  if (!frm || !frm.elements)
  {
    alert('Форма не определена');
    return false;
  }
  el = null;
  err = '';
  for(i in arr)
  {
    if (frm.elements[i])
    switch(frm.elements[i].type)
    {
      case 'text':
      case 'textarea':
      case 'password':
      case 'hidden':
        if (frm.elements[i].value == '' || frm.elements[i].value == '0')
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
        else if ((i == 'email') && (!/^[^@]+@[^@]+$/.test(frm.elements[i].value)))
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + ' | Формат: email@somethere.org' + "\n";
        }       
    	break;
      case 'select-one':
        if (frm.elements[i].selectedIndex == 0)
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
    	break;
    }
  }
  if (err == '') return true;
  else
  {
    try { el.focus(); } catch(e) {}
    alert("Пожалуйста заполните обязательные поля:\n-----------------------------------\n" + err + "-----------------------------------");
    return false;
  }
}
function listenClicks(evt) 
{
  evt = (evt) ? evt : ((event) ? event : null);
  if (evt)
  {
    el = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if (el && /^a/.test(el.tagName))
    {
      el.blur();
    }
  }
}
document.onclick=listenClicks;
var check_height = new Object();
var menu_height = new Object();
var cur_height = new Object();
var last_id2 = 0;
function show_sub2(id)
{
  el2 = document.getElementById('sp' + id);
  el3 = document.getElementById('sub' + id);
  el4 = document.getElementById('m' + id);
  if (el3)
  {
    if (!check_height[id])
    {
      check_height[id] = 0;
      if (el3.style.height == '0px')
      {
        menu_height[id] = cur_height[id] = 0;
      }
      else
      {
        menu_height[id] = cur_height[id] = el2.offsetTop + 2;
      }
    }
    if (menu_height[id] > 0)
    {
      menu_height[id] = 0;
    }
    else 
    {
      menu_height[id] = el2.offsetTop + 2;
    }
    if (last_id2 && last_id2 != id)
    {
      el2_ = document.getElementById('sp' + last_id2);
      el3_ = document.getElementById('sub' + last_id2);
      el4_ = document.getElementById('m' + last_id2);
      if (el3_ && last_id2 && !check_height[last_id2])
      {
        check_height[last_id2] = 0;
        if (el3_.style.height == '0px')
        {
          menu_height[last_id2] = cur_height[last_id2] = 0;
        }
        else
        {
          menu_height[last_id2] = cur_height[last_id2] = el2_.offsetTop + 2;
        }
      }
      if (el4_.className == 'over') el4_.className = '';
      if (el4_.className == 'actover') el4_.className = 'act';
      if (el4_.className == 'wchildactover') el4_.className = 'wchildact';
      if (el4_.className == 'wchildover') el4_.className = 'wchild';
      if (el3_)
      {
        menu_height[last_id2] = 0;
        move_sub2(last_id2);
      }
    }
    if (el4.className == '') el4.className = 'over';
    if (el4.className == 'act') el4.className = 'actover';
    if (el4.className == 'wchildact') el4.className = 'wchildactover';
    if (el4.className == 'wchild') el4.className = 'wchildover';
    last_id2 = id;
    move_sub2(id);
    return false;
  }
  return true;
}
function move_sub2(id)
{
  el2 = document.getElementById('sp' + id);
  el3 = document.getElementById('sub' + id);
  var sp = Math.round(Math.abs(cur_height[id] - menu_height[id])*0.2);
  if (sp < 5) sp = 5;
  if (cur_height[id] < menu_height[id])
  {
  	cur_height[id] += sp;
    if (cur_height[id] > menu_height[id]) cur_height[id] = menu_height[id];
  }
  else if (cur_height[id] > menu_height[id])
  {
  	cur_height[id] -= sp;
    if (cur_height[id] < menu_height[id]) cur_height[id] = menu_height[id];
  }
  el3.style.height = cur_height[id] + 'px';
  //el3.style.display = (cur_height[id]) ? '' : 'none';
  if (cur_height[id] != menu_height[id])
  {
    setTimeout("move_sub2('" + id + "')", 50);
  }  
}