﻿var Maps = {};

Maps.map = null;
Maps.directionsService = null;
Maps.directionsDisplay = null;

Maps.Init = function () {
    Maps.directionsDisplay = new google.maps.DirectionsRenderer();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 20,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    Maps.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    Maps.directionsDisplay.setMap(Maps.map);
    if (document.getElementById("directionsPanel") != null) {
        Maps.directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    }
}

Maps.AddShop = function (lng, lat) {
    if (Maps.map == null) {
        Maps.Init();
    }

    var loc = new google.maps.LatLng(lat, lng);
    Maps.map.center = loc;
    Maps.map.zoom = 15;

    var iconPT = _appTheme + "/Images/Shop/PTCBaloon.png";

    marker = new google.maps.Marker({
        map: Maps.map,
        icon: iconPT,
        draggable: false,
        animation: google.maps.Animation.DROP,
        position: loc
    });
    google.maps.event.addListener(marker, 'click', toggleBounce);
}

Maps.AddShopForMap = function (lng, lat, shopName, shopOwner, shopCity, shopAdress, shopHouseNumber, ShopPostcode, shopID, shopTel, shopImage, provinceId) {
    if (Maps.map == null) {
        Maps.Init();
    }
  
    var loc = new google.maps.LatLng(lat, lng);
    Maps.map.center = loc;
    if (provinceId == '0') {
        Maps.map.zoom = 7;
    } else {
        Maps.map.zoom =9;      
    }

    var iconPT = _appTheme + "/Images/Shop/PTCBaloon.png";

    var beginTable = '<table cellpadding="3" cellspacing="0" border="0">';
    var endTable = '</table>';
    var beginTd = '<td valing="top">';
    var endTd = '</td>';
    var beginTr = '<tr>';
    var endTr = '</tr>';
    var finalTable = '';

    finalTable += beginTable + beginTr + beginTd;

    var img = "<img alt=" + shopName + " src='" + shopImage + "' width='90px' border='0' />";

    finalTable += img;
    finalTable += endTd;

    finalTable += beginTd + "<span class='jamesBlueColor1 bold'>JAMES " + shopName + "</span><br />" + shopOwner + "<br />" + shopAdress + " " + shopHouseNumber + "<br />" + ShopPostcode + " " + shopCity + "<br />" + "Tel: " + shopTel + "<br />" + "<a class='jamesBlueColor1 small' href='DisplayShop.aspx?shopID=" + shopID + "';'>Meer informatie</a>" + endTd + endTr + endTable;

    var infowindow = new google.maps.InfoWindow({
        content: finalTable
    });

    var marker = new google.maps.Marker({
        map: Maps.map,
        icon: iconPT,
        draggable: false,
        animation: google.maps.Animation.DROP,
        position: loc
    });

    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(Maps.map, marker);
    });
}

Maps.CalculateDistance = function (startLat, startLng, endLat, endLng) {
    Maps.directionsService = new google.maps.DirectionsService();
    var start = new google.maps.LatLng(startLng, startLat);
    var end = new google.maps.LatLng(endLng, endLat);
    var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    Maps.directionsService.route(request, function (response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            Maps.directionsDisplay.setDirections(response);
        }
    });
}

function toggleBounce() {

    if (marker.getAnimation() != null) {
        marker.setAnimation(null);
    } else {
        marker.setAnimation(google.maps.Animation.BOUNCE);
    }
}

$(document).ready(function () {
    /*
    HEADER EVENTS */

    $('#btnSearchTop').click(function () {
        var text = $('#txtSeach').val();
        document.location = 'SearchResults.aspx?query=' + text;
    });

    $('#txtSeach').keyup(function (event) {
        if (event.keyCode == 13) {
            var text = $('#txtSeach').val();
            document.location = 'SearchResults.aspx?query=' + text;
        }
    });

    $('#txtPostcode').keyup(function (event) {
        if (event.keyCode == 13) {
            DoWork2();
        }
    });

    /*
    END */
});

var Application = {}

Application.Init = function () {
    Navigation.CreateSubMenuDiv();
    setInterval(Application.KeepSessionAlive, 2 * 60 * 1000);
    if (_siteRoot.toLowerCase().indexOf("onlineplanning/") < 0) {
        OPTimer.ResetTimer();
    }
}

