function getmaplist(page, viewperpage, data, swlat, swlng, nelat, nelng, sortby, ref){
//alert( document.getElementById("maphref"));

  if ( document.getElementById("maphref") != null) { 
    var mapref = document.getElementById("maphref").href;
    var maprefparams = mapref.split(",");
    if (maprefparams[4] != "''" || maprefparams[5] != "''" || maprefparams[6] != "''") {
    	var maplink = "getmapresult('"+ref+"','"+data+"',"+page+","+viewperpage+","+maprefparams[4]+","+maprefparams[5]+","+maprefparams[6]+",'"+sortby+"')";
    	var listlink = "getlistresult("+page+","+viewperpage+",'"+data+"','"+ref+"',"+maprefparams[4]+","+maprefparams[5]+","+maprefparams[6]+",'"+sortby+"')";
    }
    else {
    	var maplink = "getmapresult('"+ref+"','"+data+"',"+page+","+viewperpage+",'','','','"+sortby+"')";
    	var listlink = "getlistresult("+page+","+viewperpage+",'"+data+"','"+ref+"','','','','"+sortby+"')";
    }
    document.getElementById("maphref").href = "javascript:"+maplink;
    document.getElementById("listhref").href = "javascript:"+listlink;
  }
  if ( document.getElementById("savesearch_sortby") != null) {
    document.getElementById("savesearch_sortby").value = sortby;
  } 
  //alert(searchform);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  var page = page == undefined ? 1 : page;
  var viewperpage = viewperpage == undefined ? 10 : viewperpage;
  var data = data == undefined ? "" : data;
  var swlat = swlat == undefined ? "" : swlat;
  var swlng = swlng == undefined ? "" : swlng;
  var nelat = nelat == undefined ? "" : nelat;
  var nelng = nelng == undefined ? "" : nelng;
  var sortby = sortby == undefined ? "listing" : sortby;
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet({
          url: "/genlist.php?x=" + randomnumber + "&ref="+ref+"&sortby="+ sortby + "&result=map&page=" + page + "&view=" + viewperpage + "&data=" + data + "&swlat=" + swlat + "&swlng=" + swlng + "&nelat=" + nelat + "&nelng=" + nelng,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("listresult").innerHTML = response;
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("listresult").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  }
  });
  document.getElementById("listresult").style.display = "block";
}

function search_property() {
  dojo.xhrPost({
             url: "/zipcodesearch.php",
             load: function(response, ioArgs){
                  if (response == "0") {
                        $('#popup-invalidzip').modal1();
                  }
                  else {
			getmapresult('', '', 1, 10);
                  }
              	  return response;
  	      },
  	     error: function(response, ioArgs){
           	dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           	return response;
  	      },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: "property_search"
  });
}

