// On scroll, recalc position
window.onscroll = scrollFix; 
window.onresize = sizeFix;
function scrollFix(){
	var sdw=$("mapDivShadow");
	if (sdw != null)
	{
	    sdw.style.top=posTop()+'px';
	    sdw.style.left=posLeft()+'px'
	}
}
function sizeFix(){
	var sdw=$("mapDivShadow");
	if (sdw != null)
	{
	    sdw.style.height=pageHeight()+'px';
	    sdw.style.width=pageWidth()+'px';
	}
}
//
// Some other calculations
function pageWidth() {
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() {
	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}
function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}
function posTop() {
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
//
// Easy access to objects
function $(x){
	return document.getElementById(x);
}
//

// United Hebrew find lot on map function
function fmLotMapFind_UH(lotID) {
	fmLotMapFindBase(lotID, fmEngine_UH, $("mapDiv_UH"), $("mapDivShadow"));
}

// Mount Hope find lot on map function
function fmLotMapFind_MH(lotID) {
	fmLotMapFindBase(lotID, fmEngine_MH, $("mapDiv_MH"), $("mapDivShadow"));
}

// Wildwood find lot on map function
function fmLotMapFind_WW(lotID) {
	fmLotMapFindBase(lotID, fmEngine_WW, $("mapDiv_WW"), $("mapDivShadow"));
}

// Find a lot on the map
function fmLotMapFindBase(lotID, objfmDL, objMapDiv, objMapDivShadow) {
    if (fmDLMapIsReady) {
        var div = objMapDiv;
        objfmDL.width = mapWidth;
        objfmDL.height = mapHeight;
        objfmDL.SetVariable("_root.selectedArea_str", lotID);	
		fmDLFocusAndHighlightArea(objfmDL, fmDLMcPath, lotID); 
        var tp=posTop()+((pageHeight()-objfmDL.height)/2);
	    var lt=posLeft()+((pageWidth()-objfmDL.width)/2);
        div.style.top=tp+'px';
	    div.style.left=lt+'px';
        div.style.visibility='visible'; 
        var sdw = objMapDivShadow;
        sdw.style.visibility='visible';
    	sdw.style.top=posTop()+'px';
	    sdw.style.left=posLeft()+'px'
    } else {
        alert("The map is not fully loaded yet. Please try again in a few seconds.");
    }    
}
//
// Hide map
function fmHideMap() {
	if ($("mapDiv_UH") != null)
	{
		$("mapDiv_UH").style.visibility='hidden'; 
	}
	
	if ($("mapDiv_WW") != null)
	{
		$("mapDiv_WW").style.visibility='hidden'; 
	}
	
	if ($("mapDiv_MH") != null)
	{
		$("mapDiv_MH").style.visibility='hidden'; 
	}
	
	if ($("mapDivShadow") != null)
	{
		$("mapDivShadow").style.visibility='hidden'; 
	}
}
//
// Areas not found
function fmAreasNotFound(ids) {
    alert("The lot "+ids+" could not be found.");
    fmHideMap();
}