var ajax = new AJAX();

function requestContent(method, pageURL, _id)
{
	ajax.makeRequest(method, pageURL, onAJAXResponse, _id);
}

function onAJAXResponse()
{
    //alert(ajax.checkReadyState());
	if(ajax.checkReadyState() == "HTML")
	{
		var response = ajax.request.responseText;
		//alert(response);
		if(response)
		{
			// Retrieve all the linked css files
			/*
			var csslink = response.match(/<link[^>]*>/gi);
			csslink = csslink.join();
*/

			// Remove all the non-body tags
			response = response.replace(/[\n\r]/gi, '');
			response = response.replace(/<html>.*<\/head>/gi, '');
			response = response.replace(/<\/body>.*<\/html>/gi, '</body>');

			// Inject the linked css files
			//response = response.replace(/(<body[^>]*>)/gi, '$1'+csslink);

			var el = document.getElementById(ajax.id);
			if(el)
			{
				el.innerHTML = response;
			}
		}
	}
}

function findWordByPattern(pattern)
{
    requestContent('GET', '/findpattern.php?pattern=' + pattern, 'test');
    return false;
}

function descobrePalavra(pattern)
{
    requestContent('GET', '/br/findpattern.php?pattern=' + pattern, 'test');
    return false;
}

function findWordByClue(clue, _start)
{
    requestContent('GET', '/findclue.php?clue=' + clue + '&start=' + _start, 'test');
    return false;
}