//<![CDATA[

// ******* HELPERS *******

function stringFormat(str) {
	for(var myi = 1; myi < arguments.length; myi++) {
		str = str.replace('{' + (myi - 1) + '}', (arguments[myi] != null ? arguments[myi] : ''));
	}
	return str;
}

function $(id) { return document.getElementById(id); }

function isNullOrEmpty(str) {
	if(str == null) {
		return true;
	} else if(str.length == 0) {
		return true;
	}
	return false;
}

function escapeParameter(str) {
	str = str.replace(String.fromCharCode(39), "\\\'");
	str = str.replace(String.fromCharCode(34), "\\\"");
	str = escape(str);
	return str;
}

function unEscapeParameter(str) {
	str = unescape(str);
	str = str.replace("\\\'", String.fromCharCode(39));
	str = str.replace("\\\"", String.fromCharCode(34));
	return str;
}

// ******* DIRECTORY *******

function SpiDirectorySearcher() {

	function createRequest (resultHandler) {
		var reqObj;

		if(window.XMLHttpRequest){
			reqObj = new XMLHttpRequest();
			if((reqObj != null) && (resultHandler != null)) {
				reqObj.onreadystatechange = resultHandler;
			}
		} else if (window.ActiveXObject){
			reqObj = new ActiveXObject("Msxml2.XMLHTTP");
			if (! reqObj){
				reqObj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if((reqObj != null) && (resultHandler != null)) {
				reqObj.onreadystatechange = resultHandler;
			}
		}
		return reqObj;
	}

	this.Request;
	
	this.FindEntries = function (searchTerm, language, format, resultHandler) {
		this.Request = createRequest(resultHandler);

		if(this.Request != null) {
			this.Request.open('GET', ('/DirectoryData.ashx?format=' + format + '&lc=' + language + '&st=' + searchTerm), true);
			this.Request.send(null); 
		}
	}
}

function SpiGeoItem(id, lat, lng, title, description, location, logoPath, imagePath) {
	this.Id = id;
	this.Latitude = lat;
	this.Longitude = lng;
	this.Title = title;
	this.Description = description;
	this.Location = location;
	this.LogoPath = logoPath;
	this.ImagePath = imagePath;
}

function SpiMarker(id, posX, posY, title, description) {
	this.Id = id;
	this.PositionX = posX;
	this.PositionY = posY;
	this.Title = unEscapeParameter(title);
	this.Description = unEscapeParameter(description);
}

function SpiPoint(x, y) {
	this.X = x;
	this.Y = y;
}

//]]>
