// Add a function called trim as a method of the prototype 
// object of the String constructor.
var mode
var prefix
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


function showResponse(txt)
{
	var leftTimeObj = $("leftTime");
	//logobj.style.color="#00ff00";
	var responsetext = txt.trim()
	if (responsetext=="Turn in process")
	{
		//new ajax(prefix+"checkturn.asp?"+randomString(), {postBody: "", update: null, onComplete: showResponse});
		xhrTimeLeft.onSuccess = showResponse;
		xhrTimeLeft.url= "/aviaquiz/checkturn.asp";
		xhrTimeLeft.send("rnd="+(new Date()).valueOf());
	}
	else
	{
		if (responsetext=="Turn changed")
		{
			if (mode=="reload") alert(responsetext)
		}
	}
}

function showLeft(txt)
{
	var leftTimeObj = $("leftTime");
	//logobj.style.color="#00ff00";
	var responsetext = txt.trim()
	if (responsetext=="")
	{
		if (mode!="reload")
			if  ($("b_submitAnswer")) $("b_submitAnswer").disabled=true;
		else
			if ($("submitbttn")) $("submitbttn").disabled=true;
			
		leftTimeObj.set('html',"<a style='color:red;' onclick='document.location.reload();return false' href='#'>Turn expired</a>");
		xhrTimeLeft.url= "/aviaquiz/checkturn.asp";
		xhrTimeLeft.onSuccess = showResponse;
		xhrTimeLeft.send("rnd="+(new Date()).valueOf());
	}
	else
	{
		leftTimeObj.set('html',"&nbsp;"+txt+"&nbsp;");
		pause.delay(10000);
		//window.setTimeout("pause()",500);
	}
}

var	xhrTimeLeft = new Request({url: "/aviaquiz/timeleft.asp",onSuccess: showLeft});
function timeLeft()
{
	if (mode=="reload")	prefix = "../"; else prefix="";
	xhrTimeLeft.url= "/aviaquiz/timeleft.asp";
	xhrTimeLeft.onSuccess = showLeft;
	xhrTimeLeft.send("rnd="+(new Date()).valueOf());
}
function pause()
{
	timeLeft();
}

