﻿    // MIS popup object.
    
    var MisPopup = {
	    popupXLeftOffset : 0,
	    popupYTopOffset : 25,
        xMaxLeftOffset : 512,
        yMaxTopWindow : 10000,
        autoCenterInterval : 250,
        
        // cached popup design
        info2 : null,
        
        // tells if popup object has been initialized
        isInited : function() {
            return this.info2;
        },
        
        // initializes popup object for display
        init : function() {
            if (this.isInited())
                return;
            var info = document.getElementById('popupDesign');
            if (info && !this.info2)
                this.info2 = info.cloneNode(true);                
            var position = document.getElementById('popupPosition');
            if (position && this.info2)
                position.appendChild(this.info2);
            this.info2.style.position = 'absolute';
            this.info2.style.top = 50;
            this.info2.style.left = 75;
            this.info2.style.visibility = 'hidden';
            this.info2.style.display = 'inline';
	    MisPopup.reposition(true);
        },
        
	reposition : function(isRepeated) {
		if (! this.isInited())
			this.init();

		// position vertically inside current client view
		var yTopWindow = 0;
		if (window.pageYOffset !== undefined) // for most browsers
			yTopWindow = window.pageYOffset + this.popupYTopOffset;
        else if (document.body && document.body.scrollTop !== undefined) // and for IE
			yTopWindow = document.body.scrollTop + this.popupYTopOffset;
        this.info2.style.top = (yTopWindow > this.yMaxTopWindow ? this.yMaxTopWindow : yTopWindow);

		//centre horizontally over page
		
		var leftpad = 0;
		if (window.pageXOffset !== undefined)
		    leftpad = parseInt(window.pageXOffset + this.popupXLeftOffset);
		else if (document.body.scrollLeft !== undefined) //ie
		    leftpad = parseInt(document.body.scrollLeft);
		    
		var xViewLeft;    
		if (document.width !== undefined)
			xViewLeft = ((parseInt(document.width) - parseInt(this.info2.style.width)) / 2) + leftpad + this.popupXLeftOffset;
		else if (document.body.scrollWidth !== undefined)  //ie
		    xViewLeft = ((parseInt(document.body.scrollWidth) - parseInt(this.info2.style.width)) / 2) + leftpad + this.popupXLeftOffset;
        this.info2.style.left = (xViewLeft > this.xMaxLeftOffset ? this.xMaxLeftOffset : xViewLeft);

		if (isRepeated)
			window.setTimeout('MisPopup.reposition(true)', this.autoCenterInterval);
	},
		
        // show the specified brokerage info
        show: function(brokerId) {
            if (! this.isInited())
                this.init();
            document.getElementById('misDetailFrame').src  = '/MisDetail/MisDetail.aspx?BrokerageId=' + brokerId;
            this.info2.style.visibility = 'visible';
        },
        
        // hide the poup window
        hide: function() {
            if (! this.isInited())
                this.init();
            document.getElementById('misDetailFrame').src  = 'about:blank';
            this.info2.style.visibility = 'hidden';
        }
        
    };
    