function getmapresult(ref, data, maplistpage, maplistview, agentsearch, officesearch,querysearch,sortby){
  var searchform = "property_search";
  if (document.getElementById("features1b") != null && document.getElementById("features1b").style.display == "block") {
	searchform = "property_search";
  }
  if (document.getElementById("features2b") != null && document.getElementById("features2b").style.display == "block") {
	searchform = "agent_search";
  }
  if (document.getElementById("features2b") != null && document.getElementById("features3b").style.display == "block") {
	searchform = "office_search";
  }
//alert(searchform);
  var data = data == undefined ? "" : data;
  var agentsearch = agentsearch == undefined ? "" : agentsearch;
  var officesearch = officesearch == undefined ? "" : officesearch;
  var querysearch = querysearch == undefined ? "" : querysearch;
  var sortby = sortby == undefined ? "listing" : sortby;
  var ref = ref == undefined ? "search" : ref;
  var maplistpage = maplistpage == undefined ? 1 : maplistpage;
  var maplistview = maplistview == undefined ? 10 : maplistview;

  if (document.getElementById(searchform) != null) {

  document.getElementById("searchview").value = 'map';
  document.getElementById("searchlist").value = maplistview;
  document.getElementById("searchsort").value = sortby;
//alert(data);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrPost({
        url: "/genmap.php?x=" + randomnumber + "&page=" + maplistpage + "&view=" + maplistview+"&ref=" + ref + "&data=" + data + "&agent=" + agentsearch + "&office=" + officesearch + "&query=" + querysearch + "&sortby=" + sortby,
        load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
	      if (document.getElementById("directiondiv") != null) {
		  document.getElementById("directiondiv").style.display = "block";
	      }
		      //dojo.byId("directiondiv").style.display = "block";
              var outputs = response.split("@@");
	    //alert(outputs[0]); 
              dojo.byId("maincontent").innerHTML = outputs[1] + "<div class=\"pad-top\" id=\"resultmapdiv\"><iframe name=\"mapiframe\" id=\"mapiframe\" width=\"700\" height=\"400\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"/map2.php?data=" + outputs[0] + "&agent=" + agentsearch + "&office=" + officesearch + "&query=" + querysearch + "&sortby=" + sortby + "\"></iframe></div>";
          	//alert(dojo.byId("mapresult").innerHTML); 
  	      getmaplist(maplistpage, maplistview, outputs[0],'','','','',sortby,ref);
              if (document.getElementById('savedsearchoptions_menu') != null && document.getElementById('searchidparam') != null) {
                   document.getElementById('savedsearchoptions_menu').selectedIndex = document.getElementById('searchidparam').value - 1;
                   //alert(document.getElementById('savedsearchoptions_menu').selectedIndex);
                   //document.getElementById('searchid'+
              }
              return response;
  	},
  	error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  	},
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  	form: searchform
  });
  }
  else {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet({
          url: "/genmap.php?x=" + randomnumber + "&page=" + maplistpage + "&view=" + maplistview+"&ref=" + ref + "&data=" + data + "&agent=" + agentsearch + "&office=" + officesearch + "&query=" + querysearch + "&sortby=" + sortby,
          load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              var outputs = response.split("@@");
	     //alert(outputs[0]); 
                dojo.byId("maincontent").innerHTML = outputs[1] + "<div class=\"pad-top\" id=\"resultmapdiv\"><iframe name=\"mapiframe\" id=\"mapiframe\" width=\"700\" height=\"400\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"map2.php?data=" + outputs[0] + "\"></iframe></div>";
          	//alert(dojo.byId("mapresult").innerHTML); 
  	      getmaplist(maplistpage, maplistview, outputs[0],'','','','',sortby,ref);
              if (document.getElementById('savedsearchoptions_menu') != null) {
                   document.getElementById('savedsearchoptions_menu').selectedIndex = document.getElementById('searchidparam').value - 1;
                   //alert(document.getElementById('savedsearchoptions_menu').selectedIndex);
                   //document.getElementById('searchid'+
              }

              return response;
  	},
  	error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  	}
  });
  }
}

function getpropertydetail(street, city, state, zip, lat, lng, data, bed, bath, type) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/propertydetail2.php?x=" + randomnumber + "&streetAddress=" + street + "&city=" + city + "&state=" + state + "&zip=" + zip + "&lat=" + lat + "&lng=" + lng + "&data=" + data + "&beds=" + bed + "&baths=" + bath + "&type=" + type,
      // Called when the page loaded successfully
      load: function (response) {
              dojo.byId("detailresult").innerHTML = response;
              return response;
      },
      // Called if there was an error (such as a 404 response)
      error: function(response){
           dojo.byId("moreddtail").innerHTML =
                 "An error occurred, with response: " + response;
      }
  });
}

function advancedsearchresult(searchstring) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/genmap.php?x=" + randomnumber + "&ref=advanced" + searchstring,
      // Called when the page loaded successfully
      load: function (response) {
              var results = response.split("@@");
              dojo.byId("maincontent").innerHTML = results[1] + "<iframe width=\"700\" height=\"400\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"map.php?data=" + results[0] + "\"></iframe>";
          	//alert(dojo.byId("mapresult").innerHTML); 
  	      getmaplist(1, 10, results[0]);
              return response;
      },
      // Called if there was an error (such as a 404 response)
      error: function(response){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
      }
  });
}

