

//id is a #
//class is a .
function GetCardType() {

    //document.getElementById('BoardBasis').innerHTML
   // alert( $("#Cost").text() );


    //$("#RoomType option:selected").text()

    chosen = ""
    len = document.aspnetForm.paymentType.length

    for (i = 0; i < len; i++) {
        if (document.aspnetForm.paymentType[i].checked) {
            chosen = document.aspnetForm.paymentType[i].value
            break;
        }
    }


    switch (chosen) {
        case 'MSCD':
            Display = $("#HiddenTotal").text() * 1.015;
            break
        case 'VISA':
            Display = $("#HiddenTotal").text() * 1.015;
            break
        case 'AMEX':
            Display = $("#HiddenTotal").text() * 1.020;
            break
        default:
            Display = $("#HiddenTotal").text();
            break
    }


    $("#Cost").text(formatCurrency(Display));
    
}


function formatCurrency(num) {

    num = isNaN(num) || num === '' || num === null ? 0.00 : num;

    return addCommas( parseFloat(num).toFixed(2));

}

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}


function GetRoom1() {

    chosen1 = ""
    
    len1 = document.aspnetForm.RoomType1.length

    if (len1 > 0) {
        for (i = 0; i < len1; i++) {
            if (document.aspnetForm.RoomType1[i].checked) {
                chosen1 = document.aspnetForm.RoomType1[i].value
                break;
            }
        }
    } else {

        chosen1 = document.aspnetForm.RoomType1.value;

    }

    return chosen1;

}

function GetRoom2() {

    chosen2 = ""

    if (document.aspnetForm.RoomType2 != null) {
        len2 = document.aspnetForm.RoomType2.length

        if (len2 > 0) {
            for (i = 0; i < len2; i++) {
                if (document.aspnetForm.RoomType2[i].checked) {
                    chosen2 = document.aspnetForm.RoomType2[i].value
                    break;
                }
            }
        } else {
            chosen2 = document.aspnetForm.RoomType2.value;
        }
    }
    return chosen2;

}

function GetRoom3() {

    chosen3 = ""

    if (document.aspnetForm.RoomType3 != null) {
        len3 = document.aspnetForm.RoomType3.length

        if (len3 > 0) {
            for (i = 0; i < len3; i++) {
                if (document.aspnetForm.RoomType3[i].checked) {
                    chosen3 = document.aspnetForm.RoomType3[i].value
                    break;
                }
            }
        } else {
            chosen3 = document.aspnetForm.RoomType3.value;
        }
    }

    return chosen3;

}

function GetSelectedItem() {

    price1 = 0;
    price2 = 0;
    price3 = 0;
    
    chosen1 = ""
    chosen2 = ""
    chosen3 = ""


    chosen1 = GetRoom1();
    chosen2 = GetRoom2();
    chosen3 = GetRoom3();

    var mySplitResult1 = chosen1.split("*");
    var mySplitResult2 = chosen2.split("*");
    var mySplitResult3 = chosen3.split("*");

    for (i = 0; i < mySplitResult1.length; i++) {
        if (i == 1) {
            //document.getElementById('ctl00_ContentPlaceHolder1_Room_TotalPrice').innerHTML = mySplitResult[i];
            price1 = parseFloat(mySplitResult1[i]);
        }
        if (i == 2) {

            var BB = mySplitResult1[i];
            var Display;

            switch (BB) {
                case 'RO':
                    Display = 'Room only';
                    break
                case 'BB':
                    Display = 'Bed and Breakfast';
                    break
                case 'SC':
                    Display = 'Self Catering';
                    break
                case 'HB':
                    Display = 'Half Board';
                    break
                case 'FB':
                    Display = 'Full Board';
                    break
                case 'AI':
                    Display = 'All Inclusive';
                    break

            }


            document.getElementById('BoardBasis').innerHTML = Display;
            break;
        }
    }



    for (i = 0; i < mySplitResult2.length; i++) {
        if (i == 1) {            
            price2 = parseFloat(mySplitResult2[i]);
        }

    }

    for (i = 0; i < mySplitResult3.length; i++) {
        if (i == 1) {            
            price3 = parseFloat(mySplitResult3[i]);
        }

    }


    document.getElementById('ctl00_ContentPlaceHolder1_Room_TotalPrice').innerHTML = (price1 + price2 + price3);
           
} 




function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}



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 alertLinkSearchBox() {

    if (document.getElementById('txtCityTo') != null) {

        if (document.getElementById('txtCityTo').value == "") {
            // \n 
            alert('Please enter a holiday destination.');

            return false;
        }
    }

    if (document.getElementById('datepicker') != null) {

        if (document.getElementById('datepicker').value == "") {

            alert('Please select a departure date.');

            return false;
        }
    }


    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 alertBookPage() {

    if (document.getElementById('txtPAXDOB') != null) {

        if (document.getElementById('txtPAXDOB').value == "(dd/mm/yyyy)") {
            // \n 
            alert('Please enter a your date of birth.');

            return false;
        }
    }    

}




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: +5

    });

});



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.');
//})

    
