newsi.GridManager=function(o){
this.gebid(o.containerDiv).setAttribute("width",o.width);
this.summary=o.summary;
this._order=o.order;
this._group=[];
this._el={};
this._item=[];
this.gDataLen=o.gDataLen;
this.maxNumItems=o.maxNumItems;
this.maxShowableItems=o.maxShowableItems;
this.blockOneTxt=o.blockOneTxt;
this.drpDwnLblOne=o.drpDwnLblOne;
this.drpDwnLblTwo=o.drpDwnLblTwo;
this.buttonTxt=o.buttonTxt;
this._headers=[];
this.choice0="0";
this.choice1="1";
// start...
if(this.hasDOM()){
	this.doRead();
	this.doWrite();
	}
}
newsi.GridManager.prototype=newsi.html;
newsi.GridManager.prototype.doRead=function(){
this.getGroups();
this.dom=new newsi.HTML.DOM(this._el);
this.dom.setClass({el:this.gebid("no_script"),className:"none"})
this.populateObject();
this.getHeaders();
this.clearContent();
}
newsi.GridManager.prototype.getGroups=function(){
var x=0;
while(this.gebid("group"+x)){
	this._el["group"+x]="group"+x;
	this._group[x]={};
	x++;
	}
}
newsi.GridManager.prototype.getHeaders=function(){
var x=0;
while(x<this.maxNumItems){
	this._headers[x]=this.dom.gebtn({parent:this.gebid("gp0h"+x),el:"h4"})[0].innerHTML;
	x++;
	}
}
newsi.GridManager.prototype.populateObject=function(){
this.iterateThroughGroups("getGroupData");
this.iterateThroughGroups("getItemData");
}
newsi.GridManager.prototype.iterateThroughGroups=function(method){
var x=0;
while(this.dom["group"+this._order[x]]){this[method]({el:this.dom["group"+this._order[x]],num:this._order[x]});x++;}
}
newsi.GridManager.prototype.getGroupData=function(o){
for(var i=0;i<this.gDataLen;i++){
	if(this.gebid("gp"+o.num+"g"+i)){this._group[o.num]["g"+i]=this.gebid("gp"+o.num+"g"+i).innerHTML;}else{this._group[o.num]["g"+i]="";}
	}
}
newsi.GridManager.prototype.getItemData=function(o){
for(var i=0;i<this.maxNumItems;i++){
	if(this.gebid("gp"+o.num+"iCnd")){this._group[o.num]["iCnd"]=this.gebid("gp"+o.num+"iCnd").innerHTML;}else{this._group[o.num]["iCnd"]="";}
	if(this.gebid("gp"+o.num+"i"+i)){this._group[o.num]["i"+i]=this.gebid("gp"+o.num+"i"+i).innerHTML;}else{this._group[o.num]["i"+i]="";}
	if(this.gebid("gp"+o.num+"hCnd")){this._group[o.num]["hCnd"]=this.gebid("gp"+o.num+"hCnd").innerHTML;}else{this._group[o.num]["hCnd"]="";}
	if(this.gebid("gp"+o.num+"h"+i)){this._group[o.num]["h"+i]=this.gebid("gp"+o.num+"h"+i).innerHTML;}else{this._group[o.num]["h"+i]="";}
	}
}
newsi.GridManager.prototype.clearContent=function(){this.dom.iH({el:this.gebid("mainwrapper"),text:""});}
newsi.GridManager.prototype.doWrite=function(){
this.changeMarkup();
this.createForm();
};
newsi.GridManager.prototype.changeMarkup=function(o){
if(this.gebid("choice0")){this.choice0=this.gebid("choice0").value}
if(this.gebid("choice1")){this.choice1=this.gebid("choice1").value}

this.dom.iH({el:this.gebid("mainwrapper"),text:""});
this.iterateThroughGroups("writeGroupData");
}
newsi.GridManager.prototype.writeGroupData=function(o){
var thead=this.dom.cE({el:"thead"});
var tr=this.dom.cE({el:"tr"});
this.dom.setClass({el:tr,className:"gridrow"});

var th=this.dom.cE({el:"th"});
this.dom.setClass({el:th,className:"column0"});
//th.setAttribute("width","229");
this.dom.iH({el:th,text:this._group[o.num]["hCnd"]});
this.dom.setId({el:th,id:"gp"+o.num+"hCnd"});
this.dom.aC({parent:tr,el:th});

for(var i=0;i<this.maxShowableItems;i++){
	var th=this.dom.cE({el:"th"});
	this.dom.setClass({el:th,className:"column"+(i+1)});
	this.dom.iH({el:th,text:this._group[o.num]["h"+this["choice"+i]]});
	this.dom.setId({el:th,id:"gp"+o.num+"h"+i});
	this.dom.aC({parent:tr,el:th});
	}
	
this.dom.aC({parent:thead,el:tr});
var tbl=this.dom.cE({el:"table"});
this.dom.setId({el:tbl,id:("group"+o.num)});
tbl.setAttribute("border","0");
tbl.setAttribute("summary",this.summary);
tbl.setAttribute("cellPadding","0");
tbl.setAttribute("cellSpacing","0");
tbl.setAttribute("width","629");
this.dom.setClass({el:tbl,className:"gridlayout cndTbl"});
this.dom.aC({parent:tbl,el:thead});
var tbody=this.dom.cE({el:"tbody"});
var tr=this.dom.cE({el:"tr"});
this.dom.setClass({el:tr,className:"gridrow"});

var td=this.dom.cE({el:"td"});
this.dom.setClass({el:td,className:"column0"});
//td.setAttribute("width","229");
this.dom.iH({el:td,text:this._group[o.num]["iCnd"]});
this.dom.setId({el:td,id:"gp"+o.num+"iCnd"});
this.dom.aC({parent:tr,el:td});

for(var i=0;i<this.maxShowableItems;i++){
	var td=this.dom.cE({el:"td"});
	this.dom.setClass({el:td,className:"column"+(i+1)});
	//td.setAttribute("width","200");
	this.dom.iH({el:td,text:this._group[o.num]["i"+this["choice"+i]]});
	this.dom.setId({el:td,id:"gp"+o.num+"i"+i});
	this.dom.aC({parent:tr,el:td});
	}
	
this.dom.aC({parent:tbody,el:tr});
this.dom.aC({parent:tbl,el:tbody});
this.dom.aC({parent:this.gebid("mainwrapper"),el:tbl});
}
newsi.GridManager.prototype.createForm=function(){
var fm=this.dom.cE({el:"form"});
this.createSelect({parent:fm,num:0});
this.createSelect({parent:fm,num:1});

this.dom.iH({el:this.gebid("block1"),text:'<div class="issuesCta">'+this.blockOneTxt+'</div>'});

//this.dom.iH({el:this.gebid("block2"),text:'<div class="issuesCtaArr">'+this.drpDwnLblOne+'</div>'});

this.dom.aC({parent:this.gebid("block2"),el:fm});
var ev=new newsi.Event();
ev.addListener("onchange","choice0",this,"changeMarkup",false);
ev.addListener("onchange","choice1",this,"changeMarkup",false);
}
newsi.GridManager.prototype.createSelect=function(o){
var ddTxt=o.num+1;
var div=this.dom.cE({el:"div"});
this.dom.setClass({el:div,className:"selectDiv"});
this.dom.iH({el:div,text:'<span class=\"issuesCta\">'+ddTxt+"</span><img src=\"/nol/shared/bsp/hi/elections/london/08/issues/img/rt_arr.gif\" width=\"7\" height=\"12\" alt=\"\" border=\"0\" class=\"issuesImgInline\">"});
var sel=this.dom.cE({el:"select"});
this.dom.setId({el:sel,id:("choice"+o.num)});
this.dom.setClass({el:sel,className:"dropdown"});
this.createOption({selected:sel,num:o.num});
this.dom.aC({parent:div,el:sel});
//if(o.num==1){this.addButton({num:o.num,divtag:div});}
sel.options[Number(this["choice"+o.num])].selected=true;
this.dom.aC({parent:o.parent,el:div});
}
newsi.GridManager.prototype.addButton=function(o){
var choose=this.dom.cE({el:"input"});
choose.setAttribute("type","button");
choose.setAttribute("value",this.buttonTxt);
this.dom.setClass({el:choose,className:"gobutton"});
this.dom.setId({el:choose,id:"choose"});
this.dom.aC({parent:o.divtag,el:choose});
}
newsi.GridManager.prototype.createOption=function(o){
var x=0;
while(x<this.maxNumItems){
	var opt=this.dom.cE({el:"option"});
	opt.setAttribute("value",x);
	this.dom.iH({el:opt,text:this._headers[x]});
	this.dom.aC({parent:o.selected,el:opt});
	x++;
	}
}
