var saved_last_pos = "", sdcom_url = 'www.streetdirectory.com';
    baseurl = "http://" + location.hostname,
    traffic = null;
var global_data, global_flag_status = new Array(),
    global_update_data = true,
    global_stats = new Array(),
    stats = new Array();
var num_rows_per_page = 20,
    global_page = 1,
    global_highlight = {
        i: -1,
        prem: 0
    };
var categoryList = new Array(),
    premiumListing = new Array(),
    slideshow = new Array();
if (global_clear_cache == undefined) {
    var global_clear_cache = ""
}
var GA;

function pageIdentifySearch() {
    if (location.pathname.indexOf("/asia_travel/") != -1) {
        return "map_view"
    } else {
        if (location.pathname.indexOf("/businessfinder/preview/") != -1) {
            return "businessfinder_preview"
        } else {
            if (location.pathname.indexOf("/businessfinder/company/") != -1) {
                return "businessfinder_company"
            } else {
                if (location.pathname.indexOf("/businessfinder/company_detail") != -1) {
                    return "businessfinder_preview"
                } else {
                    if (location.pathname.indexOf("/businessfinder/") != -1) {
                        return "businessfinder_company"
                    } else {
                        return "map"
                    }
                }
            }
        }
    }
}


function $(a) {
    return document.getElementById(a)
}
function show_element(a) {
    if ($(a)) {
        $(a).style.display = "block"
    }
}
function hide_element(a) {
    if ($(a)) {
        $(a).style.display = "none"
    }
}

function containsDOM(a, c) {
    var b = false;
    do {
        if ((b = a == c)) {
            break
        }
        try {
            c = c.parentNode
        } catch (d) {
            c = null
        }
    } while (c != null);
    return b
}

function submitSearch(h) {
    var j = pageIndetify();
    f = document.fSdSearch;
    if (f.q.value == "" || f.q.value == "Find Businesses, Addresses or Products & Services here") {
        if ($("travel_from") && $("travel_to")) {
            if ($("travel_from").value != "" || $("travel_to").value != "") {
                alert("Please Select Option Below")
            } else {
                alert("You have not entered a keyword \n\n\n Try any of these keywords:\n\n a. Products and Services e.g Reflexology, Beauty\n b. Company Name e.g Asta Spa, Charles & Keith\n c. Addresses e.g Marina Bay Sands, Orchard Rd\n d. Bus Services Number e.g Bus 14\n e. Any Landmark in Singapore e.g Merlion, Beach")
            }
        } else {
            alert("You have not entered a keyword \n\n\n Try any of these keywords:\n\n a. Products and Services e.g Reflexology, Beauty\n b. Company Name e.g Asta Spa, Charles & Keith\n c. Addresses e.g Marina Bay Sands, Orchard Rd\n d. Bus Services Number e.g Bus 14\n e. Any Landmark in Singapore e.g Merlion, Beach")
        }
        f.q.focus();
        return false
    } else {
        var b = f.q.value,
            l, g = "";
        if (f.search_type) {
            l = f.search_type[0].checked ? 1 : 2;
            g = l ? "&t=" + l : ""
        }
        var k = b;
        b = encodeURIComponent(b);
        b = b.replace(/%20/gi, "+");
        if ($("rs_1")) {
            if ($("mp_rs_1")) {
                var c = pageIdentifySearch();
                if (($("rs_1") && !$("rs_2")) || $("rs_title_1").innerHTML.toLowerCase() == k.toLowerCase()) {
                    if ($("mp_rs_1").href != "javascript:void(0);" && $("mp_rs_1").href != "#" && c != "businessfinder_preview" && c != "businessfinder_company") {
                        if (j == "search" || location.pathname == "/") {
                            var e = "http://" + sdcom_url + "/asia_travel/search/?q=" + b + "" + g;
                            location.href = e
                        } else {
                            location.href = $("mp_rs_1").href;
                            return false
                        }
                    } else {
                        if ($("cat_id_1") && !window.MapAPI) {
                            if (location.pathname == "/") {
                                var a = $("rs_title_1").innerHTML;
                                a = urlencode(a).replace("%20", "+");
                                location.href = "http://" + sdcom_url + "/asia_travel/search/?q=" + a + "&d=1"
                            } else {
                                if (c == "businessfinder_preview" || c == "businessfinder_company") {
                                    location.href = $("cat_id_1").href
                                }
                            }
                        } else {
                            if (!window.MapAPI) {
                                if (j == "search") {
                                    var e = "http://" + sdcom_url + "/asia_travel/search/?q=" + b + "" + g;
                                    location.href = e
                                } else {
                                    location.href = $("mp_rs_1").href
                                }
                            } else {
                                $("mp_rs_1").onclick();
                                f.q.blur()
                            }
                            return false
                        }
                    }
                    return false
                }
            }
        }
        if (f.action.indexOf("company_listing") > 0) {
            var e = f.action + "?companyname=" + b + "" + g
        } else {
            var e = f.action + "?q=" + b + "" + g
        }
        if (h == 1) {
            e += "&d=1"
        }
        location.href = e
    }
}
var mainsearch_focus = false,
    mainsearch_hover = false,
    mainsearch_state = 0,
    flagHeader = 0;


