﻿$(document).ready(function() {

    // getMonth() returns current month index, which starts from 0;
    var curMonth = new Date().getMonth() + 1;

    DrawMonthSelector();
    InitThemeSelector();
    InitCitySelector();

    InitLogFunction();
    InitEvents();
})


var g_IsAuthenticated;
// update UI controls state and divs by authentication state
function UpdateAuthUI(isAuthenticated) {

    if (isAuthenticated) {
    
        //update the UI affer login. Hidden the regist button
        $("#regContainer").css("display", "none");
        $("#userInfoContainer").css("width", "auto");
        $("#userInfoContainer").css("margin", "0px 20px")

        g_IsAuthenticated = true;
    }
    else {
        g_IsAuthenticated = false;
    }
}

/**************************************************************************************************

NAME:   InitLogFunction

DESCRIPTION:
Initialize the log function of the clickable element of the web site

PARAS:  None

RETURNS:    None

**************************************************************************************************/
function InitLogFunction() {

    // log the event to click the homepage button in the navigation bar of the start page
    $("#navContainer a:eq(0)").click(function() {
    Log("StartPage.HomeInNavigation", "", "", "");
    });

    //log the event to click the trip plan button in the navigation bar of the start page
    $("#navContainer a:eq(1)").click(function() {
    Log("StartPage.TripPlanInNavigation", "", "", "");
    });

    //log the event to click the log in or log off button in the navigation bar of the start page
    $("#signInContainer").click(function() {
        if (g_IsAuthenticated) {
            Log("StartPage.LogOffInNavigation", "", "", "");
        }
        else {
            Log("StartPage.LogInInNavigation", "", "", "");
        }

    });

    //log the event to click the register button in the navigation bar of the start page
    $("#btnReg").click(function() {
        Log("StartPage.RegisterInNavigation", "", "", "");
    });
    
    // log the event of clicking the hotkeywords on homepage 
    $("#hotkeywords a").click(function() {
        Log("StartPage.HotQuery", $(this).text(), "", "");
    });

    // log the event of clicking the hotest city in the hot city list 
    $("#monthhotlist .liFirstLocName").click(function() {
        Log("StartPage.HotList.FirstHotCity", $(this).text(), "", "");
    });

    // log the event of clicking the hotest attraction in the special travel list
    $("#themehotlist .liFirstLocName").click(function() {
        Log("StartPage.HotList.FirstHotAttraction", $(this).text(), "", "");
    });

    // log the event of clicking the hotest attraction in the around city list
    $("#cityhotlist .liFirstLocName").click(function() {
        Log("StartPage.HotList.FirstHotAroundAttraction", $(this).text(), "", "");
    });

    // log the event of clicking the hot cities in the hot city list(except the first one)
    $("#monthhotlist .liLocName").click(function() {
        Log("StartPage.HotList.HotCity", $(this).text(), "", "");
    });

    // log the event of clicking the hot attractions in the special tavel list(except the first one)
    $("#themehotlist .liLocName").click(function() {
        Log("StartPage.HotList.HotAttraction", $(this).text(), "", "");
    });

    // log the event of clicking the hot attractions in the around city list(except the first one)
    $("#cityhotlist .liLocName").click(function() {
        Log("StartPage.HotList.HotAroundAttraction", $(this).text(), "", "");
    });

    // log the event of clicking the attractions number in the of the hottest city in the hot city list
    $("#cityDataContainer .liDetailItems :first").click(function() {
        Log("StartPage.HotCity.FisrtCity.Attractions", "", "", "");
    });

    // log the event of clicking the enabled travelogue tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkEnabledT").click(function() {
        Log("StartPage.HotCity.FisrtCity.EnableTravelogue", "", "", "");
    });

    // log the event of clicking the disabled travelogue tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkDisabledT").click(function() {
        Log("StartPage.HotCity.FisrtCity.DisableTravelogue", "", "", "");
    });

    // log the event of clicking the enabled FAQ tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkEnabledF").click(function() {
        Log("StartPage.HotCity.FisrtCity.EnableFAQ","", "", "");
    });

    // log the event of clicking the disabled FAQ tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkDisabledF").click(function() {
        Log("StartPage.HotCity.FisrtCity.DisableFAQ", "", "", "");
    });

    // log the event of clicking the enabled route tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkEnabledR").click(function() {
        Log("StartPage.HotCity.FisrtCity.EnableRoute","", "", "");
    });

    // log the event of clicking the disabled route tab of the hottest city in the hot city list
    $("#cityDataContainer .dataLinkDisabledR").click(function() {
        Log("StartPage.HotCity.FisrtCity.DisableRoute", "", "", "");
    });

    //----------------------------------------------------------
    $("#cityDataContainer .dataLinkEnabledM").click(function () {
       
        Log("StartPage.HotCity.FisrtCity.EnableMblog", "", "", "");
    });
    $("#cityDataContainer .dataLinkDisableM").click(function () {
        Log("StartPage.HotCity.FisrtCity.DisableMblog", "", "", "");
    });

    $("#themeDataContainer .dataLinkEnabledM").click(function () {
        Log("StartPage.SpecialTrip.FisrtAttraction.EnableMblog", "", "", "");
    });

    $("#themeDataContainer .dataLinkDisabledM").click(function () {
        Log("StartPage.SpecialTrip.FisrtAttraction.DisableMblog", "", "", "");
    });

    $("#arroundCityContainer .dataLinkEnabledM").click(function () {
        Log("StartPage.AroundTrip.FisrtAttraction.EnableMblog", "", "", "");
    });

    $("#arroundCityContainer .dataLinkDisabledM").click(function () {
        Log("StartPage.AroundTrip.FisrtAttraction.DisableMblog", "", "", "");
    });

    //-------------------------------------------------------------

    // log the event of clicking the enabled travelogue tab of the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkEnabledT").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.EnableTravelogue", "", "", "");
    });

    // log the event of clicking the disabled travelogue tab of  the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkDisabledT").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.DisableTravelogue","", "", "");
    });

    // log the event of clicking the enabled FAQ tab of the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkEnabledF").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.EnableFAQ", "", "", "");
    });

    // log the event of clicking the disabled FAQ tab of the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkDisabledF").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.DisableFAQ", "", "", "");
    });

    // log the event of clicking the enabled route tab of the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkEnabledR").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.EnableRoute", "", "", "");
    });

    // log the event of clicking the disabled route tab of the hottest attraction in the special travel list
    $("#themeDataContainer .dataLinkDisabledR").click(function() {
        Log("StartPage.SpecialTrip.FisrtAttraction.DisableRoute", "", "", "");
    });


    // log the event of clicking the enabled travelogue tab of the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkEnabledT").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.EnableTravelogue", "", "", "");
    });

    // log the event of clicking the disabled travelogue tab of  the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkDisabledT").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.DisableTravelogue", "", "", "");
    });

    // log the event of clicking the enabled FAQ tab of the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkEnabledF").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.EnableFAQ", "", "", "");
    });

    // log the event of clicking the disabled FAQ tab of the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkDisabledF").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.DisableFAQ", "", "", "");
    });

    // log the event of clicking the enabled route tab of the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkEnabledR").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.EnableRoute", "", "", "");
    });

    // log the event of clicking the disabled route tab of the hottest attraction in the around trip list
    $("#arroundCityContainer .dataLinkDisabledR").click(function() {
        Log("StartPage.AroundTrip.FisrtAttraction.DisableRoute", "", "", "");
    });

    // log the event of clicking the link in the footer
    $(".footer a").click(function() {
        Log("StartPage.Footer.Link", $(this).text(), "", "");
    });

    // log the event of clicking search button
    $("#btnSearch").click(function() {
        Log("StartPage.SearchButton", $("#txtSearch").attr("value"), "", "");
    });

    $("#txtSearch").keypress(function(event) {
        if (event.keyCode == 13) {
            Log("StartPage.SearchButton", $("#txtSearch").attr("value"), "", "");
        }
    });

    // log the event of clicking search button
    $("#adLinkContainer a").click(function() {
        Log("StartPage.GetTravelPlugIn","", "", "");
    });
}

