<!--
/********************************************************************************************************
 * Main.js 
 * Description: Contains all the Global Variables and Functions used in Main.html. 
 *              The Child page like DriverFactor.html uses some of these functions as well.
 *              This script requires the class definitions in classes.js.
 *              
 * Version: 2.2 
 *
 * Revisions:   Date         Participant                What is done
 *              04/02/2004   Michael Chuang             Draft the functionality for Step 1
 *              04/10/2004   Shaofeng Xi                Create the file with refactoring the code of Michael Chuang 
 *              04/11/2004   Shaofeng Xi                Create functions to initiate the page and add Estimation History Table
 *              04/15/2004   Shaofeng Xi                Add Calculation functionality
 *              04/18/2004   Shaofeng Xi                Add updateSequenceNo for Updating Estimation History, finish Update
 *		07/14/2004   Michael Chuang		Corrected Formulas (for KSLOC and Scale Factors)
 *		07/15/2004   Michael Chuang		Turned off update, so you can only input once (Too confusing with update)
 *		07/29/2004   Michael Chuang		Added Estimate Time functions
 *		08/01/2004   Michael Chuang		Changed functionality of mode buttons
  *		08/14/2004   Michael Chuang		Fixed Reset Button, changed table header to update real-time 
 *******************************************************************************************************/


//-----------------------------Global Variables--------------------------------------------------------------------------------Begin
var project = new Project();  //Global Variable stores all the information about the project.

/*********************************************************************************************
The number determines if DriverFactorWindow(The Popup Window) performs "Adding Estimation" or "Updating Estimation".
openDriverFactorWindow is using to popup the DriverFactorWindow.

0 or a number less than 0        represents "Adding Estimation"
a number >= 1                    represents "Updating Estimation" and which Estimation 
                                              (project.estimationHistory[updateSequenceNo-1]) is going to be updated.
*********************************************************************************************/
var updateSequenceNo = 0;   

//-----------------------------Global Variables--------------------------------------------------------------------------------End


//----------Initiate Project object-----------------------------------------Begin
project.loadAnalogyParameter();
project.loadCalibrationValues(project.DEFAULT_VALUES);  //Using COCOMO Default Values
//----------Initiate Project object-----------------------------------------End
    

function initiatePage() {
    var i;
    var analogyParameter;
    var option_obj;
    
    for(i=0; i<project.analogyParameterList.length; i++) {
        analogyParameter = project.analogyParameterList[i];
        
        option_obj = document.createElement("option");
        option_obj.value = analogyParameter.value;
        option_obj.text = analogyParameter.name;
        document.ProjectForm.AnalogyParameterDropdown.add(option_obj);
    }
    
    onAnalogyParameterChange("AP01");  //Display HTML elements for Default Analogy Parameter
}

/*******************************************************************
Hide HTML elements for Project Form
*******************************************************************/
function hideAllInputs() {
    
    document.getElementById("ProjectNameLabel").style.display = "none";
    document.getElementById("ProjectNameInput").style.display = "none";
    
    document.getElementById("BaselineValueLabel").style.display = "none";
    document.getElementById("BaseLineValueLabel").style.display = "none";
    document.getElementById("BaselineValueUnit_AP01").style.display = "none";
    document.getElementById("BaselineValueUnit_AP02").style.display = "none";
    document.getElementById("BaselineValueUnit_AP03").style.display = "none";
    document.getElementById("BaselineValueUnit_AP04").style.display = "none";
    document.getElementById("BaselineValueUnit_AP05").style.display = "none";
    document.getElementById("BaselineValueUnit_AP06").style.display = "none";
    document.getElementById("BaselineValueUnit_AP07").style.display = "none";
    
    document.getElementById("CurrentSLOCLabel").style.display = "none";
    document.getElementById("CurrentSLOCInput").style.display = "none";
    
    document.getElementById("CurrentFunctionPointLabel").style.display = "none";
    document.getElementById("CurrentFunctionPointInput").style.display = "none";
    
    document.getElementById("CurrentLaborRateLabel").style.display = "none";
    document.getElementById("CurrentLaborRateInput").style.display = "none";
    
    document.getElementById("CurrentLaborRateForIdealWeekLabel").style.display = "none";
    document.getElementById("CurrentLaborRateForIdealWeekInput").style.display = "none"; 
    
    document.getElementById("CurrentIterationNoLabel").style.display = "none";
    document.getElementById("CurrentIterationNoInput").style.display = "none"; 
    
    document.getElementById("AddLaborRateButton").style.display = "none";     
}

function displayCommonInputs() {
    document.getElementById("ProjectNameLabel").style.display = "";
    document.getElementById("ProjectNameInput").style.display = "";
    
    document.getElementById("BaselineValueLabel").style.display = "";
    document.getElementById("BaseLineValueLabel").style.display = "";
      
}

function onAnalogyParameterChange(value) {
    var analogyParameter;
    
    analogyParameter = project.getAnalogyParameter(value);
    if(null != analogyParameter) {
        project.analogyParameter = analogyParameter;
    }
    else {
        alert("There's not corresponding Analogy Parameter loaded. Please check the source!"); 
        return;
    }
   
    updateMenu();

        var projectName_obj = document.ProjectForm.ProjectName;
        var baselineValue_obj = document.ProjectForm.BaselineValue;
        var currentSLOC_obj = document.ProjectForm.CurrentSLOC;
        var currentFunctionPoint_obj = document.ProjectForm.CurrentFunctionPoint;
        var currentLaborRate_obj = document.ProjectForm.CurrentLaborRate;
        var currentLaborRateForIdealWeek_obj = document.ProjectForm.CurrentLaborRateForIdealWeek;
    
        projectName_obj.value = "";
        baselineValue_obj.value = "";
        currentSLOC_obj.value = "";
        currentFunctionPoint_obj.value = "";
        currentLaborRate_obj.value = "";
    	currentLaborRateForIdealWeek_obj.value = "";


}

