// Ajax support function
function getAjaxRequest()
{
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return null;
			}
		}
	}
	return xmlHttp;
}

// Updates the content of a html element.
function ajaxUpdateHtml(id, request)
{
	ajaxRequest = getAjaxRequest();
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			// Update the HTML for the element.
			document.getElementById(id).innerHTML = ajaxRequest.responseText;
			// Evaluate any embedded scripts.
			evalScripts(ajaxRequest.responseText);
		}
	}
	ajaxRequest.open("GET", request, true);
	ajaxRequest.send(null); 
}		

// Updates the content of a html element.
function ajaxUpdateHtmlValue(id, request)
{
	ajaxRequest = getAjaxRequest();
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			// Update the HTML for the element.
			document.getElementById(id).value = ajaxRequest.responseText;
			// Evaluate any embedded scripts.
			evalScripts(ajaxRequest.responseText);
		}
	}
	ajaxRequest.open("GET", request, true);
	ajaxRequest.send(null); 
}	

function extractScripts(html) {
	var scriptFragment = '<script[^>]*>([\u0001-\uFFFF]*?)</script>';
    var matchAll = new RegExp(scriptFragment, 'img');
    var matchOne = new RegExp(scriptFragment, 'im');
    return (html.match(matchAll) || []).map(function(scriptTag) {
      return (scriptTag.match(matchOne) || ['', ''])[1];
    });
  }

function evalScripts(html) {
    return extractScripts(html).map(function(script) { return eval(script) });
  }