var MonthSelectors =
{
    "全部": 0,
    "一月": 1,
    "二月": 2,
    "三月": 3,
    "四月": 4,
    "五月": 5,
    "六月": 6,
    "七月": 7,
    "八月": 8,
    "九月": 9,
    "十月": 10,
    "十一月": 11,
    "十二月": 12
}



/**************************************************************************************************

NAME:   GetMonthValue

DESCRIPTION:
Find month text by specified month value from predefined month dictionary;

PARAS:
- monthValue   [Int]
Month value with specified display text;

RETURNS:    [String]
Display text of month, which is one of KEYs in month dictionary;

**************************************************************************************************/
function GetMonthText(monthValue) {
    for (key in MonthSelectors) {
        if (MonthSelectors[key] == monthValue) {
            return key;
        }
    }
    return "";
}

var themeSelectors =
{
    "悠悠古镇": 1,
    "自然风光": 2,
    "历史古迹": 3,
    "海岛度假": 4,
    "漂流徒步": 5,
    "滑雪潜水": 6,
    "红色之旅": 7,
    "塞外风光": 8

}
var areaSelectors =
{
    "华北华东": 0,
    "华东地区": 1,
    "华南地区": 2,
    "西部地区": 3
}
var areatitle0 =
{
    "北京": 0,
    "天津": 1,
    "沈阳": 2,
    "大连": 3,
    "长春": 4,
    "哈尔滨": 5,
    "石家庄": 6,
    "太原": 7,
    "郑州": 8
}
var areatitle1 =
{
    "上海": 0,
    "杭州": 1,
    "南京": 2,
    "苏州": 3,
    "无锡": 4,
    "济南": 5,
    "厦门": 6,
    "宁波": 7,
    "福州": 8,
    "青岛": 9,
    "合肥": 10,
    "扬州": 11
}
var areatitle2 =
{
    "广州": 0,
    "深圳": 1,
    "武汉": 2,
    "长沙": 3,
    "佛山": 4,
    "南昌": 5,
    "珠海": 6,
    "东莞": 7
}
var areatitle3 =
{
    "成都": 0,
    "西安": 1,
    "重庆": 2,
    "昆明": 3,
    "乌鲁木齐": 4,
    "兰州": 5,
    "贵阳": 6,
    "西宁": 7
}