Application.KeepSessionAlive = function () {
    $.post(_siteRoot + "KeepAlive.ashx", null, function () { });
}

Application.LoadShopsInMemry = function () {
    $.get(_siteRoot + 'Ajax/Shops/ShopsHandler.ashx');
}

//
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);
}

//

var Navigation = {}

Navigation.ReturnHome = function () {
    document.location = 'Default.aspx';
}


/* 
Menu Related */

Navigation.MakeSubMenuAjax = function (text, ctrl, altText, offsetX, offsetY) {

    var data = $(text).html();
    if (data != null) {
        Tip(data, FIX, [ctrl, offsetX, offsetY], ABOVE, false, DELAY, 0, FADEIN, 0, FADEOUT, 0, STICKY, true, COPYCONTENT, true, CLICKCLOSE, true, BORDERWIDTH, 0, BGCOLOR, '', OPACITY, 85, PADDING, 0);
    }
}

Navigation.CreateSubMenuDiv = function () {
    var s = _siteRoot + 'Ajax/SubMenu.aspx';
    $.get(s, function (data) {
        var q = $('#menuSubContainer');
        //alert(data);
        q.empty();
        q.html(data);
    });
}

/*
END */

var ShopOcc = {}

ShopOcc.Occ = false;

/*
Top Shop Search */
var Shops = {}

Shops.selectedShop = 0;
Shops.linkFromCity = '';
Shops.linkFromPostCode = '';
Shops.linkIsOk = false;

Shops.SetSelectedShop = function (shopID) {
    Shops.selectedShop = shopID;
}

Shops.SearchShop = function () {
    var d = new Date();
    var textBox = $('#txtPostcode');
    var letters = $('#txtPostcode').val().length;
    if (letters < 6) {
        $('#imgTextBox').css("display", "block");
        $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/x.jpg");
    }
    else {
        if (letters == 6) {
            $('#imgTextBox').css("display", "block");
            $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/loading.gif");
            $.get(_siteRoot + 'Ajax/Utils.aspx?method=ShopExists&postcode=' + textBox.val() + '&_=' + d.getTime(), function (data) {
                if (data != null) {
                    try {
                        var q = "(" + data + ")";
                        var json = eval(q);
                        if (json != "") {
                            Shops.linkFromPostCode = 'DisplayShop.aspx?shopID=' + json;
                            $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/ok.png");
                        }
                        else {
                            $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/x.jpg");
                        }
                        //alert(Shops.linkFromCity);
                    }
                    catch (ex) {
                    }
                }
                else {
                    $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/x.jpg");
                }
            });
        }
        else if (letters > 6) {
            $('#imgTextBox').attr("src", _siteRoot + "Styles/Images/RightSide/x.jpg");
        }
    }

}

function DoWork() {
    var ddList = $("[id$='_ddlCities'] :selected").val();
    var searchPostcode = false;

    //alert(Shops.linkFromCity);

    //document.location = Shops.linkFromCity;

    if (ddList != "Selecteer plaats") {
        document.location = _siteRoot + Shops.linkFromCity;
    }
}

function DoWork2() {
    var textBox = $('#txtPostcode').val();
    
    if (textBox != "" && textBox != 'Postcode') {
        if (Shops.linkFromPostCode != "") {
            document.location = _siteRoot + Shops.linkFromPostCode;
        }
        else {

        }

    }
}

Shops.SearchShopByCity = function () {
    var ddList = $("[id$='_ddlCities'] :selected").val();

    $.get(_siteRoot + 'Ajax/Utils.aspx?method=GetNumberOfShopsByCity&citysearch=' + ddList, function (data) {
        if (data != null) {
            try {
                var q = "(" + data + ")";
                var json = eval(q);
                if (json.values == "1") {
                    Shops.linkFromCity = 'DisplayShop.aspx?shopID=' + json.shopID;
                }
                else {
                    Shops.linkFromCity = 'DisplayShops.aspx';
                }
            }
            catch (ex) {
            }

        }
    });
}

Shops.GoToShopMap = function () {
    if (Shops.linkIsOk) {
        $('#tdError').css("display", "none");
        document.location = 'ShopDirections.aspx?shopID=' + Shops.selectedShop;
    }
    else {
        $('#tdError').css("display", "block");
    }
}

