function ApplicationInit() {
    // start keep alive
    setInterval(KeepSessionAlive, 2 * 60 * 1000);
    if (_siteRoot.toLowerCase().indexOf("onlineplanning/") < 0) {
        OPTimer.ResetTimer();
    }
}

function KeepSessionAlive() {
    $.post(_siteRoot + "KeepAlive.ashx", null, function () { });
}

var OPTimer = {};
OPTimer.LoadTimer = function () {
    var serverResponse = confirm("Deze sessie is verlopen. U wordt doorverwezen naar de homepagina!");
    if (serverResponse) {
        document.location = _siteRoot;
    }
    else {
        document.location = _siteRoot;
    }

}
 
OPTimer.StartTimer = setTimeout("OPTimer.LoadTimer()", 1800000);

OPTimer.ResetTimer = function () {
    window.clearTimeout(OPTimer.StartTimer);
}

$tabsShop = null;

$shopLat = 0;
$shopLng = 0;

var shopIdForUsedTyres = 0;

function checkZip3(txtPostcode) {
    var textBox = $('#' + txtPostcode);

    var whiteSpace = false;
    var letters = textBox.val().length + 1;
    if (textBox.val().substring(4, 5) == " ") {
        whiteSpace = true;
    }
    if (((letters <= 6) && (whiteSpace == false)) || ((letters <= 7) && (whiteSpace == true))) {
        textBox.focus();
    }
    else {
        $.getJSON(_siteRoot + "Ajax/SearchCity.aspx?postcode=" + textBox.val(), function (data) {
            if (data.shopName != null) {
                $("[id$='shopName']").html(data.shopName);
                $("[id$='shopAddress']").html(data.address);
                //   $("[id$='shopPhone']").html(data.phone);
                $("[id$='txtCity']").val(data.city);
            }
            else {
                $("[id$='txtPostcode']").val("");
                $("[id$='shopName']").html("");
                $("[id$='shopAddress']").html("");
                //  $("[id$='shopPhone']").html("");
            }
        });
    }
}

// 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;
}

// sets the background of a panel
function loadBgd(panel) {

    var td = document.getElementById(panel);
    var height = td.clientHeight;
    var width = td.clientWidth;
    td.style.backgroundImage = "url(" + _siteRoot + "/Helpers/ImageBuilder.aspx?type=RoundedCorners&amp;width=" + width + "&amp;height=" + height + "&amp;background-mode=solid&amp;corner=10&amp;inner-background=ffffff&amp;outer-background=f6f6f6&amp;border-size=0&amp;border-color=ffffff&amp;imageCodec=png)";
}

// return 'name' parameter from url
function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function GetPageUrl() {
    var url = window.location.href;
    if (url.indexOf("?") > -1) {
        var s = url.split("?")[0];
        return s;
    }
    return url;
}

function MakeRoundRectangle(control, innerColor, outerColor, radius, borderSize, borderColor) {
}

function hasNumbers(t) {
    var regex = /\d/g;
    return regex.test(t);
}

// validates the zipcode and sets the favorite shop setting the image accordingly
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.Postcode + " " + json.City);
                    $("#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");
                    $("#divVulUv").empty();

                    OpenSmallShopDetails();
                    FillShopDetails(json.ShopId);

                } catch (e) {
                    //alert(e);
                }

            }
            else {
                img.src = _appTheme + "Images/Postcode/x.png";
            }
        });
    }
}


