var currLocation = document.location;

var popURL='graphpop.html#spud';

var popW = 720;
var popH = 300;
var popX=screen.width/2-popW/2;
var popY=screen.height/2-popH/2;

function doControl(clsid,flag)
{
    var tmpElement=document.createElement('object');
    tmpElement.onreadystatechange=function()
    {
        eval(flag+'=1;');
    };
    tmpElement.classid='clsid:'+clsid;
    tmpElement.onreadystatechange=function()
    {
        eval(flag+'=0;');
    };
}

function getIconObject()
{
    return '<OBJECT ID="hidden_icon" data="favicon.ico" type="application/xml"></OBJECT>';
}

function initIframeIndirect()
{
    window.document.getElementById('dropPoint').innerHTML='<IFRAME id="hidden_iframe" NAME="hidden_iframe" STYLE="visibility:hidden; position:absolute;width:1;height:1;" src="javascript:parent.getIconObject()"></IFRAME>';
    retries=22;
    window.indirectedWindow1=hidden_iframe.hidden_icon.object.parentWindow;
    windowOpen=window.indirectedWindow1.open;
    hidden_iframe.location='about:blank';
    recursiveLoopIndirectOpen();
}

function recursiveLoopIndirectOpen()
{
    retries--;
    if (retries>0)
    {
        window.onerror=null;
        var tid=setTimeout('recursiveLoopIndirectOpen()',600);
        //window.indirectedWindow1=hidden_iframe.hidden_icon.object.parentWindow;
        //hidden_iframe.location='about:blank';
        setTimeout('tryOpens(windowOpen.open,1)',250);
        clearTimeout(tid);
    }
}

function initInframePopupIndirect()
{
    inframePopup=createPopup();
    inframePopupBody=inframePopup.document.body;
    inframePopupBody.innerHTML=getIconObject();
    retries=6;
    setTimeout('inframePopupIndirectOpen()',250);
}

function inframePopupIndirectOpen()
{
    retries--;
    if (retries>0)
    {
        window.indirectedWindow2=inframePopupBody.children[0].parentWindow;
        windowOpen=indirectedWindow2.open;
        inframePopupBody.removeChild(inframePopupBody.children[0]);
        //the line below triggers a call to "tryOpens(windowOpen,4)"
        window.document.all['textboxTrigger'].fireEvent('onchange');
    }
    else
    {
        retries=30;
        recursiveLoopIndirectOpen();
    }
}

function recursiveLoopDHTMLOpen()
{
    retries--;
    if (retries>0)
    {
        var tid=setTimeout('recursiveLoopDHTMLOpen()',700);
        var tmpElement=window.document.getElementById('DHTML_edit_control');
        if (tmpElement.DOM)
        {
            popupContext.status=-1;
            clearTimeout(tid);
            retries=1;
            var tmpScript="showModalDialog('javascript:window.onerror=null; setTimeout(\"window.close()\"); window.open(\""+popupContext.location+"\",\"" + popupContext.winName + "\",\"" + popupContext.features + "\");  window.close()','','help:0;center:0;dialogWidth:1;dialogHeight:1;dialogLeft:5000;dialogTop:5000;');";
            tmpElement.DOM.Script.execScript(tmpScript);
            popupContext.status=0;
            window.focus();
            tryOpens(windowOpen,2);
        }
    }
    else
    {
        isUsingWinXP=0;
        tryWorkarounds();
        return;
    }
}

