// JavaScript Document

var count = 0;

function QA(applet, inputComponent, output){
	
	this.applet = applet;
	this.inputComponent = inputComponent;
	this.outputArea = output;
	
}

function evalInput() {
	var obj = inputComponent.value;
	var startObjNum = applet.getObjectNumber();
	applet.setErrorDialogsActive(false);
  	applet.evalCommand(obj);
  	var endObjNum = applet.getObjectNumber();
	ask(endObjNum-startObjNum,obj);
	answer(endObjNum-startObjNum,obj);
  	return false;
}

function ask(type, objName){
    
		var text;

			if(type==0){
				if(applet.exists(objName)){	
					var strType = applet.getObjectType(objName);
					text = "Q" + count + ": " + strType + " " + objName +"?\n";
					var value = outputArea.value;
            		outputArea.value = value + text;
				}
			}else{
				var name = applet.getObjectName(applet.getObjectNumber()-1);
            	text = "Q" + count + ": " + name +": "+applet.getDefinitionString(name)+" ?\n";
				var value = outputArea.value;
            	outputArea.value = value + text;
			}
       
       
}

function answer(type, objName){
    
		var text;
		if(type == 0){
			if(applet.exists(objName)){
				text = "A" + count + ": " + applet.getValueString(objName)+";\n---\n";
			    var value = outputArea.value;
        		outputArea.value = value + text;
			}
		}else{
            text = "A" + count + ": " + applet.getValueString(applet.getObjectName(applet.getObjectNumber()-1))+";\n---\n";
					var value = outputArea.value;
        	outputArea.value = value + text;
		}
        
		count++;
		
		outputArea.scrollTop = outputArea.scrollHeight;
							
        
    
}

