function getCategoryArray(){
	var cats = new Array( 24 );
	
	cats[ 0 ]  = "dlo";		// department leader office
	cats[ 3 ]  = "mdo";		// managing director office
	cats[ 6 ]  = "vpo";		// vice president's office
	cats[ 9 ]  = "typo";	// typical office
	cats[ 1 ]  = "xlws";	// extra large workstation
	cats[ 4 ]  = "lws";		// large workstation
	cats[ 7 ]  = "mws";		// medium workstation
	cats[ 10 ] = "sws";		// small workstation
	cats[ 2 ]  = "confa";	// conference room a
	cats[ 5 ]  = "confb";	// conference room b
	cats[ 8 ]  = "confc";	// conference room c
	cats[ 11 ] = "confd";	// conference room d
	cats[ 12 ] = "hqr";		// headquarters reception
	cats[ 14 ] = "or";		// office reception
	cats[ 16 ] = "sr";		// small reception
	cats[ 18 ] = "p12";		// pantry with seating for 12
	cats[ 20 ] = "p4";		// pantry with seating for 4
	cats[ 22 ] = "cp";		// coffee/pantry
	cats[ 13 ] = "lcr";		// large copy room
	cats[ 15 ] = "scr";		// small copy room
	cats[ 17 ] = "tr";		// telecom room
	cats[ 19 ] = "tc";		// telecom closet
	cats[ 21 ] = "fs";		// file-standard
	cats[ 23 ] = "co";		// coat closet

	return cats;
}

function getCategorySizesArray(){
	var catsize = new Array( 24 );
	
	catsize[ "dlo" ]	= 300;		// department leader
	catsize[ "mdo" ]	= 225;		// managing director's office
	catsize[ "vpo" ]	= 150;		// vice president's office
	catsize[ "typo" ]	= 100;		// typical office
	catsize[ "xlws" ]	= 100;		// extra large workstation
	catsize[ "lws" ]	= 60;		// large workstation
	catsize[ "mws" ]	= 50;		// medium workstation
	catsize[ "sws" ]	= 40;		// small workstation
	catsize[ "confa" ]	= 375;		// conference room a
	catsize[ "confb" ]	= 300;		// conference room b
	catsize[ "confc" ]	= 225;		// conference room c
	catsize[ "confd" ]	= 150;		// conference room d
	catsize[ "hqr" ]	= 500;		// headquarters reception
	catsize[ "or" ]		= 300;		// office reception
	catsize[ "sr" ]		= 150;		// small reception
	catsize[ "p12" ]	= 300;		// pantry with seating for 12
	catsize[ "p4" ]		= 150;		// pantry with seating for 4
	catsize[ "cp" ]		= 70;		// coffee/pantry
	catsize[ "lcr" ]	= 65;		// large copy room
	catsize[ "scr" ]	= 35;		// small copy room
	catsize[ "tr" ]		= 150;		// telecom room
	catsize[ "tc" ]		= 50;		// telecom closet
	catsize[ "fs" ]		= 12;		// file-standard
	catsize[ "co" ]		= 25;		// coat closet

	return catsize;
}

function getCookieData( cookie, label ){
	var cLen = cookie.length;
	var i = 0;
	var cEnd
	
	while( i < cLen ){
		var j = i + label.length;
		if( cookie.substring( i, j ) == label ){
			cEnd = cookie.indexOf( ";", j );
			if( cEnd == -1 ){
				cEnd = cookie.length;
			}
			return unescape( cookie.substring( j + 1, cEnd ));
		}
		i++;
	}
	return "";
}

function parseCookieData( strData ){
	var arrCookieData = new Array();
	var i = -1;
	var nextEq, nextPct;

	if( strData.length < 1 ){
		return arrCookieData;
	}

	while( i < strData.length - 1 ){
		nextEq		= strData.indexOf( "=", i );
		nextPct		= strData.indexOf( "|", nextEq + 1 );
		arrCookieData[ strData.substring( i + 1, nextEq ) ] = strData.substring( nextEq + 1, nextPct );
		i = nextPct;
	}
	
	return arrCookieData;	
}

function concatCookieData( arrDataNames, arrData ){
	var sCookieData = "";

	for( i = 0; i < arrDataNames.length; i++ ){
		sCookieData += arrDataNames[ i ] + "=" + FilterPosInt( arrData[ arrDataNames[ i ] ] ) + "|";
	}

	return sCookieData;	
}

