/*
Js contains all default functions concerning the house search
1. DETAIL HOUSE
2. FAVORITES
3. SEARCHBOX
4. SEARCHFILTERS
5. HISTORY
6. DRAWING
*/
/************************************ 1. DETAIL HOUSE */
var stopPhotoFade = 0;
var current_photo = 0;
var slideshowActive = false;
var photo_top = 'slide_photo1'
var photo_bottom = 'slide_photo2'

function FillAdditionalContentDropdown() {
  if(da('SelmapObjects') == null) return;
  if(da('mapObject')== null) return;
  if(da('searchOptionsContainer')== null) return;
  var mapObjectElements = getElementsByAttribute('mapObject','searchOptionsContainer','input');
  for(i = 0; i < mapObjectElements.length; i++) {
    var opt = document.createElement('option');
    opt.value = mapObjectElements[i].getAttribute('mapObject');
    opt.text = mapObjectElements[i].getAttribute('mapObjectCaption');
    da('SelmapObjects').options.add(opt, da('SelmapObjects').options.length);
  }
}

function initphotoslide()
{
  /*
  if (!slideshowActive)
  {
    slideshowActive=true;
    photos = getElementsByAttribute("photo", "detailHousePhotoLijstInner","img")
    photoArray = new Array();
    for(i=0;i<photos.length; i++)
    {
      photoArray[i] = photos[i].src;
    }

    current_photo = 0;
    count_photo = photoArray.length;
    photo1= photoArray[current_photo];
    photo2= photoArray[current_photo + 1];
    if (photo2>count_photo)
      photo2 = 0;
    da(photo_top).src=photo1
    da(photo_bottom).src=photo2
    da('detailHousePhoto2').style.display="none"
    da(photo_top).display="block";
    da(photo_bottom).display="block";
    alpha1=100;
    alpha2=0;
    da(photo_top).style.cssText = 'z-index: 3;filter:Alpha(opacity=100); -moz-opacity: 1;';
    da(photo_bottom).style.cssText = 'z-index: 2;filter:Alpha(opacity=0); -moz-opacity: 0;';
    stopPhotoFade = 1;
    setTimeout('resetPhotoFade()',500);
    setTimeout('startphotoslide('+alpha1+','+alpha2+')',500);
    da('slidemenuButton').value="Stop slideshow";
  }
  else
  {
    stopphotoslide();
  }
  */
}
function stopphotoslide()
{
  /*
  da('slidemenuButton').value="Start slideshow";
  slideshowActive = false;
  stopPhotoFade = 1

  photo_top = 'slide_photo1'
  photo_bottom = 'slide_photo2'


  da(photo_top).style.cssText = 'z-index: 3;filter:Alpha(opacity=100); -moz-opacity: 1;';
  da(photo_bottom).style.cssText = 'z-index: 2;filter:Alpha(opacity=0); -moz-opacity: 0;';
  da(photo_top).display="none";
  da(photo_bottom).display="none";
  da('detailHousePhoto2').style.display="block"
  */

}
function waitnextphotoslide()
{
  setTimeout('nextphotoslide()',1000);
}
function nextphotoslide()
{
  temp = photo_bottom;
  photo_bottom = photo_top;
  photo_top = temp;

  photos = getElementsByAttribute("photo", "detailHousePhotoLijstInner","img")
  photoArray = new Array();
  for(i=0;i<photos.length; i++)
  {
    photoArray[i] = photos[i].src;
  }
  current_photo ++;
  photo1= photoArray[current_photo];
  if (current_photo+1>=photoArray.length)
    current_photo = -1;
  photo2= photoArray[current_photo + 1];
  da(photo_bottom).src=photo2
  stopPhotoFade = 1;
  if(slideshowActive)
  {
    setTimeout('resetPhotoFade()',500);   // this triggers that photofades can take place again
    setTimeout('startphotoslide('+alpha1+','+alpha2+')',500);
  }
}
function resetPhotoFade()
{
  stopPhotoFade=0
}
function startphotoslide(alpha1,alpha2)
{
  if (slideshowActive)
  {
    alpha1 = alpha1- 10;
    alpha2 = alpha2+ 10;
    if (alpha1>50)
    {
      z1= 3;
      z2= 2;
    } else{
      z1= 2;
      z2= 3;
    }

    da(photo_top).style.cssText = 'z-index: '+z1+';filter:Alpha(opacity='+alpha1+'); -moz-opacity: 0.'+alpha1 + ';';
    da(photo_bottom).style.cssText = 'z-index: '+z2+';filter:Alpha(opacity='+alpha2+'); -moz-opacity: 0.'+alpha2 + ';';
    if ((alpha1>0) &&  stopPhotoFade==0)
    {
      setTimeout('startphotoslide('+alpha1+','+alpha2+')', 100)
    } else {
        da(photo_bottom).style.cssText = 'z-index: '+z2+';filter:Alpha(opacity=100); -moz-opacity: 1';
        waitnextphotoslide();
    }
  }
}

function showPhoto(src)
{
  // var photo = da('detailHousePhoto');
  // photo.src = src;
}

function showVirtualEarth()
{
  var photo = da('detailHousePhoto2');
  var virtualEarth = da('divVirtualEarth');
  photo.style.display = "none";

  virtualEarth.style.display = "block";

}

function showPhoto2(src)
{
  stopphotoslide()
  var photo = da('detailHousePhoto2');
  var virtualEarth = da('divVirtualEarth');
  photo.src = src;

  photo.style.display = "block";
//  virtualEarth.style.display = "none";
}
function getPreviousPhoto()
{
  if (typeof(currentphoto) =="undefined")
    currentphoto = 0
  var allphotos = da("allphotos").value.split(";")
  currentphoto--;
  if (currentphoto<0)
    currentphoto = allphotos.length - 1;
  showPhoto(allphotos[currentphoto]);


}
function fillPhotoArray()
{
  photoArray = new Array();
  currentPhoto=0;

  curElements = getElementsByAttribute("photoUrl", "detailHousePhotoLijstInner","img");
  for(i=0;i<curElements.length;i++)
  {
    photoArray.push(curElements[i].src);
  }
}


function getNextPhoto()
{
  if (typeof(currentphoto) =="undefined")
    currentphoto = 0;

  var allphotos = da("allphotos").value.split(";")
  currentphoto++;
  if (currentphoto>allphotos.length-1)
    currentphoto=0;
  showPhoto(allphotos[currentphoto]);
}

function changeTab(id)
{
  var n = 4;
  for (i=1;i<n+1;i++) {
    if (da('detailHouseTab'+i)!=null) {
      da('detailHouseTab'+i).className = "detailHouseTab";
      da('detailHouseContent'+i).className = "detailHouseContent";

      // da('detailHouseContent'+i).style.display="none";
      da('divTabAchter'+i).style.display="none";
      da('divTabVoor'+i).style.display="none";
    }
  }
  if (da('detailHouseTab'+id)!=null) {
    da('detailHouseTab'+id).className = "detailHouseTabActive";
    da('detailHouseContent'+id).className = "detailHouseContentActive";
    da('detailHouseContent'+id).style.display="block";

    da('divTabAchter'+id).style.display="inline";
    da('divTabVoor'+id).style.display="inline";
    da('divTabAchter'+id).style.width="6px";
    da('divTabVoor'+id).style.width="6px";
  }
  urchinTracker('Zoek/House/Tab'+id);

  hidediv('soldHousesTable');

  if(id == 3) {
    updateHistoryTab(4,4);
    getHistoryData(4,true,4);
    activateHistoryMenu();
    da('estimatePriceDuplicate').innerHTML = da('estimatePrice').innerHTML;
    try {
      da('estimatePriceDuplicate').removeChild(da('estimatePriceDuplicate').getElementsByTagName('img')[0]);
    }
    catch(err) {
      // alert(err);
    }
  }
  if (id==1)
    da('detailHouseContent').style.display="block"   //
  else
    da('detailHouseContent').style.display="none"

  hideNode('soldHousesButtons');

  if(id == 1){ //Show general map
   setTimeout(function () {
    showMapDetailTabGeneral(id);
   },250)

  }
}

function showPhoto(src)
{
  /*
  var photo = da('detailHousePhoto');
  photo.src = src;
  return;
  curElements = getElementsByAttribute("photoUrl", "detailHousePhotoLijstInner","img");
  for(i=0;i<curElements.length;i++)
  {
      curElements[i].className = "fotoScroll";
  }
  curElements[currentPhoto].className = "fotoScrollActive";
*/

}
function scroll(e)
{
  /*
  for (i=0;i< photoArray.length;i++)
  {
    if(photoArray[i]==e.src)
      currentPhoto = i;
  }
  showPhoto2(e.src);

  var par = da('detailHousePhotoLijstInner');
  var parTop = par.scrollTop;

  var border = 300;
  if (navigator.userAgent.indexOf("MSIE")>=0) border =175;

  if((e.offsetTop - parTop) < border)
  {
    intval = window.setInterval('da("detailHousePhotoLijstInner").scrollTop -= 11;', 9);
    window.setTimeout('stopScroll()', (e.clientHeight / 11) * 18);
  }
  else if((e.offsetTop - parTop) > border)
  {
    intval = window.setInterval('da("detailHousePhotoLijstInner").scrollTop += 11;', 9);
    window.setTimeout('stopScroll()', (e.clientHeight / 11) * 18);
  }
  */


}
function scrollUp()
{
  var parTop = da('detailHousePhotoLijstInner').scrollTop;
  da('scrollUp').style.display = 'block';
  var duration = 7;
  scrollTimer = 0;

  if (typeof(intval)!="undefined" && intval != null)
    window.clearInterval(intval);

  intval = window.setInterval('DoscrollInterVal(10,10)', 9);
  if (currentPhoto < photoArray.length-1)
    currentPhoto ++ ;
  showPhoto2(photoArray[currentPhoto])

}

