﻿// Amend Search Validation Javascript file
function ValidateCheckInDate_ClientValidate(source, args)
{
    if (args.Value != "")
    {
        var checkInDate;          
        
        //Check In Date
        if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_txtCheckInDate"))
        {
          checkInDate = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_txtCheckInDate").value;
        }

        var curCheckInDateArray = checkInDate.split("/");
      
        //Create Current checkIn Date
        var curCheckInDate = new Date();
            curCheckInDate.setDate(curCheckInDateArray[0]); 
            //Removed 1 month as Javascript sees months from 0-11 NOT 1-12      
            curCheckInDate.setMonth(curCheckInDateArray[1]-1);
            curCheckInDate.setYear(curCheckInDateArray[2]);     
        
        var futureCheckInDate = new Date();
        //Add 1 day
        
        futureCheckInDate.setDate(futureCheckInDate.getDate()+1); 
            
        if(curCheckInDate < futureCheckInDate)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
    else
    {
        args.IsValid = false;
    }
}

function ValidateDepDate_ClientValidate(source, args)
{
    if (args.Value != "")
    {
        var checkInDate = args.Value;          

        var curCheckInDateArray = checkInDate.split("/");
      
        //Create Current checkIn Date
        var curCheckInDate = new Date();
            curCheckInDate.setDate(curCheckInDateArray[0]); 
            //Removed 1 month as Javascript sees months from 0-11 NOT 1-12      
            curCheckInDate.setMonth(curCheckInDateArray[1]-1);
            curCheckInDate.setYear(curCheckInDateArray[2]);     
        
        var futureCheckInDate = new Date();
        //Add 1 day
        
        futureCheckInDate.setDate(futureCheckInDate.getDate()+3); 
            
        if(curCheckInDate < futureCheckInDate)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
    else
    {
        args.IsValid = false;
    }
}

function ValidateDepDatePackage_ClientValidate(source, args)
{
    if (args.Value != "")
    {
        var checkInDate = args.Value;                
       

        var curCheckInDateArray = checkInDate.split("/");
      
        //Create Current checkIn Date
        var curCheckInDate = new Date();
            curCheckInDate.setDate(curCheckInDateArray[0]); 
            //Removed 1 month as Javascript sees months from 0-11 NOT 1-12      
            curCheckInDate.setMonth(curCheckInDateArray[1]-1);
            curCheckInDate.setYear(curCheckInDateArray[2]);     
        
        var futureCheckInDate = new Date();
        //Add 1 day
        
        futureCheckInDate.setDate(futureCheckInDate.getDate()+3); 
            
        if(curCheckInDate < futureCheckInDate)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }
    else
    {
        args.IsValid = false;
    }
}

function ValidatePassengers_ClientValidate(source, args)
{   
    var adults = 0;
    var children = 0;
    var infants = 0;
    
    var rooms = 1;
    
    var totalPax;
    
    var controlId;
    var searchType;
    
    
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightAdults"))
    {
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_";
        searchType = "Flight"; 
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms"))
    {
        searchType = "Accom";
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_";
    }  
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_";
    } 
    
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_";
    }
    
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_";
    }
    
    //Flights
    if(searchType == "Flight")
    {
        //adults
        adults = document.getElementById(controlId + "ddlFlightAdults").value;        
            
        //children        
        if(document.getElementById(controlId + "ddlFlightChildren"))        
            children = document.getElementById(controlId + "ddlFlightChildren").value;
        
        //infants
        if(document.getElementById(controlId + "ddlFlightInfants"))        
            infants = document.getElementById(controlId + "ddlFlightInfants").value;        
    }
    
    //Accommodation 
    if(searchType == "Accom")
    {  
        var rooms = document.getElementById(controlId + "ddlRooms").value
        
        //Iterate through rooms
        for(i = 1; i <= numRooms; i++)
        {         
            //adults
            if(document.getElementById(controlId + "ddlAdultsRoom" + i))            
              adults += document.getElementById(controlId + "ddlAdultsRoom" + i).value;
            
            //children
            if(document.getElementById(controlId + "ddlAccomChildrenRoom" + i))            
              children += document.getElementById(controlId + "ddlAccomChildrenRoom" + i).value;           
            
            //Infants    
            if(document.getElementById(controlId + "ddlInfantsRoom" + i))            
              infants += document.getElementById(controlId + "ddlInfantsRoom" + i).value;            
        }
    }  
    
    
    //Package     
    if(searchType == "Pack")
    {
        var numRooms = document.getElementById(controlId + "ddlRooms").value;
        var valid = true;
        
        //Iterate through rooms
        for(i = 1; i <= numRooms; i++)
        {            
            //adults            
            adults += parseInt(document.getElementById(controlId + "ddlPackagesAdultsRoom" + i).value);                                
            
            //children
            if(document.getElementById(controlId + "ddlPackagesChildrenRoom" + i))            
                children += parseInt(document.getElementById(controlId + "ddlPackagesChildrenRoom" + i).value);
            
            //Infants    
            if(document.getElementById(controlId + "ddlPackagesInfantsRoom" + i))            
                infants += parseInt(document.getElementById(controlId + "ddlPackagesInfantsRoom" + i).value);
        }
    }

   //Rooms    
    if(searchType == "Accom")
    {
        rooms = document.getElementById(controlId + "ddlRooms").value        
        totalPax = (parseInt(adults) + parseInt(children) + parseInt(infants))* parseInt(rooms);
    }
    else
    {   
        totalPax = (parseInt(adults) + parseInt(children) + parseInt(infants));     
    }
    
    if(totalPax > 9)
    {
        args.IsValid = false;
    }
}


