/* 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 (onoff == "on")
  {
    style2.display = "block";
  }
  else
  {
    style2.display = "none";
  }
}

// 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,"");
}

/* work with cookies */
function readCookie(cookieName)
{
  var theCookie = "" + document.cookie;
  var ind = theCookie.indexOf(cookieName);
  if (ind == -1 || cookieName == "")
    return "";
  var ind1 = theCookie.indexOf(';', ind);
  if (ind1 == -1)
    ind1 = theCookie.length;
  return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}
function setCookie(cookieName,cookieValue,nDays)
{
  var today = new Date();
  var expire = new Date();
  if (nDays == null || nDays == 0)
    nDays = 1;
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