function updateMenu() {
  
   
    hideAllInputs();
    displayCommonInputs();
    
    switch(project.analogyParameter.value) {
        case "AP01": 
            document.getElementById("BaselineValueUnit_AP01").style.display = "";

		if(project.PMmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;
        case "AP02":
            document.getElementById("BaselineValueUnit_AP02").style.display = "";
        
		if(project.dollarsmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;
        case "AP03":
            document.getElementById("BaselineValueUnit_AP03").style.display = "";
            
            document.getElementById("CurrentFunctionPointLabel").style.display = "";
            document.getElementById("CurrentFunctionPointInput").style.display = "";
		
		if(project.PMmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;
        case "AP04":
            document.getElementById("BaselineValueUnit_AP04").style.display = "";
            
            document.getElementById("CurrentSLOCLabel").style.display = "";
    	    document.getElementById("CurrentSLOCInput").style.display = ""; 

		if(project.PMmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;
        case "AP05":
            document.getElementById("BaselineValueUnit_AP05").style.display = "";
            
            document.getElementById("CurrentFunctionPointLabel").style.display = "";
            document.getElementById("CurrentFunctionPointInput").style.display = "";
            
		if(project.dollarsmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;   
        case "AP06":
            document.getElementById("BaselineValueUnit_AP06").style.display = "";
            
		if(project.dollarsmodeon) {
		    document.getElementById("CurrentLaborRateLabel").style.display = "";
		    document.getElementById("CurrentLaborRateInput").style.display = "";
            		
            		if((project.submitted) && (isNaN(project.currentLaborRate)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            document.getElementById("CurrentSLOCLabel").style.display = "";
    	    document.getElementById("CurrentSLOCInput").style.display = ""; 
            
            break;
        case "AP07":
            document.getElementById("BaselineValueUnit_AP07").style.display = "";
                       
		if(project.dollarsmodeon) {
            		document.getElementById("CurrentLaborRateForIdealWeekLabel").style.display = "";
            		document.getElementById("CurrentLaborRateForIdealWeekInput").style.display = ""; 
            		
            		if((project.submitted) && (isNaN(project.currentLaborRateForIdealWeek)))
	            		document.getElementById("AddLaborRateButton").style.display = "";
		}
            
            break;
    }
    
    //deleteAllEstimationFromTable();
    updateTableHeader()
    
}

function updateTableHeader() { 

   if(project.submitted) {

	var effortUnit;
	
	if(project.analogyParameter.value == "AP07")
		effortUnit = "<br>(In IPW)";
	else
		effortUnit = "<br>(In PM)";

	//1 is both dollars and PM, 2 is dollars only, 3 is PM only, 4 is none
	var header1 = "<p><table align='left' width='570' style='border: 1 solid #000000' cellspacing='0' cellpadding='2'>"
		  +  "<tr>"
		  +  "<td width='50' align='center'><span><b>#</b></span></td>"
		  +  "<td width='150' align='center'><span><b>Driver/Factor</b></span></td>"
		  +  "<td width='50' align='center'><span><b>Current</b></span></td>"
		  +  "<td width='50' align='center'><span><b>New</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Estimated Cost</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Estimated Effort"+ effortUnit +"</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Command</b></span></td>"
		  +  "</tr>"
		  +  "</table></p><br>";
		  
	var header2 = "<p><table align='left' width='570' style='border: 1 solid #000000' cellspacing='0' cellpadding='2'>"
		  +  "<tr>"
		  +  "<td width='50' align='center'><span><b>#</b></span></td>"
		  +  "<td width='150' align='center'><span><b>Driver/Factor</b></span></td>"
		  +  "<td width='50' align='center'><span><b>Current</b></span></td>"
		  +  "<td width='50' align='center'><span><b>New</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Estimated Cost</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Command</b></span></td>"
		  +  "</tr>"
		  +  "</table></p><br>";
		  		  
	var header3 = "<p><table align='left' width='570' style='border: 1 solid #000000' cellspacing='0' cellpadding='2'>"
		  +  "<tr>"
		  +  "<td width='50' align='center'><span><b>#</b></span></td>"
		  +  "<td width='150' align='center'><span><b>Driver/Factor</b></span></td>"
		  +  "<td width='50' align='center'><span><b>Current</b></span></td>"
		  +  "<td width='50' align='center'><span><b>New</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Estimated Effort"+ effortUnit +"</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Command</b></span></td>"
		  +  "</tr>"
		  +  "</table></p><br>";	  		  

	var header4 = "<p><table align='left' width='570' style='border: 1 solid #000000' cellspacing='0' cellpadding='2'>"
		  +  "<tr>"
		  +  "<td width='50' align='center'><span><b>#</b></span></td>"
		  +  "<td width='150' align='center'><span><b>Driver/Factor</b></span></td>"
		  +  "<td width='50' align='center'><span><b>Current</b></span></td>"
		  +  "<td width='50' align='center'><span><b>New</b></span></td>"
		  +  "<td width='100' align='center'><span><b>Command</b></span></td>"
		  +  "</tr>"
		  +  "</table></p><br>";
		  
    if((project.dollarsmodeon) && (project.PMmodeon)) {
	    document.getElementById("EstimationHistoryTableHeader").innerHTML = header1;    
    } else if(project.dollarsmodeon) {
	    document.getElementById("EstimationHistoryTableHeader").innerHTML = header2;    
    } else if(project.PMmodeon) {
	    document.getElementById("EstimationHistoryTableHeader").innerHTML = header3;
    } else {
    	document.getElementById("EstimationHistoryTableHeader").innerHTML = header4;
    }		  
    
    
	    if(isNaN(project.step1Value))
		step1 = "N/A";
	    else
		step1 = "$"+ formatAsMoney(project.step1Value);

	    if(isNaN(project.step2Value))
		step2 = "N/A";
	    else
		step2 = formatAsNumber(project.step2Value);


		tr_obj = document.getElementById("EstimationHistoryTable").insertRow(1);

		    if((project.dollarsmodeon) && (project.PMmodeon)) {	    

			    document.getElementById("EstimationHistoryTable").deleteRow(0);

			    td_obj = tr_obj.insertCell(0);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "0"); 

			    td_obj = tr_obj.insertCell(1);
			    td_obj.setAttribute("width", "150");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(2);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(3);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(4);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", ""+step1); 

			    td_obj = tr_obj.insertCell(5);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", ""+step2); 

			    td_obj = tr_obj.insertCell(6);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "(starting)");    

		    } else if(project.dollarsmodeon) {

			    document.getElementById("EstimationHistoryTable").deleteRow(0);

			    td_obj = tr_obj.insertCell(0);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "0"); 

			    td_obj = tr_obj.insertCell(1);
			    td_obj.setAttribute("width", "150");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(2);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(3);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(4);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", ""+step1); 

			    td_obj = tr_obj.insertCell(5);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "(starting)"); 
			    
		    } else if(project.PMmodeon) {
			    
			    document.getElementById("EstimationHistoryTable").deleteRow(0);

			    td_obj = tr_obj.insertCell(0);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "0"); 

			    td_obj = tr_obj.insertCell(1);
			    td_obj.setAttribute("width", "150");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(2);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(3);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(4);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", ""+step2); 

			    td_obj = tr_obj.insertCell(5);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "(starting)");  
		    } else {
			    
			    document.getElementById("EstimationHistoryTable").deleteRow(0);

			    td_obj = tr_obj.insertCell(0);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "0"); 

			    td_obj = tr_obj.insertCell(1);
			    td_obj.setAttribute("width", "150");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(2);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 

			    td_obj = tr_obj.insertCell(3);
			    td_obj.setAttribute("width", "50");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "N/A"); 
			    
			    td_obj = tr_obj.insertCell(4);
			    td_obj.setAttribute("width", "100");
			    td_obj.setAttribute("align", "center");
			    td_obj.insertAdjacentHTML("AfterBegin", "(starting)"); 
			    
		    }

	    rebuildEstimationHistoryTable(1);  //Rebuild from the first element. 
	}
}

