function _$(id) {
    return document.getElementById(id);
}

//_prevBannerIndex = 0;
//_bannerIdPrefix = "divTBanner";
//_BannerCount = 1;
//
//function NextBanner() {
//    var cIndex = _prevBannerIndex + 1;
//    if (cIndex < _BannerCount) {
//        _$(_bannerIdPrefix + _prevBannerIndex).style.display = "none";
//        _$(_bannerIdPrefix + cIndex).style.display = "";
//        _prevBannerIndex = cIndex;
//    }
//}
//
//function PrevBanner() {
//    var cIndex = _prevBannerIndex - 1;
//    if (cIndex >= 0) {
//        _$(_bannerIdPrefix + _prevBannerIndex).style.display = "none";
//        _$(_bannerIdPrefix + cIndex).style.display = "";
//        _prevBannerIndex = cIndex;
//    }
//}

/* Search section start */

/* Search On Focus */
function readyToSearch() {
    if (_$("searchBox").value == "Search keywords") {
        _$("searchBox").value = "";
    }
}

/* Search On Blur */
function blankSearch() {
    if (_$("searchBox").value == "") {
        _$("searchBox").value = "Search keywords";
    }
}

/* Search  onkeypress */
function __searchEnter(e) {
    var keycode = null;
    if(e) {
        e = e
    }else {
        e = window.event
    }

    if(e.which) {
        keycode = e.which
    }else {
        keycode = e.keyCode
    }

    if(keycode == 13) {
        return __submainSearch();
//        if (_$("searchBox").value != ""
//                && _$("searchBox").value != "Search keywords") {
//            if (_$("searchBox").value == "Search keywords") {
//                _$("searchBox").value = "";
//            }
//            window.location = "/search.aspx?searchtext=" + escape(_$("searchBox").value);
//        }else {
//            alert('Please enter the search keyword');
//        }
//        return false;
    }else
        return true;
}

/* Search  onclick */
function __submainSearch() {
    if(_$("searchBox").value != ""
                && _$("searchBox").value != "Search keywords") {
        if(_$("searchBox").value == "Search keywords") {
            _$("searchBox").value = "";
        }
        window.location = "/search.aspx?searchtext=" + escape(_$("searchBox").value);
    }else {
        alert('Please enter the search keyword');
    }
    return false;
}
/* Search section end */

/* UI Connect Start */
function fnUiConnect(ctrlID) {
    var oSelect = _$(ctrlID);
    if (oSelect) {
        var val = oSelect.options[oSelect.selectedIndex].value;
        window.open(val, '_blank');
    }
}
/* UI Connect End */

function fnValidateSearch() {
    if (_$("zipCode").value == "") {
        if (_$("state").value == "") {
            alert("Please provide a search criteria");
            _$("zipCode").focus();
            return false;
        }
        if (_$("city").value == "") {
            alert("Please provide a city name.");
            return false;
        }
    }
    return __mapSearch();
}

/* Location JS */
function __mapSearch() {
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    var zoom = _$("zoom");
    var state = _$("state");
    var city = _$("city");

    if (sPage.toLowerCase() == "locations.aspx") {
        try {
            if (EMap != null) {
                EMap.CurrentZoomLevel = zoom.options[zoom.selectedIndex].value;

                if (_$("zipCode").value != '') {
                    Address = _$("zipCode").value;
                }else {
                    //Address = state.options[state.selectedIndex].value + " " + city.options[city.selectedIndex].value;
					Address = city.options[city.selectedIndex].value + " " + state.options[state.selectedIndex].value;
				}
                _$("__SearchAddr").value = Address;
                //EMap.FindAll(true);
                //EMap.SetZoomLevel();
                EMap.Address = Address;
                EMap.SearchAddr = Address;
                EMap.LoadMap(null, EMap.CurrentZoomLevel, null, false);
				EMap.Search();
            }
        } catch (e) {
            if (_$("zipCode").value != '') {
                _$("__SearchAddr").value = _$("zipCode").value;
            }else {
                _$("__SearchAddr").value = state.options[state.selectedIndex].value + " " + city.options[city.selectedIndex].value;
            }
            alert('error');
        }
    }else {
        window.location = "/Locations.aspx?z=" + zoom.options[zoom.selectedIndex].value + "&zip=" + _$("zipCode").value + "&c=" + city.options[city.selectedIndex].value + "&s=" + state.options[state.selectedIndex].value;
    }
}
/* Location JS End */

/* Set Location Search Criteria */
function setLocationSearch(zoomVal, zip, stateName, cityName, serviceID) {
    var zoom = _$("zoom");
    _$("zipCode").value = zip;
    var city = _$("city");
    var state = _$("state");
    //Loop Through Zoom
    for (var i = 0; i < zoom.options.length; i++) {
        if (zoom.options[i].value == zoomVal) {
            zoom.options[i].selected = zoomVal;
            break;
        }
    }
    for (var i = 0; i < state.options.length; i++) {
        if (state.options[i].value == stateName) {
            state.options[i].selected = stateName;
            break;
        }
    }

    if (state.value != "")
        setCities();

    var cityFound = false;
    //Loop Through City
    for (var i = 0; i < city.options.length; i++) {
        if (city.options[i].value == cityName) {
            city.options[i].selected = cityName;
            cityFound = true;
            break;
        }
    }

    var cityCount = city.options.length;
    if (!cityFound) {
        city.options.length = 0;
        city.options[0] = new Option("Select City", "");
    }

    //Set Service
    if (serviceID != 0)
        _mapSelectedCategoryID = serviceID;

    //__mapSearch();
}
/* Set Location Search Criteria End */

/* Redirecting in location page from home page */
function checkAndRedirectLocation() {
    var offer = _$("offering_list");
    var zoom = _$("zoom");
    if (_$("offering_list").value == "") {
        alert("Please select Offering Service");
        return false;
    }
    if (_$("zoom").value == "") {
        alert("Please select zoom level");
        return false;
    }
    if (_$("zip").value == "") {
        alert("Please enter zip code");
        return false;
    }
    window.location = "/Locations.aspx?z=" + zoom.options[zoom.selectedIndex].value + "&zip=" + _$("zip").value + "&offer=" + offer.options[offer.selectedIndex].value;
}
/* Redirecting in location page from home page end */

function clickSearch(e) {
    if (e.keyCode == 13) {
        fnValidateSearch();
        return false;
    }
}

