  //----------
  //to use Popup use this code in any element: onClick="showPopup('popup')"
  //to close popup use this code in any iFrame:  onClick="hidePopup('popup')"
  var bid = '';

  function addEvent(obj ,evt, fnc)
  {
	if (obj.addEventListener)
	  obj.addEventListener(evt,fnc,false);
	else if (obj.attachEvent)
	  obj.attachEvent('on'+evt,fnc);
	else
	  return false;
	return true;
  }

  function removeEvent(obj ,evt, fnc)
  {
	if (obj.removeEventListener)
	  obj.removeEventListener(evt,fnc,false);
	else if (obj.detachEvent)
	  obj.detachEvent('on'+evt,fnc);
	else
	  return false;
	return true;
  }

  //----------

  function appendElement(node,tag,id,htm)
  {
	var ne = document.createElement(tag);
	if(id) ne.id = id;
	if(htm) ne.innerHTML = htm;
	node.appendChild(ne);
  }

  //----------

  function showPopup(p,params,vwidth,vheight, ifheight)
  {

	var screenW = screen.width;
	var screenH = window.screen.height;


	var popup = document.getElementById(p);
	sWidth = vwidth+'px';
	sHeight = vheight+'px';	
	popup.style.width = sWidth;
	popup.style.height = sHeight;

	var leftcalc;
	var topcalc;

	leftcalc = (screenW/2)-(vwidth/2);
	topcalc = (screenH/2)-(vheight/2);
	topcalc = 210;

	popup.style.margin = ''+topcalc+'px 0px 0px '+leftcalc+'px';

	greyout(true);
	popup.style.display = 'block';
	
	if(p=="popup"){
		var frame = document.getElementById('PopupFrame');
		frame.src = params;
		frame.height = ifheight;
	} else if(p=="popupBuy"){
		bid = params;
		showBook(bid);//function in book.js
	} else {
		alert("Error: calling undefined popup");
	}
  }

  function hidePopup(p)
  {
	greyout(false);
	top.document.getElementById(p).style.display = 'none';
  }

  //----------

  function greyout(d,z)
  {
	var obj = top.document.getElementById('greyout');

	if(!obj)
	{
	  appendElement(top.document.body,'div','greyout');
	  obj = top.document.getElementById('greyout');
	  obj.style.position = 'absolute';
	  obj.style.top = '0px';
	  obj.style.left = '0px';
	  obj.style.background = '#111';
	  obj.style.opacity = '.5';
	  obj.style.filter = 'alpha(opacity=50)';
	}
	if(d)
	{
	  var ch = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	  var cw = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	  var sh = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
	  if(document.body.scrollHeight) sh = Math.max(sh,document.body.scrollHeight)
	  var sw = document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
	  if(document.body.scrollWidth) sh = Math.max(sh,document.body.scrollWidth)
	  var wh = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
	  if (navigator.appName == 'Microsoft Internet Explorer'){
		cw=cw-21;
		sw=sw-21;
	  }
	  if(!z){ z = 50 }
	  obj.style.zIndex = z;
	  obj.style.height = '940px';
	 //  obj.style.height = Math.max(wh,Math.max(sh,ch))+'px';
	  obj.style.width  = Math.max(sw,cw)+'px';
	  obj.style.display = 'block';
	  addEvent(window,'resize',greyoutResize);
	}
	else
	{
	  obj.style.display = 'none';  
	  removeEvent(window,'resize',greyoutResize);
	}
  }

  function greyoutResize()
  {
	var ch = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var cw = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	var sh = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
	if(document.body.scrollHeight) sh = Math.max(sh,document.body.scrollHeight)
	var sw = document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
	if(document.body.scrollWidth) sh = Math.max(sh,document.body.scrollWidth)
	var wh = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
	var obj = document.getElementById('greyout');
	obj.style.height = ch+'px';
	obj.style.width  = cw+'px';
	obj.style.height = Math.max(wh,Math.max(sh,ch))+'px';
	obj.style.width  = Math.max(sw,cw)+'px';
  }

  //----------

