function testScreen()
{
	testScreen2();
}

function testScreen1()
{
	//alert("in test");
	subject = document.FeedbackForm.subject.value;
	if (subject == "")
	{
		alert("Sorry, you have to have a subject");
		document.FeedbackForm.subject.focus();
		return;
	}
	username = document.FeedbackForm.username.value;
	if (username == "") 
	{
		document.FeedbackForm.username.value="annonymous";
	}
	appendText = document.FeedbackForm.appendText.value;
	if (appendText == "") 
	{
		var defappendText="<p>" + subject + "</p>";
		document.FeedbackForm.appendText.value= defappendText;
	}
	
	var d = new Date();
	rs = d.toLocaleString();
	document.FeedbackForm.date.value=rs;
	
	document.FeedbackForm.action="/akc/servlet/DisplayServlet";
	document.FeedbackForm.submit();
	
}

function testScreen2()
{
	//alert("in test");
	var subject = document.FeedbackForm.subject.value;
	var username = document.FeedbackForm.username.value;
	var appendText = document.FeedbackForm.appendText.value;
	
	var newValues = new CommandInterpreter(subject,appendText);
	if (newValues.errorMessage != "")
	{
		alert(newValues.errorMessage);
		return;
	}
	
	//there is no error
	subject = newValues.newSubject;
	appendText = newValues.newAppendText;
	alert("appendText:" + newValues.newAppendText);
	
	
	if (subject == "")
	{
		alert("Sorry, you have to have a subject");
		document.FeedbackForm.subject.focus();
		return;
	}
	
	if (username == "") 
	{
		document.FeedbackForm.username.value="annonymous";
	}
	if (appendText == "") 
	{
		var defappendText="<p>" + subject + "</p>";
		document.FeedbackForm.appendText.value= defappendText;
	}
	else
	{
		document.FeedbackForm.appendText.value= appendText;
		document.FeedbackForm.subject.value = subject;
	}
	
	var d = new Date();
	rs = d.toLocaleString();
	document.FeedbackForm.date.value=rs;
	
	document.FeedbackForm.action="/akc/servlet/DisplayServlet";
	document.FeedbackForm.submit();
	
}
function CommandInterpreter(inSubject, inAppendText)
{
	this.newSubject="";
	this.newAppendText = "";
	this.command="";
	this.errorMessage="";
	
	var trimSubject = inSubject.trim();
	var trimAppendText = inAppendText.trim();
	
	//See if a command is present
	var subjectArray = inSubject.split("|");
	if (subjectArray.length <= 1)
	{
		//there is no command
		this.newSubject=trimSubject;
		this.newAppendText = trimAppendText;
		return;
	}
	//there is command
	this.command = subjectArray[1];
	this.newSubject = subjectArray[0];
	alert('recognized command:' + this.command);
		
	//there is command
	commandfuncname = "aspire_" + this.command + "Command";
	var funcobject;
	eval("funcobject = " + commandfuncname + ";");
	alert(typeof(funcobject));
	if (typeof(funcobject) == "function")
	{
		//aspire_linkCommand(this.command, this.newSubject,trimAppendText,this);
		funcobject(this.command, this.newSubject,trimAppendText,this,inSubject,inAppendText);
	}
	else
	{
		this.errorMessage="Sorry, command not recognized:" + this.command;
	}
	return;
}

//command is available
//linkText : 1st argument or subject
//linkUrl: body text
//ci: command interpreter
function aspire_linkCommand(commandname, linkText, linkUrl, ci
			, completesubjectline
			, completeBody)
{
	alert(linkText);
	alert(linkUrl);
	
	if (linkText == "")
	{
		this.errorMessage = "Subject is empty";
		return;
	}
	if (linkUrl == "")
	{
		this.errorMessage = "A url is required for a link command";
		return;
	}
	
	var finalBody = '<p><a href="' + linkUrl + '">' + linkText + '</a></p>';
	alert(finalBody);
	ci.newAppendText = finalBody;
	ci.newSubject = linkText;
}

function aspire_echoCommand(commandname, subject, body, ci
			, completesubjectline
			, completeBody)
{
	alert("commandname:" + commandname);
	alert("subject:" + subject);
	alert("trimmedbody:" + body);
	alert("completesubjectline:" + completesubjectline);
	alert("completebody:" + completeBody);
	ci.newSubject=subject;
	ci.newAppendText = "";
}

satya - Wednesday, April 16, 2008 1:45:31 PM

how to check javascript for an undefined variable in eval

Search for: how to check javascript for an undefined variable in eval

satya - Wednesday, April 16, 2008 1:58:28 PM

checking for a null variable


<script> 
var test; 
if(test!=null){ 
document.write("exists!"); 
}else{ 
document.write("Nope"); 
} 
</script>

satya - Wednesday, April 16, 2008 1:58:43 PM

checking for undefined


<script> 
var test=1; 
if(typeof(test)=="undefined"){ 
document.write("undefined"); 
}else{ 
document.write("Exists"); 
} 
</script>

satya - Wednesday, April 16, 2008 2:04:44 PM

checking a variable at run time if it exists: IsVariableDefined?


function isVariableDefined(variablename)
{
	var t;
	var ex = "t = (typeof(" + variablename + ") == \"undefined\");";
	//alert(ex);
	eval(ex);
	//alert(t);
	return t;
}

satya - Wednesday, April 16, 2008 2:05:25 PM

executing a function conditionally


function executeConditionalOnLoad()
{
	var funcobject = getAFunctionObject("akc_onload_function");
	if (funcobject != null)
	{
		funcobject();
	}
}

satya - Wednesday, April 16, 2008 2:05:46 PM

getting a function object if it exists


function getAFunctionObject(functionName)
{
	var t = isVariableDefined(functionName);
	if (t == false)
	{
		//alert("function is defined");
		var funcobject;
		eval("funcobject = " + functionName + ";");
		return funcobject;
	}
	return null;
}

satya - Wednesday, April 16, 2008 5:46:47 PM

putting it all together


function executeConditionalOnLoad()
{
	var funcobject = getAFunctionObject("akc_onload_function");
	if (funcobject != null)
	{
		funcobject();
	}
}