﻿// moves the focus on wnter key pressed from a textbox to a specified button
var actual = 0;
var text1 = '';
var text2 = '';
var text3 = '';
var text4 = '';
var link1 = '';
var link2 = '';
var link3 = '';
var link4 = '';

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";
            }
        });
    }
}
function ChangeClass(link) {

    link.setAttribute("class", "bluelink");
}

function RestoreClass(link) {
    link.setAttribute("class", "blacklink");
}

function ChangeClass2(link) {
    thelink = $('#' + link);
    thelink.attr("class", "btnOver");
}

function RestoreClass2(link) {
    thelink = $('#' + link);
    thelink.attr("class", "btnNormal");
}




function MovePictures(nav, div, l1, l2, l3, l4, hlnk1, hlnk2, hlnk3, hlnk4, t1, t2, t3, t4) {
    text1 = t1;
    text2 = t2;
    text3 = t3;
    text4 = t4;
    link1 = l1;
    link2 = l2;
    link3 = l3;
    link4 = l4;
    $('#' + div).fadeIn(1000, function () {
      //  $('#' + div).before $('#' + nav)
        $('#' + div).cycle({
            fx: 'fade',
            speed: 'slow',
            timeout: 5000,
            pager: $('#' + nav)
        });
        hyper1 = $('#' + hlnk1);
        hyper2 = $('#' + hlnk2);
        hyper3 = $('#' + hlnk3);
        hyper4 = $('#' + hlnk4);
        setInterval('ChangeLinks(hyper1,hyper2,hyper3,hyper4)', 5000);
    });

}


function ChangeLinks(hyper1, hyper2, hyper3, hyper4) {
    if (actual == 4) {
        actual = 0;
    }

    if (actual == 0) {
        hyper1.attr('href', link4);
        hyper2.attr('href', link1);
        hyper3.attr('href', link2);
        hyper4.attr('href', link3);

        hyper1.text(text4);
        hyper2.text(text1);
        hyper3.text(text2);
        hyper4.text(text3);
    }
    else if (actual == 1) {

        hyper1.attr('href', link3);
        hyper2.attr('href', link4);
        hyper3.attr('href', link1);
        hyper4.attr('href', link2);

        hyper1.text(text3);
        hyper2.text(text4);
        hyper3.text(text1);
        hyper4.text(text2);

    }
    else if (actual == 2) {
        hyper1.attr('href', link2);
        hyper2.attr('href', link3);
        hyper3.attr('href', link4);
        hyper4.attr('href', link1);

        hyper1.text(text2);
        hyper2.text(text3);
        hyper3.text(text4);
        hyper4.text(text1);

    } else {//0

        hyper1.attr('href', link1);
        hyper2.attr('href', link2);
        hyper3.attr('href', link3);
        hyper4.attr('href', link4);

        hyper1.text(text1);
        hyper2.text(text2);
        hyper3.text(text3);
        hyper4.text(text4);

    }
    actual = actual + 1;

}

function JsBanner(nav, div, td1, td2, td3, td4) {

    $('#' + div).fadeIn(1000, function () {
        pagerEvent: 'click.cycle'
        $('#' + div).cycle({
            fx: 'fade',
            speed: 'slow',
            timeout: 3000,
            pager: $('#' + nav)
        });

        t1 = $('#' + td1);
        t2 = $('#' + td2);
        t3 = $('#' + td3);
        t4 = $('#' + td4);

        setInterval('ChangeImages(t1,t2,t3,t4)', 3000);
    });

}
function ChangeImages(t1, t2, t3, t4) {

    if (t1.attr('class') == 'divLongRed') {
         t1.attr('class', 'divShortRed');
        t2.attr('class', 'divLongBlue');
        t3.attr('class', 'divShortPurple');
        t4.attr('class', 'divShortGreen');
    } else
        if (t2.attr('class') == 'divLongBlue') {
            t1.attr('class', 'divShortRed');
            t2.attr('class', 'divShortBlue');
            t3.attr('class', 'divLongPurple');
            t4.attr('class', 'divShortGreen');
        } else
            if (t3.attr('class') == 'divLongPurple') {
                t1.attr('class', 'divShortRed');
                t2.attr('class', 'divShortBlue');
                t3.attr('class', 'divShortPurple');
                t4.attr('class', 'divLongGreen');
            } else
                if (t4.attr('class') == 'divLongGreen') {
                    t1.attr('class', 'divLongRed');
                    t2.attr('class', 'divShortBlue');
                    t3.attr('class', 'divShortPurple');
                    t4.attr('class', 'divShortGreen');
                }


}
function SetCurrentFlashImage(val) {
    if (val == 1) {
        $('#td1').attr('class', 'divShortRed');
        $('#td2').attr('class', 'divLongBlue');
        $('#td3').attr('class', 'divShortPurple');
        $('#td4').attr('class', 'divShortGreen');

    }
    else if (t2.attr('class') == 'divLongBlue') {
        $('#td1').attr('class', 'divShortRed');
        $('#td2').attr('class', 'divShortBlue');
        $('#td3').attr('class', 'divLongPurple');
        $('#td4').attr('class', 'divShortGreen');
    } else
        if (t3.attr('class') == 'divLongPurple') {
            $('#td1').attr('class', 'divShortRed');
            $('#td2').attr('class', 'divShortBlue');
            $('#td3').attr('class', 'divShortPurple');
            $('#td4').attr('class', 'divLongGreen');
        } else
            if (t4.attr('class') == 'divLongGreen') {
                $('#td1').attr('class', 'divLongRed');
                $('#td2').attr('class', 'divShortBlue');
                $('#td3').attr('class', 'divShortPurple');
                $('#td4').attr('class', 'divShortGreen');
            }

}
function OpenCrappyWidgets(control2, img) {
 
    var detail = $('#' + control2);
    var image = $('#' + img);
 
    var src = image.attr("src");
    
    if (src.indexOf("Up") > 0) {
        src=src.replace('Up', 'Down');
      
        image.attr("src", src);
    } else {
      
       
        src=src.replace('Down', 'Up');

        image.attr("src", src);
        
    }
    detail.toggle();
}
function faceva(div, img) {
  /*  var divV = $('#' + div);
    var imgG = $('#' + img);

    if (imgG.attr('src').('Down')) {
        imgG.attr('src', imgG.attr('src').replace('Down', 'Up'));
        divV.css('display', 'block');
    } else {
        imgG.attr('src', imgG.attr('src').replace('Up', 'Down'));
        divV.css('display', 'none');
    }*/
}
