var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var OWNER = document.body;

var MAIN_SWF_DIV_ID = "mainSwfDiv";

var MAIN_SWF_ID = "mainSwf";
var PATH_PREFIX = "widget/";
var MAIN_SWF_LOCATION = PATH_PREFIX + "Main.swf";
var NYSE_SOD_MAIN_SWF_WAIT_ANIMATION_LOCATION = PATH_PREFIX + "emailWaitAnimation.swf";
var MODULE_DIV_ID = PATH_PREFIX + "moduleDivId";
var MODULE_SWF_SOURCE = PATH_PREFIX + "radixModule.swf";
var MODULE_SWF_ID = "moduleSwfId";
var ERROR_DIV_ID = "errorDiv";
var PDF_DIV_ID = "pdfDiv";
var MODEL_DIV_ID = "modelDivID"
var MODULE_VIEW_STATE_NORMAL = "normal";
var MODULE_VIEW_STATE_FULL = "full";

var normalViewIframePos = {'top':0, 'left':0, 'isInit': 0};
var largeViewIframePos = {'top':0, 'left':0, 'isInit': 0};
var mainSwfState;
var mainSwfoffsetLeft = null;
var mainFlashVar;
var nyse_sod_page_content_width;  
var modelObject;
var isClosePlayListAction = 0;

function changeIfameSize(width, height)
{
    var ifrm = parent.document.getElementById("ProfileWeekSODIframe");
    ifrm.style.width = parseInt(width) + "px";
    ifrm.style.height = parseInt(height) + "px";
}

function changeIframePosition(left, top) 
{
    var ifrm = parent.document.getElementById("ProfileWeekSODIframe");
    if (left) ifrm.style.left = parseInt(left) + "px";
    if (top) ifrm.style.top = parseInt(top) + "px"; 
}

function PowTIFrameOnblur()
{
    var objcts = parent.document.getElementsByTagName('object');
    for(i=0; i<objcts.length; i++)
    {
        objcts[i].onfocus = otherFlashOnFocusHandler;
    }
}

