var scrW = (screen.width) ? (screen.width) : 0;
var scrH = (screen.height) ? (screen.height) : 0;


//  Multi-browser function for listen onLoad event.
//  Sourse from http://xpoint.ru/know-how/JavaScript/PoleznyieFunktsii?29#UstanovkaObrabotchikaSobyitiya
//
function setGlobalOnLoad(f) {
   var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ?
 document : null
   if (root){
      if(root.addEventListener) root.addEventListener("load", f, false)
      else if(root.attachEvent) root.attachEvent("onload", f)
   } else {
      if(typeof window.onload == 'function') {
         var existing = window.onload
         window.onload = function() {
            existing()
            f()
         }
      } else {
         window.onload = f
      }
   }
}

//  Назначение нескольких обработчиков для одного события
//  Sourse from http://xpoint.ru/know-how/JavaScript/PoleznyieFunktsii?29#NaznachenieNeskol'kihObrabotch
//
function addHandler(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
  {
    var handlersProp = '_handlerStack_' + event;
    var eventProp = 'on' + event;
    if (typeof object[handlersProp] == 'undefined')
    {
      object[handlersProp] = [];
      if (typeof object[eventProp] != 'undefined')
        object[handlersProp].push(object[eventProp]);
      object[eventProp] = function(e)
      {
        var ret = true;
        for (var i = 0; ret != false && i < object[handlersProp].length; i++)
          ret = object[handlersProp][i](e);
        return ret;
      }
    }
    object[handlersProp].push(handler);
  }
}

function removeHandler(object, event, handler)
{
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
  {
    var handlersProp = '_handlerStack_' + event;
    if (typeof object[handlersProp] != 'undefined')
    {
      for (var i = 0; i < object[handlersProp].length; i++)
      {
        if (object[handlersProp][i] == handler)
        {
          object[handlersProp].splice(i, 1);
          return;
        }
      }
    }
  }
}

function w_open(u)
{
  var top=10
  var left=10
  window.open(u,'popup','scrollbars=yes,resizable=yes,width=600,height=550,top='+top+',left='+left)
}

function popup(htmfile,windowname,h,w) {
	var xcoor = (screen.width) ? (screen.width-w)/2 : 0;
	var ycoor = (screen.height) ? (screen.height-h)/2 : 0;
	var properties = "toolbar=0,directories=0,menubar=0,status=1,resizable=1,location=0,scrollbars=1,copyhistory=0,height=" + h + ",width=" + w + ",top=" + ycoor +",left=" + xcoor;
	window.open(htmfile,windowname,properties);
}

function bigWin(url,wname,w,h) {
	var top=5
	var height=5
	w=(w>scrW ? scrW-50 : w)
	h=(h>scrH ? scrH-50 : h)
	var popupWin=window.open(url,wname,'location,scrollbars=yes,width='+w+',height='+h+',top='+top+',left='+top+',height='+h+',width='+w)
	popupWin.focus()
}
