/**************************************
@Clase jsChannels 
***************************************
@Autor: Sergio Cerrillo
@Fecha: 2007/08/24
@Dependencia: xmlParser.js 
@
*/

var jsChannels = Class.create();

jsChannels.prototype = {

	/**********************************************************************************************
	* Constructor
	**********************************************************************************************/
	initialize: function(idChannel, longName, shortName, logo, channelTypes){

		/*==========================================================================
		== Variables Channel
		==========================================================================*/
		this._idChannel=idChannel;
		this._longName=longName;
		this._shortName=shortName;
		this._logo=logo;
		this._channelTypes=channelTypes;

		/*==========================================================================
		== Variables obligatorias
		==========================================================================*/
		this._objOwner = this;
		this._error=false;
		this._errorTxt="";

	},

	/**********************************************************************************************
	* whoIam
	**********************************************************************************************/
	whoIam: function(){
		alert("jsChannels.js");
	},
	
	/**********************************************************************************************
	* parserChannels
	**********************************************************************************************/
	parserChannels: function(xmlsrc)
	{
		var retorno = Array();
		var xotree = new XML.ObjTree();
		tree = xotree.parseXML( xmlsrc );
		
		if (tree!=undefined && tree.Channels!= undefined && tree.Channels.Channel!=undefined)
		{
		    if(!tree.Channels.Channel.length)
		    {
		        this._idChannel=tree.Channels.Channel["-id"];
        		this._longName=tree.Channels.Channel.longName;
        		this._shortName=tree.Channels.Channel.shortName;
        		this._logo=tree.Channels.Channel.logo;
        		var chtypes=Array();
        		if (tree.Channels.Channel.channelTypes!=undefined)
        		{
        		    for (var j=0; j < tree.Channels.Channel.channelTypes.length; j++)
        		    {
        			    chtypes[j] = tree.Channels.Channel.channelTypes[j].types;
        			}
    			}
    			this._channelTypes=chtypes;
    			retorno[0] = new jsChannels(this._idChannel, this._longName, this._shortName, this._logo, this._channelTypes);
		    }
		    else 
		    {
                for (var i=0; i < tree.Channels.Channel.length; i++)
        		{
        		    this._idChannel=tree.Channels.Channel[i]["-id"];
        			this._longName=tree.Channels.Channel[i].longName;
        			this._shortName=tree.Channels.Channel[i].shortName;
        			this._logo=tree.Channels.Channel[i].logo;
        			var chtypes=Array();
        			if (tree.Channels.Channel[i].channelTypes!=undefined)
        			{
        			    for (var j=0; j < tree.Channels.Channel[i].channelTypes.length; j++)
        			    {
        				    chtypes[j] = tree.Channels.Channel[i].channelTypes[j].types;
        				}
    				}
    				this._channelTypes=chtypes;
    				retorno[i] = new jsChannels(this._idChannel, this._longName, this._shortName, this._logo, this._channelTypes);
    			}
    		}		
		}
		
		return retorno;
	}
};
