﻿function Location(varName, varPageID, varAddress, varCity, varProvince, varPostalCode, varLatitude, varLongitude, varMultiple) {
	this.Name = varName;
	this.PageID = varPageID;
	this.Address = varAddress;
	this.City = varCity;
	this.Province = varProvince;
	this.PostalCode = varPostalCode;
	this.Multiple = varMultiple;
	this.Latitude = varLatitude;
	this.Longitude = varLongitude;
	this.ToHtml = _CreateHtml;
	
	function _CreateHtml(varPageID) {
	    var varHtml = "<h2>" + this.Name + "</h2>";
	    varHtml += "<p>" + this.Address;
	    varHtml += "<br />" + this.City + ", " + this.Province + ", " + this.PostalCode;
	    if ((this.Multiple) && (varPageID != this.PageID)) {
	        varHtml += "<br /><a href=\"default.aspx?PageID=" + this.PageID + "\">Click for Club Information</a>";
	    }
	    varHtml += "</p>";
	    return varHtml;
	}
}

function LocationCollection() {
	this.LocationArray = new Array();
	this.Add = _AddLocation;
	this.Delete = _DeleteLocation;
	this.Count = _LocationCount;
	this.Item = _ReturnLocation;
	
	function _AddLocation(objLocation) {
		this.LocationArray[this.LocationArray.length] = objLocation;
	}
	
	function _DeleteLocation(varIndex) {
		if (this.LocationArray.length == 0) {
			alert ("There are no objects in this collection.");
			return;
		}
		var varNewLocationArray = new Array();
		var varCounter = 0;
		for (i = 0; i < varIndex; i++) {
			varNewLocationArray[varCounter] = this.LocationArray[i];
			varCounter += 1;
		}
		for (i = varIndex + 1; i < this.LocationArray.length; i++) {
			varNewLocationArray[varCounter] = this.LocationArray[i];
			varCounter += 1;
		}
		this.LocationArray = varNewLocationArray;
	}
	
	function _LocationCount() {
		return this.LocationArray.length;
	}
	
	function _ReturnLocation(varIndex) {
		if (varIndex > (this.LocationArray.length - 1)) {
			alert ("The requested object does not exist in the collection.");
			return;
		}
		return this.LocationArray[varIndex];
	}
}
