// function pdf() { }

var Reports_class = function(section) {
	this.section = section;
	this.reportsSaved = "";
	this.reportsRecent = "";



}


Reports_class.prototype.storeReportsPreference = function(module) {


	storePref("Reports_"+this.section+module,this["reports"+module])

}


Reports_class.prototype.addToSavedReports = function(report) {
	this.addSidebarReport("Saved",report);

}



Reports_class.prototype.addToRecentReports = function(report) {
	this.addSidebarReport("Recent",report);
}



Reports_class.prototype.addSidebarReport = function(module,report,isInit) {

	var moduleReports = this["reports" + module];

	if (!isInit && moduleReports.match("(,|^)"+report+"(,|$)")) {
		return; 
	}

	var container = Element.get("reports"+module+"Module");

	var reportLink = Element.get("reportLink"+report);
	if (!reportLink) {
		return;
	}

	if (!isInit) {

		moduleReports = moduleReports + (moduleReports?',':'') + report; // adds report to the list
		this["reports" + module] = moduleReports;
	}
	
	var cl = "smaller";

	var reportLinkSidebar, reportTextDiv;
	var reportDiv = Element.create("div",{id:"sideBarReport"+report,className:"iconBackground reportPDFLeft"},[
		reportLinkDiv = Element.create("div",{},[
			Element.create("div",{className:"reportText"},[
				reportLinkSidebar = Element.create("a",{className:cl,target:"_blank",href:reportLink.href,onclick:"pdf(this.href); return false"},reportLink.innerHTML)
			])
			// remove icon gets added here if "Saved"
		])
	],container);

	if (reportLink.innerHTML.match(/edge/i)) {
		Element.addClass(reportDiv,"external");
	}

	if (module == "Saved") {
		Element.create("div",{className:"reportRemove"},[
			Element.create("img",{Events:{type:"click",context:this,handler:this.removeSidbarReport,data:{module:module,report:report}},className:"hand",src:"/tdameritrade/images/icons/remove.gif"})
		],reportLinkDiv);


		Element.addClass(Element.parseSelector('img[forReport="addToSaved'+report+'"]'),"none");


	}


	if (!isInit) {
		this.storeReportsPreference(module)
	}



/*

<div class="iconBackground reportPDFLeft external">
	<div>
		<div class="reportText">
			<a target="_blank" onclick="addToRecentReports('10001');pdf(this.href); return false" href="/cgi-bin/apps/u/MarketEdge?symbol=DELL" class="smaller">Market Edge - Second Opinion</a>
		</div>
		<div class="reportRemove">
			<img class="hand" onclick="removeFromMyReports('10001')" src="/tdameritrade/images/icons/remove.gif"/>
		</div>
	</div>
</div>
*/


}



Reports_class.prototype.removeSidbarReport = function(e,el,data) {

	var moduleReports = this["reports" + data.module];
	moduleReports = moduleReports.replace(new RegExp(",?"+data.report),"");

	this["reports" + data.module] = moduleReports;

	Element.remove("sideBarReport"+data.report)
	Element.removeClass(Element.parseSelector('img[forReport="addToSaved'+data.report+'"]'),"none");

	this.storeReportsPreference(data.module)

}



Reports_class.prototype.drawReportsSideBar = function() {

	drawReports.call(this,"Saved");
	drawReports.call(this,"Recent");

	function drawReports(module) {
		var reports = this["reports" + module].split(",");
		for (var i=0; i<reports.length; i++){ 
			this.addSidebarReport(module,reports[i],true);
		}
	}

}




