// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue
//
// To use in masterpage use this syntax in the <head>:
//  	<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
//   	<script type="text/javascript" src="/_catalogs/masterpage/custom_activex_override.js"></script>
/////////////////////////////////////////////////////////////////////
// Name:        ProcessDefaultOnLoad
// Description: Prevents the User.ocx control in SharePoint displaying
/////////////////////////////////////////////////////////////////////
function ProcessDefaultOnLoad(onLoadFunctionNames)
{
	//** Uncomment this to see when this runs
	//alert('Fixing the Issue');
	
	ProcessPNGImages();
	UpdateAccessibilityUI();
	
	//** We comment out the offending ootb function
	//** and leave the rest of the functions as they were
	//ProcessImn();
	for (var i=0; i < onLoadFunctionNames.length; i++)
	{
		var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
		eval(expr);
	}
	if (typeof(_spUseDefaultFocus)!="undefined")
		DefaultFocus();
}

/////////////////////////////////////////////////////////////////////
// Name:        DisplayMidmarkOverlay
// Description: Old html windowing for midmark.com (Depreciated)
/////////////////////////////////////////////////////////////////////
function DisplayMidmarkOverlay(Selector, IsExposed, Size) 
{
    var Expose = "";
    var BodyHeight = window.innerHeight;
    var WindowHeight = 0;
    var TopPX = "";

    // Check if the window is exposed
    if (IsExposed)
        Expose = "#707070";
    else
        Expose = "Transparent";

    // Detirmine what class to apply to div
    if (Size == "Small")
    {
        $(Selector).addClass("midmark-overlay-small");
        WindowHeight = 400;
    }
    else if (Size == "Medium") 
    {
        $(Selector).addClass("midmark-overlay-medium");
        WindowHeight = 576;
    }
    else if (Size == "Large") 
    {
        $(Selector).addClass("midmark-overlay-large");
        WindowHeight = 702;
    }
    else 
    {
        $(Selector).addClass("midmark-overlay-medium");
        WindowHeight = 576;
    }

    if (WindowHeight >= (BodyHeight + window.scrollY))
        TopPX = 0;
    else
        TopPX = ((BodyHeight - WindowHeight) / 2) + window.scrollY;

    // get handle to the API upon initialization by enabling the "api" variable
    var api = $(Selector).overlay({
        oneInstance: false,
        closeOnEsc: true,
        closeOnClick: false,
        preload: true,
        expose: Expose,
        effect: 'apple',
        speed: 'fast',
        top: '10%',
        left: 'center',
        absolute: false,
        api: true
    });

    // open the overlay programatically with this API call 
    api.load();

    // retrieve an existing api
    api = $(Selector).overlay();
}


/////////////////////////////////////////////////////////////////////
// Name:        DisplayMidmarkWindow
// Description: 
/////////////////////////////////////////////////////////////////////
function DisplayMidmarkWindow(Selector)
{
    var api;
    var CloseSelector = Selector + " > .close";
    
    // Set styling on Midmark Window
    $(Selector).css("background-color", "#FFFFFF");
    $(Selector).css("-moz-border-radius", "6px");
    $(Selector).css("-webkit-border-radius", "6px");
    $(Selector).css("border-radius", "6px");
    $(Selector).css("padding", "10px");
    
//    if(iWidth != null)
//        $(Selector).css("width", (iWidth - 20) + "px");
//        
//    if(iHeight != null)
//        $(Selector).css("height", (iHeight - 20) + "px");

    // get handle to the API upon initialization by enabling the "api" variable
    api = $(Selector).overlay({
            oneInstance: false,
            closeOnEsc: true,
            closeOnClick: false,
            mask: {
                color: '#000000',
                loadSpeed: 200,
                opacity: 0.7
            },
            speed: 'normal',
            top: 'center',
            left: 'center',
            absolute: true,
            api: true
    });

    // open the overlay programatically with this API call
    api.load();

    // retrieve an existing api
    api = $(Selector).overlay();

    // Set styling on Close Selector
    $(CloseSelector).css("width", "36px");
    $(CloseSelector).css("height", "36px");
    $(CloseSelector).css("position", "absolute");
    $(CloseSelector).css("top", "-18px");
    $(CloseSelector).css("right", "-18px");
    $(CloseSelector).css("cursor", "pointer");
    $(CloseSelector).css("z-index", "9999");
    $(CloseSelector).css("background-image", "url(/_layouts/Midmark.Web.PublishingSite/Images/Midmark-Overlay-Close.png)");
    $(CloseSelector).css("background-repeat", "no-repeat");
    $(CloseSelector).css("visibility", "visible");
    $(CloseSelector).css("display", "block");
}
