16-Apr-08 (Created: 16-Apr-08) | More in 'CS-JavaScript'

javascript isDefined? isVariableDefined? isFunctionDefined?


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 = "";
}