﻿

function changeDate() {
    var fromdate = defromdate.GetDate();
    var todate = detodate.GetDate();
    if (fromdate > todate) {
        detodate.SetDate(fromdate);
    }
    detodate.SetMinDate(fromdate);
}


/*********************************************  Room Control javascript begins  *****************/

function roomChange() {
    var total = 4;
    var value = comboRooms.GetValue();

    for (var i = 1; i <= value; i++) {
        var label = document.getElementById("trRoom" + i);
        label.style.display = "block";

    }

    if (total > value) {
        for (var i = value + 1; i <= total; i++) {
            var label = document.getElementById("trRoom" + i);
            label.style.display = "none";

            //set children to zero
            var child = document.getElementById("R" + i + "Child");
            child.style.display = "none";
            for (j = 1; j <= 4; j++) {
                var children = document.getElementById("R" + i + "Child" + j);
                children.style.display = "none";
            }
            switch (i) {
                case 2:
                    comboChildren2.SetValue(0);
                    break;
                case 3:
                    comboChildren3.SetValue(0);
                    break;
                case 4:
                    comboChildren4.SetValue(0);
                    break;
                default:
                    break;
            }
        }
        chkMessage();
    }


}
function chkMessage() {

    if (comboChildren1.GetValue() == 0 && comboChildren2.GetValue() == 0 && comboChildren3.GetValue() == 0 && comboChildren4.GetValue() == 0) {
        document.getElementById("msgChild").style.display = "none";
    }
    else {
        document.getElementById("msgChild").style.display = "block";
    }

}

function comboChildrenChange(id) {
    chkMessage();
    var total = 4;
    var value = 0;
    var name = "";
    switch (id) {
        case 1:
            value = comboChildren1.GetValue();
            name = "R1Child";
            break;
        case 2:
            value = comboChildren2.GetValue();
            name = "R2Child";
            break;
        case 3:
            value = comboChildren3.GetValue();
            name = "R3Child";
            break;
        case 4:
            value = comboChildren4.GetValue();
            name = "R4Child";
            break;
    }

    for (var i = 1; i <= value; i++) {
        var label = document.getElementById(name + i);
        label.style.display = "block";
        document.getElementById(name).style.display = "block";
    }
    if (total > value) {
        for (var i = value + 1; i <= total; i++) {
            var label = document.getElementById(name + i);
            label.style.display = "none";
        }
    }
    if (value == 0) {
        document.getElementById(name).style.display = "none";
    }
}


function loadRoomDetails() {
    var roomCount = comboRooms.GetValue();
    var R1Child = comboChildren1.GetValue();
    var R2Child = comboChildren2.GetValue();
    var R3Child = comboChildren3.GetValue();
    var R4Child = comboChildren4.GetValue();
    OnLoadRoomCount(roomCount, R1Child, R2Child, R3Child, R4Child);
}

function OnLoadRoomCount(roomCount, R1Child, R2Child, R3Child, R4Child) {
    var num = parseInt(roomCount);
    var total = 4;
    var value = num;

    //Display rooms
    for (var i = 1; i <= value; i++) {
        var label = document.getElementById("trRoom" + i);
        label.style.display = "block";
    }
    if (total > value) {
        for (var i = value + 1; i <= total; i++) {
            var label = document.getElementById("trRoom" + i);
            label.style.display = "none";
        }
    }

    //Check Message
    if (R1Child == 0 && R2Child == 0 && R3Child == 0 && R4Child == 0) {
        document.getElementById("msgChild").style.display = "none";
    }
    else {
        document.getElementById("msgChild").style.display = "block";
    }

    //Display child count for Rooms
    for (var j = 1; j <= 4; j++) {
        switch (j) {
            case 1:
                var RCount = parseInt(R1Child);
                break;
            case 2:
                var RCount = parseInt(R2Child);
                break;
            case 3:
                var RCount = parseInt(R3Child);
                break;
            case 4:
                var RCount = parseInt(R4Child);
                break;
        }

        var child = "R" + j + "Child";
        for (var a = 1; a <= RCount; a++) {
            var label = document.getElementById(child + a);
            label.style.display = "block";
            document.getElementById(child).style.display = "block";
        }
        if (total > RCount) {
            for (var a = RCount + 1; a <= total; a++) {
                var label = document.getElementById(child + a);
                label.style.display = "none";
            }
        }
        if (RCount == 0) {
            document.getElementById(child).style.display = "none";
        }
    }
}

