﻿function getRowElement(element){
	var mParentElement = element
	while (mParentElement.tagName !== "TR"){
		mParentElement = mParentElement.parentNode
	}
	
	return mParentElement
	
}


function changeConfig(element, isDefault){
	
	var mOptionCollection = document.getElementsByName(element.name)
	
	
	for(i=0;i < mOptionCollection.length;i++){
		var mOption = mOptionCollection[i]
		var mRowElement = getRowElement(mOption)
		mRowElement.style.backgroundColor = "#fff"
	}
	
	
	var mRowElement = getRowElement(element)
	
	if (isDefault){
		mRowElement.style.backgroundColor = "#fff"
	}else{
		mRowElement.style.backgroundColor = "#e1f3f9"
	}
	

}


function getPlanPriceDiscountRate(PerMonth, PerMonthNoDiscount, PeriodType){
	var mPlanPriceTotal = getPlanPriceTotal(PerMonth, PerMonthNoDiscount, PeriodType)
	var mDiscountRate = 0
	var mTotalAmt = 0

	switch (PeriodType){
		case 1:
			mTotalAmt = PerMonth + PerMonthNoDiscount
			break
		case 2:
			mTotalAmt = ((PerMonth + PerMonthNoDiscount) * 3)
			break;
		case 3:
			mTotalAmt = ((PerMonth + PerMonthNoDiscount) * 12)
			break;
	}

	mDiscountRate = ((mTotalAmt - mPlanPriceTotal) * 100) / mTotalAmt

	return mDiscountRate
}



function getPlanPriceTotal(PerMonth, PerMonthNoDiscount, PeriodType){
	var mPlanPrice = 0

	switch(PeriodType){
		case 1:
			mPlanPrice = PerMonth + PerMonthNoDiscount
			break
		case 2:
			mPlanPrice = ((PerMonth * 3) * 0.9) + (PerMonthNoDiscount * 3)
			break
		case 3:
			mPlanPrice = (PerMonth * 10) + (PerMonthNoDiscount * 12)
			break
	}
	/*
	if (mPlanPrice % parseInt(mPlanPrice)){
		mPlanPrice = parseInt(mPlanPrice) + 1
	}			
	*/
	return mPlanPrice
}

function getPlanPricePerMonth(PerMonth, PerMonthNoDiscount, PeriodType){
	var mPlanPrice = 0

	switch(PeriodType){
		case 1:
			mPlanPrice = PerMonth + PerMonthNoDiscount
			break
		case 2:
			mPlanPrice = (((PerMonth * 3) * 0.9) / 3) + PerMonthNoDiscount
			break
		case 3:
			mPlanPrice = ((PerMonth * 10) / 12) + PerMonthNoDiscount
			break
	}
	
	if (mPlanPrice % parseInt(mPlanPrice)){
		mPlanPrice = parseInt(mPlanPrice) + 1
	}			

	return mPlanPrice
}
function getPlanPricePerMonth2(ServerPrice, PerMonth, DisPerMonth, PeriodType){
	var mPlanPrice = 0

	switch(PeriodType){
		case 1:
			mPlanPrice = ServerPrice + PerMonth + DisPerMonth
			break
		case 2:
			//mPlanPrice = ServerPrice + ((PerMonth * 0.9)) + DisPerMonth
			mPlanPrice = ServerPrice + ((PerMonth)) + DisPerMonth
			break
		case 3:
			mPlanPrice = ServerPrice + ((PerMonth * 10) / 12) + DisPerMonth
			break
	}
	
	if (mPlanPrice % parseInt(mPlanPrice)){
		mPlanPrice = parseInt(mPlanPrice) + 1
	}			

	return mPlanPrice
}
function getPlanPriceTotal2(ServerPrice, PerMonth, DisPerMonth, PeriodType){
	var mPlanPrice = 0
	
	//alert(ServerPrice + " -- " + PerMonth + " -- " + DisPerMonth + " -- " + PeriodType)

	switch(PeriodType){
		case 1:
			mPlanPrice = ServerPrice + PerMonth + DisPerMonth
			break
		case 2:
			//mPlanPrice = (ServerPrice * 3) + ((PerMonth * 0.9) * 3) + (DisPerMonth * 3)
			mPlanPrice = (ServerPrice * 3) + ((PerMonth) * 3) + (DisPerMonth * 3)
			break
		case 3:
			mPlanPrice = (ServerPrice * 12) + (((PerMonth * 10) / 12) * 12) + (DisPerMonth * 12)
			break
	}
	/*
	if (mPlanPrice % parseInt(mPlanPrice)){
		mPlanPrice = parseInt(mPlanPrice) + 1
	}			
	*/
	return mPlanPrice
}
function getPlanPriceDiscountRate2(ServerPrice, DsctPerMonth, PerMonth, DisPerMonth, PeriodType){
	var mPlanPriceTotal = 0
	var mDiscountRate = 0
	var mTotalAmt = 0

	switch (PeriodType){
		case 1:
			mPlanPriceTotal = ServerPrice
            mTotalAmt = ServerPrice
			break
		case 2:
			//mPlanPriceTotal = ((ServerPrice + PerMonth + DisPerMonth) * 3)
            //mTotalAmt = ((ServerPrice - DsctPerMonth) * 3) + ((PerMonth * 0.9) * 3) + (DisPerMonth * 3)
            mPlanPriceTotal = ((ServerPrice + PerMonth + DisPerMonth) * 3)
            mTotalAmt = ((ServerPrice - DsctPerMonth) * 3) + ((PerMonth) * 3) + (DisPerMonth * 3)
			break;
		case 3:
			mPlanPriceTotal = (((ServerPrice) + PerMonth + DisPerMonth) * 12)
            mTotalAmt = ((ServerPrice - DsctPerMonth) * 12) + (((PerMonth * 10) / 12) * 12) + (DisPerMonth * 12)
			break;
	}

	mDiscountRate = mPlanPriceTotal - mTotalAmt

	return mDiscountRate
}
