function qualForm(){
	//init class variables
	this.qualForm = this;

	//init arrays to hold all data elements
	this.typeIDs = new Array();
	this.qualifications = new Array();
	this.activeRows = new Array();
	
	//init error Array
	this.errors = null;

//////////////////////////////////////////////////////////
// Functions:
//////////////////////////////////////////////////////////

	//initialize the activeRows locations to be used later
	this.initActiveRow = function(type_id) {
		this.activeRows[type_id] = 0;
		this.typeIDs.push(type_id);
	}

	//increments the counter for active rows.
	//used in conjunction with generic messages:
	//"There are currently no $foo requirements." 
	this.addActiveRow = function(type_id) { 
		this.activeRows[type_id]++;
	}

	//decrements the counter for active rows.
	//used in conjunction with generic messages:
	//"There are currently no $foo requirements." 
	this.removeActiveRow = function(type_id) { 
		this.activeRows[type_id]--;
	}

	//adds the current type ID and the current minimum qualification ID to
	//an array tracking IDs of old qualification line items being edited.
	this.addMinQual = function(type_id, qual_id) {
		this.qualifications.push([type_id, qual_id])
	}

	//Packages up array data that has been collected while the page was in use 
	//and adds it to a form field
	this.submissionScript = function() {
		var qualVar = new String(this.qualifications.join());
	
		var joinField = document.createElement("input");
		joinField.setAttribute("type", "hidden");
		joinField.setAttribute("name", "js_qual_array");
		joinField.setAttribute("id", "js_qual_array");
		joinField.setAttribute("value", qualVar);
		
		submitButton = document.getElementById('submit_button');
		submitButton.parentNode.insertBefore(joinField, submitButton);
		theForm = document.getElementById('form_id');
		//alert(theForm.action);
		foo = document.getElementById('min_qual_text_1_new_1')

		return true;
	}

	this.initQualAdjustment = function(qualList, typeNumber, numNewQuals) {
		var qualRows = document.getElementById(qualList);
		var numAdjustments = document.getElementById(numNewQuals);
		
		numAdjustments.value = parseInt(numAdjustments.value) + 1;
		var currID = numAdjustments.value;
		qualForm.addActiveRow(typeNumber);

		//cell layout is as follows:
		//active? and Up arrow
		//order and Down arrow
		//text field
		//delete button

		row_ID = 'min_qual_row_'+typeNumber+'_new_'+currID;
		cell_0 = '<input type="hidden" name="min_qual_active_'+typeNumber+'_new_'+currID+'" id="min_qual_active_'+typeNumber+'_new_'+currID+'" value="true"><a href="#" onclick="qualForm.rowUp(\''+row_ID+'\'); return false;"><img src="images/icon_up.gif" alt="Move Up" width="12" height="19" hspace="0" vspace="0" border="0"></a>';
		cell_1 = '<input type="hidden" name="min_qual_order_'+typeNumber+'_new_'+currID+'" id="min_qual_order_'+typeNumber+'_new_'+currID+'" value="'+this.activeRows[typeNumber]+'"><a href="#" onclick="qualForm.rowDown(\''+row_ID+'\'); return false;"><img src="images/icon_down.gif" alt="Move Down" width="12" height="19" hspace="0" vspace="0" border="0"></a>';
		cell_2 = '<textarea class="formElement" name="min_qual_text_'+typeNumber+'_new_'+currID+'" id="min_qual_text_'+typeNumber+'_new_'+currID+'" rows="2" cols="90"></textarea>';
		cell_3 = '<a href="#" onClick="qualForm.deleteQualAdjustment(\'min_qual_row_'+typeNumber+'_new_'+currID+'\'); return false;"><img src="images/icon_redx.gif" alt="Delete Requirement" width="12" height="11" border="0"></a>';

		//qualForm.removeTextNodes(qualRows);
		qualRows.insertBefore(qualForm.createQualRow(row_ID, cell_0, cell_1, cell_2, cell_3), qualRows.rows[0]);
		
		//remove the "There are no _foo_ requirements" line, if it exists
		qualForm.deleteQualAdjustment('no_reqs_' + typeNumber);
	}//end function	
	
	this.deleteQualAdjustment = function(row_id){
		var row = document.getElementById(row_id);
		var s = new String(row_id);
		s = s.replace(/row/, "active"); //min_qual_active_1_2

		var min_qual_active = document.getElementById(s);
		var charIndex = s.search(/[0-9]/);
		var typeNumber = parseInt(s.charAt(charIndex), 10);
		if(s.search("no_reqs_") != -1) {
			min_qual_active.value = "false";
			row.style.display = "none";
		}
		else {
			min_qual_active.value = "false";
			row.style.display = "none";
			qualForm.removeActiveRow(typeNumber);
		}
		row.parentNode.appendChild(row);

		if(this.activeRows[typeNumber] == 0) { //if there are no active rows for this type anymore, then...
			var genericRow = document.getElementById('no_reqs_' + typeNumber);
			genericRow.style.display = ""; //this should be "table-row", but IE fails if that is used.
			genericRow.parentNode.insertBefore(genericRow, genericRow.parentNode.rows[0]);
		}
		
	}//end function
	
	this.rowDown = function(row_id) {
		var node = document.getElementById(row_id);
		if(undefined != node.nextSibling && node.nextSibling.nodeName == "#text") {
			node.parentNode.removeChild(node.nextSibling);
		}
		if(undefined != node.nextSibling && node.nextSibling.style.display != "none" && node.nextSibling.nodeName != "SCRIPT") {
			//decrement this node's order value
			tmpStr = new String(node.id);
			tmpStr = tmpStr.replace(/row/, "order");
			orderNum = document.getElementById(tmpStr);
			orderNum.value = parseInt(orderNum.value) - 1;
			
			//increment the order value of the row we're swapping with
			sib = node.nextSibling;
			tmpStr2 = new String(sib.id);
			tmpStr2 = tmpStr2.replace(/row/, "order");
			orderNum2 = document.getElementById(tmpStr2);
			orderNum2.value = parseInt(orderNum2.value) + 1;

			node.parentNode.insertBefore(node.nextSibling, node);
			return true;
		}
		else {
			return false;
		}
	}//end function

	this.rowUp = function(row_id) {
		var node = document.getElementById(row_id);
		if(undefined != node.previousSibling && node.previousSibling.nodeName == "#text") {
			node.parentNode.removeChild(node.previousSibling);
		}
		if(node.parentNode.firstChild != node && node.previousSibling.nodeName != "SCRIPT") {
			//increment this node's order value
			tmpStr = new String(node.id);
			tmpStr = tmpStr.replace(/row/, "order");
			orderNum = document.getElementById(tmpStr);
			orderNum.value = parseInt(orderNum.value) + 1;
			
			//decrement the order value of the row we're swapping with
			sib = node.previousSibling;
			tmpStr2 = new String(sib.id);
			tmpStr2 = tmpStr2.replace(/row/, "order");
			orderNum2 = document.getElementById(tmpStr2);
			orderNum2.value = parseInt(orderNum2.value) - 1;

			node.parentNode.insertBefore(node, node.previousSibling);
			return true;
		}
		else {
			return false;
		}
	}

	this.createNoRequirementsMessage = function(typeName, typeNumber){
		var row_id = 'no_reqs_' + typeNumber;
		
		currRow = document.createElement("tr");				
		currRow.setAttribute("id", row_id);

		cell = document.createElement("td");
		cell.innerHTML = 'There are currently no ' + typeName + ' requirements.';
		cell.setAttribute("className", "contentCell");
		cell.setAttribute("align", "left");
		currRow.appendChild(cell);
		
		return currRow;
	}
	
	this.createQualRow = function(rowID, cell0, cell1, cell2, cell3){
		currRow = document.createElement("tr");	
		currRow.setAttribute("id", rowID);
			
		cell = document.createElement("td");
		cell.innerHTML = cell0;
		cell.setAttribute("class", "contentCell");
		cell.setAttribute("className", "contentCell");
		cell.setAttribute("align", "left");
		currRow.appendChild(cell);	

		cell = document.createElement("td");
		cell.innerHTML = cell1;
		cell.setAttribute("class", "contentCell");
		cell.setAttribute("className", "contentCell");
		cell.setAttribute("align", "left");
		currRow.appendChild(cell);	

		cell = document.createElement("td");
		cell.innerHTML = cell2;
		cell.setAttribute("class", "contentCell");
		cell.setAttribute("className", "contentCell");
		cell.setAttribute("align", "left");
		currRow.appendChild(cell);	
		
		cell = document.createElement("td");
		cell.innerHTML = cell3;
		cell.setAttribute("class", "contentCell");
		cell.setAttribute("className", "contentCell");
		cell.setAttribute("align", "right");
		currRow.appendChild(cell);	

		return currRow;
	}
	
	this.removeTextNodes = function(tBodyTag) {
		for (i=0; i < tBodyTag.childNodes.length; i++) {
			node = tBodyTag.childNodes[i];
			if ( node.nodeType == 3 ) {
				tBodyTag.removeChild(node);
			}
		}
	}
	
} //end obj

qualForm = new qualForm();

employNotes = new Array();
		



