﻿/* Registers functionality to open pages in new browser window */

//Register FAQ Popup Window
function registerFAQPopup() {
    var faqWindow;
    jQuery('a.dfs-faq').click(function(event) {
		event.stopPropagation(); // Stops the following click function from being executed
        var href = this.href;
        var title = '_blank';
        var width = 940;
			
        var height = jQuery(window).myHeight() - 150; //screen.height
        var left = (screen.width  - width)/2;
		var top = (screen.height - height)/2;
        
        var mainContainer = jQuery('#dfs-mainContainer');
        if (mainContainer) {
			var mainContainerOffset = mainContainer.offset();
			left = mainContainerOffset.left;
			top = mainContainerOffset.top;
		} 
        
        // Close existing window if necessary
        if (faqWindow) faqWindow.close();
        faqWindow = window.open(href, title, 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',toolbar=0,resizable=1,scrollbars=1,directories=0,menubar=0,location=0,status=1');
        faqWindow.focus();
        return false;
    });
}

jQuery.fn.myHeight = function(h) { 
    var name = "Height"; 
    return this[0] == window ? 
        !jQuery.browser.msie && self["inner" + name] || 
        jQuery.boxModel && document.documentElement["client" + name] || 
        document.body["client" + name] : 
        this[0] == document ? 
                Math.max( document.body["scroll" + name], document.body["offset" + name] ) : 
                h == undefined ? 
                        ( this.length ? jQuery.css( this[0], n ) : null ) : 
                        this.css( n, h.constructor == String ? h : h + "px" ); 
  }; 