function PopupWindow(el){
this.el=el;
this.showPopup=PW_showPopup;
this.hide=PW_hidePopup;
this.hidePopupWindows=PW_hidePopupWindows;
this.isClicked=PW_isClicked;
this.closedBy=0;
this.shownBy=null;
this.offsetX=0;
this.offsetY=0;
addListener(document,'mousedown',function(e){this.hidePopupWindows(e)}.bind(this));
}

function addListener(o,e,h) {
if(typeof o.addEventListener!='undefined')o.addEventListener(e,h,false);
else if(typeof o.attachEvent!='undefined')o.attachEvent('on'+e,h);
}
function removeListener(o,e,h) {
if(typeof o.removeEventListener!='undefined')o.removeEventListener(e,h,false);
else if(typeof o.detachEvent!='undefined')o.detachEvent('on'+e,h);
}

Function.prototype.bind=function(o){var m=this; return function(){return m.apply(o,arguments);}}

function AnchorPosition_getPageOffset(e,f){
var o=f=="l"?e.offsetLeft:e.offsetTop;
while((e=e.offsetParent)!=null)
o+=f=="l"?e.offsetLeft:e.offsetTop;
return o;
}

function getAnchorPosition(a){
var c=new Object();
var o=document.getElementById(a);
c.x=AnchorPosition_getPageOffset(o,"l");
c.y=AnchorPosition_getPageOffset(o,"t");
return c;
}

function PW_showPopup(a){
if(this.closedBy==1){this.closedBy=0;return false;}
this.shownBy=a;
var c=getAnchorPosition(a);
this.x=c.x+this.offsetX;
this.y=c.y+this.offsetY;
document.getElementById(this.el).style.left=this.x+"px";
document.getElementById(this.el).style.top=this.y+"px";
document.getElementById(this.el).style.visibility="visible";
return true;
}

function PW_hidePopupWindows(e){
if (!this.isClicked(e))
this.hide();
}

function PW_hidePopup(){
document.getElementById(this.el).style.visibility="hidden";
}

function PW_isClicked(e){
if (document.getElementById(this.el) == null) return;
if(document.all){//IE
var t=window.event.srcElement;
while(t.parentElement!=null){
if(document.getElementById(this.el).style.visibility!="hidden"&&t.id==this.shownBy)this.closedBy=1;
if(t.id==this.el)return true;
t=t.parentElement;}}
else{
var t=e.target;
while(t.parentNode!=null){
if(document.getElementById(this.el).style.visibility!="hidden"&&t.id==this.shownBy)this.closedBy=1;
if(t.id==this.el)
return true;
t=t.parentNode;}}
return false;
}

function getPageOffsetLeft(el) {
var ol = el.offsetLeft;
while ((el = el.offsetParent) != null) {
ol += el.offsetLeft;
}
return ol;
}
function getPageOffsetTop(el) {
var ot = el.offsetTop;
while ((el = el.offsetParent) != null) {
ot += el.offsetTop;
}
return ot;
}
function showLoginForm(link, l, t) {
var e = document.getElementById('login_popup_form');
e.style.left = getPageOffsetLeft(link) + l + "px";
e.style.top = getPageOffsetTop(link) + t + "px";
e.style.display = 'block';
document.getElementById("usernameEdit").focus();
}
function hideLoginForm() {
var e = document.getElementById('login_popup_form');
e.style.display = 'none';
}