
/*
		This code is a JavaScript debugging library that can be used to view
	data about a web page. It gives a developer the ability to view
	session, application and page level data and the functionality
	to change the values. 
		The beginDebug() function is called from the page after a successfull login
	attempt. After this the developer must be on the development network to use it.
	Once these requirments are met then the user can access this code. beginDebug() 
	is called to open the debug window. This function will instantiate a new debug 
	class and call all the needed initialization methods. After this the user will
	view the developer page and have the functionality to work with the page data. 
*/

//******* Set some Globals **************
var debugWin;
var parentWin;
//var root = document.URL.substr(0,document.URL.length - document.location.pathname.length);
//var path = root + '/debug/debugger.asp';
var path;
path = 'http://teacenter.com/debug/debugger.asp'
//******* TEST FUNCTION **************
function test(str){alert(str);}
function openGoogle(){debugWin = window.open('http://asptest.fluentedge.com/debug/debugger.asp');}
//************************************

//******* BEGIN STARTER FUNCTIONS **************
function beginDebug(){
	alert(path);
	// http://asptest.fluentedge.com/debug/debugger.asp
	//var debugWin = window.open(path,'Debugger','dependant,height=500,width=500,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
	debugWin = window.open(path,'','dependant,height=500,width=500,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no',false);
	parentWin = debugWin.opener;
	//parentWin.document.getElementById('theBox').value = 'New Value'
	//open the new window document and populate some simple items
	//debugWin.document.open();
	//debugWin.document.write('here it is');
	//debugWin.document.close();
}

function initVars(){
	debugWin = this;
	parentWin = debugWin.opener;
	runPageData();
	//runPageDataByTag('input');
}

//******* BEGIN STARTER FUNCTIONS **************

//******* BEGIN HELPER FUNCTIONS ***************
function toggleTable(currTbl){
	if(document.getElementById){
		thisTbl = document.getElementById(currTbl).style;
		if(thisTbl.display == "block"){
			thisTbl.display = "none";
		}
		else{
			thisTbl.display = "block";
		}
		return false;
	}
	else{
		return true;
	}
}

function command(){
	//alert(str);
	toggleTable('command')
}

function session(){
	//alert(str);
	toggleTable('session')
}

function hideAllData(){
	document.getElementById('command').style.display = "none";
	document.getElementById('session').style.display = "none";
}


function runPageData(){
	// This code is Mozilla(Netscape, Firefox etc) and IE compatible
	//This function will display the entire pages HTML tags and some 
	//helpful values of each
	count = parentWin.document.getElementsByTagName("*").length;
	debugWin.document.write('<div id=""pageData"" name=""pageData"" class=""hide""><p>')
	for (i = 0; i < count; i++){
		allList = parentWin.document.getElementsByTagName("*");
		debugWin.document.write('-------------------------------------------' + '<br>');
		debugWin.document.write(i + ' = ');
		debugWin.document.write(allList.item(i) + '<br>');
		debugWin.document.write('Node Name = ' + allList.item(i).nodeName + '<br>');
		if(allList.item(i).nodeName.toLowerCase() == 'title'){
			debugWin.document.write('innerHTML = ' + allList.item(i).innerHTML + '<br>');
		}else if(allList.item(i).nodeName.toLowerCase() == 'input'){
			debugWin.document.write('Node Type = ' + allList.item(i).type + '<br>');
			debugWin.document.write('Node ID Name = ' + allList.item(i).id + '<br>');
			debugWin.document.write('Node Value = ' + allList.item(i).value + '<br>');
		}else if(allList.item(i).nodeName.toLowerCase() == 'script'){
			debugWin.document.write('Script Text = ' + allList.item(i).innerHTML + '<br>');
		}
		debugWin.document.write('Node Type= ' + allList.item(i).nodeType + '<br>');
	}
	debugWin.document.write('</p></div>')
}

