﻿/*Public*///////////////////////////////////////////////////////////////
function GetCheckInCheckoutShamsi(checkinDate, nights) {
    $get('lblCheckindateShamsi').innerHTML = "";
    $get('lblCheckoutDateShamsi').innerHTML = "";
    WebService.GetCheckInCheckoutShamsi(checkinDate, nights, function(Dates) { $get('lblCheckindateShamsi').innerHTML = " معادل " + Dates.split(",")[0]; $get('lblCheckoutDateShamsi').innerHTML = " معادل " + Dates.split(",")[1]; }, null);
}

function SaveInTextBox1(curr_Year, curr_month, curr_day, NumberOfNights) {
    var CheckOutDate = new Date(curr_Year, curr_month, curr_day);
    CheckOutDate.setDate(CheckOutDate.getDate() + NumberOfNights);


    if (curr_day.toString().length == 1) { curr_day = "0" + curr_day; }
    curr_month = parseInt(curr_month) + 1;
    if (curr_month.toString().length == 1) { curr_month = "0" + curr_month; }

    HFCheckIn.value = curr_Year + "/" + curr_month + "/" + curr_day;


    curr_day = CheckOutDate.getDate();
    if (curr_day.toString().length == 1) { curr_day = "0" + curr_day; }
    curr_month = parseInt(CheckOutDate.getMonth()) + 1;
    if (curr_month.toString().length == 1) { curr_month = "0" + curr_month; }

    HFCheckOut.value = CheckOutDate.getFullYear() + "/" + curr_month + "/" + curr_day;
    GetCheckInCheckoutShamsi(HFCheckIn.value, NumberOfNights);
}
//-----------------------------------------------------------------
function SetRoomTypeDDLSelected1(Value, drp, number) {

    if (Value == 1) { drp[0].selected = true; }
    if (Value == 2) { drp[1].selected = true; }
    if (Value == 6) { drp[2].selected = true; }
    if (Value == 3) { drp[3].selected = true; }
    if (Value == 4) { drp[4].selected = true; }


}
//-----------------------------------------------------------------
function Set_ExtraBed_Child_Visibility1(number, val) {

    ex1 = chExtraBed + number;
    child = DDLChildrenCount + number;
    if (val == 0)//apartment
    {
        $get(ex1).parentNode.disabled = false;
        $get(ex1).disabled = false;
        $get(child).parentNode.disabled = false
        $get(child).disabled = false;
    }
    else {
        //hotel
        //Otage 2 nafareh extrabed nadare
        if (val == 2 || val == 6) {
            $get(ex1).parentNode.disabled = false;
            $get(ex1).disabled = false;
        }
        else {
            $get(ex1).parentNode.disabled = true;
            $get(ex1).disabled = true;

        }

        //Otaghe Single bache nadare
        if (val == 1) {
            $get(child).parentNode.disabled = true;
            $get(child).disabled = true;
        }
        else {
            $get(child).parentNode.disabled = false;
            $get(child).disabled = false;
        }
    }
}
/*EndPublic*///////////////////////////////////////////////////////////////