function DoscrollInterVal(y, duration)
{
  scrollTimer ++;
  da("detailHousePhotoLijstInner").scrollTop += y;
  if (scrollTimer > duration)
  {
    stopScroll()
  }
}
function scrollDown()
{
  var parTop = da('detailHousePhotoLijstInner').scrollTop;
  var duration = 200;
  scrollTimer = 0

  if (parTop > 0)
    da('scrollUp').style.display = 'block';
  else
  {
    da('scrollUp').style.display = 'none';
    return;
  }
  if (typeof(intval)!="undefined" && intval != null)
    window.clearInterval(intval);
  intval = window.setInterval('DoscrollInterVal(-10,10)', 50);   // 9 -> 33
  if (currentPhoto > 0)
    currentPhoto--;


  showPhoto2(photoArray[currentPhoto])
}

function stopScroll()
{
  window.clearInterval(intval);
  intval = null;
}

function showMapDetailTabGeneral(id)
{
  detailmap = new XMap('_detailmap',false,true);
  currentMap = detailmap;
  detailmap.ShowDetailTabMap();
}


function getEstimatePrice(houseid)
{
  /*
  da('hDivPrijsToets').style.display = "none";
  var url= baseUrl + "/ajax/Housing/getEstimatePrice.aspx?tm=" + new Date().getTime() + "&houseid="+ houseid;
  xmlHttp = GetXmlHttpObject(gotEstimatePrice);
  setTimeout(function() {
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }, 1);
  */
}

function gotEstimatePrice()
{
  if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    if(xmlHttp.responseText != "") {
      da('estimatePrice').innerHTML = xmlHttp.responseText;

      //da('hDivPrijsToets').style.display = "block";
      //da('hDivPrijsToets').innerHTML = "<B>Direct Wonen Prijstoets:</B> " + xmlHttp.responseText + "<BR><i>De Direct Wonen prijstoetst neemt alle verkochte en te koop staande woningen in een straal van ongeveer 300 meter die overeenkomen met het aantal kamers en oppervlakte.</i>";
    }
  }
}

function getNumberOfHouses(soldHouses) {
  if(typeof(soldHouses)=="undefined")
    var houseURL = baseUrl + "/ajax/Housing/getSearchCount.aspx";
  else
    var houseURL = baseUrl + "/ajax/Housing/getSearchSoldCount.aspx";
  if(da('searchNew')!=null && da('searchNew').value=="1")
  {
    houseURL +="?new=1";
  }
  if(da('searchRss')!=null && da('searchRss').value!="")
  {
    houseURL +="?rss=" + da('searchRss').value;
  }
  if(da('HssId')!=null && da('HssId').value!="")
  {
    houseURL +="?HssId=" + da('HssId').value;
  }

  if (da('singleHouseOnMap') != null && da('singleHouseOnMap').value!="")
  {
    houseURL +="?Id=" + da('singleHouseOnMap').value;
  }
  if(da('hiddenBrokerId') != null && da('hiddenBrokerId').value != "") {
    houseURL +="?BrokerId=" + da('hiddenBrokerId').value + "&City="+da('hiddenCities').value;
  }
  var qrystring = location.search;
  if (qrystring.indexOf('BrokerId') > -1) {
    houseURL += qrystring + "&City="+da('hiddenCities').value;
  }

  xmlHttpObj2 = GetXmlHttpObject(gotNumberOfHouses);
  xmlHttpObj2.open("GET", houseURL, true);
  xmlHttpObj2.send(null);
}

function gotNumberOfHouses() {
  if((xmlHttpObj2.readyState == 4) || (xmlHttpObj2.readyState == 'complete')) {
    if(xmlHttpObj2.responseText != "") {

      if(!isNaN(xmlHttpObj2.responseText.match(/[0-9]+/)) && xmlHttpObj2.responseText.match(/[0-9]+/) != '') {
        CurrentCountHouse = parseInt(xmlHttpObj2.responseText.match(/[0-9]+/));
      }

      da('numberOfHouses').innerHTML= xmlHttpObj2.responseText;
      if(da('searchtext')!=null)
      {
        if (da('searchtext').innerHTML.indexOf(">")!=-1)
        {
          cinnerText = da('searchtext').innerHTML.substr(da('searchtext').innerHTML.indexOf(">") + 1, da('searchtext').innerHTML.length - da('searchtext').innerHTML.indexOf(">")+1)
          cinnerText = cinnerText.substr(0,  cinnerText.indexOf("<"))
          if(da('numberOfHouses2')) {
            da('numberOfHouses2').innerHTML = cinnerText
          }
        }
      }
      if(da('numberOfHouses')!=null)
      {
        da('numberOfHouses').style.display = "block";
        da('loadingNumberofHouses').style.display = "none";
      }
    }
  }
}
/************************************ 1. DETAIL HOUSE */


/************************************ 2. FAVORITES */
////setFavorite///
function setFavorite(id)
{
  url = "setFavorite.aspx";
  var url= baseUrl + "/ajax/Housing/"+url+"?tm=" + new Date().getTime() + "&a=a&id=" + id;

  xmlHttp = GetXmlHttpObject(new Function('settedFavorite("'+id+'")'));
  xmlHttp.open("GET", url , true);
  xmlHttp.send(null);
}

function settedFavorite(id)
{
  if((xmlHttp.readyState==4 || xmlHttp.readyState=="complete") && xmlHttp.status == 200)
  {
    if(xmlHttp.responseText != "")
    {
      response = xmlHttp.responseText;
      response = response.substring(5,response.length);
      //if(parseInt(response)==1)
        //showpopupbox("favorites.aspx",255)
      if(da('detailHouseRemoveFavorite')!=null)
        showNode('detailHouseRemoveFavorite');
      if(da('detailHouseSetFavorite')!=null)
      hideNode('detailHouseSetFavorite');
      if(da('fav'+id)!=null)
        showNode('fav'+id);
    }
  }
}

////removeFavorite///
function removeFavorite(id)
{

  url = "setFavorite.aspx";
  var url= baseUrl + "/ajax/Housing/"+url+"?tm=" + new Date().getTime() + "&a=d&id=" + id;

  xmlHttp = GetXmlHttpObject(new Function('removedFavorite("'+id+'")'));
  xmlHttp.open("GET", url , true)
  xmlHttp.send(null);
}

function removedFavorite(id)
{
  if((xmlHttp.readyState==4 || xmlHttp.readyState=="complete") && xmlHttp.status == 200)
  {
    if(xmlHttp.responseText != "")
    {
      hideNode('detailHouseRemoveFavorite');
      showNode('detailHouseSetFavorite');

      hideNode('fav'+id);
    }
  }
  else if(xmlHttp.readyState==4)
  {
    alert('Er heeft zich een fout voorgedaan. Probeer het later opnieuw.');
  }
}
/************************************ 2. FAVORITES */

////popup///
function openPopupbox(url,height,width)
{
  var popup = da('ifrmPopup');
  var ifrmleeg = da('legeIframe');
  popup.style.display = 'block';
  // ifrmleeg.style.display = 'block';
  if (height==null)
  {
    height = popup.clientHeight
  }
  if (width==null)
  {
    width = popup.clientWidth
  }
   /*
  ifrmleeg.style.pixelTop = 200;
  ifrmleeg.style.pixelLeft = 200;
  ifrmleeg.style.zIndex = 2000;
  ifrmleeg.style.width = popup.clientWidth;
  ifrmleeg.style.height = 400;
  */

  popup.style.height = height + "px";
  popup.style.width = width + "px";
  popup.style.pixelTop = getScrollTop() + 50;
  popup.style.pixelLeft = 400;
  popup.style.zIndex = 4000;
  popup.src = url;
}
////popup///

function openContentSegmentation(url)
{
  var popup = da('searchOptionsFrame');
  popup.style.display = "block";
  popup.src = url;
  parent.document.getElementById('pleaseWait6').style.display = 'none';
}

var moved = false;
function openContentSegmentation2(url)
{
  if (da("SelmapObjects").value!=0)
  {
    type = da("SelmapObjects").value;
    url += "?type="+type +"&source=1";
    var popup = da('searchOptionsFrame2');
    popup.style.display = "block";
    if(!moved) {
      var _left = popup.style.left.replace('px', '');
      _left = parseInt(_left) + 210;
      popup.style.left = _left + 'px';
      var _top = popup.style.top.replace('px', '');
      _top = parseInt(_top) - 25;
      popup.style.top = _top + 'px';
      moved = true;
    }
    popup.src = url;
    parent.document.getElementById('pleaseWait6').style.display = 'none';
  }
}

function getFavorites() {
  var url= baseUrl + "/ajax/Housing/getFavorites.aspx?tm=" + new Date().getTime();

  xmlHttp = GetXmlHttpObject(gotFavorites);
  xmlHttp.open("GET", url , true)
  xmlHttp.send(null);
}

function gotFavorites() {
  if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    response = xmlHttp.responseText.substring(5,response.length-1);;
    var countFavorites = response.split("|||||")[0];
    da('SbBarDetail3').innerHTML = response.split('|||||')[1];
  }
}

/************************************ 3. SEARCHBOX */
function updateSearchboxTab(e,c)
{
  //e = active number
  //c = count of tabs
  for(i=1;i<c+1;i++)
  {
    da('SbTab'+i).className = "SbTab";
    da('SbBarDetail'+i).className = "dn";
  }
  da('SbTab'+e).className = "SbTabActive";
  da('SbBarDetail'+e).className = "db";

  if(e == 2 && da('SbBarDetailContentWaarLinks4').className == "SbBarDetailContentWaarLinksTabActive") {
    initializeSearchboxMap();
  }

  if(e == 3) {
    getFavorites();
  }
}

