
/*
FILE CONCAT ADD FILE
PATH: /ft/resources/client/markets/researchArchive.js
*/

ArchivePage = function() {
	this.wsodContainer = Element.get("wsod");
	this.monthSelect = Element.get("month",this.wsodContainer);
	this.yearSelect = Element.get("year",this.wsodContainer);
	this.calendar = Element.get("calendarContainer",this.wsodContainer);
	
	
	this.reportType = null;
	
	
	this.archiveSelector = Element.parseSelector("archiveSelector", this.wsodContainer,"first");
	this.reportCatSelect = Element.get("catSelect",this.archiveSelector);
	this.reportViewSelect = Element.get("reportSelect",this.archiveSelector);
	
	this.reportsObj = null;
}

ArchivePage.prototype.setReportsObj = function(objIn) {
	if("object" == typeof(objIn)) {
		this.reportsObj = objIn;
	}
}

ArchivePage.prototype.setReportType = function(val) {
	if("undefined" != typeof(val)){
		this.reportType = val;
	}
}

ArchivePage.prototype.attachEvents =function() {
	
	if (this.monthSelect) {
		Events.add({
			element: [this.monthSelect, this.yearSelect],
			type: "change",
			handler: this.changeDate,
			context:this	
		});
	}
	
	if(this.reportCatSelect) {
		Events.add({
			element: this.reportCatSelect,
			type: "change",
			handler: this.changeCategory,
			context:this	
		});
	}
	
	if(this.reportViewSelect) {
		Events.add({
			element: this.reportViewSelect,
			type: "change",
			handler: this.changeReport,
			context:this	
		});
	}
}

ArchivePage.prototype.changeDate = function() {
	var month = this.monthSelect.options[this.monthSelect.selectedIndex].value;
	var year = this.yearSelect.options[this.yearSelect.selectedIndex].value;
		
	var args = {month:month, year:year, report:this.reportType};
	
	var cb = new ContentBuffer();
	cb.load({
    url: "/ft/resources/server/markets/modules/archiveContentBuffer.asp",
    data: args,
    method: "post",
		contentType:"text/html",
		context:this,
		onload: this.drawData,
		debug:true
	});
}

ArchivePage.prototype.drawData = function(cb){
	removeReportLinkEvent();//from FTReports.asp
	Element.setHTML(this.calendar,cb.getResult());
	// attach link event function that is added to page from FTReports.asp
	addReportLinkEvent();
}

ArchivePage.prototype.changeCategory = function(){
	var category = this.reportCatSelect.options[this.reportCatSelect.selectedIndex].value;
	var reportTypes = this.reportsObj;
	Element.removeChildNodes(this.reportViewSelect);
	Element.create("option",{value:""},"-- Select Report --",this.reportViewSelect);
	
	for (var key in reportTypes) {
		var report = reportTypes[key];
		if(category == report.category || report.category == "ALL") { 
			Element.create("option",{value:key},report.title,this.reportViewSelect);
		}
	}
}

ArchivePage.prototype.changeReport = function(){
	var reportCode = this.reportViewSelect.options[this.reportViewSelect.selectedIndex].value;
	var category = this.reportCatSelect.options[this.reportCatSelect.selectedIndex].value;
	window.location = '/ft/markets/researchArchive.asp?report='+reportCode+'&cat='+category;
}