/*Setdate*///////////////////////////////////////////////////////////////
function AddItems1(dropList, Text, Value) {
    var myOption;
    newOption = document.createElement("Option");
    newOption.text = Text;
    newOption.Value = Value;
    newOption.value = Value;
    dropList.options.add(newOption);
}
//-----------------------------------------------------------------
function daysInMonth1(month, year) {
    month++;
    var dd = new Date(year, month, 0);
    return dd.getDate();

}
//-----------------------------------------------------------------
function SetNightNo1(e) {
    var Checkin_month = drpCheckinMounth.options[drpCheckinMounth.selectedIndex].value;
    var Checkin_day = drpCheckinDay.options[drpCheckinDay.selectedIndex].value;
    var Checkin_Yeartt = drpCheckinMounth.options[drpCheckinMounth.selectedIndex].text;
    var Checkin_Year = Checkin_Yeartt.substring(Checkin_Yeartt.indexOf(" ") + 1);

    var Checkout_month = lblChechoutMounth.options[lblChechoutMounth.selectedIndex].value;
    var Checkout_day = lblChechoutDay.options[lblChechoutDay.selectedIndex].value;
    var Checkout_Yeartt = lblChechoutMounth.options[lblChechoutMounth.selectedIndex].text;
    var Checkout_Year = Checkout_Yeartt.substring(Checkout_Yeartt.indexOf(" ") + 1);

    var CheckinDate = new Date(Checkin_Year, Checkin_month, Checkin_day);
    var CheckoutDate = new Date(Checkout_Year, Checkout_month, Checkout_day);


    var CheckinDate1 = Date.parse(CheckinDate);
    var CheckoutDate1 = Date.parse(CheckoutDate);
    var datedif = (CheckoutDate1 - CheckinDate1) / (24 * 60 * 60 * 1000);

    if (datedif <= 15) {
        DDLNight[datedif - 1].selected = true;
        SaveInTextBox1(Checkin_Year, Checkin_month, Checkin_day, datedif);
    }
    else {
        alert('برای اقامت بیشتر از 15 شب لطفا با ما تماس بگیرید')
        DDLNight[14].selected = true;
        FillAllDate1();
    }

}
//-----------------------------------------------------------------
function FillMonth1(drp, SelectDateChekin, NumberOfNights) {
    FillMonth(drp, SelectDateChekin, NumberOfNights)
}

//-----------------------------------------------------------------
function FillDay1(drp, SelectDateChekin, NumberOfNights) {
    FillDay(drp, SelectDateChekin, NumberOfNights)

}
//function FillMonth1(drp, SelectDateChekin, NumberOfNights) {
//    var m_names = new Array("January", "February", "March",
//                "April", "May", "June", "July", "August", "September",
//                "October", "November", "December");

//    //find CheckIn Date
//    var Chekin_month = SelectDateChekin.getMonth();
//    var Chekin_day = SelectDateChekin.getDate();
//    var Chekin_Year = SelectDateChekin.getFullYear();
//    //find Selected Date (baraye chekinDDL NumberOfNights=0 ast)
//    var Select_date = new Date(Chekin_Year, Chekin_month, Chekin_day);
//    Select_date.setDate(Select_date.getDate() + NumberOfNights);

//    //var Start_date = new Date();
//    var Start_date = new Date(CurrentDate_Year, CurrentDate_Month, 1);
//    var startMonth = Start_date.getMonth();
//    var Select_index;


//    MaxMounthForReserve = 3; //12
//    drp.options.length = 0;
//    for (i = 1; i < MaxMounthForReserve +1; i++) {

//        var curr_month = Start_date.getMonth();
//        var Text = m_names[curr_month] + '  ' + Start_date.getFullYear();
//        var Value = curr_month;


//        AddItems1(drp, Text, Value);

//        if (curr_month == Select_date.getMonth()) { Select_index = i - 1; } //find selected index in dropdown


//        var t = startMonth + i;
//        if (t > MaxMounthForReserve) { t = t - MaxMounthForReserve; }
//       // alert(Select_index + "," + i + "," + t + "," + curr_month + "," + Select_date.getMonth())
//        Start_date.setMonth(t); //dafeh aval set nemishe

//        //Start_date.setMonth(t); //dafeh dovom set mishe
//    }
//    drp[Select_index].selected = true;
//}

////-----------------------------------------------------------------
//function FillDay1(drp, SelectDateChekin, NumberOfNights) {
//    var First_day;
//    var End_days;
//    var Year;
//    var Month;
//    var SelectDay;

//    //var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
//    var dayNames = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

