/*   
  





	CHANGE LOG
    1. CREATED 12/16/2008 by Nathan Townsend


*/



ReqList = new function()
{
  try{ 
	
	  var _div = null;
		

		return{
		
		  Enabled: true,
			
			GetList: function(){
			  if(_div)
			    return _div.find("table").html();
				
				return "Could not return the req list";
			}, 
			
			GetValue: function(name){
			  var val = $("#" + name + " + td").text();
				return val;
			},
		
			Initialize: function(Div)
			{
				try{
  		    _div = $(Div);
	  			Log.Add("ReqList.Initialize", "Initialized", LogType.Info);
				}catch(err){Log.Add("ReqList.Initialize", err, LogType.Error)}
			},
			
			// the xml passed in is the entire response which may or may not contain a reqlist
			Show: function(xml)
			{
			  try{
				
				  if(!this.Enabled)
					  return;
				
				  var callback = $(xml).find("stingray>callback").text();
					
				  var status = $(xml).find("stingray>status").text();
					
					if((callback == 0) && (status != "error"))
					  return;

  			  var req = $(xml).find("stingray>reqlist");
				
	  			if(req == null)
		  		  ClearList();
			  	else
				    ShowList(req);
						
				}catch(err){Log.Add("ReqList.Show", err, LogType.Error)}
			}			
  	  
			
		}
		
		// clears the list
		function ClearList()
		{
		  try{
			
			  _div.html("<p>There are no req list values to display</p>");
			
			}catch(err){Log.Add("ReqList.ShowList", err, LogType.Error)}
		}
		
		// shows the list
		function ShowList(reqNode)
		{
		  try{
			
			  if(!_div)
				  return;
			
  		  var s = $(reqNode).text();
				
			  var start = new Date();
				
      	var table = "<table class='ReqList'><tr><th>Index</th><th>Name</th><th>Value</th></tr>";
      				
        var regex = /\|{2}/g;
      	
      	var arr = s.split(regex);
      	
      	for(var i = 0; i<arr.length; i++)
      	{
      	  var m = arr[i];
      		var b = m.indexOf("=");
      		table += Utilities.Format("<tr><td class='index'>{0}</td><td class='name' id='{1}'>{2}</td><td class='value'>{3}</td></tr>", [i, m.substring(0, b), m.substring(0, b), m.substring(b+1)]);
      	} 
      	
        table += "</table>";
      	
      	table = $(table);				
				
  			_div.html(table);
				
			}catch(err){Log.Add("ReqList.ShowList", err, LogType.Error)}
		}
	
	
	}catch(err){Log.Add("ReqList", err, LogType.Error)}
}