function updateSearchboxTabWhere(e,c)
{
  //e = active number
  //c = count of tabs
  for(i=1;i<c+1;i++)
  {
    da('SbBarDetailContentWaarLinks'+i).className = "SbBarDetailContentWaarLinksTab";
    da('SbBarDetailContentWaarRechts'+i).className = "SbBarDetailContentWaarRechtsContent";
  }
  da('SbBarDetailContentWaarLinks'+e).className = "SbBarDetailContentWaarLinksTabActive";
  da('SbBarDetailContentWaarRechts'+e).className = "SbBarDetailContentWaarRechtsContentActive";

  da('hiddenSearchType').value = e;
}

function SearchOrderHover(e)
{
  if(e.className == "SbOrderActive")
    e.className = "SbOrderActiveHover";
  else
    e.className = "SbOrderHover";

  SearchOrderUpdateArrow(e)
}

function SearchOrderOut(e)
{
  if(e.className == "SbOrderActiveHover" || e.className == "SbOrderActive" )
  {
    e.className = "SbOrderActive";
    SearchOrderUpdateArrow(e);
  }
  else
  {
    e.className = "SbOrder";
    if(da("hiddenSortDirection").value == 2) {
      e.style.backgroundImage = 'url(/common/images_nieuw/SearchboxBarDetailSearchOrderDownInactive.gif)';
    }
    else {
      e.style.backgroundImage = 'url(/common/images_nieuw/SearchboxBarDetailSearchOrderUpInactive.gif)';
    }
  }

  if(da('SbOrder' + da('hiddenSortorder').value) != null) {
    SearchOrderUpdateArrow(da('SbOrder' + da('hiddenSortorder').value));
  }
}

function SearchOrderClick(e)
{
  da('SbOrderPrice').className = "SbOrder";
  da('SbOrderPrice').style.backgroundImage = '';
  da('SbOrderArea').className = "SbOrder";
  da('SbOrderArea').style.backgroundImage = '';
  da('SbOrderAddress').className = "SbOrder";
  da('SbOrderAddress').style.backgroundImage = '';
  da('SbOrderRooms').className = "SbOrder";
  da('SbOrderRooms').style.backgroundImage = '';
  da('SbOrderDateCreated').className = "SbOrder";
  da('SbOrderDateCreated').style.backgroundImage = '';
  da('SbOrderPriceSqrt').className = "SbOrder";
  da('SbOrderPriceSqrt').style.backgroundImage = '';

  e.className = "SbOrderActive";

  // When same item is being clicked, change the sort direction
  if (da('hiddenSortorder').value == e.getAttribute("Sortorder"))
    SearchOrderSwapAscDesc()

  da('hiddenSortorder').value = e.getAttribute("Sortorder")
  SearchOrderUpdateArrow(e);

  //Make an ajax call to set the tempOrder session object to the selected order
  var xmlHttp = GetXmlHttpObject(function() {
    try {
      getSearchresultsMap(0);
    }
    catch(err) {
      getSearchResultList(0);
    }
  });
  var order = e.getAttribute("Sortorder");
  var url = baseUrl + "/ajax/Housing/setSearchOrder.aspx?desc=" + da("hiddenSortDirection").value + "&order=" + order;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);

}

function SearchOrderSwapAscDesc()
{
  switch (parseInt(da("hiddenSortDirection").value))
  {
    case 1:
      da("hiddenSortDirection").value = 2;
      break;
    case 2:
      da("hiddenSortDirection").value = 1;
      break;
    default:
      da("hiddenSortDirection").value = 2;
      break;
  }
}

function SearchOrderUpdateArrow(e)
{
  if(da("hiddenSortDirection").value == 2) {
    e.style.backgroundImage = 'url(/common/images_nieuw/SearchboxBarDetailSearchOrderUp.gif)';
  }
  else {
    e.style.backgroundImage = 'url(/common/images_nieuw/SearchboxBarDetailSearchOrderDown.gif)';
  }

  e.style.backgroundRepeat = "no-repeat";
}