function getlistresult(page, viewperpage, data, ref, agent, office, query, sortby) {
  var maplink = "getmapresult('"+ref+"','"+data+"',"+page+","+viewperpage+",'"+agent+"','"+office+"','"+query+"','"+sortby+"')";
  var listlink = "getlistresult("+page+","+viewperpage+",'"+data+"','"+ref+"','"+agent+"','"+office+"','"+query+"','"+sortby+"')";
  if ( document.getElementById("maphref") != null) {
    document.getElementById("maphref").href = "javascript:"+maplink;
    document.getElementById("listhref").href = "javascript:"+listlink;
  }
  var searchform = "property_search";
  if (document.getElementById("features1b") != null && document.getElementById("features1b").style.display == "block") {
	searchform = "property_search";
  }
  if (document.getElementById("features2b") != null && document.getElementById("features2b").style.display == "block") {
	searchform = "agent_search";
  }
  if (document.getElementById("features3b") != null && document.getElementById("features3b").style.display == "block") {
	searchform = "office_search";
  }
  //alert(searchform);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  var page = page == undefined ? 1 : page;
  var viewperpage = viewperpage == undefined ? 10 : viewperpage;
  var data = data == undefined ? "" : data;
  var ref = ref == undefined ? "" : ref;
  var agent = agent == undefined ? "" : agent;
  var office = office == undefined ? "" : office;
  var query = query == undefined ? "" : query;
//alert(data);
  var randomnumber=Math.floor(Math.random()*100000)
  if (document.getElementById("directiondiv") != null) {
	  document.getElementById("directiondiv").style.display = "none";
  }
  if (document.getElementById(searchform) != null) {

  document.getElementById("searchview").value = 'list';
  document.getElementById("searchlist").value = viewperpage;
  document.getElementById("searchsort").value = sortby;

  dojo.xhrPost({
          url: "/genlist.php?x=" + randomnumber + "&sortby="+sortby+"&result=list&ref="+ref+"&page=" + page + "&view=" + viewperpage + "&data=" + data + "&agent=" + agent + "&office=" + office + "&query=" + query,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("maincontent").innerHTML = response;
	      dojo.byId("menu1").style.display = "none";
	      dojo.byId("menu2").style.display = "block";
	      if (document.getElementById('savedsearchoptions_menu') != null && document.getElementById('searchidparam') != null) {
		//alert(document.getElementById('searchidparam').value);
		   document.getElementById('savedsearchoptions_menu').selectedIndex = document.getElementById('searchidparam').value - 1;
		   //document.getElementById('searchid'+
	      }
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: searchform
  });

  }
  else {

  dojo.xhrGet({
          url: "/genlist.php?x=" + randomnumber + "&sortby="+sortby+"&result=list&ref=" + ref + "&page=" + page + "&view=" + viewperpage + "&data=" + data,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("maincontent").innerHTML = response;
	      dojo.byId("menu1").style.display = "none";
	      dojo.byId("menu2").style.display = "block";
	      if (document.getElementById('savedsearchoptions_menu') != null && document.getElementById('searchidparam') != null) {
		   document.getElementById('savedsearchoptions_menu').selectedIndex = document.getElementById('searchidparam').value - 1;
		   //alert(document.getElementById('savedsearchoptions_menu').selectedIndex);
		   //document.getElementById('searchid'+
	      }
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  }
  });

  }
  document.getElementById("listresult").style.display = "none";
}

function getsavedhomelist(page, viewperpage, ref) {
  
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet({
          url: "/genlistsavedhome.php?x=" + randomnumber + "&ref=" + ref + "&page=" + page + "&view=" + viewperpage,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("maincontent").innerHTML = response;
              dojo.byId("listresult").style.display = "none";
	      if (ref != undefined && ref == 'map') {
		dojo.byId("mapdiv").innerHTML = "<div class=\"pad-top\" id=\"resultmapdiv\"><iframe width=\"700\" height=\"400\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"map_savedhome.php\"></iframe></div>";
                dojo.byId("menu1").style.display = "block";
                dojo.byId("menu2").style.display = "none";
	      }
	      else {
                dojo.byId("menu1").style.display = "none";
                dojo.byId("menu2").style.display = "block";
	      }
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  }
  });
}
function getagentlist(page, viewperpage, data) {
  var randomnumber=Math.floor(Math.random()*100000)
  var searchform = "agent_search";
  //alert(searchform);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  var page = page == undefined ? 1 : page;
  var viewperpage = viewperpage == undefined ? 10 : viewperpage;
  var data = data == undefined ? "" : data;
//alert(data);
  if (document.agentsearch.team.value != "") {
	document.location.href = "/teamdetail.php?team="+document.agentsearch.team.value;
	return;
  }
  dojo.xhrPost({
          url: "/agentlist.php?x=" + randomnumber + "&page=" + page + "&view=" + viewperpage + "&query=" + data,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
  if (document.getElementById("directiondiv") != null) {
	  document.getElementById("directiondiv").style.display = "none";
  }
              //dojo.byId("directiondiv").style.display = "none";
              dojo.byId("maincontent").innerHTML = response;
	      //dojo.byId("menu1").style.display = "none";
	      //dojo.byId("menu2").style.display = "block";
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: searchform
  });
  document.getElementById("listresult").style.display = "none";
}

