var MapResize = {
    init: function(bIsExplorer) {
        this.bIsIE = bIsExplorer; 			// We need to know if the browser is IE or not.
        this.timerOnResize = -1; 			// IE Only: The ID number of the timer.
        this.nIEResizeTriggerCount = 0; 		// IE Only: Count the number of resize events (so we don't have to react to all of them.)
        this.nOnResizeTimeout = 1000; 		// IE Only: How long to wait in MS after a resize event to request a new map.
        this.sContainerId = 'mapImageCell'; 	// The map container element's ID.
        this.sImageId = 'mapImage'; 			// The map image's ID.
    },

    getMapContainerSize: function() {
        //try{
        var e = document.getElementById(this.sContainerId);
        return { width: e.clientWidth, height: e.clientHeight };
        //else return {width:540, height:520};
        //}catch(ex){
        //	return {width:540, height:520};
        //}		
    },

    saveMapContainerSize: function() {
        var e = document.getElementById(this.sContainerId);
        if (!e) return;
        document.Form1.txtCurMapWidth.value = '' + e.clientWidth;
        document.Form1.txtCurMapHeight.value = '' + e.clientHeight;
    },

    saveMapContainerSizeByParam: function(newWidth, newHeight) {
        document.Form1.txtCurMapWidth.value = '' + newWidth;
        document.Form1.txtCurMapHeight.value = '' + newHeight;
    },

    setMapImageSize: function(newWidth, newHeight) {
        //var e = document.getElementById(this.sImageId);
        //if(!e) return;
        //e.style.left = '0px';
        //e.style.top = '0px';
        //e.style.width = '' + newWidth + 'px';
        //e.style.height = '' + newHeight + 'px';
    },

    onResize: function() {

        //if(this.bIsIE){
        this.nIEResizeTriggerCount = 0;
        if (this.timerOnResize != -1) clearTimeout(this.timerOnResize);
        this.timerOnResize = setTimeout('MapResize.onResizeComplete()', this.nOnResizeTimeout);
        //}
        //else{
        //	this.sendMapSize();
        //}
    },

    onResizeComplete: function() {
        this.timerOnResize = -1;
        if (this.nIEResizeTriggerCount > 0) return;
        this.nIEResizeTriggerCount++;
        this.sendMapSize();
    },

    sendMapSize: function() {

        var e = document.getElementById(this.sContainerId);
        if (!e) return;

        //alert(document.Form1.txtCurMapWidth.value);
        //alert(e.clientWidth);
        //alert(document.Form1.txtCurMapHeight.value);
        //alert(e.clientHeight);

        if (document.Form1.txtCurMapWidth.value == '' + e.clientWidth && document.Form1.txtCurMapHeight.value == '' + e.clientHeight) {
            //alert('no change');
            return;
        }
        //alert('changing');

        var ms = this.getMapContainerSize();
        //alert(ms.width);
        //alert(ms.height);
        this.setMapImageSize(ms.width, ms.height);
        this.saveMapContainerSizeByParam(ms.width, ms.height);

        //var map = this.getMapContainerSize();
        document.Form1.x1.value = '' + offsetX;
        document.Form1.y1.value = '' + offsetY;
        document.Form1.x2.value = '' + (parseInt('' + document.Form1.txtCurMapWidth.value) - offsetX);
        document.Form1.y2.value = '' + (parseInt('' + document.Form1.txtCurMapHeight.value) - offsetY);
        //document.Form1.x2.value = '' + (map.width-offsetX);
        //document.Form1.y2.value = '' + (map.height-offsetY);		
        __doPostBack('btnGetNewMap', 'OnClick');
    }
};