function changeBodyContent()
{
    if (!isIE)
    {
        if(!parent.document.getElementById("radixAllContainer"))
       {
            var tmpStr = parent.document.body.innerHTML;
            tmpStr = '<div id="radixAllContainer" style="overflow:auto; overflow-y:hidden">' + tmpStr + '</div>';
            parent.document.body.innerHTML = tmpStr;
       }
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createMainSwfDiv(diviId, flashvar, pageContentWidth)
{
    parent.document.getElementById("ProfileWeekSODIframe").onblur = PowTIFrameOnblur;

    var len = arguments.length;
    var pos = -1;
    if (!isNaN(pageContentWidth) && pageContentWidth > 0) {
       nyse_sod_page_content_width = pageContentWidth;
    }
    
    if (document != null)
    {
        OWNER = document.getElementById(diviId) || document.body;
        mainFlashVar = flashvar;
        createModule();
        createMain();
        createPdf();
        saveIframePosition();
    }
}

function setActionName(actionName)
{
    if (parent.document.body.id == "")
    {
        parent.document.body.id = actionName;
    }
    
    if (actionName != "PlayVideo")
    {
        changeBodyContent();
    }
}

function getActionName()
{
    return parent.document.body.id;
}

function checkPreviousAction()
{
    if (parent.document.body.id != "")
    {
        if (parent.document.body.id == "PlayVideo")
        {
            getSwfById(MAIN_SWF_ID).autoShowPlayList();
        }
        else if (parent.document.body.id == "ShowPlayList")
        {
            getSwfById(MAIN_SWF_ID).autoShowPlayList();
        }
        else
        {
            getSwfById(MAIN_SWF_ID).switchToPreviousStage(parent.document.body.id);
        }
    }
}

function createModelDiv()
{
    modelObject = document.createElement("div");
    modelObject.setAttribute("id", MODEL_DIV_ID);
    modelObject.style.backgroundColor = "white";
    modelObject.style.position = "absolute";
    modelObject.style.left = 0 + "px";
    modelObject.style.top = 0 + "px";
    modelObject.style.right = 0 + "px";;
    modelObject.style.bottom = 0 + "px";
    modelObject.style.height = document.body.scrollHeight + "px";
    modelObject.style.width = document.body.offsetWidth;
    modelObject.style.zindex = 10000;
    document.body.appendChild(modelObject);
}

function createMain()
{
    var hasRequestedVersion = DetectFlashVer(9, 0, 124);
    if (hasRequestedVersion)
    {
        var mainSwfDiv = createDiv(MAIN_SWF_DIV_ID, 100, 0, 0, 367, 280);
        OWNER.appendChild(mainSwfDiv);
        var swfObj = new swfObject(mainSwfDiv, MAIN_SWF_LOCATION, "100%", "100%", MAIN_SWF_ID,"transparent");
        swfObj.createVar(mainFlashVar);
        swfObj.append();

        mainSwfState = "normal";
    }
    else
    {
        createErrorDiv();
    }
}

function createErrorDiv()
{
    var errorDiv = createDiv(ERROR_DIV_ID, 900, 0, 135, 367, 280);
    errorDiv.innerHTML = 'Adobe Flash Player 9.0.124 is required at least. ' + '<a href="http://www.adobe.com/go/getflash/" target="_new">Download now</a>';
    errorDiv.style.textAlign = "center";
    errorDiv.style.marginLeft = "auto";
    errorDiv.style.marginRight = "auto";
    OWNER.appendChild(errorDiv);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var MODULE_VIEW_TYPE_EMAIL = "email";
var MODULE_VIEW_TYPE_SUBSCRIBE = "subscribe";
var MODULE_VIEW_TYPE_DIALOG = "urlDialog";
var MODULE_VIEW_TYPE_VIDEO = "video";
var MODULE_VIEW_TYPE_MARKET_DATA = "marketData";

var MODULE_VIEW_POSITION_BOTTOM_LEFT = "winPositionBottomLeft";
var MODULE_VIEW_POSITION_BOTTOM_RIGHT = "winPositionBottomRight";
var radix_isEmailOrSubscribeOpen = false;
function createModule(viewType, data, viewState, viewPosition)
{
    var top;
    var left;
    var width;
    var height;
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    switch (viewType)
    {
        case MODULE_VIEW_TYPE_EMAIL:
        case MODULE_VIEW_TYPE_SUBSCRIBE:
        case MODULE_VIEW_TYPE_DIALOG:
        {
            radix_isEmailOrSubscribeOpen = true;
            if (mainSwfState == "noBottomNormal") 
            {
                left = parseInt(mainSwfDiv.style.left);
                top = mainSwfDiv.offsetTop;
                width = mainSwfDiv.offsetWidth;
                height = mainSwfDiv.offsetHeight;
                viewState = "noBottomNormal";
            }
            else if (mainSwfState == "normal")
            {
                left = parseInt(mainSwfDiv.style.left);
                top = mainSwfDiv.offsetTop;
                width = mainSwfDiv.offsetWidth;
                height = mainSwfDiv.offsetHeight;
                viewState = "normal";
            }
            else if (mainSwfState == "large")
            {
                left = parseInt(mainSwfDiv.style.left);
                top = mainSwfDiv.offsetTop;
                width = mainSwfDiv.offsetWidth;
                height = mainSwfDiv.offsetHeight;
                viewState = "large"
            }
            else
            {
                left = parseInt(mainSwfDiv.style.left);
                top = mainSwfDiv.offsetTop;
                width = mainSwfDiv.offsetWidth;
                mainSwfDiv.style.height = getBodyHeight();
                height = mainSwfDiv.offsetHeight;
                viewState = "full";
            }
            if (document.getElementById("pdfIframe"))setPDFViewHidden();
            break;
        }
        case MODULE_VIEW_TYPE_VIDEO:
        case MODULE_VIEW_TYPE_MARKET_DATA:
        {
            height = 66;
            
            switch (viewState)
            {
                case MODULE_VIEW_STATE_NORMAL:
                {
                    width = 266;
                    
                    switch (viewPosition)
                    {
                        case MODULE_VIEW_POSITION_BOTTOM_LEFT:
                        {
                            top = mainSwfDiv.offsetTop + 211;
                            left = parseInt(mainSwfDiv.style.left) + 4;    
                            break;
                        }
                        case MODULE_VIEW_POSITION_BOTTOM_RIGHT:
                        {
                            top = mainSwfDiv.offsetTop + 211;
                            left = parseInt(mainSwfDiv.style.left) + 97;    
                            break;
                        }
                    }
                    break;
                }
                case MODULE_VIEW_STATE_FULL:
                {
                    width = 359 ;
                    top = mainSwfDiv.offsetTop + 211;
                    left = parseInt(mainSwfDiv.style.left) + 4;    
                    break;
                }
                
            }
            break;
        }
        default:
        {
            top = 0;
            left = 0;
            width = 0;
            height = 0;
        }
    }
    var div = document.getElementById(MODULE_DIV_ID);
    if (!div)
    { 
        var moduleDiv = createDiv(MODULE_DIV_ID, 500, parseInt(left), parseInt(top), parseInt(width), parseInt(height));
        OWNER.appendChild(moduleDiv);
        
        var swfObj = new swfObject(moduleDiv, MODULE_SWF_SOURCE, "100%", "100%", MODULE_SWF_ID, "window");
        swfObj.createVar(data);
        swfObj.addVar("viewType", viewType);
        swfObj.addVar("viewState", viewState);
        swfObj.append();
    }
    else
    {
        var moduleSwf = getSwfById(MODULE_SWF_ID);
        moduleSwf.setData(data, viewType, viewState);
        div.style.left = parseInt(left) + "px";
        div.style.top = parseInt(top) + "px";
        div.style.width = parseInt(width) + "px";
        div.style.height = parseInt(height) + "px";
    }
    setPopUpFocus();
}

function setPopUpFocus()
{
    var popUpSwf = document.getElementById(MODULE_SWF_ID);
    if (popUpSwf.style.visibility == "hidden" || popUpSwf.style.visibility == "hidden" || popUpSwf.disabled==true)
    {
    }
    else
    {
        try
        {
           popUpSwf.focus();
        }
        catch(e)
        {
        }
    }
}

function setModuleMarketData(data)
{
     var moduleSwf = getSwfById(MODULE_SWF_ID);
     moduleSwf.setData(data);
}

function onModuleSwfMouseOut()
{
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    removeModuleSwfDiv();
    if (mainSwfState == "large")
    {
        mainSwfDiv.style.height = 433 + "px";
    }
}

function onModuleSwfMouseClick()
{
    removePdf();
    removeModuleSwfDiv();
    getSwfById(MAIN_SWF_ID).changeWin();
}

function onModuleSwfClose()
{
    removeModuleSwfDiv();
}

function removeModuleSwfDiv()
{
    radix_isEmailOrSubscribeOpen = false;
    if (isPdfOpen)
    {
        mainSwfState == "large" ? setPDFLargeViewArea() 
            : (mainSwfState == "full" ? setPDFFullViewArea()
            : setPDFNormalViewArea());
    }
    
    var moduleDiv = document.getElementById(MODULE_DIV_ID);
    moduleDiv.style.width = 0;
    moduleDiv.style.height = 0;
    getSwfById(MAIN_SWF_ID).onHidePopUpSwf();
}

var t = 0;
var isPdfOpen;
function createPdf(source)
{
    isPdfOpen = true;
    if (new Date().getTime() - t < 1000)
    {
        return;
    }
    else
    {
        t = new Date().getTime();
    }

    var pdfHeight = 0;
    var pdfWidth = 0;
    if (mainSwfState == "normal")
    {
        pdfHeight = document.getElementById(MAIN_SWF_DIV_ID).offsetHeight - 70;
    }
    else
    {
         pdfHeight = document.getElementById(MAIN_SWF_DIV_ID).offsetHeight - 27;
    }
    pdfWidth = document.getElementById(MAIN_SWF_DIV_ID).offsetWidth;

    if (pdfHeight < 0)
    {
        if (mainSwfState == "normal")
        {
            pdfHeight = 212;
            pdfWidth = 367;
        }
        else if (mainSwfState == "large")
        {
             pdfHeight = 433 - 27;
             pdfWidth = 730;
        }
        else
        {
            pdfHeight = getBodyWidth() - 27;
            pdfWidth = getBodyWidth();
        }
    }

    var pdfIframe = document.getElementById("pdfIframe");

    if (!pdfIframe)
    {
        var pdfDiv = createDiv(PDF_DIV_ID, 50,
        parseInt(document.getElementById(MAIN_SWF_DIV_ID).style.left),
        document.getElementById(MAIN_SWF_DIV_ID).offsetTop + 27,
        pdfWidth, pdfHeight);
        //pdfDiv.innerHTML = "<embed name='plugin' type='application/pdf' height='100%' width='100%' src='" + source + "' wmode='window'/>";
        pdfDiv.innerHTML = '<iframe id="pdfIframe" frameborder="0" width="100%" height="100%" src="' + source + '"><html><body marginwidth="0" marginheight="0"><embed height="100%" width="100%" name="plugin" src="' + source + '" type="application/pdf"/></body></html></iframe>';
        OWNER.appendChild(pdfDiv);
        var pdfIframe = document.getElementById("pdfIframe");
        pdfIframe.style.width = 0;
        pdfIframe.style.height = 0;
        pdfIframe.src = "";
    }
    else
    {
        var pdfDiv = document.getElementById(PDF_DIV_ID);
        if (mainSwfState == "normal"  || mainSwfState == "noBottomNormal")
        {
           pdfDiv.style.height = 212 + "px";
           pdfDiv.style.width = 367 + "px";
        }
        else if (mainSwfState == "large")
        {
            pdfDiv.style.height = 433 - 27 + "px";
            pdfDiv.style.width = 730 + "px";
        }
        else
        {
            pdfDiv.style.height = getBodyHeight() - 27 + "px";
            pdfDiv.style.width = getBodyWidth() + "px";
        }
        pdfIframe.src = source;
        pdfIframe.style.width = "100%";
        pdfIframe.style.height = "100%";
    }
}

function removePdf()
{
    isPdfOpen = false;
    var pdfIframe = document.getElementById("pdfIframe");
    pdfIframe.style.width = 0;
    pdfIframe.style.height = 0;
    pdfIframe.src = "";
    // OWNER.removeChild(document.getElementById(PDF_DIV_ID));
    getSwfById(MAIN_SWF_ID).showGalleryBackBtn(false);
}

function otherFlashOnFocusHandler()
{
    try
    {
        getSwfById(MAIN_SWF_ID).backToNormalSize();
    }
    catch(e)
    {
    }
    var ifrm = parent.document.getElementById("ProfileWeekSODIframe");
    if (ifrm.style.width == 586 + "px")
    {
        autoClosePlayList();
    }
}

function autoClosePlayList()
{
    getSwfById(MAIN_SWF_ID).autoClosePlayList();
}

function showModel()
{
    createModelDiv();
}

function hiddenModel()
{
    if (modelObject)
    {
        document.body.removeChild(modelObject);
    }
}

function setPDFFullViewArea()
{
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    var width = getBodyWidth();
    var height = getBodyHeight() - 27;

    if (pdfDiv)
    {
        pdfDiv.style.width = width + "px";
        pdfDiv.style.height = height + "px";
    }
}

function setPDFLargeViewArea()
{
    var moduleDiv = document.getElementById(MODULE_DIV_ID);
    if (moduleDiv)
    {
        moduleDiv.style.width = 0 + "px";
        moduleDiv.style.height = 0 + "px";
        //getSwfById(MAIN_SWF_ID).onHidePopUpSwf();
    }

    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv)
    {
        pdfDiv.style.height = 433 - 27 + "px";
        pdfDiv.style.width = 730 + "px";
    }
}

function setPDFViewHidden()
{
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv) 
    {
        pdfDiv.style.height = 0 + "px";
        pdfDiv.style.width = 0 + "px";
    }
}

function setPDFNormalViewArea()
{
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv) 
    {
        pdfDiv.style.height = 212 + "px";
        pdfDiv.style.width = 367 + "px";
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getDimensions(obj) {
    var element = obj;
    var top = 0, left = 0;
    do 
    {
      top += element.offsetTop  || 0;
      left += element.offsetLeft || 0;
      element = element.offsetParent;
    } 
    while (element);
    return {'left':left, 'top':top};
}

function saveIframePosition() 
{
    var dim = getDimensions(parent.document.getElementById("ProfileWeekSODIframe"));
    if (mainSwfState == "large" && !largeViewIframePos.isInit) 
    {
        largeViewIframePos.top = dim.top;
        largeViewIframePos.left = dim.left;
        largeViewIframePos.isInit = 1;
    }

    if (mainSwfState == "normal" && !normalViewIframePos.isInit) 
    {               
        normalViewIframePos.top = dim.top;
        normalViewIframePos.left = dim.left;
        if (normalViewIframePos.top != 0)
        {
            normalViewIframePos.isInit = 1;
        }
    }
}

function setSwfDivFullViewArea()
{
    var width = getBodyWidth();
    var height = getBodyHeight();
    mainSwfState = "full";
    
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    mainSwfDiv.style.width = width + "px";
    mainSwfDiv.style.height = height + "px";

    var ifm = parent.document.getElementById("ProfileWeekSODIframe");
    ifm.style.left = 0 + "px";
    ifm.style.top = 0 + "px";

    changeIfameSize(width, height);
    mainSwfDiv.style.left = 0 + "px";
    mainSwfDiv.style.top = 0 + "px";
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv)
    {
        pdfDiv.style.left = - dimension.left + "px";
        pdfDiv.style.top = - dimension.top + 27 + "px";
    }
}

function resizeToFullViewArea()
{
     saveIframePosition();
     parent.document.body.scrollTop = 0 + "px";
     if (parent.document) parent.document.body.scrollTop = "0px";
     if (isIE)
     {
         parent.document.body.style.overflow ="hidden";
     }

     parent.window.moveTo(0,0);
     parent.window.resizeTo(screen.availWidth,screen.availHeight);
     return true;
}

function getBodyWidth()
{
    return parent.document.body.clientWidth;
}

function getBodyHeight()
{
    return parent.document.body.clientHeight;
}

function getScreenWidth()
{
    return window.screen.width;
}

function getScreenHeight()
{
    return window.screen.height;
}

function setSwfDivLargeViewArea()
{
    if (isIE)
    {
        parent.document.body.style.overflow ="auto";
    }
    var iframe_dim = getDimensions(parent.document.getElementById("ProfileWeekSODIframe"));
    if (mainSwfState == "normal" && !normalViewIframePos.isInit) 
    {
        normalViewIframePos.top = iframe_dim.top;
        normalViewIframePos.left = iframe_dim.left;
        normalViewIframePos.isInit = 1;
    }
    
    mainSwfState = "large";
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    var defaultScreenWidth = 776;
    var swfWidth = mainSwfDiv.style.width;
    mainSwfDiv.style.width = 730 + "px";
    mainSwfDiv.style.height = 433 + "px";
    
    changeIfameSize(730, 433);
    var dimensions = getDimensions(mainSwfDiv);
    if (mainSwfoffsetLeft == null)
    {
        mainSwfDiv.style.left = 0 + "px";
        mainSwfDiv.style.top = 0 + "px";
        var dimensions = getDimensions(mainSwfDiv);
        mainSwfoffsetLeft = dimensions.left;
    }

    if (!largeViewIframePos.isInit) 
    {
        var iframe_left = 0;
        if (nyse_sod_page_content_width && nyse_sod_page_content_width>0) 
        {
            var tmp = (nyse_sod_page_content_width - mainSwfDiv.offsetWidth) / 2 - mainSwfoffsetLeft;
            if (tmp + mainSwfDiv.offsetWidth > nyse_sod_page_content_width) 
            {
                iframe_left = (nyse_sod_page_content_width - mainSwfDiv.offsetWidth) + "px";
            } 
            else
            {
                iframe_left = tmp + "px";
            }
        } 
        else 
        {
            var swfleft = dimensions.left;
            
            var tmpWidth = ((mainSwfDiv.offsetWidth - parseInt(swfWidth)) / 2);
            if (swfleft - tmpWidth <0) 
            {
                iframe_left = -swfleft + "px";
            }
            else
            {
                iframe_left = tmpWidth + "px";
            }
        }
        largeViewIframePos.left = iframe_left;
        
        var swftop = normalViewIframePos.isInit ? normalViewIframePos.top : iframe_dim.top;
        var offsetHeight = (433 - 280) / 2;
        if (swftop > offsetHeight) 
        {
            iframe_top = (swftop - offsetHeight) + "px";
        } 
        else
        {
            iframe_top = "0px";
        }
        largeViewIframePos.top = iframe_top; 
    }
    
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv)
    {
        pdfDiv.style.left = mainSwfDiv.style.left;
        pdfDiv.style.top = (parseInt(mainSwfDiv.style.top) + 27) + "px";
    }
    changeIframePosition(largeViewIframePos.left, largeViewIframePos.top);
}

