var prevPreview="";
var preMap="";
var preOpenCloseTxt="";
var preButton="";
var preBkId=""
var preBkId1=""
var moreResult=0;
var viewResult=20;
var scrollCount=0;
var viewless=false;
var prevScrollTop=0;
//noOfprops=100;
 // Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousedown = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s
var http_request = false;
function getHTTPReq()
{
	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
}


   function getStandardResult(url, parameters) {
      
      getHTTPReq();
      http_request.onreadystatechange = updateResponse;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function updateResponse() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('contentRight').innerHTML = result; 
			document.getElementById('moreResult').style.display = 'none';  
		    document.getElementById('searchCount').style.display = 'none'; 
			document.getElementById('resultContainer').style.position = '';
			
			
         } else {
           // alert('There was a problem with the request.');
         }
      }
   }
   
   function getAdvanceResult(obj) {
     
	  var propertyType=document.searchFormS.propertyType.value;
	  var searchStreetName=document.searchFormS.searchStreetName.value;
	  var searchCounty=document.searchFormS.searchCounty_list.value;
	  var searchCity=document.searchFormS.searchCity_list.value;
	  var searchAreaDesc=document.searchFormS.searchAreaDesc_list.value;
	  var searchTownShip=document.searchFormS.searchTownShip_list.value;
	  var searchState='OH';
	  var searchZipCode=document.searchFormS.searchZipCode_list.value;
	  var searchElementarySchool=document.searchFormS.searchElementarySchool_list.value;
	  var searchHighSchool=document.searchFormS.searchHighSchool_list.value;
	  //var searchSchoolDistrict=document.searchFormS.propertyType.value;
	  var mlsNumber=document.searchFormS.mlsNumber.value;
	   
	    var searchMinPrice=document.searchFormS.searchMinPrice.value;
		var searchMaxPrice=document.searchFormS.searchMaxPrice.value;
		var searchBedRooms=document.searchFormS.searchBedRooms.value;
		var searchBathRooms=document.searchFormS.searchBathRooms.value;
		var searchMinSqft=document.searchFormS.searchMinSqft.value;
		var searchMaxSqft=document.searchFormS.searchMaxSqft.value;
		var searchHeating=document.searchFormS.searchHeating.value;
		var searchCooling=document.searchFormS.searchCooling.value;

		var searchHeatFuel=document.searchFormS.searchHeatFuel.value;
		var searchFirePlace=document.searchFormS.searchFirePlace.value;

		var searchFoundation=document.searchFormS.searchFoundation.value;
		var searchSewer=document.searchFormS.searchSewer.value;

		var garageLow=document.searchFormS.garageLow.value;
		var searchYearBuilt=document.searchFormS.searchYearBuilt.value;
		var searchminAcres=document.searchFormS.searchminAcres.value;
		var searchmaxAcres=document.searchFormS.searchmaxAcres.value;

		var searchRoof=document.searchFormS.searchRoof.value;
		var searchStyle=document.searchFormS.searchStyle.value;
		var searchExterior=document.searchFormS.searchExterior.value;
		var searchWater=document.searchFormS.searchWater.value;

var param1="searchMinPrice="+searchMinPrice+"&searchMaxPrice="+searchMaxPrice+"&searchBedRooms="+searchBedRooms+"&searchBathRooms="+searchBathRooms+"&searchMinSqft="+searchMinSqft+"&searchMaxSqft="+searchMaxSqft+"&searchHeating="+searchHeating+"&searchCooling="+searchCooling+"&searchHeatFuel="+searchHeatFuel+"&searchFirePlace="+searchFirePlace;
var param2=param1+"&searchFoundation="+searchFoundation+"&searchSewer="+searchSewer+"&garageLow="+garageLow+"&searchYearBuilt="+searchYearBuilt+"&searchminAcres="+searchminAcres+"&searchmaxAcres="+searchmaxAcres+"&searchRoof="+searchRoof+"&searchStyle="+searchStyle+"&searchExterior="+searchExterior+"&searchWater="+searchWater;
var poststr = "propertyType="+propertyType+"&searchAreaDesc="+searchAreaDesc+"&searchStreetName="+searchStreetName+"&searchCounty="+searchCounty+"&searchCity="+searchCity+"&searchState="+searchState+"&searchZipCode="+searchZipCode+"&searchElementarySchool="+searchElementarySchool+"&searchHighSchool="+searchHighSchool+"&mlsNumber="+mlsNumber+"&showNearBy=false&"+param2;
 // alert(poststr);
  getStandardResult(SearchUrl+'testResult.php', poststr);
   }


