﻿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);
}
//


// 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 GetPageUrl() {
    var url = window.location.href;
//    if (url.indexOf("?") > -1) {
//        var s = url.split("?")[0];
//        return s;
//    }
    return url;
}

function resetDDLIndex() {
    var text1 = $("[id$='_lblServiceId']").val();
    $("[id$='_ddlLeasing']").val(text1);
}

function makeAlertLeasePlan() {
    if (window.confirm('Voor onderhoud / reparatie kunt u uw afspraak in plannen op de LeasePlan AfspraakPlanner. Klik op OK voor de LeasePlan AfspraakPlanner')) {
        var load = window.open('http://www.leaseplan.nl/afspraakplanner/index.asp', '', '');
    }
    else {
        $("[id$='_rdoButtonBanden']").attr("checked",true);
        $("[id$='_imgBanden']").attr("src", "App_Themes/Default/Images/OnlinePlanning/Banden_shadow.png");
        $("[id$='_imgReparatie']").attr("src", "App_Themes/Default/Images/OnlinePlanning/Reparatie.png");
        $("[id$='_imgOnderhoud']").attr("src", "App_Themes/Default/Images/OnlinePlanning/Onderhoud.png");
    }
}

function makeAlertOnlinePlanning() {
    var lblServiceId = $("[id$='_lblServiceId']");
    //alert(lblServiceId.val() + " " + $("[id$='_ddlLeasing']").val());
    if (lblServiceId.val() != $("[id$='_ddlLeasing']").val()) {
        if (window.confirm('U kiest nu een andere leasemaatschappij dan in ons systeem gekoppeld staat aan uw kenteken.')) {
            $("#divCheckBoxes").html('<div style="width:188px;"><img src=\'<%=AppTheme()%>/Images/LicencePlate/ajax-loader.gif\' style="padding-left:85px;padding-top:30px;"/></div>');
            lblServiceId.val($("[id$='_ddlLeasing']").val());
            if ($("[id$='_ddlLeasing']").val() == 99999) {
                $("[id$='_trOtherLeasing']").css("display", "block");
                ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], true);
            }
            else {
                $("[id$='_trOtherLeasing']").css("display", "none");
                ValidatorEnable($("[id$='_RequiredFieldValidator1']")[0], false);
            }
            CreateServicesLeasing($("[id$='_ddlLeasing']").val());
        }
        else {
            resetDDLIndex();
        }
    }
}

function verifyOnlinePlanning() {
    var d = new Date();
    $.get('Ajax/GetLeasingCompany.aspx?LeaseID=' + $("[id$='_ddlLeasing']").val() + '&_=' + d.getTime(), function(result) {
        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var json = eval(q);
                if (json.text) {
                    CreateServicesLeasing($("[id$='_ddlLeasing']").val());
                }
                else
                    if (json.showMessage)
                        CreateServicesLeasing($("[id$='_ddlLeasing']").val());
                    else
                        makeAlertOnlinePlanning();

            } catch (e) {
                //alert(e);
            }
        }
    });
}