/*********************************************  Room Control javascript ends  *****************/



function loadTime() {
    getPickupTime(0);
    getReturnTime(0);
}

function getReturnTime(e) {
    for (var i = 0; i < 24; i++) {
        var hour = i.toString();
        if (hour.length == 1) {
            hour = "0" + hour;
        }
        var s1 = hour + ":00";
        var s2 = hour + ":30";
        cbReturnTime.AddItem(s1, (i * 2) + 1);
        cbReturnTime.AddItem(s2, (i * 2) + 2);
    }
    cbReturnTime.SetSelectedIndex(e);
}

function getPickupTime(e) {
    for (var i = 0; i < 24; i++) {
        var hour = i.toString();
        if (hour.length == 1) {
            hour = "0" + hour;
        }
        var s1 = hour + ":00";
        var s2 = hour + ":30";
        cbPickupTime.AddItem(s1, (i * 2) + 1);
        cbPickupTime.AddItem(s2, (i * 2) + 2);
    }
    cbPickupTime.SetSelectedIndex(e);
}

function ShowBasketPopup(keyValue) {
    //popupBasket.SetHeaderText(Name);
    popupBasket.SetContentUrl('/ShowBasketPopup.aspx?id=' + keyValue);
    popupBasket.Show();
}

function OnSearchClick() {
    refreshSearchCallback.PerformCallback('S');
}


function HotelOnMoreInfoClick(keyValue, Name) {
    popupDetails.SetHeaderText(Name);
    popupDetails.SetContentUrl('/HotelPopupNew.aspx?code=' + keyValue);
    popupDetails.Show();
}


function ToursOnMoreInfoClick(keyValue, Name) {
    //alert(keyValue + "" + keyValue);
    popupDetails.SetHeaderText(Name);
    //popupDetails.SetContentUrl('/ShowProduct.aspx?TourId=' + keyValue);
    popupDetails.SetContentUrl('/TourPopup.aspx?id=' + keyValue);
    popupDetails.Show();
}

function OnDeleteFromBasketClick(keyValue) {
    confirmDeleteDlg.argValue = keyValue;
    confirmDeleteDlg.Show();
}

function OnConfirmDelete() {
    if (confirmDeleteDlg.argValue == 'A') {
        BFGrid.PerformCallback("Delete");
    }
    confirmDeleteDlg.Hide();
}

function ToDateValidation(s, e) {
    var selectedDate = s.date;
    if (selectedDate == null || selectedDate == false)
        return;
    var currentDate = new Date();
    if (selectedDate < defromdate.GetDate())
        e.isValid = false;
}
function FromDateChanged(s, e) {

    detodate.Validate();

}

function FromDateValidation(s, e) {
    var selectedDate = s.date;
    if (selectedDate == null || selectedDate == false)
        return;
    var currentDate = new Date();
    if (selectedDate < currentDate)
        e.isValid = false;
}
function ShowFlightTab(s, e) {

    PageControlGrid.GetTabByName("TabFlights").SetVisible("false");
    alert("hello");
}

function enterTestValues(s, e) {
    defromdate.SetDate('09/12/2008');

}

function OnSelectionChangedHotel(e) {
    //alert("selection");
    //gridHotelResults._selectAllRowsOnPage(false);    //Select the row
    //gridHotelResults.SelectRow(e.visibleIndex, true);
}

function OnSelectionChangedChildCount(s, e) {
    var selNum = s.selectedIndex;
    //var selText = s.options[selNum].text;
    var selText = s.GetValue();

    var num = parseInt(selText);
    //alert(num);
    for (var i = 1; i <= 6; i++) {

        if (i <= num) {
            var label = document.getElementById("spanLbl" + i);
            label.style.display = "block";
            var span = document.getElementById("spanChildAge" + i);
            span.style.display = "block";
        } else {
            var label = document.getElementById("spanLbl" + i);
            label.style.display = "none";
            var span = document.getElementById("spanChildAge" + i);
            span.style.display = "none";
        };
    }
    if (typeof comboChildren1 !== "undefined") {
        comboChildren1.SetSelectedIndex(s.GetSelectedIndex());
        comboChildrenChange(1);
    };
    

}

