var TheBrowserName = navigator.appName;
var TheBrowserVersion = parseFloat(navigator.appVersion);
// preload some images
pic1= new Image(65,19);
pic1.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/login_processing_button.gif";
pic2= new Image(65,19);
pic2.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/login_button.gif";
pic3= new Image(65,19);
pic3.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/logout_button.gif";
pic4= new Image(69,70);
pic4.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/delete_listing.gif";
pic5= new Image(69,70);
pic5.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_69x70.gif";
pic6= new Image(69,70);
pic6.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/new_icons/search_saved.gif";
pic7= new Image(69,70);
pic7.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/new_icons/resave_search.gif";
pic8= new Image(52,70);
pic8.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_52x70.gif";
pic9= new Image(45,26);
pic9.src="http://images.harmonhomes.com/img/11/design/clean-hh_II/new_icons/animated_go_button.gif";

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function processing(show)
{
	if (show == true)
	{
		var div = document.getElementById("div_process");
		if (div == null || div == '' || typeof(div) != 'object') { return false; }
		div.style.backgroundColor='yellow';
		div.innerHTML = "PROCESSING";
		var scrollTop = f_scrollTop();
        var scrollLeft = f_scrollLeft();
        var clientWidth = f_clientWidth();

        // Calculate left position
        var left = clientWidth - div.offsetWidth;
        left = scrollLeft + left;

        // Set position
       	div.style.position = 'absolute';
        div.style.left = (left-5) + 'px';
        div.style.top = (scrollTop+5) + 'px';
	}
	else
	{
		document.getElementById("div_process").innerHTML = "";
	}
}

function testIsValidObject(objToTest) 
{
	if (null == objToTest)
		return false;

	if ("undefined" == typeof(objToTest) )
		return false;

	return true;
}

function tdOn(td, location, color){
	if (color == '') {
		color="#D60000";
	}
	td.style.backgroundColor=color;
	if ((TheBrowserName == 'Netscape') && (TheBrowserVersion >= 5)) {
		td.style.cursor="pointer";
	} else {
		td.style.cursor="hand";
	}
	// equivalent to style="cursor:pointer;cursor:hand;"
 	window.status=location;
}
function tdOff(td, location, color){
	if (color == '') {
		color="#003163";
	}
	td.style.backgroundColor=color;
	td.style.cursor="default";
	window.status=location;
}
function rolloverImage(cellName, imageName){
	if(document.images){
		document[cellName].src = imageName;
	}
}
function loadInterestRates(){
	window.open("/servicesdetailtransfer.html?7", "Compare_Interest_Rates");	// , "scrollbars=yes,menubar=no,toolbar=yes,resizable=no,width=640,height=480,top=72,left=72"
}		
function ResetForm(formname) {
	document.forms[formname].reset();
	//  usage  --  href="javascript:ResetForm('formname');"
}
function SubmitForm(formname) {
	document.forms[formname].submit();
	//  usage  --  href="javascript:SubmitForm('formname');"
}
function showImage(thisImage) {
  mainImage.src = 'http://images.harmonhomes.com' + thisImage;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
	if (!((TheBrowserName == 'Netscape') && (TheBrowserVersion < 5))) {
		var i,p,v,obj,args=MM_showHideLayers.arguments;
		for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
			obj.visibility=v; }
	}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("##")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function switchSlide(theImage) {
	theImage.src   = 'http://images.harmonhomes.com/img/11/site/spacer.gif';
}
	
function showCityList(site) {
	if (document.forms['choose_a_state'].state_code.value == "") {
		alert("Please Choose a State");
		return;
	}
	city = document.forms['choose_a_state'].browsecity.value;
	state = document.forms['choose_a_state'].state_code.value;
	newWin = window.open("http://" + site + "/city_lookup.php?state_code=" + state + "&city_name=" + city + " ","cityLookup","width=465,height=550,resizable=yes,scrollbars=yes");
}

function showCityListNew(site, city, state) {
	newWin = window.open(site + "/city_lookup.php?ajax=1&state_code=" + state + "&city_name=" + city + " ","cityLookup","width=465,height=550,resizable=yes,scrollbars=yes");
}

function setHeight (remove_height)
{
	var navBox = document.getElementById("navBox2");
	var magicBox = document.getElementById("magicBox");
	var height_difference = 33;
	// account for top and bottom images since we only stretch the middle of the right nav
	if (navigator.userAgent.indexOf("MSIE")>=0)
		height_difference = 18;
		
	var currHeight = magicBox.offsetHeight - height_difference; 
	
	navBox.style.height = currHeight;
	navBox.style.minHeight = currHeight;

	if (remove_height > 0)
	{
		var height = magicBox.offsetHeight;
		if (height > remove_height)
		{
			magicBox.style.height  = height - remove_height;
			navBox.style.height = currHeight - remove_height;
			navBox.style.minHeight = currHeight - remove_height;
		}
	}
}
	
