/**
 *	Created with MAX's HTML Beauty++ 2004
 *	fbElement.js
 *	@author Amani Ahmed, Jordi Cuadros
 *	@date July 13 2004
*/

/**
* Keep an ordering to avoid duplicated names
*/
var defaultElementIndex=0;

/** 
 * This constructor is used to create a new input textbox space
 * for a fbForm, called an fbText
 * @param 	eName		a string defining the name/id of the blank
 *			change		a string defining the validation script to be run onChange
 *			eSize		a integer defining the size of the blank to use
 */
function fbText(eName, change, eWidth) {	
	if(eName != "" && eName != null)
		this.eName = removeTags(eName);
	else{	
		this.eName = "default"+defaultElementIndex;	
		defaultElementIndex++;	
	}
	if (eWidth==null || eWidth=="")
		this.eWidth=10;
	else this.eWidth = eWidth;
	if (change==null || change=="")
		this.onChange= "true";
	else this.onChange = change;
    this.writeBlank = writeText;
}

/** 
 * This constructor is used to create a new input dropdown list space
 * for a fbForm, called an fbCombo
 * @param 	eName		a string defining the name/id of the blank
 * 			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
 */
function fbCombo(eName, menu, change) {	
	if(eName != "" && eName != null)
		this.eName = removeTags(eName);
	else{	
		this.eName = "default"+defaultElementIndex;	
		defaultElementIndex++;	
	}
/*	if (eWidth==null || eWidth=="")
		this.eWidth=10;
	else this.eWidth = eWidth;*/
	this.menu=menu;
	if (change==null || change=="")
		this.onChange= "true";
	else this.onChange = change;
    this.writeBlank = writeCombo;
}

/** 
 * This constructor is used to create a new input space
 * for a fbForm, called an fbTextArea
 * @param 	eName		a string defining the name/id of the blank
 * 			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
 *			eWidth, eHeight		integers defining the size of the blank to use
 */
function fbTextArea(eName, change,eWidth,eHeight) {	
	if(eName != "" && eName != null)
		this.eName = removeTags(eName);
	else{	
		this.eName = "default"+defaultElementIndex;	
		defaultElementIndex++;	
	}
	if (eWidth==null || eWidth=="")
		this.eWidth=50;
	else this.eWidth = eWidth;
	if (eHeight==null || eHeight=="")
		this.eHeight=4;
	else this.eHeight = eHeight;
	if (change==null || change=="")
		this.onChange= "true";
	else this.onChange = change;
    this.writeBlank = writeTextArea;
}

/**
 * Inserts a dropdown list into a fbForm
 */
function writeCombo() {
	if(this.menu != null){
		document.writeln("<select id='"+this.eName+"' name='"+this.eName+"' onChange='return "+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 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
}*/

/**
 * Creates the markup for a text input box
 */
function writeText() {
	document.writeln("<input type='text' size='"+this.eWidth+"' id='"+this.eName+"' name='"+this.eName+"' onChange='return "+this.onChange+";'/>");
}

/**
 * Creates the markup for a textarea input box
 */
function writeTextArea() {
	document.writeln("<textarea cols='"+this.eWidth+"' rows='"+this.eHeight+"' id='"+this.eName+"' name='"+this.eName+"' onChange='return "+this.onChange+";' ></textarea>");
}