function DollarsModeOnChecked() {

	if(project.dollarsmodeon) {
		project.dollarsmodeon = false;
	} else {
		project.dollarsmodeon = true;
	}
	
	updateMenu();

	//rollback if no mode selected
	if(project.submitted) {
		if(isModeValid() == false) {
			alert("Must have one way to estimate!");
			project.dollarsmodeon = true;
			document.getElementById("DollarMode").checked = true;
		} 
		
		if(project.allinput) {
			updateProjectInputs();
		}
	}
	
	updateMenu();

}

function PMModeOnChecked() {
	
	if(project.PMmodeon) {
		project.PMmodeon = false;
		
	} else {
		project.PMmodeon = true;
		
	}
	
	updateMenu();
	
	//rollback if no mode selected
	if(project.submitted) {
		if(isModeValid() == false) {
			alert("Must have one way to estimate!");
			project.PMmodeon = true;
			document.getElementById("PMMode").checked = true;
		} 

		if(project.allinput) {
			updateProjectInputs();
		}
	}
		
	updateMenu();
	
}

function isModeValid() {

    if((project.PMmodeon) || (project.dollarsmodeon)) {
        return(true);   
    } else {
        return(false);  
    }
}


function isProjectNameValid(projectName, projectName_obj) {
    if("" == projectName) {
        alert("Project can't be empty!");
        projectName_obj.focus();
        projectName_obj.select();
        return(false);   
    } else {
        return(true);   
    }
}

function isBaselineValueValid(baselineValue, baselineValue_obj) {
    if("" == baselineValue) {
        alert("Baseline Value can't be empty!");
        baselineValue_obj.focus();
        baselineValue_obj.select();
        return(false);     
    } else {
        if(!isValidNumber(baselineValue)) {
            alert("Baseline Value must be a number!");
            baselineValue_obj.focus();
            baselineValue_obj.select();
            return(false);   
        } else {
		if(Math.round(baselineValue) > 0) {
		    return(true);
		} else {
		    alert("Current Baseline after rounded must be greater than 0!");
		    baselineValue_obj.focus();
		    baselineValue_obj.select();
		    return(false);
		}
        }
    } 
}

function isCurrentSLOCValid(currentSLOC, currentSLOC_obj) {
    var value = project.analogyParameter.value;
    
    if(("AP04" == value) || ("AP06" == value)) {
	    if("" == currentSLOC) {
		alert("Current Project Size (SLOC) can't be empty!");
		currentSLOC_obj.focus();
		currentSLOC_obj.select();
		return(false);     
	    } else {
		if(!isValidNumber(currentSLOC)) {
		    alert("Current Project Size (SLOC) must be a number greater than 0!");
		    currentSLOC_obj.focus();
		    currentSLOC_obj.select();
		    return(false);   
		} else {
		    if(Math.round(currentSLOC) > 0) {
			return(true);
		    } else {
			alert("Current Project Size (SLOC) after rounded must be greater than 0!");
			currentSLOC_obj.focus();
			currentSLOC_obj.select();
			return(false);
		    }
		}
	    } 
    } else {
        return(true);
    }
}

function isCurrentFunctionPointValid(currentFunctionPoint, currentFunctionPoint_obj) {
    var value = project.analogyParameter.value;
    
    if(("AP03" == value) || ("AP05" == value)) {
        if("" == currentFunctionPoint) {
            alert("Current Function Points can't be empty!");
            currentFunctionPoint_obj.focus();
            currentFunctionPoint_obj.select();
            return(false);     
        } else {
            if(!isValidNumber(currentFunctionPoint)) {
                alert("Current Function Points must be a number!");
                currentFunctionPoint_obj.focus();
                currentFunctionPoint_obj.select();
                return(false);   
            } else {
                if(Math.round(currentFunctionPoint) > 0) {
                    return(true);
                } else {
                    alert("Current Function Points after rounded must be greater than 0!");
                    currentFunctionPoint_obj.focus();
                    currentFunctionPoint_obj.select();
                    return(false);
                }
            }
        } 
    } else {
        return(true);
    }
}

