/** Copyright Mihai Bazon, 2003
 * Sponsored by SamWare.net [ http://samware.net ]
 *
 * This code was developed by Mihai Bazon for SamWare
 * [ http://students.infoiasi.ro/~mishoo ]
 *
 * You may use it under the GNU LGPL.
 * ( http://www.gnu.org/licenses/lgpl.html )
 *
 * You are not allowed to remove or alter this notice.
 **/
 var is_ie=((navigator.userAgent.toLowerCase().indexOf("msie")!=-1)&&(navigator.userAgent.toLowerCase().indexOf("opera")==-1));var is_compat=(document.compatMode=="BackCompat");function PopupDiv(titleText,content_id,handler){var self=this;this.handler=handler;var el=document.getElementById(content_id);var popup=document.createElement("div");popup.className="popupdiv";this.element=popup;popup.style.position="absolute";popup.style.left="0px";popup.style.top="0px";var title=document.createElement("div");title.className="title";this.title=title;popup.appendChild(title);PopupDiv.addEvent(title,"mousedown",function(ev){self._dragStart(is_ie?window.event:ev);});var button=document.createElement("div");button.className="button";title.appendChild(button);button.innerHTML="&#x00d7;";title.appendChild(document.createTextNode(titleText));this.titleText=titleText;button.onmouseover=function(){this.className+=" button-hilite";};button.onmouseout=function(){this.className=this.className.replace(/\s*button-hilite\s*/g," ");};button.onclick=function(){self.close();};button.title="Close";el.style.position="absolute";var clone=el.cloneNode(true);clone.className+=" content";clone.style.display="block";popup.appendChild(clone);this.clone=clone;document.body.appendChild(popup);var cs=popup.currentStyle;var addX=(is_ie&&is_compat)?(parseInt(cs.borderLeftWidth)+parseInt(cs.borderRightWidth)+parseInt(cs.paddingLeft)+parseInt(cs.paddingRight)):0;var addY=(is_ie&&is_compat)?(parseInt(cs.borderTopWidth)+parseInt(cs.borderBottomWidth)+parseInt(cs.paddingTop)+parseInt(cs.paddingBottom)):0;popup.style.width=(clone.offsetWidth+addX)+"px";popup.style.height=(clone.offsetHeight+title.offsetHeight)+"px";popup.style.display="none";this.dragging=false;this.onShow=null;this.onClose=null;this.modal=false;};PopupDiv.currentPopup=null;PopupDiv.prototype.showAtElement=function(el,mode){var pos,ew,eh;var popup=this.element;popup.style.display="block";var w=popup.offsetWidth;var h=popup.offsetHeight;if(el!=window){pos=PopupDiv.getAbsolutePos(el);ew=el.offsetWidth;eh=el.offsetHeight;}else{pos={x:0,y:0};var size=PopupDiv.getWindowSize();ew=size.x;eh=size.y;}if(mode.indexOf("l")!=-1){pos.x-=w;}if(mode.indexOf("r")!=-1){pos.x+=ew;}if(mode.indexOf("t")!=-1){pos.y-=h;}if(mode.indexOf("b")!=-1){pos.y+=eh;}if(mode.indexOf("c")!=-1){if(is_ie){pos.y+=document.body.scrollTop;pos.x+=document.body.scrollLeft;}else{pos.y+=window.scrollY;pos.x+=window.scrollX;}pos.x+=Math.round((ew-w)/2);pos.y+=Math.round((eh-h)/2);}this.showAt(pos.x,pos.y);};PopupDiv.prototype.showAt=function(x,y){var s=this.element.style;s.left=x+"px";s.top=y+"px";s.display="block";this.hideShowCovered();PopupDiv.currentPopup=this;PopupDiv.addEvent(document.body,["mousedown","click"],PopupDiv.checkPopup);if(is_ie&&this.modal){document.body.setCapture(false);document.body.onlosecapture=function(){(PopupDiv.currentPopup)&&(document.body.setCapture(false));};}window.event&&PopupDiv.stopEvent(window.event);if(typeof this.onShow=="function"){this.onShow();}else if(typeof this.onShow=="string"){eval(this.onShow);}};PopupDiv.prototype.close=function(){this.element.style.display="none";PopupDiv.currentPopup=null;this.hideShowCovered();PopupDiv.removeEvent(document.body,["mousedown","click"],PopupDiv.checkPopup);is_ie&&this.modal&&document.body.releaseCapture();if(typeof this.onClose=="function"){this.onClose();}else if(typeof this.onClose=="string"){eval(this.onClose);}};PopupDiv.prototype.getForm=function(){var forms=this.clone.getElementsByTagName("form");return(forms.length>0)?forms[0]:null;};PopupDiv.prototype.callHandler=function(){var tags=["input","textarea","select"];var params=new Object();for(var ti in tags){var tag=tags[ti];var els=this.clone.getElementsByTagName(tag);for(var j=0;j<els.length;++j){var el=els[j];params[el.name]=el.value;}}this.handler(this,params);return false;};PopupDiv.getAbsolutePos=function(el){var r={x:el.offsetLeft,y:el.offsetTop};if(el.offsetParent){var tmp=PopupDiv.getAbsolutePos(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y;}return r;};PopupDiv.stopEvent=function(ev){if(is_ie){window.event.cancelBubble=true;window.event.returnValue=false;}else{ev.preventDefault();ev.stopPropagation();}};PopupDiv.addEvent=function(el,evname,func){if(typeof evname!="string"){for(var i in evname){PopupDiv.addEvent(el,evname[i],func);}}else if(is_ie){el.attachEvent("on"+evname,func);}else{el.addEventListener(evname,func,true);}};PopupDiv.removeEvent=function(el,evname,func){if(typeof evname!="string"){for(var i in evname){PopupDiv.removeEvent(el,evname[i],func);}}else if(is_ie){el.detachEvent("on"+evname,func);}else{el.removeEventListener(evname,func,true);}};PopupDiv.getWindowSize=function(){if(window.innerHeight){return{y:window.innerHeight,x:window.innerWidth};}if(window.document.body.clientHeight){return{y:document.body.clientHeight,x:document.body.clientWidth};}return{y:window.document.documentElement.clientHeight,x:window.document.documentElement.clientWidth};};PopupDiv.prototype.hideShowCovered=function(){var self=this;function isContained(el){while(el){if(el==self.element){return true;}el=el.parentNode;}return false;};var tags=new Array("applet","iframe","select");var el=this.element;var p=PopupDiv.getAbsolutePos(el);var EX1=p.x;var EX2=el.offsetWidth+EX1;var EY1=p.y;var EY2=el.offsetHeight+EY1;if(el.style.display=="none"){EX1=EX2=EY1=EY2=0;}for(var k=tags.length;k>0;){var ar=document.getElementsByTagName(tags[--k]);var cc=null;for(var i=ar.length;i>0;){cc=ar[--i];if(isContained(cc)){cc.style.visibility="visible";continue;}p=PopupDiv.getAbsolutePos(cc);var CX1=p.x;var CX2=cc.offsetWidth+CX1;var CY1=p.y;var CY2=cc.offsetHeight+CY1;if((CX1>EX2)||(CX2<EX1)||(CY1>EY2)||(CY2<EY1)){cc.style.visibility="visible";}else{cc.style.visibility="hidden";}}}};PopupDiv.prototype._dragStart=function(ev){if(this.dragging){return false;}this.dragging=true;PopupDiv.currentPopup=this;var posX=ev.clientX;var posY=ev.clientY;if(is_ie){posY+=document.body.scrollTop;posX+=document.body.scrollLeft;}else{posY+=window.scrollY;posX+=window.scrollX;}var st=this.element.style;this.xOffs=posX-parseInt(st.left);this.yOffs=posY-parseInt(st.top);PopupDiv.addEvent(document,"mousemove",PopupDiv.dragIt);PopupDiv.addEvent(document,"mouseover",PopupDiv.stopEvent);PopupDiv.addEvent(document,"mouseup",PopupDiv.dragEnd);PopupDiv.stopEvent(ev);};PopupDiv.dragIt=function(ev){var popup=PopupDiv.currentPopup;if(!(popup&&popup.dragging)){return false;}is_ie&&(ev=window.event);var posX=ev.clientX;var posY=ev.clientY;if(is_ie){posY+=document.body.scrollTop;posX+=document.body.scrollLeft;}else{posY+=window.scrollY;posX+=window.scrollX;}popup.hideShowCovered();var st=popup.element.style;st.left=(posX-popup.xOffs)+"px";st.top=(posY-popup.yOffs)+"px";PopupDiv.stopEvent(ev);};PopupDiv.dragEnd=function(){var popup=PopupDiv.currentPopup;if(!popup){return false;}popup.dragging=false;PopupDiv.removeEvent(document,"mouseup",PopupDiv.dragEnd);PopupDiv.removeEvent(document,"mouseover",PopupDiv.stopEvent);PopupDiv.removeEvent(document,"mousemove",PopupDiv.dragIt);popup.hideShowCovered();};PopupDiv.checkPopup=function(ev){is_ie&&(ev=window.event);var el=is_ie?ev.srcElement:ev.target;var cp=PopupDiv.currentPopup;for(;(el!=null)&&(el!=cp.element);el=el.parentNode);if(el==null){cp.modal||ev.type=="mouseover"||cp.close();PopupDiv.stopEvent(ev);}};PopupDiv.factory=new Object();PopupDiv.create=function(titleText,content_id,handler){var ID=content_id+"/"+titleText;var popup=null;if(typeof PopupDiv.factory[ID]!="undefined"){popup=PopupDiv.factory[ID];popup.handler=handler;var tags=popup.element.getElementsByTagName("div");for(var i=0;i<tags.length;++i){var el=tags[i];el.className=el.className.replace(/\s*[a-zA-Z0-9]+-hilite\s*/g,"");}}else{popup=new PopupDiv(titleText,content_id,handler);PopupDiv.factory[ID]=popup;}return popup;};