var objAjaxReq = null;
function SendAjaxData(frm, actionPage, clientFunction)
{
	str = AssembleFormData(frm);
	//Don't let them start a new request if one is still pending
	if(objAjaxReq)
	{
		alert("Request in progress. Please wait;");
		return;
	}
	
	//Create an ajax request object
	if(window.XMLHttpRequest)
		objAjaxReq = new XMLHttpRequest();
	else (window.ActiveXObject)
	{
		try
		{
			objAjaxReq = new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch(exception1)
		{
			try 
			{
				objAjaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(exception1)
			{}
		}
	}
	if(!objAjaxReq)
	{
		alert("Your browser does not support Ajax.");
		return;
	}
	//Initialize the request object with the connection information
	objAjaxReq.open("POST", actionPage, true);
	//Function that will be called each time the server calls back
	objAjaxReq.onreadystatechange = eval(clientFunction);
	objAjaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	objAjaxReq.send(str);
}
function AssembleFormData(frm)
{
	// Assemble form data for use with xmlHttpRequest using the POST method
	// Cycle through all the form elements and apply the following rules
	// Ignore any element that does not have a name
	// If the element has a name create a name=value pair.
	// Pass the list of name value pairs back to the calling function with ampersands separating each pair
	newstr = "";
	for(i=0; i< frm.length; i++)
	{
		if(frm[i].name)
		{
			switch (frm[i].type) 
			{
			   case "radio" :
					if(frm[i].checked)
						newstr += "&" + frm[i].name + "=" + frm[i].value;
					break;
			   case "select-one" :
					if(frm[i].value && frm[i].value != "none")
						newstr += "&" + frm[i].name + "=" + frm[i].value;
					break;
			   case "select-multiple" :
					if(frm[i].value) // Are any of the option elements selected?
					{
						tmp = new Array();
						// Cycle through the options and see which ones are selected 
						for(j=0; j<frm[i].length; j++)
						{
							if(frm[i][j].selected)
								tmp[tmp.length] = frm[i][j].value
						}
						newstr += "&" + frm[i].name + "=" + tmp;
					}
					break;
			   case "checkbox" :
					if(frm[i].checked && frm[i].value != "")
						newstr += "&" + frm[i].name + "=" + frm[i].value;
					break;
			   default :
					newstr += "&" + frm[i].name + "=" + frm[i].value;
					break;
			} 
		}
	}
	if(newstr != "")
		return (newstr.slice(1)); //Trim the leading ampersand
	else
		return (null);
}