function isCurrentLaborRateValid(currentLaborRate, currentLaborRate_obj) {
    var value = project.analogyParameter.value;

    if((project.dollarsmodeon) && (project.PMmodeon)) {
    
	    if(("AP01" == value) || ("AP02" == value) || ("AP03" == value) || ("AP04" == value) || ("AP05" == value) || ("AP06" == value)) {
		if("" == currentLaborRate) {
		    alert("Current Labor Rate can't be empty!");
		    currentLaborRate_obj.focus();
		    currentLaborRate_obj.select();
		    return(false);     
		} else {
		    if(!isValidNumber(currentLaborRate)) {
			alert("Current Labor Rate must be a number!");
			currentLaborRate_obj.focus();
			currentLaborRate_obj.select();
			return(false);   
		    } else {
			if(Math.round(currentLaborRate) > 0) {
			    return(true);
			} else {
			    alert("Current Function Points after rounded must be greater than 0!");
			    currentLaborRate_obj.focus();
			    currentLaborRate_obj.select();
			    return(false);
			}
		    }
		}
	    } else { 
		return(true);
	    }
    }
    
    if(project.dollarsmodeon) {
    
	    if(("AP02" == value) || ("AP05" == value) || ("AP06" == value)) {
		if("" == currentLaborRate) {
		    alert("Current Labor Rate can't be empty!");
		    currentLaborRate_obj.focus();
		    currentLaborRate_obj.select();
		    return(false);     
		}
		else {
		    if(!isValidNumber(currentLaborRate)) {
			alert("Current Labor Rate must be a number greater than 0!");
			currentLaborRate_obj.focus();
			currentLaborRate_obj.select();
			return(false);   
		    } else {
			if(Math.round(currentLaborRate) > 0) {
			    return(true);
			} else {
			    alert("Current Function Points after rounded must be greater than 0!");
			    currentLaborRate_obj.focus();
			    currentLaborRate_obj.select();
			    return(false);
			}
		    }
		}
	    } else { 
		return(true);
	    }
    }
    
    if(project.PMmodeon) {
    
	    if(("AP01" == value) || ("AP03" == value) || ("AP04" == value)) {
		if("" == currentLaborRate) {
		    alert("Current Labor Rate can't be empty!");
		    currentLaborRate_obj.focus();
		    currentLaborRate_obj.select();
		    return(false);     
		} else {
		    if(!isValidNumber(currentLaborRate)) {
			alert("Current Labor Rate must be a number greater than 0!");
			currentLaborRate_obj.focus();
			currentLaborRate_obj.select();
			return(false);   
		    } else {
			if(Math.round(currentLaborRate) > 0) {
			    return(true);
			} else {
			    alert("Current Function Points after rounded must be greater than 0!");
			    currentLaborRate_obj.focus();
			    currentLaborRate_obj.select();
			    return(false);
			}
		    }
		}
	    } else { 
		return(true);
	    }
    }
}

function isCurrentLaborRateForIdealWeekValid(currentLaborRateForIdealWeek, currentLaborRateForIdealWeek_obj) {
    var value = project.analogyParameter.value;
    var mode1 = project.dollarsmodeon;
    
    if(("AP07" == value) && (mode1 == "1")) {
        if("" == currentLaborRateForIdealWeek) {
            alert("Current Labor Rate (for Ideal Week) can't be empty!");
            currentLaborRateForIdealWeek_obj.focus();
            currentLaborRateForIdealWeek_obj.select();
            return(false);     
        } else {
            if(!isValidNumber(currentLaborRateForIdealWeek)) {
                alert("Current Labor Rate (for Ideal Week) must be a number!");
                currentLaborRateForIdealWeek_obj.focus();
                currentLaborRateForIdealWeek_obj.select();
                return(false);   
            }
            else {
		if(Math.round(currentLaborRateForIdealWeek) > 0) {
		    return(true);
		} else {
		    alert("Current Labor Rate (for Ideal Week) after rounded must be greater than 0!");
		    currentLaborRateForIdealWeek_obj.focus();
		    currentLaborRateForIdealWeek_obj.select();
		    return(false);
		}
            }
        }
    } 
    else { 
        return(true);
    }
}



