// Globals

var GlobalSplashWin;
var GlobalLastFrame = 0;


function detectFirefoxPlugin(pluginName)
{
    for (var pluginArrayCounter = 0; pluginArrayCounter < navigator.plugins.length; pluginArrayCounter++)
    {
        if (navigator.plugins[pluginArrayCounter].name.indexOf(pluginName) > 0)
        {
            return true;
        }
    }

    return false;
}

function detectPlugin(ClassID)
{
	var AXObj = null;
	try 
	{
		AXObj = new ActiveXObject(ClassID);
	}
	catch (e){}
	if (AXObj)
		return true;
	return false;
}

function CheckForFlash()
{
    var flashinstalled = false;
	/////////////////////////////////////////////////////////////////
	// Macromedia Flash Player
	/////////////////////////////////////////////////////////////////
	testItem = new Object();
	testItem.id = "FlashPlayer";
	testItem.name = "Flash Player";
	testItem.classId = "ShockwaveFlash.ShockwaveFlash.1";

	if (detectPlugin(testItem.classId))
	{
		flashinstalled = true;
    }
    else if (detectFirefoxPlugin('Flash'))
    {
		flashinstalled = true;
    }

    return flashinstalled;
}

function SubmitScore(LOC)
{
	if (parseInt(LOC)==1)
	{
		if (frames['ContentFrame'])
			var Frame = frames['ContentFrame'];
		else
			var Frame = parent.frames['ContentFrame'];
		for(var i=0;i<Frame.document.all.length;i++)	//Loop igjennom alle elementene i dokumentet
		{
			var ObjName = Frame.document.all(i).name;
			if(ObjName)			//Hent ut navnet på elementet
			{
				if(ObjName.substring(0,6) == 'Submit') 	//Submit + CourseElementId er en hidden box som lages i top.xsl. Denne inneholder statusen til CourseElementet
				{
					var CourseElementId = ObjName.substring(7,ObjName.length);
					Frame.document.all(i).focus();
					Frame.document.all(i).value=1;
				}
			}
		}	
	}
}

function DelayGoto10(Id, ParentId, LOC)
{
	if (parent.document.getElementById("NewScore").value == 0)
		goto10(Id)
	else if (parent.document.getElementById("NewScore").value == 9)
		r = setTimeout('NavigatePage('+Id+', '+ParentId+', '+LOC+')', 200);
	else
		r = setTimeout('goto10('+Id+')', 200);
}

function NavigatePage(Id, ParentId, LOC)
{
	if (parent.document.getElementById("NewScore"))
	    parent.document.getElementById("NewScore").value = 1;
	else
	    document.getElementById("NewScore").value = 1;
	if (parent.frames['MenuFrame'])
		parent.frames['MenuFrame'].toggleFolder(ParentId,1);
	else if (frames['MenuFrame'])
		frames['MenuFrame'].toggleFolder(ParentId,1);
	
	if (parseInt(LOC)==1)
	{
		r = setTimeout('SubmitScore('+LOC+')', 300);
		r = setTimeout('DelayGoto10('+Id+', '+ParentId+', '+LOC+')', 900);
	}
	else
	{
		try
		{
			parent.goto10(Id);
		} catch (e) 
		{
			goto10(Id);
		}
	}
}
  function goto10(courseElementId)
  {
    LoadContent(courseElementId, 1);
  }
function removeHTML(LabelText)
{
}

///
/// LoadContent loads a page into the content frame. It is done in 2 steps because of a IE bug.
///
function LoadContent(CourseElementId)
{
    if(isNaN(CourseElementId) == false)
    {
        if (frames['ContentFrame'])
    	    frames['ContentFrame'].location.href = "./" + CourseElementId + ".html";
    	else
    	    parent.frames['ContentFrame'].location.href = "./" + CourseElementId + ".html";
	    CloseMenu();
	    ShowContent();

		var MenuFrame = (frames['MenuFrame'] != null) ? frames['MenuFrame'] : parent.frames['MenuFrame'];


	    if(MenuFrame != null)
	    {
		    if (document.getElementById('MenuLoaded'))
		    {
			    if(document.getElementById('MenuLoaded').value == "1")
			    {
				    MenuFrame.toggleFolder(CourseElementId,1);
				    
				}
				
		    }
		    else
		    {
			    parent.MenuFrame.toggleFolder(CourseElementId,1);
		    }
	    }		
	    else
	    {
		    alert("General.js: Menuframe does not exist.");
	    }
    }
    else
    {
	    alert("The courseelementid " + CourseElementId + " is not valid");
    }
}

//---------------------------------------------------------------
// Åpner ContentFramen
//---------------------------------------------------------------
function ShowContent()
{
	if (document.all.ContentFrame)
	{
		document.all.ContentFrame.height = 800;
		document.all.ContentFrame.width = 800;
	}
	else if (parent.document.all.ContentFrame)
	{
		
		parent.document.all.ContentFrame.height = 800;
		parent.document.all.ContentFrame.width = 800;
	}
}
//---------------------------------------------------------------
// Lukker ContentFramen
//---------------------------------------------------------------
function CloseContent()
{
	if(document.all.ContentFrame)
	{
		document.all.ContentFrame.height = 1;
		document.all.ContentFrame.width = 1;
	}
}

//---------------------------------------------------------------
// Åpner MenyFramen
//---------------------------------------------------------------
function OpenMenu()
{
	if(document.all.MenuFrame)
	{
		if (document.all.MenuFrame.height > 1) 	//The menu is open, close it
		{
			CloseMenu();
			ShowContent();
		}
		else 									//The menu is closed, open it
		{
			//Show the menu
			document.all.MenuFrame.height = "450";
			document.all.MenuFrame.width = "780";
			document.all.MenuFrame.style.left = 0;
			if(document.all.ChapterNameFrameCorner)
				document.all.ChapterNameFrameCorner.src = DesignTemplate + "ChapterNameFrameCorner_up.gif";
			
			//Hide the other frames
			CloseContent();
		}
	}
}

function CloseMenu()
{
	if(document.all.MenuFrame)
	{
		if(parseInt(document.all.MenuFrame.height) > 1)
		{
			document.all.MenuFrame.height = "1";
			document.all.MenuFrame.width = "1";
			if(document.all.ChapterNameFrameCorner)
				document.all.ChapterNameFrameCorner.src = DesignTemplate + "ChapterNameFrameCorner.gif";			
			
			//ShowContent();
		}
	}
}
//********* TIMESTAMP ************************************************************************************
function getTimeStamp()
{
	theDate = new Date();
	retVal = theDate.getHours() * 60 * 60 + theDate.getMinutes() * 60 + theDate.getSeconds();
	return retVal;

}
//********* OPEN WINDOW **********************************************************************************
function goPopUp(pfilename, title,pwidth,pheight, top, left) 
{

    var splashWin = window.open(pfilename, title ,"toolbar=0,location=0,scrollbars=1,width=" + pwidth + " ,height=" + pheight +",resizable=1,top=" +top + ",left=" + left); 
    splashWin.focus(); 

}
