var videoWin = null;
var win = null;
var exWin = null;
var qWin = null;
var helpWin = null;

function placeAnnotation(p)
{}

function placeGlobalAnnotation(p)
{}

function save_and_link(p)
{
	parent.frameNavigator.controlframe.savePrev(location.href);
	FMLlink_event(p);
}

function loadInfo(name)
{
	location.href = "til_"+name+".html";
}

function linkEvent()
{
	if ( self.parent != top )
	{
		// waiting for frames	
		while(parent.frames["leftFrame"] == null);
		while(parent.leftFrame.frames["controlframe"] == null);
		parent.leftFrame.controlframe.linkEvent(FMLmenuName,FMLname);
	}
}

function openExercise(href,width,height)
{
	var features = "width="+width+",height="+height+",screenX=200,screenY=200,top=200,left=200"; 
	exWin = window.open(href,"win",features);
	exWin.focus();
}

function openQuest(name,w,h)
{
	var features = "width="+w+",height="+h+",screenX=200,screenY=200,top=200,left=200,scrollbars"; 
	qWin = window.open("kysymykset/"+name+".html","quest",features);
}

function openVideoWindow(pageName) 
{ 	
	
}

function checkWindows()
{
	if ((videoWin != null) && !videoWin.closed)
	{
		videoWin.close();
		videoWin = null;
	}
	else if ((win != null) && !win.closed)
	{
		win.close();
		win = null;
	}
	else if ((qWin != null) && !qWin.closed)
	{
		qWin.close();
		qWin = null;		
	}
	else if ((exWin != null) && !exWin.closed)
	{
		exWin.close();
		exWin = null;		
	}
	if ((helpWin != null) && !helpWin.closed)
	{
		helpWin.close();
		helpWin = null;		
	}
}

function closeWindow()
{
	if ((win != null) && !win.closed)
	{
		win.close();
		win = null;
	}
}

function openStatWindow(href,width,height)
{
	if ((videoWin == null) || wideoWin.closed)
	{
		var URL = "tilastot/til_"+href+".html";
		var features = "width="+width+",height="+height+",screenX=200,screenY=200,top=200,left=200"; 
		win = window.open(URL,"win",features);
	}
}

function loadMenu(name) {
	if ( this != top && this.name != "frameContent" ) {
		var pageName = name.substring( name.lastIndexOf('/') + 1 );
		var menuName =( 'menu/menu_bl' + pageName.substring( pageName.indexOf( '_' ) ) );
		parent.leftFrame.mapframe.location.href = menuName;
	}
}

function loadPrev()
{
parent.frameNavigator.controlframe.loadPrev();
}	

function openHelp(name)
{
	var features = "width=600,height=400,screenX=200,screenY=200,top=200,left=200,scrollbars=yes";
	//var URL = "pelit/helpit/"+name+".html";
	var URL = "../../pelit/helpit/"+name+".html";
	helpWin = window.open(URL,'help',features);
	helpWin.focus();
}

function checkHelp()
{
	if ((helpWin != null) && !helpWin.closed)
	{
		helpWin.close();
		helpWin = null;
	}
}

function openInfoWindow(href,width,height)
{
	if ((videoWin == null) || wideoWin.closed)
	{
		var URL = "info/info_"+href+".html";
		var features = "width="+width+",height="+height+",screenX=200,screenY=200,top=200,left=200,scrollbars=yes"; 
		win = window.open(URL,"win",features);
	}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function showResult(correct,answer)
{
	if (answer==correct)
	{
		MM_showHideLayers('kysymys','','hide','vastausOikein','','show')
	}
	else
	{
		MM_showHideLayers('kysymys','','hide','vastausVaarin','','show')
	}
}


function displayText( message ) {
  this.document.write( message );
}