/*
END */

/*
CARS */

var Cars = {};

Cars.UwAuto = false;

Cars.SetUwAuto = function (value) {
    Cars.UwAuto = value;
}

/*
END */


/*
APK  */
function PopulateFieldsAPK(json) {
    if (json != undefined) {
        try {
            var carName;
            if (json.CarBrand != null && json.CarModel != null && json.CarEngine != null && json.CarYear != null) {
                carName = json.CarBrand + ' ' + json.CarModel + ' ' + json.CarEngine + ' ' + json.CarYear;
                $('#CarDetails').text(carName);
            }
            else {
                $('#CarDetails').text("");
            }

            var carApk;
            if (json.ApkDate != null) {
                carApk = "<span class='nobold normal'>Uw APK vervaldatum is: <span><span class='big nobold black'>" + json.ApkDate + "</span>";
                $('#ApkDate').html(carApk);
                $('#linkAuto').css("display", "block");
            }
            else {
                carApk = "<span class='nobold normal'>U heeft geen geldig kenteken ingevoerd<span>"
                $('#ApkDate').html(carApk);
            }
            var image;
            if (json.CarImage != null) {
                image = json.CarImage;
                $('#imgCar').attr("src", image);
                $('#imgCar').css("display", "block");
            }
            else {
                $('#imgCar').css("display", "none");
            }




        }
        catch (ex) {
        }
    }
}

/*
END */

/*
Money Back  */

function HideFunction2() {
    $('#trFacNumber').css("display", "none");
    $('#trInvNumber').css("display", "none");
    $('#trInvoiceDate').css("display", "none");

    //    ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], false);
    //    ValidatorEnable($("[id$='_CustomValidator9']")[0], false);
    //    ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], false);
    //    ValidatorEnable($("[id$='_RequiredFieldValidator5']")[0], false);
    //    ValidatorEnable($("[id$='_CustomValidator5']")[0], false);

    $.getJSON(_siteRoot + '/Ajax/ShopSearch.aspx?loadShops=alle', function (json) {
        if (json != null) {
            $("[id$='_ddlShops']").empty();
            $("[id$='_ddlShops']").append("<option value='" + 0 + "'> Selecteer een vestiging</option>");
            for (var i = 0; i < json.length; i++) {
                $("[id$='_ddlShops']").append("<option value='" + json[i].shopID + "'>" + json[i].shopName + "</option>");
            }

        }
    });

}

function HideFunction1() {
    $('#trFacNumber').css("display", "block");
    $('#trInvNumber').css("display", "block");
    $('#trInvoiceDate').css("display", "block");

    $.getJSON(_siteRoot + '/Ajax/ShopSearch.aspx?loadShops=29', function (json) {
        if (json != null) {
            $("[id$='_ddlShops']").empty();
            $("[id$='_ddlShops']").append("<option value='" + 0 + "'> Selecteer een vestiging</option>");
            for (var i = 0; i < json.length; i++) {
                $("[id$='_ddlShops']").append("<option value='" + json[i].shopID + "'>" + json[i].shopName + "</option>");
            }

        }
    });

    //    ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], true);
    //    ValidatorEnable($("[id$='_CustomValidator9']")[0], true);
    //    ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], true);
    //    ValidatorEnable($("[id$='_RequiredFieldValidator5']")[0], true);
    //    ValidatorEnable($("[id$='_CustomValidator5']")[0], true);
}

/*
END */

/*
Utils   */
function checkZip() {
    var letters = $("[id$='_txtZipcode2']").val().length;
    if (letters != 6) {
        $("[id$='_txtZipcode2']").focus();
    }
    else {
        $.getJSON(_siteRoot + '/Ajax/Utils.aspx?method=GetCityForPostalCode&postcode=' + $("[id$='_txtZipcode2']").val(), function (result) {
            if (result != "null") {
                $("[id$='_txtCity']").val(result.City);
                $("[id$='_txtAddress']").val(result.Street);
            }
        });
    }
}