function updateProjectInputs() {



    var returnValue = false;
    var analogyparameter_obj = document.ProjectForm.AnalogyParameterDropdown;
    var projectName_obj = document.ProjectForm.ProjectName;
    var baselineValue_obj = document.ProjectForm.BaselineValue;
    var currentSLOC_obj = document.ProjectForm.CurrentSLOC;
    var currentFunctionPoint_obj = document.ProjectForm.CurrentFunctionPoint;
    var currentLaborRate_obj = document.ProjectForm.CurrentLaborRate;
    var currentLaborRateForIdealWeek_obj = document.ProjectForm.CurrentLaborRateForIdealWeek;

    var projectName = trim(projectName_obj.value);
    var baselineValue = trim(baselineValue_obj.value);
    var currentSLOC = trim(currentSLOC_obj.value);
    var currentFunctionPoint = trim(currentFunctionPoint_obj.value);
    var currentLaborRate = trim(currentLaborRate_obj.value);
    var currentLaborRateForIdealWeek = trim(currentLaborRateForIdealWeek_obj.value);

    if(!isModeValid()) {
        alert("Must have one way to estimate!");
        return(false);
    }
     
    if(!isProjectNameValid(projectName, projectName_obj)) 
        return(false);

    if(!isBaselineValueValid(baselineValue, baselineValue_obj)) 
        return(false);
        
    if(!isCurrentFunctionPointValid(currentFunctionPoint, currentFunctionPoint_obj)) 
        return(false);
    
    if(!isCurrentSLOCValid(currentSLOC, currentSLOC_obj)) 
        return(false);
        
    if(!isCurrentLaborRateValid(currentLaborRate, currentLaborRate_obj)) 
        return(false);
    
    if(!isCurrentLaborRateForIdealWeekValid(currentLaborRateForIdealWeek, currentLaborRateForIdealWeek_obj))
        return(false);
       
    project.projectName = projectName;
    project.baselineValue = (Math.round(baselineValue) > 0) ? Math.round(baselineValue) : NaN;
    project.currentFunctionPoint = (Math.round(currentFunctionPoint) > 0) ? Math.round(currentFunctionPoint) : NaN;
    project.currentSLOC = (Math.round(currentSLOC) > 0) ? Math.round(currentSLOC) : NaN;
    project.currentLaborRate = (parseFloat(currentLaborRate) > 0) ? parseFloat(currentLaborRate) : NaN;
    project.currentLaborRateForIdealWeek = (parseFloat(currentLaborRateForIdealWeek) > 0) ? parseFloat(currentLaborRateForIdealWeek) : NaN;
    
    if((project.analogyParameter.value == "AP04") || (project.analogyParameter.value == "AP06"))
    	project.currentKSLOC = project.currentSLOC/1000;
    	        
    if(project.currentKSLOC < 2 && !project.yesunder2000) {
	    if (!(confirm('Agile COCOMO II was designed for projects greater than 2000 SLOC. In particular, the scale factors do not work below 2000 SLOC. Do you wish to continue with KSLOC less than 2? (cost drivers only)'))) {
		return(false);
	    } else {
	    	project.yesunder2000 = true;
	    }
    } 

if(project.PMmodeon) {

    switch(project.analogyParameter.value) {
        case "AP01":
          	project.allinput = true;
          	project.step2Value = parseFloat(project.baselineValue)/project.currentLaborRate;	
            	break;
        case "AP02":
        	project.step2Value = parseFloat(project.baselineValue);      
            	break;
        case "AP03":
        	project.allinput = true;
        	project.step2Value = parseFloat(project.baselineValue) * project.currentFunctionPoint / project.currentLaborRate;
            	break;
        case "AP04":
        	project.allinput = true;
        	project.step2Value = parseFloat(project.baselineValue) * project.currentSLOC / project.currentLaborRate;
            	break;
        case "AP05":
        	project.step2Value = project.currentFunctionPoint/parseFloat(project.baselineValue);            
            break;
        case "AP06":
        	project.step2Value = project.currentSLOC/parseFloat(project.baselineValue);
            	break;
        case "AP07":
  		project.step2Value = parseFloat(project.baselineValue); 
            	break;
    }
}

if(project.dollarsmodeon) { 
    switch(project.analogyParameter.value) {
        case "AP01":
        	project.step1Value = parseFloat(project.baselineValue); 
        	break;
        case "AP02":
        	project.allinput = true;
        	project.step1Value = parseFloat(project.baselineValue) * project.currentLaborRate; 
        	break;
        case "AP03":
        	project.step1Value = parseFloat(project.baselineValue) * project.currentFunctionPoint;
		break;
        case "AP04":
        	project.step1Value = parseFloat(project.baselineValue) * project.currentSLOC;
            	break;
        case "AP05":
        	project.allinput = true;
        	project.step1Value = project.currentFunctionPoint/parseFloat(project.baselineValue) * project.currentLaborRate;        
            	break;
        case "AP06":
        	project.allinput = true;
        	project.step1Value = project.currentSLOC/parseFloat(project.baselineValue) * project.currentLaborRate;
            	break;
        case "AP07":
        	project.allinput = true;
        	project.step1Value = parseFloat(project.baselineValue) * project.currentLaborRateForIdealWeek; 
            	break;
    }
}


    updateTableHeader();
    
    returnValue = true;
    return(returnValue);
}