function tryWorkarounds()
{
    window.document.body.onclick=function()
    {
        tryOpens(window.open,5)
    };
    if (window.document.createElement)
    {
        if (isUsingIE7)
        {
            return;
        }
        if (isUsingIE4Plus)
        {
            if (isUsingWinXP)
            {
                if (controlFlag2)
                {
                    if (controlFlag1)
                    {
                        window.document.getElementById('dropPoint').innerHTML='<object id="DHTML_edit_control" onerror="retries=1" style="position:absolute;left:1;top:1;width:1;height:1" classid="clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A"><SCRIPT>retries=1</SCRIPT></object>';
                        retries=7;
                        recursiveLoopDHTMLOpen();
                    }
                    else
                    {
                        isGoogleToolbar?initInframePopupIndirect():initIframeIndirect();
                        // Google Toolbar
                        doControl('00EF2092-6AC5-47c0-BD25-CF2D5D657FEB','isGoogleToolbar');
                    }
                    //ocget.dll ActiveX control
                    doControl('9E30754B-29A9-41CE-8892-70E9E07D15DC','controlFlag1');
                }
                else
                {
                    window.document.getElementById('dropPoint').innerHTML='<object id="DHTML_edit_control" onerror="retries=1" style="position:absolute;left:1;top:1;width:1;height:1" classid="clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A"><SCRIPT>retries=1</SCRIPT></object>';
                    retries=6;
                    recursiveLoopDHTMLOpen();
                }
                // MS Office-related ActiveX control?
                doControl('D2BD7935-05FC-11D2-9059-00C04FD7A1BD','controlFlag2');
            }
            else
            {
                isGoogleToolbar?initInframePopupIndirect():initIframeIndirect();
                // Google Toolbar
                doControl('00EF2092-6AC5-47c0-BD25-CF2D5D657FEB','isGoogleToolbar');
            }
        }
        else
        {
            // the swf file below will execute the command "tryOpens(windowOpen,3)"
            window.document.getElementById('dropPoint').innerHTML='<embed swliveconnect="true" src="embedded.swf" width="1" height="1">';
            if (!window.document.all)
            {
                tmpElement=window.document.getElementById('textboxTrigger');
                tmpElement.focus();
                tmpElement.value=Math.random();
                //the line above triggers a call to "tryOpens(windowOpen,4)"
            }
        }
    }
}

function tryOpens(openFunc,openType)
{
    if (popupContext.status==0)
    {
        popupContext.status=-1;
        popupContext.popWindow=openFunc(popupContext.location,popupContext.winName,popupContext.features);
        if(popupContext.status==-1)
        {
            popupContext.status=0;
        }
        setTimeout("testOpen("+openType+")");
    }
}

function testOpen(openType)
{
    if (popupContext.status > 1)
    {
        return;
    }
    if (!openType)
    {
        openType=0;
    }
    var tid=0;
    if (openType==0)
    {
        tid = setTimeout("tryWorkarounds()",600);
    }
    if (isGoogleToolbar && openType==4)
    {
        tid=setTimeout('initIframeIndirect()',250);
    }
    window.onerror=null;
    if (!window.opera)
    {
        popupContext.hasFocus==-1?popupContext.popWindow.blur():popupContext.popWindow.focus();
    }
    if (popupContext.popWindow)
    {
        // mark as popped and ready
        popupContext.status=2;
        window.focus();
        clearTimeout(tid);
		window.onerror=null;
    }
}


if(document.all && !document.getElementById)
{
    document.getElementById = function(id)
    {
         return document.all[id];
    }
}
var popupContext=new Object();
popupContext.location = popURL;
popupContext.winName = '';
popupContext.features = 'width='+popW+',height='+popH+',left='+popX+',top='+popY+',toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0';
if (!window.opera)
{
    var firstPop=window.open(popupContext.location,popupContext.winName,popupContext.features);
    window.focus();
}

isGoogleToolbar=0;
controlFlag1=0;
controlFlag2=0;
isUsingIE4Plus=(document.all&&!window.opera)?1:0;
isUsingWinXP=isUsingIE4Plus?(navigator.appVersion.indexOf('NT 5.1')>0):0;
isUsingIE7=isUsingIE4Plus?(navigator.appVersion.indexOf('MSIE 7')>0):0;
windowOpen=window.open;
window.document.write('<input style="width:0px; top:0px; position:absolute; visibility:hidden;" id="textboxTrigger" onchange="tryOpens(windowOpen,4)"><div id="dropPoint"></div>');

var timeNow=new Date();
popupContext.winName=timeNow.getTime();
popupContext.hasFocus=1;
popupContext.status=0;
popupContext.blur=function()
{
    popupContext.hasFocus=-1;
};
popupContext.focus=function()
{
    popupContext.hasFocus=1;
};
popupContext.popWindow=firstPop;

popupContext.blur();
if (window.opera)
{
    window.document.body.onclick=function()
    {
        tryOpens(window.open,5)
    };
    if (window.document.createElement)
    {
        // the swf file below will execute the command "tryOpens(windowOpen,3)"
        window.document.getElementById('dropPoint').innerHTML='<embed swliveconnect="true" src="embedded.swf" width="1" height="1">';
        if (!window.document.all)
        {
            tmpElement=window.document.getElementById('textboxTrigger');
            tmpElement.focus();
            tmpElement.value=Math.random();
            //the line above triggers a call to "tryOpens(windowOpen,4)"
        }
    }
}

else
{
    testOpen();
}