function setSwfDivNormalViewArea()
{
    if (isIE)
    {
        parent.document.body.style.overflow ="auto";
    }
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    mainSwfDiv.style.width = 376 + "px";
    mainSwfDiv.style.height = 280 + "px";
    
    changeIfameSize(376, 282);
    changeIframePosition(normalViewIframePos.left, normalViewIframePos.top);
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv){
        pdfDiv.style.left = 0;
        pdfDiv.style.top = 27 + "px";
    }
    
    mainSwfState = "normal";
}

function setSwfDivNoBottomNormalViewArea()
{
    if (isIE)
    {
        parent.document.body.style.overflow ="auto";
    }
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    mainSwfDiv.style.width = 376 + "px";
    mainSwfDiv.style.height = 240 + "px";
    mainSwfDiv.style.left = 0;
    mainSwfDiv.style.top = 0;
    changeIfameSize(376, 282);
    changeIframePosition(normalViewIframePos.left, normalViewIframePos.top);
    
    mainSwfState = "noBottomNormal";
    var pdfDiv = document.getElementById(PDF_DIV_ID);
    if (pdfDiv){
        pdfDiv.style.left = 0;
        pdfDiv.style.top = 27 + "px";
    }
}

function addVideoPlayListArea()
{
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    mainSwfDiv.style.width = 376 + 218 + "px";

    changeIfameSize(376 + 210, 282);
}