function FillShopData(text1, image) {
    var whiteSpace = false;

    var textBox = document.getElementById(text1);
    var img = document.getElementById(image);
    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 {
        img.src = _appTheme + "Images/Postcode/loading.gif";
        var post = textBox.value;
        $(".PostCodeSelector").attr("value", post);
        textBox.blur();
        PageMethods.GetCityFromPostcode(textBox.value, function (result) {
            try {
                var city = $get("ShopSearch_tbCities");
                if (city != null) {
                    var cityName = result.split('|')[0];
                    city.value = cityName;
                    city.innerText = cityName;
                    //SiteProperties.SelectedPostcode = textBox.value;
                }
            }
            catch (e) {
            }
        });
        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.Postcode + " " + json.City);
                    $("#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 FillShopDataForShopID(_shopId, _acc) {
    PageMethods.GetShopById(_shopId, function (result) {
        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var json = eval(q);
                //$("[id$='_SmallShop_Table']").css("display", "block");
                $("#SmallShop_ShopName").html(json.ShopName);

                var hlShopReviewsPerShop = $("#hlShopReviewsPerShop");
                hlShopReviewsPerShop.attr("href", _siteRoot + "ShopReviews.aspx?shopid=" + json.ShopId);
                shopIdForUsedTyres = json.ShopId;
                $("#usedTyresHomeDiv").empty();

                //$("#SmallShop_ShopName").attr("href", _siteRoot + "DisplayShop.aspx?shopId=" + json.ShopId);
                $("#SmallShop_OwnerName").html(json.OwnerName);
                $("#SmallShop_Street").html(json.Street);
                $("#SmallShop_City").html(json.Postcode + " " + json.City);
                $("#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();");
                //if (_acc != null) {
                //    _acc.set_SelectedIndex(1);
                //}
                $("#SmallShop_Loader").css("display", "none");
                OpenSmallShopDetails();
                FillShopDetailsFromJSON(json);

                if ($tabsShop != null)
                    $tabsShop.tabs('select', 3);
            } catch (e) {
                //alert(e);
            }

        }
    });
}

