﻿var qs = new Querystring();
var ie = false, te = false, java = false, flash = false;
var flyToId = qs.get("f", "");

function CheckIDParameter()
{
    if (flyToId != "")
    {
        GoId(flyToId);
        return true;
    }
    return false;
}

function SwapImage(img_name, img_src)
{
    document.getElementById(img_name).src=img_src;
}

function HideContent(id)
{
    document.getElementById(id).style.display="none";
}

function ShowContent(id)
{
    document.getElementById(id).style.display="block";
}

function GoToUrl(url)
{
    window.location.href=url;
}

function DisplayRequirements()
{
    HideContent("panelnews")
    ShowContent("panelreq")
    GoToUrl('#requirements');
    setTimeout("Verify();", 100);
}

function DisplayNews()
{
    HideContent("panelreq")
    ShowContent("panelnews")
}

function OnLoad()
{
    DisplayNews();
    CheckIDParameter();
}

function Ready()
{
    if (ie && te && flash)
    {
        return true;
    }
    
    return false;
}

var fullscreen = false;

function Go()
{
    show("initialize");
    setTimeout("do_Go()", 100);
}

function do_Go()
{
    if (validate() >= 0)
    {
        if (!CheckIDParameter())
        {
            if (fullscreen)
            {
                window.open('http://www.3dlisboa.com/viewer/viewer.htm?l=pt', '_blank', 'fullscreen=yes');
            }
            else
            {
                GoToUrl("http://www.3dlisboa.com/viewer/viewer.htm?l=pt");
            }
        }
    }
     
}

function Fullscreen()
{
    if (fullscreen)
    {
        fullscreen = false;
        document.getElementById("fullscreenbtn").src = "images/btnfullscreen_off.jpg";        
    }
    else
    {
        document.getElementById("fullscreenbtn").src = "images/btnfullscreen_on.jpg";
        fullscreen = true;
    }
}

function GoId(id)
{
    show("initialize");
    setTimeout("do_GoId(\"" + id + "\")", 100);
}

function do_GoId(id)
{
    if (validate() >= 0)
    {
        if (fullscreen)
        {
            window.open("http://www.3dlisboa.com/viewer/viewer.htm?l=pt&f=" + id, "_blank", "fullscreen=yes");
        }
        else
        {
            GoToUrl("http://www.3dlisboa.com/viewer/viewer.htm?l=pt&f=" + id);
        }
    }
}
function Verify()
{
    ie = EvalBrowser() >= 0;
    te = EvalTerraExplorer() >= 0;
    flash = EvalFlash() >= 0;
    java = EvalJava() >= 0;
    
    if (te)
    {
        document.getElementById("btndownload_a").src = "images/b_installed_pt.jpg";
        document.getElementById("btndownload_a").onmouseover = "";
        document.getElementById("btndownload_a").onmouseout = "";
        document.getElementById("btndownload_a").onclick = "";
    }
    
    if (flash)
    {
        document.getElementById("btndownload_b").src = "images/b_installed_pt.jpg";
        document.getElementById("btndownload_b").onmouseover = "";
        document.getElementById("btndownload_b").onmouseout = "";
        document.getElementById("btndownload_b").onclick = "";
    }
    
    if (ie)
    {
        document.getElementById("btndownload_c").src = "images/b_installed_pt.jpg";
        document.getElementById("btndownload_c").onmouseover = "";
        document.getElementById("btndownload_c").onmouseout = "";
        document.getElementById("btndownload_c").onclick = "";
    }
    
    if (java)
    {
        document.getElementById("btndownload_d").src = "images/b_installed_pt.jpg";
        document.getElementById("btndownload_d").onmouseover = "";
        document.getElementById("btndownload_d").onmouseout = "";
        document.getElementById("btndownload_d").onclick = "";
    }
    
    if (Ready())
    {
        document.getElementById("reqtextidle").style.display = "none";
        document.getElementById("reqtextwarning").style.display = "none";
        document.getElementById("reqtextok").style.display = "inline";
    }
    else
    {
        document.getElementById("reqtextidle").style.display = "none";
        document.getElementById("reqtextwarning").style.display = "inline";
        document.getElementById("reqtextok").style.display = "none";
    }
}

// hack for satisfactory funtioning in IE. Not required for Firefox. 
function clearObjs(obj)
{
    var theObj = eval(obj);
    theObj.style.display = "none";
    for (var prop in theObj)
	{
	    if (typeof(theObj[prop]) == "function")
	    {
		    theObj[prop]=null
	    }
	}	
  }

// hack for satisfactory funtioning in IE. Not required for Firefox.
function cleanup() 
{
    __flash_unloadHandler = function()
    {
	externalProbSet = true;
        if (externalProbSet) {return};
	clearObjs(explorer);
	clearObjs(flashcontent);
	if (__flash_savedUnloadHandler != null)
	{
	    __flash_savedUnloadHandler();
	}
    }

    if (window.onunload != __flash_unloadHandler)
    { 
	__flash_savedUnloadHandler = window.onunload;
	window.onunload = __flash_unloadHandler;
    }
}

// hack for satisfactory funtioning in IE. Not required for Firefox.
window.onbeforeunload=cleanup;