function selectPipe(pipeID){
	targetForm = document.getElementById("mainControlForm");
	targetForm.action = "main.aspx";
	pipeIdElement = document.getElementById("pipe");
	pipeIdElement.value = pipeID;
	pipeIdElement.click();
}
				
function selectNode(nodeID){
	targetForm = document.getElementById("mainControlForm");
	targetForm.action = "main.aspx";
	pipeIdElement = document.getElementById("changeNode");
	pipeIdElement.value = nodeID;
	pipeIdElement.click();
}
				
function selectDownStreamNode(nodeID){
	targetForm = document.getElementById("mainControlForm");
	targetForm.action = "main.aspx";
	pipeIdElement = document.getElementById("changeDownStreamNode");
	pipeIdElement.value = nodeID;
	pipeIdElement.click();
}
					
function doPathSelection(pathId){

	// reset the currentAnchor
	setCurrentAnchor("");

	targetForm = document.getElementById("mainControlForm");
	targetForm.action = "main.aspx";
	pipeIdElement = document.getElementById("pathToSelect");
	pipeIdElement.value = pathId;
	pipeIdElement.click();
}
function setShiftMod(evnt){
	if(evnt.shiftKey){
		document.getElementById("shiftModifier").checked = true;
	}
	return false;
}
					
function unSetShiftMod(evnt){
	if(evnt.shiftKey == false){
		document.getElementById("shiftModifier").checked = false;
	}
}
function changeElementClass(targetElement, newClass){
	if(targetElement != null){
		targetElement.className = newClass;
	}
}

function setCurrentAnchor(anchor){
	targetField = document.getElementById("currentAnchor");
	if(targetField != null){
		targetField.value = anchor;
	}
}

function appendAnchorToFormAction(){
	targetField = document.getElementById("currentAnchor");
	if(targetField != null && targetField.value != ""){
		targetForm = document.getElementById("mainControlForm");
		targetForm.action = "main.aspx" + getCurrentAnchor();
	}
}

function getCurrentAnchor(){
	targetField = document.getElementById("currentAnchor");
	if(targetField != null && targetField.value!=""){
		return "#"+targetField.value;
	}	
	return "";
}

function TimedReminder(){
	setTimeout("alert('Your PDF Fabrication sheet will now be available.')",5000);
}

function makeFlowRateAllTheSame(elementToCheck){

	// even though there are many newFlowRate Elements, the first one is fetched by getElementById
	// which is the one we want as the default value. How Handy.
	if(elementToCheck.checked == true){
		defaultValue = document.getElementById("newFlowRate").value;

		frPanel = document.getElementById("flowRateTable");
		tableRows = frPanel.getElementsByTagName("tr");

		for(i = 0; i < tableRows.length; i++){
			cells = tableRows[i].getElementsByTagName("td");
			if(cells.length == 2){
				cells[1].getElementsByTagName("input")[0].value = defaultValue;
				if(i > 0){
					cells[1].getElementsByTagName("input")[0].readOnly = true
				}
			}
		}
	}

	if(elementToCheck.checked == false){
		frPanel = document.getElementById("flowRateTable");
		tableRows = frPanel.getElementsByTagName("tr");

		for(i = 0; i < tableRows.length; i++){
			cells = tableRows[i].getElementsByTagName("td");
			if(cells.length == 2){
				cells[1].getElementsByTagName("input")[0].readOnly = false;
			}
		}
	}

}

