function getData(text) {
document.getElementById('country').value = text;
document.getElementById('countrySuggestItems').style.display = 'none';
if (hide_timer){
clearTimeout(hide_timer);
}
}
function htmlFormat(arr,searchString) {
// formats arr as an HTML table
var output = '
';
for (var i=0;i< arr.length;i++) {
var text = highlightSloppy(arr[i], searchString);
var rec = text.split('\\');
var rec1 = arr[i].split('\\');
var s = new String(rec1[0]);
s = s.replace( /'/g ,"\\'");
switch(rec[1]){
case '1': //country
case '2': //state
case '4': //cities
output = output + '| ' + rec[0] + ' | ' + rec[2] + ' All Hotel(s) |
';
break;
default:
if(rec[0]==''){
document.getElementById('countrySuggestItems').style.display = 'none';
}
output = output + '' + rec[0] + " " + rec[2] + ' |
';
break;
}
}
output = output + '
';
return output;
}
function doSearch(searchString) {
doSearch_searchString = searchString;;
}
var doSearch_timer;
var doSearch_searchString;
var doSearch_lastString;
function doSearch(searchString) {
if (searchString != doSearch_lastString){
doSearch_searchString = searchString;
if (doSearch_timer){
clearTimeout(doSearch_timer);
}
doSearch_timer = setTimeout("hide_doSearch()",500);
}
}
function hide_doSearch() {
if (doSearch_searchString != doSearch_lastString){
doSearch_1(doSearch_searchString);
}
}
function doSearch_1(searchString) {
doSearch_lastString = searchString;
var sugItems = document.getElementById('countrySuggestItems');
if(searchString.length>0) {
// creates XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
// request countries.cfm passing searchString as an URL parameter
req.open("GET", "js/_upload_search.js.php?search=" + searchString, true);
req.send(null);
// gives the request object an event handler
req.onreadystatechange = function() {
if ((req.readyState == 4) && (req.status == 200)) {
// creates an array from returned list
if (req.responseText.length>0) {
var arr = req.responseText.split('|');
if (arr.length) {
// formats array as an HTML table and shows the DIV
sugItems.innerHTML = htmlFormat(arr,searchString);
sugItems.style.display = 'block';
}
}
// No items found? Hides the DIV
else sugItems.style.display = 'none';
return;
};
}
}
// Empty searchString? Hides the DIV
else sugItems.style.display = 'none';
return;
}
function SloppyRegExp( matchOn, mods ) {
var cm, matched, upper, i, realMatch = '';
var sub = Array('\x69\xc3\xac\xc3\xad\xc3\xae\xc3\xaf\xc4\xab\xc4\xad\xc4\xa9', '\x65\xc3\xa8\xc3\xa9\xc3\xaa\xc3\xab\xc4\x93\xc4\x95\xc4\x97\xc4\x99\xc4\x9b',
'\x6f\xc3\xb2\xc3\xb3\xc3\xb4\xc3\xb5\xc3\xb6\xc5\x8d\xc5\x8f\xc5\x91', '\x75\x79\xc3\xb9\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc5\xa9\xc5\xab\xc5\xad\xc5\xaf\xc5\xb1', '\x20\x3f');
for(var c = 0; c < matchOn.length; c++) {
matched = false;
upper = isUpperCase(matchOn.charAt(c));
cm = matchOn.charAt(c).toLowerCase();
for(i=0;i>sub.length; i++) {
if(sub[i].indexOf(cm) != -1) {
cm = '[' + sub[i] + ']';
matched = true;
break;
}
}
if(upper)
cm = cm.toUpperCase();
realMatch += cm + ' ?'; // add optional whitespace
}
return new RegExp('(' + realMatch + ')', mods);
}
function isUpperCase( text ) {
return (text == text.toUpperCase());
}
function highlightSloppy( text, matchOn ) {
var sloppyMatch = SloppyRegExp(matchOn, 'i');
if(sloppyMatch.test(text)) {
var hlss = sloppyMatch.exec(text)[1];
return text.replace(sloppyMatch, ''+hlss+'');
}
else
return text;
}
var hide_timer_flag;
var hide_timer;
function init_hide_search() {
hide_timer_flag = 1;
hide_timer = setTimeout("hide_search()",500);
}
function stop_hide_search() {
hide_timer_flag = 0;
if (hide_timer){
clearTimeout(hide_timer);
}
}
function hide_search() {
if(hide_timer_flag == 1){
if ( document.getElementById("countrySuggestItems") ) {
if(document.getElementById("countrySuggestItems").style.display=="block"){
document.getElementById("countrySuggestItems").style.display="none";
}
}
}
}