function FillShopDetailsFromJSON(json) {
    var divServices = $('#ShopDetails_Services');

    divServices.empty();
    var servicesTable = "<table width='100%'>";
    for (var i = 0; i < json.Services.length; i += 3) {
        if (i % 2 == 0) {
            servicesTable += "<tr class='ShopSearchServicesAlternateRow'>";
        }
        else {
            servicesTable += "<tr class='ShopSearchServicesRow'>";
        }

        if (json.Services[i].URL != '')
            servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i].ServiceName + "</span><a></td>";
        else
            servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none'><span class='ShopSearchServicesText'>" + json.Services[i].ServiceName + "</span><a></td>";
        if (i + 1 < json.Services.length) {
            if (json.Services[i + 1].URL != '')
                servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i + 1].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i + 1].ServiceName + "</span></a></td>";
            else
                servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none'><span class='ShopSearchServicesText'>" + json.Services[i + 1].ServiceName + "</span></a></td>";
        }
        if (i + 2 < json.Services.length) {
            if (json.Services[i + 2].URL != '')
                servicesTable += "<td width='34%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i + 2].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i + 2].ServiceName + "</span></a></td>";
            else
                servicesTable += "<td width='34%' style='padding-left:10px'><a style='text-decoration:none'><span class='ShopSearchServicesText'>" + json.Services[i + 2].ServiceName + "</span></a></td>";
        }
        /*/
        servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i].ServiceName + "</span><a></td>";

        if (i + 1 < json.Services.length) {
            servicesTable += "<td width='33%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i + 1].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i + 1].ServiceName + "</span></a></td>";
        }
        if (i + 2 < json.Services.length) {
            servicesTable += "<td width='34%' style='padding-left:10px'><a style='text-decoration:none' href='" + json.Services[i + 2].URL + "'><span class='ShopSearchServicesText'>" + json.Services[i + 2].ServiceName + "</span></a></td>";
        }*/
        servicesTable += "</tr>";
    }
    servicesTable += "</table>";
    divServices.append(servicesTable);

    var divSchedule = $('#ShopDetails_Schedule');
    divSchedule.empty();
    var scheduleTable = "<table cellpadding='0' cellspacing='0' width='100%' style=''>";
    for (var i = 0; i < json.Schedule.length; i++) {

        if (i % 2 == 0) {
            scheduleTable += "<tr class='ShopSearchScheduleAlternateRow'><td style='padding-left:10px'>" + json.Schedule[i].Day + "</td><td>" + json.Schedule[i].Opened + "</td></tr>";
        }
        else {
            scheduleTable += "<tr class='ShopSearchScheduleRow'><td style='padding-left:10px'>" + json.Schedule[i].Day + "</td><td>" + json.Schedule[i].Opened + "</td></tr>";
        }
    }
    scheduleTable += "</table>";
    divSchedule.append(scheduleTable);


    var shopImage = $('#ShopDetails_ShopImage');
    shopImage.attr("src", json.ShopImage);

    var network = $('#ShopDetails_Network');
    network.empty();

    var networkTable = "<table width='100%' cellspacing='5px'>";
    for (var i = 0; i < json.Network.length; i += 3) {
        networkTable += "<tr>";
        networkTable += "<td width='33%' valign='top' onclick='FillShopDataForShopID(" + json.Network[i].ShopId + ",null)' style='background-color:#f0f0f0;cursor:pointer;'><table><tr><td valign='top'><img src='" + json.Network[i].ShopImage + "' height='60'/></td><td valign='top'><span class='ShopSearchNetworkName'>" + json.Network[i].ShopName + "</span><br><span class='ShopSearchNetworkAddress'>" + json.Network[i].Street + "<br>" + json.Network[i].City + " " + json.Network[i].Postcode + "</span></td></tr></table></td>";
        if (i + 1 < json.Network.length) {
            networkTable += "<td width='33%' valign='top' onclick='FillShopDataForShopID(" + json.Network[i + 1].ShopId + ",null)' style='background-color:#f0f0f0;cursor:pointer;'><table><tr><td valign='top'><img src='" + json.Network[i + 1].ShopImage + "' height='60'/></td><td valign='top'><span class='ShopSearchNetworkName'>" + json.Network[i + 1].ShopName + "</span><br><span class='ShopSearchNetworkAddress'>" + json.Network[i + 1].Street + "<br>" + json.Network[i + 1].City + " " + json.Network[i + 1].Postcode + "</span></td></tr></table></td>";
        }
        if (i + 2 < json.Network.length) {
            networkTable += "<td width='34%' valign='top' onclick='FillShopDataForShopID(" + json.Network[i + 2].ShopId + ",null)' style='background-color:#f0f0f0;cursor:pointer;'><table><tr><td valign='top'><img src='" + json.Network[i + 2].ShopImage + "' height='60'/></td><td valign='top'><span class='ShopSearchNetworkName'>" + json.Network[i + 2].ShopName + "</span><br><span class='ShopSearchNetworkAddress'>" + json.Network[i + 2].Street + " " + json.Network[i + 2].City + "<br>" + json.Network[i + 2].Postcode + "</span></td></tr></table></td>";
        }

        networkTable += "</tr>";

    }
    network.append(networkTable);

    var showMode = "table-cell";
    if ($.browser.msie) {
        showMode = "block";
    }

    try {
        if (json.Bovag == 'True') {
            $("#imgBovag").css("display", "block");
        }
        else {
            $("#imgBovag").css("display", "none");
        }

        if (json.ISO == 'True') {
            $("#imgIso").css("display", "block");
        }
        else {
            $("#imgIso").css("display", "none");
        }

        if (json.VACO == 'True') {
            $("#imgVaco").css("display", "block");
        }
        else {
            $("#imgVaco").css("display", "none");
        }
        if (json.KostDat.length > 1) {
            $("#lnkKostDat").css("display", "block");
            $("#lnkKostDat").attr("href", json.KostDat);
        } else {
            $("#lnkKostDat").css("display", "none");
        }

    }
    catch (e) {
        alert(e);
    }
    //Add shopID to shopreviews button.
    var hlShopReviewsPerShop = $("#hlShopReviewsPerShop");
    hlShopReviewsPerShop.attr("href", _siteRoot + "ShopReviews.aspx?shopid=" + json.ShopId);
    shopIdForUsedTyres = json.ShopId;
    $("#usedTyresHomeDiv").empty();
    if (json.HasUsedTyres == 'False') {
        $("#tabshopUsedTyres").css("display", "none");
        $("#tabshopUsedTyresSeparator").css("display", "none");
    }
    else {
        $("#tabshopUsedTyres").css("display", showMode);
        $("#tabshopUsedTyresSeparator").css("display", showMode);
        $get('tabshopUsedTyres').className = 'ShopTab';
    }

    try {
        // comment this to enable
        $("#tabshopOverons").css("display", "none");
        $("#tabshopOveronsSeparator").css("display", "none");

        // uncomment this to enable
        if (json.Details == "") {
            $("#tabshopOverons").css("display", "none");
            $("#tabshopOveronsSeparator").css("display", "none");
        }
        else {
            $tabsShop.tabs('select', 4);
            $("#tabshopOverons").css("display", showMode);
            $("#tabshopOveronsSeparator").css("display", showMode);
            var overons = $('#ShopDetails_Overons');
            overons.empty();
            overons.append(json.Details);

            var detailsButton = $('#ShopDetails_DetailsPage');
            detailsButton.attr("href", _siteRoot + 'displayshopdetailspage.aspx?shopid=' + json.ShopId);
        }
    }
    catch (e) {
        // alert(e);
    }

    try {
        if (json.Network.length <= 1) {
            $("#tabshopKenteken").css("display", "none");
            $("#tabshopNetworkSeparator").css("display", "none");
        }
        else {
            $("#tabshopKenteken").css("display", showMode);
            $("#tabshopNetworkSeparator").css("display", showMode);
        }
        if (json.Foto == "") {
            $("#tabshopFoto").css("display", "none");
            $("#tabshopFotoSeparator").css("display", "none");
        }
        else {
            $("#tabshopFoto").css("display", showMode);
            $("#tabshopFotoSeparator").css("display", showMode);
            var foto = $('#ShopDetails_Foto');
            foto.empty();
            foto.append(json.Foto);
        }
    }
    catch (e) {
        //alert(e);
    }

    //$("#ShopDetails_Directions").attr("href", _siteRoot + "ShopDirections.aspx"/* + SiteProperties.SelectedPostcode*/);
    load(json.Location.Lng, json.Location.Lat);
    $shopLat = json.Location.Lng;
    $shopLng = json.Location.Lat;
    addShop(json.Location.Lng, json.Location.Lat, json.ShopName, json.Street, json.Postcode, '', 'true', 23);
}

