//Add more fields dynamically.
function addField(area,field,field2,field3,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;
	if (last_item == -1) {
		last_item = 0;
		var last = "1_0";
	} else {
		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 tbody = document.getElementById(area);
		var tr = document.createElement("tr");
		var td = document.createElement("td");
		td.colSpan = 2;
		hr = document.createElement("hr");
		td.appendChild(hr);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tr = document.createElement("tr");
		td = document.createElement("td");
		var txt = document.createTextNode("Select your licensed profession: ");

		//txt.setAttribute("class", "required");
		td.appendChild(txt);
		tr.appendChild(td);
		td = document.createElement("td");
		var input = document.createElement("select");
		input.id = field+'_'+count;
		input.name = field; //+count;
		input.setAttribute("class", "required");
		inputOptions = new Array("Architect", "Engineer", "Contractor", "Subcontractor");
		for (var i=0; i < inputOptions.length; i++) {
			soption = document.createElement('option');
			soption.appendChild(document.createTextNode(inputOptions[i]));
			input.appendChild(soption);
		}
		td.appendChild(input);
		tr.appendChild(td);
		tbody.appendChild(tr);
		tr = document.createElement("tr");
		td = document.createElement("td");
		txt = document.createTextNode("Select the state in which you are licensed: ");
		td.appendChild(txt);
		tr.appendChild(td);
		td = document.createElement("td");
		
		var input2 = document.createElement("select");
		input2.id = field2+'_'+count;
		input2.name = field2; //+count;
		input2.setAttribute("class", "required");
		for (var i=0; i < myArray.length; i++) {
			soption = document.createElement("option");
			soption.appendChild(document.createTextNode(myArray[i][1]));
			soption.value = myArray[i][0];
			input2.appendChild(soption);
		}
		td.appendChild(input2);
		tr.appendChild(td);
		var input3 = document.createElement("input");
		input3.id = field3+"_"+count;
		input3.name = field3;//+count;
		input3.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
		input3.setAttribute("class", "required");
		tbody.appendChild(tr);
		tr = document.createElement("tr");
		td = document.createElement("td");
		var txt = document.createTextNode("Enter your license number for this state: ");
		td.appendChild(txt);
		tr.appendChild(td);
		td = document.createElement("td");
		td.appendChild(input3);
		tr.appendChild(td);
		tbody.appendChild(tr);
	} else { //Older Method
		field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>";
	}
}
function checkit(what) {
	if (what.checked == true) {
		document.getElementById("trTemp" + what.value).className = "marked";
	} else {
		document.getElementById("trTemp" + what.value).className = "";
	}
}
