﻿var _contactsEditorVisible = false, _vehicleOperation = "edit";
function showHideContactEditors() {
    var showClass, hideClass;
    var btUserEdit = document.getElementById("btUserEdit");
    var btUserCancel = document.getElementById("btUserCancel");
    var btUserSave = document.getElementById("btUserSave");
    if (_contactsEditorVisible) {
        _contactsEditorVisible = false;
        showClass = "userDetailsLabel";
        hideClass = "userDetailsControl";
        btUserEdit.style.display = "inline";
        btUserCancel.style.display = "none";
        btUserSave.style.display = "none";
    }
    else {
        _contactsEditorVisible = true;
        showClass = "userDetailsControl";
        hideClass = "userDetailsLabel";
        btUserEdit.style.display = "none";
        btUserCancel.style.display = "inline";
        btUserSave.style.display = "inline";
    }
    var table = document.getElementById("userDetailsTable");
    var spans = table.getElementsByTagName("span");
    for (i = 0; i < spans.length; i++) {
        if (spans[i].className == showClass)
            spans[i].style.display = "inline";
        if (spans[i].className == hideClass)
            spans[i].style.display = "none";
    }
}

function editUserDetails() {
    _contactsEditorVisible = false;
    showHideContactEditors();
    return false;
}

function cancelUserDetails() {
    _contactsEditorVisible = true;
    showHideContactEditors();
    return false;
}

function saveUserDetails() {
    cpUserDetails.PerformCallback(_vehicleOperation);
    return false;
}

function saveVehicleDetails() {
    cpVehicleDetails.PerformCallback(_vehicleOperation);
    return false;
}

function createVehicle() {
    _vehicleOperation = "create";
    tbVehicleRegNo.SetText("");
    cbVehicleMake.SetSelectedIndex(0);
    cbVehicleModel.SetSelectedIndex(0);
    cbVehicleChassis.SetSelectedIndex(0);
    cbTyreSizeFront.SetSelectedIndex(0);
    cbTyreSizeRear.SetSelectedIndex(0);
    return false;
}

function updatePressure() {
    if (cbVehicleChassis.GetValue() != "") {
        var pars = cbVehicleChassis.GetValue() + ";" + cbTyreSizeFront.GetValue() + ";" + cbTyreSizeRear.GetValue();
        cpPressures.PerformCallback(pars);
    }
}

function showLoginRegistration(isLogin) {
    var loginRegDiv = document.getElementById("loginRegister");
    var loginControlsDiv = document.getElementById("loginControls");
    var confirmDiv = document.getElementById("confirmPassword");
    if (isLogin) {
        confirmDiv.style.display = "none";
        loginRegDiv.style.display = "none";
        loginControlsDiv.style.display = "block";
    }
    else {
        confirmDiv.style.display = "block";
        loginRegDiv.style.display = "block";
        loginControlsDiv.style.display = "none";
    }
}
