function getNewLevel(e,w,n,s){				
	var latRatio = (e - w) * 1.0 / 0.0059008598;
	var lngRatio = (n - s) * 1.0 / 0.0029504299;				
	var latZoomLevel, lngZoomLevel;
	if(latRatio<1){
		latZoomLevel = 0;
	}else if(latRatio<2){
		latZoomLevel = 1;
	}else if(latRatio<4){
		latZoomLevel = 2;
	}else if(latRatio<8){
		latZoomLevel = 3;
	}else if(latRatio<16){
		latZoomLevel = 4;
	}else if(latRatio<32){
		latZoomLevel = 5;
	}else if(latRatio<64){
		latZoomLevel = 6;
	}else if(latRatio<128){
		latZoomLevel = 7;
	}else if(latRatio<256){
		latZoomLevel = 8;
	}else if(latRatio<512){
		latZoomLevel = 9;
	}else if(latRatio<1024){
		latZoomLevel = 10;
	}else if(latRatio<2048){
		latZoomLevel = 11;
	}else if(latRatio<4096){
		latZoomLevel = 12;
	}else if(latRatio<8192){
		latZoomLevel = 13;
	}else if(latRatio<16384){
		latZoomLevel = 14;
	}else if(latRatio<32768){
		latZoomLevel = 15;
	}else if(latRatio<65536){
		latZoomLevel = 16;
	}else{
		latZoomLevel = 17;
	}
					
	if(lngRatio<1){
		lngZoomLevel = 0;			
	}else if(lngRatio<2){
		lngZoomLevel = 1;			
	}else if(lngRatio<4){
		lngZoomLevel = 2;			
	}else if(lngRatio<8){
		lngZoomLevel = 3;			
	}else if(lngRatio<15.999999){
		lngZoomLevel = 4;			
	}else if(lngRatio<31.999996){
		lngZoomLevel = 5;
	}else if(lngRatio<63.999971){
		lngZoomLevel = 6;			
	}else if(lngRatio<127.99977){
		lngZoomLevel = 7;
	}else if(lngRatio<255.99815){
		lngZoomLevel = 8;			
	}else if(lngRatio<511.98517){
		lngZoomLevel = 9;			
	}else if(lngRatio<1023.8814){
		lngZoomLevel = 10;			
	}else if(lngRatio<2047.0516){
		lngZoomLevel = 11;			
	}else if(lngRatio<4088.4284){
		lngZoomLevel = 12;			
	}else if(lngRatio<8131.9257){
		lngZoomLevel = 13;			
	}else if(lngRatio<15918.630){
		lngZoomLevel = 14;			
	}else if(lngRatio<29455.314){
		lngZoomLevel = 15;			
	}else if(lngRatio<46798.022){
		lngZoomLevel = 16;			
	}else{
		lngZoomLevel = 17;
	}
	var newlevel;
	if(lngZoomLevel > latZoomLevel){
		newlevel = lngZoomLevel;
	}else{
		newlevel = latZoomLevel;
	}			
	return newlevel;
}

function Rectangle(bounds, opt_weight, opt_color) {
 	this.bounds_ = bounds;
	this.weight_ = opt_weight || 2;
	this.color_ = opt_color || "#0000FF";
}
Rectangle.prototype = new GOverlay();
// Creates the DIV representing this rectangle.
Rectangle.prototype.initialize = function(map) {
	// Create the DIV representing our rectangle
 	var div = document.createElement("div");
  	div.style.border = this.weight_ + "px solid " + this.color_;
	div.style.position = "absolute";
	// Our rectangle is flat against the map, so we add our selves to the
	// MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
	// below the marker shadows)
 	map.getPane(G_MAP_MAP_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
}
// Remove the main DIV from the map pane
Rectangle.prototype.remove = function() {
 	this.div_.parentNode.removeChild(this.div_);
}
// Copy our data to a new Rectangle
Rectangle.prototype.copy = function() {
 	return new Rectangle(this.bounds_, this.weight_, this.color_, this.backgroundColor_, this.opacity_);
}
// Redraw the rectangle based on the current projection and zoom level
Rectangle.prototype.redraw = function(force) {
 	// We only need to redraw if the coordinate system has changed
 	if (!force) return;
	// Calculate the DIV coordinates of two opposite corners of our bounds to
 	// get the size and position of our rectangle
	var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
	var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
 	// Now position our DIV based on the DIV coordinates of our bounds
	this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
	this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
	this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
 	this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
}