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;
	var array_count = ((count / 5) + 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 li = document.createElement("li");
			var input = document.createElement("input");
			var input_2 = document.createElement("input");
			var input_3 = document.createElement("input");
			var input_4 = document.createElement("input");
										
				//a.href = ""; 
				input.id = "bates"+"id_"+count;
				input.name = field+"[" + (array_count) + "]"+"[]";
				input.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
				input.size = "10"
				
				
				input_2.id = "bates"+"id_"+(++count);
				input_2.name = field+"[" + (array_count) + "]"+"[]";
				input_2.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
				input_2.size = "10";
				
				
				input_3.id = "bates"+"id_"+(++count);
				input_3.name = field+"[" + (array_count) + "]"+"[]";
				input_3.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
				input_3.size = "10";
				
				
				input_4.id = "bates"+"id_"+(++count);
				input_4.name = field+"[" + (array_count) + "]"+"[]";
				input_4.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
				input_4.size = "10";
				
				//increment the counter 
				count++;
				
				//Create remove button and onclick event to call function  IE6/7 Compatible
				var button = document.createElement("input");
				button.type = "button";
				button.name = "removethis";
				//button.setAttribute('onclick', 'removeFields(this)');
				button.id = "button"+"id_"+count++;
				button.onclick = function () { removeFields(this); }
				button.value = "Remove";
								
				li.appendChild(input);
				li.appendChild(input_2);
				li.appendChild(input_3);
				li.appendChild(input_4);
				field_area.appendChild(li);
				li.appendChild(button);
				
				
		} else { //Older Method
			field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>";
		}
	
}

function removeFields(n) {
	n.parentNode.parentNode.removeChild(n.parentNode);
}
