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: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",required:true,width:'230'},
		            {header:"HVRD",name:"hvrd",date:true,required:true,width:'150'},
		            {header:"Inicio",name:"fechaInicio",date:true,required:true,width:'150'},
		            {header:"Fin",name:"fechaFin",date:true,required:true,width:'150'},
		            {header:"Categoria",name:"categoria",required:true,width:'150',
		            	customRender : function(item, model,index) { 
		            		var categoDesc = "";
		            		if(typeof item.categoria != 'undefined' && item.categoria != null )
		            		{
		            			categoDesc = item.categoria.desc;
		            		}
		            		return categoDesc; 
		            		
		            	}
		            },
		            {header:"Release",name:"release",required:true,width:'150',
		            	customRender : function(item, model,index) { 
		            		var r = "";
		            		if(typeof item.release != 'undefined' && item.release != null )
		            		{
		            			r = item.release.desc;
		            		}
		            		return r; 
		            		
		            	}
		            }, {header:"Tipo Titulo",name:"tipoTitulo",required:true,width:'180'  },
		            {header:"Briefcase",name:"briefcase",required:true,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",required:true,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",required:true,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",required:true,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",required:true,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",required:true,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",required:true,customRender : function(item,model,index)
		            	{ 
		            	var r ="";
		            	if(item.idLista == $("#idLAvalable").val())
		            	{
		            		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();
	
};