function ValidateAdultsAgainstInfants_ClientValidate(source, args)
{
    var adults = 0;
    var infants = 0;
    var totalPax;
        
    var controlId;
    var searchType;
    
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightAdults"))
    {
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_";
        searchType = "Flight"; 
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))
    {
        searchType = "Flight";   
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms"))
    {
        searchType = "Accom";
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_";
    }
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_ddlRooms")) {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_";
    }
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_";
    }  
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))
    {
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_";
    }        
    if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_ddlRooms"))
    {
        //Accom search using the package modify search
        searchType = "Pack";
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_";
    }


    //Flights
    if(searchType == "Flight")
    {
        //adults
        adults = document.getElementById(controlId + "ddlFlightAdults").value;        
        
        //infants
        if(document.getElementById(controlId + "ddlFlightInfants"))        
            infants = document.getElementById(controlId + "ddlFlightInfants").value;        
    }
    
    //Accommodation 
    if(searchType == "Accom")
    {  
        var rooms = document.getElementById(controlId + "ddlRooms").value
        
        //Iterate through rooms
        for(i = 1; i <= numRooms; i++)
        {         
            //adults
            if(document.getElementById(controlId + "ddlAdultsRoom" + i))            
              adults += document.getElementById(controlId + "ddlAdultsRoom" + i).value;
            
            //Infants    
            if(document.getElementById(controlId + "ddlInfantsRoom" + i))            
              infants += document.getElementById(controlId + "ddlInfantsRoom" + i).value;            
        }
    }


    //Package     
    if(searchType == "Pack") {

        var numRooms = document.getElementById(controlId + "ddlRooms").value;
        var valid = true;
        //Iterate through rooms
        for(i = 1; i <= numRooms; i++)
        {            
            //adults            
            adults += parseInt(document.getElementById(controlId + "ddlPackagesAdultsRoom" + i).value);                                                      
            //Infants    
            if(document.getElementById(controlId + "ddlPackagesInfantsRoom" + i))            
                infants += parseInt(document.getElementById(controlId + "ddlPackagesInfantsRoom" + i).value);
        }
    }    
    if(adults < infants)
    {
        args.IsValid = false;
    }    
}

