﻿$(document).ready(function () {
    // Create a panel scroller
    locationsScroller2 = new Scroller("locationsContainer2", "locations2", -20);
    keyphrasesScroller2 = new Scroller("keyphrasesContainer2", "keyphrases2", -20);
});

var locationsScroller2;
var keyphrasesScroller2;
var LocIDClicked = "";
var phraseClicked = "";

function Demoredirect() {
    strURL = "http://" + window.location.host + "/keyphraseDemo.aspx?phrase=" + phraseClicked + "&loc=" + LocIDClicked;
    window.location = strURL;
}

function getLocations(elem) {
    var text = elem.value;
    if (text != "") {
        if (text.length > 3) {
            // call the get locations handler to return a list of location related to the submitted text
            // and populate them into the drop down list for selection
            var d = new Date();
            var time = d.getTime();
            elem.style.backgroundImage = "url('http://image.locallinkup.com/keyPhraseSampler/loading.gif')";
            var strURL = "http://www.locallinkup.com/resources/handlers/keyphrasedemo/getLocations.ashx?search=" + text + "&d=" + time;
            $.get(strURL, function (data) {
                if (data != "locNotFound") {
                    document.getElementById('locations2').innerHTML = data;
                    document.getElementById('locationsContainer2').style.display = "inline";
                    locationsScroller2.setScrollHeight();
                }
                elem.style.backgroundImage = "none";
            });
        }
    }
}

function locationClicked(placeID, text) {
    // set the text in the search box, hide the selection list and call getMajorLocations to get them
    document.getElementById('tnLocation').value = text;
    document.getElementById('locationsContainer2').style.display = "none";
    locationsScroller2.setScrollVisible("none");
    LocIDClicked = placeID + "^" + text;
}

function getKeyphraseSuggestions(elem) {
    // call the get keywords handler to return a list of keywords related to the submitted text
    // and populate them into the drop down list for selection
    var text = elem.value;
    if (text.length > 1) {
        var tempWords = text.split(" ");
        var textToSearch = ""
        for (var i = 0; i < tempWords.length; i++) {
            if (tempWords[i].length > 1) {
                textToSearch += tempWords[i] + " ";
            }
        }
        if (textToSearch != "") {
            elem.style.backgroundImage = "url('http://image.locallinkup.com/keyPhraseSampler/loading.gif')";
            var strURL = "http://www.locallinkup.com/resources/handlers/keyphrasedemo/getKeyPhrases.ashx?search=" + textToSearch + "&d=" + new Date().getMilliseconds();
            $.get(strURL, function (data) {
                if (data.indexOf("locNotFound") == -1) {
                    document.getElementById('keyphrases2').innerHTML = data;
                    document.getElementById('keyphrasesContainer2').style.display = "inline";
                    keyphrasesScroller2.setScrollHeight();
                }
                elem.style.backgroundImage = "none";
            });
        }
    }
}

function keyPhrasesSuggestionClicked(phraseText) {
    document.getElementById('tbPhrase').value = phraseText;
    document.getElementById('keyphrasesContainer2').style.display = "none";
    keyphrasesScroller2.setScrollVisible("none");
    phraseClicked = phraseText;
}

function checkKeys(e) {
    if (e.keyCode == 13) {
        // Enter
        try { e.preventDefault(); } catch (err) { }
        try { e.stopPropagation(); } catch (err) { }
        try { e.returnValue = false; } catch (err) { }
        return false;
    }
}