var gbl = new Array();
if (global == undefined) {
    var global = new Array()
}
if (typeof(bsn_main_search) == "undefined") {
    _b = bsn_main_search = {}
}
if (typeof(_b.Autosuggest) == "undefined") {
    _b.Autosuggest = {}
}
_b.AutoSuggest = function (e, d) {
    if (!document.getElementById) {
        return 0
    }
    this.fld = _b.DOM.gE(e);
    if (!this.fld) {
        return 0
    }
    this.sInp = "";
    this.nInpC = 0;
    this.aSug = [];
    this.iHigh = 0;
    this.cancelShow = false;
    this.submitEventChanged = false;
    this.ajax = false;
    if (document.all) {
        this.isMouseDown = false
    }
    this.oP = d ? d : {};
    var a, b = {
        minchars: 1,
        meth: "get",
        varname: "input",
        className: "autosuggest",
        timeout: 2500,
        delay: 150,
        offsety: -5,
        shownoresults: true,
        noresults: "No results!",
        maxheight: 250,
        cache: false,
        maxentries: 25
    };
    for (a in b) {
        if (typeof(this.oP[a]) != typeof(b[a])) {
            this.oP[a] = b[a]
        }
    }
    var c = this;
    this.fld.onpaste = function () {
        setTimeout(function () {
            showXsearch();
            c.getSuggestions(c.fld.value)
        }, "10")
    };
    this.fld.onkeydown = function (f) {
        return c.onKeyDown(f)
    };
    this.fld.onkeyup = function (f) {
        return c.onKeyUp(f)
    };
    this.fld.setAttribute("autocomplete", "off");
    this.addListener(this.fld, "blur", function (f) {
        if (!gbl.in_list) {
            return c.clearSuggestions();
            return hideXsearch()
        }
    });
    this.addListener(this.fld, "mouseover", function (f) {
        gbl.in_list = true
    });
    this.addListener(this.fld, "mouseout", function (f) {
        gbl.in_list = false
    })
};
_b.AutoSuggest.prototype.addListener = function (b, c, a) {
    if (window.addEventListener) {
        b.addEventListener(c, a, false)
    } else {
        b.attachEvent("on" + c, a)
    }
};
_b.AutoSuggest.prototype.onKeyDown = function (g) {
    var e = (window.event) ? window.event.keyCode : g.keyCode;
    var d = 38;
    var f = 40;
    var c = 13;
    var b = 9;
    var h = 27;
    var a = 1;
    switch (e) {
    case c:
        submitSearch(1);
        break;
    case d:
        this.changeHighlight(e);
        if (this.aSug[this.iHigh - 1]) {
            this.fld.value = this.aSug[this.iHigh - 1].value
        }
        this.cancelSuggestions(this.fld.value);
        a = 0;
        break;
    case f:
        if (this.iHigh < this.aSug.length) {
            this.fld.value = this.aSug[this.iHigh].value;
            this.changeHighlight(e);
            this.cancelSuggestions(this.fld.value)
        }
        a = 0;
        break;
    case h:
        this.clearSuggestions();
        break
    }
    return a
};
_b.AutoSuggest.prototype.onReturnKeyPress = function () {};
_b.AutoSuggest.prototype.onKeyUp = function (f) {
    var d = (window.event) ? window.event.keyCode : f.keyCode;
    var c = 38;
    var e = 40;
    var b = 13;
    var a = 1;
    switch (d) {
    case c:
        this.cancelSuggestions(this.fld.value);
        break;
    case e:
        this.cancelSuggestions(this.fld.value);
        break;
    default:
        if (this.fld.value.length < this.oP.minchars) {
            this.sInp = this.fld.value;
            hideXsearch();
            this.clearSuggestions()
        } else {
            showXsearch();
            this.getSuggestions(this.fld.value)
        }
    }
    return a
};
_b.AutoSuggest.prototype.getSuggestions = function (g) {
    if (g == this.sInp) {
        return 0
    }
    this.cancelShow = false;
    this.sInp = g;
    if (g.length < this.oP.minchars) {
        this.aSug = [];
        this.nInpC = g.length;
        return 0
    }
    var d = this.nInpC;
    this.nInpC = g.length ? g.length : 0;
    var b = this.aSug.length;
    if (this.nInpC > d && b && b < this.oP.maxentries && this.oP.cache) {
        var a = [];
        for (var e = 0; e < b; e++) {
            if (this.aSug[e].value.substr(0, g.length).toLowerCase() == g.toLowerCase()) {
                a.push(this.aSug[e])
            }
        }
        this.aSug = a;
		this.createList(this.aSug)       
        return false
    } else {
        var f = this;
        var c = this.sInp;
        clearTimeout(this.ajID);
        this.ajID = setTimeout(function () {
            f.doAjaxRequest(c)
        }, this.oP.delay)
    }
    return false
};
_b.AutoSuggest.prototype.doAjaxRequest = function (input)
{
	// check that saved input is still the value of the field
	//
	if (input != this.fld.value)
		return false;			
	
	var pointer = this;
		
	// create ajax request
	//
	if (typeof(this.oP.script) == "function")
		var url = this.oP.script(encodeURIComponent(this.sInp));
	else
		var url = this.oP.script+this.oP.varname+"="+encodeURIComponent(this.sInp);
	
	if (!url)
		return false;

	var callback = function() {		
		pointer.setSuggestions(global['data_autosuggest'],input);	
	};	
	load_data_script(url, callback);
};
_b.AutoSuggest.prototype.abortAjax = function (a) {
    if (a) {
        if (a.readyState != 4) {
            a.abort();
            a = null;
            return true
        }
    }
    return false
};
_b.AutoSuggest.prototype.cancelSuggestions = function () {
    this.cancelShow = true
};
_b.AutoSuggest.prototype.setSuggestions = function (req, input)
{
	// if field input no longer matches what was passed to the request
	// don't show the suggestions
	//
	if (input != this.fld.value || this.cancelShow)
		return false;
	
	
	this.aSug = [];
	var jsondata = req;
	if (jsondata.rs)
	{
		var n = jsondata.rs.length;
		for (var i=0;i<n;i++)
		{
			var tmp = { 'id':jsondata.rs[i].id, 'value':jsondata.rs[i].v, 'info':jsondata.rs[i].i, 'type':jsondata.rs[i].t };
			if (jsondata.rs[i].p) tmp.param = jsondata.rs[i].p;
			this.aSug.push(tmp);
		}
	}		
	
	this.idAs = "as_"+this.fld.id;
	this.idAs2 = "as2_"+this.fld.id;
	this.idAs3 = "as3_"+this.fld.id;
	this.createList(this.aSug);
};
_b.AutoSuggest.prototype.hideList = function () {
    _b.DOM.remE(this.idAs);
    _b.DOM.remE(this.idAs2);
    _b.DOM.remE(this.idAs3);
    if (!global.promo_tab_autosuggest) {
        if ($("map-include")) {
            $("map-include").className = "displayhide"
        }
    }
};

