// INIT
var _base_url;
var use_ajax				= true;
var xmlobj;

/*--------------------------------------------*/
// SET ALERT
/*--------------------------------------------*/	
function tagalert_setalert ()
{
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			return;
		}
				
		//----------------------------------
		// SHOW RESPONSE
		//----------------------------------
		
		response = xmlobj.xmlhandler.responseText;
		showTagAlertResults(response);
		setTimeout( "hideTagAlertResults();", 60000 );
	}

	//----------------------------------------------
	// Not using AJAX? Return and do nothing
	//----------------------------------------------

	if ( ! use_ajax )
	{
		return false;
	}

	value = document.getElementById("tagalert").name.replace("tag-","");

	var url    = _base_url;
	var data = "tag_id=" + value;

	xmlobj = new ajax_request();
	xmlobj.makeRequest(url, data);
	xmlobj.onreadystatechange( do_request_function );	
}

// Unobtrusive events
function init_tagalert_element(base)
{				
	_base_url = base;
	//-------------------------------------
	// Get the input element
	//-------------------------------------
	var tagalert = document.getElementById("tagalert");
	
	//-------------------------------------
	// Set the events
	//-------------------------------------

	tagalert.onclick = function() {tagalert_setalert();}
}

function showTagAlertResults(text)
{
	container = document.getElementById( "tagalertcontainer" );
	container.style.display = 'block';
	container.innerHTML = text;
}

function hideTagAlertResults()
{
	container = document.getElementById( "tagalertcontainer" );
	container.style.display = 'none';
}