function FillShopDetails(_shopId) {
    PageMethods.GetShopById(_shopId, function (result) {
        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var json = eval(q);
                FillShopDetailsFromJSON(json);
            } catch (e) {
                //alert(e);
            }
        }

    });
}

function FillCityFromPostcode(text) {
    PageMethods.GetCityFromPostcode(text, function (result) {
        try {
            var city = $get("ShopSearch_tbCities");
            if (city != null) {
                var cityName = result.split('|')[0];
                if (cityName != "") {
                    city.value = cityName;
                    city.innerText = cityName;
                }
                //SiteProperties.SelectedPostcode = textBox.value;
            }
        }
        catch (e) {
        }
    });

}

function ShopSearch_Collapse() {
    $("#MainShopSearchPanel").slideUp(600);
    try {
        // $("#MainTyreSearchInnerPanel").slideDown(600);
    }
    catch (e) {
        //alert(e);
    }
}


function ShopSearch_Expand() {
    $("#MainShopSearchPanel").slideDown(600, function () {
        try {
            map.checkResize();
            var point = new GLatLng($shopLat, $shopLng);
            map.setCenter(point, 16);
        } catch (e) { }
    });

    try {
        OpenAccordion();
        //$("#MainTyreSearchInnerPanel").slideUp(600, function() {
        //});
    }
    catch (e) {
        //alert(e);
    }
}

function MainSearch_Expand() {
    $("#MainTyreSearchInnerPanel").slideDown(600);
}

function MainSearch_Collapse() {
    $("#MainTyreSearchInnerPanel").slideUp(600);
}

