/**
 * @author: kinra@adobe.com
 * @date: 05.01.2008
 * @version: 1.0
 * 
 * This script is based on my original custom data.js widget. In this version however I am leveraging the spry 
 * lib to handle the template transformation as well pagination. There are no regressions from the origianl widget to this one.
 * The benifits from the conversion are in summary:
 *   + adobe on adobe
 *   + elliminates dual xsl (safari vs. no safari)  
 *   + elliminates custom xsl function hacks for safari  
 *   + reduces code weight.
 *   + moves away from heavy customization with high learning curve to api based  spry lib.
 *   + enabled me to figure out key innovations in enhanced decouplemnt of code parts and techniques.
 *     - If the container element exists then create the DataTableRss object type. (<div id='topIssues'/>)  
 *     - Concept of using a single type constant to determine corresponding element Ids and file names.
 *     - Reduce complexity of adding new types of datatables (e.g 'TOP_ISSUES' etc.. )
 *     - Reusable reigion comparable and just as functional as xsl
 *     - Grab the parameterized HTML structure (region) template via ajax, then invoke and transform on it.			
 *     - The ability to now have a late binding and transform of a spry:region. (elliminates regions needed to be hard coded on page and enevitable redundancy of region incusion)
 *     - Late parameterized binding to single spry:region to eliminate need for multiple regions.  
 *     - Externalized XML data source map for easly updating. (See: DataTableRss.xmlDataSourceStaticOverrideByType.js)  
 *
 *   ACTIONS NEEDED BEFORE INSTALLMENT!:
 *   + product var conversion: DataTableRSS.product = DataTableRSS_Product = product;  // requires all SPCs to be updated.
 *   + XML RSS Data Source renaming. All PSC xml data sources will need to be renamed. (e.g 'top.issues.xml' for dynamic or 'top.issues.static.xml' for manual)  
 *   + <div id="dataTopIssues"> will need to be converted to <div id="topIssues"> on PSC pages.
 *   
 *   POTENTIAL ACTION:
 *   + Need for loading message.
 *     
 *   USAGE:
 *   On the client page such as:  http://www.adobe.com/support/photoshop/
 *   <head>
 *     <script type="text/javascript"> var DataTableRSS_Product = "photoshop"; </script>
 *     <link href="/lib/com.adobe/template/data/data-rss.css" rel="stylesheet" type="text/css" />

<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/xpath.js"></script>
<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/SpryData.js"></script>
<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/SpryHTMLDataSet.js" type="text/javascript"></script>
<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/SpryDataSetShell.js" type="text/javascript"></script>
<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/SpryPagedView.js"></script>
<script src="/lib/spry/Spry_1_6_1_022408/includes_minified/SpryDOMUtils.js"></script>

<script src="/lib/com.adobe/module/DataTableRss/DataTableRss.xmlDataSourceStaticOverrideByType.js" type="text/javascript"></script>
<script>
eval("DataTableRSS.xmlDataSourceStaticOverrideByType = {" 
    + DataTableRSS.typeConstant.TOP_ISSUES + ":['photoshop','indesign','dreamweaver','acrobat','creativesuite','bridge','photoshopelements','premiereelements','distiller','flashplayer','acrreader','shockwave','illustrator','flash','premiere','acrobatconnect','fireworks','contribute','aftereffects','mediaplayer', 'devicecentral', 'versioncue', 'distiller', 'stockphotos', 'presenter', 'acrobatdotcom','flex','digitaleditions','photoshoplightroom','reader'],"
	+ DataTableRSS.typeConstant.RECENT_DOCUMENTS + ":['devicecentral', 'versioncue', 'distiller', 'stockphotos'],"
	+ DataTableRSS.typeConstant.INSTALLATION_HELP + ":['techcommsuite', 'acrobat', 'reader'],"
	+ DataTableRSS.typeConstant.DEVELOPER_DATA + ":['air']}");
</script>
<script src="/lib/com.adobe/module/DataTableRss/DataTableRss.js" type="text/javascript"></script>
<script>
DataTableRSS_Main();
</script>
<noscript>
<style>
  #topIssues, #recentDocuments, #developerData, #installationHelp, #tab-top-issues,#tab-recent-documents,#tab-developer-data, #tab-installation-help { visibility: hidden; height: 0px;}
</style>	
</noscript>

 *   </head>
 *   <body> 
 *     <div class="tabcontent">                     
 *	     <div id="topIssues" style="display: block;">
 *		   There are no top issues					
 *		 </div>
 *   </body>
 *   
*/


