var global = [];var ref_for_AS=''; function showHint(event,search_box,suggestion_div,ref_for_AS) { var KeyID ; var key; var str = ''; var xmlhttp; var keycheck; var suggestions = []; try{ event = event || window.event; KeyID = event.keyCode || event.which; } catch(e){ } if((KeyID>=48 && KeyID<=57) || (KeyID>=65 && KeyID<=90)||(KeyID>=97 && KeyID<=122)|| (KeyID==32) || (KeyID==189) || (KeyID==8)) { keycheck = KeyID; }else{ keycheck = 0; } if(keycheck != 0){ try{ str = document.getElementById(search_box).value; if(str.length<2){ if(KeyID == 38 & KeyID == 40){return;} str = str.replace(/^ +/gm, '');	document.getElementById(search_box).value = str; return; }else{ var ref = ref_for_AS; var sub_str = str.substr(0,2); var validate; if(ref == ''){ ref_for_AS = str; validate = 0; }else{ if(ref == sub_str){ validate = 1; }else{ ref_for_AS = sub_str; validate = 0; } }sub_str=sub_str.replace(/^\s+/g,'').replace(/\s+$/g,'').replace(/[(]/g,'').replace(/[)]/g,'');sub_str = sub_str.replace(/[^a-zA-Z0-9 ]/g, ' '); sub_str = sub_str.replace(/^\s+/g, '').replace(/\s+$/g, ''); while(sub_str.indexOf('  ')>0){ sub_str = sub_str.replace('  ',' '); } var sub_str=sub_str.replace(/\s/g, ''); if(validate == 0){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var temp=xmlhttp.responseText; if(temp.length > 0){ global = temp.split(","); new AutoSuggest(document.getElementById(search_box),search_box,suggestion_div,ref_for_AS,global); fireEvent(search_box, "onkeyup"); } } }; xmlhttp.open("GET","/cgi-local/search_mcat.mp?ss="+sub_str+"&type="+search_box,true); xmlhttp.send(""); } } }catch(e){ } }else{ return; } } function fireEvent(element, eventName) { evt = document.getElementById(element)[eventName]; if (typeof(evt) == "function") { document.getElementById(element)[eventName](); } } function checkHide(){ if(document.getElementById('autosuggest_head') || document.getElementById('autosuggest_city')){ var disp_head; var disp; if(document.getElementById('autosuggest_head')) { disp_head = document.getElementById('autosuggest_head'); } if(document.getElementById('autosuggest_city')) { disp = document.getElementById('autosuggest_city'); } if(disp_head && disp_head.style.display) { if(disp_head.style.display == 'block'){ disp_head.style.display = 'none'; disp_head.highlighted = -1; } } if(disp && disp.style.display) { if(disp.style.display == 'block'){ disp.style.display = 'none'; disp.highlighted = -1; } } } } function AutoSuggest(elem,search_box,suggestion_div,ref_for_AS,suggestions) { var me = this; var TAB; var ESC; var KEYUP; var KEYDN; var ENTER; try{ this.elem = elem; this.suggestions = suggestions; this.eligible = new Array(); this.inputText = null; this.highlighted = -1; this.div = document.getElementById(suggestion_div); TAB = 9; ESC = 27; KEYUP = 38; KEYDN = 40; ENTER = 13; elem.setAttribute("autocomplete","off"); if(!(elem.id)) { var id = suggestion_div + idCounter; idCounter++; elem.id = id; } }catch(e){ } elem.onkeydown = function(ev) { var key; var len; try{ showHint(ev,search_box,suggestion_div,ref_for_AS); key = me.getKeyCode(ev); len = me.eligible.length; if(len >20){len = 20} }catch(e){ } switch(key) { case KEYUP: try{ if (me.highlighted > 0) { me.highlighted--; me.changeHighlight(key); me.elem.value = me.eligible[me.highlighted]; } break; }catch(e){ } case KEYDN: try{ if (me.highlighted < (len - 1) && me.div.style.display != 'none') {  me.highlighted++; me.changeHighlight(key); me.elem.value = me.eligible[me.highlighted]; } break; }catch(e){ } case ENTER: me.useSuggestion(); break; } }; elem.onkeyup = function(ev) { var key = me.getKeyCode(ev); switch(key) { case TAB: case ESC: case KEYUP: case KEYDN: return; case ENTER: me.useSuggestion(); break; default: try{ if ( this.value.length > 2) { me.inputText = this.value; me.highlighted = -1; me.getEligible(); me.createDiv(); me.positionDiv(); if(me.eligible.length > 0){ me.showDiv(); }else{ me.hideDiv(); } } else { me.hideDiv(); } }catch(e){ } } }; this.useSuggestion = function() { try{ if(this.highlighted > -1 && this.highlighted <= this.eligible.length){ this.elem.value = this.eligible[this.highlighted]; } this.hideDiv(); setTimeout("document.getElementById('" + this.elem.id + "').focus()",0); } catch(e){ } }; this.showDiv = function() { try{ this.div.style.display = 'block'; }catch(e){ } }; this.hideDiv = function() { try{ this.div.style.display = 'none'; this.highlighted = -1; }catch(e){ } }; this.changeHighlight = function() { var lis; try{ lis = this.div.getElementsByTagName('LI'); for (i in lis) { var li = lis[i]; if (this.highlighted == i) { li.className = "selected"; } else { if(li){li.className = "";} } } }catch(e){ } }; this.positionDiv = function() { var el; var x; var y; try{ el = this.elem; x = 0; y = el.offsetHeight; while (el.offsetParent && el.tagName.toUpperCase() != 'BODY') { x += el.offsetLeft; y += el.offsetTop; el = el.offsetParent; } x += el.offsetLeft; y += el.offsetTop; this.div.style.left = x + 'px'; this.div.style.top = (y-2) + 'px'; }catch(e){ } }; this.createDiv = function() { var ul; var ctr = 0; var len; try{ ul = document.createElement('ul'); len = this.eligible.length; }catch(e){ } if(len > 20){ len = 20; } for (i=0;i<=len-1;i++) { try{ var word = this.eligible[i]; var li = document.createElement('li'); var a = document.createElement('a'); a.innerHTML = word; li.appendChild(a); if (me.highlighted == i) { li.className = "selected"; } ul.appendChild(li); ctr++; }catch(e){ } } try{ this.div.replaceChild(ul,this.div.childNodes[0]); }catch(e){ } ul.onmouseover = function(ev) { var target; try{ target = me.getEventSource(ev); while (target.parentNode && target.tagName.toUpperCase() != 'LI') { target = target.parentNode; } var lis = me.div.getElementsByTagName('LI'); for (i in lis) { var li = lis[i]; if(li == target) { me.highlighted = i; break; } } me.changeHighlight(); }catch(e){ } }; ul.onclick = function(ev) { me.useSuggestion(); me.hideDiv(); me.cancelEvent(ev); document.searchForm.submit(); }; try{ this.div.className="suggestion_list"; this.div.style.position = 'absolute'; }catch(e){ } }; this.getEligible = function() { this.eligible = new Array(); for (i in this.suggestions) { try{ var suggestion = this.suggestions[i]; var input_string = this.inputText.toLowerCase(); input_string = input_string.replace(/ +$/,""); if(suggestion.toLowerCase().indexOf(input_string) == "0"){this.eligible[this.eligible.length] =suggestion;  } } catch(e){ } } }; this.getKeyCode = function(ev) { try{ if(ev){ return ev.keyCode; } if(window.event)	{ return window.event.keyCode; } }catch(e){ } }; this.getEventSource = function(ev) { try{ if(ev) { return ev.target; } if(window.event) { return window.event.srcElement; } }catch(e){ } }; this.cancelEvent = function(ev) { try{ if(ev) { ev.preventDefault(); ev.stopPropagation(); } if(window.event) { window.event.returnValue = false; } }catch(e){ } }; }function remove_text(Form) { Form.ss.style.color = "black"; if((Form.ss.value == 'specify product name to search suppliers...') || (Form.ss.value == 'specify product name to search suppliers...')) { Form.ss.value='';} } function remove_city(Form) { if(Form.city.value == ' All India...') { Form.city.value='';Form.city.style.color = "black"; } } function CheckDataSearch(Form) { Form.ss.value=Form.ss.value.replace(/^\s+/g,'').replace(/\s+$/g,'').replace(/[(]/g,'').replace(/[)]/g,''); if(Form.city) { Form.city.value=Form.city.value.replace(/^\s+/g,'').replace(/\s+$/g,'').replace(/[(]/g,'').replace(/[)]/g,''); } if((Form.ss.value == 'specify product name to search suppliers...') || (Form.ss.value == 'specify product name to search suppliers...')) { Form.ss.value=''; } Form.ss.value = Form.ss.value.replace(/[^a-zA-Z0-9 ]/g, ' '); Form.ss.value = Form.ss.value.replace(/^\s+/g, '').replace(/\s+$/g, ''); while(Form.ss.value.indexOf('  ')>0){ Form.ss.value = Form.ss.value.replace('  ',' '); } var temp=Form.ss.value.replace(/\s/g, ''); if (temp.length < 3){ alert("Enter at least three characters for Product Search."); Form.ss.focus(); return false; }else if(!(/[a-z]/.test(Form.ss.value)) && !(/[A-Z]/.test(Form.ss.value))) { alert("kindly enter valid String for Search"); Form.ss.focus();return false; } else {	Form.ss.value=Form.ss.value.toLowerCase(); if(Form.city) { Form.city.value=Form.city.value.toLowerCase(); } return true; } } function search_onload() {  if(document.searchForm){document.searchForm.ss.style.color = "#959595"; document.searchForm.ss.value='specify product name to search suppliers...'; }} var idCounter = 0;
