﻿//var winscroll = window.onscroll;
//var winresize = window.onresize;
var BubbleMessages = new Array();

window.onscroll = function(){
    //if(winscroll){
    //    winscroll();
    //}
    for(i=0;i<BubbleMessages.length;i++){
        BubbleMessages[i].positionDiv();
    }
}
window.onresize = function(){
    //if(winresize){
    //    winresize();
    //}
    for(i=0;i<BubbleMessages.length;i++){
        BubbleMessages[i].setWindowSize();
    }
}
onload = function(){
	for(i=0;i<BubbleMessages.length;i++){
        BubbleMessages[i].setWindowSize();
    }
}

var BubbleMessage = function(){    
    BubbleMessages[BubbleMessages.length] = this;
    return this;
}

BubbleMessage.prototype = {
    getMessageDiv: function(){
        var MessageDivId = "divBubbleMessage";
        if(this.getElement(MessageDivId)==null){            
            var comp = document.createElement("div");
            comp.id = MessageDivId;
            comp.style.position = "absolute";
            comp.style.left = "0px";
            comp.style.top = "0px";
            comp.className = "bubblemessage";
            if(document.body)document.body.appendChild(comp);
        }
        return this.getElement(MessageDivId);
    },
    trim: function(str){
        return str.replace(/^\s+|\s+$/gi,"");
    },
    writeMessage: function(str){
         var comp = this.getMessageDiv();
         comp ? comp.innerHTML = str : str="";         
         (this.trim(str)=="")?this.hide():this.show();
         this.positionDiv();
    },
    show: function(){
        var comp = this.getMessageDiv();
        comp ? comp.style.visibility = "visible" : null;
    },
    hide: function(){
        var comp = this.getMessageDiv();
        comp ? comp.style.visibility = "hidden" : null;
    },
    setWindowSize: function(){
        this.positionDiv();
    },
    positionDiv: function(){
        var comp = this.getMessageDiv();        
        if(comp){
            var left = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            var top = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);        
            //comp.style.left = 0 + "px";//(this.getWindowDim().width - Math.max(comp.offsetWidth,comp.scrollWidth) + left) + "px";
	    comp.style.left = this.getLeft();
            comp.style.top = (this.getWindowDim().height - Math.max(comp.offsetHeight,comp.scrollHeight) + top) + "px";
        }
    },
    getElement: function(comp){
        return ((typeof(comp)=="string") ? document.getElementById(comp) : comp);
    },
    getWindowDim: function(){
        var WinInnerWid = 630;
        var WinInnerHei = 460;
        if( typeof( window.innerWidth ) == 'number' ) {    
        WinInnerWid = window.innerWidth;        
        }
        if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {    
        WinInnerWid = document.documentElement.clientWidth;        
        }
        if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {    
        WinInnerWid = document.body.clientWidth;        
        }
        if( typeof( window.innerWidth ) == 'number' ) {    
        WinInnerHei = window.innerHeight;
        }
        if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {    
        WinInnerHei = document.documentElement.clientHeight;
        }
        if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {    
        WinInnerHei = document.body.clientHeight;
        }        
        return {width:WinInnerWid, height:WinInnerHei};
    },
    getLeft: function() {
	obj = document.getElementById("TopBar")
	var curleft = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
		}
	}
	return curleft
    }
}