﻿var numberAttendingTextBox, isTheatrette, isFunctionRoom, isTrainingRoom1, isTrainingRoom2
var isUShape, isSchoolRoom, isBoardroom, isTheatreStyle, isStanding, numberEntered

function qv1_viewPrices() {

    var theDD = findField("1596");
    if (theDD.selectedIndex == 0) {
        var w = window.open('/Core/Pages/GetFile.aspx?ID=2d95e4ef7b9541a9bbf5', '', '');
    } else {
        var w = window.open('/Core/Pages/GetFile.aspx?ID=19bd584b91a8441d9021', '', '');
    }
    

}


function qv1_CheckNumberAttending() {

    numberAttendingTextBox = findField("557");
    numberEntered = numberAttendingTextBox.value - 0;

    
    var bookingArea = selectedValueForRadioButton(uniqueIDForFieldID["544"] + "$TheField$radBookingArea");
    isTheatrette    = (bookingArea == "Theatrette");
    isFunctionRoom  = (bookingArea == "Function Room");
    isTrainingRoom1 = (bookingArea == "Training Room 1");
    isTrainingRoom2 = (bookingArea == "Training Room 2");


    //set the style to theatre seating for theatrette by default
    if (isTheatrette) {
        document.forms[0].ctl00$PageContent$rptGenericForm$ctl10$TheField[3].checked = true;
    }

    var layout = selectedValueForRadioButton(uniqueIDForFieldID["553"] + "$TheField");
    isUShape       = (layout == "162");
    isSchoolRoom   = (layout == "163");
    isBoardroom    = (layout == "164");
    isTheatreStyle = (layout == "165");
    isStanding     = (layout == "777");


    numberAttendingTextBox.value = numberAttendingTextBox.value.replace(" ", "");
    if (isNaN(numberAttendingTextBox.value)) {
        alert("Please enter a valid number of people attending");
        numberAttendingTextBox.value = "";
        numberAttendingTextBox.focus();
    } else {
        if (isTheatrette) {
            if (numberEntered > 80) {
                alert("The maximum number of people for the Theatrette is 80")
                numberAttendingTextBox.value = "";
            }
        } else if (isFunctionRoom) {
            checkMaximums(90, 20, 24, 16, 120)
        } else if (isTrainingRoom1) {
            checkMaximums(40, 16, 16, 40, 40)
        } else if (isTrainingRoom2) {
            checkMaximums(25, 14, 14, 10, 25)
        }


    }
}

function checkMaximums(theatreStyleMax, boardroomMax, uShapeMax, schoolRoomMax, standingMax) {
    var maximumReached = 0;
    if (isTheatreStyle && numberEntered > theatreStyleMax) {
        maximumReached = theatreStyleMax;
    } else if (isBoardroom && numberEntered > boardroomMax) {
        maximumReached = boardroomMax;
    } else if (isUShape && numberEntered > uShapeMax) {
        maximumReached = uShapeMax;
    } else if (isSchoolRoom && numberEntered > schoolRoomMax) {
        maximumReached = schoolRoomMax;
    } else if (isStanding && numberEntered > standingMax) {
        maximumReached = standingMax;
    }

    if (maximumReached > 0) {
        alert("The maximum number of people for your chosen room setup is " + maximumReached + "\n\nPlease enter a number below " + maximumReached + " or choose a different room or room setup")
        numberAttendingTextBox.value = "";
    }
}