//    //find Selected Date
//    var Chekin_month = SelectDateChekin.getMonth();
//    var Chekin_day = SelectDateChekin.getDate();
//    var Chekin_Year = SelectDateChekin.getFullYear();
//    var Chekin_date = new Date(Chekin_Year, Chekin_month, Chekin_day);
//    var ChekOut_date = new Date(Chekin_Year, Chekin_month, Chekin_day);
//    //age darim drop downl avalo por mikonim
//    if (NumberOfNights == 0) {
//        End_days = daysInMonth1(Chekin_month, Chekin_Year);
//        Year = Chekin_Year;
//        Month = Chekin_month;
//        SelectDay = Chekin_day;
//        //age chekinmonth ba mahe current yeki nabashe rooz az 1 bashe
//        //if (Chekin_month != new Date().getMonth())
//        if (Chekin_month != new Date(CurrentDate_Year, CurrentDate_Month, CurrentDate_Day).getMonth())
//        { First_day = 1 }
//        else
//        { First_day = new Date(CurrentDate_Year, CurrentDate_Month, CurrentDate_Day).getDate(); }
//        //{ First_day = new Date().getDate(); }
//    }
//    else//drpchekout ast
//    {
//        ChekOut_date.setDate(Chekin_date.getDate() + NumberOfNights);
//        //bayad tarikhe select shodeh ro rozaye mahesho biareh
//        var ChekOut_month = ChekOut_date.getMonth();
//        var ChekOut_Year = ChekOut_date.getFullYear();
//        Year = ChekOut_Year;
//        Month = ChekOut_month;
//        SelectDay = ChekOut_date.getDate();
//        End_days = daysInMonth1(ChekOut_month, ChekOut_Year);
//        //age mahe checkin ba mahe checkout yeki ast 
//        //az roze (checkin be bad ro neshon bede vagarna az avale mah
//        if (ChekOut_month != Chekin_month)
//        { First_day = 1 }
//        else
//        { First_day = Chekin_day + 1; }
//    }

//    if (SelectDay < First_day)//age cookie ye rozi ro set kardeh bashe ke gozashteh
//    { SelectDay = First_day } //First_day ro select koneh

//    //alert(First_day + ',' + End_days + ',' + SelectDay + ',')
//    var Select_index;
//    drp.options.length = 0;
//    var j = 0;
//    for (i = First_day; i <= End_days; i++) {
//        var now = new Date(Year, Month, i);
//        var Text = dayNames[now.getDay()] + '  ' + i;
//        var Value = i;
//        AddItems1(drp, Text, Value);
//        if (i == SelectDay) { Select_index = j; } //find selected index in dropdown
//        j++;
//    }
//    drp[Select_index].selected = true;
//}
//-----------------------------------------------------------------
function FillAllDate1(Command) {
    var curr_month = drpCheckinMounth.options[drpCheckinMounth.selectedIndex].value;

    var tt = drpCheckinMounth.options[drpCheckinMounth.selectedIndex].text;
    var curr_Year = tt.substring(tt.indexOf(" ") + 1);

    if (Command == 'FillCheckInDay') {
        //age valin mah entekhab shode bayad avalin rooz to dropdown emrooz bashe
        var CurrentDate;
        if (drpCheckinMounth.selectedIndex == 0) {
            CurrentDate = new Date(curr_Year, curr_month, new Date(CurrentDate_Year, CurrentDate_Month, CurrentDate_Day).getDate());
        }
        else {
            CurrentDate = new Date(curr_Year, curr_month, 1);
        }
        FillDay1(drpCheckinDay, CurrentDate, 0)
    }
    //FillMonth1(drpCheckinMounth, CurrentDate,0)


    var curr_day = drpCheckinDay.options[drpCheckinDay.selectedIndex].value;
    var StartDate = new Date(curr_Year, curr_month, curr_day);

    NumberOfNights = DDLNight.selectedIndex + 1;
    
    FillMonth1(drpCheckoutMounth, StartDate, NumberOfNights);

    FillDay1(drpCheckoutDay, StartDate, NumberOfNights);

    SaveInTextBox1(curr_Year, curr_month, curr_day, NumberOfNights);
}
//-----------------------------------------------------------------
function FillAllDate1OnStartUp1(Select_Year, Select_month, Select_day, NumberOfNights) {



    var SelectDate;
    //    if (Select_Year == undefined) {
    if (NumberOfNights == undefined) {
            //SelectDate = new Date();
            SelectDate = new Date(CurrentDate_Year, CurrentDate_Month, CurrentDate_Day);
            SelectDate.setDate(SelectDate.getDate() + 2);
            NumberOfNights = 1;
        }
        else {
            SelectDate = new Date(Select_Year, Select_month, Select_day);
            
        }



    FillDay1(drpCheckinDay, SelectDate, 0)
    FillMonth1(drpCheckinMounth, SelectDate, 0)
    FillMonth1(drpCheckoutMounth, SelectDate, NumberOfNights);
    FillDay1(drpCheckoutDay, SelectDate, NumberOfNights);
    SaveInTextBox1(SelectDate.getFullYear(), SelectDate.getMonth(), SelectDate.getDate(), NumberOfNights);
    //TODO:Farhad-Mehdi: Farhad jan. man ino khodam ezafe kardam. bebin doroste?
    DDLNight.value = NumberOfNights;


    //inital First Hotel room to be double
    //if ((Select_Year == '' && Select_month == '') || (Select_Year == undefined && Select_month == undefined)) {
    if (NumberOfNights == undefined) {
        //alert(Select_Year)
        //alert(Select_month)

        SetRoomTypeDDLSelected1(2, DDLRomeType1)
        SetRoomTypeDDLSelected1(2, DDLRomeType2)
        SetRoomTypeDDLSelected1(2, DDLRomeType3)
        SetRoomTypeDDLSelected1(2, DDLRomeType4)
        SetRoomTypeDDLSelected1(2, DDLRomeType5)
    }
}



