﻿var zurl = "/includes/ajax/dealerlookup.aspx?postcode=";
var isWorking = false;
function handleHttpResponse() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			document.getElementById("results").innerHTML = http.responseText
			isWorking = false;
		}
	}
}

function getdealers() {
	if (!isWorking && http) {
		var zipValue = document.getElementById("postcode").value;
		if(zipValue.length > 1)	{
			http.open("GET", zurl + escape(zipValue), true);
			http.onreadystatechange = handleHttpResponse;
			isWorking = true;
			http.send(null);
		}
		else document.getElementById("results").innerHTML = '';
	}
}

var http = getHTTPObject(); // We create the HTTP Object
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	}
	return xmlhttp;
}

