var currentBalloonClass;
var balloonIsVisible
var balloonIsSticky;
var balloonInvisibleSelects;
var balloonOK=true;
window.onload=function(){balloonOK=true;}
var Balloon=function(){
this.minWidth=150;
this.maxWidth=600;
this.balloonTextSize='90%';
this.delayTime=500;
this.vOffset=10;
this.padding=10;
this.shadow=20;
this.balloonImage='/images/balloons/balloon.png';
this.ieImage='/images/balloons/balloon_ie.png';
this.stem=true;
this.stemHeight=32;
this.stemOverlap=3;
this.upLeftStem='/images/balloons/up_left.png';
this.downLeftStem='/images/balloons/down_left.png';
this.upRightStem='/images/balloons/up_right.png';
this.downRightStem='/images/balloons/down_right.png';
this.closeButton='/images/balloons/close.png';
}
Balloon.prototype.showTooltip=function(evt,caption,sticky,width){
if(this.isIE()&&!balloonOK)return false;
var mouseOver=evt.type.match('mouseover','i');
if(balloonIsVisible&&!balloonIsSticky&&mouseOver)return false;
if(balloonIsVisible&&balloonIsSticky&&!sticky)return false;
var el=this.getEventTarget(evt);
if(sticky&&mouseOver&&this.isSameElement(el,this.currentElement))return false;
this.firingElement=el;
if(sticky)this.hideTooltip(1);
var closeBalloon=function(){
var override=balloonIsSticky&&!balloonIsVisible;
Balloon.prototype.hideTooltip(override)
}
el.onmouseout=closeBalloon;;
balloonIsSticky=sticky;
this.width=width;
this.setActiveCoordinates(evt);
this.hideTooltip();
if(this.isOldIE()&&this.ieImage){
this.balloonImage=this.ieImage;
this.ieImage=null;
}
if(caption.match(/^url:/)){
var urlArray=caption.split(':');
caption='';
this.activeUrl=urlArray[1];
}
else if(caption.match(/^load:/)){
var load=caption.split(':');
if(!document.getElementById(load[1]))alert('problem locating element '+load[1]);
caption=document.getElementById(load[1]).innerHTML;
this.loadedFromElement=true;
}
else if(caption.match(/^(https?:|\/|ftp:)\S+$/i)){
this.activeUrl=caption;
caption='';
}
this.currentHelpText=this.getContents(caption);
this.loadedFromElement=false;
if(!this.container){
this.container=document.createElement('div');
document.body.appendChild(this.container);
this.setStyle(this.container,'position','absolute');
this.setStyle(this.container,'top',-8888);
this.setStyle(this.container,'display','inline');
}
else{
this.setStyle(this.container,'display','inline');
}
this.container.innerHTML=this.currentHelpText;
if(!this.images){
this.images=document.createElement('div');
document.body.appendChild(this.images);
this.setStyle(this.images,'position','absolute');
this.setStyle(this.images,'top',-8888);
this.setStyle(this.images,'display','inline');
if(this.upLeftStem)this.images.innerHTML='<img src='+this.upLeftStem+'>';
if(this.upRightStem)this.images.innerHTML+='<img src='+this.upRightStem+'>';
if(this.downLeftStem)this.images.innerHTML+='<img src='+this.downLeftStem+'>';
if(this.downRightStem)this.images.innerHTML+='<img src='+this.downRightStem+'>';
this.images.innerHTML+='<img src='+this.balloonImage+'>';
this.images.innerHTML+='<img src='+this.closeButton+'>';
}
else{
this.setStyle(this.images,'display','none');
}
currentBalloonClass=this;
this.timeoutTooltip=window.setTimeout(this.doShowTooltip,this.delayTime);
}
Balloon.prototype.doShowTooltip=function(){
var bSelf=currentBalloonClass;
if(balloonIsVisible)return false;
bSelf.currentElement=bSelf.firingElement;
bSelf.parseIntAll();
bSelf.setStyle(this.container,'display','none');
var balloon=bSelf.makeBalloon();
var pageWidth=YAHOO.util.Dom.getViewportWidth();
var pageCen=Math.round(pageWidth/2);
var pageHeight=YAHOO.util.Dom.getViewportHeight();
var pageLeft=YAHOO.util.Dom.getDocumentScrollLeft();
var pageTop=YAHOO.util.Dom.getDocumentScrollTop();
var pageMid=pageTop+Math.round(pageHeight/2);
var vOrient=bSelf.activeTop>pageMid?'up':'down';
var hOrient=bSelf.activeRight>pageCen?'left':'right';
var helpText=bSelf.container.innerHTML;
if(balloonIsSticky){
var style=
'margin-right:-'+Math.round(bSelf.padding/2-1)+'px;float:right;'+
'cursor:pointer;margin-top:-'+Math.round(bSelf.padding/2-1)+'px;float:right';
helpText=
'<img onclick="Balloon.prototype.hideTooltip(1)" title="Close" '+
'src="'+bSelf.closeButton+'" style="'+style+'">'+helpText;
}
document.getElementById('contents').innerHTML=helpText;
bSelf.setBalloonStyle(vOrient,hOrient,pageWidth,pageLeft);
balloonIsVisible=true;
bSelf.showHideSelect();
}
Balloon.prototype.makeBalloon=function(){
var bSelf=currentBalloonClass;
var balloon=document.getElementById('balloon');
if(balloon)document.body.removeChild(balloon);
balloon=document.createElement('div');
balloon.setAttribute('id','balloon');
document.body.appendChild(balloon);
var parts=new Array('contents','topRight','bottomRight','bottomLeft');
for(var i=0;i<parts.length;i++){
var child=document.createElement('div');
child.setAttribute('id',parts[i]);
balloon.appendChild(child);
}
bSelf.activeBalloon=balloon;
return balloon;
}
Balloon.prototype.setBalloonStyle=function(vOrient,hOrient,pageWidth,pageLeft){
var bSelf=currentBalloonClass;
var balloon=bSelf.activeBalloon;
if(typeof(bSelf.shadow)!='number')bSelf.shadow=0;
if(!bSelf.stem)bSelf.stemHeight=0;
var fullPadding=bSelf.padding+bSelf.shadow;
var insidePadding=bSelf.padding;
bSelf.setStyle(balloon,'background','url('+bSelf.balloonImage+') top left no-repeat');
bSelf.setStyle(balloon,'position','absolute');
bSelf.setStyle(balloon,'padding-top',fullPadding);
bSelf.setStyle(balloon,'padding-left',fullPadding);
bSelf.setStyle(balloon,'top',-9999);
bSelf.setStyle(balloon,'z-index',999999);
bSelf.setStyle('bottomRight','background','url('+bSelf.balloonImage+') bottom right no-repeat');
bSelf.setStyle('bottomRight','position','absolute');
bSelf.setStyle('bottomRight','right',0-fullPadding);
bSelf.setStyle('bottomRight','bottom',0-fullPadding);
bSelf.setStyle('bottomRight','height',fullPadding);
bSelf.setStyle('bottomRight','width',fullPadding);
bSelf.setStyle('topRight','background','url('+bSelf.balloonImage+') top right no-repeat');
bSelf.setStyle('topRight','position','absolute');
bSelf.setStyle('topRight','right',0-fullPadding);
bSelf.setStyle('topRight','top',0);
bSelf.setStyle('topRight','width',fullPadding);
bSelf.setStyle('topRight','z-index',-1);
bSelf.setStyle('bottomLeft','background','url('+bSelf.balloonImage+') bottom left no-repeat');
bSelf.setStyle('bottomLeft','position','absolute');
bSelf.setStyle('bottomLeft','left',0);
bSelf.setStyle('bottomLeft','bottom',0-fullPadding);
bSelf.setStyle('bottomLeft','height',fullPadding);
bSelf.setStyle('bottomLeft','z-index',-1);
if(this.stem){
var stem=document.createElement('img');
bSelf.setStyle(stem,'position','absolute');
balloon.appendChild(stem);
if(vOrient=='up'&&hOrient=='left'){
stem.src=bSelf.upLeftStem;
var height=bSelf.stemHeight+insidePadding-bSelf.stemOverlap;
bSelf.setStyle(stem,'bottom',0-height);
bSelf.setStyle(stem,'right',0);
}
else if(vOrient=='down'&&hOrient=='left'){
stem.src=bSelf.downLeftStem;
var height=bSelf.stemHeight-(bSelf.shadow+bSelf.stemOverlap);
bSelf.setStyle(stem,'top',0-height);
bSelf.setStyle(stem,'right',0);
}
else if(vOrient=='up'&&hOrient=='right'){
stem.src=bSelf.upRightStem;
var height=bSelf.stemHeight+insidePadding-bSelf.stemOverlap;
bSelf.setStyle(stem,'bottom',0-height);
bSelf.setStyle(stem,'left',bSelf.shadow);
}
else if(vOrient=='down'&&hOrient=='right'){
stem.src=bSelf.downRightStem;
var height=bSelf.stemHeight-(bSelf.shadow+bSelf.stemOverlap);
bSelf.setStyle(stem,'top',0-height);
bSelf.setStyle(stem,'left',bSelf.shadow);
}
}
if(hOrient=='left'){
var activeRight=pageWidth-bSelf.activeLeft;
bSelf.setStyle(balloon,'right',activeRight);
}
else{
bSelf.setStyle(balloon,'left',bSelf.activeRight);
}
if(!bSelf.width){
var width=bSelf.getLoc(balloon,'width');
if(width>bSelf.maxWidth)width=bSelf.maxWidth;
if(width<bSelf.minWidth)width=bSelf.minWidth;
bSelf.setStyle(balloon,'width',width);
}
else{
bSelf.setStyle(balloon,'width',bSelf.width);
}
var balloonPad=bSelf.padding+bSelf.shadow;
var balloonLeft=bSelf.getLoc(balloon,'x1');
var balloonRight=bSelf.getLoc(balloon,'x2');
if(hOrient=='left')balloonLeft+=balloonPad;
if(hOrient=='right')balloonRight+=balloonPad;
var pageRight=pageLeft+pageWidth;
if(hOrient=='right'&&balloonRight>(pageRight-30)){
bSelf.setStyle(balloon,'width',(pageRight-balloonLeft)-50);
}
else if(hOrient=='left'&&balloonLeft<(pageLeft+30)){
bSelf.setStyle(balloon,'width',(balloonRight-pageLeft)-50);
}
var lineWidth=bSelf.getLoc(balloon,'width');
var lineHeight=bSelf.getLoc(balloon,'height');
bSelf.setStyle('topRight','height',lineHeight);
bSelf.setStyle('bottomLeft','width',lineWidth);
var vOverlap=bSelf.isOverlap('topRight','bottomRight');
var hOverlap=bSelf.isOverlap('bottomLeft','bottomRight');
if(vOverlap)bSelf.setStyle('topRight','height',lineHeight-vOverlap[1]);
if(hOverlap)bSelf.setStyle('bottomLeft','width',lineWidth-hOverlap[0]);
if(vOrient=='up'){
var activeTop=bSelf.activeTop-bSelf.vOffset-bSelf.stemHeight-lineHeight;
bSelf.setStyle(balloon,'top',activeTop);
bSelf.setStyle(balloon,'display','inline');
}
else{
var activeTop=bSelf.activeTop+bSelf.vOffset+bSelf.stemHeight;
bSelf.setStyle(balloon,'top',activeTop);
}
}
Balloon.prototype.hideTooltip=function(override){
if(override&&typeof override=='object')override=false;
if(balloonIsSticky&&!override)return false;
var bSelf=currentBalloonClass;
currentBalloonClass=null;
if(bSelf)window.clearTimeout(bSelf.timeoutTooltip);
if(balloonIsSticky&&bSelf)bSelf.currentElement=null;
balloonIsVisible=false;
balloonIsSticky=false;
if(!bSelf){
var hideBalloon=document.getElementById('balloon');
if(hideBalloon)Balloon.prototype.setStyle(hideBalloon,'display','none');
}
else if(bSelf.activeBalloon){
bSelf.setStyle(bSelf.activeBalloon,'display','none');
}
Balloon.prototype.showHideSelect(1);
}
hideAllTooltips=function(){
var bSelf=currentBalloonClass;
if(!bSelf)return;
window.clearTimeout(bSelf.timeoutTooltip);
if(bSelf.activeBalloon)bSelf.setStyle(bSelf.activeBalloon,'display','none');
balloonIsVisible=false;
balloonIsSticky=false;
currentBalloonClass=null;
}
Balloon.prototype.setActiveCoordinates=function(evt){
var el=this.getEventTarget(evt);
var XY=this.eventXY(evt);
var area=el.getAttribute('coords');
var isImage=el.tagName.match('img','i');
var isTooBig=this.getLoc(el,'height')>50;
if(!area&&!isImage&&!isTooBig){
this.activeTop=this.getLoc(el,'y1')-10;
}
else{
this.activeTop=XY[1]-10;
}
this.activeLeft=XY[0]-10;
this.activeRight=this.activeLeft+20;
this.activeBottom=!area&&this.getLoc(el,'y2');
if(this.activeBottom)this.activeBottom+=10;
else this.activeBottom=this.activeTop+20;
}
Balloon.prototype.eventXY=function(event){
var XY=new Array(2);
var e=event||window.event;
XY[0]=e.pageX||e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
XY[1]=e.pageY||e.clientY+document.body.scrollTop+document.documentElement.scrollTop;
return XY;
}
Balloon.prototype.getEventTarget=function(event){
var targ;
var e=event||window.event;
if(e.target)targ=e.target;
else if(e.srcElement)targ=e.srcElement;
if(targ.nodeType==3)targ=targ.parentNode;
return targ;
}
Balloon.prototype.setStyle=function(el,att,val){
if(val&&att.match(/left|top|bottom|right|width|height|padding|margin/))val+='px';
if(el)YAHOO.util.Dom.setStyle(el,att,val);
}
Balloon.prototype.getLoc=function(el,request){
var region=YAHOO.util.Dom.getRegion(el);
switch(request){
case('y1'):return parseInt(region.top);
case('y2'):return parseInt(region.bottom);
case('x1'):return parseInt(region.left);
case('x2'):return parseInt(region.right);
case('width'):return(parseInt(region.right)-parseInt(region.left));
case('height'):return(parseInt(region.bottom)-parseInt(region.top));
case('region'):return region;
}
}
Balloon.prototype.parseIntAll=function(){
this.padding=parseInt(this.padding);
this.shadow=parseInt(this.shadow);
this.stemHeight=parseInt(this.stemHeight);
this.stemOverlap=parseInt(this.stemOverlap);
this.vOffset=parseInt(this.vOffset);
this.delayTime=parseInt(this.delayTime);
}
Balloon.prototype.showHideSelect=function(visible){
var bSelf=currentBalloonClass||new Balloon;
if(!this.isOldIE())return false;
if(!visible){
var balloonSelects=document.getElementById('contents').getElementsByTagName('select');
var myHash=new Object();
for(var i=0;i<balloonSelects.length;i++){
var id=balloonSelects[i].id||balloonSelects[i].name;
myHash[id]=1;
}
balloonInvisibleSelects=new Array();
var allSelects=document.getElementsByTagName('select');
for(var i=0;i<allSelects.length;i++){
var id=allSelects[i].id||allSelects[i].name;
if(bSelf.isOverlap(allSelects[i],bSelf.activeBalloon)&&!myHash[id]){
balloonInvisibleSelects.push(allSelects[i]);
bSelf.setStyle(allSelects[i],'visibility','hidden');
}
}
}
else if(balloonInvisibleSelects){
for(var i=0;i<balloonInvisibleSelects.length;i++){
var id=balloonInvisibleSelects[i].id||balloonInvisibleSelects[i].name;
bSelf.setStyle(balloonInvisibleSelects[i],'visibility','visible');
}
balloonInvisibleSelects=null;
}
}
Balloon.prototype.isOverlap=function(el1,el2){
if(!el1||!el2)return false;
var R1=this.getLoc(el1,'region');
var R2=this.getLoc(el2,'region');
if(!R1||!R2)return false;
if(el2.id=='balloon'){
R2.top=R2.top-30;
R2.left=R2.left-30;
R2.right=R2.right+30;
R2.bottom=R2.bottom+30;
}
var intersect=R1.intersect(R2);
if(intersect){
intersect=new Array((intersect.right-intersect.left),(intersect.bottom-intersect.top));
}
return intersect;
}
Balloon.prototype.isSameElement=function(el1,el2){
if(!el1||!el2)return false;
var R1=this.getLoc(el1,'region');
var R2=this.getLoc(el2,'region');
var same=R1.contains(R2)&&R2.contains(R1);
return same?true:false;
}
Balloon.prototype.getContents=function(section){
if(!this.helpUrl&&!this.activeUrl)return section;
if(this.loadedFromElement)return section;
var url=this.activeUrl||this.helpUrl;
var pars=this.activeUrl?'':'section='+section;
var ajax=new Ajax.Request(url,
{method:'get',
asynchronous:false,
parameters:pars,
onSuccess:function(t){Balloon.prototype.updateResult(t.responseText)},
onFailure:function(t){alert('AJAX Failure! '+t.statusText)}});
this.activeUrl=null;
return this.helpText||section;
}
Balloon.prototype.updateResult=function(text){
this.helpText=text;
}
Balloon.prototype.isIE=function(){
return document.all&&!window.opera;
}
Balloon.prototype.isOldIE=function(){
if(navigator.appVersion.indexOf("MSIE")==-1)return false;
var temp=navigator.appVersion.split("MSIE");
return parseFloat(temp[1])<7;
}
