/* * *
 *  function openPopupWindow()
 *    Open new window 'popup'
 *  expparams - "scroll=yes|no" - esli parametr ne ukazan, to scroll = no
 *  expparams - "width=~num;height=~num;"     - obyazatel'no d.b. ";" (po nemu opredelyaetsya konec chisla);      esli parametri ne ukazani - to znacheniya budut ravni popupWindowWidth i popupWindowHeight - min parametri okoshka;     esli ukazan parametr previshayushiy razmer ekrana, to razmer okna stanovitsya razmerom s okno i poyavl scroll
 *  Example: <a href="#" onClick="openPopupWindow('/about.html','scroll=no;'); return false;">
 *  Example: <a href="#" onClick="openPopupWindow('/about.html','scroll=no;width=400;height=300;'); return false;">
 *  last updated: 20/01/2003;  / /2002; 11/09/2002;
 *  for navigators: IE 5.0, NC 4.77
 *  bugs: pri ekrane 800*600 scroll nempnogo zahodit za predeli ekrana, okno ne centriruetsya (yavno vidno), i navernoe ne idet v krayniy leviy-verhn ugol esli bolshoe okno
 *  (Subbotin)
 * * */

function openPopupWindow(url,expparams){

  screenWidth = screen.width;
  screenHeight = screen.height;

  scrollvalue = "no"
  if (expparams!=null) {
    if (expparams.indexOf('scroll') != -1){
      scrollpos = expparams.indexOf('scroll')
      scrollvalue = expparams.substring(scrollpos+7,scrollpos+9)
      if (scrollvalue.indexOf('ye') != -1){
        scrollvalue = "yes"
      } else if (scrollvalue.indexOf('no') != -1){
        scrollvalue = "no"
      }
    }
  }

  popupWindowLeft = -1                              //dlya proverki potom
  popupWindowTop = -1
  if (expparams!=null) {
    widthPos = expparams.indexOf('width');
    heightPos = expparams.indexOf('height');
    if (widthPos != -1){
      strAfterWidth = expparams.substring(widthPos+6, expparams.length)     //'scroll=no;width=400;height=300;' -> '400;height=300;'
      popupWindowWidth = strAfterWidth.substring(0, strAfterWidth.indexOf(';')) //'400;height=300;' -> '400'
      popupWindowWidth = parseInt(popupWindowWidth)               //'400' -> 400
      if (popupWindowWidth > screenWidth) {                   //'10000' -> '2048'
        popupWindowWidth = screenWidth
        popupWindowWidth += -25                         //tsifra vzyata naugad, zavisit ot shirini browser_bordera
        scrollvalue = "yes"
        popupWindowLeft = 0;
      }
    } else {
      popupWindowWidth = 608;                           //(need screen size = 608)
    }
    if (heightPos != -1){
      strAfterHeight = expparams.substring(heightPos+7, expparams.length)       //'scroll=no;width=400;height=300;' -> '300;'
      popupWindowHeight = strAfterHeight.substring(0, strAfterHeight.indexOf(';'))  //'300;' -> '300'
      popupWindowHeight = parseInt(popupWindowHeight)                 //'300' -> 300
      if (popupWindowHeight > screenHeight) {                     //'10000' -> '1024'
        popupWindowHeight = screenHeight
        popupWindowHeight += -80                          //tsifra vzyata naugad, zavisit ot visoti WinToolbara i browser_bordera
        scrollvalue = "yes"
        popupWindowTop = 0;
      }
    } else {
      popupWindowHeight = 501;                          //(min screen size = 501)
    }
  } else {
    popupWindowWidth = 608;                           //(need screen size = 608)
    popupWindowHeight = 501;                          //(min screen size = 501)
  }

  if (popupWindowLeft == -1) {
    popupWindowLeft = screenWidth/2 - popupWindowWidth/2                //place window in center by X(!)
  }
  if (popupWindowTop == -1) {
    popupWindowTop = screenHeight/2 - popupWindowHeight/2               //place window in center by Y(!)
  }

  if (scrollvalue == "yes"){
    popupWindowWidth += 16
  }


  var wndName = "popupWindow"
  var wndFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no,width=" + popupWindowWidth + ",height=" + popupWindowHeight + ",top=" + popupWindowTop + ",left=" + popupWindowLeft + ",resizable=no,scrollbars=" + scrollvalue;

  popupWindow = window.open('',wndName,wndFeatures);
  popupWindow.focus();
  popupWindow = window.open(url,wndName,wndFeatures);

  return false;
}