function disableFields() { 

    //disable fields after one entry
     
     document.ProjectForm.AnalogyParameterDropdown.disabled = true; //always
     document.ProjectForm.ProjectName.disabled = true;
     document.ProjectForm.BaselineValue.disabled = true;

	if(project.PMmodeon) {

	    switch(project.analogyParameter.value) {
		case "AP01":
			document.ProjectForm.CurrentLaborRate.disabled = true;
			break;
		case "AP02":
			project.step2Value = parseFloat(project.baselineValue);      
			break;
		case "AP03":
			document.ProjectForm.CurrentLaborRate.disabled = true;
			document.ProjectForm.CurrentFunctionPoint.disabled = true;
			break;
		case "AP04":
			document.ProjectForm.CurrentLaborRate.disabled = true;
			document.ProjectForm.CurrentSLOC.disabled = true;
			break;
		case "AP05":
			document.ProjectForm.CurrentFunctionPoint.disabled = true;            
		    break;
		case "AP06":
			document.ProjectForm.CurrentSLOC.disabled = true;
			break;
		case "AP07":
			break;
	    }
	}

	if(project.dollarsmodeon) { 
	    switch(project.analogyParameter.value) {
		case "AP01":
			break;
		case "AP02":
			document.ProjectForm.CurrentLaborRate.disabled = true; 
			break;
		case "AP03":
			document.ProjectForm.CurrentFunctionPoint.disabled = true;
			break;
		case "AP04":
			document.ProjectForm.CurrentSLOC.disabled = true;
			break;
		case "AP05":
			document.ProjectForm.CurrentFunctionPoint.disabled = true;
			document.ProjectForm.CurrentLaborRate.disabled = true;       
			break;
		case "AP06":
			document.ProjectForm.CurrentSLOC.disabled = true;
			document.ProjectForm.CurrentLaborRate.disabled = true;
			break;
		case "AP07":
			document.ProjectForm.CurrentLaborRateForIdealWeek.disabled = true; 
			break;
	    }
	}
	    switch(project.analogyParameter.value) {
		case "AP01":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
	       		break
		case "AP02":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
			break;
		case "AP03":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
			break;
		case "AP04":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
			break;
		case "AP05":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";   
			break;
		case "AP06":
			if((project.submitted) && (!(isNaN(project.currentLaborRate))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
			break;
		case "AP07":
			if((project.submitted) && (!(isNaN(project.currentLaborRateForIdealWeek))))
	       			document.getElementById("AddLaborRateButton").style.display = "none";
			break;
	    }
}

function addDriverFactor() {
    updateSequenceNo = 0;  //To set the Global Variable value to 0 to indicate this is an "Addition"
    
    if(false == updateProjectInputs()) {
        return;
    } else {
    	project.submitted = true;   
    	updateMenu();
    }
 	
    disableFields(); 
	
    openDriverFactorWindow();  //Then open the Popup window to add, the DriverFactor window will check the global variable "updateSequenceNo" to see if it's an "Addition"
}

function updateDriverFactor(sequenceNo) {
    updateSequenceNo = sequenceNo;  //To change the Global Variable value to indicate this is an "update"
    
    openDriverFactorWindow();   //Then open the Popup window to update, the DriverFactor window will check the global variable "updateSequenceNo" to see if it's an "update"
}

function addLaborRate() {
    if(false == updateProjectInputs()) {
        return;
    }  else {
    	project.submitted = true;    
    	updateMenu();
    }  
    
    disableFields();
    
}

function openDriverFactorWindow() {
    var winWidth = 700;
    var winHeight = 500;
    var leftPosition, topPosition;
    var settings;
    
    leftPosition = (screen.width) ? (screen.width-winWidth)/2 : 0;
    topPosition = (screen.height) ? (screen.height-winHeight)/2 : 0;

    settings = "width=" + winWidth + " ,height=" + winHeight + ", left=" + leftPosition + ", top=" + topPosition + ", scrollbars=yes, status=yes, resizable=yes";

    project.winHandler = window.open("DriverFactor.html", "DriverFactorWin", settings); 
    project.winHandler.focus();
}

function openViewReportWindow() {
    var winHandler2 = null;
    var winWidth = 750;
    var winHeight = 600;
    var leftPosition, topPosition;
    var settings;
    
    /*************Do we need to check if inputs exist?************************/

    if(false == updateProjectInputs()) {
        return;
    } else {
    	project.submitted = true;    
    	updateMenu();
    }
    
    disableFields(); 

    /*************************************************************************/
    
    leftPosition = (screen.width) ? (screen.width-winWidth)/2 : 0;
    topPosition = (screen.height) ? (screen.height-winHeight)/2 : 0;

    settings = "width=" + winWidth + " ,height=" + winHeight + ", left=" + leftPosition + ", top=" + topPosition + ", scrollbars=yes, status=yes, resizable=yes";

    project.winHandler2 = window.open("ViewReport.html", "ViewReportWin", settings); 
    project.winHandler2.focus();
}


/******************************************************************************
Calculate the Cost for the current Estimation[sequenceNo-1] on the basis of baselineValue
@Parameter sequenceNo   Integer    
@Return String        A formatted String like "$1345.00" or "N/A"
******************************************************************************/
function calculateProjectCostUpTo(sequenceNo) {
    var currentCostString;
    var currentCost = project.calculateCostUpTo(sequenceNo);
    
    if (isNaN(currentCost)) 
        currentCostString = "N/A";
    else {
        currentCostString = "$"+formatAsMoney(currentCost);
    }
    
    return(currentCostString);
}

/******************************************************************************
Calculate the Cost for the current Estimation[sequenceNo-1] on the basis of baselineValue
@Parameter sequenceNo   Integer    
@Return String        A formatted String like "$1345.00" or "N/A"
******************************************************************************/
function calculateProjectPMUpTo(sequenceNo) {
    var currentPMString;
    var currentPM = project.calculatePMUpTo(sequenceNo);
    
    if (isNaN(currentPM)) 
        currentPMString = "N/A";
    else {
        currentPMString = formatAsNumber(currentPM);
    }
    
    return(currentPMString);
}


function insertOneRowToTable(sequenceNo, basisType, basisObject, lastRatingLevel, currentRatingLevel) {
    var tableObject = document.all.item("EstimationHistoryTable");
    var tr_obj, td_obj;
    var basisObjectString;
    var currentCost, temporaryCost, temporaryPM;
    
    if(basisType == project.TYPE_COST_DRIVER) {
        basisObjectString = basisObject.categoryName + "--" + basisObject.name;
    } 
    else {  //basisTYpe = project.TYPE_SCALE_FACTOR
        basisObjectString = basisObject.name;
    }
    
    //--------------------Calculate the Cost for the current Estimation[sequenceNo-1] on the basis of baselineValue--------Begin
    temporaryCost = calculateProjectCostUpTo(sequenceNo);
    temporaryPM = calculateProjectPMUpTo(sequenceNo);
    //--------------------Calculate the Cost for the current Estimation[sequenceNo-1] on the basis of baselineValue--------End
    
    tr_obj = tableObject.insertRow(sequenceNo);
    td_obj = tr_obj.insertCell(0);
    td_obj.setAttribute("bgcolor", "#FCF5D3");
    td_obj.setAttribute("width", "50");
    td_obj.setAttribute("align", "center");
    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ sequenceNo +"</span>");
    
    td_obj = tr_obj.insertCell(1);
    td_obj.setAttribute("width", "150");
    td_obj.setAttribute("align", "center");
    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ basisType +"<br/>("+ basisObjectString +")</span>");
    
    td_obj = tr_obj.insertCell(2);
    td_obj.setAttribute("width", "50");
    td_obj.setAttribute("align", "center");
    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ lastRatingLevel +" (" + basisObject.findRatingValue(lastRatingLevel) + ")</span>");
    
    td_obj = tr_obj.insertCell(3);
    td_obj.setAttribute("width", "50");
    td_obj.setAttribute("align", "center");
    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ currentRatingLevel +" (" + basisObject.findRatingValue(currentRatingLevel) + ")</span>");    
    
    if((project.dollarsmodeon) && (project.PMmodeon)) {
	    td_obj = tr_obj.insertCell(4);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ temporaryCost +"</span>");

	    td_obj = tr_obj.insertCell(5);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ temporaryPM +"</span>");

	    td_obj = tr_obj.insertCell(6);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<a href='javascript:updateDriverFactor(" + sequenceNo + ")'>Update</a> &nbsp; <a href='javascript:deleteEstimationFromTable(" + sequenceNo + ")'>Delete</a>");    
    } else if(project.dollarsmodeon) {
	    td_obj = tr_obj.insertCell(4);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ temporaryCost +"</span>");

	    td_obj = tr_obj.insertCell(5);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<a href='javascript:updateDriverFactor(" + sequenceNo + ")'>Update</a> &nbsp; <a href='javascript:deleteEstimationFromTable(" + sequenceNo + ")'>Delete</a>");    
    } else if(project.PMmodeon) {
	    td_obj = tr_obj.insertCell(4);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<span>"+ temporaryPM +"</span>");

	    td_obj = tr_obj.insertCell(5);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<a href='javascript:updateDriverFactor(" + sequenceNo + ")'>Update</a> &nbsp; <a href='javascript:deleteEstimationFromTable(" + sequenceNo + ")'>Delete</a>");    
    } else {
	    td_obj = tr_obj.insertCell(4);
	    td_obj.setAttribute("width", "100");
	    td_obj.setAttribute("align", "center");
	    td_obj.insertAdjacentHTML("AfterBegin", "<a href='javascript:updateDriverFactor(" + sequenceNo + ")'>Update</a> &nbsp; <a href='javascript:deleteEstimationFromTable(" + sequenceNo + ")'>Delete</a>");    
    }

}