function setSearchView(searchview)
{
  var url = baseUrl + '/ajax/Housing/setSearchView.aspx?searchview=' + searchview + '&tm=' + new Date().getTime();
  xmlHttp = GetXmlHttpObject(empty);
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

function empty() { }

function initializeSearchboxMap() {
  /*
  var opts = {
    container: 'map',
    controls: ['zoom'],
    enableDrawing: true,
    startingPoint: coordNL,
    startingZoomLv: 7
  };

  var map = new GoogleMap(opts);
  if(!loading) {
    var polygonLoad = new AsyncCall(map, 1000, 'LoadPolygons', '');
    AsyncCall.asyncExecute(polygonLoad);
    delete polygonLoad;
  }
  */
}
/************************************ 3. SEARCHBOX */

function showPaging(count,totalPages,functionTodo)
{
  if(da('HssId')!=null && da('HssId').value!="" || da('searchRss')!=null && da('searchRss').value!="")
  {
    da('searchResultsMapPaging').style.display="none";
    da('sortorders').style.display="none";
  }
  if(da('searchRss')!=null && da('searchRss').value!="")
    da('sortorders').style.display="none";
  if (!functionTodo || typeof functionTodo=="undefined")
  {
    functionTodo = "getSearchresultsMap";
  }
  //Find current page number
  var currentPage = parseInt(da('toPage').value);
  //var nextPage = (((currentPage+1)*count)-count);
  var nextPage = currentPage+1;
  //var previousPage = (((currentPage-1)*count)-count);
  var previousPage = currentPage-1;
  if(previousPage == 0) previousPage = 1;
  var paging = " ";

  // Setup for navigation items. Left section, center section and right section
  var leftPages     = 6       // number of pages to show near 'previous' link
  var centerPages   = 6       // number of pages in 'center'
  var rightPages    = 6       // number of pages to show near 'next' link

  var linkList = new Array()
  var linkListitem = 0;
  var firstPage = 1;
  var lastPage = totalPages;

  //previous button
  if (previousPage-1>=0)
  {
//    paging += (currentPage == 0)? "":"<div class=\"searchPaginationPrevious\"><a  href=\"#bottom\" onclick=\""+functionTodo+"(" + (previousPage-1) + ");\"><img src=\"/common/images/bgBack.gif\"></a></div>";
    paging += (currentPage == 0)? "":"<div class=\"searchPaginationPrevious\"><a  href=\"#navtop\" onclick=\""+functionTodo+"(" + previousPage + ");\"><img src=\""+baseUrl+"/common/images/bgBack.gif\"></a></div>";
  }

  // Add all the pages that are displayed in one array
  // left section
  for (i=0;i<leftPages;i++)
  {
    linkList[linkListitem] = firstPage + i;
    linkListitem++ ;
  }
  // center section
  for (i=0;i<centerPages;i++)
  {
    center = parseInt( centerPages/2 ) + 1;
    linkList[linkListitem] = currentPage + ((i+1)-center);
    linkListitem++ ;
  }
  // right section
  for (i=0;i<rightPages;i++)
  {
    linkList[linkListitem] = lastPage - (rightPages-i-1);
    linkListitem++ ;
  }
  result = "";
  for (i=0; i<linkList.length ; i++ )
  {
     result += linkList[i] + ", ";
  }
  // remove overlap in the center part of the navigation
  for (i=leftPages;i<(leftPages+centerPages) ; i++)
  {
    countitem = 0 ;
    for (j=0;j<linkList.length; j++)
    {
      if (linkList[j]==linkList[i])
      {
        countitem ++;
      }
    }
    if (countitem>1)
    {
      // center number has overlapping, remove the item
      linkList[i]=0
    }
  }


  var nrOffdots = 0;
  result = "";
  for (i=0; i<linkList.length ; i++ )
  {
     result += linkList[i] + ", ";
  }
  for(i=1; i<=lastPage; i++)
  {

    var content = "";
    var hasLink = false;
    for (j=0;j<linkList.length;j++ )
    {
      style='searchresultNotSelected';
      if (i==linkList[j]  && hasLink==false)
      {
        // left section
        if (j==0)
         content +='<div class=\"searchPaginationCenter\">';
        // center section

        if (i==currentPage)
        {
          style = 'searchresultSelected'
        }

//        content += '&nbsp;<a href="#bottom" class="'+style+'" onclick="javascript:'+functionTodo+'('+ ((parseInt(i)*parseInt(count))-parseInt(count)) +');">'+i+'</a>&nbsp;';
        content += '&nbsp;<a href="#navtop" class="'+style+'" onclick="javascript:'+functionTodo+'('+ i +');">'+i+'</a>&nbsp;';
        hasLink = true;
      }
    }

    if (hasLink==false)
    {
      if (i == linkList[leftPages-1]+1 || i == linkList[leftPages+centerPages-1]+1)
      {
        content = "";
        content += " ... ";
      }
    }
    paging += content;
  }

  //Volgende button
  // nextPage
  if (nextPage < (lastPage * 6)) {
    paging += "</div><div class=\"searchPaginationNext\"><a href=\"#navtop\" onclick=\""+functionTodo+"(" + nextPage + ");\"><img src=\""+baseUrl+"/common/images/bgMore.gif\"></a></div><div id=c></div>";
  }
  return paging;
}


function InitSearchOrder()
{
  SortValue = da('hiddenSortorder').value
  if (da('SbOrderPrice').getAttribute("Sortorder") == SortValue)
  {
    da('SbOrderPrice').className = "SbOrderActive";
    SearchOrderUpdateArrow(da('SbOrderPrice'))
  }
  if (da('SbOrderArea').getAttribute("Sortorder") == SortValue)
  {
    da('SbOrderArea').className = "SbOrderActive";
    SearchOrderUpdateArrow(da('SbOrderArea'))
  }
  if (da('SbOrderRooms').getAttribute("Sortorder") == SortValue)
  {
    da('SbOrderRooms').className = "SbOrderActive";
    SearchOrderUpdateArrow(da('SbOrderRooms'))
  }
  if (da('SbOrderPriceSqrt').getAttribute("Sortorder") == SortValue)
  {
    da('SbOrderPriceSqrt').className = "SbOrderActive";
    SearchOrderUpdateArrow(da('SbOrderPriceSqrt'))
  }


}
var seperator = ";";
function da(o)
{
  return document.getElementById(o)
}
/************************************ 4. SEARCHFILTERS*/


// Create HTML markeup for the searchbox
// hiddenNr       = a hidden input containing the number of items
// values         = a hidden input containing the values that have been entered
// divInsert      = the location where the output is generated
// ItemPrefixName = the prefix name of each inputbox
// Type           = The type (which is being used in getItem)

// hiddenNr, values, itemprefixname and type can contain multiple values seperated with ||
var canRemove=true
function Init_Objects(hiddenNr, values, divInsert, ItemPrefixName,Type)
{
  hiddenNrArray = hiddenNr.split("||")
  valuesArray = values.split("||")
  ItemPrefixNameArray = ItemPrefixName.split("||")
  TypeArray = Type.split("||")

  da(divInsert).innerHTML = "";
  da(hiddenNrArray[0]).value = 0

  if (da(valuesArray[0]).value.indexOf(seperator)>=0)
  {
    cities = da(valuesArray[0]).value.split(seperator);
    x = "";
    for (i=1;i<=  cities.length;i++)
    {
      for (z=0; z<hiddenNrArray.length;z++)
      {
        cities = da(valuesArray[z]).value.split(seperator);
        da(hiddenNrArray[z]).value = cities.length
        // Generate the HTML part and insert this on the page
        if (cities[i-1])
        {
          cvalue = cities[i-1];
        } else {
          cvalue = "";
        }
        x+= getItem(i,cvalue,TypeArray[z],hiddenNr, values,divInsert,ItemPrefixName,Type);

        /*
        // update the value from the item
        */
      }
    }
    da(divInsert).innerHTML += x + "\n\n";
    slength= da(valuesArray[0]).value.split(seperator).length;
    if (da(valuesArray[1]))
    {
      if (da(valuesArray[1]).value.split(seperator).length > slength)
      {
        slength= da(valuesArray[1]).value.split(seperator).length;
      }
    }
    for (i=1;i<= slength;i++)
    {
      for (z=0; z<hiddenNrArray.length;z++)
      {
        cities = da(valuesArray[z]).value.split(seperator);
        obj = da(ItemPrefixNameArray[z]+""+i)
        if(obj!=null)
        {
          if (obj.type=="text")
          {
            if (cities[i-1])
              obj.value = cities[i-1]
          }
          if (obj.type=="select-one")
          {
            for (j=0;j<obj.options.length;j++)
            {
              if (obj.options[j].value==cities[i-1])
              {
                obj.options[j].setAttribute("selected","selected")
                obj.options[j].selected = true;
              }
            }
          }
        }
      }
    }

  }
  else
  {
    // Setup the default search box when no items have been added

    da(divInsert).innerHTML = "";
    content = "";
    for (z=0; z<hiddenNrArray.length;z++)
    {
      da(hiddenNrArray[z]).value = 1
      x = getItem(1,da(valuesArray[z]).value,TypeArray[z],hiddenNr, values,divInsert,ItemPrefixName,Type);
      content += x

    }
    da(divInsert).innerHTML += content;
    for (z=0; z<hiddenNrArray.length;z++)
    {
      obj = da(ItemPrefixNameArray[z] +"1")
      if (obj!=null)
      {
        if (obj.type=="select-one")
        {
          for (j=0;j<obj.options.length;j++)
          {
            if (obj.options[j].value==da(valuesArray[z]).value)
            {
              obj.options[j].setAttribute("selected","selected")
              obj.options[j].selected = true;
            }
          }
        }
     }
    }
  }
}

// Adding a single item within a specific type
// The add button is located on the inc_searchbox
function Add_Item(hiddenNr, values, divInsert,ItemPrefixName,Type)
{
  // Step one, grab all the values that have been entered and save this in the hidden fields
  hiddenNrArray = hiddenNr.split("||")
  valuesArray = values.split("||")
  ItemPrefixNameArray = ItemPrefixName.split("||")
  TypeArray = Type.split("||")
  for (z=0; z<hiddenNrArray.length;z++)
  {
    setHiddenfields(valuesArray[z],ItemPrefixNameArray[z])
  }

  // Step two, rebuild the existing HTML code
  // this is necessary for keep track of other fields that have been changed
  Init_Objects(hiddenNr, values, divInsert, ItemPrefixName,Type)
  content ="";
  // Step 3, add the new item
  for (z=0; z<hiddenNrArray.length;z++)
  {
    y = 0;
    y = parseInt(da(valuesArray[z]).value.split(seperator).length) + 1;
    // Exception:
    // When searching on Street add the last City entered as default value.
    if (Type.indexOf("||")>=0)
    {
      arrayvalues = da(valuesArray[z]).value.split(seperator)
      if (TypeArray[z]=="StreetCities")
      {
        // Excpetion, keep the last entered value
        lastvalue = arrayvalues[arrayvalues.length-1]
      }
      else
      {
        lastvalue = "";
      }
      x = getItem(y,lastvalue,TypeArray[z],hiddenNr, values,divInsert,ItemPrefixName,Type);
    }
    else
    {
      x = getItem(y,'',TypeArray[z],hiddenNrArray[z], valuesArray[z],divInsert,ItemPrefixNameArray[z],Type);
    }
    content += x
    da(valuesArray[z]).value += seperator;
    da(hiddenNrArray[z]).value = y
//    items = da(valuesArray[z]).value.split(seperator).length;
  }
  da(divInsert).innerHTML += content;

}

// Remove any item from the search box
function RemoveItem(RemoveItem, hiddenNr, values,divInsert,ItemPrefixName,Type)
{
  hiddenNrArray = hiddenNr.split("||")
  valuesArray = values.split("||")
  ItemPrefixNameArray = ItemPrefixName.split("||")
  TypeArray = Type.split("||")
  // Step one, grab all the values that have been entered and save this in the hidden fields
  for (z=0; z<hiddenNrArray.length;z++)
  {
    y ="";
    isempty = false;
    items = da(valuesArray[z]).value.split(seperator).length;
    // check if all items are empty
    for (i=1;i<=items;i++)
    {
        obj = da(ItemPrefixNameArray[z]+""+i)
        if (obj)
        {
          if (obj.type=="text")
            y += obj.value;
          if (obj.type=="select-one")
          {
            y +=obj.options[obj.selectedIndex].value;
          }
        }
    }


    if (y == "")
    {
      isempty = true;
    }


    y ="";
    for (i=1;i<=items;i++)
    {
      // Do not keep the values of the removed item
      if (i!=RemoveItem)
      {
        if (isempty)
        {
          if (items-1!=i)
          {
            y += seperator;
          }

        } else {
          if (y!="")
            y += seperator;
        }
        obj = da(ItemPrefixNameArray[z]+ i)
        if (obj)
        {
          if (obj.type=="text")
            y += obj.value;
          if (obj.type=="select-one")
          {
            y +=obj.options[obj.selectedIndex].value;
          }
        }
      }
    }
    if (isempty && y==";;")
      y=";";    // fix for empty values...

    da(hiddenNrArray[z]).value = parseInt(da(hiddenNrArray[z]).value) - 1
    // Save the data in a hidden field
    da(valuesArray[z]).value = y
    items = da(valuesArray[z]).value.split(seperator).length;
  }
  // Rebuild the HTML code

  Init_Objects(hiddenNr, values, divInsert, ItemPrefixName,Type)
//  da('hiddenShapes').value = da(divInsert).innerHTML;
}

// getItem contains the HTML code that is inserted
function getItem(item,value,type,hiddenNr, values,divInsert, ItemPrefixName,Typearray)
{
  if (type=="City")
  {
    x = "<div class=\"SbInner\"><input type=\"text\" class=\"inputText\"  value=\""+value+"\" onkeydown=\"checkEnter(event,'Validate()')\" valEmpty msg=\"Plaats\" id=\""+ItemPrefixName+item +"\" onblur=\"getValidCityName(this,this.value)\">"
    if (canRemove==true && item>1)
      x += "<input type=\"button\" class='Sbbtn' value=\"-\" onclick=\"RemoveItem(\'"+ item+ "\',\'"+hiddenNr+"\',\'"+values+"\',\'"+divInsert+"\',\'"+ItemPrefixName+"\', 'City')\">";

    x+="</div>"
  }
  if (type=="Provence")
  {
    cRemoveButton = "<input type=\"button\" value=\"-\" class='Sbbtn' onclick=\"RemoveItem(\'"+ item+ "\',\'"+hiddenNr+"\',\'"+values+"\',\'"+divInsert+"\',\'"+ItemPrefixName+"\', 'Provence')\">"
	  x = "<select class=SearchBoxSelect id=\"" + ItemPrefixName+item+"\">";
	  x += '<option value="1">Drenthe</option>';
	  x += '<option value="2">Flevoland</option>';
	  x += '<option value="3">Friesland</option>';
	  x += '<option value="4">Gelderland</option>';
	  x += '<option value="5">Groningen</option>';
	  x += '<option value="6">Limburg</option>';
	  x += '<option value="7">Noord Brabant</option>';
	  x += '<option value="8">Noord Holland</option>';
	  x += '<option value="9">Overijssel</option>';
	  x += '<option value="10">Utrecht</option>';
	  x += '<option value="11">Zeeland</option>';
	  x += '<option value="12">Zuid Holland</option>';
    x += "</select>"
    if(canRemove==true)
      x+=cRemoveButton
    }
  if (type=="Street")
  {
    x = "";
    x += "<div class=\"SbInnerLarge\">";
    x += "<div class='SbInnerLeft'>Straat</div>";
    x += "<div class='SbInnerRight'><input type=\"text\" class=\"inputText\" onkeydown=\"checkEnter(event,'Validate()')\" value=\""+value+"\" valEmpty msg=\"Straat\" id=\"txtStreet"+item +"\">"
    x += "</div>";
    if (canRemove==true && item>1)
     x+= "<input type=\"button\" value=\"-\" class='Sbbtn' onclick=\"RemoveItem(\'" + item+ "\',\'"+hiddenNr+"\',\'"+values+"\',\'"+divInsert+"\',\'"+ItemPrefixName+"\', \'"+Typearray+ "\')\">";
    x +="<div id='c'></div>";
    x += "</div>"

  }
  if (type=="StreetCities")
  {
    x ="";
    x += "<div class=\"SbInnerLarge\">";
    x += "<div class='SbInnerLeft'>Plaats</div>";
    x += "<div class='SbInnerRight'><input type=\"text\" class=\"inputText\" onkeydown=\"checkEnter(event,'Validate()')\" value=\""+value+"\" onChange='getValidCityName(this,this.value);' valEmpty msg=\"Plaats\" id=\"txtPlaats"+item +"\"></div>";
    x +="<div id='c'></div>";
    x +="</div>";

/*

    x = "<div class=\"SbInnerLarge\">";
    x += "<div class='SbInnerRight'><input type=\"text\" class=\"inputTextsmall\" onkeydown=\"checkEnter(event,'Validate()')\" value=\""+value+"\" onChange='getValidCityName(this,this.value);' valEmpty msg=\"Plaats\" id=\"txtPlaats"+item +"\"></div>";
*/
  }
  if (type=="Zipcode")
  {
    x = "<div class=\"SbInnerLarge\">";
    x += "<div class='SbInnerLeft'>Postcode</div>";
    x += "<div class='SbInnerRight'>";
    x += "<input type=\"text\" class=\"inputTextZip\" onkeydown=\"checkEnter(event,'Validate()')\" value=\""+value+"\" valZip=\"NLSpecial\" msg=\"Postcode\" valEmpty msg=\"Postcode\" id=\"txtZipcode"+item +"\">";
    x += "</div>"
    x +="<div id='c'></div>";
  }
  if (type=="Ranges")
  {
    x="";
    x += "<div class='SbInnerLeft'>Straal</div>";
    x += "<div class='SbInnerRight'>";
    x += '<select class=SearchBoxSelect id="ddlRanges' + item +'">';
    x += getEnumRange();
    x += '</select>';
    x += '</div>';
    Rangevalues = da('hiddenRanges').value.split(';')
    if(canRemove==true && item>1)
    {
      x +="<input type=\"button\" value=\"-\" class='Sbbtn' onclick=\"RemoveItem(\'"+ item+ "\',\'"+hiddenNr+"\',\'"+values+"\',\'"+divInsert+"\',\'"+ItemPrefixName+"\', '"+Typearray+"')\"> \n";
    }
    x +="<div id='c'></div>";
    x += "</div>";
  }


  return x;
}

// Save all values
function setHiddenfields (hiddenValues, identifier, items)
{
  y=da(hiddenValues);
  items = y.value.split(seperator).length;     // the amount of items to save in the hidden value
  y.value = "";
  for (i=1;i<=items;i++)
  {
    x = da(identifier + i );
    if (x)
    {
      if (x.type=="text")
        y.value +=x.value;
      if (x.type=="select-one")
      {
        y.value +=x.options[x.selectedIndex].value;
      }
      // Last seperator is not needed
      if (items!=i)
        y.value += seperator;
    }
  }
}


function Validate()
{
  /*
  if (document.getElementById('ddlPriceMax').selectedIndex - document.getElementById('ddlPriceMin').selectedIndex > 15 ||
      (document.getElementById('ddlPriceMax').selectedIndex == 0 && document.getElementById('ddlPriceMin').selectedIndex == 0)) {
    alert('De "prijs van"- en "prijs tot"-waarden liggen te ver uiteen. Verfijn a.u.b. uw zoekopdracht');
    return false;
  }
  */
  searchform = true;
  if (da('hiddenSearchType').value==1)
    searchform = validateCurrentContainer('Insert_selcity');
  if (da('hiddenSearchType').value==2)
    searchform = validateCurrentContainer('Insert_selzipcode');
  if (da('hiddenSearchType').value==3)
    searchform = validateCurrentContainer('Insert_selstreet');


  if (validateCurrentContainer('SbFirstPart') && searchform)
  {
    // Send all the input values in hidden values
    items = parseInt(da('hiddenNrCity').value);
    setHiddenfields('hiddenCities','txtCity', items);

    items = parseInt(da('hiddenNrStreet').value);
    setHiddenfields('hiddenStreets','txtStreet', items);

    items = parseInt(da('hiddenNrStreet').value);
    setHiddenfields('hiddenStreetsCities','txtPlaats', items);


    items = parseInt(da('hiddenNrZipcode').value);
    setHiddenfields('hiddenZipcodes','txtZipcode', items);

    items = parseInt(da('hiddenNrZipcode').value);
    setHiddenfields('hiddenRanges','ddlRanges', items);

    items = parseInt(da('hiddenNrProvence').value);
    setHiddenfields('hiddenProvences','ddlProvence', items);
    document.form01.submit();
  }
}

function init_Streets(item)
{
  streets= da('hiddenStreets').value.split(seperator);
  da('txtStreet'+item).value=streets[i-1];
}

function changeHouseSatus(memberid,type,housesaleid,housesaletype)
{
  // where type = 'HouseSold' or 'Remove'
  var url= baseUrl + "/ajax/Housing/changeHouseStatus.aspx?tm=" + new Date().getTime() + "&memberid=" + memberid  + "&"+type+"=1&housesaleid=" + housesaleid + "&housesaletype=" + housesaletype;
  xmlHttp = GetXmlHttpObject(gotchangeHouseStatus);
  xmlHttp.open("GET", url , false);
  xmlHttp.send(null);
}

function gotchangeHouseStatus()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.responseText != "") {
    }
    else {
      alert("Er heeft zich een fout voorgedaan.")
    }
  }
}
function getOwnHousesForSale()
{
  // where type = 'HouseSold' or 'Remove'
  var url= baseUrl + "/ajax/Housing/getOwnHousesForSale.aspx?tm=" + new Date().getTime() ;
  xmlHttp = GetXmlHttpObject(gotOwnHousesForSale);
  xmlHttp.open("GET", url , false);
  xmlHttp.send(null);
}