function DefaultShopSearch() {
    var d = new Date();
    var textBox = $('#txtPostcode2');
    var letters = $('#txtPostcode2').val().length;
    if (letters == 6) {
        $('#imgTextBox2').css("display", "block");
        $('#imgTextBox2').attr("src", "Styles/Images/RightSide/loading.gif");
        $.get('Ajax/Utils.aspx?method=ShopExists&postcode=' + textBox.val() + '&_=' + d.getTime(), function (data) {
            if (data != null) {
                try {
                    var q = "(" + data + ")";
                    var json = eval(q);
                    if (json != "") {
                        Shops.linkIsOk = true;
                        Shops.linkFromCity = 'DisplayShop.aspx?shopID=' + json;
                        $('#imgTextBox2').attr("src", "Styles/Images/RightSide/ok.png");
                    }
                    else {
                        Shops.linkIsOk = false;
                        $('#imgTextBox2').attr("src", "Styles/Images/RightSide/x.jpg");
                    }
                    //alert(Shops.linkFromCity);
                }
                catch (ex) {
                    Shops.linkIsOk = false;
                }
            }
            else {
                Shops.linkIsOk = false;
                $('#imgTextBox2').attr("src", "Styles/Images/RightSide/x.jpg");
            }
        });
    }
    else {
        Shops.linkIsOk = false;
        $('#imgTextBox2').attr("src", "Styles/Images/RightSide/x.jpg");
    }
}

/*
END */

/*
Badges  */

function DisplayDefault() {
    $('#BadgeDefault').css("display", "block");
    $('#BadgeContent').css("display", "none");
}

function DisplayContent1() {
    $('#BadgeDefault').css("display", "none");
    $('#BadgeContent').css("display", "block");
}

function DisplayContent2() {
    $('#BadgeDefault').css("display", "none");
    $('#BadgeContent').css("display", "none");
}



/*
END */

/*
Licence Plate   */

function checkLicence(txtLicence) {
    var text1 = txtLicence;
    var textBox = text1;
    var letters = textBox.value.length + 1;
    var text;
    var start;
    if (letters <= 8) {
        if (letters >= 3) {
            text = textBox.value;
            for (start = 3; start <= letters; start = start + 1) {
                if (textBox.value.charAt(start - 2) != '-') {
                    if (((isNaN((textBox.value.charAt(start - 2)))) && (!isNaN(textBox.value.charAt(start - 3))) && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))
                            || ((!isNaN((textBox.value.charAt(start - 2)))) && (isNaN(textBox.value.charAt(start - 3))) && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))) {
                        text = textBox.value;
                        textBox.value = text.substring(0, start - 2) + "-" + text.substring(start - 2);
                        text = textBox.value;
                        textBox.focus();
                    }
                    if (((isNaN(textBox.value.charAt(start - 2))) && (isNaN(textBox.value.charAt(start - 3))) && (isNaN(textBox.value.charAt(start - 4))) && (isNaN(textBox.value.charAt(start - 5))) && (textBox.value.charAt(start - 5) != '-') && (textBox.value.charAt(start - 4) != '-') && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))
                                || ((!isNaN(textBox.value.charAt(start - 2))) && (!isNaN(textBox.value.charAt(start - 3))) && (!isNaN(textBox.value.charAt(start - 4))) && (!isNaN(textBox.value.charAt(start - 5))) && (textBox.value.charAt(start - 5) != '-') && (textBox.value.charAt(start - 4) != '-') && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-') && (textBox.value.charAt(start - 4) != '') && (textBox.value.charAt(start - 5) != ''))) {
                        textBox.value = text.substring(0, start - 3) + "-" + text.substring(start - 3);
                        textBox.focus();
                    }
                }
            }
        }
        else
            textBox.focus();
    }
    else {
        if (IsLicenceValid()) {
            textBox.value.length = 8;
        }
    }
}

function ValidateLicence(obj, args) {
    //var text1 = "<%=txtLicense1.ClientID %>";

    //var licence1 = document.getElementById(text1).value;
    var licence1 = $("[id$='_txtLicense1']").val();
    var licenceJustNumbers = replace(replace(licence1, '-', ''), '-', '');

    if (licence1 == null) {
        args.IsValid = false;
        return false;
    }
    if ((licence1.length == 8) && (licenceJustNumbers.length == 6)) {
        args.IsValid = true;
        return true;
    }
    else {
        args.IsValid = false;
        return false;
    }
}

function replace(string, text, by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0, txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0, i) + by;

    if (i + txtLength < strLength)
        newstr += replace(string.substring(i + txtLength, strLength), text, by);

    return newstr;
}

