function calculatePrice() {


}

function sendToPaymentSystem() {
    document.getElementById('waitDialog').style.display = '';
    document.theForm.submit();
}

function remove_seat(eventid, seatid, seatcat, localid) {
    document.getElementById('waitDialog').style.display = '';
    var event = $('#airplane').attr('eventid');
    if (event == eventid) {
        var seat = $('#seat_' + seatid);
        var type = $(seat).attr('class');
        if (type == 'selected') {
            if ($(seat).attr('sc') == seatcat) {
                var sc = $(seat).attr('sc');
                $(seat).removeClass();
                $(seat).toggleClass('active');
                $.post("/Internal/RemoveSeat/" + seatid, "SeatCategory=" + seatcat, function(theResponse) {
                document.getElementById('waitDialog').style.display = 'none';
                    $('#row_' + seatid).remove();
                    $('#seat_' + seatid).removeClass();
                    $('#seat_' + seatid).toggleClass('free');
                    this.blur();
                });
            }
            else {
                alert($(seat).attr('sc') + " != " + seatcat);
            }
        }
    }
    else {
        $.post("/Internal/RemoveSeat/" + seatid, "SeatCategory=" + seatcat + "&LocalID=" + localid + "&EventID=" +eventid , function(theResponse) {
        $('#row_' + seatid).remove();
        document.getElementById('waitDialog').style.display = 'none';
            this.blur();
        });
    }
          
}


function categoryChange(selectObj) { 
    var idx = selectObj.selectedIndex;
    var tc = selectObj.options[idx].value;
    //alert("Seat : " + seat + " Category : " + tc);
    var seat = $(selectObj).attr('id').replace('S', '');
    var ev = $(selectObj).attr('ev');
    var sc = $(selectObj).attr('sc');
    var lo = $(selectObj).attr('lo');
    var input = "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc;
    //alert(input);
    $.post("/Internal/ChangeCategory/" + seat + "/", "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc, function(theResponse) {
        //alert(theResponse);
    });

}

