﻿// moves the focus on wnter key pressed from a textbox to a specified button
function MoveFocusToControl(e, btn) {
    var characterCode;
    if (e && e.which) // NN4 specific code
    {
        e = e;
        characterCode = e.which;
    } else {
        e = event
        characterCode = e.keyCode; // IE specific code
    } if (characterCode == 13) //// Enter key is 13
    {
        e.returnValue = false;
        e.cancelBubble = true;
  
        var obj2=document.getElementById(btn);

        eval(unescape(obj2.href.replace("javascript:", "")));
        return false;
    } else return true;
}

function CustomPostcodeSearch_DoSearch(text1, image, cityTB) {
    var whiteSpace = false;

    var textBox = document.getElementById(text1);
    var img = document.getElementById(image);
    var city = document.getElementById(city);
    var letters = textBox.value.length + 1;
    if (textBox.value.substring(4, 5) == " ") {
        whiteSpace = true;
    }

    if (((letters <= 6) && (whiteSpace == false)) || ((letters <= 7) && (whiteSpace == true))) {
        /*if (letters <= 4) {
        if (hasNumbers(textBox.value)) {
        textBox.style.backgroundColor = "red";
        }
        else {
        textBox.style.backgroundColor = "white";
        }
        }*/
        textBox.focus();
    }
    else {
        if (img != null) {
            img.src = _appTheme + "Images/Postcode/loading.gif";
        }
        textBox.blur();
        var post = textBox.value;
        $(".PostCodeSelector").attr("value", post);
        PageMethods.GetCityFromPostcode(textBox.value, function(result) {
            if (city != null) {
                city.value = result;
                //SiteProperties.SelectedPostcode=textBox.value;
            }
        });
        PageMethods.GetShopByPostcode(textBox.value, function(result) {
            if (result != "null") {
                img.src = _appTheme + "Images/Postcode/bifa.jpg";

                //SiteProperties.SelectedPostcode = textBox.value;

                var js = "var json=" + result + ";";
                try {
                    var q = "(" + result + ")";
                    var json = eval(q);

                    $("#SmallShop_ShopName").html(json.ShopName);
                    // $("#SmallShop_ShopName").attr("href", _siteRoot + "DisplayShop.aspx?shopId=" + json.ShopId);
                    $("#SmallShop_OwnerName").html(json.OwnerName);
                    $("#SmallShop_Street").html(json.Street);
                    $("#SmallShop_City").html(json.City + json.Postcode);
                    $("#SmallShop_Phone").html(json.Phone);
                    $("#SmallShop_Email").html("Mail");
                    $("#SmallShop_Email").attr("href", 'mailto:' + json.Email);

                    $("#SmallShop_Image").css("background-image", "url('" + json.Image + "')");
                    $("#SmallShop_Image").attr("onmouseover", "TipSimpleImage('" + json.OwnerPictureLarge + "&width=200');");
                    $("#SmallShop_Image").attr("onmouseout", "UnTip();");

                    $("#SmallShop_Loader").css("display", "none");

                    OpenSmallShopDetails();
                    FillShopDetails(json.ShopId);
                } catch (e) {
                    //alert(e);
                }

            }
            else {
                img.src = _appTheme + "Images/Postcode/x.png";
            }
        });
    }
}   