function PleaseWait()
{
    var controlId
    //Flight
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_";
    //Accom
    if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_";
    if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmendAccommodationControl1_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmendAccommodationControl1_";
    
    // package
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_imgPleaseWait"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_";
        


    // amend flight control
    if(document.getElementById(controlId + "imgPleaseWait"))
        document.getElementById(controlId + "imgPleaseWait").style.display = '';
    if(document.getElementById(controlId + "btnSearch"))
        document.getElementById(controlId + "btnSearch").style.display = 'none';       
           
    return true;
}

function ValidatateChildAges_Packages(source, args)
{   
    var controlId;
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_ddlRooms"))   
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_";    
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendPackageControl_";    
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_ddlRooms"))    
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendPackageControl_";    
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_ddlRooms"))    
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendPackageControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControlDatePicker_";        
   if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_";
        
    var numRooms = document.getElementById(controlId + "ddlRooms").value;
    var valid = true;
    
    //Iterate through rooms
    for(i = 1; i <= numRooms; i++)
    {
          var numChildren = document.getElementById(controlId + "ddlPackagesChildrenRoom" + i).value;
        //Iterate through children
        for(j = 1; j <= numChildren; j++)
        {
            if(document.getElementById(controlId + "room" + i + "_child" + j + "_cell").value == 0)
                valid = false;            
        }
    }
    
    args.IsValid = valid;
}

function ValidatateChildAges_Accom(source, args)
{  
    var numRooms = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms").value;
    var valid = true;
    
    //Iterate through rooms
    for(i = 1; i <= numRooms; i++)
    {
          var numChildren = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlAccomChildrenRoom" + i).value;
        //Iterate through children
        for(j = 1; j <= numChildren; j++)
        {
            if(document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_room" + i + "_child" + j + "_cell").value == 0)
                valid = false;            
        }
    }
    args.IsValid = valid;
}

function ValidateChildAges_Flight(source, args)
{
    var controlId
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightAdults"))    
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_";        
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))    
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_";    
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_ddlFlightAdults"))    
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_";    
    if(document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_ddlFlightAdults"))    
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_";
    if(document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_ddlFlightAdults"))
        controlId =   "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_";
       
    var numChildren = document.getElementById(controlId + "ddlFlightChildren").value;
    var valid = true;
    var count = 1;
    
    //iterate through children
    for(i = 1; i <= numChildren; i++)
    {   
        if(document.getElementById(controlId + "child" + i + "_cell").value == 0)       
            valid = false;        
    }
    
    args.IsValid = valid;
}

window.scrollTo = function() { }


function showRoomsWarning() {
    if (document.getElementById("ctl00_ContentPlaceHolder_SearchControl01_AccommodationControl_ddlRooms")) {
        if (document.getElementById("ctl00_ContentPlaceHolder_SearchControl01_AccommodationControl_ddlRooms").value > 1) {
            document.getElementById("accomRoomWarning").style.display = "block";
        }
        else {
            document.getElementById("accomRoomWarning").style.display = "none";
        }
    }
    if (document.getElementById("ctl00_ContentPlaceHolder_SearchControl01_PackagesControl_ddlRooms")) {
        if (document.getElementById("ctl00_ContentPlaceHolder_SearchControl01_PackagesControl_ddlRooms").value > 1) {
            document.getElementById("packagesRoomWarning").style.display = "block";
        }
        else {
            document.getElementById("packagesRoomWarning").style.display = "none";
        }
    }
    if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms")) {
        if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms").value > 1) {
            document.getElementById("accomRoomWarning").style.display = "block";
        }
        else {
            document.getElementById("accomRoomWarning").style.display = "none";
        }
    }
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_ddlRooms")) {
        if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendPackageControl_ddlRooms").value > 1) {
            document.getElementById("packagesRoomWarning").style.display = "block";
        }
        else {
            document.getElementById("packagesRoomWarning").style.display = "none";
        }
    }
}

function selectairport() {
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightDepPoint")) {
        setTimeout("selectdeparture()", 1000);
    }
}