function OnLoadChildCount(s) {

    var num = parseInt(s);
    //alert(num);
    for (var i = 1; i <= 6; i++) {

        if (i <= num) {
            var label = document.getElementById("spanLbl" + i);
            label.style.display = "block";
            var span = document.getElementById("spanChildAge" + i);
            span.style.display = "block";
        } else {
            var label = document.getElementById("spanLbl" + i);
            label.style.display = "none";
            var span = document.getElementById("spanChildAge" + i);
            span.style.display = "none";
        };
    }


}

function addToBasket(objectName, id) {

    callBackAddToBasket.PerformCallback(objectName + ';' + id);
    document.getElementById(objectName + id).className = "booklink";
    document.getElementById(objectName + id).style.display = "none";
    BookingPanel.Show();
    return;
}

function OnGetTourRowValues(values) {
    ToursOnMoreInfoClick(values[0], values[1]);
}

function ShowTourDetailsPopup(value) {
    GridTourResults.GetRowValues(value, 'id;ShortName', OnGetTourRowValues);
}

function onCellClick(rowIndex, fieldName) {
    if (fieldName != 'add') {
        GridTourResults.GetRowValues(rowIndex, 'id;ShortName', OnGetTourRowValues);
    }

    /*ShowTourDetailsPopup(e.visibleIndex);*/
}





function onBookingCellClick(rowIndex, fieldName)
{
   MasterGrid.GetRowValues(rowIndex, 'id;Name;ProductType', BookingOnMoreInfoClick);
}

function BookingOnMoreInfoClick(values) {

    if(values[2] != 3)
        {
            popupBookingDetails.SetHeaderText(values[1]);
            popupBookingDetails.SetContentUrl('/ShowFlightDetailControlObjBooking.aspx?SegmentId=' + values[0]);
            popupBookingDetails.Show();
        }
}


function searchHotel(keyValue) {

    SearchSegmentCorp(keyValue, '2', 120, 120);

}
function searchFlight(keyValue) {

    SearchSegmentCorp(keyValue, '1', 100, 100);
}

function searchSegment(keyValue) {

    SearchSegmentCorp(keyValue, 1, 100, 100);
}

function CloseSegmentWindow(value) {

    if (value == 'true') {
        popupSegmentDetails.Hide();
    }
}
function RefreshGrids() {
    gridProjectUsers.Refresh();
    SegmentGrid.Refresh();
    gridBaskets.Refresh();
    gridBookings.Refresh();
}

function updateProject() {
    CallbackUpdate.PerformCallback();
}
function loadProject(value) {
    callbackUpdateGrids.PerformCallback(value);
}
function OnGetProjectRowValues(values) {
    callbackUpdateGrids.PerformCallback(values);
}

function onCellClickProjectsOld(rowIndex, fieldName) {
    if (fieldName != '') {
        gridProjects.GetRowValues(rowIndex, 'id', OnGetProjectRowValues);
    }
}
function onCellClickProjects(rowIndex, fieldName) {
    if (fieldName != '') {
        gridProjects.ExpandDetailRow(rowIndex);
    }
}
function onCellClickBasket(rowIndex, fieldName) {
    if (fieldName != '') {
        callbackPanelBasket.PerformCallback(rowIndex);
    }
}
function loadBasket(value) {
    callbackPanelBasket.PerformCallback(value);

}
function loadBooking(value) {
    callbackPanelBooking.PerformCallback(value);

}
function bookBasket(value) {

    document.location = '/CorporatePaxSelection.aspx?BasketId=' + value;
}
function OnProjectSegmentsClickEdit(keyValue, Name, type, image) {

    popupSegmentDetails.SetHeaderImageUrl('/Images/' + image);
    popupSegmentDetails.SetHeaderText(Name + ' Search');

    switch (type) {
        case '1':

            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupFlights.aspx?id=' + keyValue + '&type=' + type);
            break;
        case '2':
            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupHotel.aspx?id=' + keyValue + '&type=' + type);
            break;
        case '3': // Car
            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupCar.aspx?id=' + keyValue + '&type=' + type);
            break;
        case '4': // Tours
            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupTour.aspx?id=' + keyValue + '&type=' + type);
            break;
        case '5': // Activities
            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupActivity.aspx?id=' + keyValue + '&type=' + type);
            break;
        case '6': // Services
            popupSegmentDetails.SetContentUrl('/ShowSearchControlPopupService.aspx?id=' + keyValue + '&type=' + type);
            break;
        default:
            return;
            break;
    }

    popupSegmentDetails.Show();
}
function NewProject() {

    gridProjects.AddNewRow();

}

