//Vars to hold the names of the IDs of the Fields that contain the data for the prices
var PhoneDescriptionID = 'PHONEDESCRIPTION';
var PhoneMonthlyPriceID = 'PHONEMONTHLYPRICE';
var PhoneActivationPriceID = 'PHONEACTIVATIONPRICE';

var InternetDescriptionID = 'INTERNETDESCRIPTION';
var InternetMonthlyPriceID = 'INTERNETMONTHLYPRICE';
var InternetActivationPriceID = 'INTERNETACTIVATIONPRICE';

var TotalActivationCostID = 'TOTALACTIVATIONCOST';
var TotalCostID = 'TOTALCOST';

//********** No need to change anything below this line *********************************

///Vars to contain the current data for display ...

var PhoneDescription='';
var PhoneMonthlyPrice=0;
var PhoneActivationPrice=0;

var InternetDescription='';
var InternetMonthlyPrice=0;
var InternetActivationPrice=0;

var FeatureTotal = 0;

///Function to update the display 
function RefreshPriceDisplay(){
	///May Need to add formating later...
	var TotalCost;
	var tmpStr;
	var TotalActCost;
	
	//tmpStr = " <a href='/'>test</a>";
	//document.getElementById(PhoneDescriptionID).innerHTML = PhoneDescription + tmpStr ;
	document.getElementById(PhoneDescriptionID).innerHTML = PhoneDescription ;
	
	
	document.getElementById(PhoneMonthlyPriceID).innerHTML = " $" + PhoneMonthlyPrice.toFixed(2) + "* month";
	document.getElementById(PhoneActivationPriceID).innerHTML = "Activation Fee: $" + PhoneActivationPrice.toFixed(2);
	
	document.getElementById(InternetDescriptionID).innerHTML = InternetDescription;
	document.getElementById(InternetMonthlyPriceID).innerHTML = " $" + InternetMonthlyPrice.toFixed(2) + "* month";
	document.getElementById(InternetActivationPriceID).innerHTML = "Activation Fee: $" + InternetActivationPrice.toFixed(2);

	TotalActCost = PhoneActivationPrice + InternetActivationPrice;
	TotalCost = PhoneMonthlyPrice + InternetMonthlyPrice + FeatureTotal;
	
	
	document.getElementById(TotalActivationCostID).innerHTML = " $" +  TotalActCost.toFixed(2);
	document.getElementById(TotalCostID).innerHTML = " $" +  TotalCost.toFixed(2);
}

function SetPlanData(Prices){
	
	//Defaults
	PhoneDescription = '';
	PhoneMonthlyPrice = 0;
	PhoneActivationPrice = 0;
	InternetDescription = '';
	InternetMonthlyPrice = 0;
	InternetActivationPrice = 0;
	
	var Value;
	for(Field in Prices){
		Value = Prices[Field];
		switch( Field.toUpperCase() ){
			case "PHONEDESCRIPTION": case "PHONE_DESCRIPTION": PhoneDescription = Value; break;
			case "PHONEMONTHLYPRICE": case "PHONE_MONTHLY_PRICE":  PhoneMonthlyPrice = Value; break;
			case "PHONEACTIVATIONPRICE": case "PHONE_ACTIVATION_PRICE":  PhoneActivationPrice = Value; break;
			case "INTERNETDESCRIPTION": case "INTERNET_DESCRIPTION": InternetDescription = Value; break;
			case "INTERNETMONTHLYPRICE": case "INTERNET_MONTHLY_PRICE": InternetMonthlyPrice = Value; break;
			case "INTERNETACTIVATIONPRICE": case "INTERNET_ACTIVATION_PRICE":  InternetActivationPrice = Value; break;
		}
	}
	RefreshPriceDisplay();
}

function handleFeatureCheckboxClick(CheckBox,FeatureData){
	var Price;
	Price = FeatureData['PRICE'];
	if(CheckBox.checked){
		//alert ("You just selected the " + FeatureData['DESCRIPTION'] + " checkbox!");
		AdjustFeatureTotal(Price);
	} else {
		//alert ("You just unselected the " + FeatureData['DESCRIPTION'] + " checkbox!");
		AdjustFeatureTotal(Price * -1);
	}
}

function AddFeatureToPrice(FeatureData){
	Price = FeatureData['PRICE'];
	AdjustFeatureTotal(Price);
}

function AdjustFeatureTotal(Amt){
	FeatureTotal += Amt;
	RefreshPriceDisplay();
}