function showAdvanceResult(obj) {
     
	  var propertyType=document.searchForm.propertyType.value;
	  var searchStreetName=document.searchForm.searchStreetName.value;
	  
	  if(searchStreetName=="Address")
		  {
		  searchStreetName="";
		  }
	  
	  var searchHouseNo=document.searchForm.searchHouseNo.value;
	  
	  if(searchHouseNo=="Street"){searchHouseNo="";}
	  var searchCounty=document.searchForm.searchCounty.value;
	  
	  var searchCity=document.searchForm.searchCity.value;
	  var searchAreaDesc=document.searchForm.searchAreaDesc.value;

	  	   var tempArea = searchAreaDesc;
            tempArea = tempArea.replace(/&amp;/g,"&");
            tempArea = tempArea.replace(/&/g,"%26");
            searchAreaDesc=tempArea;

	  var searchTownShip=document.searchForm.searchTownShip.value;
	  var searchState='OH';
	  var searchZipCode=document.searchForm.searchZipCode.value;
	  var searchElementarySchool=document.searchForm.searchElementarySchool.value;
	  var searchHighSchool=document.searchForm.searchHighSchool.value;
	  var searchSchoolDistrict=document.searchForm.searchSchoolDistrict.value;
	  var mlsNumber=document.searchForm.mlsNumber.value;
	        if(mlsNumber == "MLS #")
			  {
			  mlsNumber="";
			  }
	    var searchMinPrice=document.searchForm.searchMinPrice.value;
		var searchMaxPrice=document.searchForm.searchMaxPrice.value;
		var searchBedRooms=document.searchForm.searchBedRooms.value;
		var searchBathRooms=document.searchForm.searchBathRooms.value;
		var searchMinSqft=document.searchForm.searchMinSqft.value;
		var searchMaxSqft=document.searchForm.searchMaxSqft.value;
		var searchHeating=document.searchForm.searchHeating.value;
		var searchCooling=document.searchForm.searchCooling.value;

		var searchHeatFuel=document.searchForm.searchHeatFuel.value;
		var searchFirePlace=document.searchForm.searchFirePlace.value;

		var searchFoundation=document.searchForm.searchFoundation.value;
		var searchSewer=document.searchForm.searchSewer.value;

		var garageLow=document.searchForm.garageLow.value;
		var searchYearBuilt=document.searchForm.searchYearBuilt.value;
		try{
		var searchAcres=document.searchForm.searchAcres.value;
		}catch(e){}
		var searchmaxAcres="";

		var searchRoof=document.searchForm.searchRoof.value;
		var searchStyle=document.searchForm.searchStyle.value;
		var searchExterior=document.searchForm.searchExterior.value;
		var searchWater=document.searchForm.searchWater.value;

		var searchHud=document.getElementById('searchHud').checked;
		var searchFixer=document.getElementById('searchFixer').checked;
		var searchBank=document.getElementById('searchBank').checked;
		var searchAuction=document.getElementById('searchAuction').checked;
		var sortSeq=document.getElementById('sortBySeq').value;
		var sortOption=document.getElementById('sort').value;
		
        var searchOpenHouse=document.getElementById('openHouse').checked;

		if(searchOpenHouse==true)
	    {
		var openHouse=1;
		}
     
	 var listCount = 0;
	 var searchListing="";
        try {
            listCount = document.searchForm.searchListing.length;
        } catch(e) {}
        var tc = 0;
        for(var j=0;j<listCount; j++) {
            var chk = "";
            var tmpVal = "";
            chk = document.searchForm.searchListing[j].checked;
            if(chk) {
               tmpVal = document.searchForm.searchListing[j].value;
               if(tc == 0) {
                  searchListing = tmpVal;
               } else {
                  searchListing += ", "+ tmpVal;
               }
               tc++;
            }           
        }

/*
		var searchListing="";
			
			if(searchHud==true)
			{
			searchListing='HUD';
			}
			else if(searchFixer==true)
	        {
	        searchListing='Short Sales';
			}
			else if(searchBank==true)
	        {
	        searchListing='Bank Owned';
			}
			else if(searchAuction==true)
			{
			 searchListing='Auction';
			}
	*/

		//var searchListing=document.searchForm.searchListing.value;
		//alert(searchListing);

var param1="searchMinPrice="+searchMinPrice+"&searchMaxPrice="+searchMaxPrice+"&searchBedRooms="+searchBedRooms+"&searchBathRooms="+searchBathRooms+"&searchMinSqft="+searchMinSqft+"&searchMaxSqft="+searchMaxSqft+"&searchHeating="+searchHeating+"&searchCooling="+searchCooling+"&searchHeatFuel="+searchHeatFuel+"&searchFirePlace="+searchFirePlace;
var param2=param1+"&sort="+sortOption+"&sortSeq="+sortSeq+"&searchListing="+searchListing+"&searchFoundation="+searchFoundation+"&searchSewer="+searchSewer+"&garageLow="+garageLow+"&searchYearBuilt="+searchYearBuilt+"&searchAcres="+searchAcres+"&searchmaxAcres="+searchmaxAcres+"&searchRoof="+searchRoof+"&searchStyle="+searchStyle+"&searchExterior="+searchExterior+"&searchWater="+searchWater;
var poststr = "propertyType="+propertyType+"&searchAreaDesc="+searchAreaDesc+"&searchHouseNo="+searchHouseNo+"&searchStreetName="+searchStreetName+"&searchCounty="+searchCounty+"&searchCity="+searchCity+"&searchState="+searchState+"&searchZipCode="+searchZipCode+"&searchSchoolDistrict="+searchSchoolDistrict+"&searchElementarySchool="+searchElementarySchool+"&searchHighSchool="+searchHighSchool+"&mlsNumber="+mlsNumber+"&openHouse="+openHouse+"&showNearBy=false&"+param2;
 // alert(poststr);
  getStandardResult(SearchUrl+'testResult.php', poststr);
   }


