var rowCount = 16;
var multiple = 2;
function getFadeData(ddlForm)
{

	var fadeRows = getFadeMultidimensionalArray()

	ddlForm.fadeAdvantage.value=fadeRows[ddlForm.fadelist.selectedIndex][0];
	ddlForm.fadeCostMultiple.value=FormatNumber(fadeRows[ddlForm.fadelist.selectedIndex][1],0,false,false,true);
	var ap = getFadeActivePoints(ddlForm);
	var tm = getPharmiTechTypeMultiple(ddlForm);
	var fm = parseFloat(fadeRows[ddlForm.fadelist.selectedIndex][1]);
	var retVal = ((ap * fm) * (tm * multiple));
	ddlForm.fadeCreditCost.value = FormatNumber(retVal,0,false,false,true);
	
}
function getPharmiTechTypeMultiple(ddlForm)
{
	var pt = parseFloat("0");
	//parse input
	pt = ddlForm.pharmiTechTypeList[ddlForm.pharmiTechTypeList.selectedIndex].value;
	return parseFloat(pt);
}
function getFadeMultidimensionalArray()
{
	var fadeRows = new Array(rowCount);
	for (i=0; i <= rowCount; i++)
	{ 
		fadeRows[i] = new Array(2);
	}

	fadeRows[0][0] = "N/A";
	fadeRows[0][1] = "1";
	fadeRows[1][0] = "+1/4";
	fadeRows[1][1] = "2";
	fadeRows[2][0] = "+1/2";
	fadeRows[2][1] = "4";
	fadeRows[3][0] = "+3/4";
	fadeRows[3][1] = "8";
	fadeRows[4][0] = "+1";
	fadeRows[4][1] = "16";
	fadeRows[5][0] = "+1 1/4";
	fadeRows[5][1] = "32";
	fadeRows[6][0] = "+1 1/2";
	fadeRows[6][1] = "64";
	fadeRows[7][0] = "+1 3/4";
	fadeRows[7][1] = "128";
	fadeRows[8][0] = "+2";
	fadeRows[8][1] = "256";
	fadeRows[9][0] = "+2 1/4";
	fadeRows[9][1] = "512";
	fadeRows[10][0] = "+2 1/2";
	fadeRows[10][1] = "1024";
	fadeRows[11][0] = "+2 3/4";
	fadeRows[11][1] = "2048";
	fadeRows[12][0] = "+3";
	fadeRows[12][1] = "4096";
	fadeRows[13][0] = "+3 1/4";
	fadeRows[13][1] = "8192";
	fadeRows[14][0] = "+3 1/2";
	fadeRows[14][1] = "16384";
	fadeRows[15][0] = "+3 3/4";
	fadeRows[15][1] = "32768";
	fadeRows[16][0] = "+4";
	fadeRows[16][1] = "65536";
	
	return fadeRows
}

function getFadeActivePoints(ddlForm)
{
	var ap = parseFloat("0");
	//parse input
	ap  = ddlForm.fadeActivePoints.value.replace(/\$|\,/g,'');
	ap  =  parseFloat((isNaN(ap ) || (ap =="")) ? "0": ap );
	ddlForm.fadeActivePoints.value = FormatNumber(parseFloat(ap),0,false,false,true);
	return parseFloat(ap);
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
	/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 	**********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;	
}