var requestObject = createRequestObject(); var reg_name; var acregion_keydown_idx = 0; var acregion_timer = null; var reg_start=0; var reg_keyname; function sendRequest(evt) { if (!evt) evt = event; if (window.event) ackey = window.event.keyCode; else if (evt) ackey = evt.which; if(ackey==40 || ackey==38 || ackey==9) { void(0); return; } if(acregion_timer!=null){ clearTimeout(acregion_timer); } reg_keyname=document.forms.main_form['region_name'].value; if (reg_keyname.length > 2) reg_start=1; else reg_start=0; var q = 'https://yippykya.com/snmenu_region_ajax.php?key=' + escape(document.forms.main_form['region_name'].value) + '&country_num=' + document.forms.main_form['country_num'].value; acregion_timer = setTimeout('delayExec("'+ q +'");',500); } function delayExec(myURL){ clearTimeout(acregion_timer); if (!isNaN( parseFloat(document.getElementById("country_num").value) ) ) { if (parseFloat(document.getElementById("country_num").value) > 0) { document.getElementById("region_name").disabled=false; } else document.getElementById("region_name").disabled=true; } else document.getElementById("region_name").disabled=true; requestObject.open('GET', myURL, true); requestObject.onreadystatechange = getRegion; requestObject.send(null); } function autoregion_keydown(evt){ if (window.event) ackey = window.event.keyCode; else if (evt) ackey = evt.which; switch (ackey){ case 38: //up acregion_hover_list(acregion_keydown_idx-1); return false; break; case 40: // down acregion_hover_list(acregion_keydown_idx+1); return false; break; case 13: // return document.getElementById("region_name").blur(); acregion_return(); return false; break; case 9: if (reg_start==1) { if (window.event) window.event.keyCode=39; else if (evt) evt.which=39; } else if(document.getElementById('auto_div').style.display != 'none') { document.getElementById('auto_div').style.display='none'; document.getElementById("region_name").focus(); } break; default: break; } } function acregion_hover_list(idx){ old_item = g('reg_' + acregion_keydown_idx); cur_item = g('reg_' + idx); if(cur_item!=null){ //alert('here'); cur_item.className = 'autocomplete_hover'; acregion_keydown_idx = idx; }else{ return; } if(old_item!=null){ old_item.className = 'autocomplete'; } } function acregion_return(){ cur_item = g('reg_' + acregion_keydown_idx); if(cur_item!=null){ // alert(cur_item.childNodes[0]); selectEntry(cur_item.childNodes[0]); } autoregion_clear(); return false; } function autoregion_clear(){ acregion_keydown_idx = 0; } function getRegion() { if ( requestObject.readyState == 4 ) { var rawResponse = requestObject.responseText; var myDiv = document.getElementById('auto_div'); if (document.forms.main_form['region_name'].value!=reg_name) document.forms.main_form['region_num'].value ='0'; if ( rawResponse.length > 2 ) { myDiv.innerHTML = unescape(rawResponse); myDiv.style.display = 'block'; myDiv.zIndex=2; if (document.getElementById('desrch')) { if (document.getElementById('desrch').disabled==false) document.getElementById('desrch').disabled=true; } } else { myDiv.style.display = 'none'; } } } /* function selectEntry(varName,varNum,varBlank) { document.forms.main_form['region_name'].value = varName; reg_name=varName; document.forms.main_form['region_num'].value = varNum; document.getElementById('auto_div').style.display = 'none'; if (document.getElementById('desrch')) { document.getElementById('desrch').disabled=false; } } */ function selectEntry(obj){ varName = obj.attributes.getNamedItem('varname').value; varNum = obj.attributes.getNamedItem('varnum').value; varBlank = obj.attributes.getNamedItem('varblank').value; document.forms.main_form['region_name'].value = varName; reg_name=varName; document.forms.main_form['region_num'].value = varNum; document.getElementById('auto_div').style.display = 'none'; if (document.getElementById('desrch')) { document.getElementById('desrch').disabled=false; } reg_start=0; //document.forms.main_form['region_name'].focus(); }