function TitulosGrid(gridN , dataIn) {
	this.gridName = gridN;
	this.grid;
	this.data = dataIn;
	var    me = this;
	
	this.columns = [
		            {header:"", name:"idTituloCnt", visible:false},
		            {header:"", name:"idLista"    , visible:false},
		            {header:"", name:"bajaPerdida", visible:false},
		            {header:"", name:"nombreUnico", visible:false},
		            
		            {header:me.makeSelectAll(),name:"idTitulo2",customRender : function(item, model,index) {
	            	    var name = "aux["+ index+"]."+model.name+"[0]";
	            	    var r ="";
	            	    if(item.idLista == $("#idLAvalable").val())		            	
	            	    	r+="<input class='idRow"+gridN+"' id='dyn1"+name+"' name='"+index+"' type='checkbox' />";		            	
	            	    return r; 
	            	    }
		            },
		            {header:"Titulo"  , name:"descTitulo" , width:'230'},
		            {header:"Episodio", name:"episodio"   , width:'230'},
		            {header:"Inicio"  , name:"fechaInicio", date:true , width:'150'},
		            {header:"Fin"     , name:"fechaFin"   , date:true , required:true , width:'150'},
		            {header:"VU"      , name:"vidaUtil"   , width:'90', readonly:true},
		            
		            {header:"Categor\u00EDa DDA",name:"pagoCateg",width:'150', customRender : function(item, model,index) { 
		            		var pagoCateg = "";
		            		if(typeof item.pagoCateg != 'undefined' && item.pagoCateg != null )		            	
		            			pagoCateg = item.pagoCateg.desc;		            		
		            		return pagoCateg; 		            		
		            	}},
		            
		            {header:"Categor\u00EDa",name:"categoriaTit",width:'150', customRender : function(item, model,index) { 
		            		var categoriaTit = "";
		            		if(typeof item.categoriaTit != 'undefined' && item.categoriaTit != null )		            		
		            		   categoriaTit = item.categoriaTit.desc;		            		
		            		return categoriaTit; 
		            	}
		            },
		            
		            {header:"", name:"temporada"  , width:'90',visible:false},
		            {header:"", name:"precioAnual", width:'90',visible:false, currency:true},
		            
		            {header:"Precio",name:"costoF",width:'90', customRender : me.renderCurrency},
		            
		            {header:"Amortizaci\u00F3n "+  $("#fechaAmortizacion").val()                , name:"amortizacion"      , width:'90', customRender : me.renderCurrency},
		            {header:"Amortizaci\u00F3n "+ ( parseInt($("#fechaAmortizacion").val())+1  ), name:"amortizacionDos"   , width:'90', customRender : me.renderCurrency},
		            {header:"Amortizaci\u00F3n "+ ( parseInt($("#fechaAmortizacion").val())+2  ), name:"amortizacionTres"  , width:'90', customRender : me.renderCurrency},
		            {header:"Amortizaci\u00F3n "+ ( parseInt($("#fechaAmortizacion").val())+3  ), name:"amortizacionCuatro", width:'90', customRender : me.renderCurrency},
		            
		            {header:"Briefcase",name:"briefcase",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name;
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled' " ;
		            	if(item.briefcase ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
		            },
		            
		            {header:"DTO",name:"dto",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name;
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled'" ;
		            	if(item.dto ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
		            },
		            
		            {header:"DTR",name:"dtr",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name;
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled'" ;
		            	if(item.dtr ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
		            },
		            
		            {header:"SD",name:"sd",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name+"[0]";
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled'" ;
	            		if(item.sd ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
		            },
		            
		            {header:"HD",name:"hd",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name+"[1]";
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled'" ;
	            		if(item.hd ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
	            	},
		            
	            	{header:"3D",name:"threed",customRender : function(item, model,index) {
	            	    var name = "titulos["+ index+"]."+model.name+"[2]";
	            		var r = "<input id='dyn1"+name+"' name='"+name+"' type='checkbox' disabled='disabled'" ;
	            		if(item.threed ) { r+= " checked='checked' "; }
	            	    r+=" />";
		            	return r; }
	            	},
		            
	            	{header:"Acciones",name:"formatos",customRender : function(item,model,index)
		            	{ 
		            	var r ="";
		            	
		            	if(item.idLista == $("#idLAvalable").val() && $("#estatusContrato").val() == '1')
		            	{
		            		r+=  "<a  href='#' name="+index+" onClick='titulosController.openEditRow(this)'><i class='fa fa-pencil'></i></a> | ";
		            		r+="<a  href='#' name="+index+" onClick='titulosController.openDeleteItem(this)'><i class='fa fa-times'></i></a>";
		            	}
		            	return r;}
		            }
 		            ];

	var _vc = [];
	this.columns.forEach(function(column, i) {
		if (column.visible != false) {
			_vc.push(column);
		}
	});

	this.visibleColumns = _vc;
	this.init();
}

TitulosGrid.prototype.getColumns = function(dataIn) {
	return this.columns;
};

TitulosGrid.prototype.reload = function(dataIn) {
	this.data = dataIn;
	this.grid.setItems(this.data);
	this.grid.init();
};

TitulosGrid.prototype.indexSelected = function() {
	var selected = [];
	$(".idRow" +this.gridName).each(function (){
		if(this.checked)
		{
			selected.push($(this).attr("name"));
		}
	});
	return selected;
};

TitulosGrid.prototype.itemsSelected = function() {
	var selected = this.indexSelected();
	var _items = [];
	for (var _i = 0; _i < selected.length ; _i++)
	{
		_items.push( this.getItemByIndex(selected[_i]));
	}
	return _items;
};

TitulosGrid.prototype.getItemByIndex = function(index) {
	var data = this.grid.getItems();
	if(index<=data.length)
	{
		return data[index];
	}
	else return [];
};

TitulosGrid.prototype.selectAll = function(item) {
	$(".idRow"+this.gridName).prop('checked',$(item).prop('checked'));
	
};

TitulosGrid.prototype.makeSelectAll = function() {
    return "<input class='idRow' id='dyn1' name='' type='checkbox' onClick='titulosController.grid.selectAll(this)' />";
};

TitulosGrid.prototype.init = function() {
	var me = this;
	me.grid = $("#"+me.gridName).dynTable({
		lazyInit : true,
		local    : true,
		prefix   : 'titulos',
		root     : 'titulos',
		colModel : me.visibleColumns,
        edit     : false,
        expand   : { "exp":true , "column":"descTitulo" , "attribute": "hijos"},
        dateFormatIn :"yy-mm-dd",
        dateFormatOut:"mm/dd/yy"
	});
	
	me.grid.setItems(me.data);
	me.grid.init();
	
};

TitulosGrid.prototype.renderCurrency = function(item, model,index,value) {
	var r = "<div align='right'>";
	if( value != "" && value != null && !isNaN(value))
	{
		var n = parseFloat(value);
		r += "$ " + n.formatDLA();
	}
	r+="</div>";
	return r;
};