// JavaScript Copyright 2007 GameTracker.com.


//PROFILE HARDWARE EDIT
//*****************************
//*****************************
function setFormValue(entryID)
{
	document.getElementById(entryID).value = document.getElementById(entryID + "_scan").value
}
//*****************************
//*****************************
function specScanRequestWrapper()
{
	document.getElementById('system_scan_start_button').style.display = "none";
	document.getElementById('system_scanning_button').style.display = "inline";
	var maxAttemps = 30;
	for (var i = 1; i < maxAttemps; ++i)
	{
		setTimeout('specScanRequest()', i * 10000);
	}
	setTimeout('specScanRequestLast()', maxAttemps * 10000);
}
//*****************************
//*****************************
function specScanRequest()
{
	$.ajax(
	{
		type: 'GET',
		url: '/ajax_requests.php?action=getSystemSpecDate&rnd=' + Math.round(Math.random() * 10000000),
		processData: false,
		dataType: 'html',
		success: function(html)
		{
			resultCode = html.toString().substring(0,1);
			resultString = html.toString().substring(1);
			if(resultCode == 0 && resultString != last_scan)
			{
				document.location.hash = '#scan'
				document.location.reload();
				return;
			}
			if(resultCode == 2)
			{
				alert(resultString);
				document.location.hash = '#scan'
				document.location.reload();
				return;
			}
		},
		error: function(xml)
		{
			alert("Server Request Failed");
		}
	});
}
//*****************************
//*****************************
function specScanResponseLast()
{
	$.ajax(
	{
		type: 'GET',
		url: '/ajax_requests.php?action=getSystemSpecDate&rnd=' + Math.round(Math.random() * 10000000),
		processData: false,
		dataType: 'html',
		success: function(html)
		{
			resultCode = html.toString().substring(0, 1);
			resultString = html.toString().substring(1);
			if(resultCode == 0 && resultString != last_scan)
			{
				document.location.hash = '#scan'
				document.location.reload();
				return;
			}
			if(resultCode == 2)
			{
				alert(resultString);
				document.location.hash = '#scan'
				document.location.reload();
				return;
			}
			document.getElementById('system_scan_start_button').style.display = "inline";
			document.getElementById('system_scanning_button').style.display = "none";
			alert("System scan timed out. Please wait until you receive a system scan confirmation message from GSC. Then refresh this page in your browser.");
		},
		error: function(xml)
		{
			alert("Server Request Failed");
		}
	});
}


//*****************************
//*****************************
$(document).ready(function()
{
	if (document.getElementById("profile_videolinks_link") != null)
	{
		$('#profile_videolinks_link').blur(function()
		{
			


			$('#profile_videolinks_title').val('Searching...');
			$('#profile_videolinks_title').attr("disabled", "disabled");
			$('#profile_videolinks_add_button').attr("disabled", "disabled");
			
			$.ajax(
			{
				type: 'GET',
				url: '/ajax_requests.php?action=getYouTubeVideoTitle&link=' + encodeURIComponent($('#profile_videolinks_link').val()),
				processData: false,
				dataType: 'html',
				success: function(html)
				{
					$('#profile_videolinks_title').val(html);
					$('#profile_videolinks_title').removeAttr("disabled");
					$('#profile_videolinks_add_button').removeAttr("disabled");
				},
				error: function(html)
				{
					alert("Could not contact server");
					$('#profile_videolinks_title').val('');
					$('#profile_videolinks_title').removeAttr("disabled");
					$('#profile_videolinks_add_button').removeAttr("disabled");
				}
			});
		});
	}
});






