﻿function ViewPrimaPage(fadeIn)
{
    var browser = BrowserName();

    if (fadeIn == "")
    {
        fadeIn = 100;
    }

    //alert(browser);

    if (browser == "Safari")
    {
        alert("If you are using Safari, please go to the Safari Preferences and select the Security Tab and check the option to Accept cookies: Always.");
    }

    var pe = document.getElementById("ppDiv");
    var se = document.getElementById("shadowDiv");
    var te = document.getElementById("transDiv");

    //Dialog Div
    if (pe != "undefined" && se != "undefined")
    {
        var winW
        var winH;

        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            if (typeof document.documentElement != "undefined" &&
                    typeof document.documentElement.clientWidth != "undefined" &&
                    document.documentElement.clientWidth != 0)
            {
                winW = document.documentElement.clientWidth - 13;
                winH = document.documentElement.scrollTop + (document.documentElement.offsetHeight / 2) - 180;  //Minus one half height of the pe
            }
            // older versions of IE
            else
            {
                winW = document.getElementsByTagName("body")[0].clientWidth - 13;
                winH = document.getElementsByTagName("body")[0].scrollTop + (document.getElementsByTagName("body")[0].offsetHeight / 2) - 180;  //Minus one half height of the pe
            }
        }
        else
        {
            winH = window.pageYOffset + (window.innerHeight / 2) - 185;
            winW = window.innerWidth - 13;
        }

        //Floating window
        pe.style.left = ((winW / 2) - 294) + "px";

        pe.style.top = winH + "px";

        //Shadow window
        se.style.left = ((winW / 2) - 315) + "px";
        se.style.top = (winH - 20) + "px";

        if (navigator.appName.indexOf("Microsoft") == -1)
        {
            pe.style.height = "370px";
        }
    }

    //Transparent Div
    if (te != "undefined")
    {
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            te.style.height = document.body.clientHeight + 30;
        }
        else
        {
            te.style.height = document.documentElement.offsetHeight + 30 + "px";
        }
    }

    window.onscroll = window_position;
    window.onresize = window_position;

    setTimeout("fadeInTransparentOverlay()", fadeIn);
}

function fadeInTransparentOverlay()
{
    var blank1 = changeTransparentOpacity(0);
    document.getElementById("transDiv").style.display = "block";

    //speed for each frame
    var speed = 1;
    var timer = 0;
    var ppShadowDiv = document.getElementById("shadowDiv");
    var ppDiv = document.getElementById("ppDiv");

    ppDiv.style.display = "block";

    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        ppShadowDiv.style.display = "block";
    }

    for (i = 0; i <= 50; i++)
    {
        setTimeout("changeTransparentOpacity(" + i + ")", (timer * speed));
        setTimeout("changeMessageOpacity(" + (i * 2) + ")", (timer * speed));
        timer++;
    }
}

function changeTransparentOpacity(opacity)
{
    if (opacity <= 40)
    {
        var transDiv = document.getElementById("transDiv").style;
        transDiv.opacity = (opacity / 100);
        transDiv.MozOpacity = (opacity / 100);
        transDiv.KhtmlOpacity = (opacity / 100);
        transDiv.filter = "alpha(opacity=" + opacity + ")";
    }
}

function changeMessageOpacity(opacity)
{
    var ppDiv = document.getElementById("ppDiv").style;

    ppDiv.opacity = (opacity / 50);
    ppDiv.MozOpacity = (opacity / 50);
    ppDiv.KhtmlOpacity = (opacity / 50);
    ppDiv.filter = "alpha(opacity=" + opacity + ")";

    ppDiv = document.getElementById("shadowDiv").style;

    ppDiv.opacity = (opacity / 50);
    ppDiv.MozOpacity = (opacity / 50);
    ppDiv.KhtmlOpacity = (opacity / 50);
    ppDiv.filter = "progid:DXImageTransform.Microsoft.Blur(PixelRadius='10', MakeShadow='true', ShadowOpacity='0.50'); alpha(opacity=" + opacity + ")";
}

function hidePPDiv()
{
    var ppDiv = document.getElementById("ppDiv");
    var ppShadowDiv = document.getElementById("shadowDiv");
    var transDiv = document.getElementById("transDiv");

    ppShadowDiv.style.display = "none";
    ppDiv.style.display = "none";
    transDiv.style.display = "none";
}

function window_position()
{
    var i = document.getElementById("ppDiv").offsetHeight / 2;
    var j = document.getElementById("shadowDiv").offsetHeight / 2;
    var k = document.getElementById("ppDiv").offsetWidth / 2;
    var l = document.getElementById("shadowDiv").offsetWidth / 2;

    var centerTop;
    var centerLeft;

    if (typeof window.pageYOffset == "number")
    {
        centerTop = window.pageYOffset + (window.innerHeight / 2);
        centerLeft = window.pageXOffset + (window.innerWidth / 2);
    }
    else if (window.document.documentElement.scrollTop != null)
    {
        centerTop = window.document.documentElement.scrollTop + (window.document.documentElement.clientHeight / 2);
        centerLeft = window.document.documentElement.scrollLeft + (window.document.documentElement.clientWidth / 2);
    }

    document.getElementById("ppDiv").style.top = centerTop - i + "px";
    document.getElementById("shadowDiv").style.top = centerTop - j + "px";

    document.getElementById("ppDiv").style.left = centerLeft - k + "px";
    document.getElementById("shadowDiv").style.left = centerLeft - l + "px";
}

function checkMaxLength(e, el)
{
    return true;
}

function BrowserName()
{
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return "Opera";
    if (agt.indexOf("staroffice") != -1) return "Star Office";
    if (agt.indexOf("webtv") != -1) return "WebTV";
    if (agt.indexOf("beonex") != -1) return "Beonex";
    if (agt.indexOf("chimera") != -1) return "Chimera";
    if (agt.indexOf("netpositive") != -1) return "NetPositive";
    if (agt.indexOf("phoenix") != -1) return "Phoenix";
    if (agt.indexOf("firefox") != -1) return "Firefox";
    if (agt.indexOf("safari") != -1) return "Safari";
    if (agt.indexOf("skipstone") != -1) return "SkipStone";
    if (agt.indexOf("msie") != -1) return "IE";
    if (agt.indexOf("netscape") != -1) return "Netscape";
    if (agt.indexOf("mozilla/5.0") != -1) return "Mozilla";
    if (agt.indexOf("\/") != -1)
    {
        if (agt.substr(0, agt.indexOf("\/")) != "mozilla")
        {
            return navigator.userAgent.substr(0, agt.indexOf("\/"));
        }
        else
        {
            return "Netscape";
        }
    }
    else if (agt.indexOf(" ") != -1)
    {
        return navigator.userAgent.substr(0, agt.indexOf(" "));
    }
    else
    {
        return navigator.userAgent;
    }
}

function SlowFadeIn(fadeIn)
{
    window.onscroll = window_position;
    window.onresize = window_position;

    window.setTimeout("ViewPrimaPage(300);", fadeIn);
}

function IsPracticeOpen()
{
    var data;
    var ifrm = window.frames["fraSvc"];

    if (ifrm != null)
    {
        data = ifrm.document.getElementById("txtData").value;

        if (data == "Open")
            data = true;
        else
            data = false;

        return data;
    }
    else
    {
        return false;
    }
}
