var localhost_recording_does_work = false;
var loopback_recording_does_work = false;

function displayGoHere()
{
	document.getElementById("address_prompt").style.visibility="visible";
	document.getElementById("go_here").user_site.focus();
}

function goHere()
{
	var url=document.getElementById("go_here").user_site.value;
	if (url.indexOf("://") < 0)
	{
		url="http://"+url;
	}
	
	var orig_url = url;
	
	if( !localhost_recording_does_work ) {
		url = url.replace(/http\:\/\/localhost/i, "http://" + hostname());
		url = url.replace(/https\:\/\/localhost/i, "https://" + hostname());
	}
	
	if( !loopback_recording_does_work ) {
		url = url.replace(/http\:\/\/127.0.0.1/i, "http://" + hostname());
		url = url.replace(/https\:\/\/127.0.0.1/i, "https://" + hostname());
	}

	if( url != orig_url )
		alert("Note: Web Performance Load Tester detected a reference to \"localhost\" or \"127.0.0.1\" and revised it to read \"" + hostname() + ",\" the host name of the machine on which Load Tester is running.");
	
	window.location=url;
	return false;
}

function interfaceNameFromID(sid) {
	var interface_name = "unknown interface"
		
	if(sid == "localhosttest")
		interface_name = "localhost";
	else if(sid = "loopbacktest")
		interface_name = "127.0.0.1";

	 return interface_name;
}

function imgTestSuccess(sid) {
	document.getElementById(sid + '-text').innerHTML = "Recording on " + interfaceNameFromID(sid) + " should work."
	
	if(sid == "localhosttest")
		localhost_recording_does_work = true;
	if(sid == "loopbacktest")
		loopback_recording_does_work = true;
	
	adviseForLocalhost();
}

function imgTestFailure(sid) {
	var fail_url = "http://www.webperformance.com/diagnostic/fail.gif"

	document.getElementById(sid + '-img').onload = function() {};
	document.getElementById(sid + '-img').src = fail_url;
	document.getElementById(sid + '-text').innerHTML = "Recording on " + interfaceNameFromID(sid) + " is not correctly configured in your browser's proxy settings.";

	adviseForLocalhost();
}

function adviseForLocalhost() {
	if(localhost_recording_does_work && loopback_recording_does_work) {
		document.getElementById("localhost_advise").innerHTML = "You can record on either \"localhost\" or \"127.0.0.1\" for evaluation or testcase development purposes.  Any test case you develop using this method will need to be reconfigured with a fully qualified domain name before you can run a distributed load test.";
	} else {
		document.getElementById("localhost_advise").innerHTML = "Either your browser can not reach both \"localhost\" and \"127.0.0.1\", or your browser is configured to bypass our proxy when using the loopback interface.  If you want to use this capability, you will need to reconfigure your browser's proxy settings.";
	}
}