function removeVideoPlayListArea()
{
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    
    if (mainSwfState == "large") 
    {
        changeIfameSize(730, 433);
    }
    else 
    {
        if (isClosePlayListAction == 1)
        {
            mainSwfDiv.style.width = 367 + "px";
            isClosePlayListAction = 0;
        }
        else
        {
            mainSwfDiv.style.width = 376 + "px";
        }

        changeIfameSize(376, 282);
    }
}

function removeAllVideoPlayListArea()
{
    var mainSwfDiv = document.getElementById(MAIN_SWF_DIV_ID);
    autoClosePlayList();
    isClosePlayListAction = 1;
    if (mainSwfState == "large") 
    {
        mainSwfDiv.style.width = 730 + "px";
        changeIfameSize(730, 433);
    }
    else 
    {
        mainSwfDiv.style.width = 367 + "px";
        changeIfameSize(376, 282);
    }
}

function getParentIframeName()
{
    return parent.document.getElementById("ProfileWeekSODIframe").name;
}

function getPathPrefix()
{
    return PATH_PREFIX;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createDiv(divId, z, x, y, w, h)
{
    var divObj = document.createElement("div");
    divObj.id = divId;

    if (h < 0)
    {
        h = 0;
    }

    with(divObj.style)
    {
        position = "absolute";
        margin = 0;
        left = x + "px";
        top = y + "px";
        height = h + "px";
        width = w + "px";
        zIndex = z;
    }
    
    return divObj;
}

function getSwfById(swfId) 
{
     if (navigator.appName.indexOf("Microsoft") != -1) 
     {
         return window[swfId];
     } 
     else 
     {
         return document[swfId];
     }
}

function swfObject(o, swfurl, w, h, id,mode) 
{
    this.o = o;
    this.swfurl = swfurl;
    this.w = w;
    this.h = h;
    this.mode = 'opaque';
    this.id = "un" + Math.random();
    if (mode) this.mode =  mode;
    if (id) this.id = id;
    var str = '<object {fcy} classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="{w}" height="{h}"><param name="movie" value="{url}"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="{mode}"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="{vars}"><embed {cy} src="{url}" wmode="{mode}" FlashVars="{vars}" menu="false" quality="high" width="{w}" allowFullScreen="true" allowScriptAccess="always" height="{h}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
    this.str = str.replace(/{url}/g, this.swfurl).replace(/{w}/g, this.w).replace(/{h}/g, this.h).replace(/{mode}/g, this.mode);    

    if (navigator.appName.indexOf("Microsoft") == -1) 
    {
        this.str = this.str.replace("{cy}", 'id="{id}"')
        this.str = this.str.replace("{fcy}", '')
    } 
    else 
    {
        this.str = this.str.replace("{cy}", '');
        this.str = this.str.replace("{fcy}", 'id="{id}"')
    }
    
    this.str = this.str.replace(/{id}/g, this.id);
    
    this.addVar = function (varname, argument)
    {
        var tmp = varname + '=' + argument;
        if (this.vars != '') tmp = '&' + tmp;
        this.vars += tmp;
    }
    
    this.createVar = function (data)
    {
        this.vars = data;
    }
    
    this.append = function()
    {
        this.str = this.str.replace(/{vars}/g, this.vars);
        this.o.innerHTML = this.str;
    }
}

////////////////////////////////////////////////////////////////////////////////
var mainLoadStatus = false;
var minLoadStatus = false;

function getLoadUrl()
{
    return url = NYSE_SOD_MAIN_SWF_WAIT_ANIMATION_LOCATION;
}

function changeMainLoadStatus()
{
    if (minLoadStatus)
    {
        allLoadComplete();
    }
    else
    {
        mainLoadStatus = true;
    }
}
 
function changeMinLoadStatus()
{
    if (mainLoadStatus)
    {
        allLoadComplete();
    }
    else
    {
        minLoadStatus = true;
    }
}
 
function allLoadComplete()
{
    getSwfById(MAIN_SWF_ID).allLoadComplete();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetSwfVer(){
    // NS/Opera version >= 3 check for Flash plugin in plugin array
    var flashVer = -1;
    
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
            var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
            var descArray = flashDescription.split(" ");
            var tempArrayMajor = descArray[2].split(".");            
            var versionMajor = tempArrayMajor[0];
            var versionMinor = tempArrayMajor[1];
            var versionRevision = descArray[3];
            if (versionRevision == "") {
                versionRevision = descArray[4];
            }
            if (versionRevision[0] == "d") {
                versionRevision = versionRevision.substring(1);
            } else if (versionRevision[0] == "r") {
                versionRevision = versionRevision.substring(1);
                if (versionRevision.indexOf("d") > 0) {
                    versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
                }
            }
            var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
        }
    }
    // MSN/WebTV 2.6 supports Flash 4
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
    // WebTV 2.5 supports Flash 3
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
    // older WebTV supports Flash 2
    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
    else if ( isIE && isWin && !isOpera ) {
        flashVer = ControlVersion();
    }
        
    return flashVer;
}