_b.AutoSuggest.prototype.createList = function(arr)
{
	var page_search = pageIdentifySearch(); 
	var pointer = this;
	
	// get rid of old list
	// and clear the list removal timeout
	//
	_b.DOM.remE(this.idAs);
	_b.DOM.remE(this.idAs2);
	_b.DOM.remE(this.idAs3);
	this.killTimeout();
	
	
	// if no results, and shownoresults is false, do nothing
	//
	if (arr.length == 0 && !this.oP.shownoresults)
		return false;
	//this.scrollTop + this.offsetHeight < this.scrollHeight) this.scrollTop = this.scrollHeight - this.offsetHeight;
	// create holding div
	//
	var div = _b.DOM.cE("div", {id:this.idAs, className:this.oP.className});
	div.style.cssText = 'overflow-x: hidden';
	if (document.all)
	{
		pointer.isMouseDown = false;
		div.onmousedown = function(e) {pointer.isMouseDown = true; return false;};
	}
	
	// create and populate ul
	//
  var table = _b.DOM.cE('table', {id:'as_table', cellSpacing:0, cellPadding:2, border:0});

  var tbody = _b.DOM.cE('tbody', {id:'as_tbody'});
	
	// loop throught arr of suggestions
	// creating an LI element for each suggestion
	//
	var onclick_url = '',url1,url2,row,str_detail,str_cat,output,cat,val;
	
	var num_arr = arr.length, display;
	display = 'display: block';
	var showMapView = false;

	for (var i=0; i < num_arr;i++)
	{
		// format output with the input enclosed in a EM element
		// (as HTML, not DOM)
		//
		row = arr[i];	
		if(row && row.param && row.param.hasxy!=undefined && row.param.hasxy==1){
			showMapView =true;
		}else{
			showMapView =false;
		}
		//if (row.value.indexOf('Wheelock Place') != -1) console.log(row.param.x);
		if (row.param && row.param.ct == 1)
		 val = '[Bus Stop] '+row.value;
		else
		 val = row.value;	
		 if (!val) continue;
		 val2 = (val) ? val.replace(/'/g, "\\'") : val;
	
    if (val.length > 71 && this.fld.offsetWidth == 406)  output = val.substr(0, 68) + '...';
	else if(val.length > 77 && this.fld.offsetWidth == 486 || val.length > 77 && this.fld.offsetWidth == 487)  output = val.substr(0, 74) + '...';
    else  output = val;

	
		str_detail = '';
		str_cat = '';
		cat = get_cat_type_name(row.type);
		var url_onclick_all="";
		//console.log(i, row);
		keyword = $('q').value;
		keyword = keyword.replace("'","%27");
		if (cat == 'Property') 
		{
			//hash_url = "#t/src/c/prop/";
			str_cat = '<span style="color:#AD0945">Property</span>';
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="#">Map View</a> | <a href="#">Profile View</a></div>';
		}
		else if (cat == 'Company') 
		{	
			url1 = 'http://'+sdcom_url+'/businessfinder/company_detail.php?companyid='+row.param.bid+'&branchid='+row.param.lid;
			str_cat = '<span style="color:#CC9900">Company Name</span>';			
			if(page_search == 'businessfinder_preview' || page_search == 'businessfinder_company' || showMapView ==false || page_search == 'map_view' || page_search == 'map'){
				url2 = 'http://'+sdcom_url+'/asiatravel/singaporemap/business/'+row.param.bid+'/'+row.id+'/';
				url3 = 'http://'+sdcom_url+'/businessfinder/company_detail.php?companyid='+row.param.bid+'&branchid='+row.param.lid;
				onclick_url = 'as_json_main_search.hideList();';
				if(page_search == 'businessfinder_preview' || page_search == 'businessfinder_company' || showMapView ==false) url_onclick_all = "\"" + url3 +"\" onclick=\""+onclick_url+"\"";
				else url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";
		
			} else {
				url2 = 'http://'+sdcom_url+'/businessfinder/company_detail.php?companyid='+row.param.bid+'&branchid='+row.param.lid;
				onclick_url = 'as_json_main_search.hideList();';
				url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";
			}				
			var str_branch = '';
			if (row.param.b > 1)
			{ 
				str_branch = ' | <a href="http://'+sdcom_url+'/businessfinder/company_branch/'+row.param.bid+'/'+row.param.lid+'/">All Branches</a>';
			}

			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;">'+(showMapView ? '<a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick="'+onclick_url+'">Map View</a> | ' : '' )+'<a  href="'+url1+'">Profile view</a> '+str_branch+'</div>';
		}
		else if (cat == 'Zone') 
		{
			str_cat = '<span style="color: #99f">' + cat + '</span>';
			var z = encodeURIComponent(row.value);								
			z = z.replace(/%20/gi,"+");
			z = z.replace("+District","");			
			url1 = "http://"+sdcom_url+"/asia_travel/travel/travel_main.php?zonename="+z;							
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url1+'" onclick="'+onclick_url+'">Map View</a></div>';
		}
		else if (cat == 'Location')
		{
			str_cat = '<span style="color: #393">' + cat + '</span>';	
			url2 = 'http://'+sdcom_url+'/asia_travel/travel/travel_id_'+row.param.pid+'/travel_site_'+row.param.aid+'/';
			onclick_url = 'as_json_main_search.hideList(); return true;';
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;">'+'<a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick="'+onclick_url+'">Map View</a>'+'</div>';
		}	else if (cat == 'POI')
		{
			str_cat = '<span style="color: #393">' + cat + '</span>';		
			url2 = 'http://'+sdcom_url+'/asiatravel/singaporemap/business/'+row.param.bid+'/'+row.id; 		
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick="'+onclick_url+'">Map View</a></div>';			
		}
		else if (cat == 'Restaurant')
		{
			str_cat = '<span style="color: #ee992f">' + cat + '</span>';
			var resto_name = get_keyword(val);
			url1 = 'http://'+sdcom_url + "/restaurants/singapore/reviews/location-"+resto_name+"-"+row.id+".php";		
			url2 = 'http://'+sdcom_url+'/asiatravel/singaporemap/restaurant/'+row.param.eid+'/'+row.id+'/';				
			onclick_url = 'as_json_main_search.hideList();';			
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url2+'"  onclick="'+onclick_url+'">Map View</a> | <a href="'+url1+'">Profile View</a></div>';
		}
		else if (cat == 'SD Feature') 
		{
			str_cat = '<span style="color: #fc3">' + cat + '</span>';
			url1 = 'http://'+sdcom_url +'/' + row.param.o;
			onclick_url = 'as_json_main_search.hideList();';
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a href="'+url1+'"  onclick="'+onclick_url+'">Go To Feature</a></div>';
		}
		else if (cat == 'Bus Route')
		{			
			str_cat = '<span style="color:#d0a807">Bus Route</span>';	
			if (row.value.charAt(1) == 'B'){
				url2 = 'http://'+sdcom_url + "/travel/buses/sbs/"+row.param.o+"/";
			}
			else{
				url2 = 'http://'+sdcom_url + "/travel/buses/smrt/"+row.param.o+"/";
			}
			onclick_url = 'as_json_main_search.hideList();';			
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a href="'+url2+'" onclick="'+onclick_url+'">Bus Route View</a></div>';
		}
		else if (cat == 'Category') 
		{
			str_cat = '<span style="color:#d0a807">Industry</span>';
			if(typeof(row.param.su) != 'undefined' && row.param.su!='' ){
				val=row.param.su
			}
			var cat_name = get_keyword(val);
			cat_name = cat_name.replace("'","%27");
				
			url1 = 'http://'+sdcom_url + "/businessfinder/company/"+row.id+"/"+cat_name+"/";
			url3 = '';
			if (row.param.d == 1) dir = 'business';
			else if (row.param.d == 2) dir = 'resto';
			else if (row.param.d == 3) dir = 'property';
			if(page_search == 'map'){				
				if(location.pathname=='/'){
					url2= 'http://'+sdcom_url + "/asiatravel/singaporemap/business/-"+row.id+"/"+cat_name+"/";	
					onclick_url = 'as_json_main_search.hideList();';	
					url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";	
					
				}else{
					url2 = 'javascript:void(0);';
					onclick_url = "catclick('"+row.id+"','"+cat_name+"','"+dir+"'); as_json_main_search.hideList(); return false;";
					url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";
				}
			}
			else if(page_search == 'map_view'){			
				url2= 'http://'+sdcom_url + "/asiatravel/singaporemap/business/-"+row.id+"/"+cat_name+"/";	
				onclick_url = 'as_json_main_search.hideList();';	
				url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";										
			}			
			else if(page_search=='businessfinder_company'){
				url3 = 'http://'+sdcom_url + "/businessfinder/company/"+row.id+"/"+cat_name+"/";
				url2= 'http://'+sdcom_url + "/asiatravel/singaporemap/business/-"+row.id+"/"+cat_name+"/";	
				onclick_url = 'as_json_main_search.hideList();';	
				url_onclick_all = "\"" + url3 +"\" onclick=\""+onclick_url+"\"";				
			}else if(page_search=='businessfinder_preview'){
				url3= 'http://'+sdcom_url + "/businessfinder/preview/"+row.id+"/"+cat_name+"/";	
				url2= 'http://'+sdcom_url + "/asiatravel/singaporemap/business/-"+row.id+"/"+cat_name+"/";	
				onclick_url = 'as_json_main_search.hideList();';
				url_onclick_all = "\"" + url3 +"\" onclick=\""+onclick_url+"\"";	
			}			
			if (dir == 'business'){
				if(page_search=='businessfinder_preview'){
					url1 = 'http://'+sdcom_url + "/businessfinder/preview/"+row.id+"/"+cat_name+"/";
				}else{
					url1 = 'http://'+sdcom_url + "/businessfinder/company/"+row.id+"/"+cat_name+"/";
				}	
			}
			else if (row.param.bid){
				url1 = 'http://'+sdcom_url + "/businessfinder/company/"+row.param.bid+"/"+cat_name+"/";	
			}
			else if (dir == 'resto'){
				url1 = 'http://'+sdcom_url + "/restaurants/resto/"+row.id+"/"+cat_name+"/";
			}

			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick=" '+onclick_url+'">Map View</a> | <a id="cat_id_'+(i + 1)+'" href="'+url1+'">Directory View</a></div>';
		}
		else if (cat == 'Category in Location'){
			str_cat = '<span style="color:#d0a807">Category</span>';
			var cat_name = get_keyword(val);
			cat_name = cat_name.replace("'","%27");
			url1 = 'http://'+sdcom_url + "/asia_travel/travel_sites/whats_nearby/cat/"+row.id+"/"+cat_name+"/";
			url3 = '';
			if(page_search == 'map'){
				url2 = 'javascript:void(0);';
				onclick_url = "catLocclick('"+row.id+"','"+cat_name+"'); as_json_main_search.hideList(); return false;";
				url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";
			}
			else if(page_search == 'map_view'){		
				url2= 'http://'+sdcom_url + "/asiatravel/singaporemap/business/-"+row.id+"/"+cat_name+"/";	
				onclick_url = 'as_json_main_search.hideList();';	
				url_onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";									
			}			

			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick="'+onclick_url+'">Map View</a> | <a href="'+url1+'">Directory View</a></div>';
		}
		else if (cat == 'Category in Zone')
		{
			str_cat = '<span style="color:#d0a807">Industry</span>';			
			var cat_name,zone_name;
			if (row.param.zn && row.param.cn)
			{
				cat_name = get_keyword(row.param.cn);
				zone_name = get_keyword(row.param.zn);
			} else 
			{
				var re = new RegExp(/(.*)\b(In|At|near|nearby|near by|around|within|close by|beside|located)\b(.*)/gi);
				var rv = row.value.replace(/[@]/g, 'At');
				rv = rv.replace(/[\\]/g, '\\');
				rv = rv.replace(/[\/]/g, '\/');
				var m = re.exec(rv);			
				if (m)
				{
					cat_name = get_keyword(m[1].replace(/^\s+|\s+$/g,""));
					zone_name = get_keyword(m[3].replace(/^\s+|\s+$/g,""));
					
				}
			}
			
			url1= 'http://'+sdcom_url + '/businessfinder/zone/' + row.param.z + '/' + row.param.c + '/' + cat_name + '/';
			url2= 'http://'+sdcom_url + '/asiatravel/singaporemap/business/-' + row.param.c + '/' + cat_name + '/' + zone_name + '/';
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><a id="mp_rs_'+(i + 1)+'" href="'+url2+'" onclick="'+onclick_url+'">Map View</a> | <a href="'+url1+'">Directory View</a></div>';						
			url_onclick_all=url2;
		}
		else if (cat == 'SD Routing')
		{
			str_cat = '<span style="color:#d0a807">SD Routing</span>';
//			url1= 'http://'+sdcom_url + '/travel/mrt_guide/direction_result/' + row.param.f.lid + '_to_' + row.id + '/';
	
			var start = row.id;
			var end = row.param.lid;
			url1 = "http://" + sdcom_url + "/routing/automobile_guide/" + start + "_to_" + end + "/major_roads/";
			url2 = "http://" + sdcom_url + "/travel/bus_guide/direction_result/" + start + "_to_" + end + "/minimum_walking_distance/";
			url3 = "http://" + sdcom_url + "/travel/mrt_guide/direction_result/" + start + "_to_" + end + "/";
			url4 = "http://" + sdcom_url + "/travel/bus_mrt_guide/direction_result/" + start + "_to_" + end + "/";
			str_detail = '<div id="rs_'+(i + 1)+'" style="' + display + '; padding-bottom: 3px;"><span style="color:green;">Travel by : </span><a href="'+url1+'">Driving Direction</a> | <a href="'+url2+'">Bus only</a> | <a href="'+url3+'">MRT only</a> | <a href="'+url4+'">Bus & MRT</a></div>';						
		}		
		if (cat == 'Category' || cat == 'Zone' || cat == 'SD Feature' ) url2 = url1;
		else if (cat == 'Property') url2 = '';
		else url2 = url2				

		
		if(url_onclick_all) onclick_all = url_onclick_all;
		else if(url2 == undefined) onclick_all = "\"" + url1 + "\" " + onclick_url1 ;
		else if(cat == 'Location' || cat == 'Bus Route') onclick_all = "\"" + url2 +"\" onclick=\""+onclick_url+"\"";
		else onclick_all = "\"" + url1 +"\" onclick=\""+onclick_url+"\"";
		
		
		var str_info = row.info ? '<div style="font-size:10px;">'+row.info+'</div>' : '';	
		output = '<div style="float:left;"><a href='+ onclick_all +' style="color:black; text-decoration:none;" ><div id="rs_title_'+(i+1)+'" style="font-size:11px;font-weight:bold;">'+output+'</div>'+str_info+'</a>'+str_detail+'</div><div style="float:right">'+str_cat+'</div>';
	//output = '<div style="font-size:11px;font-weight:bold;">'+output+'</div>'+str_info;

    var tr = _b.DOM.cE('tr', {});
    var td = _b.DOM.cE('td', {}, output, true);
	td.className = "as_nohighlight";

    td.name = i + 1;
		//td.onclick = function () { pointer.setHighlightedValue(); return false; };
		td.onmouseover = function () { 
			pointer.setHighlight(this.name); 		
			};
		//td.onmouseout = function (e) { if (checkMouseLeave(this,e) && num_arr > 5) hide_element('rs_'+gbl['last_move'])};
    tr.appendChild(td);
    tbody.appendChild(tr);
	}
	
	
	table.appendChild(tbody);
	div.appendChild(table);
	
	var br = document.createElement('br');
	div.appendChild(br);
	/*var footer = document.createElement("div");
	footer.style.cssText = 'padding-left:2px';
	footer.innerHTML = '<a href="http://' + sdcom_url + '/asia_travel/search/?q=' + encodeURIComponent(this.fld.value) + '" class="sgsblue">Show all results for "'+this.fld.value+'"</a>';
	div.appendChild(footer);*/
	

	// get position of target textfield
	// position holding div below it
	// set width of holding div to width of field
	//
	var not_ie = !document.layers && !document.all, div_l, div_t, div_w, tbl_w ;
	
	var pos = _b.DOM.getPos(this.fld);
	
	//if (!document.layers && !document.all) div.style.left 		= (pos.x + 1) + "px";
	//else div.style.left 		= pos.x + "px";
	if (not_ie) div_l 		= (pos.x - 3)  + "px"; //Marion : Edit : Left;
	else div_l 		= (pos.x - 3) + "px";
	
	div_t 		= ( pos.y + this.fld.offsetHeight + this.oP.offsety + 25) + "px";
	//div_w 	= (this.fld.offsetWidth - 12) + "px";
	if (not_ie) div_w 	= (this.fld.offsetWidth + 34) + "px"; //Marion : Ubah Width Auto Suggest
	else div_w 	= (this.fld.offsetWidth + 33) + "px";

	// set mouseover functions for div
	// when mouse pointer leaves div, set a timeout to remove the list after an interval
	// when mouse enters div, kill the timeout so the list won't be removed
	//
	gbl['in_list'] = false;
	div.onmouseover 	= function(){ gbl['in_list'] = true; pointer.killTimeout() };
	if (window.addEventListener) div.addEventListener('DOMMouseScroll', onwheel, false);
	div.onmousewheel 	= onwheel;
	div.onmouseout = function() { gbl['in_list'] = false; };
	//div.onmouseout 		= function(){ pointer.resetTimeout() };
		

	// add DIV to document
	//

	
	// add div 
	document.getElementsByTagName("body")[0].appendChild(div);
	
	var top_info = this.fld.offsetHeight + 215;
	var left_info = div_l;
	var top_messsage = $(this.idAs3);
	
	if (top_messsage)
	{
		top_messsage.style.cssText = "position:absolute;left:" + left_info + ";top:"+ top_info +"px;padding-top:4px; border-right:1px solid #f3d900; border-bottom:none; border-left:1px solid #f3d900; text-align:center;z-index:10000;width:"+div_w+";height:13px;margin:0px;";
		top_messsage.style.backgroundImage = 'url("http://' + sdcom_url + '/img/map/bg-search.gif")';
		top_messsage.style.backgroundRepeat = 'repeat-x';
		
	} else
	{
		top_messsage = _b.DOM.cE('div', {id:this.idAs3,className:this.oP.className});
		top_messsage.onmouseover = function() { gbl['in_list'] = true; };
		top_messsage.onmouseout = function() { gbl['in_list'] = false; };
		top_messsage.style.cssText = "position:absolute;left:" + left_info + ";top:"+ top_info +"px;padding-top:4px; border-right:1px solid #f3d900; border-bottom:none; border-left:1px solid #f3d900; text-align:center;z-index:10000;width:"+div_w+";height:13px;margin:0px;";
		top_messsage.style.backgroundImage = 'url("http://' + sdcom_url + '/img/map/bg-search.gif")';
		top_messsage.style.backgroundRepeat = 'repeat-x';
		if(global['show_xz'] != 1) search_tips();
		top_messsage.innerHTML = global['temp_searchs'];
		if(top_messsage.innerHTML == "undefined") top_messsage.innerHTML = "<b>Loading ...</b>";
		document.body.appendChild(top_messsage);
	}
	
	
	var search_msg_width = '96%';
 	if (!not_ie) { 
 		if(div.offsetHeight > div.scrollHeight) {
			tbl_w = '100%';	
			search_msg_width = "300px";
		}
		else 
		{
			tbl_w = '95%';		
			search_msg_width = "300px";
		}
		
	} else tbl_w = '100%';	
	table.width = tbl_w;
	
	
	var top_change = div.offsetHeight + 275;
	var left_change = div_l;
	var suggest_add_div = $(this.idAs2);
	
	if (not_ie) suggest_wdth 	= (this.fld.offsetWidth + 44) + "px"; //Marion : Width yang Bawah
	else suggest_wdth 	= (this.fld.offsetWidth + 44) + "px"; //Marion Width yang Bawah
	
	var left_close = (this.fld.offsetWidth - 120) + "px"; //Marion : Ini buat Geser Tanda Close
	
	if (suggest_add_div)
	{
		suggest_add_div.style.cssText = "position:absolute;left:" + left_change + ";top:"+ top_change +"px;border-left:1px solid #f3d900;border-right:1px solid #f3d900;border-bottom:1px solid #f3d900;border-top:0px solid #f3d900;z-index:10000;width:"+suggest_wdth+";height:24px;padding:0px;margin:0px;";
	} else
	{
		suggest_add_div = _b.DOM.cE('div', {id:this.idAs2});
		var url_suggest = 'http://' + sdcom_url + '/feedback_company.php';
		suggest_add_div.style.cssText = "position:absolute;left:" + left_change + ";top:"+ top_change +"px;border-left:1px solid #f3d900;border-right:1px solid #f3d900;border-bottom:1px solid #f3d900;border-top:0px solid #f3d900;z-index:10000;width:"+suggest_wdth+";height:24px;padding:0px;margin:0px;";
		suggest_add_div.style.backgroundImage = 'url("http://' + sdcom_url + '/img/search/background-repeat.gif")';
		suggest_add_div.style.backgroundRepeat = 'repeat-x';
		var val_label = this.fld.value.length > 50 ? this.fld.value.substr(0,47)+'...' : this.fld.value;
		var close_button_img = 'http://' + sdcom_url + '/img/search/close-button.gif';
		//var close_button_img_hover =  'http://' + sdcom_url + '/img/search/close-button-hover.gif';
		var close_code = '<img src="'+close_button_img+'" style="position:relative;top:7px;left:'+left_close+';" name="cls_btn" onMouseOver="activate()"  onMouseOut="deactivate()" onClick="unactive()"/></div>';
	
		var param_q = encodeURIComponent(this.fld.value);
		param_q = param_q.replace('%20', '+');
		suggest_add_div.innerHTML = '<div style="position:relative;"><div style="position:absolute;left: 0px; top:-10px; width:575px;"><div style="padding-left:5px;padding-top:3px;font-family:arial;font-size:11px;"><b><a class="sgs" href="'+ url_suggest +'">Submit Businesses Info</a></b>'+close_code+'</div></div></div>';
		document.body.appendChild(suggest_add_div);
	}

	div.style.borderBottom = "0";
	
	// currently no item is highlighted
	//
	this.iHigh = 0;
	
	div.style.left = div_l;
	div.style.top = div_t;
	div.style.width = div_w;
	
	// remove list after an interval
	//
	var pointer = this;
	this.toID = setTimeout(function () { 	hideXsearch(); pointer.clearSuggestions(); }, this.oP.timeout);
	
};

_b.AutoSuggest.prototype.changeHighlight = function (c) {
    var e = _b.DOM.gE("as_tbody");
    if (!e) {
        return false
    }
    if (!this.submitEventChanged) {
        _b.DOM.gE("fSdSearch").onsubmit = function (h) {
            return false
        };
        this.submitEventChanged = true
    }
    var g, a = 5,
        b = this.iHigh;
    if (c == 40) {
        g = this.iHigh + 1
    } else {
        if (c == 38) {
            g = this.iHigh - 1
        }
    }
    if (g > e.childNodes.length) {
        g = e.childNodes.length
    }
    if (g < 1) {
        g = 1
    }
    var d = $(this.idAs);
    var f = e.childNodes[g - 1].childNodes[0];
    if (c == 40 && f.offsetTop + f.offsetHeight > d.scrollTop + d.offsetHeight) {
        d.scrollTop = f.offsetTop + f.offsetHeight - d.offsetHeight + 12
    } else {
        if (c == 38 && f.offsetTop < d.scrollTop) {
            d.scrollTop = f.offsetTop
        }
    }
    this.setHighlight(g)
};
_b.AutoSuggest.prototype.setHighlight = function (c) {
    var b = _b.DOM.gE("as_tbody");
    gbl.last_move = c;
    if (!b) {
        return false
    }
    if (this.iHigh > 0) {
        this.clearHighlight()
    }
    this.iHigh = Number(c);
    var a = b.childNodes[this.iHigh - 1];
    a.childNodes[0].className = "as_highlight";
    this.killTimeout()
};
_b.AutoSuggest.prototype.clearHighlight = function () {
    var b = _b.DOM.gE("as_tbody");
    if (!b) {
        return false
    }
    if (this.iHigh > 0) {
        var a = b.childNodes[this.iHigh - 1];
        a.childNodes[0].className = "as_nohighlight";
        this.iHigh = 0
    }
};
_b.AutoSuggest.prototype.setHighlightedValue = function () {
    if (this.iHigh) {
        if (this.aSug[this.iHigh - 1]) {
            var a = this.aSug[this.iHigh - 1].info ? (this.aSug[this.iHigh - 1].value ? ", " : "") + this.aSug[this.iHigh - 1].info.replace("Add :", "") : "";
            this.sInp = this.fld.value = this.aSug[this.iHigh - 1].value + a
        }
        this.fld.focus();
        if (this.fld.selectionStart) {
            this.fld.setSelectionRange(this.sInp.length, this.sInp.length)
        }
        hideXsearch();
        this.clearSuggestions();
        if (typeof(this.oP.callback) == "function") {
            this.oP.callback(this.aSug[this.iHigh - 1])
        }
    }
};
_b.AutoSuggest.prototype.killTimeout = function () {
    clearTimeout(this.toID)
};
_b.AutoSuggest.prototype.resetTimeout = function () {
    clearTimeout(this.toID);
    var a = this;
    this.toID = setTimeout(function () {
        hideXsearch();
        a.clearSuggestions()
    }, 1000)
};
_b.AutoSuggest.prototype.clearSuggestions = function () {
    this.killTimeout();
    var c = _b.DOM.gE(this.idAs);
    var g = _b.DOM.gE(this.idAs2);
    var f = _b.DOM.gE(this.idAs3);
    var e = this;
    _b.DOM.gE("fSdSearch").onsubmit = function (h) {
        return false
    };
    this.submitEventChanged = false;
    if (c) {
        var d = new _b.Fader(c, 1, 0, 250, function () {
            _b.DOM.remE(e.idAs)
        })
    }
    if (g) {
        var b = new _b.Fader(g, 1, 0, 250, function () {
            _b.DOM.remE(e.idAs2)
        })
    }
    if (f) {
        var a = new _b.Fader(f, 1, 0, 250, function () {
            _b.DOM.remE(e.idAs3)
        })
    }
};
if (typeof(_b.Ajax) == "undefined") {
    _b.Ajax = {}
}
_b.Ajax = function () {
    this.req = {};
    this.isIE = false
};
_b.Ajax.prototype.makeRequest = function (c, b, a, d) {
    if (b != "POST") {
        b = "GET"
    }
    this.onComplete = a;
    this.onError = d;
    var e = this;
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
        this.req.onreadystatechange = function () {
            e.processReqChange()
        };
        this.req.open("GET", c, true);
        this.req.send(null)
    } else {
        if (window.ActiveXObject) {
            this.req = new ActiveXObject("Microsoft.XMLHTTP");
            if (this.req) {
                this.req.onreadystatechange = function () {
                    e.processReqChange()
                };
                this.req.open(b, c, true);
                this.req.send()
            }
        }
    }
};
_b.Ajax.prototype.processReqChange = function () {
    if (this.req.readyState == 4) {
        if (this.req.status == 200) {
            this.onComplete(this.req)
        } else {
            this.onError(this.req.status)
        }
    }
};
if (typeof(_b.DOM) == "undefined") {
    _b.DOM = {}
}
_b.DOM.cE = function (g, c, b, f) {
    var h = document.createElement(g);
    if (!h) {
        return 0
    }
    for (var d in c) {
        h[d] = c[d]
    }
    var e = typeof(b);
    if (e == "string" && !f) {
        h.appendChild(document.createTextNode(b))
    } else {
        if (e == "string" && f) {
            h.innerHTML = b
        } else {
            if (e == "object") {
                h.appendChild(b)
            }
        }
    }
    return h
};
_b.DOM.gE = function (c) {
    var a = typeof(c);
    if (a == "undefined") {
        return 0
    } else {
        if (a == "string") {
            var b = document.getElementById(c);
            if (!b) {
                return 0
            } else {
                if (typeof(b.appendChild) != "undefined") {
                    return b
                } else {
                    return 0
                }
            }
        } else {
            if (typeof(c.appendChild) != "undefined") {
                return c
            } else {
                return 0
            }
        }
    }
};
_b.DOM.remE = function (a) {
    var b = this.gE(a);
    if (!b) {
        return 0
    } else {
        if (b.parentNode.removeChild(b)) {
            return true
        } else {
            return 0
        }
    }
};
_b.DOM.getPos = function (c) {
    var c = this.gE(c);
    var b = c;
    var d = 0;
    if (b.offsetParent) {
        while (b.offsetParent) {
            d += b.offsetLeft;
            b = b.offsetParent
        }
    } else {
        if (b.x) {
            d += b.x
        }
    }
    var b = c;
    var a = 0;
    if (b.offsetParent) {
        while (b.offsetParent) {
            a += b.offsetTop;
            b = b.offsetParent
        }
    } else {
        if (b.y) {
            a += b.y
        }
    }
    return {
        x: d,
        y: a
    }
};
if (typeof(_b.Fader) == "undefined") {
    _b.Fader = {}
}
_b.Fader = function (b, f, e, a, d) {
    if (!b) {
        return 0
    }
    this.e = b;
    this.from = f;
    this.to = e;
    this.cb = d;
    this.nDur = a;
    this.nInt = 50;
    this.nTime = 0;
    var c = this;
    this.nID = setInterval(function () {
        c._fade()
    }, this.nInt)
};
_b.Fader.prototype._fade = function () {
    this.nTime += this.nInt;
    var a = Math.round(this._tween(this.nTime, this.from, this.to, this.nDur) * 100);
    var c = a / 100;
    if (this.e.filters) {
        try {
            this.e.filters.item("DXImageTransform.Microsoft.Alpha").opacity = a
        } catch (b) {
            this.e.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + a + ")"
        }
    } else {
        this.e.style.opacity = c
    }
    if (this.nTime == this.nDur) {
        clearInterval(this.nID);
        if (this.cb != undefined) {
            this.cb()
        }
    }
};
_b.Fader.prototype._tween = function (e, a, g, f) {
    return a + ((g - a) * (e / f))
};