function gotOwnHousesForSale()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.responseText !="")
    {
      da('content').innerHTML = xmlHttp.responseText;
      hideNode("pleaseWait1")
      hideWait(6);
    } else {
    }
  }
}


function getHouseAddress(e,city,address,housenumber)
{
  if (city!=null && address!=null && city!="" && address !="")
  {
    address = address.replace("'", "\'");
    address += " " + housenumber;
    var url= baseUrl + "/ajax/Housing/getHouseAddress.aspx?tm=" + new Date().getTime() + "&city=" + city  + "&address=" + address ;
    xmlHttp = GetXmlHttpObject(gotHouseAddress);
    xmlHttp.open("GET", url , false);
    xmlHttp.send(null);
  }
}

function gotHouseAddress()
{
  cityHasBeenFound = false;
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.responseText !="")
    {
      count = parseInt(xmlHttp.responseText);
      if (count>=1) {
        alert("Deze woning is al opgegeven!")
        da('validAddress').value = 0;
      }
      else {
        da('validAddress').value = 1;
      }
    }
  }
}

function getValidCityName(e,city)
{
  city = city.replace("'", "\'");
  var url= baseUrl + "/ajax/Housing/getCityByName.aspx?tm=" + new Date().getTime() + "&city=" + city  + "&objectname=" + e.id + "&count=" + e.value.length;
  xmlHttp = GetXmlHttpObject(gotValidateCityName);
  xmlHttp.open("GET", url , false);
  xmlHttp.send(null);
}

function gotValidateCityName()
{
  cityHasBeenFound = false;
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.responseText !="")
    {
      // 0 = City count
      // 1 = Name of city
      // 2 = Object to fill
      result = xmlHttp.responseText.split('||');
      if (parseInt(result[0])>0)
      {
        city = result[1];
        object = result[2];
        da(object).value = city;
        cityHasBeenFound = true;
      }
      else
      {
        // check if there are alternative options.
        result[1] = result[1].replace("'","\'")
        cities = result[1].split(';');
        object = result[2];
        da('similarCities').innerHTML = "";
        showcities = "";
        if (cities.length>0 && cities[0]!="")
        {
          for(i=0;i<cities.length;i++)
          {
            if (i%2==0)
              divstyle = "cityrow1";
            else
              divstyle = "cityrow2";
            // ' are being replaced by _ else javascript error in IE
            showcities += "<div class='"+divstyle+"' onclick=\"selectCityByName('"+cities[i].replace("'",'_')+"','"+object+"')\">"+cities[i] + "</div>"
          }
          da('similarCities').innerHTML = showcities ;
          da('similarCitiesContainer').style.display="block";
          if(da('similarCitiesFrame')!=null)
            da('similarCitiesFrame').style.display="block";
        }
        else {
          alert("Plaatsnaam is niet gevonden");
          return;
        }

        txtobject =  da(result[2]);
        if(txtobject.value != "")
        {
//          txtobject.value= "";
//          alert("Plaatsnaam is niet gevonden");
//          txtobject.focus();
        }
      }
    }
    else
    {
      txtobject.value= "";
      alert("Plaatsnaam is niet gevonden");
      return;
    }
  }
}
function selectCityByName(cityName,object)
{
  // _ are being replaced by '
  da(object).value = cityName.replace("_","'");
  if(da('similarCitiesFrame')!=null)
  {
    da('similarCitiesFrame').style.display="none";
  }
  da('similarCitiesContainer').style.display="none";
  da(object).focus();
  if(da('txtCity'))
    getHouseCount();
}

