/*
	Class: SpreadSheet, 2008 Ago 01
*/
SpreadSheet = function()
{
	this.processorSpreadSheetUrl = null;
	this.site_url = null;
	this.getSpreadSheet_success = function(o)
	{
		//alert(o.responseText);
		if(o.responseText !=undefined && o.responseText!=null && o.responseText!='null')
		{
			var myDataSource = new YAHOO.util.DataSource(YAHOO.lang.JSON.parse(""+o.responseText));
			myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
			//myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
			myDataSource.responseSchema = 
			{ 
				fields: ["1A", "2A","3A","4A","5A","6A","7A","8A","9A","10A","11A","12A","13A"] 
			};
			
			var myCustomCellFormatter = function(elCell, oRecord, oColumn, oData) 
			{
					var cell = oData;
					var pos = cell.indexOf("**");
					if(pos != -1)
					{
						YAHOO.util.Dom.replaceClass(elCell.parentNode, "yui-dt-desc","cellStyleBlue");
						 elCell.innerHTML = oData;
					}
					else
					{
						var pos = cell.indexOf("*");
						if(pos != -1)
						{
							YAHOO.util.Dom.replaceClass(elCell.parentNode, "yui-dt-desc","cellStylePink");
							 elCell.innerHTML = oData;
						}
						else
						{
							YAHOO.util.Dom.replaceClass(elCell.parentNode, "cellStylePink", "yui-dt-desc"); 
							elCell.innerHTML = oData;
						}
					}
	        }; 
			
            YAHOO.widget.DataTable.Formatter.myCustom = myCustomCellFormatter;

			var myColumnDefs = 
			[ 
				{key:"1A", label:"PRODUCTS", width:70, formatter:"myCustom"}, 
				{key:"2A", label:"JAN", width:20, formatter:"myCustom"}, 
				{key:"3A", label:"FEB", width:20, formatter:"myCustom"},
				{key:"4A", label:"MAR", width:20, formatter:"myCustom"},
				{key:"5A", label:"APR", width:20, formatter:"myCustom"},
				{key:"6A", label:"MAY", width:20, formatter:"myCustom"},
				{key:"7A", label:"JUN", width:20, formatter:"myCustom"}, 
				{key:"8A", label:"JUL", width:20, formatter:"myCustom"}, 
				{key:"9A", label:"AUG", width:20, formatter:"myCustom"},
				{key:"10A", label:"SEP", width:29, formatter:"myCustom"},
				{key:"11A", label:"OCT", width:20, formatter:"myCustom"},
				{key:"12A", label:"NOV", width:20, formatter:"myCustom"},
				{key:"13A", label:"DEC", width:20, formatter:"myCustom"}				

			];
			//YAHOO.widget.DataTable.Formatter.deleteUrl1 = this.deleteUrl;
			this.flowerAvailabilityTable=new YAHOO.widget.DataTable(this.flowerAvailabilityDiv, myColumnDefs, myDataSource, {selectionMode:"single",scrollable:false, width:"610px"});
			
			this.flowerAvailabilityTable.subscribe("rowMouseoverEvent", this.flowerAvailabilityTable.onEventHighlightRow);
			this.flowerAvailabilityTable.subscribe("rowMouseoutEvent", this.flowerAvailabilityTable.onEventUnhighlightRow);
			this.flowerAvailabilityTable.subscribe("rowClickEvent", this.flowerAvailabilityTable.onEventSelectRow);
		}
		else
		{
			YAHOO.util.Dom.get(this.flowerAvailabilityDiv).innerHTML= ("<div class='brownBoldTitle'>...</div>");
		}
		
	}
	this.getSpreadSheet_failure = function()
	{
		alert("error");	
	}
	this.getSpreadSheet = function()
	{
		var callBack=
		{
			success: this.getSpreadSheet_success,
			failure: this.getSpreadSheet_failure,
			scope: this
		};		
		var postData = "";
		YAHOO.util.Dom.get(this.flowerAvailabilityDiv).innerHTML= ("<p>Loading ...<p>");
		YAHOO.util.Connect.asyncRequest('POST', this.processorSpreadSheetUrl, callBack, postData);		
	}
	/*
		Note: 2008 Ago 01
		Start init function
	*/
	this.init = function(site_url)
	{
		this.site_url = site_url;
		this.processorSpreadSheetUrl = "http://"+this.site_url+"/includes/Spreadsheet_Excel_Reader/phpExcelReader.php";
		this.flowerAvailabilityDiv = YAHOO.util.Dom.get("flowerAvailability");
		this.getSpreadSheet();	
	}
}
		
