﻿if ( !window.Entities )
    window.Entities = {};
    
Entities.Hotel = function( xmlData )
{
    if ( xmlData != undefined )
    {
        for ( var i=0; i<xmlData.childNodes.length; i++ )
        {
            if ( xmlData.childNodes[i].nodeName == "price" )
                this.price = xmlData.childNodes[i].childNodes[0].nodeValue;
            if ( xmlData.childNodes[i].nodeName == "stars" )
                this.stars = xmlData.childNodes[i].childNodes[0].nodeValue;
            if ( xmlData.childNodes[i].nodeName == "name" )
                this.name = xmlData.childNodes[i].childNodes[0].nodeValue;
            if ( xmlData.childNodes[i].nodeName == "phone" )
            {
                try { this.phone = xmlData.childNodes[i].childNodes[0].nodeValue; }
                catch (e) { this.phone = ""; }
            }
            if ( xmlData.childNodes[i].nodeName == "address" )
            {
                try { this.address = xmlData.childNodes[i].childNodes[0].nodeValue; }
                catch (e) { this.address = ""; }
            }
            if ( xmlData.childNodes[i].nodeName == "city" )
                this.city = xmlData.childNodes[i].childNodes[0].nodeValue;
        }
    }
}

Entities.Hotel.prototype.price = null;
Entities.Hotel.prototype.stars = null;
Entities.Hotel.prototype.name = null;
Entities.Hotel.prototype.phone = null;
Entities.Hotel.prototype.address = null;
Entities.Hotel.prototype.city = null;

Entities.Hotel.prototype.getPrice = function()
{
    return this.price;
}
Entities.Hotel.prototype.getStars = function()
{
    return this.stars;
}
Entities.Hotel.prototype.getName = function()
{
    return this.name;
}
Entities.Hotel.prototype.getPhone = function()
{
    return this.phone;
}
Entities.Hotel.prototype.getAddress = function()
{
    return this.address;
}
Entities.Hotel.prototype.getCity = function()
{
    return this.city;
}

Entities.Hotel.prototype.isHotel = function( o )
{
    if (Object.getTypeName(o) == "Object")
    {
        var me = [ "price","stars","name","phone","address","city" ];
        var he = this.getKeys( o );
        if ( me.length != he.length )
            return false;
        else
        {
            for ( var i=0; i<he.length; i++ )
                if ( !this.isInArray(me,he[i]) )
                    return false;
            return true;
        }
    }
    return false;
}

Entities.Hotel.prototype.getKeys = function( o )
{
    if (o==undefined) o = this;
    var arr = [];
    for ( var j in o )
        arr.push(j);
    return arr;
}

Entities.Hotel.prototype.isInArray = function(arr,item)
{
    for (var i=0; i<arr.length; i++)
        if ( arr[i] == item )
            return true;
    return false;
}