function addEstimationToTable(basisType, basisObject, lastRatingLevel, currentRatingLevel) {
    var sequenceNo;
    
    project.addEstimation(basisType, basisObject, lastRatingLevel, currentRatingLevel);
    sequenceNo = project.estimationHistory.length;
    
    insertOneRowToTable(sequenceNo, basisType, basisObject, lastRatingLevel, currentRatingLevel);  //Add one row at the end of the Table
} 

function updateEstimationToTable(sequenceNo, basisType, basisObject, lastRatingLevel, currentRatingLevel) {
    var sequenceNo;
    
    project.updateEstimation(sequenceNo, basisType, basisObject, lastRatingLevel, currentRatingLevel);
    
    rebuildEstimationHistoryTable(sequenceNo);
} 

function deleteOneRowFromTable(sequenceNo) {
    var tableObject = document.all.item("EstimationHistoryTable");
    
    tableObject.deleteRow(sequenceNo); 
}

function deleteEstimationFromTable(sequenceNo) {
       
    if (confirm('Are you sure you want to delete this Estimation?')) {
        if(true == project.deleteEstimation(sequenceNo)) {
            deleteOneRowFromTable(sequenceNo);
            
            rebuildEstimationHistoryTable(sequenceNo);
        } 
        else {
            alert("Failed to delete the Estimation!");
            return;
        }
    }
}

function deleteAllEstimationFromTable() {
    var i;
    
    for(i=project.estimationHistory.length; i>=1; i--) {
            deleteOneRowFromTable(i);
    }
}

function rebuildEstimationHistoryTable(fromSequenceNo) {
    var i;
    var estimation;
    
    //-----Firstly, Delete from sequenceNo to estimationHistory.length--------------
    for(i=fromSequenceNo; i<=project.estimationHistory.length; i++) {
        deleteOneRowFromTable(fromSequenceNo);
    }
    
    for(i=fromSequenceNo; i<=project.estimationHistory.length; i++) {
        estimation = project.estimationHistory[i-1];
        insertOneRowToTable(i, estimation.basisType, estimation.basisObject, estimation.lastRatingLevel, estimation.currentRatingLevel);
    }
}

function resetEverything() {
   if (project.winHandler && project.winHandler.open && !project.winHandler.closed)
    	project.winHandler.close();

   if (project.winHandler2 && project.winHandler2.open && !project.winHandler2.closed)
    	project.winHandler2.close();
    
    document.getElementById("DollarMode").checked = false;
    document.getElementById("PMMode").checked = false;
    
    window.location.reload();
}





/* History, just comments */

/********************************************************************************
Iteration is set to 1, uncomment if you want a different value - Begin
********************************************************************************

function isCurrentIterationNoValid(currentIterationNo, currentIterationNo_obj) {
    var value = project.analogyParameter.value;
    
    if("AP07" == value) {
        if("" == currentIterationNo) {
            alert("Current Iteration Number can't be empty!");
            currentIterationNo_obj.focus();
            currentIterationNo_obj.select();
            return(false);     
        }
        else {
            if(!isValidNumber(currentIterationNo)) {
                alert("Current Iteration Number must be a number greater than 0!");
                currentIterationNo_obj.focus();
                currentIterationNo_obj.select();
                return(false);   
            }
            else {
                return(true);
            }
        }
    } 
    else { 
        return(true);
    }
}

********************************************************************************
Iteration is set to 1, uncomment if you want a different value - End
********************************************************************************/