// DONT FORGET TO TURN IE DEBUG OFF
/* ****************************************************************************** */
var debugDataTableRSS = false; //
//adobe.Console.log("DataTableRSS.js");
function mydebug_DataTableRSS(s) { if(debugDataTableRSS) { if(Prototype.Browser.WebKit) {  /*alert(s);*/  } else {  if (!document.all) { try { if(window.console) { console.log(s); } } catch(ex) {} } }} }
/* ********************************** START MAIN ****************************************** */
function DataTableRSS_Main(){
  try {
	  if (DataTableRSS.documentLocation.indexOf('#') > -1) {
	  	//alert(DataTableRSS.documentLocation);
		var myLocationPoundIndex = DataTableRSS.documentLocation.indexOf('#');
		//alert(myLocationPoundIndex);
		var myNewLoc = DataTableRSS.documentLocation.slice(0,myLocationPoundIndex);
		if (!Prototype.Browser.WebKit) {
			window.setTimeout("document.location = '" + myNewLoc + "';", 1 * 1000);
            return;
		} else {
			document.location.href = myNewLoc + "#";			
		}
	  }
  //document.location = (DataTableRSS.documentLocation + "#DataTableRSS_" + dataTableRSSType + "_Anchor");
  } catch(ex) {
  	
  }

	try {
		DataTableRSS.product = DataTableRSS_Product;// = product;   
		if (DataTableRSS.product) {
			//Note: Array in theroy for multiple products not there yet
			mydebug_DataTableRSS("registerOnLoad(DataTableRSS.initDataTableRSS);");
			
			for (var i = 0; i < DataTableRSSTypeSequenceInvokation.length; i++) {
				var dataTableRssType = DataTableRSSTypeSequenceInvokation[i];
				var elId = DataTableRSS.formatAndSetElIdFromParsedTypeConstant(dataTableRssType);
				DataTableRSS.ObjectCollection[dataTableRssType] = new DataTableRSS(DataTableRSS.product, dataTableRssType);
				DataTableRSS.ObjectCollection[dataTableRssType].elId = elId;

			 // !Issue: this unfortunallty still is not solid due to the fact tha the elId may not be ready in the dom yet..
			 // the has index must be skipped and no fetch attempt should be made in the case of no valid corresponding datatable type elId.
			 // So the question is can move this to put region... and how would that affect when called form getDataFor Product lazy style..?
			 // Would that recreate the VPN latency issue i just solved by puttin it here?
			
				eval('DataTableRSS_' + dataTableRssType + ' = (new Spry.Data.XMLDataSet(DataTableRSS.ObjectCollection[dataTableRssType].xmlDataSourceUrl, "rss/channel/item",{entityEncodeStrings: false}));');
				eval("DataTableRSS.ObjectCollection[dataTableRssType].xmlDataSet = DataTableRSS_" + dataTableRssType + ";");

             // I think all i need is some error indicaiton to forward the hash index...?
			 // if there was a 404 then forward the hash index.. 
              mydebug_DataTableRSS("DataTableRSS_Main:loop-for:" + dataTableRssType);
			}
			registerOnLoad(DataTableRSS.initDataTableRSS); // this prevents it from working correctly in MAC/FF	
		}
	} 
	catch (ex) {
		mydebug_DataTableRSS("DataTableRSS:Error:" + ex.message);
	}
}
/* ********************************** END MAIN ****************************************** */
if(Prototype.Browser.WebKit) {
	document.writeln("<style>");
	document.writeln("table.data tbody tr.description-hidden, table.data thead tr.description-hidden { visibility: collapse;  display: none;  }");
	document.writeln("table.data-small tbody tr.description-hidden, table.data-small thead tr.description-hidden { visibility: collapse; display: none; }");
	document.writeln("</style>");			
}	

//adobe.SCRIPT_ENGINE == "JScript" && adobe.SCRIPT_VERSION < 5.7
//2:57 PM btapley: adobe.SCRIPT_VERSION only works with IE right now. I have a proposal to add this later for other browsers eg.
//2:57 PM btapley: adobe.SCRIPT_ENGINE == "JavaScript" && adobe.SCRIPT_VERSION == 1.5

if (document.all) {
	if (adobe.SCRIPT_ENGINE == "JScript" && adobe.SCRIPT_VERSION < 5.7) {
	document.writeln("<style>");
	document.writeln("table.data-small tbody td label a:hover { background-color:#FFF5C0; color:#CC0000; }");
	document.writeln("</style>");			
	}
}
// fixes footer gap in FF
if (!Prototype.Browser.WebKit && !document.all) {
	document.writeln("<style>");
	document.writeln(" table.data-small tbody tr.description-hidden, table.data-small thead tr.description-hidden { display: none; }");
	document.writeln("</style>");			
}
/* ****************************************************************************** */
// keep transient from 'DataTableRss.xmlDataSourceStaticOverrideByType.js'
var DataTableRSS_TypeConstant = DataTableRSS.typeConstant; 
var DataTableRSS_xmlDataSourceStaticOverrideByType = DataTableRSS.xmlDataSourceStaticOverrideByType;

