

//id is a #
//class is a .

$('#flight_only').hide();
$('#ddlPackCityTo').hide();

if ( document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Packages !=null )
{
    if (document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Packages.checked) {
             
        $('#ddlCityTo').show();
        $('#txtCityTo').hide();
        $('#FlightFrom').show();
        $('#AirlineMenu').show();
        $('#flight_only').hide();

    }
}


//     if ($("#datepicker").val() == null) {
//        $("#datepicker").val(getDate())
//     }
//    

//     function getDate() {
//         var date = new Date()
//         var year = date.getFullYear()
//         var month = date.getMonth()
//         var day = date.getDay()
//         var today = month + "/" + day + "/" + year

//         return today
//
//     }

function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}

function MapAreaDisplay(r) {

    $(".MapText").hide();
    $("#MapText" + r).show();

}

function popUp2(URL) {
    window.open(URL, 'CallBack', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=755,height=610,left = 240,top = 240');
}

function popUp(URL) {
    window.open(URL, 'CallBack', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=645,height=440,left = 240,top = 240');
}


function alertLinkPackageSearch() {

    if (document.getElementById('datepicker') != null) {

        var currentTime = new Date()
        var month = currentTime.getMonth()
        var day = currentTime.getDate() + 5
        var year = currentTime.getFullYear()

        var mytoday = new Date();
        mytoday.setFullYear(year, month, day);


        var userDate = new Date();
        userDate.setFullYear(document.getElementById('datepicker').value.substr(6, 4), document.getElementById('datepicker').value.substr(3, 2) - 1, document.getElementById('datepicker').value.substr(0, 2));

        if (userDate < mytoday) {

            alert('Please select a departure date 5 days inadvance.');

            return false;
        }


    }

}

function alertLinkSearchBox() {

    
    //if(document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Flight.checked) 
  //  {
            //do flight check
//            if (document.getElementById('FlyingFrom') != null) 
//            {
//                if (document.getElementById('FlyingFrom').value == "") 
//                {
//                    alert('Please enter Flying From');
//                    return false;
//                }
//            }
//            
//             if (document.getElementById('FlyingTo') != null) {
//                if (document.getElementById('FlyingTo').value == "") {
//                    alert('Please enter Flying To');
//                    return false;
//                }
//            }

//            if (document.getElementById('datepicker01') != null) {

//                if (document.getElementById('datepicker01').value == "") {

//                    alert('Please select a departure date.');

//                    return false;
//                }
//                
//                
//                var currentTime = new Date()
//                var month = currentTime.getMonth()
//                var day = currentTime.getDate() + 5
//                var year = currentTime.getFullYear()

//                var mytoday = new Date();
//                mytoday.setFullYear(year, month, day);


//                var userDate = new Date();
//                userDate.setFullYear(document.getElementById('datepicker01').value.substr(6, 4), document.getElementById('datepicker01').value.substr(3, 2) - 1, document.getElementById('datepicker01').value.substr(0, 2));

//                if (userDate < mytoday) {

//                    alert('Please select a departure date 5 days in advance.');

//                    return false;
//                }
//                    
//                    
//            }
//            if (document.getElementById('datepicker1') != null) {

//                if (document.getElementById('datepicker1').value == "") {

//                    alert('Please select a return date.');

//                    return false;
//                }
//            }
//            
//            if (document.getElementById('datepicker01') != null && document.getElementById('datepicker01') != null) 
//            {
//                    
//                var d = document.getElementById('datepicker01').value.split('/');
//                var d2 = document.getElementById('datepicker1').value.split('/');

//                var Date1 = new Date(d[2], d[1]*1-1, d[0]);
//                var Date2 = new Date(d2[2], d2[1]*1-1, d2[0]);
//            
//                DaysDiff = Math.floor((Date1.getTime() - Date2.getTime())/(1000*60*60*24));
//            
//                if(DaysDiff > 0)
//                {
//                    alert('Return date must be greater than the Departure date.');
//                    return false;            
//                }
//            }
//            
//            document.getElementById('datepicker').value = document.getElementById('datepicker01').value;
            
   // }
   // else 
  //  {
        
//        if (document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Flight_Hotel.checked) 
//        {
//            if (document.getElementById('txtCityFrom') != null) 
//            {
//                if (document.getElementById('txtCityFrom').value == "") 
//                {
//                    alert('Please enter Frlying From.');
//                    return false;
//                }
//            }
//            
//             if (document.getElementById('txtCityTo').value == "") 
//             {
//                alert('Please enter destination');
//                return false;
//            }
//        }
//            

       // if (document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Holidays.checked) {
               
                if (document.getElementById('ddlCityTo') != null) {

                    if (document.getElementById('ddlCityTo').value == "") {
                        // \n 
                        alert('Please select a holiday destination.');

                        return false;
                    }
                }


         //   }

          //  if (document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Hotel.checked) {
               // if (document.getElementById('txtCityTo').value.toLowerCase() == "maldives") {

                //    alert('Sorry this destination is not available');

                ///    return false;
              //  }
           // }

//            if (document.aspnetForm.ctl00_ContentPlaceHolder1_Search1_Hotel.checked) {
//                if (document.getElementById('datepicker') != null) {

//                    var currentTime = new Date()
//                    var month = currentTime.getMonth()
//                    var day = currentTime.getDate() + 5
//                    var year = currentTime.getFullYear()

//                    var mytoday = new Date();
//                    mytoday.setFullYear(year, month, day);


//                    var userDate = new Date();
//                    userDate.setFullYear(document.getElementById('datepicker').value.substr(6, 4), document.getElementById('datepicker').value.substr(3, 2) - 1, document.getElementById('datepicker').value.substr(0, 2));

//                    if (userDate < mytoday) {

//                        alert('Please select a departure date 5 days inadvance.');

//                        return false;
//                    }


//                }
//            }


            if (document.getElementById('datepicker') != null) {

                if (document.getElementById('datepicker').value == "") {

                    alert('Please select a departure date.');

                    return false;
                }
            }
   //  }
   
}

function alertLinkDateBox() {
    if (document.getElementById('datepicker') != null) {

        if (document.getElementById('datepicker').value == "") {
            
            alert('Please select a departure date.');

            return false;
        }
    }
}
function SetNewPriceHotel(ValueString)
{
    var ValueString;
    var PriceArray = ValueString.split('*');
    var NewPrice = PriceArray[1];
    var NewPricePP = PriceArray[3];
    
    //1:2:0:0:DBT-TH1:ST*1077.42*BB*75.65
    document.getElementById('ctl00_ContentPlaceHolder1_Room_TotalPrice1').innerHTML = NewPrice;
    document.getElementById('ctl00_ContentPlaceHolder1_Room_TotalPrice2').innerHTML = NewPrice;
    document.getElementById('ctl00_ContentPlaceHolder1_Room_TotalPrice3').innerHTML = NewPricePP;    
}

function DisableDays(date) {
    // var noDisable = $.datepicker.DisableDays(date);
    // return [false, 'CLOSED'];

    var test1 = date.getDate();


    return [true, ''];
}


$(function() {



    $('#datepicker').datepicker({
        numberOfMonths: 2,
        showButtonPanel: true,
        showOn: 'button',
        buttonImage: '/media/JQuery/UI/calendar.gif',
        buttonText: 'Please select a travel date',
        buttonImageOnly: true,
        duration: 'fast',
        dateFormat: "dd/mm/yy",
        beforeShowDay: DisableDays,
        
        minDate: 0

    });


    $('#datepicker').click(function () {
        $('#datepicker').datepicker('show'); 
     }); 


});


//ADD by waq

function DisableDays2(date) {
    // var noDisable = $.datepicker.DisableDays(date);
    // return [false, 'CLOSED'];
    var date = '16/12/2010';
    return [true, date];
}

function setDatePicker() {
    if(document.getElementById('datepicker1').value=='') {
        document.getElementById('datepicker1').value = document.getElementById('datepicker01').value;
        document.getElementById('datepicker1').style.color ='#FFFFFF';
    }
}
function setDatePicker2() {
    document.getElementById('datepicker1').style.color ='#000000';
}

var date = new Date();
var m = date.getMonth(), d = date.getDate()+5, y = date.getFullYear();
var m2 = date.getMonth(), d2 = date.getDate()+6, y2 = date.getFullYear();

$(
    function() {
    $('#datepicker01').datepicker({
       
        numberOfMonths: 2,
        showButtonPanel: true,
        showOn: 'button',
        buttonImage: 'http://www.bestattravel.co.uk/media/JQuery/UI/calendar.gif',
        buttonText: 'Please select a travel date',
        buttonImageOnly: true,
        duration: 'fast',
        dateFormat: "dd/mm/yy",
        beforeShowDay: DisableDays,
        onSelect: function (){setDatePicker();},
        minDate: new Date(y, m, d)
    });
});

$(
    
    function() {

    $('#datepicker1').datepicker({
    
        numberOfMonths: 2,
        showButtonPanel: true,
        showOn: 'button',
        buttonImage: 'http://www.bestattravel.co.uk/media/JQuery/UI/calendar.gif',
        buttonText: 'Please select a travel date',
        buttonImageOnly: true,
        duration: 'fast',
        dateFormat: "dd/mm/yy",
        beforeShowDay: DisableDays,
        minDate: new Date(y2, m2, d2),
        onSelect: function (){setDatePicker2();}

    });

});
//End ADD by waq

function ChangeRooms()
{
    switch ($("#cboRooms option:selected").text()) {

        case "1":
            $('#BSRT-Room2-positioner').hide();

            $('#Room2_Child_Group').hide();
            $('#cboChild1_2_Group').hide();
            $('#cboChild2_2_Group').hide();
            $('#cboChild3_2_Group').hide();


            $('#BSRT-Room3-positioner').hide();

            $('#Room3_Child_Group').hide();
            $('#cboChild1_3_Group').hide();
            $('#cboChild2_3_Group').hide();
            $('#cboChild3_3_Group').hide();

            break;

        case "2":
            $('#BSRT-Room2-positioner').show();
            $('#BSRT-Room3-positioner').hide();

            $('#Room3_Child_Group').hide();
            $('#cboChild1_3_Group').hide();
            $('#cboChild2_3_Group').hide();
            $('#cboChild3_3_Group').hide();

            break;
        case "3":
            $('#BSRT-Room2-positioner').show();
            $('#BSRT-Room3-positioner').show();
            break;

    }
}


$("#cboRooms").change(function() {
    ChangeRooms();
})


$("#cboChild1").change(function() {

    ChangeChild1();

})

function ChangeChild1() {

    switch ($("#cboChild1 option:selected").text()) {
        case "0":
            $('#Room1_Child_Group').hide();
            $('#cboChild1_1_Group').hide();
            $('#cboChild2_1_Group').hide();
            $('#cboChild3_1_Group').hide();
            break;

        case "1":
            $('#Room1_Child_Group').show();
            $('#cboChild1_1_Group').show();
            $('#cboChild2_1_Group').hide();
            $('#cboChild3_1_Group').hide();
            break;
        case "2":
            $('#Room1_Child_Group').show();
            $('#cboChild1_1_Group').show();
            $('#cboChild2_1_Group').show();
            $('#cboChild3_1_Group').hide();
            break;
        case "3":
            $('#Room1_Child_Group').show();
            $('#cboChild1_1_Group').show();
            $('#cboChild2_1_Group').show();
            $('#cboChild3_1_Group').show();
            break;

    }
    
    
}

$("#cboChild2").change(function() {
    ChangeChild2();
})


function ChangeChild2() {

    switch ($("#cboChild2 option:selected").text()) {
        case "0":
            $('#Room2_Child_Group').hide();
            $('#cboChild1_2_Group').hide();
            $('#cboChild2_2_Group').hide();
            $('#cboChild3_2_Group').hide();
            break;

        case "1":
            $('#Room2_Child_Group').show();
            $('#cboChild1_2_Group').show();
            $('#cboChild2_2_Group').hide();
            $('#cboChild3_2_Group').hide();
            break;
        case "2":
            $('#Room2_Child_Group').show();
            $('#cboChild1_2_Group').show();
            $('#cboChild2_2_Group').show();
            $('#cboChild3_2_Group').hide();
            break;
        case "3":
            $('#Room2_Child_Group').show();
            $('#cboChild1_2_Group').show();
            $('#cboChild2_2_Group').show();
            $('#cboChild3_2_Group').show();
            break;

    }
    
}

$("#cboChild3").change(function() {
    ChangeChild3();
})

function ChangeChild3() {

    switch ($("#cboChild3 option:selected").text()) {
        case "0":
            $('#Room3_Child_Group').hide();
            $('#cboChild1_3_Group').hide();
            $('#cboChild2_3_Group').hide();
            $('#cboChild3_3_Group').hide();
            break;

        case "1":
            $('#Room3_Child_Group').show();
            $('#cboChild1_3_Group').show();
            $('#cboChild2_3_Group').hide();
            $('#cboChild3_3_Group').hide();
            break;
        case "2":
            $('#Room3_Child_Group').show();
            $('#cboChild1_3_Group').show();
            $('#cboChild2_3_Group').show();
            $('#cboChild3_3_Group').hide();
            break;
        case "3":
            $('#Room3_Child_Group').show();
            $('#cboChild1_3_Group').show();
            $('#cboChild2_3_Group').show();
            $('#cboChild3_3_Group').show();
            break;

    }

}

// $("#cboAdults1").change(function() {
//      alert('Handler for ' + $("#cboAdults1 option:selected").text() + ' called.');
//})
function checkInOutOptions(jtype)
{
    var outbound = document.getElementsByName('SelectOutbound');
    var inbound =  document.getElementsByName('SelectInbound');
    var jtype;
    
    var ocnt = 0;
    var incnt = 0;
    
    for(var i = 0; i < outbound.length; i++)
    {
        if(outbound[i].checked) 
        {
            ocnt = 1;   
        }
    }
    
    if(jtype=='ONEWAY' && ocnt>0) 
    {
        return true;
    }
    
    for(var i = 0; i < inbound.length; i++)
    {
        if(inbound[i].checked) 
        {
            incnt = 1;
        }
    }
    
    if(ocnt==0 || incnt==0) 
    {
       return false;
    }
    return true;
    
}
function checkInboundOptions(inprice) 
{
    var outbound = document.getElementsByName('SelectOutbound');
    var outprice;
    var inprice;
    for(var i = 0; i < outbound.length; i++) 
    {
        if(outbound[i].checked) 
        {
            outprice = outbound[i].value;
            outprice = outprice.split("_");
            outprice = outprice[2];
            
            if(outprice!=inprice) 
            {
                outbound[i].checked = false;
            }
        }
    }
}
function checkOutboundOptions(outprice) {
    var inbound = document.getElementsByName('SelectInbound');
    var outprice;
    var inprice;
    
	for(var i = 0; i < inbound.length; i++) 
	{
		if(inbound[i].checked) 
		{
		    inprice = inbound[i].value;
		    inprice = inprice.split("_");
		    inprice = inprice[2];
		    
		    if(outprice!=inprice) {
		        inbound[i].checked = false;
		    }	
		}
	}
    
}
function chooseCheapest(airlinename) {

    var SortAirline = airlinename;
	pathArray = window.location.href.split( '?' );
	var newPathname = pathArray[pathArray.length-1];
	newPathname = newPathname.replace('SortAirlineCheapNav','s'+airlinename);
	var url = newPathname+'&SortAirlineCheapNav='+SortAirline;
	window.location.replace('?'+url);
	//alert(url);

}