/**************************************************************************************************

Rewrite the property onclick of the object window.document 
function window.document.onclick() is rewriting the event of window and can't be accepted by the 
firfox;

DESCRIPTION:
This function is called when click blank area to disappear selector windows;

**************************************************************************************************/

window.document.onclick = function(e) {
    //this code is edit for fixing the bug 'id=34185'
    e = window.event || e;
    var srcElement = e.srcElement || e.target; 

    if ((srcElement.id != "monthListTitle") && (srcElement.id != "themeListTitle") && (srcElement.id != "cityListTitle")) {

        $("#cityselector").css({ "display": "none" });
        $("#themeselector").css({ "display": "none" });
        $("#monthselector").css({ "display": "none" });
    }
}

/**************************************************************************************************

NAME:   InitCitySelector

DESCRIPTION:
Initialize the content of the citySelector div;

PARAS:  None

RETURNS:    None

**************************************************************************************************/
function InitCitySelector() {
    var cityCells0 = "";
    var cityCells1 = "";
    var cityCells2 = "";
    var cityCells3 = "";

    cityCells0 = "<div>";
    cityCells1 = "<div>";
    cityCells2 = "<div>";
    cityCells3 = "<div>";
    var selectedKey = $("#cityhotlist .hotlistTitle a").text();
    var temp;
    for (key in areaSelectors) {
        if (key == "华北华东") {
            for (key in areatitle0) {
                if (key == "石家庄") {
                    cityCells0 += "</div>";
                    cityCells0 += "<div>";
                }
                if (key == selectedKey) {
                    cityCells0 += "<span>" + key + "</span>"
                }
                else {
                    cityCells0 += "<a";
                    //cityCells0 += " href = \" \"";
                    cityCells0 += ">" + key + "</a>";
                }
            }
            cityCells0 += "</div>";
            $("#area0").html(cityCells0);
        }

        if (key == "华东地区") {
            for (key in areatitle1) {
                if (key == "厦门") {
                    cityCells1 += "</div>";
                    cityCells1 += "<div>";
                }
                if (key == selectedKey) {
                    cityCells1 += "<span>" + key + "</span>"
                }
                else {
                    cityCells1 += "<a";
                    //cityCells1 += " href = \" \"";
                    cityCells1 += ">" + key + "</a>";
                }
            }
            cityCells1 += "</div>";
            $("#area1").html(cityCells1);
        }

        if (key == "华南地区") {
            for (key in areatitle2) {
                if (key == "珠海") {
                    cityCells2 += "</div>";
                    cityCells2 += "<div>";
                }
                if (key == selectedKey) {
                    cityCells2 += "<span>" + key + "</span>"
                }
                else {
                    cityCells2 += "<a";
                    //cityCells2 += " href = \" \"";
                    cityCells2 += ">" + key + "</a>";
                }
            }
            cityCells2 += "</div>";
            $("#area2").html(cityCells2);

        }
        if (key == "西部地区") {
            for (key in areatitle3) {
                if (key == "贵阳") {
                    cityCells3 += "</div>";
                    cityCells3 += "<div>";
                }
                if (key == selectedKey) {
                    cityCells3 += "<span>" + key + "</span>"
                }
                else {
                    cityCells3 += "<a";
                    //cityCells3 += " href = \" \"";
                    cityCells3 += ">" + key + "</a>";
                }
            }
            cityCells3 += "</div>";
            $("#area3").html(cityCells3);
        }
    }
    $("#cityselector a").click(function() {
        var key = $(this).text();
        ProcessArroundCity(key);

        // log the event of clicking the city in the cityselector
        Log("StartPage.HotCityTitle.City", key, "", "");
    });
}