/*EndSetdate*///////////////////////////////////////////////////////////////







function RoomTypeDDLSelectedChanged1(drp, HA, number) {

    var val = drp.options[drp.selectedIndex].value;
    if (HA == 1) {//hotel

        Set_ExtraBed_Child_Visibility1(number, val);

        switch (number) {
            case 1:
                SelectedHotelDropDown1 = val;
                break;
            case 2:
                SelectedHotelDropDown2 = val;
                break;
            case 3:
                SelectedHotelDropDown3 = val;
                break;
            case 4:
                SelectedHotelDropDown4 = val;
                break;
            case 5:
                SelectedHotelDropDown5 = val;
                break;
            default:
                //nothing
        }
    }
    else { //apartment
        switch (number) {
            case 1:
                SelectedApartmentDropDown1 = val;
                break;
            case 2:
                SelectedApartmentDropDown2 = val;
                break;
            case 3:
                SelectedApartmentDropDown3 = val;
                break;
            case 4:
                SelectedApartmentDropDown4 = val;
                break;
            case 5:
                SelectedApartmentDropDown5 = val;
                break;
            default:
                //nothing
        }
    }
}
//-----------------------------------------------------------------
function RoomNumberChanged1() {
    //drpRoomNumber = $get('ctl00_ContentPlaceHolder1_DDLRoomNo');
    val = drpRoomNumber.options[drpRoomNumber.selectedIndex].value;
    switch (val) {
        case '1':
            Utility.show1('PanelRooms1');
            Utility.hide1('PanelRooms2');
            Utility.hide1('PanelRooms3');
            Utility.hide1('PanelRooms4');
            Utility.hide1('PanelRooms5');
            break;
        case '2':
            Utility.show1('PanelRooms1');
            Utility.show1('PanelRooms2');
            Utility.hide1('PanelRooms3');
            Utility.hide1('PanelRooms4');
            Utility.hide1('PanelRooms5');
            break;
        case '3':
            Utility.show1('PanelRooms1');
            Utility.show1('PanelRooms2');
            Utility.show1('PanelRooms3');
            Utility.hide1('PanelRooms4');
            Utility.hide1('PanelRooms5');
            break;
        case '4':
            Utility.show1('PanelRooms1');
            Utility.show1('PanelRooms2');
            Utility.show1('PanelRooms3');
            Utility.show1('PanelRooms4');
            Utility.hide1('PanelRooms5');
            break;
        case '5':
            Utility.show1('PanelRooms1');
            Utility.show1('PanelRooms2');
            Utility.show1('PanelRooms3');
            Utility.show1('PanelRooms4');
            Utility.show1('PanelRooms5');
            break;


    }
    //vase inke bar asase serch type hotel ya apartment help ro show hide koneh
    PrepareSearchType1()
}
//-----------------------------------------------------------------
function NumberofChildrenChanged1(drpID, drpChild1ID, drpChild2ID, lblChild1ID, lblChild2ID) {
    drpChildNumber = $get(drpID)
    val = drpChildNumber.options[drpChildNumber.selectedIndex].value;

    switch (val) {
        case '0':
            Utility.hide3(drpChild1ID);
            Utility.hide3(lblChild1ID);
            Utility.hide3(drpChild2ID);
            Utility.hide3(lblChild2ID);
            break;
        case '1':
            Utility.show3(drpChild1ID);
            Utility.show3(lblChild1ID);
            Utility.hide3(drpChild2ID);
            Utility.hide3(lblChild2ID);
            break;
        case '2':
            Utility.show3(drpChild1ID);
            Utility.show3(lblChild1ID);
            Utility.show3(drpChild2ID);
            Utility.show3(lblChild2ID);
            break;
    }

}
//-----------------------------------------------------------------
function PrepareSearchType1(changeapartmenthotelwitheachother) {
    //alert($get('ctl00_SearchHotelControl1_RbtnShearchInHotel').checked)
    //if ($get('ctl00_ContentPlaceHolder1_RbtnShearchInHotel').checked == true) {
//    drpHotelApartment = $get('ctl00_ContentPlaceHolder1_DropDownListHotelApartment');

//    if (drpHotelApartment.options[drpHotelApartment.selectedIndex].value==0) {
        Utility.show1(lnkClose1);

        //alert(Utility.IsHidden('PanelRooms2'))
        if (Utility.IsHidden('PanelRooms2') == false)
            Utility.show1(lnkClose1);
        else
            Utility.hide1(lnkClose2);

        if (Utility.IsHidden('PanelRooms3') == false)
            Utility.show1(lnkClose3);
        else
            Utility.hide1(lnkClose3);

        if (Utility.IsHidden('PanelRooms4') == false)
            Utility.show1(lnkClose4);
        else
            Utility.hide1(lnkClose4);

        if (Utility.IsHidden('PanelRooms5') == false)
            Utility.show1(lnkClose5);
        else
            Utility.hide1(lnkClose5);



        ////dar in ghesmat meghdare selectde hotel va aparteman ba ham yeki mishe t aba avaz kardane type search hamon no otagh baz entekhgab beshe
        if (changeapartmenthotelwitheachother != '1') {
            //alert(33)
            if ((SelectedApartmentDropDown1 == 5) || (SelectedApartmentDropDown1 == 6))
            { SelectedHotelDropDown1 = 2 } //donafare
            else { SelectedHotelDropDown1 = SelectedApartmentDropDown1; }

            if ((SelectedApartmentDropDown2 == 5) || (SelectedApartmentDropDown2 == 6))
            { SelectedHotelDropDown2 = 2 } //donafare
            else { SelectedHotelDropDown2 = SelectedApartmentDropDown2; }

            if ((SelectedApartmentDropDown3 == 5) || (SelectedApartmentDropDown3 == 6))
            { SelectedHotelDropDown3 = 2 } //donafare
            else { SelectedHotelDropDown3 = SelectedApartmentDropDown3; }

            if ((SelectedApartmentDropDown4 == 5) || (SelectedApartmentDropDown4 == 6))
            { SelectedHotelDropDown4 = 2 } //donafare
            else { SelectedHotelDropDown4 = SelectedApartmentDropDown4; }

            if ((SelectedApartmentDropDown1 == 5) || (SelectedApartmentDropDown5 == 6))
            { SelectedHotelDropDown5 = 2 } //donafare
            else { SelectedHotelDropDown5 = SelectedApartmentDropDown5; }
//        }
        //alert(0)
        //alert(SelectedHotelDropDown1)



        CreateHotelRoomTypeDDL(1, DDLRomeType1);
        CreateHotelRoomTypeDDL(2, DDLRomeType2);
        CreateHotelRoomTypeDDL(3, DDLRomeType3);
        CreateHotelRoomTypeDDL(4, DDLRomeType4);
        CreateHotelRoomTypeDDL(5, DDLRomeType5);

        //age double ya twin nist disabkle beshe
        Set_ExtraBed_Child_Visibility1(1, DDLRomeType1.options[DDLRomeType1.selectedIndex].value);
        Set_ExtraBed_Child_Visibility1(2, DDLRomeType2.options[DDLRomeType2.selectedIndex].value);
        Set_ExtraBed_Child_Visibility1(3, DDLRomeType3.options[DDLRomeType3.selectedIndex].value);
        Set_ExtraBed_Child_Visibility1(4, DDLRomeType4.options[DDLRomeType4.selectedIndex].value);
        Set_ExtraBed_Child_Visibility1(5, DDLRomeType5.options[DDLRomeType5.selectedIndex].value);


    }
//    else {
//        Utility.hide1('ctl00_ContentPlaceHolder1_lnkClose1');
//        Utility.hide1('ctl00_ContentPlaceHolder1_lnkClose2');
//        Utility.hide1('ctl00_ContentPlaceHolder1_lnkClose3');
//        Utility.hide1('ctl00_ContentPlaceHolder1_lnkClose4');
//        Utility.hide1('ctl00_ContentPlaceHolder1_lnkClose5');

//        //alert(1)
//        //alert(SelectedApartmentDropDown1)
//        ////dar in ghesmat meghdare selectde hotel va aparteman ba ham yeki mishe t aba avaz kardane type search hamon no otagh baz entekhgab beshe
//        if (changeapartmenthotelwitheachother != '1') {
//            //alert(22)
//            if (SelectedHotelDropDown1 != 6)
//            { SelectedApartmentDropDown1 = SelectedHotelDropDown1; }
//            else { SelectedApartmentDropDown1 = 2 } //donafare

//            if (SelectedHotelDropDown2 != 6)
//            { SelectedApartmentDropDown2 = SelectedHotelDropDown2; }
//            else { SelectedApartmentDropDown2 = 2 } //donafare

//            if (SelectedHotelDropDown3 != 6)
//            { SelectedApartmentDropDown3 = SelectedHotelDropDown3; }
//            else { SelectedApartmentDropDown3 = 2 } //donafare

//            if (SelectedHotelDropDown4 != 6)
//            { SelectedApartmentDropDown4 = SelectedHotelDropDown4; }
//            else { SelectedApartmentDropDown4 = 2 } //donafare

//            if (SelectedHotelDropDown5 != 6)
//            { SelectedApartmentDropDown5 = SelectedHotelDropDown5; }
//            else { SelectedApartmentDropDown5 = 2 } //donafare
//        }



//        CreateApartmentRoomTypeDDL(1, DDLRomeType1);
//        CreateApartmentRoomTypeDDL(2, DDLRomeType2);
//        CreateApartmentRoomTypeDDL(3, DDLRomeType3);
//        CreateApartmentRoomTypeDDL(4, DDLRomeType4);
//        CreateApartmentRoomTypeDDL(5, DDLRomeType5);

//        //age double ya twin nist disabkle beshe
//        Set_ExtraBed_Child_Visibility1(1, 0);
//        Set_ExtraBed_Child_Visibility1(2, 0);
//        Set_ExtraBed_Child_Visibility1(3, 0);
//        Set_ExtraBed_Child_Visibility1(4, 0);
//        Set_ExtraBed_Child_Visibility1(5, 0);
//    }
}



