﻿function stateInsert(state) {
    $j('input[marker=inpState]').val(state);
}
function weightInsert(weight) {
    $j('input[driveWeight=true]').val(weight);
    $j('input[fullDriveWeight=true]').val(weight);   
    
}
function providerInsert(provider) {
    var el = $j('input[marker=provider]');
    el.val(provider);
    el.forceDependers();
}
function priceInsert(price) {
    $j('span[price=true]').text(price);
}

function showStopsCount() {
    centerPopup(true);
    loadPopup(true);
}
function showWeight() {
    centerPopup(false);
    loadPopup(false);
}
var popupStatus = 0;
function loadPopup(isStopsCount) {
    if (popupStatus == 0) {
        $j("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $j("#backgroundPopup").fadeIn("slow");
        if (isStopsCount)
            $j("#popupStopsCount").fadeIn("slow");
        else
            $j("#popupWeight").fadeIn("slow");
        popupStatus = 1;
    }
}
function disablePopup(isStopsCount) {
    if (popupStatus == 1) {
        if (isStopsCount)
            $j("#popupStopsCount").fadeOut("slow");
        else
            $j("#popupWeight").fadeOut("slow");
        $j("#backgroundPopup").fadeOut("slow");
        popupStatus = 0;
    }
}

function centerPopup(isStopsCount) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight;
    var popupWidth;
    if (isStopsCount) {
        popupHeight = $j("#popupStopsCount").height();
        popupWidth = $j("#popupStopsCount").width();
        $j("#popupStopsCount").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else {
        popupHeight = $j("#popupWeight").height();
        popupWidth = $j("#popupWeight").width();
        $j("#popupWeight").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }

    $j("#backgroundPopup").css({
        "height": windowHeight
    });
}

$j(document).ready(function() {
    $j("#popupStopsClose").click(function() {
        disablePopup(true);
    });
    $j("#popupWeightClose").click(function() {
        disablePopup(false);
    });
    $j("#btnStopsClose").click(function() {
        disablePopup(true);
    });
    $j("#btnWeightClose").click(function() {
        disablePopup(false);
    });    
});