var hasUpdate = 0;



var section = []

section['ROOM'] = ['room_1_total','room_2_total','room_3_total','room_other_total','guest_room_total'];

section['MEETING'] = ['session_room_total','board_room_total','break_room_total','hosp_room_total','regis_room_total','other_room_total','meeting_room_total'];

section['MEAL'] = ['cont_total','full_total','lunch_total','dinner_total','rec_total','am_total','pm_total','food_total'];

section['AV'] = ['lavmic_cost','standmic_cost','light_cost','lcd_cost','record_cost','connect_cost','chart_cost','padpen_cost','otherav_cost','av_total'];

section['DECORATION'] = ['sign_cost','plant_cost','centerpiece_cost','regdec_cost','stage_cost','set_cost','otherdec_cost','dec_total'];

section['REC'] = ['golf_cost','tennis_cost','outings_cost','otherrec_cost','recreate_total'];

section['OTHER'] = ['other_1_total','other_2_total','other_3_total','other_4_total','other_total'];

function calcFields() {

	_target = document.getElementById(arguments[arguments.length-1]);

	var output = 1 

	for(i=1;i<arguments.length-1;i++) {

		var field = parseFloat(document.getElementById(arguments[i]).value)

		_value = (!isNaN(field)&&field!="") ? field : 0;

		if(_value != 0) hasUpdate = 1;

		output *= _value;

	}

	_target.value = Math.round(output*100)/100;

	calcSectionTotals(arguments[0]);

}

function calcTotals() {

	_target = document.getElementById(arguments[arguments.length-1]);

	var output = 0;

	for(i=0;i<arguments.length-1;i++) {

		argValue = parseFloat(document.getElementById(arguments[i]).value);

		_value = (!isNaN(argValue)&&argValue!="") ? argValue : 0;

		if(_value != 0) hasUpdate = 1;

		output += _value;

	}

	_target.value = output;

}

function calcSectionTotals(_type) {

	_target = document.getElementById(section[_type][section[_type].length-1])

	var total = 0;

	for(x=0;x<section[_type].length-1;x++) {

		var group = parseFloat(document.getElementById(section[_type][x]).value);

		total += (!isNaN(group)&&group!="") ? group : 0;

	}

	_target.value = Math.round(total*100)/100;

	calcTotals('guest_room_total','meeting_room_total','food_total','other_total','grand_total');

	

}

function acceptNumbers(e) {

	var evt = window.event ? e.keyCode : e.which;

	if((evt>=33&&evt<46)||(evt==47)||(evt>58)) {

		return false;

	} else { 

		return true;

	}

}



function sendToExcel(f) {

	var submitURL = "/meetings/budget_calculator.xls?jspName=meetings_budget_calculator&fileName=budget_calculator.xls"

	var inputList = f.getElementsByTagName("input");

	var queryStringBuilder = ""

	for(i=0;i<inputList.length;i++) {

		if(inputList[i].type=="text"&&inputList[i].disabled!=1) {

			queryStringBuilder += inputList[i].id + "=" + escape(inputList[i].value);

			if(i!=inputList.length-1) queryStringBuilder += "&";

		}

	}

	window.open(submitURL + "&" + queryStringBuilder + "&" + "timestamp=" + new Date().getTime());

}

function clearDefaultText(t,v) {

	if(t.value == v) {

		t.value = "";

	}

}