/**
 *	Created with MAX's HTML Beauty++ 2004
 *	answerElement.js
 *	@author Amani Ahmed
 *	@date July 13 2004
*/


/**
 * This constructor is used to create a new input space for a pForm, called an 
 * answerElement, that is given a default name and size
 * @param 	aType		a string defining type of bank to use
 *			menu		an array of strings for the dropdown menu options
 *						or multiple choice options			
*/
var defaultIndex = 0;
function answerElement(aType, menu) {	
	this.aName = "default"+defaultIndex;
	this.aType = aType;		
	this.menu = menu;
	this.aSize = 5;
	this.change = null;
    this.writeBlank = writeBlank;

	defaultIndex++;
}

/** 
 * This constructor is used to create a new input space
 * for a pForm, called an answerElement
 * @param 	aName		a string defining the name/id of the blank
 *			aType 		a string defining the type of blank to use
 * 			menu		an array of strings for the dropdown menu options
 *						or multiple choices options
 *			change		a string defining the validation script to be run onChange
 *			aSize		a integer defining the size of the blank to use
 */
function answerElement(aName, aType, menu, change, aSize) {	
	if(aName != "" && aName != null)
		this.aName = removeTags(aName);
	else{	
		this.aName = "default"+defaultIndex;	
		defaultIndex++;	
	}
	
	this.aType = aType;
	this.menu = menu;
	this.aSize = aSize;
	this.change = change;
    this.writeBlank = writeBlank;
}

/**
 * Inserts a blank space (textbox or dropdown menu) into a pForm
 * or creates multiple choice answers with radio buttons or check boxes
 */
function writeBlank() {
	if(this.aType == "text")			// text box blank
		document.writeln("<input type='text' size='"+this.aSize+"' id='"+this.aName+"' name='"+this.aName+"' onChange='"+this.change+"'/>");
	else if(this.aType == "menu"){		//drop-down menu blank		
		if(this.menu != null){
			document.writeln("<select id='"+this.aName+"' name='"+this.aName+"' onChange='"+this.change+"'>");

			document.writeln("<option><\/option>");		
			
			for(cnt = 0; cnt < (this.menu).length; cnt++)
				document.writeln("<option>", (this.menu)[cnt], "<\/option>");		
			
			document.writeln("</select>");	
		}else alert('menu error in writeBlanks');
	}else if(this.aType == "radio"){	// multiple choice with only 1 correct answer (radio button)
		if(this.menu != null){
			radioElements="<div class='qmultiple'>"
			for(cnt = 0; cnt < (this.menu).length; cnt++)
				radioElements+=((cnt==0)?"":"<br \/>")+"<input type='radio' id='"+this.aName+"' name='"+this.aName+"' value='"+cnt+"'>"+(this.menu)[cnt];								
		}else alert('menu error in writeBlanks');
		radioElements+="<\/div>";
		document.writeln(radioElements);	
	}else if(this.aType == "checkBox"){	// multiple choice with more than 1 correct answer (check boxes)
		if(this.menu != null){
			for(cnt = 0; cnt < (this.menu).length; cnt++)
				document.writeln("<br><span class='qmultiple'><input type='checkbox' id='"+this.aName+cnt+"' name='"+this.aName+cnt+"'>"+(this.menu)[cnt]+"<\/span>");	
		}else alert('menu error in writeBlanks');
	}else alert('type error in writeBlanks'); // type given is not an option
}
