/**
 * Get the query string from the current URL 
 */
function getURLQueryString() {
	return window.top.location.search.substring(1);
}

/**
 * Get the value of the parameter 'parameterName' from the 'queryString'
 *
 * This function is meant to pull off parameters from the URL query string via getURLQueryString()
 */
function getParameter ( queryString, parameterName ) {
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		begin = queryString.indexOf ( parameterName );
		if ( begin != -1 ) {
			begin += parameterName.length;
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
		
			return unescape ( queryString.substring ( begin, end ) );
		}
	return "null";
	}
}

function resetHowToExpanders()
{
	var x = 1;
	for(x = 1; x <= 7; x++)
	{
		var divCss = $j('#detail' + x + 'Div').css('display');
		if (divCss && divCss != 'none')
		{
			eval('hideDetail' + x + "();");
		}
		
		$j('#close' + x).hide();
		$j('#expand' + x).show();
	}
}

function showDetail(indexVal)
{
	resetHowToExpanders();
	$j('#expand' + indexVal).hide();
	$j('#close' + indexVal).show();
	eval("showDetail" + indexVal + "();");
	$j('#openDivIndex').val(indexVal);
}

function showLinks(hintIndex)
{
	$j('#hintForm\\:hintIcon_' + hintIndex).hide();
	$j('#hintForm\\:hintIcon2_' + hintIndex).show();
	$j('#hintForm\\:hintIconLink_' + hintIndex).show();
}

function hideLinks(hintIndex)
{
	$j('#hintForm\\:hintIcon_' + hintIndex).show();
	$j('#hintForm\\:hintIcon2_' + hintIndex).hide();
	$j('#hintForm\\:hintIconLink_' + hintIndex).hide();
}

function updateHintButtons(currentHintIndex)
{
	var maxHintsTaken = parseInt($j('#hintForm\\:maxHintsTaken').val());
	
	// reset all button images
	for(var hintIndex = 1; hintIndex <=4;hintIndex++)
	{
		if (hintIndex <= maxHintsTaken)
		{
			$j('#hintForm\\:hintIcon_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'c.gif');
			$j('#hintForm\\:hintIcon2_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'c.gif');
			$j('#hintForm\\:hintIconLink_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'c.gif');
			
			showLinks(hintIndex);
		}
		else
		{
			$j('#hintForm\\:hintIcon_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'a.gif');
			$j('#hintForm\\:hintIcon2_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'a.gif');
			$j('#hintForm\\:hintIconLink_' + hintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + hintIndex + 'a.gif');
			
			hideLinks(hintIndex);
		}
	}
	
	// enable the link for the "next" link
	if (maxHintsTaken != 4)
	{
		showLinks(maxHintsTaken + 1);
	}
	
	if (currentHintIndex != -1)
	{
		$j('#hintForm\\:hintIcon_' + currentHintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + currentHintIndex + 'b.gif');
		$j('#hintForm\\:hintIcon2_' + currentHintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + currentHintIndex + 'b.gif');
		$j('#hintForm\\:hintIconLink_' + currentHintIndex).attr('src', contextPath + '/images/buttons/bttn_hint_' + currentHintIndex + 'b.gif');
	}	
}

function submitToHiddenSubmitter(index, submitterId)
{
	//var encodedSubmitterId = '#courseForm\\:courseGroupTable\\:' + index + '\\:' + submitterId;
	
	
	//alert(submitterId);
	$j('#courseForm\\:courseGroupTable\\:' + index + '\\:' + submitterId).click();
	//$j('#courseForm\\:courseGroupTable\\:0\\:' + submitterId).click();
}

// These functions are in common.js as they need to be available througout the ru2 app.
function showWebEqApplet()
{
	var isWebEq;
	isWebEq = $j('#questionForm\\:editorTypeRadioBtns\\:1').attr('checked');
	if (isWebEq)
	{
		$j('#webEQPractice').show();
	}
}

function hideWebEqApplet()
{
	isWebEq = $j('#questionForm\\:editorTypeRadioBtns\\:1').attr('checked');
	if (isWebEq)
	{
		$j('#webEQPractice').hide();
	}
}