var DataTableRSS = Class.create({
	initialize: function(_product, _dataTableType) {
		mydebug_DataTableRSS("DataTableRSS::initialize: 'var product = " + _product + ";' is defined on client page.");
		mydebug_DataTableRSS("DataTableRSS::initialize: _dataTableType = " + _dataTableType);
        // 
        this.product = _product;
        this.type = _dataTableType; 		
		this.xmlDataSourceUrl = DataTableRSS.setXmlDataSourceUrl(_product, _dataTableType); 
		this.xmlDataSet = {}; // sprys object...  
		this.xmlDataSetShell = {}; // sprys object... 
		this.toggleState = false;
		this.xmlDoc = null; // the raw doc from the xml http request.
		this.elId = null;		
		this.errorMsg = DataTableRSS.errorMsg;
		this.region = "";
		this.originalHTML = "";
	} // End Method
}); // End Class

// Static Vars
DataTableRSS.pageSize = 10;
DataTableRSS.ObjectCollection = [];
DataTableRSS.product = null;
DataTableRSS.htmlTemplate = '/lib/com.adobe/module/DataTableRss/DataTableRss-Region.ssi';
DataTableRSS.xmlDataSource_ROOT_DIRECTORY = "/support/";
DataTableRSS.xmlDataSource_SUB_DIRECTORY_PATH = "/rss/";
DataTableRSS.dataSourceDefaultXpath = "rss/channel/item";
DataTableRSS.tempObj = null;//new _DataTableRSS();
DataTableRSS.documentLocation = "" + document.location + "";
DataTableRSS.loadDataCallback_HashKeyIndex = 0;
DataTableRSS.anchorCheck = true; // weird issue on tech comm suit page
DataTableRSS.locale = "";
// externalize this.
DataTableRSS.errorMsg = "[Error no feed available.]"; // {}

// For now this can be static.
DataTableRSS.templateRegion = "";

// Copies from 'DataTableRss.xmlDataSourceStaticOverrideByType.js'
DataTableRSS.typeConstant = DataTableRSS_TypeConstant; 
DataTableRSS.xmlDataSourceStaticOverrideByType = DataTableRSS_xmlDataSourceStaticOverrideByType;

// These are assocated with spry:region  "DataTableRSS_{$dataTableType}" 
// Do this manually if too slow via the eval().
// var DataTableRSS_TOP_ISSUES, DataTableRSS_RECENT_DOCUMENTS, DataTableRSS_INSTALLATION_HELP, DataTableRSS_DEVELOPER_DATA;
for(var i = 0; i < DataTableRSSTypeSequenceInvokation.length; i++) {
     eval("var DataTableRSS_" + DataTableRSSTypeSequenceInvokation[i]  + ";");		
}
/* ****************************************************************************** */
//var DataTableRSSTypes = ["TOP_ISSUES","RECENT_DOCUMENTS","INSTALLATION_HELP","DEVELOPER_DATA"];
// Invoke DataTableRSS several times based on the config object..  
/* ****************************************************************************** */

// "TOP_ISSUES" becomes "top.issues.xml"
DataTableRSS.formatAndSetXmlDataSourceFileNameFromParsedTypeConstant = function(_type, isStatic) {
	  var xmlFileName = "";
	  // to lower case, replace "_" with "." and append ".xml"
 	  _type = _type.toLowerCase();
	  xmlFileName = _type.replace("_",".")
      xmlFileName = xmlFileName + ((isStatic)?'.static':'') + ".xml";
	  return xmlFileName;    		
}

// "TOP_ISSUES" becomes "topIssues"
DataTableRSS.formatAndSetElIdFromParsedTypeConstant = function(_type) {
	  var elId = "";
	  // to lower case split on '_'  make first char after '_' to upper case..
	  _type = _type.toLowerCase();
	  var elIdSplit = _type.split("_");

	  for (var e = 0; e < elIdSplit.length; e++) {
		if (elIdSplit[e] == "_") {
           alert("_");	  	
	  	} else {
	  		if (e == 0) {
	  			elId += elIdSplit[e];
	  		} else {				
	  			var firstChar = ((elIdSplit[e]).slice(0,1)).toUpperCase();
				var elIdTemp; 
				elIdTemp = (elIdSplit[e]).slice(1, elIdSplit[e].length);				
	  			elId += firstChar + elIdTemp;
	  		}
	  	}
	  }		
	  return elId;    	
}

// "TOP_ISSUES" becomes "Top issues"   // is or are... i18n  Hmmmm
DataTableRSS.formatAndSetErrorTokenFromParsedTypeConstant = function(_type) { }

DataTableRSS.paginateNext = function(dataTableRSSType) {
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.nextPage();	
  DataTableRSS.toggleRangeByType(dataTableRSSType, true);
  fixLinks("");
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.addObserver(fixLinks);		 
}

DataTableRSS.paginatePrev = function(dataTableRSSType) {
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.previousPage();	
  DataTableRSS.toggleRangeByType(dataTableRSSType, true);
  fixLinks("");
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.addObserver(fixLinks);		 
}