function FocusProjectRow(row) {
    gridProjects.PerformCallback(row);
}
function OnEndCallback(s, e) {

}

function SearchSegmentCorp(keyValue, type, x, y) {

    switch (type) {
        case '1':

            popupSegmentResults.SetWindowContentUrl(popupSegmentResults.GetWindowByName('FlightResultWindow'), 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(popupSegmentResults.GetWindowByName('FlightResultWindow'), x, y);
            break;
        case '2':
            var HotelWindow = popupSegmentResults.GetWindowByName('HotelResultWindow');
            popupSegmentResults.SetWindowContentUrl(HotelWindow, 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(HotelWindow, x, y);

            break;
        case '3':
            popupSegmentResults.SetWindowContentUrl(popupSegmentResults.GetWindowByName('CarResultWindow'), 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(popupSegmentResults.GetWindowByName('CarResultWindow'), x, y);


            break;
        case '4':
            popupSegmentResults.SetWindowContentUrl(popupSegmentResults.GetWindowByName('TourResultWindow'), 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(popupSegmentResults.GetWindowByName('TourResultWindow'), x, y);

            break;
        case '5':
            popupSegmentResults.SetWindowContentUrl(popupSegmentResults.GetWindowByName('ActivityResultWindow'), 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(popupSegmentResults.GetWindowByName('ActivityResultWindow'), x, y);

            break;
        case '6':
            popupSegmentResults.SetWindowContentUrl(popupSegmentResults.GetWindowByName('ServiceResultWindow'), 'SearchControlStart.aspx?SegmentId=' + keyValue);
            popupSegmentResults.ShowWindowAtPos(popupSegmentResults.GetWindowByName('ServiceResultWindow'), x, y);

            break;
        default:
            break;
    }

}

function SetSegmentHeader(keyValue, type, text) {

    switch (type) {
        case '1':
            popupSegmentResults.GetWindowByName('FlightResultWindow').SetHeaderText(text);
            break;
        case '2':
            popupSegmentResults.GetWindowByName('HotelResultWindow').SetHeaderText(text);
            break;
        case '3':
            popupSegmentResults.GetWindowByName('CarResultWindow').SetHeaderText(text);
            break;
        case '4':
            popupSegmentResults.GetWindowByName('TourResultWindow').SetHeaderText(text);
            break;
        case '5':
            popupSegmentResults.GetWindowByName('ActivityResultWindow').SetHeaderText(text);
            break;
        case '6':
            popupSegmentResults.GetWindowByName('ServiceResultWindow').SetHeaderText(text);
            break;
        default:
            break;
    }

}

function SearchAll() {
    var theArray = SegmentGrid.cpSearchIndexes;
    var x = 40;
    var y = 40;
    for (var i = 0; i < theArray.length; i++) {
        SearchSegmentCorp(theArray[i].split(';')[0], theArray[i].split(';')[1], x, y);
        x = x + 28;
        y = y + 28;
    }
    SetSegmentHeader('0', '1', 'Searching for Flights... please wait');
    SetSegmentHeader('0', '2', 'Searching for Hotels... please wait');
    SetSegmentHeader('0', '3', 'Searching for Cars... please wait');
    SetSegmentHeader('0', '4', 'Searching for Tours... please wait');
    SetSegmentHeader('0', '5', 'Searching for Activities... please wait');
    SetSegmentHeader('0', '6', 'Searching for Services... please wait');
}

