
function RoomSearch() {
    var room_type = document.getElementById('room_type').value;
    var check_in_date = document.getElementById('check_in_date').value;
    var nights = document.getElementById('nights').value;
    var adults = document.getElementById('adults').value;
    var children = document.getElementById('children').value;
    var rooms = document.getElementById('rooms').value;
    var age1 = document.getElementById('age1');
    var age2 = document.getElementById('age2');
    var tarihFormat = document.getElementById('TarihFormat');


    if (children == 1) {
        if (age1.value == "") {
            alert("Please select a Child 1 Age");
            age1.focus();
            return false;
        }
    }
    else if (children == 2) {
        if (age1.value == "") {
            alert("Please select a Child 1 Age");
            age1.focus();
            return false;
        }

        if (age2.value == "") {
            alert("Please select a Child 2 Age");
            age2.focus();
            return false;
        }
    }

    var today = new Date();
    var ci = Date.parse(check_in_date);
    today = today.clearTime();
    ci = ci.clearTime();
    var format = "MM/dd/yyyy";
    if (tarihFormat != null) {
        format = tarihFormat.value;
    }

    var tarihENFormatlanmisHali = ci.toString(format);
    if (today <= ci) {
        var query = "sid=" + encodeURI(sid) +
                       "&rt=" + encodeURI(room_type) +
                       "&ci=" + encodeURI(tarihENFormatlanmisHali) +
                       "&ng=" + encodeURI(nights) +
                       "&ro=" + encodeURI(rooms) +
                       "&ad=" + encodeURI(adults) +
                       "&ch=" + encodeURI(children) +
                       "&a1=" + encodeURI(age1.value) +
                       "&a2=" + encodeURI(age2.value) +
                       "&sr=1";
        //parent.location.href = "https://www.bestreserver.com/sistemonline/Default.aspx?" + query;
        parent.location.href = returnUrl + "?" + query;

    }
    else {
        alert('Please select a date from tomorrow');
    }
}
function RoomSearchGroup() {
    var room_type = document.getElementById('room_type').value;
    var check_in_date = document.getElementById('check_in_date').value;
    var nights = document.getElementById('nights').value;
    var adults = document.getElementById('adults').value;
    var children = document.getElementById('children').value;
    var rooms = document.getElementById('rooms').value;
    var age1 = document.getElementById('age1');
    var age2 = document.getElementById('age2');
    var tarihFormat = document.getElementById('TarihFormat');

    var today = new Date();
    var ci = Date.parse(check_in_date);
    today = today.clearTime();
    ci = ci.clearTime();

    var format = "MM/dd/yyyy";
    if (tarihFormat != null) {
        format = tarihFormat.value;
    }
    var tarihENFormatlanmisHali = ci.toString(format);

    var query = "rt=" + encodeURI(room_type) +
                       "&ci=" + encodeURI(tarihENFormatlanmisHali) +
                       "&ng=" + encodeURI(nights) +
                       "&ro=" + encodeURI(rooms) +
                       "&ad=" + encodeURI(adults) +
                       "&ch=" + encodeURI(children) +
                       "&a1=" + encodeURI(age1.value) +
                       "&a2=" + encodeURI(age2.value) +
                       "&sr=0";


    var query = "sid=" + encodeURI(sid) +
                       "&rt=" + encodeURI(room_type) +
                       "&ci=" + encodeURI(check_in_date) +
                       "&ng=" + encodeURI(nights) +
                       "&ro=" + encodeURI(rooms) +
                       "&ad=" + encodeURI(adults) +
                       "&ch=" + encodeURI(children) +
                       "&a1=" + encodeURI(age1.value) +
                       "&a2=" + encodeURI(age2.value) +
                       "&sr=0";
    //1 ise direkt arar 0 ise indexe yonlenir durur.
    //parent.location.href = "https://www.bestreserver.com/sistemonline/Default.aspx?" + query;
    parent.location.href = returnUrl + "?" + query;
}
function CalenderSetup() {
    var currentTime = new Date();
    //currentTime.add(1).days();

    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var tarih = month + "/" + day + "/" + year;

    var kullanilacakTarihFormat = 'mm/dd/yy';

    //var turkTarihiMi = GetQSValue('TurkTarihiMi');
    var tarihFormat = document.getElementById('TarihFormat');
    if (tarihFormat != null && tarihFormat.value == "dd/MM/yyyy") {
        kullanilacakTarihFormat = "dd/mm/yy";
        tarih = day + "/" + month + "/" + year;
    }
    document.getElementById("check_in_date").value = tarih;
    $(document).ready(function() {
        $('#check_in_date').datepicker({ dateFormat: kullanilacakTarihFormat });
    });


    CocukSayiAyarla();
}

function CocukSayiAyarla() {

    var cocukNesneAd = '#children';
    var odaTipNesneAd = '#room_type';
    var odaTipId = $(odaTipNesneAd).val();
    var cocukSayi = odaKapasite[odaTipId];
    $(cocukNesneAd).empty();

    for (i = 0; i <= cocukSayi; i++) {
        $(cocukNesneAd).append($('<option></option>').val(i).html(i.toString()));
    }
    YasGoster();
}
function YasGoster() {
    var children = document.getElementById("children");
    var lbl1 = document.getElementById("lblage1");
    var lbl2 = document.getElementById("lblage2");
    var age1 = document.getElementById("age1");
    var age2 = document.getElementById("age2");

    if (children.value == 0) {
        age1.selectedIndex = 0;
        age1.style.display = "none";
        age2.selectedIndex = 0;
        age2.style.display = "none";
        lbl1.style.display = "none";
        lbl2.style.display = "none";
    }
    else if (children.value == 1) {
        age1.selectedIndex = 0;
        age1.style.display = "block";
        age2.selectedIndex = 0;
        age2.style.display = "none";
        lbl1.style.display = "block";
        lbl2.style.display = "none";
    }
    else if (children.value == 2) {
        age1.selectedIndex = 0;
        age1.style.display = "block";
        age2.selectedIndex = 0;
        age2.style.display = "block";
        lbl1.style.display = "block";
        lbl2.style.display = "block";
    }
}




function GetQSValue(findName) {
    var name = new String();
    var value = new String();
    var querystring = document.location.href;
    if (querystring.indexOf("?") == -1) {
        return "null";
    }
    querystring = querystring.split("?");
    querystring = querystring[1].split("&");
    for (q = 0; q < querystring.length; q++) {
        var pair = querystring[q].split("=");
        name = pair[0].toLowerCase();
        value = pair[1].toLowerCase();
        if (findName.toLowerCase() == name) {
            return value;
        }
    }
}  