function get_cat_type_name(b) {
    var a = "";
    switch (b) {
    case 1:
        a = "Location";
        break;
    case 2:
        a = "Company";
        break;
    case 3:
        a = "Restaurant";
        break;
    case 4:
        a = "Category";
        break;
    case 5:
        a = "Zone";
        break;
    case 6:
        a = "SD Feature";
        break;
    case 7:
        a = "Bus Route";
        break;
    case 8:
        a = "Category in Zone";
        break;
    case 9:
        a = "SD Routing";
        break;
    case 10:
        a = "POI";
        break;
    case 11:
        a = "Category in Location";
        break
    }
    return a
}
function get_keyword(a) {
    a = a.replace(/[&\(\)]/g, "");
    a = a.replace(/[\+\-,\/ ]/g, "_");
    a = a.replace(/%20/g, "_");
    return a
}


var options_search = {
	script: function (q) { 
		q = q.replace(/ /gi,"+");
		q = q.replace(/%20/gi,"+");
		return "http://www.streetdirectory.com/search/api/sd.php?q="+q;  
	} ,
	varname:"q",
	json:true,
	shownoresults:false,
	timeout:300000,	
	minchars:1,
	maxresults:10,
	callback: function (q) { 
			return false;					
	}
};

function set_data(data)
{		
	global['data_autosuggest'] = data;
}