function runPageDataByTag(tagName){
	// This code is Mozilla(Netscape, Firefox etc) and IE compatible
	//This function will display the specified page HTML tags and some 
	//helpful values of that tag type
	count = parentWin.document.getElementsByTagName(tagName).length;
	debugWin.document.write('<div id=""pageData"" name=""pageData"" class=""hide""><p>')
	for (i = 0; i < count; i++){
		allList = parentWin.document.getElementsByTagName(tagName);
		debugWin.document.write('-------------------------------------------' + '<br>');
		debugWin.document.write(i + ' = ');
		debugWin.document.write(allList.item(i) + '<br>');
		debugWin.document.write('Node Name = ' + allList.item(i).nodeName + '<br>');
		if(allList.item(i).nodeName.toLowerCase() == 'title'){
			debugWin.document.write('innerHTML = ' + allList.item(i).innerHTML + '<br>');
		}else if(allList.item(i).nodeName.toLowerCase() == 'input'){
			debugWin.document.write('Node Type = ' + allList.item(i).type + '<br>');
			debugWin.document.write('Node ID Name = ' + allList.item(i).id + '<br>');
			debugWin.document.write('Node Value = ' + allList.item(i).value + '<br>');
		}else if(allList.item(i).nodeName.toLowerCase() == 'script'){
			debugWin.document.write('Script Text = ' + allList.item(i).innerHTML + '<br>');
		}
		debugWin.document.write('Node Type= ' + allList.item(i).nodeType + '<br>');
	}
	debugWin.document.write('</p></div>')
}

				
//******* END HELPER FUNCTIONS **************


//******** BEGIN COMMAND WINDOW EXECUTION FUNCTIONS ***************
function execute(){
	//debugWin.document.open();
	var varItem
	var answer
	var cmd = debugWin.document.getElementById('cmdLine').value;
	
	// first see if we are trying to get a value of a hidden <input> item
	if(cmd.substr(0,1) == '?'){
		try{
				varItem = cmd.substr(1);
				answer = parentWin.document.getElementById(varItem).value;
				debugWin.document.getElementById('cmdDisp').value = varItem + ' = ' + answer;
			}catch(e){
				debugWin.document.getElementById('cmdDisp').value = varItem + ' = ' + ' Not found on the page!';
				//alert("Oops! Something bad just happened. Calling 911...");
			}
	}// next see if we are trying to execute an intrinsic command item
	else if(cmd.substr(0,1) == '!'){
		try{
				var cmdName	
				var itemName;
				
				cmdName = cmd.substr(1,cmd.indexOf('(')-1);
				itemName = cmd.substr(cmd.indexOf('(')+1).substr(0,cmd.substr(cmd.indexOf('(')+1).indexOf(')'));
				
				if(cmdName.toLowerCase() == 'object'){
					try{
							answer = parentWin.document.getElementById(itemName);
							debugWin.document.getElementById('cmdDisp').value = itemName + ' = ' + answer;	
						}catch(e){
							debugWin.document.getElementById('cmdDisp').value = e.message;
						}
				}
				else if(cmdName.toLowerCase() == 'post'){
					try{
							parentWin.document.forms[itemName].submit();	
						}catch(e){
							debugWin.document.getElementById('cmdDisp').value = e.message;
						}
				}

		}catch(e){
			debugWin.document.getElementById('cmdDisp').value = e.message;
		}
	}// Try executing the statements as javascript commands against the parent page
	else{
		try{
				answer = parentWin.eval(cmd);
				debugWin.document.getElementById('cmdDisp').value =' = ' + answer;
			}catch(e){
				debugWin.document.getElementById('cmdDisp').value = e.message;
			}
	}
	
}
//******** end COMMAND WINDOW EXECUTION FUNCTIONS ***************

//******* BEGIN CLASS FUNCTIONS **************
function cDebug(name,id){
	this.name=name;
	this.id=id;
}
//******* END CLASS FUNCTIONS **************