$(document).ready(function() {
    $("#locals").change(function() {

        var tc = $(this).val();
        //alert(tc);
        //$.post("/Internal/GetEvents/" + tc + "/", "", function(theResponse) {
        //    $("#Event").html(theResponse);
        //});
        var div = $('#events');
        div.html('<div style="text-aling:center;"> <h1>Laddar...</h1></div>');


        window.location.replace("/Internal/Seatmap?LocalID=" + tc);

    });
    $("#events").change(function() {
        var tc = $(this).val();
        var local = $("#locals").val();
        var div = $('#container');
        div.html('<div style="text-aling:center;"> <h1>Laddar...</h1></div>');


        window.location.replace("/Internal/Seatmap?EventID=" + tc + "&LocalID=" + local);
    });
    $(".ticketcategoryselect").change(function() {

        var tc = $(this).val();
        var seat = $(this).attr('id');
        //alert("Seat : " + seat + " Category : " + tc);
        var ev = $(this).attr('ev');
        var sc = $(this).attr('sc');
        var lo = $(this).attr('lo');
        //  int sc,int tc, int ev, int lo)
        //alert("Seat : " + seat + " Category : " + tc);
        var input = "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc;
        //alert(input);
        $.post("/Internal/ChangeCategory/" + seat + "/", "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc, function(theResponse) {
            //alert(theResponse);
        });

    });
    // Add click listener to seats

    $('#unnumbered a').click(function() {

        // Asign value of the link target
        var thisTarget = $(this).attr('href');
        //alert('Hej');
        document.getElementById('waitDialog').style.display = '';
        //$('.waitDialog').style.display = 'none';
        //alert('Hej!');
        var type = $(this).attr('class');
        var sc = $(this).attr('sc');
        var ev = $(this).attr('ev');
        $(this).removeClass();
        $(this).toggleClass('active');
        //alert("/Internal/AddSeat/" + thisTarget.substr(6) + "?sc=" + sc + "&ev=" + ev);
        $.post("/Internal/AddSeat/" + thisTarget.substr(6), "sc=" + sc + "&ev=" + ev, function(theResponse) {
            //alert(theResponse.toString());
            document.getElementById('waitDialog').style.display = 'none';
            if (theResponse.toString().substr(0, 1) == "0") {
                alert(theResponse.toString().substr(1));
                this.blur();
            }
            else if (theResponse.toString().substr(0, 1) == "1") {
                alert(theResponse.toString().substr(1));
                this.blur();
            }
            else {
                $('#tickets tr:last').after(theResponse.toString());
                this.blur();
            }
        });

        // Toggle selected class on/off

        this.blur();
        return false;
    }
		);

    $('#airplane a').click(function() {
        // Asign value of the link target
        var thisTarget = $(this).attr('href');

        var type = $(this).attr('class');
        if (type == 'selected') {
            var sc = $(this).attr('sc');
            $(this).removeClass();
            $(this).toggleClass('active');

            //document.getElementById('row_' + thisTarget.substr(6)).remove();
            $.post("/Internal/RemoveSeat/" + thisTarget.substr(6), "SeatCategory=" + sc, function(theResponse) {
                $('#row_' + thisTarget.substr(6)).remove();
                $('#seat_' + thisTarget.substr(6)).removeClass();
                $('#seat_' + thisTarget.substr(6)).toggleClass('free');
                this.blur();
                $(".ticketcategoryselect").change(function() {

                    var tc = $(this).val();
                    var seat = $(this).attr('id');
                    alert("Seat : " + seat + " Category : " + tc);
                    var ev = $(this).attr('ev');
                    var sc = $(this).attr('sc');
                    var lo = $(this).attr('lo');
                    //  int sc,int tc, int ev, int lo)
                    //alert("Seat : " + seat + " Category : " + tc);
                    var input = "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc;
                    alert(input);
                    document.getElementById('waitDialog').style.display = '';
                    $.post("/Internal/ChangeCategory/" + seat + "/", "sc=" + sc + "&ev=" + ev + "&lo=" + lo + "&tc=" + tc, function (theResponse) {
                        document.getElementById('waitDialog').style.display = 'none';
                        //alert(theResponse);
                    });

                });
            });
            //alert('#row_' + thisTarget.substr(6));
        }
        else if (type == 'free') {
            var sc = $(this).attr('sc');
            $(this).removeClass();
            $(this).toggleClass('active');
            //alert("/Internal/AddSeat/" + thisTarget.substr(6) + "?sc=" + sc);
            document.getElementById('waitDialog').style.display = '';
            $.post("/Internal/AddSeat/" + thisTarget.substr(6), "sc=" + sc, function(theResponse) {
                //$('#row_' + thisTarget.substr(6)).remove();
                document.getElementById('waitDialog').style.display = 'none';
                if (theResponse.toString().substr(0, 1) == "0") {
                    alert(theResponse.toString().substr(1));
                    $('#seat_' + thisTarget.substr(6)).removeClass();
                    $('#seat_' + thisTarget.substr(6)).toggleClass('notavailable');
                    this.blur();
                }
                else if (theResponse.toString().substr(0, 1) == "1") {
                    alert(theResponse.toString().substr(1));
                    $('#seat_' + thisTarget.substr(6)).removeClass();
                    $('#seat_' + thisTarget.substr(6)).toggleClass('free');
                    this.blur();
                }
                else {
                    $('#tickets tr:last').after(theResponse.toString());
                    $('#seat_' + thisTarget.substr(6)).removeClass();
                    $('#seat_' + thisTarget.substr(6)).toggleClass('selected');
                    this.blur();
                }
            });

            // Show target tbody and hide others

            //$(thisTarget).addClass('selected');


            // Assign the value of the parent <li class="*">
        }

        // Toggle selected class on/off

        this.blur();
        return false;
    }
		);

    // Assign function to master checkbox
    $('#check_all').click(function() {
        if (this.checked === true) {
            // Add class="selected" to seat
            $('#airplane a, #passenger_details tbody tr').addClass('selected');
            $('#passenger_details input, #passenger_details select').removeAttr('disabled');
            this.blur();
        }
        else {
            // Remove class="selected" from seat
            $('#airplane a, #passenger_details tbody tr').removeClass('selected');
            $('#passenger_details input').attr('disabled', 'disabled').val('');
            $('#passenger_details select').each(function() {
                this.disabled = true;
                this.selectedIndex = 0;
            }
					);
            this.blur();
        }
    }
		);
}
);