/**************************************************************************************************

NAME:   ProcessArroundCity

DESCRIPTION:
Entry function to change a theme in a UI selector or by internal function access.
It contains,
1. Update UI elements and redraw theme selector;
2. Send async requests to Json service and update UI with returned results;

PARAS:
- themeText  [String]
Theme text which is one of predefined themes in service;

RETURNS:    None

**************************************************************************************************/
function ProcessArroundCity(cityName) {

    // update title;
    $("#cityListTitle").text(cityName);

    // redraw city selector for new selected value;
    InitCitySelector();

    // close city selector;
    CloseCitySelector();

    // start to loading data;
    LoadDataAsync("#cityhotlist .dataContainer", { "act": "GetHotListArroundCity", "q": cityName }, CallBackHotListArroundCity);
}

function CallBackHotListArroundCity() {
    InitLogFunction();
}

/**************************************************************************************************

NAME: DrawMonthSelector()

DESCRIPTION:
initilize the content od the monthSelector div

**************************************************************************************************/

function DrawMonthSelector() {
    //init data in selector;
    var monthCells = "";
    var selectedKey = $("#monthhotlist .hotlistTitle a").text();
    monthCells += "<div>";
    for (key in MonthSelectors) {

        if (key == "全部") {
            continue;
        }
        if ((key == "五月") || (key == "九月")) {

            monthCells += "</div>"
            monthCells += "<div>";
        }

        if (key == selectedKey) {
            monthCells += "<span>" + key + "</span>"
        }
        else {
            monthCells += "<a";
            // monthCells += " href = \" \"";
            monthCells += ">" + key + "</a>";
        }
    }
    monthCells += "</div>"
    $("#monthselector").html(monthCells);

    // register mouse click events.
    $("#monthselector a").click(function() {
        var key = $(this).text();
        var val = MonthSelectors[key];
        ProcessMonth(val);

        // log the event of clicking the month in the monthselector
        Log("StartPage.HotMonthTitle.Month", val, "", "");
    });
}

/**************************************************************************************************

NAME:   ProcessMonth

DESCRIPTION:
Entry function to change a month value in a UI selector or by internal function access.
It contains,
1. Update UI elements and redraw month selector;
2. Send async requests to Json service and update UI with returned results;

PARAS:
- monthVal  [Int]
Month number which starts from 1. If it's 0, it indicate all month;

RETURNS:    None

**************************************************************************************************/
function ProcessMonth(monthVal) {
    
    // update title;
    $("#monthhotlist .hotlistTitle a").text(GetMonthText(monthVal));

    // redraw month selector for new selected value;
    DrawMonthSelector();

    // close month selector;
    CloseMonthSelector();

    // start to loading data;
    LoadDataAsync("#monthhotlist .dataContainer", { "act": "GetHotListByMonth", "q": monthVal }, CallBackHotListByMonth);
}