var as_json_main_search = new bsn_main_search.AutoSuggest('q', options_search);


function activate() {
    document.images.cls_btn.src = "http://" + sdcom_url+ "/img/search/close-button-hover.gif";
    document.images.cls_btn.style.cursor = "pointer"
}
function deactivate() {
    document.images.cls_btn.src = "http://" + sdcom_url+ "/img/search/close-button.gif"
}
function unactive() {
    as_json_main_search.hideList()
}
function cancelEvent(a) {
    a = a ? a : window.event;
    if (a.stopPropagation) {
        a.stopPropagation()
    }
    if (a.preventDefault) {
        a.preventDefault()
    }
    a.cancelBubble = true;
    a.cancel = true;
    a.returnValue = false;
    return false
}
function closebutton() {
    _b.DOM.remE(this.idAs);
    _b.DOM.remE(this.idAs2);
    _b.DOM.remE(this.idAs3);
    return false
}
function catclick(c, b, a) {
    cat_name_url = str_replace("_", " ", b);
    setCatName(cat_name_url);
    change_title("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", c, b);
    updateMapIcon(c, a, "", "", "", "", "", "", "", "", "", true, false, "")
}
function catLocclick(c, b) {
    var a = "place";
    cat_name_url = str_replace("_", " ", b);
    setCatName(cat_name_url);
    change_title("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", c, b, false);
    updateMapIcon(c, a, "", "", "", "", "", "", "", "", "", true, false, "")
}
function bizclick(m, l, p, o, j, q, h, k, f, a, e, r) {
    var s = q ? (o ? ", " : "") + q.replace("Add :", "") : "";
    set_q(o + s);
    global.dir_nearby = "business";
    global.bid_nearby = p;
    global.lid_nearby = h;
    if ($("td_greymenu")) {
        $("td_greymenu").innerHTML = ""
    }
    if ($("arrow_pointer_div")) {
        hide_element("arrow_pointer_div")
    }
    hide_element("default_side");
    var i = MapAPI.projection.metricToGeo(m, l);
    var c = i.lon;
    var g = i.lat;
    if (icons.icons.web) {
        icons.remove_group("web")
    }
    resetIcon();
    global.data_ajax = "";
    web = icons.create({
        css: "free_marker",
        w: 32,
        h: 32,
        left: 248,
        top: 108,
        x: c,
        y: g,
        cursor: "pointer",
        offset_x: 17,
        offset_y: 16
    }, "web");
    as_json_main_search.hideList();
    if ("nearby_last_idx" in global) {
        global.nearby_last_idx = 0
    }
    if ($("preview_detail")) {
        close_compMinisite()
    }
    if (a > 1) {
        if (e == 1) {
            global.branch_search = "biz_prem";
            change_title("", "", "", "", "", "", "business", p, "", "", "", "", a, e, r);
            activeTabMapview();
            $("content_header_listing").style.display = "none";
            updateMapIcon("", "business", "", p, "", "", "", "", "", "", "", true, false, "", {
                showloading: false
            });
            MapAPI.setCenter(new GeoPoint(103.81682020417014, 1.3348813408286913), 7)
        } else {
            global.branch_search = "biz";
            change_title("", "", "", "", "", "", "business", p, "", "", "", "", a, e, r);
            activeTabMapview();
            $("content_header_listing").style.display = "none";
            updateMapIcon("", "business", "", p, "", "", "", "", "", "", "", true, false, "", {
                showloading: false
            });
            MapAPI.setCenter(new GeoPoint(103.81682020417014, 1.3348813408286913), 7)
        }
    } else {
        var b = function (u) {
            if (u) {
                var t = u.split(",");
                setCatName(j);
                if (t[0] == "biz_prem") {
                    change_title("", "", "", "", "", "", "business", p, "", "", t[0], "", "", "", r);
                    if ($("content_header_listing").style.display == "block") {
                        $("content_header_listing").style.display = "none"
                    }
                    setcenter_businessimg(k, f, c, g, p, t[0], j, h)
                } else {
                    change_title("", "", "", "", "", "", "business", p, "", "", t[0], t[1], "", "", r);
                    var v = function () {
                        updateMapIcon(t[1], "business", "", "", "", "", "", "", "", "", "", true, false, "", {
                            showloading: false
                        });
                        setcenter_businessimg(k, f, c, g, p, t[0], j, h)
                    };
                    getBussinessDropdown(p, "map", v)
                }
            } else {
                setCatName(j);
                updateMapIcon("", "business", "", p, h, "", "")
            }
        };
        var n = function () {};
        var d = "http://" + location.hostname + "/asia_travel/mappage/ajax_new/get_bizz_type.php?cid=" + p + "&v=" + global.v_c + global_clear_cache;
        ajax(d, b, n);
        hideNewDDForm();
        if ($("content_lhs")) {
            $("content_lhs").style.display = ""
        }
        MapAPI.setCenter(new GeoPoint(c, g), 13);
        if ($("original_pos")) {
            $("original_pos").innerHTML = c + "," + g
        }
        global.direction = new Array;
        global.direction["lid"] = h;
        global.link_from = "";
        global.link_to = ""
    }
    load_menu_tab("", "", "", "&businessId=" + p)
}
function locclick(j, h, g, d, n, c, b, i) {
    var e = c ? (n ? ", " : "") + c.replace("Add :", "") : "";
    set_q(n + e);
    var a, k, m, f;
    if (j > 1000) {
        m = MapAPI.projection.metricToGeo(j, h);
        a = m.lon;
        k = m.lat
    } else {
        a = j;
        k = h
    }
    var l = (b == undefined || b == "") ? 13 : b;
    MapAPI.setCenter(new GeoPoint(a, k), l);
    if (icons.icons.web) {
        icons.remove_group("web")
    }
    web = icons.create({
        css: "free_marker",
        w: 32,
        h: 32,
        left: 248,
        top: 108,
        x: a,
        y: k,
        cursor: "pointer",
        offset_x: 17,
        offset_y: 16
    }, "web");
    moveStarPosition(MapAPI, new Point(350, 300));
    setCatName(n);
    cek = false;
    action_map_loc(g, d, i);
    if ($("ovi")) {
        removeElement("ovi")
    }
    if ("nearby_last_idx" in global) {
        global.nearby_last_idx = 0
    }
    hideNewDDForm();
    if ($("content_lhs")) {
        $("content_lhs").style.display = ""
    }
}

