
//Add more fields dynamically.
function addField(area,field,limit) {
	if(!document.getElementById) return; //Prevent older browsers from getting any further.
	var field_area = document.getElementById(area);
	var all_inputs = field_area.getElementsByTagName("input"); //Get all the input fields in the given area.
	//Find the count of the last element of the list. It will be in the format '<field><number>'. If the 
	//		field given in the argument is 'friend_' the last id will be 'friend_4'.
	var last_item = all_inputs.length - 1;
	var last = all_inputs[last_item].id;
	var count = Number(last.split("_")[1]) + 1;
	
	//If the maximum number of elements have been reached, exit the function.
	//		If the given limit is lower than 0, infinite number of fields can be created.
	if(count > limit && limit > 0) return;
 	
	if(document.createElement) { //W3C Dom method.
		var tr = document.createElement("tr");
		var td_text = document.createElement("td");
		var td_radio = document.createElement("td");
		var input_text = document.createElement("input");
		var input_correct = document.createElement("input");
		input_text.id = field+count;
		input_text.name = "data[Answer]["+count+"][text]";
		input_text.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
		td_text.appendChild(input_text);
		input_correct.id = field+count;
		input_correct.name = "data[Answer]["+count+"][correct]";
		input_correct.type = "text";
		td_radio.appendChild(input_correct);
		tr.appendChild(td_text);
		tr.appendChild(td_radio);
		field_area.appendChild(tr);
	} 
}
	