function GetLastValidPaymentYear( vPayments ){
	var vLeaseYears = 0;

	for( i = vPayments.length - 1; i >= 0; i-- ){
		vPayments[ i ] = parseFloat( vPayments[ i ] );
		if( isNaN( vPayments[ i ] ) == false ){
			vLeaseYears = i + 1;
			break;
		}
	}
	
	return vLeaseYears
}

function FilterInvalidPayments( vPayments, vLeaseYears ){

	for( i = 0; i < vPayments.length; i++ ){
		if( i >= vLeaseYears ){
			vPayments[ i ] = "";
			continue;
		}
		vPayments[ i ] = FilterPosFloat( vPayments[ i ] );
	}

	return vPayments;
}

function FilterPosInt( Val ){
	var newVal = parseInt( Val, 10 );
	
	if( isNaN( newVal ) || newVal <= 0 ){
		newVal = 0;
	}
	
	return newVal;
}

function FilterPosFloat( Val ){
	var newVal = parseFloat( Val );
	
	if( isNaN( newVal ) || newVal <= 0 ){
		newVal = 0;
	}
	
	return newVal;
}

function FilterPercent( Val ){
	var newVal = parseFloat( Val );
	
	if( isNaN( newVal ) || newVal <= 0 ){
		newVal = 0;
	} 
	else if( newVal > 100 ){
		newVal = 100;
	}
	
	return newVal;
}

function FormatDecimal( Amount, decPlaces, bComma ){
	var isNegative = false;	
	var sAmount = parseFloat( Amount );
	
	if( isNaN( sAmount )){
		return "n/a";
	}
	
	if( sAmount < 0 ){
		isNegative = true;
	}
	
	sAmount = "" + ( Math.round( Math.abs( sAmount ) * Math.pow( 10, decPlaces ) ) / Math.pow( 10, decPlaces ) );
	
	if( bComma ){
		var decLocation = sAmount.indexOf( "." );
		var comNum = 0;
		
		if( decLocation == -1 ){
			decLocation = sAmount.length;
		}
		
		for( var i = decLocation; i > 1; i-- ){
			comNum++;
			if( comNum == 3 ){
				sAmount = sAmount.substring( 0, i - 1 ) + "," + sAmount.substring( i - 1 );
				comNum = 0;
			}
		}	
	}
	
	if( isNegative ){
		sAmount = "(" + sAmount + ")";
	}
	
	return sAmount;
}

function ConvertToDollars( Amount, bComma ){
	var sAmount;
	var isNegative = false;
	
	if( ( "" + Amount ) == "" ){
		return "";
	}
	
	sAmount = parseFloat( Amount );
	
	if( isNaN( sAmount )){
		return "n/a";
	}
	
	if( sAmount < 0 ){
		isNegative = true;
	}
	
	sAmount = "" + Math.round( Math.abs( sAmount ) * 100 );
	
	while( sAmount.length <= 2 ){
		sAmount = "0" + sAmount;
	}
		
	sAmount = sAmount.substring( 0, sAmount.length - 2 ) + "." + sAmount.substring( sAmount.length - 2, sAmount.length );
	
	if( bComma ){
		var decLocation = sAmount.indexOf( "." );
		var comNum = 0;
		
		if( decLocation == -1 ){
			decLocation = sAmount.length - 1;
		}
		
		for( var i = decLocation; i > 1; i-- ){
			comNum++;
			if( comNum == 3 ){
				sAmount = sAmount.substring( 0, i - 1 ) + "," + sAmount.substring( i - 1 );
				comNum = 0;
			}
		}	
	}

	if( isNegative ){
		sAmount = "(" + sAmount + ")";
	}

	return sAmount;
}

function GetPayment( vNPV, vLeaseYears, vDiscountRate ){
	var vPMT = 0;
	
	vPMT = vNPV * ( ( vDiscountRate / 100 ) / ( 1 - ( 1 / ( Math.pow( 1 + ( vDiscountRate / 100 ), vLeaseYears ) ) ) ) );
	
	return vPMT;
}

function GetNPV( vPayments, vLeaseYears, vDiscountRate ){
	var vNPV = 0;

	for( i = 0; i < vLeaseYears; i++ ){
		vNPV += vPayments[ i ] / Math.pow( ( 1 + ( vDiscountRate / 100 ) ), i + 1 );
	}
	return vNPV
}