function getDreamHouses()
{
  var url= baseUrl + "/ajax/Housing/getdreamhouse.aspx?tm=" + new Date().getTime();
  xmlHttp = GetXmlHttpObject(gotDreamHouses);
  xmlHttp.open("GET", url , true)
  xmlHttp.send(null);
}
function gotDreamHouses()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.responseText != "")
    {
      da('DreamHouses').innerHTML = xmlHttp.responseText;
    }
  }
}
function getNrOfHouses()
{
  var url= baseUrl + "/ajax/Housing/getDefaultPageData.aspx?tm=" + new Date().getTime() + "&sender=NrHouses";
  xmlHttp2 = GetXmlHttpObject(gotNrOfHouses);
  xmlHttp2.open("GET", url , true)
  xmlHttp2.send(null);
}
function gotNrOfHouses()
{
  if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
  {
    if(xmlHttp2.responseText != "")
    {
      da('actueleKoopwoningen').innerHTML = 'Doorzoek ' + xmlHttp2.responseText + ' actuele koopwoningen';
    }
  }
}
function getNextHouse() {
  var current = parseInt(da('currentHouse').value);
  var totaal = parseInt(da('totalHouses').value);
  var bladzijde = parseInt(da('toPage').value);

  var currentAbs = ((bladzijde - 1) * count) + current;
  if(current % count == 0 && currentAbs != totaal) {
    if(totaal - (bladzijde * count) < 0)
      return;

    getSearchresultsMap(count * bladzijde, "first",false);

    var currentAbs = da('toPage').value = ++bladzijde;
    return;
  }
  else if(currentAbs == totaal) {
    return;
  }
/*
  if(bladzijde < totaal) {
     da('toPage').value = ++bladzijde;
     return;
  }
*/
  var next = current + 1;
  getHouseDetail(da('house'+next).getAttribute('houseid'), next);
}

function getPreviousHouse() {
  var current = parseInt(da('currentHouse').value);
  if(current == 1) {
    var bladzijde = parseInt(da('toPage').value);
    var totaal = parseInt(da('totalHouses').value);
    if(bladzijde == 1)
      return;
    getSearchresultsMap((6 * bladzijde) - 12, "last");
    da('toPage').value = --bladzijde;
    return;
  }
  var prev = current - 1;
  getHouseDetail(da('house'+prev).getAttribute('houseid'), prev);
}

function showWait(index, width, height) {
  if (da('pleaseWait'+index)!=null)
    da('pleaseWait'+index).style.display = 'block';
}

function hideWait(index) {
  setTimeout(function() {
    if (da('pleaseWait'+index)!=null)
    {
      da('pleaseWait'+index).style.display = 'none';
    }
  },10);
}


function CalculateMonth(price)
{
  da('ageRequest').value = 30;
  da('incomeRequest').value = 25000;
  da('housePrice').value = price;
  da('ownInvest').value = 0;
  da('NewOrExisting').value = 1;
  changeTab(4);
  calculateMonthlyMortgage();
}

function changeSearch(e, searchtype)
{
  if (typeof searchByAddress=="undefined")
    searchByAddress=false;
  if(searchtype == 'zip' && e.getAttribute('searchtype')=="city") {
    e.className = 'VpSearchInputMedium';
    e.originalCssText = e.style.cssText;
    if(e.style.cssText.indexOf('float:') == -1)
      e.style.cssText += 'float:left;';
    e.setAttribute('searchtype', searchtype);
    e.setAttribute('valZip','NLSpecial')
    showNode('range');
  }
  if(searchtype == 'city'  && e.getAttribute('searchtype')!="address") {
    e.className = 'VpSearchInputLarge';
    e.style.cssText = e.originalCssText;
    e.setAttribute('searchtype', searchtype);
    hideNode('range');
  }

  if(searchtype == 'city' ||  searchtype == 'address') {
    e.removeAttribute('valZip')
    e.className = 'VpSearchInputLarge';
    e.style.cssText = e.originalCssText;
    hideNode('range');
  }
  if(searchtype == 'address') {
    if (typeof searchByAddress=="undefined")
      searchByAddress=false;
    if(!searchByAddress)
    {
      searchByAddress=true
      // when someone typed a zipcode, then remove that before searching on city/ street
      if(e.value.substring(0,4).search(/\d{4,}/) > -1)
        e.value="";
      showNode('street');
      da('validateStreet').checked=true
      da('searchaddress').innerHTML = "Zoek op plaats of postcode"
      da('searchtype1a').innerHTML = "Vul een <B>plaats</B> en een <B>straat</B> in:"
      e.setAttribute('searchtype', "address");
    } else {
      hideNode('street');
      hideNode('range');
      searchByAddress=false
      da('validateStreet').checked=false
      da('searchaddress').innerHTML="Zoek op adres"
      da('searchtype1a').innerHTML = "Vul een <B>plaats</B> of <B>postcode</B> in:"
      e.setAttribute('searchtype', "city");
    }
  }
  if(searchtype=='address' && da('txtCity').value=='' || da('txtCity').value=='Plaats of Postcode' || da('txtCity').value=='Plaats')
  {
    if (searchByAddress)
      da('txtCity').value='Plaats'
    else
      da('txtCity').value='Plaats of Postcode'
    if (da('txtStreet').value=='')
      da('txtStreet').value= "Straat";
    if (da('txtCity').value=='Plaats' || da('txtCity').value=='Plaats of Postcode')
      da('txtCity').className = 'VpSearchInputLargeGrey'
    if (da('txtStreet').value=='Straat')
      da('txtStreet').className = 'VpSearchInputLargeGrey'
  }


}

function getHouseCount()
{
  var url = baseUrl + "/ajax/Housing/getSearchresultsCount.aspx?tm=" + new Date().getTime();
  searchtype = da('txtCity').getAttribute('searchtype');
  var additionalText = '';
  if (searchtype=="city") {
    vars = "&City=" + da("txtCity").value;
    additionalText = (da("txtCity").value != '') ? ' in ' + da("txtCity").value : '';
  }
  if (searchtype=="address") {
    vars = "&City=" + da("txtCity").value + "&street=" + da("txtStreet").value;
    additionalText = (da("txtStreet").value != '') ? ' aan de ' + da("txtStreet").value : '';
    additionalText += (da("txtCity").value != '') ? ' in ' + da("txtCity").value : '';
  }
  if (searchtype=="zip") {
    vars = "&zipcode=" + da("txtCity").value + "&range=" + da("ddlRange").value;
    additionalText = (da("txtCity").value != '') ? ' in postcode gebied ' + da("txtCity").value : '';
  }

  url += vars;
  xmlHttpSC = GetXmlHttpObject(new Function('gotHouseCount("' + additionalText + '");'));
  xmlHttpSC.open("GET", url , true)
  xmlHttpSC.send(null);
}

function gotHouseCount(addText)
{
  if(xmlHttpSC.readyState == 4 && xmlHttpSC.status == 200) {
    if(xmlHttpSC.responseText.indexOf("count=") !=-1)
    {
      result = xmlHttpSC.responseText.split("=");
      da("Housecount").style.display = "block";
      returnstring = "woningen gevonden";
      if (result[1]==1)
        returnstring = "woning gevonden";
      da("Housecount").innerHTML = result[1]+" " +returnstring + addText;
    }
  }
}

//----------------- Gemiddelde prijzen op voorpagina -------------------
function GetAveragePrice()
{
  var url= baseUrl + "/ajax/Housing/getDefaultPageData.aspx?sender=AveragePrice" ;
  xmlHttpAvg = GetXmlHttpObject(GotAveragePrice);

//  showNode('waitpopup');
  xmlHttpAvg.open("GET", url , true)
  xmlHttpAvg.send(null);
}
function GotAveragePrice()
{
  if (xmlHttpAvg.readyState==4 || xmlHttpAvg.readyState=="complete")
  {
    if(xmlHttpAvg.responseText != "")
    {
      var allData = xmlHttpAvg.responseText.split(';;');
      //da('VpExtraBarDetail3').innerHTML = respons;

      var innerH = '<table id="VpExtraAvgTable" class="HdTable" cellpadding="0" cellspacing="0"">'

      for(row= 0;row<allData.length;row++)
      {
        innerH += '<tr >'

        var cellData = allData[row].split('||');

        if(cellData == "")
        {
          innerH += "</tr>";
          continue;
        }
        for(cell = 0; cell<cellData.length;cell++)
        {
          //Create table cell with class name
          if (row==0)
            innerH += '<td class="HdTableHeader">';
          else if((cell==1) || (cell==2) )
            innerH += '<td class="HdTableCellNr">';
          else
            innerH += '<td class="HdTableCell">';

          innerH += cellData[cell] + "</td>";
        }
        innerH += '</tr>';
      }
      innerH += '</table>';
      da('VpExtraBarDetail3').innerHTML = innerH;
    }
  }
}

//----------------- Einde Gemiddelde prijzen op voorpagina -------------------
//----------------- Meest bekeken op voorpagina -------------------
function GetMostViewed()
{
  var url= baseUrl + "/ajax/Housing/getDefaultPageData.aspx?sender=MostViewed" ;
  xmlHttpMV = GetXmlHttpObject(GotMostViewed);

//  showNode('waitpopup');
  xmlHttpMV.open("GET", url , true)
  xmlHttpMV.send(null);
}
function GotMostViewed()
{
  if (xmlHttpMV.readyState==4 || xmlHttpMV.readyState=="complete")
  {
    if(xmlHttpMV.responseText != "")
    {
      da('VpExtraBarDetail2').innerHTML = xmlHttpMV.responseText;
    }
  }
}
function hoverOverMostViewed(id, divClass)
{
  da(id).className = divClass + "Hover";
}