function set_q(a) {
    $("q").value = decodeURIComponent(a)
}
function onwheel(a, b) {
    a = a ? a : window.event;
    a.cancelBubble = true;
    a.cancel = true;
    if (!a) {
        a = window.event
    }
    if (a.wheelDelta) {
        delta = a.wheelDelta / 120
    } else {
        if (a.detail) {
            delta = -a.detail / 3
        }
    }
    if (b != undefined) {
        if (delta < 0) {
            if (b.scrollTop + b.offsetHeight - delta * 24 < b.scrollHeight) {
                return true
            } else {
                if (b.scrollTop + b.offsetHeight < b.scrollHeight) {
                    b.scrollTop = b.scrollHeight - b.offsetHeight
                }
                cancelEvent(a);
                return false
            }
        } else {
            if (delta > 0) {
                if (b.scrollTop - (delta) * 24 > 0) {
                    return true
                } else {
                    if (b.scrollTop > 0) {
                        b.scrollTop = 0
                    }
                    cancelEvent(a);
                    return false
                }
            }
        }
    } else {
        if (delta < 0) {
            if (this.scrollTop + this.offsetHeight - delta * 24 < this.scrollHeight) {
                return true
            } else {
                if (this.scrollTop + this.offsetHeight < this.scrollHeight) {
                    this.scrollTop = this.scrollHeight - this.offsetHeight
                }
                cancelEvent(a);
                return false
            }
        } else {
            if (delta > 0) {
                if (this.scrollTop - (delta) * 24 > 0) {
                    return true
                } else {
                    if (this.scrollTop > 0) {
                        this.scrollTop = 0
                    }
                    cancelEvent(a);
                    return false
                }
            }
        }
    }
}
function getName(a) {
    as_json_main_search.clearSuggestions();
    $("q").value = a
}
function getRoute(link_id1, link_id2, mode, weight, q) {
    
    if (document.getElementById) {
        var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest()
    }
    var projection = (MapAPI.viewportInfo.levelIndex > 4) ? "WGS" : "Mercator";
    if (x) {
        x.onreadystatechange = function () {
            if (x.readyState == 4 && x.status == 200) {
                var xylist = eval("(" + x.responseText + ")");
                if (xylist == "") {
                    alert("Sorry, we have no route information")
                } else {
                    var x1 = xylist.source.x;
                    var y1 = xylist.source.y;
                    var x2 = xylist.destination.x;
                    var y2 = xylist.destination.y;
                    var wgs_projection = (new SD.projection.Server()).get("UTM WGS-1984 48N");
                    var lonlat1 = wgs_projection.metricToGeo(x1, y1);
                    var lonlat2 = wgs_projection.metricToGeo(x2, y2);
                    if (mode == undefined) {
                        mode = 1
                    }
                    if (weight == undefined) {
                        weight = 0
                    }
                    routing.setMode(mode, weight);
                    var startPin = routing.addMarker({
                        marker: "start",
                        x: lonlat1.lon,
                        y: lonlat1.lat
                    });
                    var endPin = routing.addMarker({
                        marker: "end",
                        x: lonlat2.lon,
                        y: lonlat2.lat
                    });
                    MapAPI.setCenter(lonlat1, get_level());
                    global.active_list = "dd"
                }
            }
        };
        var url = "http://" + location.hostname + "/asia_travel/mappage/ajax/get_xy_linkid.php?link_id1=" + link_id1 + "&link_id2=" + link_id2 + "&p=" + projection + "&v=" + global.v_c + global_clear_cache;
        x.open("GET", url, true);
        x.send(null)
    }
}
function set_data_search_tips(data)
{
	global['data_search_tips'] = data;
}