function fixForm( form ) 
{
	if (form.input_selection.value == "" || form.input_selection.value == "City, State --OR-- Zip")
		alert("Please enter in a City, State or Zip");
	else
	{
		var low_range = "default";
		var high_range = "default";
		var bedroom_min = "default";
		var bath_min = "default";
		var bedroom_max = "default";
		var bath_max = "default";
		var search_type = "all";
		var new_homes = "default";
		var open_houses = "default";
		var virtual_tours = "default";
		var multiple_photos = "default";
		var videos = "default";
		
		if (form.lorange.value != "Min Price")
		{
			low_range = form.lorange.value;
			low_range = low_range.replace(/,/gi,"");
			low_range = low_range.replace(/\$/gi,"");
		}

		if (form.hirange.value != "Max Price")
		{
			high_range = form.hirange.value;
			high_range = high_range.replace(/,/gi,"");
			high_range = high_range.replace(/\$/gi,"");
		}

		if (form.lorange.value != "Min Price" && form.hirange.value != "Max Price")
		{	
			if (parseInt(high_range) < parseInt(low_range))
			{
				alert("Min price is higher then max price, please fix this and resubmit");
				return false;
			}
			
			/* this is ok, if they wanted to search for a specific price
			if (form.hirange.value == form.lorange.value)
			{
				alert("Min price is the same as max price, please fix this and resubmit");
				return false;
			}*/
		}
			
		if (form.bedroom_min.options[form.bedroom_min.selectedIndex].value != "")
			bedroom_min = form.bedroom_min.options[form.bedroom_min.selectedIndex].value;
			
		if (testIsValidObject(form.bedroom_max))
		{
			if (form.bedroom_max.options[form.bedroom_max.selectedIndex].value != "")
				bedroom_max = form.bedroom_max.options[form.bedroom_max.selectedIndex].value;
		}
			
		if (form.bath_min.options[form.bath_min.selectedIndex].value != "")
			bath_min = form.bath_min.options[form.bath_min.selectedIndex].value;
			
		if (testIsValidObject(form.bath_max))
		{
			if (form.bath_max.options[form.bath_max.selectedIndex].value != "")
				bath_max = form.bath_max.options[form.bath_max.selectedIndex].value;
		}
			
		for (x = 0; x < 6; x++)
		{
			if (form.searchtype[x].checked == true)
				search_type = form.searchtype[x].value;
		}
		
		if (testIsValidObject(form.searchFilter))
		{
			// 0 new_homes, 1 open_houses, 2 virtual_tours, 3 multiple_photos, 4 videos
			if (form.searchFilter[0].checked)
				new_homes = 1;
			if (form.searchFilter[1].checked)
				open_houses = 1;
			if (form.searchFilter[2].checked)
				virtual_tours = 1;
			if (form.searchFilter[3].checked)
				multiple_photos = 1;
			if (form.searchFilter[4].checked)
				videos = 1;
		}
		
		var url="/ajax_stub.php?city_state_zip="+form.input_selection.value+"&low_range="+low_range+"&high_range="+high_range+"&bedroom_min="+bedroom_min+"&bedroom_max="+bedroom_max+"&bath_min="+bath_min+"&bath_max="+bath_max+"&search_type="+search_type+
				"new_homes="+new_homes+"&open_houses="+open_houses+"&virtual_tours="+virtual_tours+"&multiple_photos="+multiple_photos+"&videos="+videos;
		httpRequest("GET",url,true,handleResponse);
	}
	
	return false;
}