function hoverOutMostViewed(id, divClass)
{
    da(id).className = divClass;
}

//----------------- Einde Meest bekeken op voorpagina  -------------------

function changeMinRooms(e) {
  if(e.value == '999')
    hideNode('divRoomsMax');
  else
    showNode('divRoomsMax');
}
function changeMinArea(e) {
  if(e.value == '350')
    hideNode('divAreaMax');
  else
    showNode('divAreaMax');
}


function hoverOverItem(e, divClass)
{
  e.className = divClass + "Hover";
}

function hoverOutItem(e, divClass)
{
  e.className = divClass;
}

/************************************ 5. HISTORY */
function gotSoldHousesTable(div, xmlHttpNumber, text)
{
  if (xmlHttpNumber.readyState==4 || xmlHttpNumber.readyState=="complete")
  {
    if (xmlHttpNumber.responseText != "")
    {
    var response = xmlHttpNumber.responseText;
    var parentDiv = da(div);
    var childDiv = document.createElement('div');
    var allData = response.split(';;');
    var innerTable = '<span>' + text + '</span><table id="soldHTable" class="HdTable" cellpadding="0" cellspacing="0">'

    for(i = 0; i<allData.length; i++)
    {
      innerTable += '<tr>';
      var rowData = allData[i].split('||');
      if (rowData == "")
      { innerTable += '</tr>'; }
      else
      {
        for (j = 0; j<rowData.length;j++)
        {
          if(i==0)
          { innerTable += '<td class="HdTableHeader">'; }
          else if (j==1 || j==2 || j==3 || j==4 || j==5)
          { innerTable += '<td class="HdTableCellNr">'; }
          else
          { innerTable += '<td class="HdTableCell">'; }

          var cellData = rowData[j].split('::');

          if (cellData == "")
          {
            innerTable += '</td>';
            continue;
          }

          if (j==0 && i!=0)
          { innerTable += i;}
          else
          {
            if(i!=0 && j ==3)
            {
             if(cellData[1].length == 5)
             { innerTable += cellData[1].substring(0,2) + "." + cellData[1].substring(2,5); }
             else if(cellData[1].length == 6)
             { innerTable += cellData[1].substring(0,3) + "." + cellData[1].substring(3,6); }
             else if(cellData[1].length == 6)
             { innerTable += cellData[1].substring(0,3) + "." + cellData[1].substring(3,6); }
             else
             { innerTable += cellData[1]; }
            }
            else
            { innerTable += cellData[1]; }
          }
            innerTable += '</td>';
         }
       }
         innerTable += '</tr>';
     }
    innerTable += '</table>';
    clearChilds(parentDiv);
    childDiv.innerHTML = innerTable;
    parentDiv.appendChild(childDiv);
    }
  }
}
/************************************ 5. HISTORY */


/************************************ 6. DRAWING */
function openDrawingMap() {
  var empty = document.createElement('div');
  var __h = document.documentElement.clientHeight;
  var __w = document.documentElement.clientWidth;
  empty.style.cssText = 'position: absolute; top: 0px; left: 0px; width: '+__w+'px; height: '+__h+'px; background-color: #000000; z-index: 1; ' +
    'filter: Alpha(opacity=50); -moz-opacity: 0.5;';
  var popup = document.createElement('div');
  popup.style.cssText = 'position: absolute; top: 0px; left: 0px; z-index: 10;';
  popup.innerHTML = '' +
    '<iframe frameborder="1" scrolling="no" src="'+baseUrl+'/drawing.aspx" ' +
      'style="position: absolute; left: 200px; top: 130px; z-index: 11; width: 780px; height: 520px;"></iframe>';
  document.body.appendChild(empty);
  document.body.appendChild(popup);
}

var _help_box;
function showHelp(subject) {
  var ifrm = $CE('div');
  switch(subject)
  {
    case 'drawing':
      var width = 873, height = 400;
      var left = Math.max((document.body.clientWidth / 2) - (width / 2), 0); // middle of popup will be in middle of screen, or whole popup starts @ 0
      ifrm.style.cssText = 'position: absolute; top: 150px; left: '+left+'px; width: '+width+'px; height: '+height+'px; background-color: Transparent; z-index: 10001;';
      ifrm.innerHTML = '<iframe src="'+baseUrl+'/help.aspx" id="helpiframeInner" style="width: '+width+'px; height: '+height+'px;" frameborder="0" allowtransparency></iframe>'
      break;
    case 'favorites':
      var width = 471, height = 300;
      var left = Math.max((document.body.clientWidth / 2) - (width / 2), 0); // middle of popup will be in middle of screen, or whole popup starts @ 0
      ifrm.style.cssText = 'position: absolute; top: 150px; left: '+left+'px; width: '+width+'px; height: '+height+'px; background-color: Transparent; z-index: 10001;';
      ifrm.innerHTML = '<iframe src="'+baseUrl+'/favorites.aspx" id="helpiframeInner" style="width: '+width+'px; height: '+height+'px;" frameborder="0" allowtransparency></iframe>'
      break;
  }
  ifrm.id = 'helpiframe';
  var screenGreyout = $CE('div');
  screenGreyout.innerHTML = '<iframe src="about:blank" style="position:absolute;top:0px;left:0px;filter:Alpha(opacity=0);-moz-opacity:0.0;' +
    'width:'+document.body.clientWidth+'px;height:1000px;"></iframe>';
  screenGreyout.style.cssText = 'position:absolute;top:0px;left:0px;width:'+document.body.clientWidth+'px;height:1000px;background-color:Gray;filter:Alpha(opacity=50);-moz-opacity:0.5;';
  screenGreyout.popup = ifrm;
  document.body.appendChild(screenGreyout);
  document.body.appendChild(ifrm);
  _help_box = screenGreyout;
}

function closeHelp() {
  document.body.removeChild(_help_box.popup);
  document.body.removeChild(_help_box);
}
/************************************ 6. DRAWING */


/********************************************
*** External web site on "House Detail" page
**********************************************/
function getShowHouseWebSite() {
  if(da('houseWebSite')!=null)
  {
    var houseURL = baseUrl + "/ajax/Housing/IsWebSiteValid.aspx?houseId=" + da('houseWebSite').getAttribute('houseId');
    xmlHttpSite = GetXmlHttpObject(gotShowHouseWebSite);
    xmlHttpSite.open("GET", houseURL, true);
    xmlHttpSite.send(null);
  }

}

	function showPrijsVerloop(houseSaleId, cityId)
	{

		var chart = new FusionCharts("common/charts/MSBar2D.swf", "chartdiv01", "320", "300", "0", "1");
		var chart2 = new FusionCharts("common/charts/MSBar2D.swf", "chartdiv02", "320", "300", "0", "1");
		var chart3 = new FusionCharts("common/charts/MSLine.swf", "chartdiv03", "680", "230", "0", "1");



		if(houseSaleId != "0")
		{
			chart.setDataURL("common/charts/vraagprijzen.aspx?h=" + houseSaleId);
			chart2.setDataURL("common/charts/vierkantemeterprijzen.aspx?h=" + houseSaleId);
			chart3.setDataURL("common/charts/prijsverloop.aspx?h=" + houseSaleId);
		}

		if(cityId != "0")
		{
			chart.setDataURL("common/charts/vraagprijzen.aspx?cityId=" + cityId);
			chart2.setDataURL("common/charts/vierkantemeterprijzen.aspx?cityId=" + cityId);
			chart3.setDataURL("common/charts/prijsverloop.aspx?cityId=" + cityId);
		}

		chart.render(document.getElementById('chartdiv'));
		chart2.render(document.getElementById('chartdiv2'));
		chart3.render(document.getElementById('chartdiv3'));
	}

function gotShowHouseWebSite() {
  if((xmlHttpSite.readyState == 4 ) || (xmlHttpSite.readyState == 'complete')){
    if(xmlHttpSite.responseText != ""){
      var respons = xmlHttpSite.responseText;
      if(respons == "true")
        da('houseWebSite').style.display = 'block';
    }
  }
}


function showHouseWebSite(site)
{
  if(document.getElementById('helpBox').style.display=='block')
  {
    document.getElementById('helpBox').style.display='none';
    hideWait(5);
  }
  else
  {
    document.getElementById('helpBox').style.display='block';
    showWait(5);
  }
  var width = 900;
  document.getElementById('helpBox').width = width + "px";
  document.getElementById('helpBox').height = "500px";
  document.getElementById('helpBox').style.top = 200 + document.body.scrollTop + "px" ;
  document.getElementById('helpBox').style.left = (document.body.clientWidth / 2) - (width / 2) + "px" ;
  document.getElementById('helpBox').src = "common/iframe/houseWebsite.aspx?url=" + site;
}
//***** End external website code*************