DataTableRSS.toggleRangeByTypePage = function(dataTableRSSType){
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.goToPage(DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.getCurrentPage());	
  DataTableRSS.toggleRangeByType(dataTableRSSType);
  fixLinks("");
  DataTableRSS.ObjectCollection[dataTableRSSType].xmlDataSet.addObserver(fixLinks);		 	
}

DataTableRSS.toggleRangeByType = function(dataTableRSSType, suppressToggle) {	
  mydebug_DataTableRSS("DataTableRSS.toggleRangeByType::" + dataTableRSSType + "::" + suppressToggle);

  var mySummaryElementArray = Spry.$$("#dataTableRSS_" + dataTableRSSType + "_table tr.description-hidden");
  mydebug_DataTableRSS("mySummaryElementArray:" + mySummaryElementArray.length);	
  var _suppressToggle = false;
  try { if(suppressToggle) _suppressToggle = true; } catch(ex) { alert('no suppres toggle') }
  try {
  if (suppressToggle) {
	  if (DataTableRSS.ObjectCollection[dataTableRSSType].toggleState == true) {
	      $('showMoreInfo_' + dataTableRSSType).checked = true;
          if(document.all) {
	        mySummaryElementArray.setStyle("display: block;"); 		  	
		  } else{		  	
	          mySummaryElementArray.setStyle("visibility: visible;"); 
				if (Prototype.Browser.WebKit) {
	              mySummaryElementArray.setStyle("display: block;"); 		  					
				} else {
	              mySummaryElementArray.setStyle("display: table-row;"); 		  					
				}
		  }
		  mydebug_DataTableRSS("It stays true ");	
	  } else {
		  $('showMoreInfo_' + dataTableRSSType).checked = false;
          if(document.all) {
	        mySummaryElementArray.setStyle("display: none;"); 		  	
		  } else{		  	
	          mySummaryElementArray.setStyle("visibility: collapse;"); 
				if (Prototype.Browser.WebKit) {
	              mySummaryElementArray.setStyle("display: none;"); 		  					
				} else {
	              mySummaryElementArray.setStyle("display:;"); 		  					
				}
		  }
	      mydebug_DataTableRSS("It stays false ");	
	  }  	
  } else {
	  if (DataTableRSS.ObjectCollection[dataTableRSSType].toggleState == true) {
		  DataTableRSS.ObjectCollection[dataTableRSSType].toggleState = false;
	      $('showMoreInfo_' + dataTableRSSType).checked = false;
          if(document.all) {
	        mySummaryElementArray.setStyle("display: none;"); 		  	
		  } else{		  	
	          mySummaryElementArray.setStyle("visibility: collapse;"); 
				if (Prototype.Browser.WebKit) {
	              mySummaryElementArray.setStyle("display: none;"); 		  					
				} else {
	              mySummaryElementArray.setStyle("display:;"); 		  					
				}
		  }
	      mydebug_DataTableRSS("It was true now it will be false");	
	  } else {
		  DataTableRSS.ObjectCollection[dataTableRSSType].toggleState = true;
		  $('showMoreInfo_' + dataTableRSSType).checked = true;
          if(document.all) {
	        mySummaryElementArray.setStyle("display: block;"); 		  	
		  } else{		  	
	          mySummaryElementArray.setStyle("visibility: visible;"); 
				if (Prototype.Browser.WebKit) {
	              mySummaryElementArray.setStyle("display: block;"); 		  					
				} else {
	              mySummaryElementArray.setStyle("display: table-row;"); 		  					
				}
		  }
		  mydebug_DataTableRSS("It was false now it will be true");
	  }  
  }  
  } catch (ex) {
  	//alert(ex.message);
  }
  
  
 // alert(DataTableRSS.documentLocation);
  if(!Prototype.Browser.WebKit) {
  	document.location = (DataTableRSS.documentLocation + "#DataTableRSS_" + dataTableRSSType + "_Anchor");
  } else {
  	// Safari hates the anchor.. 
  }
  
  if(document.all) {
    document.body.scrollTop = (document.body.scrollTop - 45);
  } else {
  	//var myBody = (document.getElementsByTagName('body')[0]);
  	//alert(myBody.nodeName);
  	//alert(myBody.scrollTop);
    //document.(document.getElementByTagName('body')[0]).scrollTop = ((document.getElementByTagName('body')[0]).scrollTop - 45); 	
  }
  mydebug_DataTableRSS("DataTableRSS.ObjectCollection[dataTableRSSType].toggleState::" + DataTableRSS.ObjectCollection[dataTableRSSType].toggleState);  
}

/** THIS WILL NOT WORK WITH MICRO SITE & VERIFY TECH COM SUITE PAGE               **/
DataTableRSS.setLocaleForXmlDataSorcePath = function(_product) {
 return DataTableRSS.locale;
}