function IsLicenceValid() {
    var licence1 = $("[id$='_txtLicense1']").val();
    var licenceJustNumbers = replace(replace(licence1, '-', ''), '-', '');

    if (licence1 == null) {
        return false;
    }

    if ((licence1.length == 8) && (licenceJustNumbers.length == 6)) {
        return true;
    }
    else {
        return false;
    }
}

/*
END */

/* 
TWETTER     */

function GetTwitter(divul) {
    var resultAchter = $("[id$='_twitterResults']");
    $.get("Ajax/GetTwitter.aspx?mode=default&div=" + divul, function (fakeNewsJson) {
        if (fakeNewsJson != null && fakeNewsJson != "null") {
            resultAchter.html(fakeNewsJson);
            alert(fakeNewsJson);
        }
    });
}

function LoadTwitter() {
    //    $("#twitter").css("display", "block");
    //    $("#twitter").getTwitter({
    //        userName: "jamesauto_nl",
    //        numTweets: 1,
    //        loaderText: "Loading tweets...",
    //        slideIn: true,
    //        showHeading: false,
    //        //headingText: "Laatste tweets",
    //        showProfileLink: true
    //    });
    $.getJSON("http://api.twitter.com/1/statuses/user_timeline/jamesauto_nl.json?count=2&callback=?", function (json) {
        if (json != null) {
            $("#twitter").css("display", "block");
            $("#lblContent").html(json[0].text);
            $.getJSON("Ajax/GetTwitter.aspx?date=" + json[0].created_at, function (data) {
                if (data != null) {
                    $("#lblDate").html(data.Date);
                }

                else {
                    $("#lblDate").html(json[0].created_at.replace('+0000 ', ''));
                }
            });
        }
    });
}


function FillTwitter(branduser) {
    var link = "http://api.twitter.com/1/statuses/user_timeline/" + branduser + ".json?count=2&callback=?";
    var final = '';
    try {
        $.getJSON(link, function (json) {

            var table = "<table cellspacing=\"0\" cellpadding=\"2\"  width=\"100%\">";
            var trtd = "";
            var i = 0;
            final += table;
            var textToAdd;
            if (json[0].text.length > 40)
                textToAdd = json[0].text.substring(0, 40) + "...";
            else
                textToAdd = json[0].text;
            var trtd = "<tr><td  style=\"padding-top: 5px;\">" + "<span class=\"small\">" + textToAdd + "</span></td></tr>";
            var newTd = '';

            $.getJSON("Ajax/TwitterUtils.aspx?date=" + json[0].created_at + "&text1=" + textToAdd.replace('#', ''), function (data) {

                if (data != null) {
                    newTd = "<tr> <td>" + "<span class=\"small\" style=\"color: #aaaaaa\">" + data.Date + "</span></td></tr>";

                    final = final + trtd + newTd;
                    var textToAdd2;
                    if (json[1].text.length > 40)
                        textToAdd2 = json[1].text.substring(0, 40) + "...";
                    else
                        textToAdd2 = json[1].text;

                    trtd = "<tr><td>" + "<span class=\"small\">" + textToAdd2 + "</span></td></tr>";
                    newTd = '';

                    $.getJSON("Ajax/TwitterUtils.aspx?date=" + json[1].created_at + "&text2=" + textToAdd2.replace('#', ''), function (data) {
                        if (data != null) {
                            newTd = "<tr><td>" + "<span class=\"small\" style=\"color: #aaaaaa\">" + data.Date + "</span></td></tr>";


                            final = final + trtd + newTd;
                            //  var link = "<tr><td align=\"right\" ><a class=\"text\"  href=\"http://twitter.com/" + branduser + "\" style=\"cursor:pointer;color: #5F5F5F; text-align: right; text-decoration: underline; font-style: italic; padding-right: 5px;\" target=\"_blank\"><i>Alle tweets</i></a></td></tr>";
                            //  final = final + link + "</table>";
                            final = final + "</table>";

                            $("[id$='_divTwitter']").html(final);

                            // $.getJSON("Ajax/TwitterUtils.aspx?tweet=true", function (data) {

                            // });
                        }
                    });
                }
            });

            if (json.length == 0) {
                $("[id$='_divTwitter']").html("<span class=\"text\">" + branduser + " hasn't tweeted yet</span>");
            }
        });
    }
    catch (exception) {

    }

}