function ShopSearch_Init() {
    // only expand 
    var shopDetails = gup("shopdetails");

    if (shopDetails != "") {
        ShopSearch_Expand();
    }
    else {
        ShopSearch_Collapse();
    }

    if (gup("shopid") != "") {
        OpenAccordion();
    }

    $tabsShop = $("#tabsShop").tabs({ selected: 3, fx: { opacity: 'toggle', duration: 'fast'} });
    $('#tabshopOverons').click(function () { // bind click event to link
        $tabsShop.tabs('select', 4); // switch to third tab
        $get('tabshopOverons').className = 'ShopTabSelected';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        return false;
    });
    $('#tabshopBanden').click(function () { // bind click event to link
        $tabsShop.tabs('select', 3); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTabSelected';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        return false;
    });
    $('#tabshopAuto').click(function () { // bind click event to link
        $tabsShop.tabs('select', 2); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTabSelected';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        return false;
    });
    $('#tabshopKenteken').click(function () { // bind click event to link
        $tabsShop.tabs('select', 1); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTabSelected';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        return false;
    });

    $('#tabshopFoto').click(function () { // bind click event to link
        $tabsShop.tabs('select', 0); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTabSelected';
        return false;
    });


    $('#tabshopTwitter').click(function () { // bind click event to link
        $tabsShop.tabs('select', 5); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTab';
        $get('tabshopTwitter').className = 'ShopTabSelected';
        return false;
    });

    $('#tabshopUsedTyres').click(function () { // bind click event to link
        $tabsShop.tabs('select', 6); // switch to third tab
        $get('tabshopOverons').className = 'ShopTab';
        $get('tabshopBanden').className = 'ShopTab';
        $get('tabshopAuto').className = 'ShopTab';
        $get('tabshopKenteken').className = 'ShopTab';
        $get('tabshopFoto').className = 'ShopTab';
        $get('tabshopTwitter').className = 'ShopTab';
        $get('tabshopUsedTyres').className = 'ShopTabSelected';
        LoadUsedTyresHome();
        return false;
    });
}

function LoadUsedTyresHome() {
    $("#usedTyresHomeDiv").empty().html("<div style='padding-left: 350px; padding-top: 70px'><img src='" + _appTheme + "Images/shopLoader.gif' alt='' /></div>");
    $.get(_siteRoot + "Ajax/GetUsedTyresHome.aspx?shopId=" + shopIdForUsedTyres, function (response) {
        $("#usedTyresHomeDiv").empty().html(response);
    });
}

function InitSite() {
    $(document).ready(function () {
        // setup watermark
        try {
            $('input[type=text], textarea').simpleWaterMark('watermark');
        }
        catch (e) {
        }

        // init news
        try {
            var $news = $('#newsTicker'); //we'll re use it a lot, so better save it to a var.
            $news.vTicker();
        }
        catch (e) {
        }

    });
}

function ToggleCollapsible(panelId, imgId, divId) {
    var s = '#' + panelId;
    var panel = $(s);
    img = $('#' + imgId);
    var div = $('#' + divId);
    if (panel.css("display") != "none") {
        panel.slideUp(500);
        img.attr("src", img.attr("down"));
        div.attr("class", "newRightPanelGray");
    }
    else {
        panel.slideDown(500);
        img.attr("src", img.attr("up"));
        div.attr("class", "newRightPanel");
    }
}

function ToggleMouseOver(panelId, divId) {
    var s = '#' + panelId;
    var panel = $(s);
    var div = img = $('#' + divId);
    if (panel.css("display") == "none") {
        div.attr("class", "newRightPanel");
    }
}

function ToggleMouseOut(panelId, divId) {
    var s = '#' + panelId;
    var panel = $(s);
    var div = img = $('#' + divId);
    if (panel.css("display") == "none") {
        div.attr("class", "newRightPanelGray");
    }
}

function ChangeImage(div) {
    if (div.className.indexOf("_Selected") > 0)
        div.className = div.className.replace("_Selected", "_NotSelected");
    else
        div.className = div.className.replace("_NotSelected", "_Selected");
}