/* * *
 *  function openPopupImage()
 *    - указывается именно размер картинки
 *    - подпись указывается в 4ой позиции
 *    - чтобы окно не закрывалось автоматически, нужно в 5ую позиции указать что-нибудь, кроме '', например 'nonAutoClose'
 *  Example:    <a href="#" onclick="openPopupImage('/img/image.jpg', 300, 200); return false;">
 *  Example:    <a href="#" onclick="openPopupImage('/img/image.jpg', 300, 200, 'Descrition', 'nonAutoClose'); return false;">
 *  Last updated: 21.01.2003.
 *  Navigators:  IE5.5, NC4.77
 *  bugs: хорошо бы центрировать окно; еще попробовать добавить подпись для картинки,  взятую из alt=""
 *  (Nemo)
 * * */
function openPopupImage(img_url, w, h, img_title, nonAutoClose, low_src) {
  JSVer = (navigator.userAgent.indexOf ("Mozilla") != -1 ? parseInt(navigator.appVersion.substring(0,1)) : 0);
  MSIE = (navigator.userAgent.indexOf ("MSIE") != -1);

    if (JSVer < 3) {
        return true;
    }
    var r_w = w, r_h = h, s = '', s_scroll = 'no';
    if (JSVer >= 3) {
        if (JSVer == 3) {
            r_w += 52; r_h += 52;
        }
        r_w += 20; r_h += 20;
        if (img_title)  r_h += 18;
        if (screen) {
            if (screen.availWidth < r_w) {
                s_scroll = 'yes';
                r_w = screen.availWidth;
            }
            if (screen.availHeight < r_h) {
                s_scroll = 'yes';
                r_h = screen.availHeight;
            }
        } else
            s_scroll = 'yes';
        s = 'status=no,resizable=yes,scrollbars=' + s_scroll + ',width=' + r_w + ',height=' + r_h;
        var secWnd = window.open('', 'SecondWnd', s);
        with (secWnd) {
            document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n");
            document.write("<html>\n");
            document.write("<head>\n");
            document.write("<title>image</title>\n");
            document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=WINDOWS-1251\">\n");
            document.write("</head>\n");
            document.write("<body ");
      if ((nonAutoClose == null) || (nonAutoClose == "")){
              document.write("onBlur=\"javascript:close()\" ");
      }
      document.write("bgcolor=\"white\" marginheight=\"0\" marginwidth=\"0\" leftmargin=\"0\" rightmargin=\"0\" topmargin=\"0\" bottommargin=\"0\">\n");
            if (JSVer >= 4 || MSIE) {
                document.write("<div style='left:0px; top:0px; margin:10px 10px 10px 10px; text-align: center;'>");
            }
            document.write("<img src=\""+img_url+"\" width="+ w +" height=" + h + (low_src != null ? (" lowsrc=" + low_src) : '') + " border=0 style='border : 1ps solid #ba6105;'>");
            if ((img_title != null) && (img_title != "")) {
                if (JSVer >= 4)
                    document.write("<div style=\"width: 1px; height: 2px;\"><spacer type=\"block\" width=\"1\" height=\"2\"/></div><span style='font-size:8pt;font-family:Tahoma,Arial Cyr,Arial,Helv;'><center>");
                else
                    document.write("<br><center><font size=1 face=\"Tahoma,Arial Cyr,Arial,Helv\">");
                document.writeln(img_title);
                if (JSVer >= 4)
                    document.write("</center></span>");
                else
                    document.writeln("</font></center>");
            }
            if (JSVer >= 4 || MSIE) {
                document.write("</div>\n");
            }
            document.writeln("</body>\n</html>");
            document.close();
        }
        return false;
    }
    return false;
}