function selectdeparture() {
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightDepPoint")) {
        var dropdown = document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightDepPoint");
        for (var i = 0; i < dropdown.length; i++) {
            if (dropdown[i].value == 'Exeter') dropdown.selectedIndex = i;
        }
    }
}

var firstLoad = true;


function showRooms(type, type2) {
    var controlId;
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_Amend" + type + "Control_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_Amend" + type + "Control_";
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmend" + type + "Control_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmend" + type + "Control_";
    if (document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_Amend" + type + "Control_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_Amend" + type + "Control_";
    if (document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmend" + type + "Control_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmend" + type + "Control_";
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_Amend" + type + "ControlDatePicker_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_Amend" + type + "ControlDatePicker_";
    if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_ddlRooms"))
        controlId = "ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControlLeft_";

    if (!controlId)
        return;

    //Get the number of rooms  
    var numRooms = document.getElementById(controlId + "ddlRooms").value;

    if (!numRooms)
        return;

    // show or hide the children
    checkChildrenFlights(1, type, type2, controlId);
    checkChildrenFlights(2, type, type2, controlId);
    checkChildrenFlights(3, type, type2, controlId);
    checkChildrenFlights(4, type, type2, controlId);

    if (document.getElementById("divChildInfoRoom1"))
        document.getElementById("divChildInfoRoom1").style.display = 'none';


    for (childNumber = 2; childNumber <= 4; childNumber++) {
        // hide the room controls that dont need to show  
        document.getElementById(controlId + "tbl" + type2 + "adtionPaxRoom" + childNumber).style.display = 'none'
        document.getElementById(controlId + "room" + childNumber).style.display = 'none'
        document.getElementById("divChildInfoRoom" + childNumber).style.display = 'none';
    }

    var numChildren = document.getElementById(controlId + "ddl" + type2 + "ChildrenRoom1").value;

    if (numChildren != 0)
        document.getElementById("divChildInfoRoom1").style.display = '';

    if (numRooms >= 2) {
        document.getElementById(controlId + "tbl" + type2 + "adtionPaxRoom2").style.display = ''
        document.getElementById(controlId + "room2").style.display = ''
        if (document.getElementById(controlId + "ddl" + type2 + "ChildrenRoom2").value != 0)
            document.getElementById("divChildInfoRoom2").style.display = '';
    }
    if (numRooms >= 3) {
        document.getElementById(controlId + "tbl" + type2 + "adtionPaxRoom3").style.display = ''
        document.getElementById(controlId + "room3").style.display = ''
        if (document.getElementById(controlId + "ddl" + type2 + "ChildrenRoom3").value != 0)
            document.getElementById("divChildInfoRoom3").style.display = '';
    }
    if (numRooms >= 4) {
        document.getElementById(controlId + "tbl" + type2 + "adtionPaxRoom4").style.display = ''
        document.getElementById(controlId + "room4").style.display = ''
        if (document.getElementById(controlId + "ddl" + type2 + "ChildrenRoom4").value != 0)
            document.getElementById("divChildInfoRoom4").style.display = '';
    }

    if (firstLoad) {
        firstLoad = false;
        document.getElementById("divChildInfoRoom1").style.display = 'none';
        document.getElementById("divChildInfoRoom2").style.display = 'none';
        document.getElementById("divChildInfoRoom3").style.display = 'none';
        document.getElementById("divChildInfoRoom4").style.display = 'none';
    }
}

function checkChildrenFlights(roomNumber, type, type2, controlId) {
    var numChildren = document.getElementById(controlId + "ddl" + type2 + "ChildrenRoom" + roomNumber).value;

    for (childNumber = 1; childNumber <= 4; childNumber++) {
        document.getElementById(controlId + "room" + roomNumber + "_child" + childNumber + "_cell").style.display = "none";
        document.getElementById(controlId + "room" + roomNumber + "_child" + childNumber + "_head").style.display = "none";
    }
    if (numChildren >= 1) {
        document.getElementById(controlId + "room" + roomNumber + "_child1_cell").style.display = "";
        document.getElementById(controlId + "room" + roomNumber + "_child1_head").style.display = "";
    }
    if (numChildren >= 2) {
        document.getElementById(controlId + "room" + roomNumber + "_child2_cell").style.display = "";
        document.getElementById(controlId + "room" + roomNumber + "_child2_head").style.display = "";
    }
    if (numChildren >= 3) {
        document.getElementById(controlId + "room" + roomNumber + "_child3_cell").style.display = "";
        document.getElementById(controlId + "room" + roomNumber + "_child3_head").style.display = "";
    }
    if (numChildren >= 4) {
        document.getElementById(controlId + "room" + roomNumber + "_child4_cell").style.display = "";
        document.getElementById(controlId + "room" + roomNumber + "_child4_head").style.display = "";
    }
}

function checkChildren(roomNumber, type, type2) {
    if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom" + roomNumber)) {
        var numChildren = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom" + roomNumber).value;
        for (childNumber = 1; childNumber <= 4; childNumber++) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell").style.display = "none";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_head").style.display = "none";

            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell2").style.display = "none";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_head2").style.display = "none";
            }
        }
        if (numChildren >= 1) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child1_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child1_head").style.display = "";
        }
        if (numChildren >= 2) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child2_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child2_head").style.display = "";
        }
        if (numChildren >= 3) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child3_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child3_head").style.display = "";
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child3_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child3_cell2").style.display = "";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child3_head2").style.display = "";
            }
        }
        if (numChildren >= 4) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child4_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child4_head").style.display = "";
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child4_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child4_cell2").style.display = "";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + roomNumber + "_child4_head2").style.display = "";
            }
        }
    }
    else {
        var numChildren = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_ddl" + type2 + "ChildrenRoom" + roomNumber).value;
        for (childNumber = 1; childNumber <= 4; childNumber++) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell").style.display = "none";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_head").style.display = "none";

            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_cell2").style.display = "none";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child" + childNumber + "_head2").style.display = "none";
            }
        }
        if (numChildren >= 1) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child1_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child1_head").style.display = "";
        }
        if (numChildren >= 2) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child2_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child2_head").style.display = "";
        }
        if (numChildren >= 3) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child3_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child3_head").style.display = "";
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child3_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child3_cell2").style.display = "";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child3_head2").style.display = "";
            }
        }
        if (numChildren >= 4) {
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child4_cell").style.display = "";
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child4_head").style.display = "";
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child4_cell2")) {
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child4_cell2").style.display = "";
                document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AffiliateAmend" + type + "Control1_room" + roomNumber + "_child4_head2").style.display = "";
            }
        }
    }
}