function getofficelist(page, viewperpage, data) {
  var randomnumber=Math.floor(Math.random()*100000)
  var searchform = "office_search";
  //alert(searchform);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  var page = page == undefined ? 1 : page;
  var viewperpage = viewperpage == undefined ? 10 : viewperpage;
  var data = data == undefined ? "" : data;
//alert(data);
  dojo.xhrPost({
          url: "/officelist.php?x=" + randomnumber + "&page=" + page + "&view=" + viewperpage + "&query=" + data,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
  if (document.getElementById("directiondiv") != null) {
	  document.getElementById("directiondiv").style.display = "none";
  }
              //dojo.byId("directiondiv").style.display = "none";
              dojo.byId("maincontent").innerHTML = response;
	      //dojo.byId("menu1").style.display = "none";
	      //dojo.byId("menu2").style.display = "block";
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: searchform
  });
  document.getElementById("listresult").style.display = "none";
}



/*
function propertyscroll() {
  //alert(searchform);
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  dojo.xhrPost({
          url: "/genlist.php?page=" + page + "&view=" + viewperpage + "&data=" + data,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("mapresult").innerHTML = response;
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("mapresult").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
}
}
/*
function propertydetail(query, data) {
  var searchform = "property_search";
  if (document.getElementById("features1b").style.display == "block") {
        searchform = "property_search";
  }
  if (document.getElementById("features2b").style.display == "block") {
        searchform = "agent_search";
  }
  if (document.getElementById("features3b").style.display == "block") {
        searchform = "office_search";
  }
  //The form data is sent to the given URL using a POST method,
  //rather than a GET by using the dojo.xhrPost function.
  dojo.xhrPost({
          url: "/property_detail.php?data=" + data + "&" + query,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("maincontent").innerHTML = response;
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("maincontent").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: searchform
  });
  document.getElementById("listresult").style.display = "none";
}
*/

function userprofile(userid) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/userprofile.php?x=" + randomnumber + "&userid=" + userid,
      // Called when the page loaded successfully
      load: function (data) {
     		dojo.byId('userprofile').innerHTML = data;
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("userprofile").innerHTML =
                 "An error occurred, with response: " + response;
      }
  });
  
}


function editprofile(userid) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/editprofile.php?x=" + randomnumber + "&userid=" + userid,
      // Called when the page loaded successfully
      load: function (data) {
     		dojo.byId('userprofile').innerHTML = data;
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("userprofile").innerHTML =
                 "An error occurred, with response: " + response;
      }
  });
  
}

function saveprofile() {
  if (/\w@\w/.test(document.editprofile.email.value) == false) {
	alert("Please enter a valid email");
	return;
  }
  dojo.xhrPost({
          url: "/editprofile_act.php",
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("userprofile").innerHTML = response;
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("userprofile").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: "editprofile"
  });
}


function changepassword(userid) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/changepassword.php?x="+ randomnumber + "&userid=" + userid,
      // Called when the page loaded successfully
      load: function (data) {
     		dojo.byId('password').innerHTML = data;
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("password").innerHTML =
                 "An error occurred, with response: " + response;
      }
  });
  
}


function savepassword() {
  dojo.xhrPost({
          url: "/changepassword_act.php",
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              dojo.byId("password").innerHTML = response;
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("password").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: "changepassword"
  });
}


