   var moz = ((document.all)? false : true);
   var ie = ((document.all)? true : false);

   var mainNamingContainer;
   var locfieldsNamingContainer;   
   var bIsWebTop = false;
 
    function SetClientID(ClientID, isWebTop) {
		mainNamingContainer = ClientID;
		locfieldsNamingContainer = mainNamingContainer.substring(0,mainNamingContainer.indexOf("MapSearch_")) + "LocationFields_";
		if(ClientID.indexOf("Webtop") != -1)
			bIsWebTop = (isWebTop == "True");
	}
	
	function KeyDown(e)
	{
		var key_index;
		if(moz)
			key_index = e.which;
		else
			key_index = window.event.keyCode;
		if(key_index == 13)
		{
			if(document.getElementById("ignmaxListPrice") != null)
				CalcMaxListPrice();
			if(document.getElementById("ignminListPrice") != null)
				CalcMinListPrice();
			DoSearch('MapSearchCriteria');
			return false;
		}
		return;
	}
	// start event listener
	document.onkeydown = KeyDown;

    function ImageBox(imgId) {  
      var origX, origY;
      var imgPosition, imgDimension;
      var dragDiv, overLayer;
      var isCropped = false;
      
      
      function init() {
        var img = document.getElementById(imgId);  
        imgPosition = ElementUtil.getElementPosition(img);
        imgDimension = ElementUtil.getElementDimension(img);   

        dragDiv = document.getElementById("dragDiv");
                                 
        dragDiv.style.visibility = "hidden";
        dragDiv.style.position = "absolute";
        dragDiv.style.border = "1px solid blue";
        dragDiv.style.width = "0px";
        dragDiv.style.height = "0px";
        dragDiv.style.zIndex = 3;
        //dragDiv.style.left = "20px";
        //dragDiv.style.top = "20px";
        dragDiv.style.overflow = "hidden";      
        
        if(ie) {
          // Removes default drag behaviour on image
          ElementUtil.addEventListener(img, "drag", function() {return false;});
          // Adds my "drag" behaviour to the image
          ElementUtil.addEventListener(img, "mousedown", mouseDown);
        }
         if(moz) {
          img.onmousedown = mouseDown;
		  //dragDiv.onmousedown = mouseDown;  
        }
     
        eMinLat = document.getElementById(mainNamingContainer + "allminlatitude");
		eMaxLat = document.getElementById(mainNamingContainer + "allmaxlatitude");
		eMinLong = document.getElementById(mainNamingContainer + "allminlongitude");
		eMaxLong = document.getElementById(mainNamingContainer + "allmaxlongitude");
		MapImg = document.getElementById(mainNamingContainer + "MainMap");
		var strMapImgSrc = new String(MapImg.src);

        if (eMinLat.value != "" && strMapImgSrc.indexOf("mapid") != -1) {
			if(strMapImgSrc.length > 29 && strMapImgSrc.indexOf('=') != -1) {
				MapID = strMapImgSrc.substring(strMapImgSrc.indexOf("mapid=")+6,strMapImgSrc.indexOf("&LastLat"));
				LastLat = strMapImgSrc.substring(strMapImgSrc.indexOf("LastLat=")+8,strMapImgSrc.indexOf("&LastLong"));
				LastLong = strMapImgSrc.substring(strMapImgSrc.indexOf("LastLong=")+9,strMapImgSrc.indexOf("&DiffLat"));
				DiffLat = strMapImgSrc.substring(strMapImgSrc.indexOf("DiffLat=")+8,strMapImgSrc.indexOf("&DiffLong"));
				if(strMapImgSrc.indexOf("&point") == -1)
					DiffLong = strMapImgSrc.substring(strMapImgSrc.indexOf("DiffLong=")+9);
				else
					DiffLong = strMapImgSrc.substring(strMapImgSrc.indexOf("DiffLong=")+9,strMapImgSrc.indexOf("&point"));
			}
	
			// Convert lat and long to x and y values
			imgPosition = ElementUtil.getElementPosition(MapImg);
			imgDimension = ElementUtil.getElementDimension(MapImg);
			   
			var CenterX = imgDimension.width/2 + imgPosition.left;
			var CenterY = imgDimension.height/2 + imgPosition.top;
			var x1 = (parseFloat(eMinLong.value)-parseFloat(LastLong))*imgDimension.width/(2*parseFloat(DiffLong)) + CenterX;
			var y1 = (parseFloat(LastLat)-parseFloat(eMinLat.value))*imgDimension.height/(2*parseFloat(DiffLat)) + CenterY;
			var x2 = (parseFloat(eMaxLong.value)-parseFloat(LastLong))*imgDimension.width/(2*parseFloat(DiffLong)) + CenterX;
			var y2 = (parseFloat(LastLat)-parseFloat(eMaxLat.value))*imgDimension.height/(2*parseFloat(DiffLat)) + CenterY;
			
			if(ie)
				dragDiv.style.visibility = "visible";
			if(x1 < x2) {
				origX = x1;
			}
			else {
				origX = x2;
				x2 = x1;
			}
			if(y1 < y2) {
				origY = y1;
			}
			else {
				origY = y2;
				y2 = y1;
			}
			dragDivLeft = origX;
			dragDivTop = origY;
			dragDivWidth = 1;
			dragDivHeight = 1;

			if(origX <= imgPosition.left) {
				dragDivLeft = imgPosition.left - 1;
				if(x2 >= imgPosition.left)
					dragDivWidth = x2 - imgPosition.left;
				else   
					dragDivWidth = 0;
			}
			if(x2 > (imgPosition.left + imgDimension.width)) {
				if(ie) {            
					dragDivWidth = imgDimension.width - (dragDivLeft - imgPosition.left);
				}
				else if(moz) {
					dragDivWidth = imgDimension.width - (dragDivLeft - imgPosition.left) - 2;
				}
				if(origX > (imgPosition.left + imgDimension.width))
					dragDivWidth = 0;
			}
			else if (origX > imgPosition.left) {
				var newWidth = x2 - origX;
				var newLeft = -1;
				if(newWidth < 0) {
					if(x2 > imgPosition.left) {
						newLeft = x2;
					}
					newWidth = origX - x2;
				}
				if(newLeft != -1) {
					dragDivLeft = newLeft;
				}
				dragDivWidth = newWidth;
			}  
			if(origY <= imgPosition.top) {
				dragDivTop = imgPosition.top;
				if(y2 >= imgPosition.top)
				{ 
					dragDivHeight = y2 - imgPosition.top;
				}
				else
				{
					dragDiv.style.visibility = "hidden";
					dragDivHeight = 0;
				}
			}
			if(y2 > (imgPosition.top + imgDimension.height)) {
				if(ie) {
					dragDivHeight = imgDimension.height - (dragDivTop - imgPosition.top) + 1;
				}
				else if(moz) {
					dragDivHeight = imgDimension.height - (dragDivTop - imgPosition.top) - 2;
				}
				if(origY > (imgPosition.top + imgDimension.height))
				{
					dragDivHeight = 0;
					dragDiv.style.visibility = "hidden";
				}
			}
			else if(origY > imgPosition.top) {
				var newHeight = y2 - origY;
				var newTop = -1;
				if(newHeight < 0) {
					if(y2 > imgPosition.top) {
						newTop = y2;
						newHeight = origY - y2;
					}
				}
				if(newTop != -1) {
					dragDivTop = newTop;
				}
				dragDivHeight = newHeight;
			}
			if(isNaN(dragDivLeft))
			{
				dragDivLeft = imgPosition.left;
				dragDivTop = imgPosition.top;
				dragDivWidth = imgDimension.width;
				dragDivHeight = imgDimension.height;
			}
			if(ie)
			{
				dragDiv.style.left = dragDivLeft;
				dragDiv.style.top = dragDivTop;
				dragDiv.style.width = dragDivWidth;
				dragDiv.style.height = dragDivHeight;
			}
			if(moz)
			{
				DrawMozRect(dragDivLeft, dragDivWidth, dragDivTop, dragDivHeight)
			}
							
			// set the current values
			document.getElementById(mainNamingContainer + "XDown").value = dragDivLeft;
			document.getElementById(mainNamingContainer + "XUp").value = dragDivLeft + dragDivWidth;
			document.getElementById(mainNamingContainer + "YDown").value = dragDivTop;
			document.getElementById(mainNamingContainer + "YUp").value = dragDivTop + dragDivHeight;
		} 
      }   
      
      function mouseDown(evt) {
        if(!evt) {
          evt = event;
        }
        XDown = document.getElementById(mainNamingContainer + "XDown");
        YDown = document.getElementById(mainNamingContainer + "YDown");
        XUp = document.getElementById(mainNamingContainer + "XUp");
        YUp = document.getElementById(mainNamingContainer + "YUp");
        
        MapImg = document.getElementById(mainNamingContainer + "MainMap");
        imgPosition = ElementUtil.getElementPosition(MapImg);     
       
        if(ie)
        {
			dragDiv.style.zIndex = -1;
			dragDiv.style.left = evt.offsetX;
			dragDiv.style.top = evt.offsetY;
			origX = evt.offsetX;
			origY = evt.offsetY;
        }
        else
        {
			dragDiv.style.left = evt.layerX;
			dragDiv.style.top = evt.layerY;
			origX = evt.layerX;
			origY = evt.layerY;
        }
        dragDiv.style.width = "1px";
        dragDiv.style.height = "1px";
        
        XDown.value = origX;
        YDown.value = origY;
        XUp.value = origX;
        YUp.value = origY;
        
        if(moz)
        {
			MapImg.addEventListener("mousemove", mouseMove,   true);
			document.addEventListener("mouseup",   mouseUp, true);
			evt.preventDefault();
        }
        else
        {
			ElementUtil.addEventListener(MapImg, "mousemove", mouseMove);
			ElementUtil.addEventListener(document, "mouseup", mouseUp); 
        }
        evt.cancelBubble = true;
        return false;   
      }
      function mouseMove(evt) {
         if(!evt) {
            evt = event;
         }
         if(ie)
		 {
			dragDiv.style.zIndex = 3;
			dragDiv.style.visibility = "visible";
			offsetX = evt.offsetX;
			offsetY = evt.offsetY;
		 }
		 else
		 {
			offsetX = evt.layerX;
			offsetY = evt.layerY;
		 }

		 Xtmp = offsetX;
		 Ytmp = offsetY;
		 
		 XUp = document.getElementById(mainNamingContainer + "XUp");
	 	 YUp = document.getElementById(mainNamingContainer + "YUp");
	 		
	 	 if(moz || (Xtmp > 0 && Ytmp > 0))
	 	 {
	 		XUp.value = Xtmp;
	 		YUp.value = Ytmp;
			if(origX < Xtmp)
			{
				divLeft = origX;
				divWidth = Xtmp - origX;
			}
			else
			{
				divLeft = Xtmp;
				divWidth = origX - Xtmp;
			}
			if(origY > Ytmp)
			{
				divTop = Ytmp;
				divHeight = origY - Ytmp;
			}
			else
			{
				divTop = origY;
				divHeight = Ytmp - origY; 
			}
			if(ie)
			{
				dragDiv.style.left = divLeft;
				dragDiv.style.top = divTop;
				dragDiv.style.width = divWidth;
				dragDiv.style.height = divHeight;
			}
			if(moz && offsetX != 0)
				DrawMozRect(divLeft, divWidth, divTop, divHeight); 
		}
	  }
      
      function mouseUp(evt) {
		MapImg = document.getElementById(mainNamingContainer + "MainMap");
        if(moz)
        {
		  MapImg.removeEventListener("mousemove", mouseMove, true);
          document.removeEventListener("mouseup", mouseUp, true);
        }
        else
        {
          ElementUtil.removeEventListener(MapImg, "mousemove", mouseMove); 
          ElementUtil.removeEventListener(document, "mouseup", mouseUp);
        }
        
        XDown = document.getElementById(mainNamingContainer + "XDown");
		YDown = document.getElementById(mainNamingContainer + "YDown");
        XUp = document.getElementById(mainNamingContainer + "XUp");
		YUp = document.getElementById(mainNamingContainer + "YUp");

		if(ie)
	    {
			offsetX = evt.offsetX;
			offsetY = evt.offsetY;
		}
		else
		{
			offsetX = evt.layerX;
			offsetY = evt.layerY;
		}
		if(!(XUp.value == XDown.value && YUp.value == YDown.value))
			SetMapSearchValues("rect", "");
		else
			dragDiv.style.zIndex = -1;
      } 
      
      function DrawMozRect(divLeft, divWidth, divTop, divHeight)
      {
			topDiv = document.getElementById("topDiv");
			//topDiv.style.position = "absolute";
			//topDiv.style.border = "1px solid #0000ff";
			topDiv.style.width = divWidth + "px";
			topDiv.style.left = divLeft + "px";
			topDiv.style.top = divTop + "px";
			topDiv.style.height = "0px";
			topDiv.style.zIndex = 3;
			
			btmDiv = document.getElementById("btmDiv");
			//btmDiv.style.position = "absolute";
			//btmDiv.style.border = "1px solid #0000ff";
			btmDiv.style.width = divWidth + "px";
			btmDiv.style.left = divLeft + "px";
			btmDiv.style.top = parseInt(divTop) + parseInt(divHeight) + "px";
			btmDiv.style.height = "0px";
			btmDiv.style.zIndex = 3;
			
			leftDiv = document.getElementById("leftDiv");
			//leftDiv.style.position = "absolute";
			//leftDiv.style.border = "1px solid #0000ff !important";
			leftDiv.style.width = "0px";
			leftDiv.style.left = divLeft + "px";
			leftDiv.style.top = divTop + "px";
			leftDiv.style.height = divHeight + "px";
			leftDiv.style.zIndex = 3;
			
			rightDiv = document.getElementById("rightDiv");
			//rightDiv.style.position = "absolute";
			//rightDiv.style.border = "1px solid #0000ff !important";
			rightDiv.style.width = "0px";
			rightDiv.style.left = parseInt(divLeft) + parseInt(divWidth) + "px";
			rightDiv.style.top = divTop + "px";
			rightDiv.style.height = divHeight + "px";
			rightDiv.style.zIndex = 3;
      }
       
      init();
     
      this.getX = function() {
        return (parseInt(dragDiv.style.left) - parseInt(imgPosition.left));
      }
      
      this.getY = function() {
        return (parseInt(dragDiv.style.top) - parseInt(imgPosition.top));
      }
      
      this.getWidth = function() {
        return parseInt(dragDiv.style.width);
      }
      
      this.getHeight = function() {
        return parseInt(dragDiv.style.height);
      }    
      
      this.toggleCrop = function() {
        var img = document.getElementById(imgId);
        var str = "";
        if(isCropped) {
          str = "rect(auto auto auto auto)";
          isCropped = false;
        }
        else {
          var top = this.getY();
          var left = this.getX();
          var bottom = this.getY() + this.getHeight();
          var right = this.getX() + this.getWidth();
          if(moz) {
            bottom = bottom + 2;
            right = right + 2;
          }
          str = "rect(" + top + "px, " + 
          right + "px, " + 
          bottom + "px, " + left + "px)";  
          isCropped = true;
        }
        img.style.clip = str;
      }     
      this.toString = function() {
        var str = "Left: " + this.getX() + "px\n" +
        "Top: " + this.getY() + "px\n" +
        "Width: " + this.getWidth() + "px\n" + 
        "Height: " + this.getHeight() + "px";
        return str;     
      }	      
    }
    ImageBox.boxes = new Array();
    ImageBox.createBox = function(imgId) {
    //debugger
      ImageBox.boxes[imgId] = new ImageBox(imgId);
    }
    ImageBox.getBox = function(imgId) {
      return ImageBox.boxes[imgId];
    }
    var ElementUtil = new Object();
    ElementUtil.getElementPosition = function(elt){
      var position = new Object();  
      if(elt.style.position == "absolute") {
        position.left = parseInt(elt.style.left);
        position.top = parseInt(elt.style.top);
      }
      else {
        position.left = ElementUtil.calcPosition(elt, "Left"); 
        position.top = ElementUtil.calcPosition(elt, "Top");   
      }  
      return position;
    }
    
     ElementUtil.calcPosition = function(elt, dir){
        var tmpElt = elt;
        var pos = parseInt(tmpElt["offset" + dir]);
        pos = 0;
  
		//while(tmpElt.tagName != "HTML") {
		//	tmpElt = tmpElt.offsetParent;
		//	pos += parseInt(tmpElt["offset" + dir]);
		//}
		
        return pos;
    }
    
    ElementUtil.getElementDimension = function(elt) {
      var dim = new Object();
      dim.width = elt.offsetWidth;
      dim.height = elt.offsetHeight;
      return dim;
    }    
  
    ElementUtil.addEventListener = function(o, type, handler) {
      if(ie) {
        o.attachEvent("on" + type, handler);
      }
      else if(moz) {
        o.addEventListener(type, handler, false);
      }
    }

    ElementUtil.removeEventListener = function(o, type, handler) {
      if(ie) {
        o.detachEvent("on" + type, handler);
      }
      else if(moz) {
        o.removeEventListener(type, handler, false);
      }
    }
    function trim (s) { 
		return s.replace(/^\s+|\s+$/g, ''); 
    }
    
    function setUpVals(){
    
    }
    
    function DoMapSearchSave()
	{
		if(checkSearchParam() == true)
		{	
			doSave();
		}
	}
	
    function DoSearch(PostBackControlName)
	{
		if (ie && !Page_ClientValidate()) { return false;}
		var strCity = "";
		var strPostalCode = "";
		var strCounty = 0;
		if (document.getElementById(locfieldsNamingContainer + "alllstCity"))
		{
			document.getElementById(locfieldsNamingContainer + "alllstCity").value = trim(document.getElementById(locfieldsNamingContainer + "alllstCity").value);
			strCity = document.getElementById(locfieldsNamingContainer + "alllstCity").value;
		}
		if (document.getElementById(locfieldsNamingContainer + "alllstPostalCode"))
		{
			document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value = trim(document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value);
			strPostalCode = document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value;
			strPostalCode = strPostalCode.replace(/ /g, "");
			document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value = strPostalCode;
		}
		if (document.getElementById(locfieldsNamingContainer + "allstrCounty"))
		{
			document.getElementById(locfieldsNamingContainer + "allstrCounty").value = trim(document.getElementById(locfieldsNamingContainer + "allstrCounty").value);	
			strCounty = document.getElementById(locfieldsNamingContainer + "allstrCounty").value;
		}
		else if(document.getElementById(locfieldsNamingContainer+ "alllstCounty"))
		{
			document.getElementById(locfieldsNamingContainer + "alllstCounty").value = trim(document.getElementById(locfieldsNamingContainer + "alllstCounty").value);
			strCounty = document.getElementById(locfieldsNamingContainer + "alllstCounty").value;
		}	
			
		if (strCity != "" || strPostalCode != "" || strCounty != "" || PostBackControlName == "alllstStateOrProvince")
		{
			if(!(PostBackControlName == "alllstStateOrProvince")) //&& document.getElementById(locfieldsNamingContainer+ "alllstStateOrProvince").selectedIndex == 0))
			{
				//remove the rectangle
				document.getElementById(mainNamingContainer + "allminlatitude").value = "";
				document.getElementById(mainNamingContainer + "allmaxlatitude").value = "";
				document.getElementById(mainNamingContainer + "allminlongitude").value = "";
				document.getElementById(mainNamingContainer + "allmaxlongitude").value = "";
			}
			if(PostBackControlName == "alllstStateOrProvince") 
			{
				// changing state, so clear other fields
				document.getElementById(locfieldsNamingContainer + "alllstCity").value = "";
				document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value = "";
				if (document.getElementById(locfieldsNamingContainer + "allstrCounty"))
					document.getElementById(locfieldsNamingContainer + "allstrCounty").value = "";
				else if(document.getElementById(locfieldsNamingContainer + "alllstCounty"))
					document.getElementById(locfieldsNamingContainer + "alllstCounty").value = "";
			}
		}
	
		if(checkSearchParam() == true)
		{	
			// post back the page
			__doPostBack(PostBackControlName,"");
		}
		else
		{
			return false;
		}
	}	
	function SetMapSearchValues(Scope, Action) {

		// Scope = rect or fullmap
		// Action is the Pan or Zoom value
		var useDropdown=false;
		var MapID = "";
		// These arrays are also defined in MapCentral.cs
		var DiffLatArray = new Array(0.002995, 0.007986, 0.024956, 0.059895, 0.262040, 0.831898, 1.6471406);
		var DiffLongArray = new Array(0.003790, 0.010106, 0.031574, 0.075742, 0.330473, 1.041265, 2.082579);
		// construct the map search criteria value	
		MapImg = document.getElementById(mainNamingContainer + "MainMap");
		var strMapImgSrc = new String(MapImg.src);
		if(strMapImgSrc.length > 29 && strMapImgSrc.indexOf('=') != -1 && strMapImgSrc.indexOf('mapid') != -1) {
			MapID = strMapImgSrc.substring(strMapImgSrc.indexOf("mapid=")+6,strMapImgSrc.indexOf("&LastLat"));
			LastLat = strMapImgSrc.substring(strMapImgSrc.indexOf("LastLat=")+8,strMapImgSrc.indexOf("&LastLong"));
			LastLong = strMapImgSrc.substring(strMapImgSrc.indexOf("LastLong=")+9,strMapImgSrc.indexOf("&DiffLat"));
			DiffLat = strMapImgSrc.substring(strMapImgSrc.indexOf("DiffLat=")+8,strMapImgSrc.indexOf("&DiffLong"));
			DiffLong = strMapImgSrc.substring(strMapImgSrc.indexOf("DiffLong=")+9,strMapImgSrc.indexOf("&point"));
		}
		else  // no map found, unable to zoom
			return;
		
		var XDown = document.getElementById(mainNamingContainer + "XDown");
		var YDown = document.getElementById(mainNamingContainer + "YDown");
		var XUp = document.getElementById(mainNamingContainer + "XUp");
		var YUp = document.getElementById(mainNamingContainer + "YUp");
		
		imgPosition = ElementUtil.getElementPosition(MapImg);
		imgDimension = ElementUtil.getElementDimension(MapImg); 
		if(Scope == "fullmap" || (XDown.value == XUp.value && YDown.value == YUp.value))
		{
			// Remember the current Rectangle in case it is still used
			OrigXDown = XDown.value;
			OrigXUp = XUp.value;
			OrigYDown = YDown.value;
			OrigYUp = YUp.value;
			OrigDiffLat = DiffLat;
			OrigDiffLong = DiffLong;
		 	// Use full map coord in search
			XDown.value = imgPosition.left;
			XUp.value = imgPosition.left + imgDimension.width;
			YDown.value = imgPosition.top;
			YUp.value = imgPosition.top + imgDimension.height;
			
			var bZooming = false;

			switch (Action)
			{
				case "Scale0":
					DiffLat = DiffLatArray[0];
					DiffLong = DiffLongArray[0];
					bZooming = true;
					break;
				case "Scale1":
					DiffLat = DiffLatArray[1];
					DiffLong = DiffLongArray[1];
					bZooming = true;
					break;
				case "Scale2":
					DiffLat = DiffLatArray[2];
					DiffLong = DiffLongArray[2];
					bZooming = true;
					break;
				case "Scale3":
					DiffLat = DiffLatArray[3];
					DiffLong = DiffLongArray[3];
					bZooming = true;
					break;
				case "Scale4":
					DiffLat = DiffLatArray[4];
					DiffLong = DiffLongArray[4];
					bZooming = true;
					break;
				case "Scale5":
					DiffLat = DiffLatArray[5];
					DiffLong = DiffLongArray[5];
					bZooming = true;
					break;
				case "Scale6":
					DiffLat = DiffLatArray[6];
					DiffLong = DiffLongArray[6];
					bZooming = true;
					break;				
				case "ZoomIn":
					// get current scale
					for(var i=0; i<DiffLatArray.length; i++)
					{
						if(DiffLatArray[i] == DiffLat)
							currScale = i;
					}
					// decrement scale if possible
					if (currScale > 0) 
						currScale--;
					DiffLat = DiffLatArray[currScale];
					DiffLong = DiffLongArray[currScale];
					bZooming = true;
					break; 
				case "ZoomOut":
					// get current scale
					for(var i=0; i<DiffLatArray.length; i++)
					{
						if(DiffLatArray[i] == DiffLat)
							currScale = i;
					}
					// increment scale if possible
					if (currScale < 6) 
						currScale++;
					DiffLat = DiffLatArray[currScale];
					DiffLong = DiffLongArray[currScale];
					bZooming = true;
					break; 
				case "N":
					YDown.value = imgPosition.top - imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height - imgDimension.height/4;
					break;
				case "NE":
					XDown.value = imgPosition.left + imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width + imgDimension.width/4;
					YDown.value = imgPosition.top - imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height - imgDimension.height/4;
					break;
				case "E":
					XDown.value = imgPosition.left + imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width + imgDimension.width/4;
					break;
				case "SE":
					XDown.value = imgPosition.left + imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width + imgDimension.width/4;
					YDown.value = imgPosition.top + imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height + imgDimension.height/4;
					break;
				case "S":
					YDown.value = imgPosition.top + imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height + imgDimension.height/4;
					break;
				case "SW":
					XDown.value = imgPosition.left - imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width - imgDimension.width/4;
					YDown.value = imgPosition.top + imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height + imgDimension.height/4;
					break;
				case "W":
					XDown.value = imgPosition.left - imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width - imgDimension.width/4;
					break;
				case "NW":
					XDown.value = imgPosition.left - imgDimension.width/4;
					XUp.value = imgPosition.left + imgDimension.width - imgDimension.width/4;
					YDown.value = imgPosition.top - imgDimension.height/4;
					YUp.value = imgPosition.top + imgDimension.height - imgDimension.height/4;
					break;
				default:
					// do nothing
					break;
			}
			if (bZooming)
			{
				XDown.value = imgPosition.left;
				XUp.value = imgPosition.left + imgDimension.width;
				YDown.value = imgPosition.top;
				YUp.value = imgPosition.top + imgDimension.height;
			}
		}
		if (XDown.value != "") {
		
			// set the values on the search page		
			eMapID = document.getElementById(mainNamingContainer + "allignmapid");			
			eMinLat = document.getElementById(mainNamingContainer + "allminlatitude");
			eMaxLat = document.getElementById(mainNamingContainer + "allmaxlatitude");
			eMinLong = document.getElementById(mainNamingContainer + "allminlongitude");
			eMaxLong = document.getElementById(mainNamingContainer + "allmaxlongitude");
			eLastLat = document.getElementById(mainNamingContainer + "allignlastlat");
			eLastLong = document.getElementById(mainNamingContainer + "allignlastlong");
			eDiffLat = document.getElementById(mainNamingContainer + "alligndifflat");
			eDiffLong = document.getElementById(mainNamingContainer + "alligndifflong");
			eMapID.value = MapID;
			eLastLat.value = LastLat;
			eLastLong.value = LastLong;
			eDiffLat.value = DiffLat;
			eDiffLong.value = DiffLong; 

			var CenterX = imgDimension.width/2 + imgPosition.left;
			var CenterY = imgDimension.height/2 + imgPosition.top;	
			var xd = (XDown.value - CenterX) * DiffLong*2/imgDimension.width + parseFloat(LastLong);
			var yd = (CenterY - YDown.value) * DiffLat*2/imgDimension.height + parseFloat(LastLat);
			var xu = (XUp.value - CenterX) * DiffLong*2/imgDimension.width + parseFloat(LastLong);
			var yu = (CenterY - YUp.value) * DiffLat*2/imgDimension.height + parseFloat(LastLat);

			if (xd < xu) {
				eMinLong.value = xd;
				eMaxLong.value = xu;
			}
			else if (xd > xu) {
				eMinLong.value = xu;
				eMaxLong.value = xd;
			}
			if (yd < yu) {
				eMinLat.value = yd;
				eMaxLat.value = yu;
			}
			else if (yd > yu) {
				eMinLat.value = yu;
				eMaxLat.value = yd;
			}	
			// clear the city, county and zip fields
			if (document.getElementById(locfieldsNamingContainer + "alllstCity"))
				document.getElementById(locfieldsNamingContainer + "alllstCity").value = "";
			if (document.getElementById(locfieldsNamingContainer + "alllstPostalCode"))
				document.getElementById(locfieldsNamingContainer + "alllstPostalCode").value = "";
			if (document.getElementById(locfieldsNamingContainer + "allstrCounty"))
				document.getElementById(locfieldsNamingContainer+ "allstrCounty").value = "";
			else if(document.getElementById(locfieldsNamingContainer + "alllstCounty"))
				document.getElementById(locfieldsNamingContainer + "alllstCounty").value = "";
			// get center of rectangle for zooming
			document.forms[0].x.value = Math.round((parseInt(XDown.value) + parseInt(XUp.value))/2) - parseInt(imgPosition.left);
			document.forms[0].y.value = Math.round((parseInt(YDown.value) + parseInt(YUp.value))/2) - parseInt(imgPosition.top);
		}
		// post back the page
		if(Scope == "fullmap")
			return true;
		else
			__doPostBack("MapSearchCriteria","");
      } 