DataTableRSS.setXmlDataSourceUrl = function(_product, _dataTableType) {
  var dirPath = DataTableRSS.locale + DataTableRSS.xmlDataSource_ROOT_DIRECTORY + _product + DataTableRSS.xmlDataSource_SUB_DIRECTORY_PATH;	
  var fileName; 
  
  //determine if manual or auto  
  // put in default by type
  var isStatic = false;
  if (DataTableRSS.locale == "") {  
	  for(var i=0; i< (DataTableRSS.xmlDataSourceStaticOverrideByType[_dataTableType]).length; i++) {   
	      if(_product == DataTableRSS.xmlDataSourceStaticOverrideByType[_dataTableType][i]) {
	          // Do static version
		      isStatic = true;
		  }   
	  }  
  } else {
  	  isStatic = true;
  }
  fileName = DataTableRSS.formatAndSetXmlDataSourceFileNameFromParsedTypeConstant(_dataTableType, isStatic)		
  return (dirPath + fileName);

}

DataTableRSS.messages = {};
//DataTableRSS.messages.loading = "Loading...";
//
DataTableRSS.getDataForProduct =  function(_product,_dataTableType) {
   mydebug_DataTableRSS("DataTableRSS.getDataForProduct:" + _product + "::" + _dataTableType );
  try {
   var myObj = DataTableRSS.ObjectCollection[_dataTableType];
   //$(myObj.elId).innerHTML = DataTableRSS.messages.loading; 

   myObj.xmlDataSourceUrl = DataTableRSS.setXmlDataSourceUrl(_product, _dataTableType);   
	
	for(var i = 0; i < DataTableRSSTypeSequenceInvokation.length; i++) {
	     if(_dataTableType == DataTableRSSTypeSequenceInvokation[i]) {
		   DataTableRSS.loadDataCallback_HashKeyIndex = i;
	       break;
		 }
	}
  
    eval('myObj.xmlDataSet = DataTableRSS_' + myObj.type + '= (new Spry.Data.XMLDataSet(myObj.xmlDataSourceUrl, "rss/channel/item",{entityEncodeStrings: false}));');	  
    DataTableRSS.putRegion();
/*
	for (var i = 0; i < DataTableRSSTypeSequenceInvokation.length; i++) {
	  var myDTType = DataTableRSSTypeSequenceInvokation[i];
          try {
             DataTableRSS.toggleRangeByType(myDTType, true);
          } catch(ex) {
		   	  //continue;
		  }
	}
*/

  } catch(ex) {
     mydebug_DataTableRSS("DataTableRSS.getDataForProduct:" + ex.message);
  } 
}