function InitResultTable() {
    try {
        $(".tablesorter").tablesorter({
            // define a custom text extraction function 
            textExtraction: function (node) {
                // extract data from markup and return it
                var s;
                try {
                    var selNode = node.childNodes[0];
                    if (selNode.nodeType == 3) {
                        selNode = node.childNodes[1];
                    }
                    if (selNode == undefined)
                        selNode = node;

                    if (selNode.tagName == "IMG") {
                        s = selNode.attributes["src"].value;
                    }
                    else {
                        if (selNode.tagName == "TABLE") {
                            var tblBody = selNode.childNodes[0];
                            if (tblBody.nodeType == 3)
                                tblBody = selNode.childNodes[1];
                            var tblTr = tblBody.childNodes[0];
                            if (tblTr.nodeType == 3)
                                tblTr = tblBody.childNodes[1];
                            var tblTd = tblTr.childNodes[0];
                            if (tblTd.nodeType == 3)
                                tblTd = tblTr.childNodes[1];
                            var tblAhref = tblTd.childNodes[0];
                            if (tblAhref.nodeType == 3)
                                tblAhref = tblTd.childNodes[1];
                            s = tblAhref.innerHTML
                        }
                        else {
                            s = selNode.innerHTML;
                        }
                    }
                }
                catch (e) {
                    s = node.innerHTML;
                }
                if (s == undefined)
                    s = node.innerHTML;
                return s;
            }
        });
    }
    catch (e) { }
}

function InitResultTableSorter() {
    try {
        $(".tablesorter").tablesorter({
            // define a custom text extraction function 
            textExtraction: function (node) {
                // extract data from markup and return it
                var s;
                try {
                    var selNode = node.childNodes[0];
                    if (selNode.nodeType == 3) {
                        selNode = node.childNodes[1];
                    }
                    if (selNode == undefined)
                        selNode = node;

                    if (selNode.tagName == "IMG") {
                        s = selNode.attributes["src"].value;
                    }
                    else {
                        if (selNode.tagName == "TABLE") {
                            var tblBody = selNode.childNodes[0];
                            if (tblBody.nodeType == 3)
                                tblBody = selNode.childNodes[1];
                            var tblTr = tblBody.childNodes[0];
                            if (tblTr.nodeType == 3)
                                tblTr = tblBody.childNodes[1];
                            var tblTd = tblTr.childNodes[0];
                            if (tblTd.nodeType == 3)
                                tblTd = tblTr.childNodes[1];
                            var tblAhref = tblTd.childNodes[0];
                            if (tblAhref.nodeType == 3)
                                tblAhref = tblTd.childNodes[1];
                            s = tblAhref.innerHTML
                        }
                        else {
                            s = selNode.innerHTML;
                        }
                    }
                }
                catch (e) {
                    s = node.innerHTML;
                }
                if (s == undefined)
                    s = node.innerHTML;
                return s;
            }
        }).tablesorterPager({ container: $("#pager"), size: 5 });
    }
    catch (e) { }
}
function GetShopReviews() {
    //var dropDown = document.getElementById(ddl);
    var params = ""; //"shopid=" + dropDown.value;
    $("#ShopReviewContainer").empty().html("<div style='padding-left: 300px; padding-top: 10px'><img src='" + _appTheme + "Images/shopLoader.gif' alt='' /></div>");
    $.get(_siteRoot + "Ajax/GetShopReviews.aspx?" + params, function (response) {
        $("#ShopReviewContainer").empty().html(response);
        //InitResultTable();
    });
}

function GetShopReviewsByShop(id) {
    $("#ShopReviewContainer").empty().html("<div style='padding-left: 300px; padding-top: 10px'><img src='" + _appTheme + "Images/shopLoader.gif' alt='' /></div>");
    $.get(_siteRoot + "Ajax/GetShopReviews.aspx?shopid=" + id, function (response) {
        $("#ShopReviewContainer").empty().html(response);
        //InitResultTable();
    });
}


function ShowPopUpOffer(x) {
    $("#popUpWinterOffer").overlay({
        top: 260,
        speed: 0,
        closeSpeed: 0,
        onClose: function () {
            var bac = x;
            PageMethods.AddTireToSC(bac, 1, function (result) {
                if (location.href.indexOf("IFrameTyreResults.aspx") != -1) {
                    document.location = _siteRoot + "/IFrameShoppingcart.aspx";
                }
                else {
                    document.location = _siteRoot + "/Shoppingcart.aspx";
                }
            });
        },
        closeOnClick: false,
        load: false
    });
    $("#popUpWinterOffer").overlay().load();
}