function toggle(id,prev,butn,mapid,lat,lang,prow,photocount,imgPath,sliderID,mls) {

		var state = document.getElementById(id).style.display;
		
		if(prevPreview != id && prevPreview !="")
	     {
	     document.getElementById(preMap).innerHTML="";
		 document.getElementById(prevPreview).style.display = 'none';
		 document.getElementById(preOpenCloseTxt).innerHTML='Open Preview';
		 document.getElementById(preButton).src = "http://wellesbowen.com/search/images/bottom_arrow1.png";
		 document.getElementById(preBkId).style.background='none';
		 document.getElementById(preBkId1).style.background='none';
		 preBkId="";
		 }
	
			if (state == 'block') {
				document.getElementById(mapid).innerHTML="";
				document.getElementById(id).style.display = 'none';
				
				document.getElementById(prev).innerHTML='Open Preview';
				
				document.getElementById(butn).src ="http://wellesbowen.com/search/images/bottom_arrow1.png";
				preBkId=prow;
			} else {
				document.getElementById(id).style.display = 'block';
				document.getElementById(prow).style.background='#CCDCEB';//'rgb(221, 237, 182)';
				document.getElementById(id).style.background='#CCDCEB';//'rgb(221, 237, 182)';
				prevPreview=id;
				preMap=mapid;
				preOpenCloseTxt=prev;
				preButton=butn;
				preBkId=prow;
				preBkId1=id;
				var divWidth = (photocount * 133) + 20;
                var sliderHtml="";
			 if(photocount > 0)
				{
					 var ct=2;
					 var img_path="";
					
					sliderHtml='<table width="'+divWidth+'" cellspacing="0" cellpadding="0" border="0"><tr>';
					for(var p=1; p < photocount; p++)
						{
						if(ct>9)
							{
							img_path= ct + ".jpg";
							imgPath1= imgPath + img_path;
							}
							else
							{
								img_path= "0"+ct + ".jpg";
								imgPath1= imgPath + img_path;
							
							}
							var lightBoxURL="http://wellesbowen.com/search/lightbox.php?mls="+mls+"&pos="+ct+"&imgcount="+photocount;
							
							sliderHtml = sliderHtml + '<td valign="top" class="details"><a href="'+lightBoxURL+'" title="'+imgPath1+'" onclick="return GB_show(\'\', this.href)"><img height="100px" width="133px" src="'+imgPath1+'"></a></td>';

							//sliderHtml = sliderHtml + '<td valign="top" class="details"><img height="100px" width="133px" src="'+imgPath1+'"></td>';
						  ct++;
						}
					sliderHtml = sliderHtml + "</tr></table>";
				try{
				document.getElementById(sliderID).innerHTML=sliderHtml;
				   }catch(e){}
				}

				document.getElementById(mapid).innerHTML='<iframe scrolling="no" height="146" frameborder="0" width="286" src="http://paqmule.com/search/google.php?lat='+lat+'&amp;lng='+lang+'"></iframe>';

				document.getElementById(prev).innerHTML='Close Preview';
		
				document.getElementById(butn).src = "http://wellesbowen.com/search/images/up_arrow2.gif";
				
			}
		}