function CallBackHotListByMonth() {
    InitLogFunction();
}

/**************************************************************************************************

NAME:ThemeSelector()

DESCRIPTION:
initilize the content od the theme Selector div

**************************************************************************************************/
function InitThemeSelector() {

    var themeCells = "";
    var selectedKey = $("#themehotlist .hotlistTitle a").text();
    themeCells += "<div>"
    for (key in themeSelectors) {
        if ((key == "海岛度假") || (key == "红色之旅")) {
            themeCells += "</div>";
            themeCells += "<div>";
        }
        if (key == selectedKey) {
            themeCells += "<span>" + key + "</span>"
        }
        else {
            themeCells += "<a";
            // themeCells += " href = \" \"";
            themeCells += ">" + key + "</a>";
        }
    }
    themeCells += "</div>";
    $("#themeselector").html(themeCells);

    // register mouse click events.
    $("#themeselector a").click(function() {

        var themeText = $(this).text();

        ProcessTheme(themeText);

        // log the event of clicking the theme in the themeselector
        Log("StartPage.HotThemeTitle.Theme", themeText, "", "");
    });
}

/**************************************************************************************************

NAME:   ProcessTheme

DESCRIPTION:
Entry function to change a theme in a UI selector or by internal function access.
It contains,
1. Update UI elements and redraw theme selector;
2. Send async requests to Json service and update UI with returned results;

PARAS:
- themeText  [String]
Theme text which is one of predefined themes in service;

RETURNS:    None

**************************************************************************************************/
function ProcessTheme(themeText) {

    // update title;
    $("#themehotlist .hotlistTitle a").text(themeText);

    // redraw theme selector for new selected value;
    InitThemeSelector();

    // close theme selector;
    ClosethemeSelector();

    // start to loading data;
    LoadDataAsync("#themehotlist .dataContainer", { "act": "GetHotListByTheme", "q": themeText }, CallBackHotListThem);
}

function CallBackHotListThem() {
    InitLogFunction();
}

/**************************************************************************************************

NAME:ThemeSelector()

DESCRIPTION:
register events with handlers for start page

**************************************************************************************************/

function InitEvents() {

    //theme selector show/hide
    $("#themehotlist .changefilter").click(function() {

        if ($("#themeselector").is(":hidden")) {
            $("#themeselector").fadeIn("fast");
            $("#monthselector").hide();
            $("#cityselector").hide();
        }
        else {
            $("#themeselector").hide();
        }
    });

    // month selector show/hide
    $("#monthhotlist .changefilter").click(function() {
        if ($("#monthselector").is(":hidden")) {
            $("#monthselector").fadeIn("fast");
            $("#themeselector").hide();
            $("#cityselector").hide();
        }
        else {
            $("#monthselector").hide();
        }

    });

    //city selector show/hide
    $("#cityhotlist .changefilter").click(function() {

        if ($("#cityselector").is(":hidden")) {

            $("#cityselector").fadeIn("fast");
            $("#monthselector").hide();
            $("#themeselector").hide();
        }
        else {
            $("#cityselector").hide();
        }
    });

    //    // click on search box;
    //    $("#btnSearch").click(function() {
    //        window.location = "search.aspx?q=" + encodeURI(Filters.FilterSearch($("#txtSearch").val()));
    //    });
}

// hide month selector panel
function CloseMonthSelector() {
    $("#monthselector").hide();
}

// hide theme selector panel 
function ClosethemeSelector() {
    $("#themeselector").hide();
}

// hide city selector panel
function CloseCitySelector() {
    $("#cityselector").hide();
}


var sle_Index = -1;
var originalText = "";
var timer_ExcSearch = null;
var excuteTimer = false;
var selBgColor ="#def3ff" ;//"#67bdfd"
var unSelBgColor = "#ffffff";

