//<![CDATA[
var is_ie6 = (
	window.external &&
	typeof window.XMLHttpRequest == "undefined"
);
//]]>


function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('suggestions').hide();
		if(is_ie6){
			$('price-range').style.visibility='visible';
			$('beds').style.visibility='visible';
		}
	} else {
		
		new Ajax.Request('http://www.sellmodern.com/template/sitesellmodern/ajax-processor.php', {method: 'post', parameters: {queryString: ""+inputString+""}, onSuccess: function(data){
			$('autoSuggestionsList').innerHTML = data.responseText;
			
			if(data.responseText.length == 0){ 
				$('suggestions').hide();
				if(is_ie6){
					$('price-range').style.visibility='visible';
					$('beds').style.visibility='visible';
				}
			}
			else{
				$('suggestions').show();
				
				if(is_ie6){
					$('price-range').style.visibility='hidden';
					$('beds').style.visibility='hidden';
				}
			}
		}});
	}
} // lookup

function fill(thisValue) {
	if(thisValue == null)
		thisValue = '';
	
	$('location').value = thisValue;
	
	if(is_ie6)
		setTimeout("$('suggestions').hide();$('price-range').style.visibility='visible';$('beds').style.visibility='visible';", 200);
	else
		setTimeout("$('suggestions').hide();", 200);
	
}


		/*  This is the old ajax request with jquery. Jquery conflicted with prototype and broke lightbox so i redid the ajax request in prototype
		
		$.post("http://www.sellmodern.com/template/sitesellmodern/ajax-processor.php", {queryString: ""+inputString+""}, function(data){
			$('#autoSuggestionsList').html(data);
			if(data.length == 0) 
				$('#suggestions').hide();
			else
				$('#suggestions').show();
		});*/

/*function Trim(s)
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function getHTTPObject()
{
    if (window.XMLHttpRequest)
      {
          xmlhttp=new XMLHttpRequest()
      }
    else if (window.ActiveXObject)
      {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
      }
    return xmlhttp;
}

var http = getHTTPObject();

function search_text()
{

    if(document.getElementById('search-text').value.length>3)
    {
			
    var vUrl;
    vUrl='wordajax.php?value='+Trim(document.getElementById('search-text').value)+'';
     
      var isWorking = false;
        if (!isWorking)
        {
                http.open("GET", vUrl , true);
                 isWorking = true;
                http.onreadystatechange = handleHttpResponseemail;
            http.send(null);
        }
    }    
}
function handleHttpResponseemail() {
    if (http.readyState == 4)
    {
    isWorking = false;
    var valResponse;
    valResponse = http.responseText;     
   
        document.getElementById("searcheid").innerHTML=""; 
        var str =valResponse.split("\n");
		
      //alert(valResponse); 
	   
	   //alert(str.length);
        var suggest="";
        for(i=0; i < str.length - 1; i++) {
            suggest = '<div style="cursor:hand;cursor:pointer;" onmouseover="javascript:suggestOver(this);" ';
            suggest += 'onmouseout="javascript:suggestOut(this);" ';
            suggest += 'onclick="javascript:setSearch(this.innerHTML);"';
            suggest += 'class="suggest_link">' + str[i] + '</div>';
            document.getElementById("searcheid").innerHTML+= suggest;
            document.getElementById("searcheid").style.display="";   
        }
    //alert(suggest);
    //document.getElementById("searcheid").innerHTML=valResponse;
    //return 1;    
    }
    
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
    document.getElementById('search-text').value = value;
    document.getElementById('searcheid').innerHTML = '';
	 document.getElementById('searcheid').style.display = 'none';
   
}

function copytotext(val)
{

 document.getElementById('search-text').value=val;
}

function onkeyPress(e)
{
var key = window.event ? e.keyCode : e.which;
if (key == 13)
StartClick();
e.cancelBubble = true;
e.returnValue = false;
return false;
}*/