function loadMap(add,map)
{

load(map);
}

function postSearchForm(val)
{
document.getElementById('sort').value=val;
document.searchForm.submit();
}

function postSearchFormAjax(val)
{
document.getElementById('sortBySeq').value=val;
document.getElementById('sort').value=val;
filterSearchResult();
}

function changeBackground(id)
{

document.getElementById(id).style.background='#CCDCEB';//'rgb(221, 237, 182)';
}

function changeBackgroundOut(id)
{
	if(preBkId != id)
	{
document.getElementById(id).style.background='none';
	}
}

function getMouseXY(e) {
	
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  document.getElementById('MouseY').value = tempY

	 //alert(tempY);
  return true
}

function OnScrollDiv () {
           var div = document.getElementById ("Search_resultContainer");
		   var scrollBt=div.scrollHeight - div.clientHeight;
		   
		   if(div.scrollTop==scrollBt)
	        {
							 
			 if(moreResult>20 || noOfprops1 > 20)
				{
			     viewResult=viewResult+20;
				}
				else
				{
				viewResult=moreResult;
				}

			if(noOfprops1 > 20 && noOfprops1 <= 40)
				{
				moreResult=noOfprops1 - 20;
				}
			else if(viewResult > noOfprops1)
				{
				moreResult = moreResult;
				}
			else
				{
				moreResult=noOfprops1 - viewResult;
				}

				//alert("More: "+ moreResult+" and  View :"+viewResult+" num:"+noOfprops1);

				if(moreResult > 0 && viewResult > 0 && viewResult < noOfprops1)
					{
				 
			     document.getElementById('moreResult').innerHTML='<div class="loading-indicator" style="position:absolute;left:420px;top:540px;width: 195px;background:#2F4E6E;color: #fff;"><img src="http://paqmule.com/search/images/largeLoader.gif" width="32" height="32" style="margin-right:5px;float:left;vertical-align:top;" alt="loader"><span id="loading-msg">Loading '+viewResult+' of '+noOfprops1+' Properties...</span> </div>"';
			     document.getElementById('moreResult').style.display='block';
				 //alert("More if : "+ moreResult+" and  View :"+viewResult+" num:"+noOfprops1);
				  //updateResultDiv(moreResult,viewResult);
				  updateResultDiv(moreResult,viewResult,'1');
					}
					else if(moreResult > 0 && moreResult <= 20 && viewResult > 0 && viewless == false)
				    {
					 viewless=true;
				     document.getElementById('moreResult').innerHTML='<div class="loading-indicator" style="position:absolute;left:420px;top:540px;width: 195px;background:#2F4E6E;color: #fff;"><img src="http://paqmule.com/search/images/largeLoader.gif" width="32" height="32" style="margin-right:5px;float:left;vertical-align:top;" alt="loader"><span id="loading-msg">Loading '+noOfprops1+' of '+noOfprops1+' Properties...</span> </div>"';
			         document.getElementById('moreResult').style.display='block';
				     // alert("More else : "+ moreResult+" and  View :"+viewResult+" num:"+noOfprops1);
				    // updateResultDiv(moreResult,noOfprops1);
					  updateResultDiv(moreResult,viewResult,'0');
				    }
                 
			}
		   //}
        //setFirstAndLast();
		scrollCount++;
		}





function getStandardMoreResult(url, parameters) {
      
      getHTTPReq();
      http_request.onreadystatechange = updateMoreResponse;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function updateMoreResponse() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;

            document.getElementById('Search_resultContainer').innerHTML = document.getElementById('Search_resultContainer').innerHTML + result; 
			document.getElementById('moreResult').style.display='none';
			//document.getElementById('loading').style.display = 'none';  
		    //document.getElementById('searchCount').style.display = 'none';  
			
         } else {
            //alert('There was a problem with the request.');
         }
      }
   }


function updateResultDiv(moreResult,viewResult,ismore)
{
var poststr = "moreResult="+moreResult+"&viewResult="+viewResult+"&isMore="+ismore;
  
  getStandardMoreResult(SearchUrl+'moreSearchResult.php', poststr);
}