// Customize map pan/zoom functionality
function MM_swapImgRestore() {
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() {
	var d=document; 
	if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
	 for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document;
	n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);
	i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
	if(!x.oSrc) x.oSrc=x.src;
	x.src=a[i+2];}
}

function ScaleBtnClick(ScaleBtnID){
	if(checkSearchParam() == true)
	{
		maxLatitude = document.getElementById(mainNamingContainer + "allmaxlatitude");
		if(maxLatitude != null)
			SetMapSearchValues("fullmap", ScaleBtnID);
		document.forms[0].ScaleBtn.value = ScaleBtnID;
		document.forms[0].submit();
	}
}

function PanBtnClick(PanBtnID){
	if(checkSearchParam() == true)
	{
		maxLatitude = document.getElementById(mainNamingContainer + "allmaxlatitude");
		if(maxLatitude != null)
			SetMapSearchValues("fullmap", PanBtnID);
		document.forms[0].PanBtn.value = PanBtnID;
		document.forms[0].submit();
	}
}
function PropDetail(theUrl) {   
	document.location.href = theUrl;
}
function toggleInstructionsImg(){
	if($('imgShowHidedivInstructions').src.indexOf('detail_expand_icon.gif')>0){
		$('imgShowHidedivInstructions').src ='/images/detail_close_icon.gif'
	}else{
		$('imgShowHidedivInstructions').src ='/images/detail_expand_icon.gif'
	}
}
function toggleInstructions(){
	Effect.toggle('divInstructions', 'slide', { beforeStart: toggleInstructionsImg});
}
function showHide(DivName)
{
	HiddenCtrl = document.getElementById(mainNamingContainer.substring(0, mainNamingContainer.indexOf("MapSearch")) + "show" + DivName);
	DivCtrl = document.getElementById(mainNamingContainer.substring(0, mainNamingContainer.indexOf("MapSearch")) + DivName);
	if (DivCtrl == null)
		DivCtrl = document.getElementById(DivName);
	ImgAdvSearch = document.getElementById("imgShowHide" + DivName);
	if(HiddenCtrl != null)
	{
		// flip the visibility
		if(HiddenCtrl.value == "true")
		{
			DivCtrl.style.display = "none";
			HiddenCtrl.value = "false";
			ImgAdvSearch.src="/images/detail_expand_icon.gif";
		}
		else
		{
			DivCtrl.style.display = "";
			HiddenCtrl.value = "true";
			ImgAdvSearch.src="/images/detail_close_icon.gif";
			
			if(DivName == "AdvSearch" && document.getElementById("Cat") != null)
			{
				category = document.getElementById("Cat").options[document.getElementById("Cat").selectedIndex].value;
				DivCtrl = document.getElementById("as_" + category);
				DivCtrl.style.display = "";			
			} 
		}
		// Set expiration days here
		var expiredays = 365;
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		setCookie( DivName, HiddenCtrl.value, ExpireDate );
	}
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function ClickBin(FieldName)
{
	var cb = document.getElementsByName(FieldName);
	
	var BitMaskSum = "";
	for(i=0; i<cb.length; i++)
	{
		if (cb[i].checked)
		{
			myValue = cb[i].value;
			if(BitMaskSum == "")
				BitMaskSum = myValue;
			else
			{
				BitMaskSum = BitMaskSum + "|" + myValue + "";
				// this doesn't always work, so handle it in c# instead
				//BitMaskSum = BitMaskSum|myValue;
			}
		}
	}
	
	var iB = FieldName.indexOf("ign");
	if(iB != -1)
	{
		// set the actual value to use in the search field
		hidden = document.getElementById(FieldName.substring(0,iB) + "bin" + FieldName.substring(iB+3,FieldName.length));
		hidden.value = BitMaskSum;
	}
}	
function ASDdlChanged(FieldName)
{
	var Ddl = document.getElementById(FieldName);
	var iB = FieldName.indexOf("ign");
	var Type, myLabel="";
		
	var BitMaskSum = "";
	var myLabel = "";

	for(i=0; i<Ddl.length;i++)
	{
		if (Ddl.options[i].selected)
		{
			myValue = Ddl[i].value;
	
			if(BitMaskSum == "")
				BitMaskSum = myValue;
			else
				BitMaskSum = BitMaskSum|myValue;
		}
	}
	// set the actual value to use in the search field
	if(iB != -1)
		Hdn = document.getElementById(FieldName.substring(0,iB) + "bin" + FieldName.substring(iB+3,FieldName.length));
	if(Hdn)
		Hdn.value = BitMaskSum;
}
function ViewResults(resultsUrl)
{
	document.forms[0].action = resultsUrl;
	document.forms[0].__VIEWSTATE.name = "Previous__VIEWSTATE";
	document.forms[0].submit();
}

function Cnvrt(fld){
	var key_index;
	if(moz)
		key_index = e.which;
	else
		key_index = window.event.keyCode;
	var Element = document.getElementById(fld);
	if(Element.value == ".")
		Element.value = "0."
	var AcreElement, SqFtElement;
	
	if(fld.indexOf("ign") != -1) {
		calcAcres = true
		AcreElement = document.getElementById(fld.replace("ign",""));
	}
	else {
		calcAcres = false
		SqFtElement = document.getElementById(fld.substring(0, fld.length - 17) + "ign" + fld.substring(fld.length - 17));
	}
	
	if (isNaN(Element.value) || Element.value.length == 0)
	{
		if(Element.value.length > 0){
			Element.value = '';
			if (key_index != 8) // allow backspacing
				alert ("Could you please enter a Numeric Value?  Thank you. ");
		}
		
		if(AcreElement)
			AcreElement.value = '';			
		else if(SqFtElement)
			SqFtElement.value = ''; 
						
		Element.focus();
	}
	else
	{
		var tval = parseFloat(Element.value);
		if (calcAcres)
		{
			var tacres = (tval/43559.83);
			if(AcreElement)
				AcreElement.value = Math.round(tacres * 100)/100;
		}
		else
		{
			var tsrft = (tval * 43559.83)
			if(SqFtElement)
				SqFtElement.value = Math.floor(parseFloat(tsrft));
		}
	}	
}

function validateStateZip(strPostalCode, strState)
{
	// validate postal code
	switch (strState) { 
			case "CA":
				if(strPostalCode.indexOf("90") != 0 && strPostalCode.indexOf("91") != 0 && strPostalCode.indexOf("92") != 0
					&& strPostalCode.indexOf("93") != 0 && strPostalCode.indexOf("94") != 0 && strPostalCode.indexOf("95") != 0
					&& strPostalCode.indexOf("960") != 0 && strPostalCode.indexOf("961") != 0)
				{
					return "- " + strPostalCode + " is not a valid California zip code.\n";
				}
				break;
			case "NV":
				if(strPostalCode.indexOf("889") != 0 && strPostalCode.indexOf("89") != 0)
				{
					return "- " + strPostalCode + " is not a valid Nevada zip code.\n";
				}
				break;
			case "TX":
				if(strPostalCode.indexOf("733") != 0 && strPostalCode.indexOf("75") != 0 && strPostalCode.indexOf("76") != 0
						&& strPostalCode.indexOf("77") != 0 && strPostalCode.indexOf("78") != 0 && strPostalCode.indexOf("79") != 0
						&& strPostalCode.indexOf("885") != 0)
				{
					return "- " + strPostalCode + " is not a valid Texas zip code.\n";
				}
				break;
			case "AZ":
				if (strPostalCode.indexOf("85") != 0 && strPostalCode.indexOf("86") != 0)
				{
					return "- " + strPostalCode + " is not a valid Arizona zip code.\n";
				}
				break;
			default:
				break;		
	}
	return "";
} 
function checkSearchParam()
{
	if(locfieldsNamingContainer==null){
		locfieldsNamingContainer="";
	}
	if(mainNamingContainer==null){
		mainNamingContainer="";
	}


	var ErrorTxt = "";
	var minPrice, maxPrice, minPriceVal, maxPriceVal, strCat
	var bValidData = true;
	if(document.getElementById("Cat") != null)
	{
		if(document.getElementById("Cat").type == "select-one")
			strCat = document.getElementById("Cat").options[document.getElementById("Cat").selectedIndex].value;
		else
			strCat = document.getElementById("Cat").value;
	}
	if(document.getElementById(locfieldsNamingContainer + "alllstCity") != null)
	{
		var strCity = document.getElementById(locfieldsNamingContainer + "alllstCity").value;
		if(strCity != "")
		{
			var ret = strCity.search(/[^-a-zA-Z ,'.]/);
			if(ret != -1)
				ErrorTxt = ErrorTxt + "- City must be a comma-separated list of city name(s)\n";
		}		
	}
	if(document.getElementById(locfieldsNamingContainer + "alllstPostalCode") != null)
	{
		var alllstPostalCode = document.getElementById(locfieldsNamingContainer + "alllstPostalCode");
		var strPostalCodes = alllstPostalCode.value;
		var bInvalidZip = false;
		
		if(document.getElementById(locfieldsNamingContainer + "alllstStateOrProvince") != null){
			var strState = document.getElementById(locfieldsNamingContainer + "alllstStateOrProvince").options[document.getElementById(locfieldsNamingContainer + "alllstStateOrProvince").selectedIndex].value;
		}
		
		if(strPostalCodes != "")
		{
			var zipCheck = strPostalCodes.split(",");
			for(i=0;i<zipCheck.length;i++)
			{
				zipCheck[i] = zipCheck[i].replace(/\s/,"");
				ErrorTxt = ErrorTxt + validateStateZip(zipCheck[i], strState);
				if(isNaN(zipCheck[i]) || zipCheck[i].length != 5)
					bInvalidZip = true;
			}
			if(bInvalidZip)
				ErrorTxt = ErrorTxt + "- Zip code must be a comma-separated list of 5 digit numeric value(s)\n";
		}
	}
	minPrice = document.getElementById("allminListPrice");
	maxPrice = document.getElementById("allmaxListPrice");
	if(minPrice != null && maxPrice != null)
	{
		minPriceVal = parseInt(minPrice.value);
		maxPriceVal = parseInt(maxPrice.value);
		if(minPrice.value != "" && maxPrice.value != "" && minPriceVal > maxPriceVal)
			ErrorTxt = ErrorTxt + "- Price range minimum value must be less than the maximum\n";
	}
	ignminListPrice = document.getElementById("ignminListPrice");
	if(ignminListPrice != null)
	{
		// no msg -- alert is handled by control
		if (ignminListPrice.value != "" && isNaN(ignminListPrice.value))
			bValidData = false;
	}
	ignmaxListPrice = document.getElementById("ignmaxListPrice");
	if(ignmaxListPrice != null)
	{
		// no msg -- alert is handled by control
		if (ignmaxListPrice.value != "" && isNaN(ignmaxListPrice.value))
			bValidData = false;
	}
	var lstType = document.getElementById(strCat + "lstType");
	if(lstType != null && lstType.selectedIndex == -1)
		ErrorTxt = ErrorTxt + "- Please select a property type\n";
	var minBedrooms = document.getElementById(strCat + "minBedrooms");
	var maxBedrooms = document.getElementById(strCat + "maxBedrooms");
	if(minBedrooms != null && maxBedrooms != null)
	{
		if(minBedrooms.value != "" && maxBedrooms.value != "" && parseInt(minBedrooms.value) > parseInt(maxBedrooms.value))
			ErrorTxt = ErrorTxt + "- Bedrooms minimum value must be less than the maximum\n";
	}
	var minBathsFull = document.getElementById(strCat + "minBathsFull");
	var maxBathsFull = document.getElementById(strCat + "maxBathsFull");
	if(minBathsFull != null && maxBathsFull != null)
	{
		if(minBathsFull.value != "" && maxBathsFull.value != "" && parseInt(minBathsFull.value) > parseInt(maxBathsFull.value))
			ErrorTxt = ErrorTxt + "- Bathrooms minimum value must be less than the maximum\n";
	}
	var minStories = document.getElementById(strCat + "minStories");
	var maxStories = document.getElementById(strCat + "maxStories");
	if(minStories != null && maxStories != null)
	{
		if(minStories.value != "" && maxStories.value != "" && parseInt(minStories.value) > parseInt(maxStories.value))
			ErrorTxt = ErrorTxt + "- Stories minimum value must be less than the maximum\n";
	}
	var minYearBuilt = document.getElementById(strCat + "minYearBuilt");
	var maxYearBuilt = document.getElementById(strCat + "maxYearBuilt");
	if(minYearBuilt != null && maxYearBuilt != null)
	{
		var today = new Date();
		if(isNaN(minYearBuilt.value))
			ErrorTxt = ErrorTxt + "- Minimum Year Built value must be numeric\n";
		else if(minYearBuilt.value != "" && minYearBuilt.value.length != 4)
			ErrorTxt = ErrorTxt + "- Minimum Year Built value must be four digits\n";
		else if(minYearBuilt.value > today.getFullYear())
			ErrorTxt = ErrorTxt + "- Minimum Year Built value must not be greater than " + today.getFullYear() + "\n";
		if(isNaN(maxYearBuilt.value))
			ErrorTxt = ErrorTxt + "- Maximum Year Built value must be numeric\n";
		else if(maxYearBuilt.value != "" && maxYearBuilt.value.length != 4)
			ErrorTxt = ErrorTxt + "- Maximum Year Built value must be four digits\n";
		else if(maxYearBuilt.value > today.getFullYear())
			ErrorTxt = ErrorTxt + "- Maximum Year Built value must not be greater than " + today.getFullYear() + "\n";
		if(minYearBuilt.value != "")
			minYearBuilt.value = Math.round(minYearBuilt.value);
		if(maxYearBuilt.value != "")
			maxYearBuilt.value = Math.round(maxYearBuilt.value);
		if(minYearBuilt.value != "" && maxYearBuilt.value != "" && parseInt(minYearBuilt.value) > parseInt(maxYearBuilt.value))
			ErrorTxt = ErrorTxt + "- Year Built minumum value must be less than the maximum\n";
	}
	var minLivingArea = document.getElementById(strCat + "minLivingArea");
	var maxLivingArea = document.getElementById(strCat + "maxLivingArea");
	if(minLivingArea != null && maxLivingArea != null)
	{
		minLivingArea.value = minLivingArea.value.replace(/,/g, "");
		maxLivingArea.value = maxLivingArea.value.replace(/,/g, "");
		if(isNaN(minLivingArea.value))
			ErrorTxt = ErrorTxt + "- Square Feet minimum value must be numeric\n";
		else if(minLivingArea.value != "")
			minLivingArea.value = Math.round(minLivingArea.value);
		if(isNaN(maxLivingArea.value))
			ErrorTxt = ErrorTxt + "- Square Feet maximum value must be numeric\n";
		else if(maxLivingArea.value != "")
			maxLivingArea.value = Math.round(maxLivingArea.value);
		if(minLivingArea.value != "" && maxLivingArea.value != "" && parseInt(minLivingArea.value) > parseInt(maxLivingArea.value))
			ErrorTxt = ErrorTxt + "- Square Feet minimum value must be less than the maximum\n";
	}
	var minLotSizeAcre = document.getElementById(strCat + "minLotSizeAcre");
	var maxLotSizeAcre = document.getElementById(strCat + "maxLotSizeAcre");
	if(minLotSizeAcre != null && minLotSizeAcre.value != "" && isNaN(minLotSizeAcre.value))
		ErrorTxt = ErrorTxt + "- Lot size minimum value must be numeric\n";
	if(maxLotSizeAcre != null && maxLotSizeAcre.value != "" && isNaN(maxLotSizeAcre.value))
		ErrorTxt = ErrorTxt + "- Lot size maximum value must be numeric\n";
	if(minLotSizeAcre != null && maxLotSizeAcre != null)
	{
		if(minLotSizeAcre.value != "" && maxLotSizeAcre.value != "" && parseFloat(minLotSizeAcre.value) > parseFloat(maxLotSizeAcre.value))
			ErrorTxt = ErrorTxt + "- Lot size minimum value must be less than the maximum\n";
	}
	if(document.getElementById("alllstMLSListingID") != null)
	{
		var alllstMLSListingID = document.getElementById("alllstMLSListingID");
		if(alllstMLSListingID.value != "")
		{
			alllstMLSListingID.value = alllstMLSListingID.value.replace(/ /g, "");
			if (isNaN(alllstMLSListingID.value.replace(/,/g, "")) || alllstMLSListingID.value.indexOf(".") != -1)
				ErrorTxt = ErrorTxt + "- MLS Number must be a comma-separated list of numeric value(s)\n";
		}
	}
	if(ErrorTxt != "")
	{
		alert("Please fix the following errors:\n" + ErrorTxt);
		return false;
	}
	else if (bValidData)
		return true;
	else
		return false;		 
}


function viewPropDetail(ListingID, pageKey)
{
	XDown = document.getElementById(mainNamingContainer + "XDown").value;
    XUp = document.getElementById(mainNamingContainer + "XUp").value;
    YDown = document.getElementById(mainNamingContainer + "YDown").value;
    YUp = document.getElementById(mainNamingContainer + "YUp").value;
    //if((XDown == XUp && YDown == YUp) || moz)
    //{
		if(bIsWebTop)
		{
			var mlsid = ListingID.substring(0,ListingID.indexOf("-"))
			var listingid = ListingID.substring(ListingID.indexOf("-") + 1);
			var url = "/tools/wtmls/print_a1_photo.asp?mlsid=" + mlsid + "&mlslistingid=" + listingid;
			
			var windowParams = "height=600,width=800,left=50,top=50,scrollbars=yes,resizable=yes,toolbar=yes,location=yes,directories=no,status=yes,menubar=yes";
			window.open(url,"_new",windowParams);
		}
		else    
			//__doPostBack("detail",ListingID);
			gotoPage(pageKey + "?listingID=" + ListingID + "&src=propSearch");
	//}
}

function viewPropertyDetail(ListingID)
{
	viewPropDetail(ListingID, "/propertyDetail.aspx")
}


function viewExecutiveEstatesDetail(ListingID)
{

	viewPropDetail(ListingID, "/executiveEstatesDetail.aspx")
}
function fineHomesDetail(ListingID)
{
	viewPropDetail(ListingID, "/fineHomesDetail.aspx")
}
function goMap(varState)
{ 
	var varURL ;
	varURL = '/mlsmaps/mlsmapping'+varState+'.asp?state='+varState ;
	window.open(varURL,"my_new_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=800");
}

function InactiveMLS(statusControl)
	{//agents only see inactive in member MLS and MLSs not blocked to non-members
		var hdnFieldNamingContainer = "";
		if(mainNamingContainer.indexOf("MapSearch") != -1)
			hdnFieldNamingContainer = mainNamingContainer.substr(0,mainNamingContainer.indexOf("MapSearch"))
		var listStatus = window.document.getElementById(statusControl.id);
		if (listStatus != null)
		{
			// Find the MLS select menu in the form
			for(i=0; i<document.forms[0].elements.length; i++)
			{
				if(document.forms[0].elements[i].id.indexOf("alllstMLSID") != -1)
				{
					var listObj = document.forms[0].elements[i];
					break;
				}
			}
			var myStatus = listStatus.options[listStatus.selectedIndex].value;
			var listMLS;
			
			if((myStatus == "X")||(myStatus == "E")||(myStatus == "S")||(myStatus == "W"))
				listMLS = window.document.getElementById(hdnFieldNamingContainer + "InactiveMLSList");
			else
				listMLS = window.document.getElementById(hdnFieldNamingContainer + "ActiveMLSList");
			if (listMLS.value.length > 0)
			{
				var curSelect = listObj.options[listObj.selectedIndex].value
				var MLSArray = listMLS.value.split("|");
				listObj.options.length = 0;
				var newOpt0;
				newOpt0 = document.createElement("option");
				newOpt0.text = "ALL"
				listObj.options.add(newOpt0);
				listObj[0].value = "";
				
				for (var k = 1; k < MLSArray.length;)
				{
					var newOpt1;
					newOpt1 = document.createElement("option");
					newOpt1.text = MLSArray[k - 1]
					listObj.options.add(newOpt1);
					listObj[listObj.options.length - 1].value = MLSArray[k];
					k = k + 2;
					if (listObj[listObj.options.length - 1].value == curSelect)
					{
						listObj.selectedIndex = listObj.options.length - 1;
					}
				}
			}
		}
	}
	
	function ShowHide(tbl,img,span,hdn){
	var t = document.getElementById(tbl);
	var i = document.getElementById(img);
	var s = document.getElementById(span);
	var h = document.getElementById(hdn);
//alert('ShowHide() - asHdn=' + h.value + '.');
	if (h.value == "True") {
		t.style.display = "none";
		h.value = "False";
		i.src = "/images/detail_expand_icon.gif"; // -
		s.removeChild(s.lastChild);
		s.appendChild(document.createTextNode("More Search Options"));
	}
	else {
		t.style.display = "";
		h.value = "True";
		i.src = "/images/detail_close_icon.gif"; // +
		s.removeChild(s.lastChild);
		s.appendChild(document.createTextNode("Hide More Search Options"));
	}
}

function Cnvrt(Element){

	var tval = parseFloat(Element.value)
	if (isNaN (tval))
	{
		if(!isBlank(Element.value)){
			alert ("You must Enter a Numeric Value")
		}
		Element.value = ''
		Element.focus()
	} 
	
	else
	{
		if(Element.id.indexOf("_ign") != -1)
		{
			// convert sq ft to acres
			var tacres = (tval/43559.83);
			var regexp = /_ign/;
			AcresElement = document.getElementById(Element.id.replace(regexp, "_"));
			if(AcresElement != null)
				AcresElement.value = Math.round(100*tacres)/100;
		}
		else
		{
			// convert acres to sq ft
			var tsrft = (tval * 43559.83);
			var regexp1 = /_res/;
			var regexp2 = /_lnd/;
			if(Element.id.indexOf("_res") != -1)
			{
				SqFtElement = document.getElementById(Element.id.replace(regexp1, "_ignres"));
				if(SqFtElement != null)
					SqFtElement.value = Math.floor(parseFloat(tsrft));
			}
			else
			{
				SqFtElement = document.getElementById(Element.id.replace(regexp2, "_ignlnd"));
				if(SqFtElement != null)
					SqFtElement.value = Math.floor(parseFloat(tsrft));
			}
		}
	} 		  
}


function DSCHasMinTownshipCriteria(source, arguments){
	var formElements = document.__aspnetForm.elements; 
	for (i=0; i<formElements.length; i++) {
		if (formElements[i].id.indexOf("twntownship") > 0){
			myArr = formElements[i].id.split("_")
			myIndex = myArr[myArr.length-1]
			myCat = myArr[myArr.length-2].substr(0,3)
			myTownship = formElements[i].value
			myRange = eval("formElements['" + mainNamingContainer + myCat + "twnrange_" + myIndex + "'].value")
			mySection = eval("formElements['" + mainNamingContainer + myCat + "twnsection_" + myIndex + "'].value")
			if(!isBlank(myTownship) && (isBlank(myRange) || isBlank(mySection))){
				arguments.IsValid = false;
				formElements[i].focus();
				break;
			}else if(!isBlank(myRange) && (isBlank(myTownship) || isBlank(mySection))){
				arguments.IsValid = false;
				formElements[i].focus();
				break;
			}else if(!isBlank(mySection) && (isBlank(myTownship) || isBlank(myRange))){
				arguments.IsValid = false;
				formElements[i].focus();
				break;
			}else{
				arguments.IsValid = true;
			}
		}
	}
	
}

function DSCGetElementName(name){
	var retval="";
	arr = name.split("_");
	retval=arr[arr.length-1];
	return retval;
}

function DSCGetElementPrefix(name){
	var retval="";
	arr = name.split("_");
	for(i=0;i<arr.length-1;i++){
		retval+=arr[i]+"_";
	}
	return retval;
}

function DSCGetMinElement(name){
	var retval="";
	retval=name.substr(0,3) + "min" + name.substr(6,name.length);
	return retval;
}

function DSCGetMaxElement(name){
	var retval="";
	retval=name.substr(0,3) + "max" + name.substr(6,name.length);
	return retval;
}

function DSCCompareRangeDropDown(source, arguments)
{
	ElementName = DSCGetElementName(source.controltovalidate);
	Prefix = DSCGetElementPrefix(source.controltovalidate);
	MinElement = Prefix+DSCGetMinElement(ElementName);
	MaxElement = Prefix+DSCGetMaxElement(ElementName);

	myMin=eval("document.__aspnetForm."+MinElement);
	minVal = myMin[myMin.selectedIndex].value;

	myMax=eval("document.__aspnetForm."+MaxElement);
	maxVal = myMax[myMax.selectedIndex].value;	
	
	if((minVal.length>0)&&(maxVal.length>0)){
		if(parseInt(minVal)<=parseInt(maxVal)){
			arguments.IsValid = true;
		}else{
			arguments.IsValid = false;
			myMin.focus();
		}	
	}else{
		arguments.IsValid = true;
	}
}

function DSCRequired(source, arguments)
{	
	controltovalidate = source.id.substr(0,source.id.indexOf("Required"))
	ElementName = DSCGetElementPrefix(controltovalidate) + DSCGetElementName(controltovalidate);
	Element = eval("document.__aspnetForm."+ElementName)
	if(!isBlank(Element.value)){
		arguments.IsValid = true;
	}else{
		arguments.IsValid = false;
		Element.focus();
	}
}
function DSCHasMinPublicSearchCriteria(source, arguments)
{
	arguments.IsValid = true;
}

function DSCHasMinSearchCriteria(source, arguments)
{
	arguments.IsValid = true;
}