function ControlVersion()
{
    var version;
    var axo;
    var e;

    // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

    try {
        // version will be set for 7.X or greater players
        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
        version = axo.GetVariable("$version");
    } catch (e) {
    }

    if (!version)
    {
        try {
            // version will be set for 6.X players only
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
            
            // installed player is some revision of 6.0
            // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
            // so we have to be careful. 
            
            // default to the first public version
            version = "WIN 6,0,21,0";

            // throws if AllowScripAccess does not exist (introduced in 6.0r47)        
            axo.AllowScriptAccess = "always";

            // safe to call for 6.0r47 or greater
            version = axo.GetVariable("$version");

        } catch (e) {
        }
    }

    if (!version)
    {
        try {
            // version will be set for 4.X or 5.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
            version = axo.GetVariable("$version");
        } catch (e) {
        }
    }

    if (!version)
    {
        try {
            // version will be set for 3.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
            version = "WIN 3,0,18,0";
        } catch (e) {
        }
    }

    if (!version)
    {
        try {
            // version will be set for 2.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            version = "WIN 2,0,0,11";
        } catch (e) {
            version = -1;
        }
    }
    
    return version;
}

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
    versionStr = GetSwfVer();
    if (versionStr == -1 ) {
        return false;
    } else if (versionStr != 0) {
        if(isIE && isWin && !isOpera) {
            // Given "WIN 2,0,0,11"
            tempArray         = versionStr.split(" ");     // ["WIN", "2,0,0,11"]
            tempString        = tempArray[1];            // "2,0,0,11"
            versionArray      = tempString.split(",");    // ['2', '0', '0', '11']
        } else {
            versionArray      = versionStr.split(".");
        }
        var versionMajor      = versionArray[0];
        var versionMinor      = versionArray[1];
        var versionRevision   = versionArray[2];

            // is the major.revision >= requested major.revision AND the minor version >= requested minor
        if (versionMajor > parseFloat(reqMajorVer)) {
            return true;
        } else if (versionMajor == parseFloat(reqMajorVer)) {
            if (versionMinor > parseFloat(reqMinorVer))
                return true;
            else if (versionMinor == parseFloat(reqMinorVer)) {
                if (versionRevision >= parseFloat(reqRevision))
                    return true;
            }
        }
        return false;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkInstallReader()
{
    if (navigator.userAgent.indexOf("Firefox") > 0)
    {
        if (findPluginForFireFox("pdf") || findPluginForFireFox("document"))
        {
            installReader("true");
            
        }
        else
        {
            installReader("false");
        }
    } 
    else if (navigator.userAgent.indexOf("MSIE") > 0) 
    {
    
        if (findPluginForIE())
        {
            installReader("true");
        }else
        {
            installReader("false");
        }
    }
}

function findPluginForFireFox(ext) 
{
  var thisExt, findExt;
  for (var n=0; n < navigator.plugins.length; n++) {
      for (var m=0; m < navigator.plugins[n].length; m++) {
          thisExt = navigator.plugins[n][m].description.toLowerCase();
          findExt = thisExt.indexOf(ext);
          if (findExt != -1)
             return(true);
      }
  }
  return(false);
}

function findPluginForIE()
{
    if (!window.ActiveXObject) return false;
        try { if (new ActiveXObject('AcroPDF.PDF')) return true;} 
        catch (e) {}
        try { if (new ActiveXObject('PDF.PdfCtrl')) return true;} 
        catch (e) {}
        return false;
}

function installReader(value)
{
    getSwfById(MAIN_SWF_ID).installReader(value);
}