function getsavedsearcheslisting(id) {
  dojo.xhrPost({
          url: "/myaccount_savedsearches.php?searchid=" + id,
              load: function(response, ioArgs){
              //dojo.byId("mapresult").innerHTML = response;
              //Dojo recommends that you always return(response); to propagate
              //the response to other callback handlers. Otherwise, the error
              //callbacks may be called in the success case.
              var results = response.split("@@");
	      dojo.byId("listingsfound").innerHTML = results[0];
	      if (Number(results[0]) > 10) {
		dojo.byId("listingsshowed").innerHTML = 10;
	      }
	      else {
		dojo.byId("listingsshowed").innerHTML = results[0] + " ";
	      }
              dojo.byId("savedsearchlistings").innerHTML = results[1]+" ";
//alert(results[2]);
              dojo.byId("search_viewall").href = "javascript:getlistresult(1,10,'"+results[2]+"','myaccount','','','','"+results[3]+"');";
	      initScrollLayer();
              return response;
  },
  error: function(response, ioArgs){
           dojo.byId("savedsearchlistings").innerHTML =
                 "An error occurred, with response: " + response;
           return response;
  },
  //Setting the 'form' parameter to the ID of a form on the page
  //submits that form to the specified URL
  form: "savedsearches"
  });
}



function getsavedproperties(userid) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/myaccount_savedproperties.php?x=" + randomnumber + "&userid=" + userid,
      // Called when the page loaded successfully
      load: function (data) {
	      var results = data.split("@@");
	      dojo.byId('propertiessaved').innerHTML = results[0];
	      if (Number(results[0]) > 10) {
	      	dojo.byId('propertiesshowed').innerHTML = 10;
	      }
	      else {
	        dojo.byId('propertiesshowed').innerHTML = results[0];
	      }
	      if (Number(results[0])  == 0) {
		document.getElementById("a_savedpropertiesdiv").style.display = "none";
		document.getElementById("a_nosavedproperties").style.display = "block";
	      }
     	      dojo.byId('savedproperties').innerHTML = results[1];
	      initScrollLayer1();
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("savedproperties").innerHTML =
                 "An error occurred, with response: " + data;
      }
  });
  
}


function deletesavedproperty(propid, userid, pagefrom, page, view) {
  var answer = confirm("Do you want to delete this listing?");
  if (!answer) {
	return;
  }
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/myaccount_deletesavedproperty.php?userid=" + userid + "&delete=" + propid,
      // Called when the page loaded successfully
      load: function (data) {
     	      //dojo.byId('savedproperties').innerHTML = results[1];
	      //initScrollLayer1();
	      if (pagefrom == 'map') {
		getsavedhomelist(page,view,'map');
	      }
              else if (pagefrom == 'list') {
		getsavedhomelist(page,view,'list');
	      }
	      else {
	      	getsavedproperties(userid);
	      }
	      if (Number(data) == 0) {
			document.location.href = "myaccount.php";
	      }
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("savedproperties").innerHTML =
                 "An error occurred, with response: " + data;
      }
  });
}

function saveproperty(saveform) {
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/saveproperty.php",
      // Called when the page loaded successfully
      load: function (response) {
	var data = response.split("||");
	$.modal.close();	
	$.modal1.close();	
	var formobj = document.getElementsByTagName("form");
	for(var i=0; i<formobj.length; i++) {
		if (/^savepropertyform\d*$/.test(formobj[i].id)) {
			formobj[i].openhouse.checked = data[1] == "Y" ? true : false;
			formobj[i].pricechange.checked = data[2] == "Y" ? true : false;
		}
	}

	if (document.getElementById(saveform) != undefined) {
		if (data[0] != "") { //listing have saved before, skip adding
			var savepropertyform = document.getElementById(saveform);
			var optionsobj = document.getElementById("savedhomeoptions");
			var addresstext = savepropertyform.streetAddress.value + ", " + savepropertyform.city.value + ", " + savepropertyform.state.value + " " + savepropertyform.zip.value;
			for(var i=0; i<optionsobj.length; i++) {
				if (optionsobj.options[i].value == "") {
					optionsobj.options[i] = null;
				}
			}
			optionsobj.options[optionsobj.length] = new Option(addresstext,data[0],false,false);
		}
	}
      },
      // Called if there was an error (such as a 404 response)
      error: function(response){
      },
      form: saveform
  });
}

function emailthislisting() {
	dojo.xhrPost({
		url: "/emailthislisting.php",
		load: function(response, ioArgs){
			$.modal.close();
		},
		error: function(data){
		},
		form: "emailthislistingform"
	});
}

