/* hide and show layer */
function toggleLayer(whichLayer, onoff)
{
  var style2;
  if (document.getElementById) // this is the way the standards work
    style2 = document.getElementById(whichLayer).style;
  else
  {
    if (document.all) // this is the way old msie versions work
      style2 = document.all[whichLayer].style;
    else
      if (document.layers) // this is the way nn4 works
        style2 = document.layers[whichLayer].style;
  }
  if ('on' == onoff)
    style2.display = 'block';
  else
    style2.display = 'none';
}

/* counts length of <textarea> field*/
function text_counter(field, countfield, maxlimit)
{
  if (field.value.length > maxlimit)
  {
    field.value = field.value.substring(0, maxlimit);
    alert('Это поле не может содержать более ' + maxlimit + ' символов.');
    return false;
  }
  else
    countfield.value = maxlimit - field.value.length;
}

// checks email address
function is_correct_email(item)
{
  if (!item || ('' == item))
    return false;
  var at="@"
  var dot="."
  var lat=item.indexOf(at)
  var litem=item.length
  var ldot=item.indexOf(dot)
  if (item.indexOf(at)==-1) return false;
  if (item.indexOf(at)==-1 || item.indexOf(at)==0 || item.indexOf(at)==litem) return false;
  if (item.indexOf(dot)==-1 || item.indexOf(dot)==0 || item.indexOf(dot) >= litem - 2) return false;
  if (item.indexOf(at,(lat+1))!=-1) return false;
  if (item.substring(lat-1,lat)==dot || item.substring(lat+1,lat+2)==dot) return false;
  if (item.indexOf(dot,(lat+2))==-1) return false;
  return item.indexOf(" ") == -1;
}

// delete all spaces at the beginning and at the end of the string
function trim(stringToTrim)
{
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}

