// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

function PopUpCriteriaBrowser( session, ttID, topic, level, criterion ) 
{
	url = 'displayCriteria.asp'
		+ '?' + 'session'   + '=' + session
		+ '&' + 'tt'		+ '=' + ttID 
		+ '&' + 'topic'     + '=' + topic 
		+ '&' + 'level'     + '=' + level
		+ '&' + 'criterion' + '=' + criterion;

	window.open( url, 'Hello', 'scrollbars=yes,resizable=yes,top=10,left=10,width=800,height=500' );
}

// ---------------------------------------------------------------------

function rollOver(p_obj) {
	p_obj.src = p_obj.src.replace(/_up/i, '_hover');
}

// ---------------------------------------------------------------------

function rollOut (p_obj) {
	p_obj.src = p_obj.src.replace(/_hover/i, '_up');
}

// ---------------------------------------------------------------------

// Global to make sure the tip box only shown once per screen visit.
var m_tip_shown = false;

function homepageCheckboxAction () 
{
	var e = document.getElementById('countLabel');
	var b = document.getElementById('divStartButton');
	var h_count;
	var h_str;

	// Some screens won't have countLabel defined
	if ( !e ) return;

	// Initialise
	h_count=0;

	// Count how many checkboxes have been checked
	for(var i=0; i<document.criteriaselect.elements.length; i++)
	{
	   if (document.criteriaselect.elements[i].type == 'checkbox' && document.criteriaselect.elements[i].name != 'longkeys' && document.criteriaselect.elements[i].checked) h_count++;
	}

	// What label should be displayed?
	if ( h_count == 0 )
		h_str = 'Add one or <br/>more keys to your test';
	else if ( h_count == 1 )
		h_str = 'There is<br/> ' + h_count + ' key<br/> in your test';
	else
		h_str = 'There are<br/> ' + h_count + ' keys<br/> in your test';

	// Write the text to the page
	e.innerHTML  = h_str;

	// Display the tip div for the number of keys in a test
	if (h_count == 4)
	{
		if (!m_tip_shown)
		{
			var h_tipdiv = document.getElementById('divTipsMini'); 
			var h_left = getImgLeft('imgMsgAnchor'); 
			var h_top  = getImgTop('imgMsgAnchor'); 
			if(h_tipdiv) 
			{ 
			  h_tipdiv.style.top = h_top+35; 
			  h_tipdiv.style.left = h_left+130;
			  h_tipdiv.style.visibility = 'visible'; 
			}
			// We've shown the tip so not again.
			m_tip_shown = true;
		}
	}


	// If we have some keys selected then show the button otherwise hide it
	if ( h_count > 0 )
		b.style.visibility='visible';
	else
		b.style.visibility='hidden'; 

}

// ---------------------------------------------------------------------


function clearHelpMenu()
{
	var h_helpdiv = document.getElementById("divHelpOptions");

	if(h_helpdiv)
	{
		h_helpdiv.style.visibility = "hidden";
	}
}

// ---------------------------------------------------------------------

function rollOverHelp(p_obj) {
	
	p_obj.src = p_obj.src.replace(/_up/i, '_hover');

	var h_top = getImgTop( p_obj.id );
	var h_left = getImgLeft( p_obj.id );

	var h_helpdiv = document.getElementById("divHelpOptions");

	if(h_helpdiv)
	{
		h_helpdiv.style.top = h_top + 26;
//		h_helpdiv.style.left = h_left - 120;
		h_helpdiv.style.left = h_left - 110;
		h_helpdiv.style.visibility = "visible";
		hideTutorialMovie();
	}


}

// ---------------------------------------------------------------------

function rollOutHelp (p_obj) {
	p_obj.src = p_obj.src.replace(/_hover/i, '_up');

	var h_helpdiv = document.getElementById("divHelpOptions");

	if(h_helpdiv)
	{
		h_helpdiv.style.visibility = "hidden";
	}

	showTutorialMovie();

}

// ---------------------------------------------------------------------

function rollOverHelpDiv(p_obj) {
	p_obj.style.visibility = "visible";

	var h_helpimg = document.getElementById("imgHelpdropdown");

	if(h_helpimg)
	{
		h_helpimg.src = h_helpimg.src.replace(/_up/i, '_hover');
	}

	hideTutorialMovie();
}

// ---------------------------------------------------------------------

function rollOutHelpDiv (p_obj) {
	p_obj.style.visibility = "hidden";

	var h_helpimg = document.getElementById("imgHelpdropdown");

	if(h_helpimg)
	{
		h_helpimg.src = h_helpimg.src.replace(/_hover/i, '_up');
	}

	showTutorialMovie();

}

// ---------------------------------------------------------------------

function getImgLeft( id )
{
	if ( document.getElementById || document.all )
	{
		return getParentLeft( document.images[id] );
	}
	else if ( document.layers )
	{
		return document.images[id].x;
	}

	// Shouldn't get here!
	return 0;
}

// ---------------------------------------------------------------------

function getParentLeft( obj )
{
	if ( obj.offsetParent )
	{
		return obj.offsetLeft + getParentLeft( obj.offsetParent );
	}
	else
	{
	if ( obj.offsetLeft ) 
		return obj.offsetLeft;
	else 
		return 0;
	}

	// Shouldn't get here!
	return 0;
}

// ---------------------------------------------------------------------


function getImgTop( id )
{
	if ( document.getElementById || document.all )
	{
		return getParentTop( document.images[id] );
	}
	else if ( document.layers )
	{
		return document.images[id].y;
	}

	// Shouldn't get here!
	return 0;

}

// ---------------------------------------------------------------------

function getParentTop( obj )
{
	if ( obj.offsetParent )
	{
		return obj.offsetTop + getParentTop( obj.offsetParent );
	}
	else
	{
	if ( obj.offsetTop ) 
		return obj.offsetTop;
	else 
		return 0;
	}

	// Shouldn't get here!
	return 0;

}

// ---------------------------------------------------------------------

function hideTutorialMovie()
{
	var h_div = document.getElementById("divTutorialMovie");

	if(h_div)
	{
		h_div.style.visibility = "hidden";
	}

	showTutorialWatermark()

}

// ---------------------------------------------------------------------

function showTutorialMovie()
{
	var h_div = document.getElementById("divTutorialMovie");

	hideTutorialWatermark()

	if(h_div)
	{
		h_div.style.visibility = "visible";
	}
}

// ---------------------------------------------------------------------

function hideTutorialWatermark()
{
	var h_div = document.getElementById("divTutorialWatermark");

	if(h_div)
	{
		h_div.style.display = "none";
	}

}

// ---------------------------------------------------------------------

function showTutorialWatermark()
{
	var h_div = document.getElementById("divTutorialWatermark");

	if(h_div)
	{
		h_div.style.display = "block";
	}
}

// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

function OpenPopup(p_url, p_params, p_name)

{

	eval("kfm"+p_name+" = window.open('"+p_url+"','"+p_name+"','"+p_params+"')");



	if (eval("kfm"+p_name) && window.focus) eval("kfm"+p_name).focus();

}

// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

function hide_selects () 
{
	var selects, i; 

	selects = document.getElementsByTagName('select'); 
	for(i=0;i<selects.length;i++) 
	{
		selects[i].style.visibility='hidden'; 
	}
}

// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

function show_selects () 
{
	var selects, i; 

	selects = document.getElementsByTagName('select'); 
	for(i=0;i<selects.length;i++) 
	{
		selects[i].style.visibility='visible'; 
	}
}

// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

