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 checkSubscribe(){
    form = document.subscribe;

    if (form.mail.value.trim() == "") {
      alert('Пожалуйста, введите Ваш E-Mail');
      form.mail.focus();
      return false;
    }
  
    if (form.password.value.trim() == "") {
      alert('Пожалуйста, введите пароль');
      form.password.focus();
      return false;
    }
  
    if (form.confirm_password.value.trim() != "" && form.confirm_password.value != form.password.value) {
      alert('Пароли не совпадают');
      form.confirm_password.focus();
      return false;
    }

    return true;
    
  }

  function getGoodOrder ()
  {
    var str = document.location.hash;
    found = str.match(/\#GO=(\d{1,3})/i);
    if (found) return found[1]?found[1]:1;
    else return 1;
  }

  var MS  = (navigator.appName.indexOf("Microsoft")!=-1);
  var VER = parseInt(navigator.appVersion);
  var IE4 = (MS&&VER==4);
  function Show(id) {
    if ( IE4 ) {
      MsgBlock = eval("msg" + id);
    } else {
      MsgBlock = document.getElementById("msg" + id);
    }
    if ( MsgBlock ) {
      if ( MsgBlock.style.display != "") {
        MsgBlock.style.display = "";
      }
      else {
        MsgBlock.style.display = "none";
      }
    }
  }

  function PostMsg(ItemID,MessID) {
    url = '/compcomment.html?ItemID='+ItemID+'&MessID='+MessID;
    PostPopup = window.open(url,'','width=550,height=450,scrollbars=0,status=0,resizeable=0');
    PostPopup.focus();
  }

  function PostMsg2(ItemID,MessID) {
    url = '/discomment.html?ItemID='+ItemID+'&MessID='+MessID;
    PostPopup = window.open(url,'','width=550,height=450,scrollbars=0,status=0,resizeable=0');
    PostPopup.focus();
  }

  function FriendMsg(ItemID) {
    url = '/comptofriend.html?ItemID='+ItemID;
    PostPopup2 = window.open(url,'','width=550,height=550,scrollbars=0,status=0,resizeable=0');
    if(PostPopup2)
      PostPopup2.focus();
  }

  function FriendMsg2(ItemID) {
    url = '/distofriend.html?ItemID='+ItemID;
    PostPopup2 = window.open(url,'','width=550,height=550,scrollbars=0,status=0,resizeable=0');
    if(PostPopup2)
      PostPopup2.focus();
  }


  function BannerLoaded(){

    t = document.getElementById("banner_top");
    if (null != t){
      timg = document.getElementById("btopimg");
      if (null != timg)
        timg.src="/getbanner.php?t=top&i="+t.innerHTML;
      else{
        var so = new SWFObject("/getbanner.php?t=top&i="+t.innerHTML, "mymovie", "760", "90", "9", "#336699");
        so.write("flashbannertop");
      }
    }

    l = document.getElementById("banner_left");
    if (null != l){
      limg = document.getElementById("bleftimg");
      if (null != limg)
        limg.src="/getbanner.php?t=left&i="+l.innerHTML;
      else{
        var so = new SWFObject("/getbanner.php?t=left&i="+l.innerHTML, "mymovie", "180", "180", "9", "#336699");
        so.write("flashbannerleft");
      }
    }

    r = document.getElementById("banner_right");
    if (null != r){
      rimg = document.getElementById("brightimg");
      if (null != rimg)
        rimg.src="/getbanner.php?t=right&i="+r.innerHTML;
      else{
        var so = new SWFObject("/getbanner.php?t=right&i="+r.innerHTML, "mymovie", "240", "400", "9", "#336699");
        so.write("flashbannerright");
      }
    }

    setTimeout("IncBannerShow()", 3000);
  }

  function IncBannerShow(){
    uri = "";
    t = document.getElementById("banner_top");
    if (null != t)
      uri = uri+"&top="+t.innerHTML;
    l = document.getElementById("banner_left");
    if (null != l)
      uri = uri+"&left="+l.innerHTML;
    r = document.getElementById("banner_right");
    if (null != r)
      uri = uri+"&right="+r.innerHTML;

    href = "/banner.php?a=inc"+uri;

    frame = document.getElementById("BannerLoader");
    frame.src = href;
  }


