var popupMouseOn = false;
var currentPopup = 0;

function popupOn(bln, id) {
  if (bln) {
    popupMouseOn = bln;

    if (id) {
      document.getElementById('popup_'+id).style.display = 'none';
    }
  }
}

function showBlPopup(id) {

  if (document.getElementById('popup_'+currentPopup)) {
    document.getElementById('popup_'+currentPopup).style.display = 'none';
    currentPopup = 0;
    popupMouseOn = false;
  }

  if (id) {
    var popup = document.getElementById('popup_'+id);

    if (!popupMouseOn) {
      currentPopup = id;
      popup.style.display = 'block';
    }
  }
}

function hideBlPopup(id, delay) {
  if (id) {
    var popup = document.getElementById('popup_'+id);

    if (!popupMouseOn) {

      if (id && delay) {
        if (popup.style.display != 'none') {
          setTimeout("hideBlPopup('"+id+"')", 500);
        }
      } else {
        popup.style.display = 'none';
        popupOn(false);
      }
    }
  }
}

function popup(href, title, width, height, scrollbars) {
  var myWidth = 0;
  var myHeight = 0;

  if(typeof(window.innerWidth) == 'number') {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  var left = (myWidth / 2) - (width / 2);
  var top = (myHeight / 2) - (height / 2);

  if (!title) {
    title = 'popup';
  }

	var popupWindow = window.open(href, title, 'location=no,status=no,scrollbars='+ scrollbars +',toolbar=no,directories=no,resizable=no,width='+width+',height='+height+',left='+left+',top='+top);
	popupWindow.focus();
}
