//alert ("1.2");

var band_objs = new Array(); // holds refs to band objects so you can loop through them.
var array_num = 0;
var uc_array = new Array(50,250,350,475,625);
var uc1_array = new Array(60,300,420,570,750);
var uc2_array = new Array(70,350,490,665,875);
var quad_array = new Array(40,125,200,325,500);
var sht_array = new Array(30,60,120,300,475);
var c2p_array = new Array(20,40,90,150,300);

var distances = new Array(); //  base distances to be modified by the individual bands
distances[0] = 0;
distances[1] = 0; //0-49K //0-100k,
distances[2] = 100; //50-149 //101-200k,
distances[3] = 200; //150-274 //201-300k, 
distances[4] = 275; //275-399 // 301-400k/
distances[5] = 375; //400k+
//distances[] = ;

var high_travel = 0;
var high_av = 0;
//alert(' = ' + );
function calcBandHours(a) 
{
 var season_variable = (document.getElementById('sept_mar').checked == true)? this.season : 0;
 var the_hours = parseFloat(this.chosen_hours); //alert('the hours = ' + the_hours); // created by the ddlist for a given band 
 var total_hourly_cost = this.per_hour * the_hours; // raw calc of time * per hour
 //alert('total_hourly_cost(' + total_hourly_cost + ') = this.per_hour(' + this.per_hour + ') * the_hours(' + the_hours + ')')
 var total_cost = 0;
 if(a == true)
 {total_cost = total_hourly_cost;} //use hourly cost if more than one band
 else
 {total_cost = (this.chosen_hours > this.min_time)? total_hourly_cost : (this.min_time * this.per_hour);} // use min time if only 1 band
 var total_seasonal_discount_time = (this.chosen_hours > this.min_time)? this.chosen_hours : this.min_time;
 var return_total_cost = total_cost + (season_variable * total_seasonal_discount_time);
 //alert('return_total_cost(' + return_total_cost + ') = total_cost(' + total_cost + ') + (season_variable(' + season_variable + ') * total_seasonal_discount_time(' + total_seasonal_discount_time + ')');
 return return_total_cost;
}

function band(hourly_rate,minimum_time,travel_charge,av_charge,seasonal_rebate,is_used,band_name) //creates a band object with properties set per band
	{
	 this.per_hour = hourly_rate;
	 this.min_time = minimum_time;
	 this.travel = travel_charge;
	 this.av = av_charge;
	 this.season = seasonal_rebate;
	 this.in_use = is_used;
	 this.bname = band_name;
	 this.calc_hours = calcBandHours; //creates method (attaches function reference)
	 band_objs[array_num] = this; //adds a reference to band_objs array.
	 array_num++;
	 }

//(hourly_rate,minimum_time,travel_charge,av_charge,seasonal_rebate,is_used,band_name)
var urban_cowboys = new band(625,3,uc_array,100,-25,false,'urban_cowboys');
var urban_cowboys1 = new band(750,4,uc1_array,150,-50,false,'urban_cowboys1');
var urban_cowboys2 = new band(875,4,uc2_array,250,-50,false,'urban_cowboys2');
var quadra = new band(450,3,quad_array,75,-25,false,'quadra');
var stu_harrison_trio = new band(325,"2.5",sht_array,0,0,false,'stu_harrison_trio'); //check per hour cost and minimum time...
var custom_2piece = new band(200,"1.5",c2p_array,0,0,false,'custom_2piece');


function getTravel(this_band_travel)
{
 var this_high_travel = 0; // holder for highest travel
 var array_id = document.getElementById('distance_choice'); //id ref for which distance dd list
 //var chosen_trav_cost = distances[array_id.options[array_id.selectedIndex].value]; //holder for dd list value
 var temp_band_cost = this_band_travel.travel[array_id.options[array_id.selectedIndex].value]; //holder for given band's travel cost
 //var temp_band_trav_cost = (chosen_trav_cost + temp_band_modifier); //add travel cost and band modifier
 this_high_travel = (temp_band_cost > high_travel)? temp_band_cost : high_travel; //test for highest
 return this_high_travel; //send back answer to function that called this function 
}

function controlBox()
{
 var more_than_one_band = false;
 var band_price = new Array(); //array to store separate band prices
 var band_nums = 0;
 
 for(i=0; i<band_objs.length; i++)
 	{if(band_objs[i].in_use == true)
		{band_nums++;}
	}
	 
 for(i=0; i<band_objs.length; i++)
 	{
	 var band_x = band_objs[i];
	 if(band_x.in_use == true)
	 	{more_than_one_band = (band_nums > 1)? true : false ; //alert('more than 1 = ' + more_than_one_band);
		 band_price.push(band_x.calc_hours(more_than_one_band)); //calc band price and place in array; must use push method to place in consecutive order
		 high_travel = getTravel(band_x); //calc highest travel cost
		 high_av = (band_x.av > high_av)? band_x.av : high_av; //get highest av cost
		}
	}

var total_band_price = 0; //
var current_price = 0; //number to start price comparison
var band_array_num = null; //holds which array position number is highest
if(more_than_one_band == true) // if more than one band
	{
	 for(i=0; i<band_price.length; i++)
		{
		 if(band_price[i] > current_price) // if band price from array is more than current price
	 		{//alert('band_price[' + i + '](' + band_price[i] + ') : current_price(' + current_price + ')');
			 current_price = band_price[i]; // make the current price the band price
			 band_array_num = i; //use this counter number as the index value for band_price array
			}
		}
	 if(band_array_num != null)
	 	{
		 var new_price = band_price[band_array_num];
		 //alert('new_price = ' + new_price);
		 new_price = (new_price*2)
		 //alert('new_price2 = ' + new_price);
		 band_price[band_array_num] = new_price;
		 for(i=0; i<band_price.length; i++)
			{var temp_price = band_price[i];
			 //alert('band price pre:' + temp_price);
			 temp_price = (temp_price/2);
			 band_price[i] = temp_price;
			 //alert('band price post:' + band_price[i]);
			}
		}
	}

for(i=0; i<band_price.length; i++)
	{total_band_price += band_price[i];} //add band prices
	
var the_av_cost = (document.getElementById('the_av').checked == true)? high_av : 0; //test for av need
//alert('total_band_price (' + total_band_price + ') + high_travel (' + high_travel + ') + the_av_cost (' + the_av_cost + ') = ' + (total_band_price + high_travel + the_av_cost));
var total_price = total_band_price + high_travel + the_av_cost; // add it up

document.getElementById('total_price_text').value = total_price.toString(); // set the text

 high_travel = 0;
 high_av = 0;
 the_av_cost = 0;
}

function bandReset()
{
 for(i=0; i<band_objs.length; i++)
 	{
	 var band_x = band_objs[i];
	 band_x.in_use = false
	}
 high_travel = 0;
 high_av = 0;
 the_av_cost = 0;
}

function randNum()
{var the_div = document.getElementById('randomnum');
 var the_date = new Date();
 var the_tag = (Math.floor(Math.random()*999999))
 the_div.innerHTML = ' <b>TAG# ' + the_tag + '</b>' + ' ';
 document.getElementById('tag').value = the_tag;
}