/********************************************
*** getHousesInNeighbourhood for "House Detail" page
**********************************************/
function getHousesInNeighbourhood(id){
/*
  da('housesInNeibourhoodWait').style.display="block";
  var url= baseUrl + "/ajax/Housing/getHousesInNeighbourhood.aspx?tm=" + new Date().getTime() + "&id="+ id;

  xmlHttpNeibours = GetXmlHttpObject(gotHousesInNeibourhood);
  xmlHttpNeibours.open("GET", url , true);
  xmlHttpNeibours.send(null);
*/
}
function gotHousesInNeibourhood(){
  if (xmlHttpNeibours.readyState == 4 && xmlHttpNeibours.status == 200) {
    da('housesInNeibourhoodWait').style.display="none";
    if(xmlHttpNeibours.responseText != "") {
      da('housesInNeibourhood').innerHTML = xmlHttpNeibours.responseText;
    }
  }
}
function getHouseLastViewed(profileid)
{
  /*
  da('housesInNeibourhoodWait').style.display="block";
  var url= baseUrl + "/ajax/Housing/getHouseslastViewed.aspx?tm=" + new Date().getTime() + "&id="+ profileid;

  xmlHttpLastViewed = GetXmlHttpObject(gotHouseLastViewed);
  xmlHttpLastViewed.open("GET", url , true);
  xmlHttpLastViewed.send(null);
  */
}
function gotHouseLastViewed()
{
  if (xmlHttpLastViewed.readyState == 4 && xmlHttpLastViewed.status == 200) {
      response = xmlHttpLastViewed.responseText;
      da('houseLastViewed').innerHTML = response;
    }
}
//***** End external website code****************************

/********************************************
*** getRecentSold for "House Detail" page
**********************************************/
function getRecentSold(id){
  // var url= baseUrl + "/ajax/Housing/getRecentSold.aspx?tm=" + new Date().getTime() + "&id="+ id;
  // xmlHttpRecentSold = GetXmlHttpObject(gotRecentSold);
  // xmlHttpRecentSold.open("GET", url , true);
  // xmlHttpRecentSold.send(null);
}
function gotRecentSold(){
  if (xmlHttpRecentSold.readyState == 4 && xmlHttpRecentSold.status == 200) {
    if(xmlHttpRecentSold.responseText != "") {
//      da('housesInRecentSoldWait').style.display="none";
      houses = xmlHttpRecentSold.responseText.split("||");
      innertHtml="";

      //  0 = address
      //  1 = city
      //  2 = area
      //  3 = room
      //  4 = price
      //  5 = solddate
      //  6 = number of days for sale
      //  7 = housetype
      //  8 = photo
      column = 0;
      if (houses.length>0)
      {
        setExtraDivC = true;
        for (i=0;i<houses.length; i++)
        {
          if (typeof(houses[i])!="undefined")
          {
            columns = houses[i].split('|')
            innertHtml += "<div id='fl' style='margin-right:5px;'>";
            innertHtml += "<div class='searchResultsSoldHousesList'>";
            innertHtml +="<div class='searchResultsMapWoningListFoto'>";
            innertHtml +="<img src='"+ columns[8] + "'/>";
            innertHtml +="</div>";
            innertHtml +="<div class='searchResultsMapWoningListDetails' style='overflow: hidden; width: 180px; height: 100px;'>";
            innertHtml +="<span id='fr'>"+columns[4]+"</span>"
            innertHtml +="<b>"+columns[1]+"</b><br/>"
            innertHtml +=columns[0]+"<br/>"
            innertHtml +="<b>" + columns[7]+"</b>: "+ columns[3] + " kamers, "+columns[2]+"m2 <br/>"
            innertHtml +="Verkocht op: " + columns[5]+"<br/>"
            innertHtml +=columns[6]+" dagen te koop gestaan op onze website<br/>"
            innertHtml +="</div></div>"
            innertHtml +="</div>"
            column ++
            if (column==2)
            {
              setExtraDivC = false;

              column = 0;
              innertHtml += "<div id='c'></div>";
            }
          }
        }
        if(setExtraDivC)
          innertHtml += "<div id='c'></div>";
      }
      // da('housesInRecentSold').innerHTML = innertHtml;
      // da('houseRecentSoldHeader').style.display = 'block';
    }
  }
}
//***** End external website code****************************


function getScrollTop()
{
  if (document.documentElement && !document.documentElement.scrollTop)
    // IE6 +4.01 but no scrolling going on
    return 0;
  else if (document.documentElement && document.documentElement.scrollTop)
    // IE6 +4.01 and user has scrolled
    return document.documentElement.scrollTop;
  else if (document.body && document.body.scrollTop)
    return document.body.scrollTop;
}
function toggleMapSize(e, currentMapId, moveX, moveY,position) {
  if (typeof(moveX)=="undefined")
    var moveX = 240;
  if (typeof(moveY)=="undefined")
    var moveY = 72;


  currentMap = eval(currentMapId)
  if(e.getAttribute('currentmapsize') == 'normal') {
    if(currentMap.ResizeGradually(moveX, moveY, 10, 30,position)) {
      e.setAttribute('currentmapsize', 'large');
      e.src = baseUrl+'/common/images_nieuw/mapLegendIconMin.gif';
      // e.innerHTML = '<img src="'+baseUrl+'/common/images_nieuw/mapLegendIconMin.gif" /> ';

      e.title = 'header=[<b>Kaart weer kleiner maken</b>] body=[Klik hier om de kaart te verkleinen naar de originele grootte]';
      reloadBox(e);  // boxover reload
    }
  }
  else if(e.getAttribute('currentmapsize') == 'large') {
    if(currentMap.ResizeGradually(-1*moveX, -1*moveY, 10, 30,position)) {
      e.setAttribute('currentmapsize', 'normal');
      e.src = baseUrl+'/common/images_nieuw/mapLegendIconPlus.gif';
      // e.innerHTML = '<img src="'+baseUrl+'/common/images_nieuw/mapLegendIconPlus.gif" />';
      e.title = 'header=[<b>Kaart vergroten</b>] body=[Klik hier om de kaart groter te maken]';
        reloadBox(e);  // boxover reload
    }
  }
}

/////////////////////////////////////
//
// Virtual Earth Map
//
/////////////////////////////////////
var HouseDetail = {
  id : "",
  type : 0,
  vemap : "",
  Get : function(clientId, houseId, type) {
    var xml = AjaxCall.Create();
    var url = baseUrl + '/Common/Ajax/Housing/getHouseDetail.aspx?HouseSaleId=' + houseId + '&Type=' + type;
    HouseDetail.type = type;
    xml.onreadystatechange = function() {
      if(xml.readyState == 4 && xml.status == 200) {
        // TODO: Show housedetail / hide results / initialize house detail map / apply backbutton logic
        HouseDetail.Show();
        if (clientId!=null)
        {
          if(HouseDetail.type == 2) { // if list, clientid of resultslist-repeater item is passed
            da(clientId + 'hasBeenRead').style.display = 'block';
            da(clientId + 'container').className = 'houseListItem';
          }
          else { // otherwise, source element (HtmlMarker) is passed
              clientId.src = baseUrl + '/Common/Images/huisgrijs3.gif';
          }
         }
        da('divHouseDetail').innerHTML = xml.responseText;
      }
    }
    xml.open('GET', url, true);
    xml.send(null);
  },
  Show : function() {
    if(this.type == 2) {
      // search type=list
      da('searchResultsList').style.display = "none";
      da('divHouseDetail').style.display = "block";
      da('buttonBack').style.display = "block";
    }
    else {
      // search type=Map
      da('searchResultsMap').style.display = "none";
      da('divHouseDetail').style.display = "block";
      da('buttonBack').style.display = "block";
    }
    setTimeout(function() {
      if(da('_detailmap')) {
        HouseDetail.initDetailMap();
        if(da('veMap')) {
          var vemap = new VEMap('veMap');
          HouseDetail.vemap = vemap;
          var coordinates = new VELatLong(parseFloat(da('gethouseDetailLatitude').value), parseFloat(da('gethouseDetailLongitude').value));
          vemap.LoadMap(coordinates, 19 , 'r', false);
          vemap.SetMapStyle(VEMapStyle.Birdseye);
          vemap.HideDashboard();
          //vemap.AttachEvent("onmousewheel", Disabled);
          //vemap.AttachEvent("onmousedown", Disabled);
          MapControl.Features.ScaleBarKilometers = true;
          setTimeout(function () {
            var available = HouseDetail.IsBirdseyeAvailable();
            if (!available) {
              showNode('divPhotos');
              hideNode('divVeMap');
              hideNode('lnkPhotos');
              hideNode('lnkVEMap');
            }
          }, 1000);
        }
      }
    }, 250);
  },
  IsBirdseyeAvailable : function () {
    return HouseDetail.vemap.IsBirdseyeAvailable();
  },
  Hide: function() {
    if(HouseDetail.type == 2) {
      // search type=list
      da('searchResultsList').style.display = "block";
      da('divHouseDetail').style.display = "none";
      da('buttonBack').style.display = "none";
    }
    else {
      if (resetSoldHouses != null && resetSoldHouses)
        da('soldHousesCheckBox').checked = false;

      // search type=Map
      da('searchResultsMap').style.display="block";
      da('divHouseDetail').style.display="none";
      da('buttonBack').style.display="none";
    }
  },
  initDetailMap : function () {
    detailmap = new XMap('_detailmap', false, true);
    currentMap = detailmap;
    detailmap.ShowDetailTabMap();
  }
};


function Disabled()
{
  // set this to false to enable the mousewheel behaviour.
   return true;
}

function initVeMap()
{
    if(da('veMap')) {
      vemap = new VEMap('veMap');
      var coordinates = new VELatLong(parseFloat(da('gethouseDetailLatitude').value), parseFloat(da('gethouseDetailLongitude').value));
      vemap.LoadMap(coordinates, 19 ,'r' ,false);
      vemap.SetMapStyle(VEMapStyle.Birdseye);
      vemap.HideDashboard();

      if (vemap.IsBirdseyeAvailable()) {
      }
        var lat = da('gethouseDetailLatitude').value;
        var lng = da('gethouseDetailLongitude').value;
        var x = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,lng));
        vemap.AddShape(x);
        setTimeout(function () {
          var available = vemap.IsBirdseyeAvailable();
          if (!available) {
//            showNode('divPhotos');
//            hideNode('divVeMap');
//            hideNode('lnkPhotos');
//            hideNode('lnkVEMap');
          }
        }, 1000);
    }
}