$(document).ready(function () {

    $("body").click(function () { $("#dropDown").hide(); });

    $("#txtSearch").keyup(function (event) {
   
        var keyCode = event.keyCode;

        if (delKeyCode(keyCode))
            return;

        var key = document.getElementById("txtSearch").value;

        if (key == "") {
            $("#dropDown").hide();
            return;
        }
        var top = $("#txtSearch").offset().top;
        var left = $("#txtSearch").offset().left;


        //begin search
        if (keyCode == 13) {
            $("#dropDown").hide();
            sle_Index = -1;
        }
        //down key
        else if (keyCode == 40) {

            var divList = document.getElementById("dropDown").getElementsByTagName("div");
            if (divList == 0)
                return;

            if (sle_Index != (divList.length - 1)) {
                sle_Index++;
            }
            else {
                sle_Index = -1;
                document.getElementById("txtSearch").value = originalText;
            }

            var getValue = "";
            for (var i = 0; i < divList.length; i++) {

                if (i != sle_Index) {
                    divList[i].style.backgroundColor = unSelBgColor;
                }
                else {
                    divList[i].style.backgroundColor = selBgColor;
                    getValue = divList[i].innerText;
                    document.getElementById("txtSearch").value = getValue;
                }
            }
        }

        //Up key
        else if (keyCode == 38) {

            var divList = document.getElementById("dropDown").getElementsByTagName("div");

            if (divList == 0)
                return;

            if (sle_Index != -1) {
                if (sle_Index == 0) {
                    document.getElementById("txtSearch").value = originalText;
                }
                sle_Index--;

            }

            else {
                sle_Index = divList.length - 1;
            }

            var getValue = "";
            for (var i = 0; i < divList.length; i++) {

                if (i != sle_Index) {
                    divList[i].style.backgroundColor = unSelBgColor;
                }
                else {
                    divList[i].style.backgroundColor = selBgColor;
                    getValue = divList[i].innerText;
                    document.getElementById("txtSearch").value = getValue;
                }
            }
        }
        //get the d
        else {

            sle_Index = -1;

            if (excuteTimer == false) {
                StartExcSearchTimer(key);
                excuteTimer = true;
            }
            else {
                EndExcSearchTimer(key);
            }

            originalText = document.getElementById("txtSearch").value;
        }
    });

});


function StartExcSearchTimer(keyValue) {
  
    timer_ExcSearch = window.setTimeout("ajax_Request('" + keyValue + "')", 400);
}

function EndExcSearchTimer(keyValue) {
    if (timer_ExcSearch != null) {
        window.clearTimeout(timer_ExcSearch);
    }
   
    timer_ExcSearch = window.setTimeout("ajax_Request('" + keyValue + "')", 400);

}


function ajax_Request(keyValue) {
   
   GetQueryAutoSuggestion(keyValue);

   
   
   
}

function delKeyCode(keyCode) {
    var array = new Array();
    array = [16, 19, 20, 27, 33, 34, 35, 36, 45, 46, 91, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 145, 192];
    for (i = 0; i < array.length; i++) {
        if (keyCode == array[i]) {
            return true;
            break;
        }

        return false;
    }
}

function GetQueryAutoSuggestion(query) {
  
    $.ajax(
    {
        type: 'post',
        url: '/get.aspx?' + new Date().valueOf(),
        data: { "act": "GetQueryAutoSuggestion",
            "q": query
        },
        dataType: 'json',

        beforeSend: function (XMLHttpRequest) {

        },

        success: function (data, textStatus) {
         
            if (data == null)
                return;
            var itemList = eval(data);
            var itemData = itemList.DataList;

            $("#dropDown").empty();
            for (var i = 0; i < itemData.length; i++) {
                var item = itemData[i].item;
                $("#dropDown").append("<div class='resItem'>" + item + "</div>");
            }
            if (itemData.length > 0) {
                $("#dropDown").show();

                $("#dropDown >div").mouseover(function () {
                    if (sle_Index >= 0) {
                        $("#dropDown >div:eq(" + sle_Index + ")").css("background-color", unSelBgColor);
                    }
                    $(this).css("background-color", selBgColor);
                });

                $("#dropDown >div").mouseout(function () {
                    $(this).css("background-color", unSelBgColor);
                });
                $("#dropDown >div").click(function () {

                    $("#txtSearch").val($.trim($(this).text()));
                    $(this).parent().hide();
                });
            }
        },

        complete: function (XMLHttpRequest, textStatus) {
        
        },

        error: function (XMLHttpRequest, textStatus, errorThrown) {
           
            // show error msg in display blocks.
        }
    })
}