function handleResponse()
{
	if(ajax_tooltipObj)
		ajax_hideTooltip();

	if (request.readyState == 1)
	{
		var new_html = "";
		
		if (document.forms['choose_a_state'].search_box.value == 'index')
		{
			if (document.forms['choose_a_state'].distance.value != '25')
			{
				new_html = "<img src='http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/processing-button_01.gif' class=\"buttonsearch\"/>\n";
				new_html += "<input type=\"image\" value=\"Options\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonOptions.gif\" alt=\"Click for more search options\" onClick=\"document.forms.choose_a_state.distance.value='25';\" class=\"buttonmore\" />\n";
			}
			else
			{
				new_html = "<input type=\"image\" value=\"Browse\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonSearch.gif\" alt=\"Find A Home & Real Estate Listings\" onClick=\"document.forms.choose_a_state.distance.value='0';\" class=\"buttonsearch\" />\n";
				new_html += "<img src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/processing-button_01.gif\" class=\"buttonmore\"/>\n";
			}
		}
		else
		{
			if (document.forms['choose_a_state'].distance.value != '25')
			{
				new_html += "<img src='http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/processing-button_01.gif'/>\n";
				new_html += "<input type=\"image\" value=\"Options\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonOptions.gif\" alt=\"Click for more search options\" onClick=\"document.forms.choose_a_state.distance.value='25';\" style=\"margin-left:50px\" />\n";
			}
			else
			{
				new_html += "<input type=\"image\" value=\"Browse\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonSearch.gif\" alt=\"Find A Home & Real Estate Listings\" onClick=\"document.forms.choose_a_state.distance.value='0';\"/>\n";
				new_html += "<img src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/processing-button_01.gif\" style=\"margin-left:50px\"/>\n";
			}
		}
		
		document.getElementById("subproc").innerHTML = new_html;
	}
	
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			if (request.responseText != "")
			{				
				if ( request.responseText.indexOf("{") != -1)
				{
					the_object = eval("(" + request.responseText + ")");
					
					if (typeof the_object.zip_code != "undefined")
					{
						document.forms['choose_a_state'].zip.value = the_object.zip_code;
						
						// zero out if we had any old values
						document.forms['choose_a_state'].browsecity.value = "";
						document.forms['choose_a_state'].state_code.value = "";
					}
	
					if ( (typeof the_object.state != "undefined") && (typeof the_object.city != "undefined") )
					{
						document.forms['choose_a_state'].browsecity.value = the_object.city;
						document.forms['choose_a_state'].state_code.value = the_object.state;
						
						// zero out if we had any old values
						document.forms['choose_a_state'].zip.value = "";
					}
					
					if (document.forms['choose_a_state'].zip.value.length == 0 
						&& (document.forms['choose_a_state'].browsecity.value.length == 0 
							&& document.forms['choose_a_state'].state_code.value.length == 0) )
					{
						alert("Please Enter a City and State, or valid Zip Code");
					}
					else
					{
						document.choose_a_state.submit();
					}
				}
				else
				{
					// clear out old values
					document.forms['choose_a_state'].zip.value = "";
					document.forms['choose_a_state'].browsecity.value = "";
					document.forms['choose_a_state'].state_code.value = "";
					
					if (document.forms['choose_a_state'].search_box.value == 'index')
					{
						new_html = "<input type=\"image\" value=\"Browse\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonSearch.gif\" alt=\"Find A Home & Real Estate Listings\" onClick=\"document.forms.choose_a_state.distance.value='0';\" class=\"buttonsearch\" />\n";
						new_html += "<input type=\"image\" value=\"Options\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonOptions.gif\" alt=\"Click for more search options\" onClick=\"document.forms.choose_a_state.distance.value='25';\" class=\"buttonmore\" />\n";
					}
					else
					{
						if (document.forms['choose_a_state'].search_box.value == 'find_a_home')
						{
							new_html = "<input type=\"image\" value=\"Browse\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonSearch.gif\" alt=\"Find A Home & Real Estate Listings\" onClick=\"document.forms.choose_a_state.distance.value='0';\"/>\n";
							new_html += "<input type=\"image\" value=\"Options\" src=\"http://images.harmonhomes.com/img/11/design/clean-hh_II/newdesign04/boxparts/ButtonOptions.gif\" alt=\"Click for more search options\" onClick=\"document.forms.choose_a_state.distance.value='25';\" style=\"margin-left:50px\" />\n";
						}
					}
			
					document.getElementById("subproc").innerHTML = new_html;
					if (document.forms['choose_a_state'].search_box.value == 'index')
						ajax_showTooltip(request.responseText,document.getElementById("input_selection"), "left", "red");
					else
						ajax_showTooltip(request.responseText,document.getElementById("input_selection"), "right", "red");
				}		
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mls_webid(id)
{
	if (id.length == 0)
	{
		ajax_showTooltip(get_error("no_value"),document.getElementById("mls_webid_image"), "bottom_left", "red");
		return false;
	}
	
	var url="/ajax_stub.php?mls_webid=1&id="+id;
	httpRequest("GET",url,true,handleResponse_mls_webid);
}

function handleResponse_mls_webid()
{
	if(ajax_tooltipObj)
		ajax_hideTooltip();
		
	document.getElementById("mls_webid_image").innerHTML = '<img class="webid_image" src="http://images.harmonhomes.com/img/11/design/clean-hh_II/new_icons/animated_go_button.gif" class="imgNoBorder" />';
	
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			// put the GO button back
			//document.getElementById("mls_webid_image").innerHTML = '<input type="image" value="websearch" src="http://images.harmonhomes.com/img/11/design/clean-hh/newdesign04/button-go3.gif" alt="Web ID Search"  class="webid_image" onclick="mls_webid(alt_search_id.value)">';
			document.getElementById("mls_webid_image").innerHTML = '<input type="image" value="websearch" src="http://images.harmonhomes.com/img/11/design/clean-hh/newdesign04/button-go3.gif" alt="Web ID Search"  class="webid_image">';
			if (request.responseText.trim() == "false")
			{
				ajax_showTooltip(get_error("bad_mls_webid"),document.getElementById("mls_webid_image"), "bottom_left", "red");
			}
			else
			{
				if (request.responseText.trim() != "detail")
				{
					window.open("http://www.harmonhomes.com/redirect_transfer.php?type=WEBSITE&track=0&website="+request.responseText);
				}
				else
				{
					document.web_id.submit();
				}
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}


function mhs_login(username, password, type_flag)
{
	if (type_flag == null)
	{
		var type_flag = 'CON';
	}
	var url="/ajax_stub.php?mhs_login=1&username="+username+"&password="+password+"&type_flag="+type_flag;
	httpRequest("GET",url,true,handleResponse_login);
}

function handleResponse_login()
{
	if(ajax_tooltipObj)
		ajax_hideTooltip();
		
	document.getElementById("mhsbarbutton").innerHTML = '<img src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/login_processing_button.gif" class="imgNoBorder" />';
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			if (request.responseText == "false")
			{
				// put the login button back
				document.getElementById("mhsbarbutton").innerHTML = '<a href="#" onclick="mhs_login(username.value, password.value,type_flag)"><img src="http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/login_button.gif" class="imgNoBorder" /></a>';
				// call the message javascript for user nav bar
				// with an error
				ajax_showTooltip(get_error("failed_login"),document.getElementById("mhsbarbutton"), "bottom_left", "red");
			}
			else
			{
				document.getElementById("mhs_nav_bar").innerHTML = request.responseText;
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
} 

function mhs_logout(type_flag)
{
	var url="/ajax_stub.php?mhs_logout=1";
	httpRequest("GET",url,true,handleResponse_logout);
}

function handleResponse_logout()
{
	if (request.readyState == 1)
		processing(true);
		
	if (request.readyState == 4)
	{
		processing(false);
		 
		if(request.status == 200)
		{
			if (request.responseText == "false")
			{
				// call the message javascript for user nav bar
				// with an error
			}
			else
			{
				document.location.reload();
//				var navbar = document.getElementById('mhs_nav_bar').innerHTML;
//				document.getElementById("mhs_nav_bar").innerHTML = request.responseText;
//				if (navbar.match('Upgrades'))
//				{
//						document.location.href = "/myPAL/login";
//				}
//				else
//				{
//						document.location.href = "/myHomeSearch/login";
//				}
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mhs_save_listing(consumer_id, listing_id, type, page)
{
	var url="/ajax_stub.php?mhs_save_listing=1&consumer_id="+consumer_id+"&listing_id="+listing_id+"&type="+type+"&page="+page;

	switch (page)
	{
		case 'photos':
			httpRequest("GET",url,true,handleResponse_save_listing_photos);
			break;
		case 'video':
			httpRequest("GET",url,true,handleResponse_save_listing_videos);
			break;
		case 'allfeaturedlistings':
			httpRequest("GET",url,true,handleResponse_save_listing_allfeaturedlistings);	
			break;
	}
}

function mhs_delete_listing(consumer_id, listing_id, type, page)
{
	var url="/ajax_stub.php?mhs_delete_listing=1&consumer_id="+consumer_id+"&listing_id="+listing_id+"&type="+type+"&page="+page;
	
	switch (page)
	{
		case 'photos':
			httpRequest("GET",url,true,handleResponse_delete_listing_photos);
			break;
		case 'video':
			httpRequest("GET",url,true,handleResponse_delete_listing_videos);
			break;
		case 'allfeaturedlistings':
			httpRequest("GET",url,true,handleResponse_delete_listing_allfeaturedlistings);	
			break;
	}	
}

function handleResponse_save_listing_photos()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
		document.getElementById("mhs_saved_listing_photos").innerHTML = '<img border="0" src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_69x70.gif" style="margin:0px -3px;  _padding:0px; _border:none;">';
	}
		
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			var json = eval("(" + request.responseText + ")");
			if ( json.has_error == 1)
			{
				document.getElementById("mhs_saved_listing_photos").innerHTML = json.html;
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_photos"), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_photos").innerHTML = json.html;
				ajax_showTooltip_timed(get_error("listing_saved"),document.getElementById("mhs_saved_listing_photos"),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_save_listing_videos()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
		document.getElementById("mhs_saved_listing_video").innerHTML = '<img border="0" src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_69x70.gif" style="margin:0px -3px;  _padding:0px; _border:none;">';
	}
		
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			var json = eval("(" + request.responseText + ")");
			if ( json.has_error == 1)
			{
				document.getElementById("mhs_saved_listing_video").innerHTML = json.html;
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_video"), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_video").innerHTML = json.html;
				ajax_showTooltip_timed(get_error("listing_saved"),document.getElementById("mhs_saved_listing_video"),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_save_listing_allfeaturedlistings()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
			
		processing(true);
	}
		
	if (request.readyState == 4)
	{
		processing(false);
		if(request.status == 200)
		{
			var json = eval("(" + request.responseText + ")");
			if ( json.has_error == 1)
			{
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_"+json.listing_id), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_"+json.listing_id).innerHTML = json.html;
				document.getElementById("mhs_saved_listing_img_"+json.listing_id).style.display = "inline";
				ajax_showTooltip_timed(get_error("listing_saved"),document.getElementById("mhs_saved_listing_"+json.listing_id),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_delete_listing_videos()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
		document.getElementById("mhs_saved_listing_video").innerHTML = '<img border="0" src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_69x70.gif" style="margin:0px -3px;  _padding:0px; _border:none;">';
	}
		
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			var json = eval('(' + request.responseText + ')');
			if ( json.has_error == 1)
			{
				document.getElementById("mhs_saved_listing_video").innerHTML = json.html;
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_video"), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_video").innerHTML = json.html;
				ajax_showTooltip_timed(get_error("listing_deleted"),document.getElementById("mhs_saved_listing_video"),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_delete_listing_photos()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
		document.getElementById("mhs_saved_listing_photos").innerHTML = '<img border="0" src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_69x70.gif" style="margin:0px -3px;  _padding:0px; _border:none;">';
	}
		
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			var json = eval('(' + request.responseText + ')');
			if ( json.has_error == 1)
			{
				document.getElementById("mhs_saved_listing_photos").innerHTML = json.html;
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_photos"), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_photos").innerHTML = json.html;
				ajax_showTooltip_timed(get_error("listing_deleted"),document.getElementById("mhs_saved_listing_photos"),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_delete_listing_allfeaturedlistings()
{
	if (request.readyState == 1)
	{
		if(ajax_tooltipObj)
			ajax_hideTooltip();
			
		processing(true);
	}
		
	if (request.readyState == 4)
	{
		processing(false);
		if(request.status == 200)
		{
			var json = eval('(' + request.responseText + ')');
			if ( json.has_error == 1)
			{
				ajax_showTooltip(get_error("0"),document.getElementById("mhs_saved_listing_"+json.listing_id), "bottom_right", "red");
			}
			else
			{
				document.getElementById("mhs_saved_listing_"+json.listing_id).innerHTML = json.html;
				document.getElementById("mhs_saved_listing_img_"+json.listing_id).style.display = "none";
				ajax_showTooltip_timed(get_error("listing_deleted"),document.getElementById("mhs_saved_listing_"+json.listing_id),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mhs_save_search(consumer_id, mss_id, input_selection, state_code, browsecitys, zip, sort, whichway, searchtype, property_type, 
							lorange, hirange, bedroom_min, bedroom_max, bath_min, bath_max, search_box)
{
	var url="/ajax_stub.php?mhs_save_search=1&consumer_id="+consumer_id+"&mss_id="+mss_id+"&input_selection="+input_selection+"&state_code="+state_code+"&browsecitys="+browsecitys+"&zip="+zip+"&sort="+sort+"&whichway="+whichway+"&searchtype="+searchtype+"&property_type="+property_type+"&lorange="+lorange+"&hirange="+hirange+"&bedroom_min="+bedroom_min+"&bedroom_max="+bedroom_max+"&bath_min="+bath_min+"&bath_max="+bath_max+"&search_box="+search_box;
	httpRequest("GET",url,true,handleResponse_save_search);
}

function handleResponse_save_search()
{
	if (request.readyState == 1)
	{
		document.getElementById("mhs_saved_search").innerHTML = '<img src="http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/my_home_search/icons/muted_processing_52x70.gif" style=\"border:none\">';
		if(ajax_tooltipObj)
			ajax_hideTooltip();
	}
		
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			if ( request.responseText.indexOf("|") != -1)
			{
				var error = request.responseText.split("|");
				document.getElementById("mhs_saved_search").innerHTML = error[2];
				ajax_showTooltip(get_error(error[1]),document.getElementById("mhs_saved_search"), "bottom_left", "red");
			}
			else
			{
				document.getElementById("mhs_saved_search").innerHTML = '<img src="http://images.harmonhomes.com/img/11/design/clean-hh_II/new_icons/search_saved.gif" class="imgNoBorder">';
				ajax_showTooltip_timed(get_error("search_saved"),document.getElementById("mhs_saved_search"),"bottom_right","blue","default");
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mhs_delete_search(consumer_id, mss_id, type)
{
	var url="/ajax_stub.php?mhs_delete_search=1&consumer_id="+consumer_id+"&mss_id="+mss_id+"&type="+type;
	httpRequest("GET",url,true,handleResponse_delete_search);
}

function handleResponse_delete_search()
{
	if (request.readyState == 1)
		processing(true);
		
	if (request.readyState == 4)
	{
		processing(false);
		
		if(request.status == 200)
		{
			if (request.responseText == "false")
			{
				// call the message javascript for user nav bar
				// with an error
			}
			else
			{
				var mhs_div = document.getElementById("mhs_search");
				var old_search = document.getElementById("mhs_search_"+request.responseText);
				var height = old_search.offsetHeight;
				mhs_div.removeChild(old_search);
				setHeight(height);
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mhs_change_send_email(consumer_id, mss_id, type)
{
	// figure out what was selected
	var selection = document.getElementById("run_frequency_"+mss_id);
	var value = selection.options[selection.selectedIndex].value;
	var url="/ajax_stub.php?mhs_change_send_email=1&consumer_id="+consumer_id+"&mss_id="+mss_id+"&type="+type+"&value="+value;
	httpRequest("GET",url,true,handleResponse_change_send_email);
}

function handleResponse_change_send_email()
{
	if (request.readyState == 1)
		processing(true);
	
	if (request.readyState == 4)
	{
		processing(false);
		
		if(request.status == 200)
		{
			if (request.responseText == "false")
			{
				// call the message javascript for user nav bar
				// with an error
			}
			else
			{
				var return_values = request.responseText.split(",");
				if (return_values[1] == "never")
					document.getElementById("mhs_search_expire_"+return_values[0]).style.visibility='hidden';
				else
					document.getElementById("mhs_search_expire_"+return_values[0]).style.visibility='visible';
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function mhs_edit_search_expire(mss_id, expire, consumer_id)
{
	if(ajax_tooltipObj)
		ajax_hideTooltip();
		
	// set up the boxes
	var date_boxes = "";
	var m_names = new Array("JAN", "FEB", "MAR", 
"APR", "MAY", "JUN", "JUL", "AUG", "SEP", 
"OCT", "NOV", "DEC");
	var expire_parts = expire.split("-");
	date_boxes = "<select id='mhs_search_edit_day_"+mss_id+"' name='mhs_search_edit_day_"+mss_id+"'>";
	for (var x = 1; x < 32; x++)
	{
		date_boxes += "<option value="+x+" ";
		if (expire_parts[0] == x)
			date_boxes += "SELECTED";
		date_boxes += ">"+x+"</option>";
	}
	date_boxes += "</select>";
	
	date_boxes += "<select id='mhs_search_edit_month_"+mss_id+"' name='mhs_search_edit_month_"+mss_id+"'>";
	for (var x = 0; x < 11; x++)
	{
		date_boxes += "<option value="+m_names[x]+" ";
		if (expire_parts[1] == m_names[x])
			date_boxes += "SELECTED";
		date_boxes += ">"+m_names[x]+"</option>";
	
	}
	date_boxes += "</select>";
	
	date_boxes += "<select id='mhs_search_edit_year_"+mss_id+"' name='mhs_search_edit_year_"+mss_id+"'>";
	var date = new Date();
	var year = date.getFullYear();
	expire_parts[2] = 20 + expire_parts[2];
	for (var x = year; x < (year+3); x++)
	{
		date_boxes += "<option value="+x+" ";
		if (expire_parts[2] == x)
			date_boxes += "SELECTED";
		date_boxes += ">"+x+"</option>";
	}
	date_boxes += "</select>";
	
	date_boxes += "<a href='#' onclick='ajax_hideTooltip(); mhs_save_search_expire("+mss_id+", "+consumer_id+", mhs_search_edit_day_"+mss_id+".options[mhs_search_edit_day_"+mss_id+".selectedIndex].value, mhs_search_edit_month_"+mss_id+".options[mhs_search_edit_month_"+mss_id+".selectedIndex].value, mhs_search_edit_year_"+mss_id+".options[mhs_search_edit_year_"+mss_id+".selectedIndex].value); return false;' onmouseover=\"ajax_showTooltip_delay(get_error('help_search_expire_edit'),this,'bottom_left','blue','default');return false\" onmouseout=\"ajax_hideTooltip()\"><img style='margin-left:10px;border:none' src='http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/edit_icon.gif'></a>";
	
	document.getElementById("mhs_search_expire_"+mss_id).innerHTML = date_boxes;
}

function mhs_edit_name(mss_id, name, consumer_id)
{
	var width = document.getElementById("mhs_search_name_"+mss_id).offsetWidth - 19;
	document.getElementById("mhs_search_name_"+mss_id).innerHTML = "<input style='width:"+width+"px' type='text' id='mhs_search_edit_name_"+mss_id+"' value='"+name+"'><a href='#' onclick='ajax_hideTooltip(); mhs_save_search_name("+mss_id+", "+consumer_id+", mhs_search_edit_name_"+mss_id+".value); return false;' onmouseover=\"ajax_showTooltip_delay(get_error('help_search_name_edit'),this,'bottom_left','blue','default');return false\" onmouseout=\"ajax_hideTooltip()\"><img style='margin-left:10px;border:none' src='http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/edit_icon.gif'></a>";
}

function mhs_save_search_name(mss_id, consumer_id, name)
{
	if(ajax_tooltipObj)
		ajax_hideTooltip();
			
	// fix this with json returns
	if (name.length > 0)
	{
		var url="/ajax_stub.php?mhs_save_search_name=1&consumer_id="+consumer_id+"&mss_id="+mss_id+"&name="+name;
		httpRequest("GET",url,true,handleResponse_save_search_name);
		document.getElementById("mhs_search_name_"+mss_id).innerHTML = "<b><a href='/homesearch.php?run_search=1&mss_id="+mss_id+"'>"+name+"</b></a><a href='#' onclick='ajax_hideTooltip(); mhs_edit_name("+mss_id+", \""+name+"\", "+consumer_id+"); return false;' onmouseover=\"ajax_showTooltip_delay(get_error('help_search_name_edit'),this,'bottom_left','blue','default');return false\" onmouseout=\"ajax_hideTooltip()\"><img style='margin-left:10px;border:none' src='http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/edit_icon.gif'></a>";
	}
	else
	{
		ajax_showTooltip(get_error("3"),document.getElementById("mhs_search_name_"+mss_id), "right", "red");
	}
}

function mhs_save_search_expire(mss_id, consumer_id, day, month, year)
{
	var url="/ajax_stub.php?mhs_search_expire=1&consumer_id="+consumer_id+"&mss_id="+mss_id+"&day="+day+"&month="+month+"&year="+year;
	httpRequest("GET",url,true,handleResponse_save_search_expire);
}

function handleResponse_save_search_name()
{
	if (request.readyState == 1)
		processing(true);
		
	if (request.readyState == 4)
	{
		processing(false);
		
		if(request.status == 200)
		{
			var return_values = request.responseText.split("|");
			
			if ( return_values[0] == "false")
			{
				// show error
			}
			else
			{
				// processing
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function handleResponse_save_search_expire()
{
	if (request.readyState == 1)
	{
		processing(true);
		if(ajax_tooltipObj)
			ajax_hideTooltip();
	}
		
	if (request.readyState == 4)
	{
		processing(false);
		
		if(request.status == 200)
		{
			var return_values = request.responseText.split("|");
			
			if ( return_values[0] == "false")
			{
				ajax_showTooltip(get_error(return_values[2]),document.getElementById("mhs_search_expire_"+return_values[1]), "right", "red");
			}
			else
			{
				document.getElementById("mhs_search_expire_"+return_values[0]).innerHTML = "Expires: "+return_values[2]+"<a href='#' onclick='ajax_hideTooltip(); mhs_edit_search_expire("+return_values[0]+", \""+return_values[3]+"\", "+return_values[1]+"); return false;' onmouseover=\"ajax_showTooltip_delay(get_error('help_search_expire_edit'),this,'bottom_left','blue','default');return false\" onmouseout=\"ajax_hideTooltip()\"><img style='margin-left:10px;border:none' src='http://images.harmonhomes.com/img/11/design/clean-hh_II/MyHomeSearch/edit_icon.gif'></a>";
			}
			
			if (bIsDevSite == 1)
			{
				var url="/ajax_stub.php?write_debug_query=1";				
				httpRequest("GET",url,false, handleResponse_write_query);
				url="/ajax_stub.php?write_debug_misc=1";				
				httpRequest("GET",url,true, handleResponse_write_misc);
			}
		}
	}
}

function nNavigatorWindow ( listing_Url ) {
	var newWindow;
	if(newWindow) { newWindow = window.close(); }
	newWind = window.open( listing_Url , "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=670, height=620")
	}
	
function nNavigatorWindow ( listing_Url ) {
	var newWindow;
	if(newWindow) { newWindow = window.close(); }
	newWind = window.open( listing_Url , "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=670, height=620")
	}
	
	
function f_clientWidth() {
        return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
        );
}

function f_scrollLeft() {
        return f_filterResults (
        window.pageXOffset ? window.pageXOffset : 0,
        document.documentElement ? document.documentElement.scrollLeft : 0,
        document.body ? document.body.scrollLeft : 0
);
}

function f_scrollTop() {
        return f_filterResults (
        window.pageYOffset ? window.pageYOffset : 0,
        document.documentElement ? document.documentElement.scrollTop : 0,
        document.body ? document.body.scrollTop : 0
);
}

function f_filterResults(n_win, n_docel, n_body) {
        var n_result = n_win ? n_win : 0;
        if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function handleResponse_write_query()
{
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			document.getElementById("query").innerHTML = document.getElementById("query").innerHTML + request.responseText;
		}
	}
}

function handleResponse_write_misc()
{
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			document.getElementById("misc").innerHTML = document.getElementById("misc").innerHTML + request.responseText;
		}
	}
}

function get_error(error)
{
	var error_message = "";
	switch (error)
	{	
		case '0':
			error_message = "You must be logged in to My Home Search to use this functionality.<br><br>If you would like to login go <a href='http://www.harmonhomes.com/myHomeSearch/Login'>here</a>, if you need to register, go <a href='http://www.harmonhomes.com/myHomeSearch/Register'>here</>.";
			break;
		case '1':
			error_message = "Unknown error with your request.";
			break;
		case '2':
			error_message = "You can not set the expire date into the past. If you no longer want to receive emails for this saved search, please change the frequency to NEVER.";
			break;
		case '3':
			error_message = "The name of your search must be at least 1 character long.";
			break;
		case 'failed_login':
			error_message = "Your username / password did not match, please try again.<br><br>If you are having trouble remembering your username / password please go <a href='http://www.harmonhomes.com/myHomeSearch/forgotten-password'>here</a>.";
			break;
		case 'help_search_name':
			error_message = "Saved search name - Click here to view the listings within this saved search.";
			break;
		case 'help_search_name_edit':
			error_message = "Click here to change the saved search name. When finished editing, click on this icon again to save your changes.";
			break;
		case 'help_search_edit':
			error_message = "Click here to modify saved search options. When finished editing, rerun the search, then click on resave search icon on listing results page to save changes.";
			break;
		case 'help_search_delete':
			error_message = "Clicking this will delete this saved search.";
			break;
		case 'help_search_total_count':
			error_message = "This is the total number of listings for your saved search. Clicking this link will take you to the search results showing all these listings. Any New/Updated listings will show up at the top of the results.";
			break;
		case 'help_search_new_count':
			error_message = "This is the total number of NEW listings for your saved search. Clicking this link will take you to the search results only showing your NEW listings.";
			break;
		case 'help_search_update_count':
			error_message = "This is the total number of UPDATED listings for your saved search. Clicking this link will take you to the search results only showing your UPDATED listings.";
			break;
		case 'help_search_expire_edit':
			error_message = "Click here to change the expiration date for new and updated listing email alerts.";
			break;
		case 'listing_saved':
			error_message = "Listing successfully saved.";
			break;
		case 'listing_deleted':
			error_message = "Listing successfully deleted.";
			break;
		case 'search_saved':
			error_message = "Search successfully saved.";
			break;
		case 'search_deleted':
			error_message = "Search successfully deleted.";
			break;
		case 'bad_mls_webid':
			error_message = "The MLS or Web ID you entered was not found.";
			break;
		case 'no_value':
			error_message = "Please enter a value to search on.";
			break;
	}
	
	return error_message;
}
