// function used to delay by a set time calling ajax script until a specified // number of ms from the last keypress var key_location_delay = (function() { var timer = 0; return function(callback, ms) { clearTimeout(timer); timer = setTimeout(callback, ms); }; })(); function suggest_location(e) { var intKey = 0; e = (window.event)? event : e; intKey = (e.keyCode)? e.keyCode: e.charCode; if (intKey == 40) //down { //SWITCH THEM OFF if (this.pos>0 && this.pos<=num_rows) { div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#F1F8FF'; document.getElementById("find").value = ''; } //SWITCH THEM ON if (this.pos+1<=num_rows) { this.pos = this.pos+1; div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#ffffff'; document.getElementById("find").value = document.getElementById(div_id + "_value").value.replace(/&/gi, '&'); } else if(this.pos+1 == num_rows+1) { this.pos = this.pos +1; } } else if (intKey == 38) //up { //SWITCH THEM OFF if (this.pos>0 && this.pos<=num_rows) { div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#F1F8FF'; document.getElementById("find").value = ''; } //SWITCH THEM ON if (this.pos-1>0) { this.pos = this.pos-1; div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#ffffff'; input_text = document.getElementById("find").value = document.getElementById(div_id + "_value").value.replace(/&/gi, '&'); } else if (this.pos-1==0) { this.pos = this.pos-1; } } else { this.pos=0; key_location_delay(function(){ getSuggestions_location(); }, 300); } } function getSuggestions_location() { xmlHttp=GetXmlHttpObject2(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var citynameleft = document.getElementById('city_nameleft'); if (citynameleft) { citynameleft = citynameleft.value; } else { citynameleft = ""; } var url="/location/suggest_location.php?str="+document.getElementById("find").value +"&city_name=" + citynameleft ; xmlHttp.onreadystatechange=displaySuggestions_location; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function displaySuggestions_location() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { trimmed = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); delim = trimmed.indexOf(":==:"); num_rows = parseInt(trimmed.substr(0,delim)); remaining = trimmed.substr(trimmed.indexOf(":==:")+4); trimmed = remaining; if (remaining!='') { document.getElementById("suggestBox_location").style.visibility = 'visible'; document.getElementById("suggestBox_location").innerHTML=remaining; } else { document.getElementById("suggestBox_location").style.visibility = 'hidden'; this.pos = 0; } } } function changePosition_location(id) { if (this.pos > 0 && this.pos <= num_rows) { div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#F1F8FF'; document.getElementById("find").value = ''; } this.pos = id; div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#ffffff'; } function updateSearch_location(city) { window.location = "/cities/" + city; /* if (this.pos > 0 && this.pos <= num_rows) { div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#F1F8FF'; document.getElementById("find").value = ''; } this.pos = id; div_id = "sl"+this.pos; document.getElementById(div_id).style.background = '#ffffff'; document.getElementById("find").value = document.getElementById(div_id +"_value").value.replace(/&/gi, '&'); document.getElementById("suggestBox_location").style.visibility = 'hidden'; document.getElementById("find").focus(); document.getElementById("find").value = document.getElementById("find").value; this.pos = 0; */ } function clickedon_location(id) { //alert('yip' + document.getElementById('industry_name_left').value); if(document.getElementById('find').value=='') { document.getElementById('find').value='Find a Service ...'; }else if( document.getElementById('find').value=='Find a Service ...') { document.getElementById('find').value=''; } document.getElementById('suggestBox_location').style.visibility='hidden'; } /* function GetXmlHttpObject2() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } return xmlHttp; }*/