// request.js

var baseURL = 'http://test.dtagent.net/NewCarForm/Service.asmx/';
var basePath = '/car_data/';

// Gets the XMLHttpRequest object for the browser. Due
// to the way IE uses this object, a new XmlHttpRequest
// should be created each time a request is made.
function CreateXmlHttpRequest() {
	var xmlRequest = false;
	// all modern browsers
	if (window.XMLHttpRequest) {
		xmlRequest = new XMLHttpRequest();
	}
	// old versions of IE
	else if (window.ActiveXObject) {
		xmlRequest = new ActiveXObject('Microsoft.XMLHTTP');
	}
	return xmlRequest;
}

// get a file from the server
function GetFile(filePath, evtHandler) {
	var xmlRequest = CreateXmlHttpRequest();
	if (!xmlRequest) {
		// browser does not support requests, show an error
		alert('Your browser is not supported.');
	}
	else {
		// prepare the request
		xmlRequest.open('GET', basePath + filePath, true);
		xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		// prepare to handle the response
		xmlRequest.onreadystatechange = function() {
			if (xmlRequest.readyState == 4) {
				if (xmlRequest.status == 200) {
					evtHandler(xmlRequest.responseText);
				}
			}
		};
		// send the request
		xmlRequest.send(null);
	}
}