//function CreateServicesLeasing(leaseId) {
//    var d = new Date();
//    var service = '';
//    if ($("[id$='_rdoButtonReparatie']").is(':checked'))
//        service = "Reparatie";
//    else
//        if ($("[id$='_rdoButtonOnderhoud']").is(':checked')) {
//        service = "Onderhoud";
//    }
//    else
//        if ($("[id$='_rdoButtonBanden']").is(':checked')) {
//        service = "Banden";
//    }
//    else {
//        service = "Banden";
//    }
//    $("[id$='_ddlLeasing']").val(leaseId);
//    $("#containerServiceCategory").html('<div style="width:188px;"><img src="App_Themes/Default/Images/LicencePlate/ajax-loader.gif" style="padding-left:340px;padding-top:30px;"/></div>');
//    if (leaseId == 30144)
//        service = "Banden";
//    $.get('Ajax/GetServicesForLeasingStep1.aspx?LeaseID=' + leaseId + "&service=" + service + '&_=' + d.getTime(), function(json) {
//        var $Content = $(json);
//        $("#__VIEWSTATE", $Content).remove();
//        $("#containerServiceCategory").html($Content);
//        $("#divLeasing").html($Content);
//        $.get('Ajax/GetLeasingCompany.aspx?LeaseID=' + leaseId + '&_=' + d.getTime(), function(result) {
//            if (result != "null") {
//                var js = "var json=" + result + ";";
//                try {
//                    var q = "(" + result + ")";
//                    var json = eval(q);
//                    $("[id$='_imgLeasingCompany']").attr("src", json.image);
//                    if (json.text) {
//                        $("[id$='_lblMessage']").show();
//                        $("[id$='_lblServiceConnected']").val(json.leaseId);
//                    }
//                    else
//                        $("[id$='_lblMessage']").hide();
//                    $("[id$='_ddlLeasingLeaseControl']").val(json.leaseId);
//                } catch (e) {
//                    //alert(e);
//                }
//            }
//            if ($("[id$='_rdoButtonReparatie']").is(':checked'))
//                service = "Reparatie";
//            else
//                if ($("[id$='_rdoButtonOnderhoud']").is(':checked')) {
//                service = "Onderhoud";
//            }
//            else
//                if ($("[id$='_rdoButtonBanden']").is(':checked')) {
//                service = "Banden";
//            }
//            else {
//                service = "Banden";
//            }
//            $("#divCheckBoxes").html('<div style="width:188px;"><img src="App_Themes/Default/Images/LicencePlate/ajax-loader.gif" style="padding-left:85px;padding-top:30px;"/></div>');
//            $.post("Ajax/GetServicesForACategory.aspx?leasing=" + leaseId + "&category=" + service, function(content) {
//                var $Content = $(content);
//                $("#__VIEWSTATE", $Content).remove();
//                $("#divCheckBoxes").html($Content);
//                $("[id$='_lblCategoryName']").val(service);
//            });
//        });
//    });

//}

function bringServices(obj) {
    var text1 = obj.parentNode.getElementsByTagName('label')[0].innerHTML;
    $("#divCheckBoxes").html('<div style="width:188px;"><img src="App_Themes/Default/Images/LicencePlate/ajax-loader.gif" style="padding-left:85px;padding-top:30px;"/></div>');
    $.post("Ajax/GetServicesForACategory.aspx?category=" + text1, function(content) {
        var $Content = $(content);
        $("#__VIEWSTATE", $Content).remove();
        $("#divCheckBoxes").html($Content);
        $("[id$='_lblCategoryName']").val(text1);
        if ($("[id$='_rdoButtonReparatie']").is(':checked')) {
            $("[id$='_imgReparatie']").attr("src", _appTheme + "/Images/OnlinePlanning/Reparatie_shadow.png");
            $("[id$='_imgOnderhoud']").attr("src", _appTheme + "/Images/OnlinePlanning/Onderhoud.png");
            $("[id$='_imgBanden']").attr("src", _appTheme + "/Images/OnlinePlanning/Banden.png");
        }
        else
            if ($("[id$='_rdoButtonOnderhoud']").is(':checked')) {
                $("[id$='_imgOnderhoud']").attr("src", _appTheme + "/Images/OnlinePlanning/Onderhoud_shadow.png");
                $("[id$='_imgReparatie']").attr("src", _appTheme + "/Images/OnlinePlanning/Reparatie.png");
                $("[id$='_imgBanden']").attr("src", _appTheme + "/Images/OnlinePlanning/Banden.png");
        }
        else
            if ($("[id$='_rdoButtonBanden']").is(':checked')) {
                $("[id$='_imgBanden']").attr("src", _appTheme + "/Images/OnlinePlanning/Banden_shadow.png");
                $("[id$='_imgReparatie']").attr("src", _appTheme + "/Images/OnlinePlanning/Reparatie.png");
                $("[id$='_imgOnderhoud']").attr("src", _appTheme + "/Images/OnlinePlanning/Onderhoud.png");
        }
    });
}

function bringServices2(radioText) {
    $("#divCheckBoxes").html('<div style="width:188px;"><img src="App_Themes/Default/Images/LicencePlate/ajax-loader.gif" style="padding-left:85px;padding-top:30px;"/></div>');
    $.post("Ajax/GetServicesForACategory.aspx?category=" + radioText, function(content) {
        var $Content = $(content);
        $("#__VIEWSTATE", $Content).remove();
        $("#divCheckBoxes").html($Content);
        $("[id$='_lblCategoryName']").val(radioText);
    });
}