// Grab the parameterized HTML structure template via ajax, then invoke and transform on it.			
DataTableRSS.initDataTableRSS = function() {
  mydebug_DataTableRSS("DataTableRSS.initDataTableRSS");		
  new Ajax.Request(DataTableRSS.htmlTemplate,{method: 'post', onSuccess: DataTableRSS.putRegion });
}
/********************************************************************************/
DataTableRSS.putRegion = function(xslhr,obj) {
  mydebug_DataTableRSS("DataTableRSS.putRegion");
  // Store Region for reuse if needed..   
  try {
    DataTableRSS.templateRegion = "" + xslhr.responseText + "";
  } catch(ex) {
  	
  }
  try {	
        var lastTrueType = "";
	  	for(var i=0;i<DataTableRSSTypeSequenceInvokation.length;i++) {
			mydebug_DataTableRSS("itteration:" + i);    
			//mydebug_DataTableRSS(DataTableRSSTypeSequenceInvokation);
			var dataTableRssType = DataTableRSSTypeSequenceInvokation[i];
            //mydebug_DataTableRSS(dataTableRssType); 
		    DataTableRSS.tempObj = DataTableRSS.ObjectCollection[dataTableRssType];
            //mydebug_DataTableRSS(DataTableRSS.tempObj); 
			
			var elId = DataTableRSS.tempObj.elId;

		  	try { if($(elId).nodeType); } catch(ex) {
				//trueCount = trueCount + 1;
				mydebug_DataTableRSS("------------------");
                
				
				//debugDataTableRSS = true;
			    mydebug_DataTableRSS("Element ID:" + elId + " cannot be found.");
				//debugDataTableRSS = false;
				
								
				//debugDataTableRSS = false;
				var TempDataTableRSSTypeSequenceInvokation = new Array();
				for (var a = 0; a < DataTableRSSTypeSequenceInvokation.length; a++) {
				   if(a!=i) {
				   	 TempDataTableRSSTypeSequenceInvokation[TempDataTableRSSTypeSequenceInvokation.length] = DataTableRSSTypeSequenceInvokation[a];
				   }
				}
				DataTableRSSTypeSequenceInvokation = null;
				//alert(TempDataTableRSSTypeSequenceInvokation);	
				DataTableRSSTypeSequenceInvokation = [];
				for (var j = 0; j < TempDataTableRSSTypeSequenceInvokation.length; j++) {
				   	 DataTableRSSTypeSequenceInvokation[DataTableRSSTypeSequenceInvokation.length] = TempDataTableRSSTypeSequenceInvokation[j];
				}
				//alert(DataTableRSSTypeSequenceInvokation);	
				i = (i - 1); //dangerous... 
				continue;
			}	
	
			try {
				mydebug_DataTableRSS("ADDING REGION FOR:" + dataTableRssType);
		       xslhrResponseText_DtTypeAdded = (DataTableRSS.templateRegion).replace(/{\$dataTableType}/g,dataTableRssType); 			 		
			  // grab original HTML source in case of error.
			  try {
			    DataTableRSS.tempObj.originalHTML = $(elId).innerHTML;
			    $(elId).update(xslhrResponseText_DtTypeAdded);			  			  
			  } catch(ex) {}
			  
			  //var xmlDOMDocument = Spry.Utils.stringToXMLDoc(DataTableRSS.tempObj.xmlDoc);
			  //DataTableRSS.tempObj.xmlDataSet.setDataFromDoc(xmlDOMDocument);
              // ...finished putting Region.  
			  try {
				  DataTableRSS.tempObj.xmlDataSet = new Spry.Data.PagedView(DataTableRSS.tempObj.xmlDataSet, {pageSize:DataTableRSS.pageSize});			 			        
				  (eval("DataTableRSS.tempObj.xmlDataSetShell = DataTableRSS_" + dataTableRssType + "= new Spry.Data.DataSetShell(DataTableRSS.tempObj.xmlDataSet);"));			 			  
			  } catch (ex) {
			      mydebug_DataTableRSS(ex.message);
			      continue;
			  }   			  
	          Spry.Data.initRegions();
              DataTableRSS.tempObj.xmlDataSetShell.setInternalDataSet(DataTableRSS.tempObj.xmlDataSet, true);

              lastTrueType = DataTableRSS.tempObj.type;
              DataTableRSS.ObjectCollection[DataTableRSS.tempObj.type] = DataTableRSS.tempObj; //.clone(true);
              mydebug_DataTableRSS("DataTableRSS.ObjectCollection[DataTableRSS.tempObj.type].xmlDataSourceUrl:" + DataTableRSS.ObjectCollection[DataTableRSS.tempObj.type].xmlDataSourceUrl);
              DataTableRSS.tempObj = null;
    		} catch (ex) {
				 // debug
				 mydebug_DataTableRSS(DataTableRSSTypeSequenceInvokation[i] + ":ERROR:" + ex.message); 
                 continue;			
			}				
		}

  } catch(ex) {
  	  mydebug_DataTableRSS("DataTableRSS.putRegion:Error:" + ex.message);
  }  

  DataTableRSS.ObjectCollection[lastTrueType].xmlDataSet.addObserver(fixLinks);		
  
}