function showAccomRooms(type, type2) {
    if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms")) {
        //Get the number of rooms
        var numRooms = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_AmendAccommodationControl1_ddlRooms").value;

        // show or hide the children
        checkChildren(1, type, type2);
        checkChildren(2, type, type2);
        checkChildren(3, type, type2);
        checkChildren(4, type, type2);

        document.getElementById("divChildInfoRoom1").style.display = 'none';
        for (childNumber = 2; childNumber <= 4; childNumber++) {
            // hide the room controls that dont need to show  
            document.getElementById("tbl" + type2 + "PaxRoom" + childNumber).style.display = 'none'
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room" + childNumber).style.display = 'none'
            document.getElementById("divChildInfoRoom" + childNumber).style.display = 'none';
        }

        var numChildren = document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom1").value;
        if (numChildren != 0)
            document.getElementById("divChildInfoRoom1").style.display = '';

        if (numRooms >= 2) {
            document.getElementById("tbl" + type2 + "PaxRoom2").style.display = ''
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room2").style.display = ''
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom2").value != 0)
                document.getElementById("divChildInfoRoom2").style.display = '';
        }
        if (numRooms >= 3) {
            document.getElementById("tbl" + type2 + "PaxRoom3").style.display = ''
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room3").style.display = ''
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom3").value != 0)
                document.getElementById("divChildInfoRoom3").style.display = '';
        }
        if (numRooms >= 4) {
            document.getElementById("tbl" + type2 + "PaxRoom4").style.display = ''
            document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_room4").style.display = ''
            if (document.getElementById("ctl00_ContentPlaceHolder_AccomResultsControl_Amend" + type + "Control1_ddl" + type2 + "ChildrenRoom4").value != 0)
                document.getElementById("divChildInfoRoom4").style.display = '';
        }

        if (firstLoad) {
            firstLoad = false;
            document.getElementById("divChildInfoRoom1").style.display = 'none';
            document.getElementById("divChildInfoRoom2").style.display = 'none';
            document.getElementById("divChildInfoRoom3").style.display = 'none';
            document.getElementById("divChildInfoRoom4").style.display = 'none';
        }
    }
}