//for search tip dynamic
function search_tips(id) 
{
	var prm= (id != undefined) ? '?id='+id : '';	
	var url =  'http://' + sdcom_url + '/search/api/etc/search_tips.php'+prm;
	var prefix = "<span style='color:#ba0000;'>Today Tip's </span>: Search for ";
	if (global['temp_searchs'] && $('as3_q') && global['id_tips'] != id)
	{
		$('as3_q').innerHTML= global['temp_searchs'];				
		return;
	}
	
	var callback = function()
	{
		if($('as3_q')) $('as3_q').innerHTML= prefix + global['data_search_tips'];				
		global['temp_searchs'] =  prefix + global['data_search_tips'];			
		global['id_tips'] = id;
	}
	load_data_script(url, callback);
}
function hideAll() {
    if ($("xmas_div_overlay")) {
        $("xmas_div_overlay").style.display = "none"
    }
    if (window.m1) {
        m1.hide()
    }
    if (window.marathon) {
        marathon.hide()
    }
    if ($("xmas_div")) {
        $("xmas_div").style.display = "none"
    }
    if ($("content_listing_title")) {
        var a = $("content_listing_title").getElementsByTagName("input");
        for (var b = 0; b < a.length; b++) {
            a[b].checked = false
        }
    }
}
function showXsearch(a) {
    if (document.getElementById("q")) {
        if (a == "search") {
            if ($("q").value.length != 0) {
                show_element("img_x_search")
            }
        } else {
            show_element("img_x_search")
        }
    }
}
function hideXsearch(a) {
    if (document.getElementById("q")) {
        hide_element("img_x_search");
        if ($("q")) {
            $("q").value = ""
        }
    }
}
var body = document.getElementsByTagName("body")[0];
body.onmousedown = function () {
    if (location.pathname.indexOf("/realestate/") == -1 || location.pathname.indexOf("/jobs/") == -1) {
        if (!gbl.in_list) {
            as_json_main_search.clearSuggestions()
        }
    }
};// JavaScript Document

function load_data_script(src, callback) 
{
	var script = document.createElement("script");
	
	if(script.addEventListener)	script.addEventListener("load", callback, false);
	else if(script.attachEvent)	script.attachEvent("onreadystatechange",function() 
	{ var target = window.event.srcElement;
	  if(target.readyState == "loaded")
	  callback.call(target);
	});	
	
	script.src = src;
	document.getElementsByTagName("head")[0].appendChild(script);	
}

function pageIndetify(){
	if(location.pathname.indexOf('/restaurants/')  != -1 || location.pathname.indexOf('/restaurant/')  != -1) return 'restaurant';
	else if(location.pathname.indexOf('/realestate/') != -1) return 'realestate';
	else if(location.pathname.indexOf('/jobs/') != -1)return 'jobs';
	else if(location.pathname.indexOf('/search/')  != -1)return 'search';
	else if(global['preview_bf']) return 'map';
	else if(location.pathname.indexOf('/businessfinder/')  != -1)return 'businessfinder';
	else return 'map';
}


//top changed in line 2177,2220,2158 for tips auto suggest


