﻿function IFrameLoad(iframe)
{
    if (iframe == null)
    {
        return;
    }
    
    var srcPath = iframe.getAttribute("srcPath");
    
    var tabIndex = TabsGetTabIndexByIFrame(iframe);
    if (tabIndex != -1)
    {
        TabsButtons[tabIndex].disabled = false;
    }
    
    var src = srcPath;
        
    var iframeParentType = IFrameGetParentType(iframe);
    if (iframeParentType != null)
    {
        src = UrlAddQueryString(src, "IFrameParentType", iframeParentType);
    }
    
    var srcQueryStringKeys = IFrameGetSrcQueryStringKeys(iframe);
    if (srcQueryStringKeys != null)
    {
        var srcQueryStringValues = ElementGetValues(iframe.getAttribute("srcQueryStringValues"), iframe);
        for (var i = 0; i < srcQueryStringKeys.length; i++)
        {
            if (srcQueryStringValues[i] != null && srcQueryStringValues[i] != "")
            {
                src = UrlAddQueryString(src, srcQueryStringKeys[i], encodeURI(srcQueryStringValues[i]));
            }
        }
    }
    
    src = UrlAddQueryString(src, "time", new Date().getTime());
    
    iframe.src = src;
}
function IFrameDontLoad(iframe)
{
    iframe.src = "";
    
    var tabIndex = TabsGetTabIndexByIFrame(iframe);
    if (tabIndex != -1)
    {
        for (var i = tabIndex; i < TabsButtons.length; i++)
        {
            TabsButtons[i].disabled = true;
        }
    }
}
function IFrameOnLoad()
{
    IFrameDIV = document.getElementById("IFrameDIV");
    
    var disabled = false;
    if (window.frameElement.getAttribute("iframeEnabled") != null)
    {
        if (window.frameElement.getAttribute("iframeEnabled") == "False")
        {
            disabled = true;
        }
    }
    IFrameDIV.disabled = disabled;
    
    IFrameFixHeight();
    
    if (document.implementation.hasFeature("MutationEvents", "2.0") || window.MutationEvent)
    {
        //Mozilla Firefox
        $(IFrameDIV).bind("DOMAttrModified", IFrameOnDOMAttributeModified);
    }
    else
    {
        //Internet Explorer
        $(IFrameDIV).bind("resize", IFrameFixHeight);
    }
    
    var parentWindow = window.parent;
    while (typeof parentWindow != "undefined" && parentWindow != null)
    {
        if (typeof parentWindow.IFrameLoaded == "function")
        {
            parentWindow.IFrameLoaded(window.frameElement);
        }
        if (parentWindow == parentWindow.parent) parentWindow = null; else parentWindow = parentWindow.parent;
    }
}




function IFrameGetParentType(iframe)
{
    return iframe.getAttribute("iframeParentType");
}
function IFrameGetSrcQueryStringKeys(iframe)
{
    if (iframe.getAttribute("srcQueryStringKeys") == null)
    {
        return null;
    }
    
    var srcQueryStringKeys = iframe.getAttribute("srcQueryStringKeys").split(';');
    return srcQueryStringKeys;
}




//Ova funkcija se koristi kod uslovne validacije
function IFrameEnableValidation(iframe, enable)
{
    var iframeWindow = iframe.contentWindow;
    if (typeof iframeWindow.Page_ClientValidate == "undefined")
    {
        return "";
    }
    
    for (i = 0; i < iframeWindow.Page_Validators.length; i++)
    {
        var validator = iframeWindow.Page_Validators[i];
        ValidatorEnable(validator, enable);
    }
}




var IFrameDIV = null;
function IFrameFixHeight()
{
    var windowToFix = window;
    while (windowToFix.frameElement != null)
    {
        if (windowToFix.IFrameDIV != null)
        {
            windowToFix.frameElement.style.height = $(windowToFix.document).height() + "px";
        }
        windowToFix = windowToFix.parent;
    }
}
function IFrameOnDOMAttributeModified(event)
{
    if (event.attrName == "style")
    {
        window.setTimeout(IFrameFixHeight, 100);
    }
}




function IFrameAnd(booleans)
{
    for (var i = 0; i < booleans.length; i++)
    {
        if (booleans[i] == false)
        {
            return false;
        }
    }
    return true;
}
function IFrameOr(booleans)
{
    for (var i = 0; i < booleans.length; i++)
    {
        if (booleans[i] == true)
        {
            return true;
        }
    }
    return false;
}

