function summaryEdit (f) {
	setStep (f);
	document.form.submit();
}

function setStatus (f){
var vCurStep = 1;
var iCurStep = document.form.STEP.value;
vCurStep = parseInt(iCurStep);

	if (f == "Calculate"){
		document.form.STEP.value = vCurStep ;
	} else if (f == "Next") {
		if (vCurStep >= 5) { vCurStep = 5;}
		else {vCurStep = vCurStep + 1;}
		document.form.STEP.value = vCurStep;
	} else if (f == "Previous") {
	
		if (vCurStep <= 1) { vCurStep = 1;}
		else { vCurStep = vCurStep - 1;}		
		document.form.STEP.value = vCurStep;
	} else if (f == "SubmitSummary") {
		document.form.STEP.value = 5;
	}		

}

function setStep (f){

	if (f == "Step_2"){
		document.form.STEP.value = 2 ;
	} else if (f == "Step_3") {
		document.form.STEP.value = 3;
	} else if (f == "Step_4") {
		document.form.STEP.value = 4;
	} else if (f == "Step_5") {
		document.form.STEP.value = 5;		
	} else {
		document.form.STEP.value = 1;
	}

}

function setPackage (e){
	if (e.value == "1") {
		document.form.PACKAGE.value = "484_FBGA";
	} else {
		document.form.PACKAGE.value = "780_FBGA";
	}
}

function clearZero(element) { if (element.value == "0.00") element.value = ""; 
return true; }

function addZero(element) { if (element.value == "") element.value = "0.00"; 
return true; }

function roundn(n, x)
{
	x = (!x) ? 2 : places;
	return Math.round(n * Math.pow(10, x)) / Math.pow(10, x);
}


function setOnlyNumeric() {
var fLength = document.form.length;
var eType = "";
var eVal = "";
var reComma = /,/gi;

	for (var i = 0; i < fLength; i++) {
		eType = document.form[i].type;
		eVal = document.form[i].value;
		if ((eType == "text") || (eType == "hidden")){
			document.form[i].value = eVal.replace(reComma,"");
		}
	}

}

function nonNumeric(str)
{
	for (var i = 0; i < str.length; i++)
	{
		var c = str.charAt(i);
		if ((c < "0" || c > "9") && c != "-" && c != ".") { return true; }
	}
	return false;
}


function checkNum(element, minval, maxval)
{
	if (!minval) minval = 0;
	if (!maxval) maxval = 99999;
	var str = element.value + "";
	if (str == "") { element.value = "0.00"; return true; }
	if (parseFloat(str) < minval || parseFloat(str) > maxval || nonNumeric(str))
	{
		alert("\nThis field must be a number from " + minval + " to " + maxval);
		element.value = "";
		element.focus();
		return false;
	}
	return true;
}

function checkNumTA(element, tempGrade, maxval)
{
//	if (!minval) minval = 0;
	if (!maxval) maxval = 150;
	var str = element.value + "";
	if (str == "") { element.value = "0.00"; return true; }
	
		ta_minval = -50;
		ta_maxval = 150;	
	
	if (parseFloat(str) < ta_minval || parseFloat(str) > ta_maxval || nonNumeric(str))
	{
		alert("\nThis field must be a number from -50 to 150");
		element.value = "";
		element.focus();
		return false;
	}
	return true;
}


function gotoSubstep(url_path) {
		document.form.action = url_path;
		setOnlyNumeric();
		document.form.submit();
		return false;
	}
	
	
function popUp(theURL) {
    var newWin = open(theURL,"popWin","width=400,height=260,top=10,left=10,scrollbars,resizable");
	newWin.focus();
}	

function help(topic)
{
	if (help_msg[topic])
	{
		var help_win = window.open("","","width=300,height=300");
		help_win.document.open();
		help_win.document.write(header + help_msg[topic] + closeButton + footer);
		help_win.document.close();
		if (!IE3) { help_win.focus(); }
	}
}


function formatNumberK(num, precision) {
denominator = Math.pow(10, precision)
number = Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision);
str_number = new String(number);
if (precision>0) {
	if (str_number.indexOf(".")<0) {
		str_number += ".";
		for (i=0;i<precision;i++) {
			str_number += "0";
		}
	} else {
		// --- decimal point is found, need to pad trailing zero's
		number_after_decimal = str_number.length - (str_number.indexOf(".") + 1);
		if (number_after_decimal < precision) {
			for (i=number_after_decimal;i<precision;i++) {
				str_number += "0";
			}
		}
	}
}
return (str_number);
}	


function formatPercentage(num, precision) {
denominator = Math.pow(10, precision)
percent = Math.round(num * 100 * denominator)/denominator;
str_percentage = new String(percent);
if (precision>0) {
	if (str_percentage.indexOf(".")<0) {
		str_percentage += ".";
		for (i=0;i<precision;i++) {
			str_percentage += "0";
		}
	} else {
		// --- decimal point is found, need to pad trailing zero's
		number_after_decimal = str_percentage.length - (str_percentage.indexOf(".") + 1);
		if (number_after_decimal < precision) {
			for (i=number_after_decimal;i<precision;i++) {
				str_percentage += "0";
			}
		}
	}
}
return (str_percentage + "%");
}


function formatNumber(num) {
num = Math.round(num);
dstr = new String(num);
fstr = "";
for (i=dstr.length;i>=0;i=i-3) {
	if (i-3>0) {
		fstr = "," + dstr.substring(i-3,i) + fstr;
	} else {
		fstr = dstr.substring(0,i) + fstr;
		break;
	}
}
return fstr;
}


function roundn(n, x)
{	// places
//x = (!x) ? 2 : x;
return Math.round(n * Math.pow(10, x)) / Math.pow(10, x);
}

		
