﻿// JScript File

function MilitaryFacilities() {
    this.data = [];
    this.selectedItem = '';
    this.getMapPointByID = getMapItemById;
    this.getInfoWindowHTML = getInfoWindowHTMLByIdMilitary;
}

function getInfoWindowHTMLByIdMilitary(infoWindowID) {
    return this.getMapPointByID(infoWindowID).infoWindowHTML;
}

function NVSearchResults(){
    this.data = [];
    this.selectedItem = '';
    this.getCommunityByID = getItemById;
    this.getMapPointByID = getMapItemById;
    this.getInfoWindowHTML = getInfoWindowHTMLById;
    this.hasCommunities = matchCriteria;
//    this.itemDetailView = new SearchResultsDetail(document.getElementById("searchResultsItemDetail"));
//    this.setSelectedItem = setSelItem; 
}

function getItemById(itemId){
	for(var i=0;i<this.data.Communities.length;i++){
		if(this.data.Communities[i].ID == itemId){
			return this.data.Communities[i];
		}
	}
	return null;
}

function getMapItemById(itemId){
	for(var i=0;i<this.data.MapPoints.length;i++){
		if(this.data.MapPoints[i].infoWindowID == itemId){
			return this.data.MapPoints[i];
		}
	}
	return null;
}

function matchCriteria(infoWindowID, filter){
	for(var i=0;i<this.data.MapPoints.length;i++){
    		if(this.data.MapPoints[i].infoWindowID == infoWindowID){
			    for(var x=0;x<this.data.MapPoints[i].Communities.length;x++){
			        cItem = this.data.MapPoints[i].Communities[x];
			        if(filter == "all"
                    ||(filter == "SF" && cItem.SingleFamily) 
                    ||(filter == "TH" && cItem.Townhome) 
                    ||(filter == "CO" && cItem.Condo)
                    ||(filter == "EST" && cItem.Estate) 
                    ||(filter == "ACT" && cItem.ActiveAdult) 
                    ||(filter == "RES" && cItem.Resort)            
                    ){
                    return true;
                    }
                }
    		}
	}
	return false;
}

function getInfoWindowHTMLById(infoWindowID, filter){
    infoWindowHTML = "";
    myMapPoint = null;
    myMapPoint = this.getMapPointByID(infoWindowID);
    
    for(var j=0;j<myMapPoint.Communities.length;j++){
        cItem = myMapPoint.Communities[j];
        if(filter == "all" 
        ||(filter == "SF" && cItem.SingleFamily) 
        ||(filter == "TH" && cItem.Townhome)
        ||(filter == "CO" && cItem.Condo)
        ||(filter == "EST" && cItem.Estate)
        ||(filter == "ACT" && cItem.ActiveAdult) 
        ||(filter == "RES" && cItem.Resort)            
        ){
            infoWindowHTML += cItem.infoWindowHTML;
        }
    }
	return infoWindowHTML;
}

//function setSelItem(item){
//	this.selectedItem = item;
//	this.itemDetailView.setItem(this.selectedItem);
//}