function jqGetServices() {
    var text1 = $("[id$='_lblServices']");
    text1.value = '';
    $("#divCheckBoxes :checked").each(function() {
        text1.value = text1.value + $(this).val() + "|";
    });
    $("[id$='_lblServices']").val(text1.value);
	//alert(text1.value)
}

/* online planning*/

function getTimeApp(date) {
    $.post("Ajax/GetAvailableTimeApp.aspx?date=" + date, function(content) {
        var $Content = $(content);
        $("#__VIEWSTATE", $Content).remove();
        $("#containerTime").html($Content);
    });

}


function ChangeClass2(link) {
    thelink = $('#' + link);
    thelink.attr("class", "btnOver");
}

function RestoreClass2(link) {
    thelink = $('#' + link);
    thelink.attr("class", "btnNormal");
}


function Intervals(b1, b2, b3, b4,b5) {
    if (b1.attr('class') == 'btnOver') {
        b1.attr('class', 'btnNormal');
        b2.attr('class', 'btnOver');
        b3.attr('class', 'btnNormal');
        b4.attr('class', 'btnNormal');
        b5.attr('class', 'btnNormal');

    } else if (b2.attr('class') == 'btnOver') {
        b1.attr('class', 'btnNormal');
        b2.attr('class', 'btnNormal');
        b3.attr('class', 'btnOver');
        b4.attr('class', 'btnNormal');
        b5.attr('class', 'btnNormal');


    } else if (b3.attr('class') == 'btnOver') {
        b1.attr('class', 'btnNormal');
        b2.attr('class', 'btnNormal');
        b3.attr('class', 'btnNormal');
        b4.attr('class', 'btnOver');
        b5.attr('class', 'btnNormal');
    }
    else if (b4.attr('class') == 'btnOver') {
        b1.attr('class', 'btnNormal');
        b2.attr('class', 'btnNormal');
        b3.attr('class', 'btnNormal');
        b5.attr('class', 'btnOver');
        b4.attr('class', 'btnNormal');
    }
    else if (b5.attr('class') == 'btnOver') {
        b4.attr('class', 'btnNormal');
        b2.attr('class', 'btnNormal');
        b3.attr('class', 'btnNormal');
        b1.attr('class', 'btnOver');
        b5.attr('class', 'btnNormal');
    }
    else {

        b4.attr('class', 'btnNormal');
        b2.attr('class', 'btnNormal');
        b3.attr('class', 'btnNormal');
        b1.attr('class', 'btnOver');
        b5.attr('class', 'btnNormal');
    }
    
   
}
function MoveButtons(nav, div, buton1, buton2, buton3, buton4,buton5) {
    $('#' + div).fadeIn(1000, function() {
        $('#' + div).cycle({
            fx: 'fade',
            speed: 'slow',
            timeout: 5000,
            pager: $('#' + nav)
        });
        b1 = $('#' + buton1);
        b2 = $('#' + buton2);
        b3 = $('#' + buton3);
        b4 = $('#' + buton4);
        b5 = $('#' + buton5);
    });
    setInterval('Intervals(b1,b2,b3,b4,b5)', 5000);

}

function Explode(control) {
    var link = $('#' + control);

	link.css({'z-index' : '5'}); /*Add a higher z-index value so this image stays on top*/
	link.addClass("logoZoom").stop() /* Add class of "logoZoom", then stop animation queue buildup*/
		.animate({
			marginTop: '0px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '0px',
			top: '0%',
			left: '6%',
			width: '288px', /* Set new width */
			height: '57px', /* Set new height */
			padding: '0px'
}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
setTimeout(function() { Implode(control);  }, 400);
}

function Implode(control) {
    var link = $('#' + control);

    link.css({ 'z-index': '0' }); /* Set z-index back to 0 */
    link.removeClass("logoZoom").stop()  /* Remove the "logoZoom" class , then stop animation queue buildup*/
		    .animate({
		        marginTop: '0', /* Set alignment back to default */
		        marginLeft: '0',
		        top: '0',
		        left: '0',
		        width: '282px', /* Set width back to default */
		        height: '53px', /* Set height back to default */
		        padding: '0px'

		    }, 400);
}
function SetLogoTimer(control) {

    var image = control;
    setInterval(function() { Explode(image); }, 5000);
}

