function trimStr(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function openAjaxRequest() {
	var ajaxreq = false;

	if (window.XMLHttpRequest) {
		ajaxreq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			ajaxreq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e1) {
			try {
				ajaxreq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e2) {
				ajaxreq = false;
			}
		}
	}

	return ajaxreq;
}

function execAjaxRequest( URL, parmData, responseHandler, responseType ) {
	var ajaxReq = openAjaxRequest();

	if ( ajaxReq ) {
		ajaxReq.onreadystatechange = function () {
			if ( ajaxReq.readyState == 4 && ajaxReq.status == 200 ) {
				if ( responseType == 'X' ) {
					responseHandler( ajaxReq.responseXML );
				}
				else if ( responseType == 'J' ) {
					var jsonStr = trimStr( ajaxReq.responseText );
					if ( jsonStr == '' )
						jsonStr = '{ }';

					responseHandler( eval( '(' + jsonStr + ')' ) );
				}
				else {
					responseHandler( ajaxReq.responseText );
				}
			}
		}

		ajaxReq.open("POST", URL, true);
		ajaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajaxReq.send( parmData );
	}
}
