﻿/**
 * @author jason.ibele
 */


var mediaType = document.getElementById('mediaType');
var propType = document.getElementById('propType');

// variable base numbers
var emc = document.getElementById('emc'); // Effective Monthly Cost
var adr = document.getElementById('adr'); // Average Daily Rate
var als = document.getElementById('als'); // Average Length of Stay
var avlb = document.getElementById('avlb'); // Average Look-to-Book Rate
var amv = document.getElementById('amv'); // Avg. No. Monthly Visitors

// result fields
var rAnmmv  = document.getElementById('rAnmmv');  // Avg. No. Monthly Media Views
var rAnmmvp = document.getElementById('rAnmmvp'); // Avg. No. Monthly Media Views from 3rd Party Sites
var rIiltb  = document.getElementById('rIiltb');  // Increase in Look-to-Book
var rNib    = document.getElementById('rNib');    // No. of Incremental Bookings
var rNibp   = document.getElementById('rNibp');  // No. of Incremental Bookings on 3rd Party Sites
var rTaib   = document.getElementById('rTaib');   // Total Annual Incremental Bookings
var rTaibm   = document.getElementById('rTaibm');   // Total Monthly Incremental Bookings
var rAroi   = document.getElementById('rAroi');   // Annual Return On Investment
var rNbpfm  = document.getElementById('rNbpfm');  // No. of Bookings/Month to Pay for Media
var tibm = document.getElementById('tibm'); // Total No. of Incremental Bookings per Month

function onPropChange(){
	propType.style.backgroundColor = 'lightblue';
	calculateRoi();
	
}
function onTypeChange(){
	if(isNaN(mediaType.value)) {
		emc.value = '';
		return;
	}
	
	emc.value = Number(mediaType.value);
	mediaType.style.backgroundColor = 'lightblue';
	calculateRoi();
	
}
function calculateRoi() {
	
	if(isNaN(mediaType.value) || mediaType.value == '') {
		emc.value = '';
		mediaType.style.backgroundColor = "#FF6F75";
		//alert('Please select a media service type');
		return;
	}

	rAnmmv.value = Math.round(amv.value*0.25);
	rAnmmvp.value = Math.round(rAnmmv.value*0.9);
	
	switch(Number(emc.value)) {
		case(175):
			rIiltb.value = (propType.value == 1) ? 30 : 89; // Percentage Look to Book
			break;
		case(275):
			rIiltb.value = (propType.value == 1) ? 30 : 89; // Percentage Look to Book
			break;
		case(375):
			rIiltb.value = (propType.value == 1) ? 30 : 89; // Percentage Look to Book
			break;
		case(100):
			rIiltb.value = (propType.value == 1) ?  18 : 67; // Percentage Look to Book
			break;
		default:
			alert(emc.value);
	}
	
	rNib.value  = Math.round(((rAnmmv.value*(avlb.value/100)*(rIiltb.value/100))+(rAnmmvp.value*.0225) ));
	rNibp.value = Math.round((rAnmmvp.value*(avlb.value/100)*(0.5)*(rIiltb.value/100)));
	rTaibm.value = Math.round((rNib.value*adr.value*als.value)+(rNibp.value*adr.value*als.value*0.8));	
	rTaib.value = Math.round(rTaibm.value*12);
	tibm.value = Number(rNib.value)+Number(rNibp.value);
	rAroi.value = Math.round(rTaib.value/(emc.value*12));
	rNbpfm.value = Math.round( (emc.value/(adr.value*als.value))*100)/100;

}