//-------------Below is the functions created by Michael Chuang without following the OO Design------
	function change(index) {
		
		var base1 = document.getElementById('base1');
		var base2 = document.getElementById('base2');
		var base3 = document.getElementById('base3');
		var base4 = document.getElementById('base4');
		var base5 = document.getElementById('base5');
		var base6 = document.getElementById('base6');

		var lines1 = document.getElementById('lines1');
		var lines2 = document.getElementById('lines2');
		var size1 = document.getElementById('size1');
		var size2 = document.getElementById('size2');
		var lang1 = document.getElementById('lang1');
		var lang2 = document.getElementById('lang2');
		var fp1 = document.getElementById('fp1');
		var fp2 = document.getElementById('fp2');
		var labor1 = document.getElementById('labor1');
		var labor2 = document.getElementById('labor2');

		if(index == 1) {
			//Total Cost in Dollars

			//change base term
			base1.style.display = "";
			base2.style.display = "none";
			base3.style.display = "none";
			base4.style.display = "none";
			base5.style.display = "none";
			base6.style.display = "none";

			lines1.style.display = "none";
			lines2.style.display = "none";
			size1.style.display = "none";
			size2.style.display = "none";
			lang1.style.display = "none";
			lang2.style.display = "none";
			fp1.style.display = "none";
			fp2.style.display = "none";
			labor1.style.display = "none";
			labor2.style.display = "none";


		} else if(index == 2) {
			//Total Effort in Person-Month

			//change base term
			base1.style.display = "none";
			base2.style.display = "";
			base3.style.display = "none";
			base4.style.display = "none";
			base5.style.display = "none";
			base6.style.display = "none";

			lines1.style.display = "none";
			lines2.style.display = "none";
			size1.style.display = "none";
			size2.style.display = "none";
			lang1.style.display = "none";
			lang2.style.display = "none";
			fp1.style.display = "none";
			fp2.style.display = "none";
			labor1.style.display = "";
			labor2.style.display = "";

		} else if(index == 3) {
			//Productivity in Dollars / Function Points

			//change base term
			base1.style.display = "none";
			base2.style.display = "none";
			base3.style.display = "";
			base4.style.display = "none";
			base5.style.display = "none";
			base6.style.display = "none";

			lines1.style.display = "none";
			lines2.style.display = "none";
			size1.style.display = "none";
			size2.style.display = "none";
			lang1.style.display = "";
			lang2.style.display = "";
			fp1.style.display = "";
			fp2.style.display = "";
			labor1.style.display = "none";
			labor2.style.display = "none";

		} else if(index == 4) {
			//Productivity in Dollars / Lines of Code

			//change base term
			base1.style.display = "none";
			base2.style.display = "none";
			base3.style.display = "none";
			base4.style.display = "";
			base5.style.display = "none";
			base6.style.display = "none";

			lines1.style.display = "";
			lines2.style.display = "";
			size1.style.display = "none";
			size2.style.display = "none";
			lang1.style.display = "none";
			lang2.style.display = "none";
			fp1.style.display = "none";
			fp2.style.display = "none";
			labor1.style.display = "none";
			labor2.style.display = "none";

		} else if(index == 5) {
			//Productivity in Function Points / Person-Month

			//change base term
			base1.style.display = "none";
			base2.style.display = "none";
			base3.style.display = "none";
			base4.style.display = "none";
			base5.style.display = "";
			base6.style.display = "none";

			lines1.style.display = "none";
			lines2.style.display = "none";
			size1.style.display = "none";
			size2.style.display = "none";
			lang1.style.display = "";
			lang2.style.display = "";
			fp1.style.display = "";
			fp2.style.display = "";
			labor1.style.display = "";
			labor2.style.display = "";

		} else if(index == 6) {
			//Productivity in Lines of Code / Person-Month

			//change base term
			base1.style.display = "none";
			base2.style.display = "none";
			base3.style.display = "none";
			base4.style.display = "none";
			base5.style.display = "none";
			base6.style.display = "";

			lines1.style.display = "none";
			lines2.style.display = "none";
			size1.style.display = "";
			size2.style.display = "";
			lang1.style.display = "none";
			lang2.style.display = "none";
			fp1.style.display = "none";
			fp2.style.display = "none";
			labor1.style.display = "";
			labor2.style.display = "";

		} else {
			alert("Wrong Option Choice");
		}


	}

	function none() {

		document.getElementById('base1').style.display = "none";
		document.getElementById('base2').style.display = "none";
		document.getElementById('base3').style.display = "none";
		document.getElementById('base4').style.display = "none";
		document.getElementById('base5').style.display = "none";
		document.getElementById('base6').style.display = "none";
		document.getElementById('base1').style.display = "";

		document.getElementById('lines1').style.display = "none";
		document.getElementById('lines2').style.display = "none";
		document.getElementById('size1').style.display = "none";
		document.getElementById('size2').style.display = "none";
		document.getElementById('lang1').style.display = "none";
		document.getElementById('lang2').style.display = "none";
		document.getElementById('fp1').style.display = "none";
		document.getElementById('fp2').style.display = "none";
		document.getElementById('labor1').style.display = "none";
		document.getElementById('labor2').style.display = "none";

	}

	function formOutput(formobj) {
		var analogy = formobj.elements["analogy"].value;
		var projectname = formobj.elements["ProjectName"].value;
		var baseline = formobj.elements["BaselineValue"].value;
		var codelines = formobj.elements["CodeLines"].value;
		var projectsize = formobj.elements["ProjectSize"].value;

		formulas(analogy,projectname,baseline,codelines,projectsize);
		return true;
	}

	function NewWindow(mypage,myname,w,h,scroll,data) {

		var win = null;

		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

		settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';

		win = window.open(mypage,myname,settings);
		win.document.open("text/html","replace");
		win.document.write(data);
		win.focus();
		
		

	}

	function formulas(index, ProjectName,Baseline,CodeLines,ProjectSize) {

		var outputHTML = "<iframe src='DriverFactor.html' width=650 height=450 border='0' frameborder='no'></iframe>";
                //var outputHTML = "";
                
		NewWindow("","outputHTML",700,500,"yes",outputHTML);
		//NewWindow("DriverFactor.html","outputHTML",700,500,"yes",outputHTML);
	}


-->