/**
 * ESV Popup Reference
 *
 * @author Scott Yang <scotty@yang.id.au>
 * @version 1.0
 */ 
 /*Here where made some changes by AGP Production s.r.o. to be possible to pass the url target
 was added var My_url and all around to its function.
 Also to set an style to each url we use My_Style variable
 */

var ESVPopup = {};
var My_url=''
var My_Style='ESVPopupFrame'

// URL to the static page. Default to 'esvpopup.html' in the same directory.
ESVPopup.baseurl = '';
ESVPopup.frame = null;

ESVPopup.show = function(passage, x, y) {
	ie = document.all;

    if (!ESVPopup.baseurl) {
        var elms = document.getElementsByTagName('script');

        for (var i = 0; i < elms.length; i++) {
            if (elms[i].src && (elms[i].src.indexOf("esvpopup.js") != -1)) {
                var src = elms[i].src;
                ESVPopup.baseurl = src.substring(0, src.lastIndexOf('/')+1);
                break;
            }
        }
    }

    //url = ESVPopup.baseurl + 'esvpopup.html?passage='+encodeURI(passage);
	//url = ESVPopup.baseurl + 'esvpopup.html';
	url = ESVPopup.baseurl + 'info_usercard.htm';
	url = My_url;
    if (!ESVPopup.frame) {
        var frame = null;

        // MSIE does not have a proper DOM2 implementation so <iframe/>
        // created by DOM2 does not work sometimes. Fortunately we can use
        // insertAdjacentHTML()
        if (ie) {
            var html = '<iframe width="266" height="100" id="'+My_Style+'" frameborder="0" '+
                'src="'+url+'" style="width: 266px; height: 100px; background-color: #fff; overflow: hidden; position:absolute; z-index: 1; top:'+y+
                'px;left:'+x+'px;" scrolling="no"></iframe>';
            document.body.insertAdjacentHTML('afterbegin', html);
            frame = document.getElementById(My_Style);
            frame.attachEvent('onblur', ESVPopup._onhide);
            document.body.attachEvent('onmousedown', ESVPopup._onhide);
        } else {
            var frame = document.createElement('IFRAME');
            document.body.appendChild(frame);
            frame.id = My_Style;
            frame.frameBorder = 0;
            frame.marginHeight = 0;
            frame.marginWidth = 0;
            frame.src = url;

            frame.style.position = 'absolute';
            frame.style.top = y+'px';
            frame.style.left = x+'px';

            frame.addEventListener('blur', ESVPopup._onhide, false);
            window.addEventListener('mousedown', ESVPopup._onhide, false);
        }
        
        ESVPopup.frame = frame;
    } else {
		ESVPopup.frame = document.getElementById(My_Style);// to get the actual style
		ESVPopup.frame.src = url;
        ESVPopup.frame.style.top = y + 'px';
        ESVPopup.frame.style.left = x + 'px';
        ESVPopup.frame.style.display = '';
    }

    // Fixing up the position so no overflow is needed. We need to detect
    // whether we are under XHTML or HTML 4
    var b;
    if (ie) {
        b = document.documentElement.clientWidth ? document.documentElement :
            document.body;
    } else {
        b = (document.doctype && document.doctype.publicId && 
             (document.doctype.publicId.indexOf('XHTML') >= 0)) ?
            document.documentElement : document.body;
    }

    var dh = b.clientHeight;
    var dw = b.clientWidth;
    dh = (ESVPopup.frame.offsetHeight+y) - dh;
    dw = (ESVPopup.frame.offsetWidth+x)  - dw;

    ESVPopup.frame.style.left = x-(dw>0?dw:0)+b.scrollLeft + 'px';
    ESVPopup.frame.style.top  = y-(dh>0?dh:0)+b.scrollTop  + 'px';
};

ESVPopup.onclick = function(e, passage, MyUrl, MyStyle) {
	My_url=MyUrl;
	My_Style=MyStyle;
    if (!e) e = window.event;
//	My_url=MyURL

    var x = e.clientX;
    var y = e.clientY;

    if (!passage) {
        var elm = e.srcElement || e.target;
        passage = elm.innerHTML;
    }
    ESVPopup.show(passage, x, y);
};

ESVPopup._onhide = function(event) {
    var f = ESVPopup.frame;
    if (f) {
        f.style.display = 'none';
    }
};

