if ('undefined' == typeof String.prototype.ltrim) {
  String.prototype.ltrim = function() {
    return this.replace(/^\s+/, '');
  }
}

if ('undefined' == typeof String.prototype.rtrim) {
  String.prototype.rtrim = function() {
    return this.replace(/\s+$/, '');
  }
}

if ('undefined' == typeof String.prototype.trim) {
  String.prototype.trim = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
  }
}

function OpenPhoto(img, w, h, title){
  if (w && h) {
    if (w > screen.availWidth || h > screen.availHeight) {
      if (w / screen.availWidth > h / screen.availHeight) {
        h *= screen.availWidth / w;
        w = screen.availWidth;
      }
      else {
        w *= screen.availHeight / h;
        h = screen.availHeight;
      }
    }
    if (!title) title = 'Просмотр фотографии';
    var win = window.open("", "_blank", "width="+w+", height="+h);
    win.document.write("<html><head>\n");
    win.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">\n");
    win.document.write("<title>"+title+"</title></head>\n");
    win.document.write("<body style=\"padding: 0; margin: 0; cursor: hand;\">\n");
    win.document.write("<img src=\""+img+"\" width=\""+w+"\" height=\""+h+"\" alt=\""+title+"\" title=\""+title+"\" onclick=\"window.close()\">\n");
    win.document.write("</body></html>");
    win.focus();
  }
}

function CheckBasketForm(){
  form = document.forma;

  if (form.surname.value.trim() == "") {
      alert('Пожалуйста, введите Вашу фамилию');
      form.surname.focus();
      return false;
  }
  
  if (form.name.value.trim() == "") {
      alert('Пожалуйста, введите Ваше имя');
      form.name.focus();
      return false;
  }
  
  if (form.sname.value.trim() == "") {
      alert('Пожалуйста, введите Ваше отчество');
      form.sname.focus();
      return false;
  }
  
  if (form.index.value.trim() == "") {
      alert('Пожалуйста, заполните поле почтовый индекс');
      form.index.focus();
      return false;
  }

  if (form.city.value.trim() == "") {
      alert('Пожалуйста, заполните поле город');
      form.city.focus();
      return false;
  }
  
  if (form.addr.value.trim() == "") {
      alert('Пожалуйста, заполните поле улица');
      form.addr.focus();
      return false;
  }
  
  if (form.home.value.trim() == "") {
      alert('Пожалуйста, заполните поле дом');
      form.home.focus();
      return false;
  }
  
  if (form.flat.value.trim() == "") {
      alert('Пожалуйста, заполните поле квартира');
      form.flat.focus();
      return false;
  }
  
  if (form.tel.value.trim() == "") {
      alert('Пожалуйста, заполните поле телефон');
      form.tel.focus();
      return false;
  }
  
  return true;
}