function fixLinks(notificationType, notifier, data){
	//alert(notificationType)
	if (notificationType == "onPreLoad") {
		return;
	}
	if (notificationType == "onPostLoad") {
		return;
	}
    var doPatch = false; 
    //alert(notificationType + "::" + data + ":" + DataTableRSS.documentLocation + "\n" + DataTableRSSTypeSequenceInvokation.length);   
	for(var i = 0; i < DataTableRSSTypeSequenceInvokation.length; i++) {
      var myDTType = DataTableRSSTypeSequenceInvokation[i];
	  mydebug_DataTableRSS("myDTType::" + myDTType);
	  try {
		//alert(eval("$('DataTableRSS_' + myDTType).innerHTML;"));		
	    if(document.all) {        
		   var withLinks = eval("$('DataTableRSS_' + myDTType).innerHTML;");
	       if(withLinks == "") {
				// come back later.. 
				doPatch = true;
				mydebug_DataTableRSS("come back later...");
		        break;
		   }
		   var documentLocation = new String(DataTableRSS.documentLocation);
		       var slash = documentLocation.lastIndexOf("/");
			   documentLocation = documentLocation.slice(0,(slash + 1));
			   documentLocation = documentLocation.replace(/\//g,"\\/");
			   //alert(documentLocation);
			   eval("withLinks = withLinks.replace(/" + documentLocation + "/g,'');");
	           //alert(withLinks);
               eval("$('DataTableRSS_' + myDTType).innerHTML = withLinks;");	
               eval("$('DataTableRSS_' + myDTType).style.fontFamily = 'font-family:Arial,Helvetica,sans-serif';");	
		       mydebug_DataTableRSS((eval("$('DataTableRSS_' + myDTType).innerHTML;")).slice(0,100));		
		}	

        if (DataTableRSS.ObjectCollection[myDTType].toggleState == true) {  	
          var mySummaryElementArray = Spry.$$("#dataTableRSS_" + myDTType + "_table tr.description-hidden");
	      $('showMoreInfo_' + myDTType).checked = true;
 		  if(document.all) {
	        mySummaryElementArray.setStyle("display: block;"); 		  	
		  } else{		  	
	          mySummaryElementArray.setStyle("visibility: visible;"); 
				if (Prototype.Browser.WebKit) {
	              mySummaryElementArray.setStyle("display: block;"); 		  					
				} else {
	              mySummaryElementArray.setStyle("display: table-row;"); 		  					
				}
		  }		  
        }
			  	
	  } catch (ex) {
	      //alert("myDTType:" + myDTType + "::" + ex.message); 	
	      //alert("myDTType:::" + ex.message); 		
		  doPatch = true; 
	  }    
		
	}

	if(doPatch) {
		  window.setTimeout("fixLinks()", 3 * 1000);
	}
	
}

//function fixLinks() {
	//alert("fixLinks");
//}

/* ****************************************************************************** */
// I am overriding this here: its originally in SpryData.js
// Switcharoo...
Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadDataCallbackOrg = Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadDataCallback;
//
Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadDataCallback = function(req)
{
	if (req.xhRequest.readyState != 4) {
		return;
	}
	//debugDataTableRSS = true;

    var myRssDtType = DataTableRSSTypeSequenceInvokation[DataTableRSS.loadDataCallback_HashKeyIndex];
	var myRssDtObj =  DataTableRSS.ObjectCollection[myRssDtType];
	mydebug_DataTableRSS("================================loadDataCallback=======================================");		  
    //mydebug_DataTableRSS(DataTableRSSTypeSequenceInvokation);
	mydebug_DataTableRSS("DataTableRSS.loadDataCallback_HashKeyIndex:" + DataTableRSS.loadDataCallback_HashKeyIndex);		  
	mydebug_DataTableRSS("DataTableRSS:myRssDtType:" + myRssDtType);		  
	mydebug_DataTableRSS("DataTableRSS:status:" + 	req.xhRequest.status);	
	mydebug_DataTableRSS("DataTableRSS:req.xhRequest.responseText:" + 	req.xhRequest.responseText.slice(0,200));	
	mydebug_DataTableRSS("DataTableRSS:req:" +  req.xhRequest.statusText); 

	// Since IE and Safari does not follow any particular order in invoking this... i will need to come up with a clever way to assign the error text for 404 cases..
	// Hack..
	// So basically DataTableRSS.loadDataCallback_HashKeyIndex is usless in IE
	if(document.all || Prototype.Browser.WebKit) {
		if(adobe.SCRIPT_ENGINE == "JScript" && adobe.SCRIPT_VERSION < 5.7) {	
		    // If there was a no $(elId) I need to forward the index... 
			// this can help to determine if transform was successfull for IE.. 
			// note that the response text for IE has no correlation to the DT type here.. due to the lack of call backs being invloked in sequence..  
		    try  {
		var myInnerHTMLTest = $(myRssDtObj.elId).innerHTML;		  
		mydebug_DataTableRSS("DataTableRSS:myRssDtType:$(myRssDtObj.elId).innerHTML:" + myInnerHTMLTest);		      
		if(DataTableRSS.anchorCheck) {
		  mydebug_DataTableRSS(">>>>>>>>>>:" + $('DataTableRSS_' + myRssDtType + '_Anchor').nodeName  );
		}
		//$(DataTableRSS_{$dataTableType}
			
			} catch(ex) {
				try {
		          mydebug_DataTableRSS(">>>>>>>>>>:'_Anchor':" + myRssDtObj.elId + ":" + ex.message );
				} catch(ex) {
					
				}
				
				if (document.all) {
					try {
					  //$(myRssDtObj.elId).innerHTML = myRssDtObj.originalHTML;
				    } catch(ex) {
						
					}
				}
				//return;
			}
		}
	}
 
	//debugDataTableRSS = false;
	
	var rawData = null;

	if (this.xhRequestProcessor) {
		rawData = this.xhRequestProcessor(req.xhRequest);
	}

	if (this.sessionExpiredChecker) {
		Spry.Utils.setOptions(req, {'rawData': rawData}, false);
		if (this.sessionExpiredChecker(req))
		{
			this.state = Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_FAILED;
			this.notifyObservers("onRequestSessionExpired", req);
			this.observers.length = 0;

            // added this. 
	        DataTableRSS.loadDataCallback_HashKeyIndex = DataTableRSS.loadDataCallback_HashKeyIndex + 1;
	        mydebug_DataTableRSS("RETURN A"); 
			//debugDataTableRSS = false;		

			return;
		}
	}

	//mydebug_DataTableRSS("DataTableRSS:myRssDtType:myRssDtObj.originalHTML:" + myRssDtObj.originalHTML);		  
	if (!rawData) {
        debugDataTableRSS = true;

        //mydebug_DataTableRSS("DataTableRSS:!rawData");		  
	
		this.state = Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_FAILED;
		this.notifyObservers("onRequestError", req);
		this.observers.length = 0; // Clear the observers list.

        try {
		  var oDoc = (new DOMParser()).parseFromString(req.xhRequest.responseText, "text/xml");		
		  if(!Sarissa.getParseErrorText(oDoc).match("no parsing errors")) {
		   	// put an error message on the screen in the elId			
			$(myRssDtObj.elId).innerHTML = myRssDtObj.originalHTML;

			if(req.xhRequest.status == "404") {
              $(myRssDtObj.elId).update(DataTableRSS.errorMsg);				
			}
			mydebug_DataTableRSS("DataTableRSS:" + myRssDtType + ":\n" + myRssDtObj.xmlDataSourceUrl + "\n" + Sarissa.getParseErrorText(oDoc));		  						
		  } 
		 } catch(ex) { 
                  if(adobe.SCRIPT_ENGINE == "JScript" && adobe.SCRIPT_VERSION < 5.7) {
				  	// figure out a way to put messages in for IE7
					//alert(ex.message);
					try {
				      if(req.xhRequest.status == "404") {
					  	$(myRssDtObj.elId).innerHTML = DataTableRSS.errorMsg
					  }
					} catch(ex) {}
					fixLinks();
					
				  }
				   debugDataTableRSS = false;
			   	  mydebug_DataTableRSS("DataTableRSS:myRssDtType:" + myRssDtType + "::" + ex.message);		  
		 } 

	    //$(DataTableRSS.ObjectCollection['TOP_ISSUES'].elId).style.border = "solid pink 1px";   
        DataTableRSS.loadDataCallback_HashKeyIndex = DataTableRSS.loadDataCallback_HashKeyIndex + 1;
        //mydebug_DataTableRSS("DataTableRSS:!rawData:exit");		  
        //debugDataTableRSS = false;		
	    //mydebug_DataTableRSS("RETURN B"); 

        debugDataTableRSS = false;		
		return;
	}
    //debugDataTableRSS = false;		

	this.rawData = rawData;
	this.state = Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_SUCCESSFUL;

	// Notify all of the cached request's observers!
	this.notifyObservers("onRequestResponse", req);

	// Clear the observers list.
	this.observers.length = 0;

    /*** added ***/
	if (req.xhRequest.responseText) {
		try { myRssDtObj.xmlDoc = new String(req.xhRequest.responseText); 
	  //$(DataTableRSS.ObjectCollection['TOP_ISSUES'].elId).style.border = "solid purple 1px";   
		} catch(ex) {
			  	  mydebug_DataTableRSS("OVERRIDDEN::Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadDataCallback::" + ex.message);	
				 //alert(ex.message) 		
		}
	}
    //try { alert(myRssDtType + "::" +  myRssDtObj.xmlDoc); } catch(ex) {}
    DataTableRSS.loadDataCallback_HashKeyIndex = DataTableRSS.loadDataCallback_HashKeyIndex + 1;
	mydebug_DataTableRSS("RETURN C"); 
    //debugDataTableRSS = false;		
	// put a program state to indicate complete?
	
    //DataTableRSS.loadDataCallback_HashKeyIndex

};

DataTableRSS.state = "";

Spry.Debug.debugOut = function(str, bgColor) { return; }

/* ****************************************************************************** */
/* Sarissa Lib Extracts */
function Sarissa(){};
Sarissa.PARSED_OK = "Document contains no parsing errors";
Sarissa.PARSED_EMPTY = "Document is empty";
Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error";
     
    /**
     * <p>Returns a human readable description of the parsing error. Usefull
     * for debugging. Tip: append the returned error string in a &lt;pre&gt;
     * element if you want to render it.</p>
     * <p>Many thanks to Christian Stocker for the initial patch.</p>
     * @argument oDoc The target DOM document
     * @returns The parsing error description of the target Document in
     *          human readable form (preformated text)
     */
    Sarissa.getParseErrorText = function (oDoc){
        var parseErrorText = Sarissa.PARSED_OK;
        if(!oDoc.documentElement){
            parseErrorText = Sarissa.PARSED_EMPTY;
        } else if(oDoc.documentElement.tagName == "parsererror"){
            parseErrorText = oDoc.documentElement.firstChild.data;
            parseErrorText += "\n" +  oDoc.documentElement.firstChild.nextSibling.firstChild.data;
        } else if(oDoc.getElementsByTagName("parsererror").length > 0){
            var parsererror = oDoc.getElementsByTagName("parsererror")[0];
            parseErrorText = Sarissa.getText(parsererror, true)+"\n";
        } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){
            parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR;
        };
        return parseErrorText;
    };
	
/* ********************************** INVOKE MAIN ****************************************** */
//DataTableRSS_Main();  // let invoker call this instead.