function emailprequalify() {
        dojo.xhrPost({
                url: "/prequalify.php",
                load: function(response, ioArgs){
                        $.modal.close();
                },
                error: function(data){
                },
                form: "prequalify1"
        });
}

function emailcontact(popupform) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrPost({
        url: "/emailagent.php?x="+randomnumber,
        load: function(response, ioArgs){
                $.modal.close();
                $.modal1.close();
                return response;
        },
        error: function(response, ioArgs){
                return response;
        },
        form: popupform
  });
}

function deletesavedsearch(userid) {
  var answer = confirm("Do you want to delete this search?");
  if (!answer) {
	return;
  }
  var todelete = document.savedsearches.searchid.value;
  if (document.getElementById('savedsearchidparam') != null) {
	todelete = document.getElementById('savedsearchidparam').value;
  }
  /*if (document.savedsearches.searchid.value == "" || document.savedsearches.searchid.value == undefined) {
	return;
  }
  */
  if (todelete == "" || todelete == undefined) {
	return;
  }
  var deletedindex = document.savedsearches.searchid.selectedIndex;
  if (document.getElementById('searchidparam') != null) {
	deletedindex = document.getElementById('searchidparam').value - 1;
  }
  document.savedsearches.searchid.options[document.savedsearches.searchid.selectedIndex] = null;
  if (document.getElementById('listingsshowed') != null) {
	document.getElementById('listingsshowed').innerHTML = "";
  }
  if (document.getElementById('listingsfound') != null) {
	document.getElementById('listingsfound').innerHTML = "";
  }
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/myaccount_deletesavedsearch.php?userid=" + userid + "&delete=" + todelete,
      // Called when the page loaded successfully
      load: function (data) {
	      if (document.getElementById("savedsearchlistings")) {
	     	      dojo.byId("savedsearchlistings").innerHTML = "";
	      }
	      //initScrollLayer1();
  	      document.savedsearches.searchid.selectedIndex = deletedindex - 1;
	      if (document.savedsearches.searchid.selectedIndex >= 0) {
	      	  if (document.getElementById("savedsearchlistings")) {
		      getsavedsearcheslisting(document.savedsearches.searchid.options[document.savedsearches.searchid.selectedIndex].value);
		  }
		  else {
		      getlistresult(1,10,document.savedsearches.searchid.options[document.savedsearches.searchid.selectedIndex].value, 'myaccount','','','',document.getElementById("sort"+document.savedsearches.searchid.selectedIndex).value);
		  }
	      }
	      else {
		  document.location.href = "myaccount.php";
		  document.getElementById("deletesavedsearchdiv").style.display = "none";
		  document.getElementById("a_nosavedsearch").style.display = "block";
		  document.getElementById("a_savedsearchdiv").style.display = "none";
		  document.savedsearches.searchid.options[0] = new Option("No saved searches", "", false, false);
	      }
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           dojo.byId("savedproperties").innerHTML =
                 "An error occurred, with response: " + data;
      }
  });
}

function checkemail(email) {
  var randomnumber=Math.floor(Math.random()*100000)
  dojo.xhrGet ({
      // Location of the HTML content we want to grab
      url: "/emailcheck.php?x="+ randomnumber + "&email=" + email,
      // Called when the page loaded successfully
      load: function (data) {
		if (data == "1") {	
			document.getElementById("duplicateemailerror").style.display = "inline";
			if (document.registerform != undefined) {
				document.registerform.email.value = "";
				document.registerform.email.focus();
			}
			if (document.editprofile != undefined) {
				document.editprofile.email.value = "";
				document.editprofile.email.focus();
			}
		}
		else {
			document.getElementById("duplicateemailerror").style.display = "none";
		}
      },
      // Called if there was an error (such as a 404 response)
      error: function(data){
           //dojo.byId("").innerHTML =
            //     "An error occurred, with response: " + data;
      }
  });
}

function savesearch() {
        if (document.savethissearch.savesearchname.value == "") {
                alert("Please enter a search name");
                document.savethissearch.savesearchname.focus();
                return false;
        }
        document.savethissearch.method = "post";
        document.savethissearch.action = "/savethissearch.php";
        document.savethissearch.submit();
}

function savesearch_nouser() {
        document.savethissearch.method = "post";
        document.savethissearch.action = "/signin.php";
        document.savethissearch.submit();
}


