﻿function min(field, minlength) {
    if (field.length < minlength)
        return true;
    else
        return false
}

function HotelNamesFromWS() {
    MyAjaxClass.GetDefaultHotelNames(HotelNames_callback, null, null, null, onTimeoutHotelNames, null);
}
function onTimeoutHotelNames() {
    return false;
}
function HotelNames_callback(r) {
    window.status = ""
    if (r == null) return;
    if (r.error != null) {
        alert(r.error.Message);
        return;
    }
    var res = r.value;
    HotelNamesResult(res.HotelNames);
}
function HotelNamesResult(res){
    yazi = '';
    if (res != null) {
            yazi += '<ul class="list">';
            for (var i = 0; i < res.length; i++) {
                if (i!=res.length){
                    yazi += '<li><a id="'+res[i].HotelID+'" href="#">'+ res[i].Name +'</a></li>';
                }
                else{
                    yazi += '<li class="last"><a id="'+res[i].HotelID+'" href="#">'+ res[i].Name +'</a></li>';
                }
            }
            yazi += '</ul>';
            document.getElementById("hotel_names").innerHTML = yazi;
            HotelsFromWS()
    }
}

function HotelsFromWS() {
    MyAjaxClass.GetDefaultHotels(Hotels_callback, null, null, null, onTimeoutHotels, null);
}
function onTimeoutHotels() {
    return false;
}
function Hotels_callback(r) {
    window.status = ""
    if (r == null) return;
    if (r.error != null) {
        alert(r.error.Message);
        return;
    }
    var res = r.value;
    HotelsResult(res.Hotels);
}
function HotelsResult(res){
    yazi = '';
    if (res != null) {
            var mCount=1;
            yazi += '<ul class="column-list">';
            for (var i = 0; i < res.length; i++) {
                if (mCount % 3 == 0){
                    
                    
                    yazi += '<li class="last">';
                    yazi += '<h2>' + res[i].Name + '&nbsp;/&nbsp;' + res[i].Region + '</h2>';
                    yazi += '<img width="190" height="121" src="Console/' + res[i].Image + '" alt=""/>';
                    yazi += '<p>' + res[i].Description + '</p>';
                    yazi += '</li>';
                    
                }
                else{
                    yazi += '<li>';
                    yazi += '<h2>' + res[i].Name + '&nbsp;/&nbsp;' + res[i].Region + '</h2>';
                    yazi += '<img width="190" height="121" src="Console/' + res[i].Image + '" alt=""/>';
                    yazi += '<p>' + res[i].Description + '</p>';
                    yazi += '</li>';
                }
                mCount++;
            }
            yazi += '</ul>';
            document.getElementById("rightside").innerHTML = yazi;
    }
}