function showFlightChildren() {
    var controlId;
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_ddlFlightChildren"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControl_";
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_ddlFlightChildren"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AffiliateAmendFlightControl_";
    if (document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_ddlFlightChildren"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AmendFlightControl_";
    if (document.getElementById("ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_ddlFlightChildren"))
        controlId = "ctl00_ContentPlaceHolder_MulticomFlightResultsControl_AffiliateAmendFlightControl_";
    if (document.getElementById("ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_ddlFlightChildren"))
        controlId = "ctl00_ContentPlaceHolder_FlightResultsControl_AmendFlightControlDatePicker_";


    if (document.getElementById(controlId + "ddlFlightChildren")) {
        //Get the number of children
        var numChildren = document.getElementById(controlId + "ddlFlightChildren").value;

        //if rooms is 1 and children is 0 hide the grid
        if (numChildren == "0") {
            document.getElementById(controlId + "flightChildGrid").style.display = "none";
        }
        //else display the grid based on rooms and adults
        else {
            document.getElementById('divChildDiscount').style.display = "";

            //Show Grid
            document.getElementById(controlId + "flightChildGrid").style.display = "block";
            switch (numChildren) {
                case "1":
                    document.getElementById(controlId + "flightchild1").style.display = "block";
                    document.getElementById(controlId + "flightchild2").style.display = "none";
                    document.getElementById(controlId + "flightchild3").style.display = "none";
                    document.getElementById(controlId + "flightchild4").style.display = "none";
                    break;
                case "2":
                    document.getElementById(controlId + "flightchild1").style.display = "block";
                    document.getElementById(controlId + "flightchild2").style.display = "block";
                    document.getElementById(controlId + "flightchild3").style.display = "none";
                    document.getElementById(controlId + "flightchild4").style.display = "none";
                    break;
                case "3":
                    document.getElementById(controlId + "flightchild1").style.display = "block";
                    document.getElementById(controlId + "flightchild2").style.display = "block";
                    document.getElementById(controlId + "flightchild3").style.display = "block";
                    document.getElementById(controlId + "flightchild4").style.display = "none";
                    break;
                case "4":
                    document.getElementById(controlId + "flightchild1").style.display = "block";
                    document.getElementById(controlId + "flightchild2").style.display = "block";
                    document.getElementById(controlId + "flightchild3").style.display = "block";
                    document.getElementById(controlId + "flightchild4").style.display = "block";
                    break;
                default:
                    document.getElementById(controlId + "flightchild1").style.display = "none";
                    document.getElementById(controlId + "flightchild2").style.display = "none";
                    document.getElementById(controlId + "flightchild3").style.display = "none";
                    document.getElementById(controlId + "flightchild4").style.display = "none";
                    break;
            }
        }
    }
}

function chkAirlinesClickedPackage() {
    if (document.getElementById(flightSearchControl2Id + "chkAirlines").checked) {
        document.getElementById(flightSearchControl2Id + "divAirlineOperators").style.display = '';
    }
    else {
        document.getElementById(flightSearchControl2Id + "divAirlineOperators").style.display = 'none';
    }
}
