﻿
function mv_OnOpen() {
    mv_SetDirection(-1);
}

var __holderElementID = null;

function RenderControl(control, holder) {
    __holderElementID = holder;
    
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "/inc/" + control,
            rnd: Math.round()
        },
        onSuccess: function(transport) {  document.getElementById(__holderElementID).innerHTML = transport.responseText; },
        onFailure: function(){ alert('Fel uppstod: RenderControl') }
    });
}

function mv_SetDirection(move) {
    var _mv_toggle = document.getElementById("globalMinVistelseToggle");
    _mv_toggle.className = (move < 0 ? "down" : "");
}

function mv_SaveDates(startCal, endCal) {
    var year;
    
    year = (startCal.selectedDate.getYear() < 2008 ? (startCal.selectedDate.getYear() + 1900) : startCal.selectedDate.getYear());
    
    var startDate = year + "-" +
                    (startCal.selectedDate.getMonth()+1) + "-" +
                    startCal.selectedDate.getDate();
                    
    year = (endCal.selectedDate.getYear() < 2008 ? (endCal.selectedDate.getYear() + 1900) : endCal.selectedDate.getYear());                    
                    
    var endDate   = year + "-" +
                    (endCal.selectedDate.getMonth()+1) + "-" +
                    endCal.selectedDate.getDate();                    
                    
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/SaveDates",
            start: startDate,
            end: endDate,
            rnd: Math.round()
        },
        onSuccess: _PrintDates,
        onFailure: function(){ alert('Fel uppstod: SaveDates') }
    });
}

function _PrintDates(transport) {
    document.getElementById("mv_datestext").innerHTML = transport.responseText;
    mv_ToggleVisible("mv_dates");
}

function mv_SavePeople() {
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/SavePeople",
            amount: document.getElementById("mv_people_amount").value,
            rnd: Math.round()
        },
        onSuccess: _PrintPeople,
        onFailure: function(){ alert('Fel uppstod: SavePeople') }
    });
}

function _PrintPeople(transport) {
    document.getElementById("mv_peopletext").innerHTML = transport.responseText;
    mv_ToggleVisible("mv_people");
}

function mv_SaveRooms() {
    var roomString = "";
    var inp = document.getElementById("room_table").getElementsByTagName("input");
    for (var i = 0; i < inp.length; i++) {
        var pid = inp[i].id.replace("roomPeople_", "");
        if (parseInt(inp[i].value) > 0)
            roomString += pid + "|" + document.getElementById("roomName_" + pid).innerHTML + "|" + inp[i].value + "|";
    }
    
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/SaveRooms",
            rooms: roomString,
            rnd: Math.round()
        },
        onFailure: function(){ alert('Fel uppstod: SaveRooms') }
    });
}

function mv_AddRoom(id, name, people) {
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/AddRoom",
            id: id,
            name: name,
            people: people,
            rnd: Math.round()
        },
        onSuccess: _PrintRoom,
        onFailure: function(){ alert('Fel uppstod: AddRoom') }
    });
}

function _PrintRoom(transport) {
    RenderControl("Booking_Rooms", "booking_rooms");
    ctl00_ctl00_ctl00_mvFlyoutglobalMinVistelseToggle.Open();
}

function mv_AddSpa(id, name, people) {
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/AddSpa",
            id: id,
            name: escape(name),
            people: people,
            rnd: Math.round()
        },
        onSuccess: _PrintSpa,
        onFailure: function(){ alert('Fel uppstod: AddSpa') }
    });
}

function _PrintSpa(transport) {
    RenderControl("Booking_Spa", "booking_spa");
    ctl00_ctl00_ctl00_mvFlyoutglobalMinVistelseToggle.Open();
}

function mv_SaveSpa() {
    var roomString = "";
    var inp = document.getElementById("spa_table").getElementsByTagName("input");
    for (var i = 0; i < inp.length; i++) {
        var pid = inp[i].id.replace("spaPeople_", "");
        roomString += pid + "|" + document.getElementById("spaName_" + pid).innerHTML + "|" + inp[i].value + "|";
    }
    
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/SaveSpa",
            rooms: roomString,
            rnd: Math.round()
        },
        onFailure: function(){ alert('Fel uppstod: SaveSpa') }
    });
}

function mv_AddConference(id, name, people) {
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/AddConference",
            id: id,
            name: name,
            people: people,
            rnd: Math.round()
        },
        onSuccess: _PrintConference,
        onFailure: function(){ alert('Fel uppstod: AddConference') }
    });
}

function _PrintConference(transport) {
    RenderControl("Booking_Conference", "booking_conference");
    ctl00_ctl00_ctl00_mvFlyoutglobalMinVistelseToggle.Open();
}

function mv_SaveConference() {
    var roomString = "";
    var inp = document.getElementById("conference_table").getElementsByTagName("input");
    for (var i = 0; i < inp.length; i++) {
        if (parseInt(inp[i].value) > 0) {
            var pid = inp[i].id.replace("confPeople_", "");
            roomString += pid + "|" + document.getElementById("conferenceName_" + pid).innerHTML + "|" + inp[i].value + "|";
        }
    }
    
    new Ajax.Request("/inc/Events.aspx", {
        method: "get",
        parameters: {
            func: "Events/SaveConference",
            rooms: roomString,
            rnd: Math.round()
        },
        onSuccess: _PrintConference,
        onFailure: function(){ alert('Fel uppstod: SaveConference') }
    });
}