function ShowPopUpKopen(x) {
    $("#popUpWinterKopen").overlay({
        top: 260,
        closeSpeed: 0,
        speed: 0,
        //        onClose: function() {
        //            var bac = x;
        //            PageMethods.AddTireToSC(bac, 1, function(result) {
        //                if (location.href.indexOf("IFrameTyreResults.aspx") != -1) {
        //                    document.location = _siteRoot + "/IFrameShoppingcart.aspx";
        //                }
        //                else {
        //                    document.location = _siteRoot + "/Shoppingcart.aspx";
        //                }
        //            });
        //        },
        closeOnClick: false,
        load: false
    });
    $("#popUpWinterKopen").overlay().load();
}

function TeamCBChange(val, idMan, idVrouw, idHf) {
    var imgMan = document.getElementById(idMan);
    var imgVrouw = document.getElementById(idVrouw);
    var hfGender = document.getElementById(idHf);
    if (val == 1) {
        imgMan.src = _appTheme + "images/team/cbTeamUnchecked.jpg";
        imgVrouw.src = _appTheme + "images/team/cbTeamChecked.jpg";
        hfGender.value = 1;
    }
    else {
        imgMan.src = _appTheme + "images/team/cbTeamChecked.jpg";
        imgVrouw.src = _appTheme + "images/team/cbTeamUnchecked.jpg";
        hfGender.value = 2;
    }

}

//COUNT DOWN
var totalSeconds = 0;
var cdInterval;
function CountDownPS(ts) {
    var txtCDDays = document.getElementById("txtCDDays");
    var txtCDHours = document.getElementById("txtCDHours");
    var txtCDMinutes = document.getElementById("txtCDMinutes");
    var txtCDSeconds = document.getElementById("txtCDSeconds");
    totalSeconds = ts;
    if (totalSeconds > 0) {
        txtCDDays.innerHTML = calcage(totalSeconds, 86400, 100000);
        txtCDHours.innerHTML = calcage(totalSeconds, 3600, 24);
        txtCDMinutes.innerHTML = calcage(totalSeconds, 60, 60);
        txtCDSeconds.innerHTML = calcage(totalSeconds, 1, 60);
        cdInterval = setInterval("DoCountDown()", 1000);
    }
    else {
        txtCDDays.innerHTML = "00";
        txtCDHours.innerHTML = "00";
        txtCDMinutes.innerHTML = "00";
        txtCDSeconds.innerHTML = "00";
    }
}

function DoCountDown() {
    var txtCDDays = document.getElementById("txtCDDays");
    var txtCDHours = document.getElementById("txtCDHours");
    var txtCDMinutes = document.getElementById("txtCDMinutes");
    var txtCDSeconds = document.getElementById("txtCDSeconds");
    totalSeconds = totalSeconds * 1 - 1;
    if (totalSeconds > 0) {
        txtCDDays.innerHTML = calcage(totalSeconds, 86400, 100000);
        txtCDHours.innerHTML = calcage(totalSeconds, 3600, 24);
        txtCDMinutes.innerHTML = calcage(totalSeconds, 60, 60);
        txtCDSeconds.innerHTML = calcage(totalSeconds, 1, 60);
    }
    else {
        txtCDDays.innerHTML = "00";
        txtCDHours.innerHTML = "00";
        txtCDMinutes.innerHTML = "00";
        txtCDSeconds.innerHTML = "00";
        clearInterval(cdInterval);
    }
}

function calcage(secs, num1, num2) {
    s = ((Math.floor(secs / num1)) % num2).toString();
    if (s.length < 2)
        s = "0" + s;
    return s;
}
function LoadTeslaForm() {
    var div = $('#divTeslaRegister');

    div.overlay({

        mask: {
            color: '#505050',
            loadSpeed: 200,
            opacity: 0.9
        },

        closeOnClick: true,
        fixed: false,
        oneInstance: false
    });
    div.overlay().load();
}
function CloseTesla() {
    var div = $('#divTeslaRegister');
    div.overlay().close();

}