/*
END */

function makeOnlinePlanning() {
    var txtLicense1 = $("[id$='_txtLicense1']");
    var txtError = $("[id$='_lblError']");
    if (txtLicense1.val() == "") {
        // ValidatorEnable($("[id$='_RequiredLicencePlate']")[0], true);
        // return false;
        txtError.css("display", "block");

    }
    else {
        txtError.css("display", "none");
        // ValidatorEnable($("[id$='_RequiredLicencePlate']")[0], false); */
        if ($("[id$='_chkPrivate']").is(':checked'))
            document.location = _siteRoot + 'OnlinePlanning/OnlinePlanning.aspx?service=onderhoud&userTypeId=1';
        else
            document.location = _siteRoot + 'OnlinePlanning/OnlinePlanning.aspx?service=onderhoud';
    }
}

function GoToOccasions() {
    $('#Contact').css("display", "none");
    $('#Overons').css("display", "none");
    $('#Services').css("display", "none");
    $('#Diensten').css("display", "none");
    $('#Occassions').fadeIn(800);

    $('#TCL').attr("class", "HoverLeft");
    $('#TCM').attr("class", "HoverMiddle");
    $('#TCR').attr("class", "HoverRight");

    $('#TOL').attr("class", "HoverLeft");
    $('#TOM').attr("class", "HoverMiddle");
    $('#TOR').attr("class", "HoverRight");

    $('#TSL').attr("class", "HoverLeft");
    $('#TSM').attr("class", "HoverMiddle");
    $('#TSR').attr("class", "HoverRight");

    $('#TDL').attr("class", "HoverLeft");
    $('#TDM').attr("class", "HoverMiddle");
    $('#TDR').attr("class", "HoverRight");

    $('#TOCL').attr("class", "noHoverLeft");
    $('#TOCM').attr("class", "noHoverMiddle");
    $('#TOCR').attr("class", "noHoverRight");

    if (ShowOcc.Occ == true) {
        $("[id$='_trAction']").css("display", "none");
        $("[id$='_trAutooz']").css("display", "none");
        $("[id$='_trAutoozCar']").css("display", "none");

        $("[id$='_trAction']").css("position", "absolute");
        $("[id$='_trAutooz']").css("position", "absolute");
    }
    else {
        $("[id$='_trAction']").css("display", "block");
        $("[id$='_trAutooz']").css("display", "block");
        $("[id$='_trAutoozCar']").css("display", "block");

        $("[id$='_trAction']").css("position", "static");
        $("[id$='_trAutoozCar']").css("position", "static");
    }

    return false;
}


function ShowCalendar() {
    
    $("[id$='_txtInvoiceDate']").datepicker({
        showOn: "button",
        dateFormat: 'yy-mm-dd',
        buttonImage: "Styles/Images/datepicker.jpg",
        buttonImageOnly: true
    });
}

var Validatop = {};

/*
CAPCHA CONTROL  */

//var RecaptchaOptions = {
//    theme : 'clean',
//    language : nl
// };

/*
END */

function CheckValidation() {
    if ($("[id$='_chkAgrement : checked']").is(':checked')) {
        return true;
    }
    else {
        $('#spanError').css("display", "block");
        return false;
    }
}

function GoToBottom() {

    var height = document.body.clientHeight;
    window.scrollTo(0, height);

}


function CheckFactuurStap1() {
    CheckFactuurStuff();
}

function CheckFactuurStuff() {
    var i = 0;
    if ($('#trFacNumber').is(':visible')) {
        if ($("[id$='_txtInvoiceNumber']").val() != "") {
            $('#span1').css("display", "none");
        }
        else {
            $('#span1').css("display", "block");
            i++;
        }
        if ($("[id$='_txtInvoiceAmount']").val() != "") {
            $('#span2').css("display", "none");
        }
        else {
            $('#span2').css("display", "block");
            i++;
        }
        if ($("[id$='_txtInvoiceDate']").val() != "") {
            $('#span3').css("display", "none");
        }
        else {
            $('#span3').css("display", "block");
            i++;
        }
        if ($("[id$='_chkTerms']").is(':checked')) {
            $('#spanError').css("display", "none");
        }
        else {
            $('#spanError').css("display", "block");
            i++;
        }
    }
    else {
        if ($("[id$='_chkTerms']").is(':checked')) {
            $('#spanError').css("display", "none");
        }
        else {
            $('#spanError').css("display", "block");
            i++;
        }
    }

    if (i > 0)
        return false;
    else
        return true;
}

