function CurZoomIndex(mapid){
    var CurIndex = ZoomIndex[mapid];
    if(CurIndex == null){
	CurIndex = DefaultZoomIndex;
	ZoomIndex[mapid] = CurIndex;
    }
    return CurIndex;
}
function CurSizeIndex(mapid){
    var CurIndex = SizeIndex[mapid];
    if(CurIndex == undefined){
	CurIndex = DefaultSizeIndex;
	SizeIndex[mapid] = CurIndex;
    }
    return CurIndex;
}
function PanTo(mapid,X,Y){
    var ZoomIndex = CurZoomIndex(mapid);
    var ZoomValue = Zoom[ZoomIndex];
    var Val = (PanDist * ZoomValue);
    var CurPanDist = Val.toFixed(2);
    PanV += (X * CurPanDist);
    var Pan_V = PanV.toFixed(2);
    PanH += (Y * CurPanDist);
    var Pan_H = PanH.toFixed(2);
    var mapimage = document.getElementById('map_'+mapid);
    var src_str = mapimage.src;
    var result1 = src_str.replace(/PanVertical\=[-\d\.]*/, 'PanVertical=' + Pan_V);
    var result2 = result1.replace(/PanHorizontal\=[-\d\.]*/, 'PanHorizontal=' + Pan_H);
    mapimage.src = result2;
}
function ZoomTo(mapid,Index){
    var mapimage = document.getElementById('map_'+mapid);
    var srcstr = mapimage.src;
    var result = srcstr.replace(/Zoom\=(\d)+(\.\d)?/, 'Zoom=' + Zoom[Index]);
    mapimage.src = result;
    var OldIndex = CurZoomIndex(mapid);
    ZoomIndex[mapid] = Index;
    MapDeactivateZoomBars(mapid);
    MapActivateZoomBar(mapid,Index);
}
function MapReSize(mapid,Index){
    var mapimage = document.getElementById('map_'+mapid);
    var srcstr = mapimage.src;
    var result = srcstr.replace(/Width\=(\d)+/, 'Width=' + SizeWidth[Index]);
    result = result.replace(/Height\=(\d)+/, 'Height=' + SizeHeight[Index]);
    mapimage.src = result;
    mapimage.width = SizeWidth[Index];
    mapimage.height = SizeHeight[Index];
    SizeIndex[mapid] = Index;
    MapDeactivateSizeBars(mapid);
    MapActivateSizeBar(mapid,Index);
}
function MapZoomOut(mapid){
    var CurIndex = CurZoomIndex(mapid);
    for (var i=0;i<Zoom.length;i++){
	if(CurIndex == i){
	    if(Zoom[i-1] != undefined){
		ZoomTo(mapid,i-1);
	    }
	    break;
	}
    }
}
function MapZoomIn(mapid){
    var CurIndex = CurZoomIndex(mapid);
    for (var i=0;i<Zoom.length;i++){
	if(CurIndex == i){
	    if(Zoom[i+1] != undefined){
		ZoomTo(mapid,i+1);
	    }
	    break;
	}
    }
}
function MapZmMouseOver(mapid,Zoom){
    var CurIndex = CurZoomIndex(mapid);
    if(Zoom != CurIndex){
	var bar = document.getElementById('zbar_'+Zoom+'_'+mapid);
	bar.src='/images/maps/bar_active.gif';
    }
}
function MapZmMouseOut(mapid,Zoom){
    var CurIndex = CurZoomIndex(mapid);
    if(Zoom != CurIndex){
	var bar = document.getElementById('zbar_'+Zoom+'_'+mapid);
	bar.src='/images/maps/bar.gif';
    }
}
function MapSzMouseOver(mapid,Size){
    var CurIndex = CurSizeIndex(mapid);
    if(Size != CurIndex){
	var bar = document.getElementById('sbar_'+Size+'_'+mapid);
	bar.src='/images/maps/bar_active.gif';
    }
}
function MapSzMouseOut(mapid,Size){
    var CurIndex = CurSizeIndex(mapid);
    if(Size != CurIndex){
	var bar = document.getElementById('sbar_'+Size+'_'+mapid);
	bar.src='/images/maps/bar.gif';
    }
}
function MapDeactivateSizeBars(mapid){
    document.getElementById('sbar_0_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('sbar_1_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('sbar_2_'+ mapid).src = "/images/maps/bar.gif";
}
function MapActivateSizeBar(mapid,Index){
    document.getElementById('sbar_'+Index+'_'+ mapid).src = "/images/maps/bar_select.gif";
}
function MapDeactivateZoomBars(mapid){
    document.getElementById('zbar_0_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_1_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_2_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_3_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_4_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_5_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_6_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_7_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_8_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_9_'+ mapid).src = "/images/maps/bar.gif";
    document.getElementById('zbar_10_'+ mapid).src = "/images/maps/bar.gif";
}
function MapActivateZoomBar(mapid,Index){
    document.getElementById('zbar_'+Index+'_'+ mapid).src = "/images/maps/bar_select.gif";
}
function MapRestore(mapid,url,width,height){
    var mapimage = document.getElementById('map_'+mapid);
    mapimage.src = url;
    mapimage.width = SizeWidth[DefaultSizeIndex];
    mapimage.height = SizeHeight[DefaultSizeIndex];
    MapDeactivateSizeBars(mapid);
    MapActivateSizeBar(mapid,DefaultSizeIndex);
    SizeIndex[mapid] = DefaultSizeIndex;
    MapDeactivateZoomBars(mapid);
    MapActivateZoomBar(mapid,DefaultZoomIndex);
    ZoomIndex[mapid] = DefaultZoomIndex;
}

