//################ GRID FUNCTIONS ################################################
function getPhotoURL(mlsListingID, clonedMlsID, photoAtHbm, photoCount) { 
   if(photoAtHbm=="True" || parseInt(photoCount) > 0)
   {
	   var strPropPhotoURL = document.getElementById('divPhotoSource').value;
	   var tmp1 = mlsListingID.substring(mlsListingID.length-1, mlsListingID.length);
	   var tmp2 = mlsListingID.substring(mlsListingID.length-2, mlsListingID.length-1);
	   var tmp3 = mlsListingID.substring(mlsListingID.length-3, mlsListingID.length-2);
	   
	    //This block of code only builds subdirectories if the last 3 digits of propertyID are NUMERIC
        //--------------------------------------------------------------------------------------------
//						if(!(isNaN(tmp1))) 
//						{ 
//						var folders=tmp1+'/';
//							if(!(isNaN(tmp2))) 
//								{ 
//								folders+=tmp2+'/';
//									if(!(isNaN(tmp3))) { folders+=tmp3+'/';}
//								}
//						}
	    //--------------------------------------------------------------------------------------------


        //This block of code builds subdirectories regardless of alpha/numeric characters
        //--------------------------------------------------------------------------------------------
            var folders=tmp1+'/'+tmp2+'/'+tmp3+'/';
        //--------------------------------------------------------------------------------------------
		strPropPhotoURL+=clonedMlsID+"\/"+folders+mlsListingID+".jpg";
	}
	else
	{
		var strPropPhotoURL="App_Themes/Default/Images/Map/PhotoComing.jpg";
	}
	return strPropPhotoURL;
}
function displayPhotoForGrid(shapeIndex, mlslistingID, mlsID, photoAtHbm, photoCount, addr, listingID, clonedMLSID, metroAreaID) {
    var photoURL = getPhotoURL(mlslistingID, clonedMLSID, photoAtHbm, photoCount);
    $('divPhoto').innerHTML = "<a href=\"javascript:popUpCenteredWindow(\'ListingDetail.aspx?LID=" + listingID+"&MLSID="+mlsID+"&MetroAreaID="+metroAreaID + "\');\"><img src=\""+photoURL+"\" border=\"0\" /></a>";
    
    if(shapeIndex!=null) {
	    //toggleInfoBox(shapeIndex,'on');
	    var shape = _listingLayer.GetShapeByIndex(shapeIndex-2);
	    var pixel = _map.LatLongToPixel(new VELatLong(shape.Latitude,shape.Longitude));
	    var obj =document.getElementById('divAddressHover'); 
        obj.style.display="block";
        obj.style.top=pixel.y+'px';
        obj.style.left=pixel.x+'px';
        document.getElementById('divAddressText').innerHTML = unescape(addr);
	}
}
function hideAddressHover() {
    $("divAddressHover").style.display="none";
}
//******** Show hover box on map **********
var t;
function toggleInfoBox(ShapeIndex,state) {
        document.getElementById('divAddressText').innerHTML = "";
        document.getElementById('divAddressHover').style.display="none";
//	if(state == 'on') {
//		t=setTimeout("showInfoBox("+ShapeIndex+")",300);
//	}
//	else {
//		hideInfoBox()
//		}
}
function showInfoBox(ShapeIndex) 
{       
        var shape = _listingLayer.GetShapeByIndex(ShapeIndex-1);
		//var shapeID = shape.GetID();    //Use this for ajax version of hover box
		//launchHoverBox(shapeID);        //Use this for ajax version of hover box

        _map.ShowInfoBox(shape); //Use this for non-ajax hover box
}
function hideInfoBox() {
	clearTimeout(t);
	_map.HideInfoBox();
}

function clearGrid() {
    document.getElementById('divGrid').innerHTML='';
    document.getElementById('divPhoto').innerHTML='';
    document.getElementById('divGrid').style.display='none';
	document.getElementById('divSummary').style.display='none';
    document.getElementById('divHeader1').style.display='none';
    document.getElementById('divHeader2').style.display='none';
}
function displaySummary(ListingPrice,City,SquareFeet,Bedrooms,Bathrooms,ListAgentInfo)
{
    var row = "<span id=\"headerCity\" style=\"font-weight:bold;float:right;text-align:right;width:105px;overflow-x:hidden;\">"+City+"</span>"
    +"<span id=\"headerPrice\" style=\"font-weight:bold;color:Red;float:left;width:70px;\">"+ListingPrice+"</span><br />"
    + "<span id=\"headerBedsBaths\" style=\"font-weight:bold;float:right;\">"+Bedrooms+"Beds/"+Bathrooms+"Baths</span>"
    + "<span id=\"headerSqFt\" style=\"font-weight:bold;float:left;\">"+SquareFeet+" Sqft</span><br />" 
    + "<div id=\"headerMLS\" style=\"font-size:.7em;height:20px;width:100%;overflow:hidden;\">courtesy of "+unescape(ListAgentInfo)+"</div>";
    document.getElementById('divSummary').innerHTML = row;
}
function clearSummary(){
    document.getElementById('divSummary').innerHTML = '';
    document.getElementById('divPhoto').innerHTML = '';
}