function CheckNewsLetter() {
    if ($("[id$='_chkTerms : checked']").is(':checked')) {
        return true;
    }
    else {
        $('#spanErr').css("display", "block");
        return false;
    }
}

function LoadUwAuto(value) {

    $('#imgUwAuto').css("display", "block");

    $.getJSON(_siteRoot + 'Ajax/Car/GetCarDetails.aspx?licence=' + value, function (data) {
        if (data != null) {
            if (data.error == "False") {
                //$('#tdCarPerformace').html(data.carImages);
                $('#tdCarDetails').html(data.carDetails + data.carPerformace);
            }
            else {
                $('#tdCarDetails').html("");
            }
        }
    });

    $.getJSON(_siteRoot + 'Ajax/Car/GetCarImage.aspx?licence=' + value, function (data) {
        if (data != null) {
            if (data.error == "False") {
                $('#tdCarName').html(data.carName);
                $('#tdCarPerformace').html(data.carImages);
                $('#tdTyres').html("Uw bandenmaat: " + data.carTyre);
            }
            else {
                $('#tdCarName').html("U heeft geen geldig kenteken ingevoerd");
                $('#tdCarPerformace').html("");
                $('#tdTyres').html("");
            }
        }
    });

    $('#imgUwAuto').css("display", "none");
}

ShoppingCart = {};

ShoppingCart.ShopName = '';
ShoppingCart.ShopAdress = '';
ShoppingCart.ShopTel = '';
ShoppingCart.ShopEmail = '';
ShoppingCart.ShopDistance = '';

ShoppingCart.GetShopsByCity = function () {
    $('#divSearchShop').css("display", "none");
    $('#divLoader').css("display", "block");
    $.getJSON(_siteRoot + '/Ajax/ShoppingCart/ShoppingCartWork.aspx?mode=city&city=' + $("[id$='ddlCitiesPlaats'] :selected").val(), function (data) {
        if (data.Content != null) {
            $('#divLoader').css("display", "none");
            $('#divShopResults').empty();
            $('#divShopResults').html(data.Content);
        }
    });
}

ShoppingCart.GetShopsByPostcode = function () {
    $('#divSearchShop').css("display", "none");
    $('#divLoader').css("display", "block");
    $.getJSON(_siteRoot + '/Ajax/ShoppingCart/ShoppingCartWork.aspx?mode=postcode&postcode=' + $("[id$='_txtPostcodeAdvanced']").val(), function (data) {
        if (data.Content != null) {
            $('#divLoader').css("display", "none");
            $('#divShopResults').empty();
            $('#divShopResults').html(data.Content);
        }
    });
}

ShoppingCart.SetPrefferedShop = function (shopID) {
    $.get(_siteRoot + '/Ajax/ShoppingCart/ShoppingCartWork.aspx?mode=favourite&shopID=' + shopID, function (data) {
        if (data != null) {
            ShoppingCart.ShopName = data.ShopName;
            ShoppingCart.ShopAdress = data.ShopAdress;
            ShoppingCart.ShopTel = data.ShopTel;
            ShoppingCart.ShopEmail = data.ShopEmail;
            ShoppingCart.ShopDistance = data.ShopDistance;

            document.location = 'ShoppingCart/Default.aspx';

            //            $("#divChangeShop").overlay().onclose(function (event) {
            //                alert(ShoppingCart.ShopName);

            //                $("[id$='_lblShopName']").val(ShoppingCart.ShopName);
            //                $("[id$='_lblShopAdress']").val(ShoppingCart.ShopAdress);
            //                $("[id$='_lblShopTel']").val(ShoppingCart.ShopTel);
            //                $("[id$='_lblShopEmail']").val(ShoppingCart.ShopEmail);
            //                $("[id$='_lblShopDistance']").val(ShoppingCart.ShopDistance);
            //            });
        }
    });
}
