// Expense calculator

{
var svc='Default';
var price10=5;
var pricea4=15;
var total;
var code;
var error;
}

function desel(radio)
{
	//alert(radio+'| l='+radio.length);
	for (i=0; i < radio.length; i++)
	   {		   
	   if (radio[i].checked){
		   //alert(i);
		   radio[i].checked=false;}
	   }	
};

function dedesc(){		//descriptors
	desc_0.style.display='block';
	desc_1.style.display='none';
	desc_2.style.display='none';
	desc_3.style.display='none';
	desc_4.style.display='none';
	desc_5.style.display='none';		
}

function hide_all_sub()
{
	edited_n.style.display='block';
	print10x.style.display='block';	
	place.style.display='none';
	w_day_opt.style.display='none';
	makeup.style.display='none';
	duration.style.display='none';
	giveall.style.display='block';
	edited.style.display='none';
	send.style.display='none';
	print1.style.display='none';
	photobook.style.display='none';
	calc_button.style.display='none';		
	back_button.style.display='none';	
	reset_button.style.display='none';
	//resetting
	calc.give_all.checked=false;
	calc.print_10.checked=false;
	calc.print_a4.checked=false;	
	calc.makeup.checked=false;		
	result.innerHTML='';
}

function hide_all()
{

	desel(calc.sub_1);
	desel(calc.sub_2);
	desel(calc.sub_3);
	desel(calc.sub_4);	
	sub1.style.display='none';
	sub2.style.display='none';
	sub3.style.display='none';
	sub4.style.display='none';
	sub5.style.display='none';	
	hide_all_sub();		

};

function limit_val(source, target){
	// alert(source);
	target.options.length = 0;
	c=0;
	for(i=5;(i<=source);i+=5)
	{
		target.options[c]=new Option(i,i);
		c++;
	}
}

function choice_main(V){
	hide_all();
	desc_0.style.display='none';
	switch (V){
		case '1':
		{//individual
			sub1.style.display='block';
			desc_1.style.display='block';

			
		}; break;
		case '2':
		{//Double
			sub2.style.display='block';
			desc_2.style.display='block';
			
		}; break;
		case '3': 
		{//Children
			sub3.style.display='block';
			desc_3.style.display='block';
			limit_val(40, calc.edited);	
		}; break;
		case '4':
		{//reportage
			sub4.style.display='block';
			desc_4.style.display='block';
		}; break;
		case '5':
		{//film photo
			//place.style.display='block';
			sub5.style.display='block';	
			desc_5.style.display='block';
			edited.style.display='block';
			duration.style.display='block';
			print1.style.display='block';					
			giveall.style.display='none';
			calc_button.style.display='block';	
			limit_val(calc.duration.value*10, calc.edited);	
			limit_val(calc.edited.value, calc.print10);
			limit_val(calc.edited.value, calc.printa4);						
		}; break;
		default: 
		{
			alert(V+'please select type!');
			reset_all();
		};
	}
}
//subchoice individual
function choice_sub1(V){
	hide_all_sub();	
	calc_button.style.display='block';
	reset_button.style.display='block';
	limit_val(calc.duration.value*15, calc.edited);
	limit_val(calc.edited.value, calc.print10);
	limit_val(calc.edited.value, calc.printa4);
	switch (V){
		case '1':
		{//individual common
			svc='individual common';
			place.style.display='block';
			makeup.style.display='block';
			duration.style.display='block';
			edited.style.display='block';
			send.style.display='block';
			print1.style.display='block';
			photobook.style.display='block';
			//alert(v)
		}; break;
		case '2':
		{//Portfolio
			svc='Portfolio';
			limit_val(30, calc.edited);
			makeup.style.display='block';
			edited.style.display='block';
			photobook.style.display='block';
			print1.style.display='block';
			calc.print_a4.checked=true;
			calc.printa4.style.display='inline';
			calc.printa4.value=10;
			calc.printa4.disabled=false;
			
		}; break;
		case '3': 
		{//Web2.0
			svc='Web 2.0';
			place.style.display='block';
			makeup.style.display='block';
			edited.style.display='block';
			edited_n.style.display='none';
			giveall.style.display='block';
			print1.style.display='block';
			send.style.display='block';
			limit_val(5,calc.print10);
			limit_val(5,calc.printa4);
			//alert(v)
		}; break;
		default:alert(V+' op!')
	}
	
}
//subchoice pair
function choice_sub2(V){	
	hide_all_sub();
	calc_button.style.display='block';
	reset_button.style.display='block';
	limit_val(calc.edited.value, calc.print10);
	switch (V){
		case '1':
		{//Love Story
			svc='Love Story';
			makeup.style.display='block';
			//duration.style.display='block';
			edited.style.display='block';
			//send.style.display='block';
			print1.style.display='block';
			print10x.style.display='block';	
			photobook.style.display='block';
			limit_val(40, calc.edited);	
			//alert(v)
		}; break;
		case '2':
		{//Wedding
			svc='Wedding';
			limit_val(100, calc.edited);
			limit_val(5, calc.print10);
			limit_val(5, calc.printa4);
			w_day_opt.style.display='block';
			makeup.style.display='block';
			edited.style.display='block';
			print1.style.display='block';
			photobook.style.display='block';
			//alert(v)
		}; break;
		default:alert(V+' op!')
	}
}
//subchoice children
function choice_sub3(V){
	hide_all_sub();
	calc_button.style.display='block';	
	reset_button.style.display='block';
	limit_val(calc.edited.value, calc.print10);
	switch (V){
		case '1':
		{//6-24 month
			
			//place.style.display='block';//no studio!
			edited.style.display='block';
			//send.style.display='block';
			print1.style.display='block';
			photobook.style.display='block';
			//alert(v)
		}; break;
		default:
		{
			place.style.display='block';
			edited.style.display='block';
			//send.style.display='block';
			print1.style.display='block';
			photobook.style.display='block';
			//alert(v)
		}
	}
}
//reportages & corporate
function choice_sub4(V){
	hide_all_sub();
	calc_button.style.display='block';
	reset_button.style.display='block';
	limit_val(calc.edited.value, calc.print10);
	switch (V){
		case '1':
		{//Reportage
			svc='Reportage';
			limit_val(100, calc.print10);
			limit_val(100, calc.printa4);
			duration.style.display='block';			
			send.style.display='block';
			print1.style.display='block';
			//alert(v)
		}; break;
		case '2':
		{//Graduate
			svc='Graduate';
			place.style.display='block';
			edited.style.display='block';
			print1.style.display='block';
			photobook.style.display='block';
			//alert(v)
		}; break;
		default:alert(V+' op!')
	}
}


//Funcion that check or uncheck fields in wedding options depending on "Full" state
function w_day(field, st)
{		
	//alert('L:'+field.length);
	if(st == 1)
	{		
		for (i=1;i<=4;i++)
		{			
			field[i].checked = field[0].checked;				
		}	
		if(field[0].checked){framed.style.borderColor='#ED1C24'} else {framed.style.borderColor='#EFEFEF'};
	} else 
	{	
		c=0;
		//alert(this);
		
		for (i=1;i<field.length;i++)
		{
			//alert(i+ '=' + field[i].checked);
			if (field[i].checked == true)	
			{
				c++;
			}
		}
		//alert('checked fields: '+c);
		if (c==4) 
		{
			field[0].checked=true;		
		} else 
		{
			field[0].checked=false
		}
		if(field[0].checked){framed.style.borderColor='#ED1C24'} else {framed.style.borderColor='#EFEFEF'};	
	}
}

function enable(source,target)
{
	if (source.checked==true){target.disabled=false; target.style.display='inline'} else {target.disabled=true; target.style.display='none'};
}

function radio_value(radio)
{
	for (i=0; i < radio.length; i++)
	   {
	   if (radio[i].checked)
		  {
		  return radio[i].value;
		  }
	   }
}

function show_result()
{
	var res = document.getElementById('result');
	res.innerHTML=svc+'\n'+'Place:'+radio_value(calc.place)+'; Makeup: '+calc.makeup.checked+'; Duration:'+calc.duration.value+'; Ned: '+calc.edited.value+'; Sendway:'+radio_value(calc.send)+'; Print10:'+calc.print10.value+'; PrintA4: '+calc.printa4.value+'; Photobook '+calc.photobook.checked;

}

///////////////////////////////////////////CALCULATORS///////////////////////////////////////////////
///                                                                                              ////
///                Не дивуйтесь, всю цю неоптимізовану нісенітницю я нашкрябав власноруч         ////
///                                                                                              ////
///                                                                                              ////
/////////////////////////////////////////////////////////////////////////////////////////////////////
function calc_11()
{//1.1 Common photosession
    
	total=0;
	pl=0;
	// $:hour@place 	 
	code='11.';
	code+=calc.duration.value;
	switch(radio_value(calc.place))	
	{
		case '1': {pl=150; code+='xO';}; break;
		case '2': {pl=300; code+='xS';}; break;
		case '3': {pl=200; code+='xI';}; break;
		default: alert("select location first!");
	}
	if(calc.makeup.checked==true){
		//alert('+300');
		total+=200;
		code+='mk';
	}
	//alert('time*work: +'+calc.duration.value*pl);
	total+=calc.duration.value*pl;
	//number of edited photos;
	total+=(calc.edited.value-5)*30;
	code+=calc.edited.value+'e';
	//double price for all
	if (calc.give_all.checked==true){total+=pl*calc.duration.value; code+='X2'};
	//+20 for CD
	if (radio_value(calc.send)==2){total+=20; code+='cd'};
	//if prinetd 10x15
	if(calc.print_10.checked==true){
		total+=calc.print10.value*price10;
		//alert('10x15: '+calc.print10.value*price10);
		code+='10-'+calc.print10.value
	};
	//if prinetd A4
	if(calc.print_a4.checked==true){
		total+=calc.printa4.value*pricea4;
		//alert('A4: '+calc.printa4.value*pricea4);
		code+=('A-'+calc.printa4.value
	)};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}

function calc_12()
{//1.2 Porfolio
	code='12.';
    total=700;
	pl=0;
	// $:hour@place 		
	if(calc.makeup.checked==true){
		//alert('+300');
		total+=300;
		code+='mk';
	}	
	//number of edited photos;
	total+=(calc.edited.value-10)*20;
	code+=calc.edited.value+'e';
	//double price for all
	if (calc.give_all.checked==true){total+=total/2; code+='X2';};	
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=(calc.printa4.value-5)*pricea4; code+=('A-'+calc.printa4.value);};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}

function calc_13()
{//1.3 Web 2.0
	total=50;
	pl=0;
	// $:hour@place 	 
	code='13.';	
	switch(radio_value(calc.place))	
	{
		case '1': {pl=150; code+='xO';}; break;
		case '2': {pl=250; code+='xS';}; break;
		case '3': {pl=200; code+='xI';}; break;
		default: alert("select location first!");
	}
	total+=pl;
	if(calc.makeup.checked==true){
		//alert('+300');
		total+=150;
		code+='mk';
	}
	//double price for all
	if (calc.give_all.checked==true){total+=300; code+='X2'};
	//+20 for CD
	if (radio_value(calc.send)==2){total+=20; code+='cd'};
	//if prinetd 10x15
	if(calc.print_10.checked==true){total+=calc.print10.value*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
	//return total;	
}

function calc_21()
{//2.1 Love Story

	total=300;
	pl=0;
	// $:2hour@place 	 
	code='21.';
	code+=calc.duration.value;	
	if(calc.makeup.checked==true){
		total+=200;
		code+='mk';
	}		
	//number of edited photos;
	total+=calc.edited.value*20;
	code+=calc.edited.value+'e';
	//double price for all
	if (calc.give_all.checked==true){total+=400; code+='X2'};
	//if prinetd 10x15
	if(calc.print_10.checked==true){total+=calc.print10.value*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}

function calc_22()
{//2.2 Wedding
	total=0;
	pl=0;
	// $:hour@place 	 
	code='22.';	c=0;
		if(calc.w_day_opt[0].checked==true){
		//alert('+2000');
		total+=2000;
		code+='FD';
	} else 	{
		
		for (i=1;i<calc.w_day_opt.length; i++)
		{
			if (calc.w_day_opt[i].checked==true){c++; code+='-'+i;}			
		}		
		if(c>0){total+=(c*500); error=false; } else {alert("You've forgotten to select part of your wedding!"); throw 'stop';};
	}	
	if(calc.makeup.checked==true){
		total+=200;
		code+='mk';
	}		
	/*number of edited photos;
	total+=calc.edited.value*30;
	code+=calc.edited.value+'e';*/
	//number of edited photos;
	total+=(calc.edited.value-10)*20; code+=calc.edited.value+'e';
	//double price for all
	if (calc.give_all.checked==true){total+=500; code+='X2'};	
	//print 10x15 (10 included)
	if(calc.print_10.checked==true){total+=(calc.print10.value-10)*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
	//lovestory
	if(calc.w_preoption.checked==true){total+=800; code+='-LS-'};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}

function calc_3()
{//3.Kids
   
	total=0;
	pl=0;
	// $:hour@place 	 
	code='3.';
	switch(radio_value(calc.sub_3))	
	{
		case '1': {code+='k1';}; break;
		case '2': {code+='k2';}; break;
		case '3': {code+='k3';}; break;
		default: alert("there's no kids home!");
	}		
	switch(radio_value(calc.place))	
	{
		case '1': {total+=400;  code+='xO';}; break;
		case '2': {total+=500;  code+='xS';}; break;
		case '3': {total+=400;  code+='xI';}; break;
		default: alert("there's no place like home!");
	}		
	//number of edited photos;
	total+=(calc.edited.value-10)*20;
	code+=calc.edited.value+'e';
	//double price for all
	if (calc.give_all.checked==true){total+=400; code+='X2'};
	//+20 for CD
	code+='cd';
	//if prinetd 10x15
	if(calc.print_10.checked==true){total+=(calc.print10.value-10)*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}

function calc_41()
{//4.1 Reportage
	total=0;
	pl=0;
	// $:hour@place 	 
	code='41.';
	code+='R'+calc.duration.value;
	if (calc.duration.value<=2)
	{
		total+=calc.duration.value*300;		
	} else 
	{
		total+=(2*300);
		total+=(calc.duration.value-2)*200;
	};
	//+20 for CD
	if (radio_value(calc.send)==2){code+='cd'};
	//if prinetd 10x15
	if(calc.print_10.checked==true){total+=calc.print10.value*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
	//for photobook
	if(calc.photobook.checked==true){total+=500; code+='ph'};
	//return total;	
}
function calc_42()
{//4.2 Graduate
	total=2000;	 
	code='42.G';	
}

function calc_5()
{//5.Film
	total=0;
	code='51.';
	code+='F'+calc.duration.value;
	total+=calc.duration.value*100;
	fn=0;
	if(calc.film_give_negative.checked==true){total+=400};
	//if(calc.film_digital.checked==true){total+=100};
	//film type selector affects on price
	if (radio_value(calc.frame_type)==1){fn=10} else {fn=5};
	switch(calc.film_type.value)	
	{
		case 'bw': {tp=60; c='xBW';}; break;
		case 'color': {tp=60; c='xCLR';}; break;
		case 'slide': {tp=100; c='xSLD';}; break;
		default: alert("there's no film type selected!");
	}
	//number of edited photos and films;
		
	//nf=Math.ceil(calc.edited.value/fn);
	nf=calc.duration.value;
	//alert('Films: '+nf);
	total+=nf*tp+20*calc.edited.value; code+=calc.edited.value+c;
	
	//if prinetd 10x15
	if(calc.print_10.checked==true){total+=calc.print10.value*price10; code+='10-'+calc.print10.value};
	//if prinetd A4
	if(calc.print_a4.checked==true){total+=calc.printa4.value*pricea4; code+=('A-'+calc.printa4.value)};
}

function smart_limit()
{
	if (calc.sel_main.value=='5'){
		if (radio_value(calc.frame_type)==1){limit_val(calc.duration.value*10, calc.edited)} else {limit_val(calc.duration.value*5, calc.edited)};	
	} else {
		limit_val(calc.duration.value*15, calc.edited);
	}
}

function pidraxyj()
{ 
	total=0;
	code='';
	switch(calc.sel_main.value)	
	{
		case '1': {
				switch(radio_value(calc.sub_1))	
				{
					case '1': {calc_11(); wtf('11');}; break;
					case '2': {calc_12(); wtf('12');}; break;
					case '3': {calc_13(); wtf('13');}; break;
					default: alert("something gone wrong in personal!");
				}								
			}; break;
		case '2': {
				switch(radio_value(calc.sub_2))	
					{
						case '1': {calc_21(); wtf('21');}; break;
						case '2': {calc_22(); wtf('22');}; break;
						default: alert("problem in pair!");
					}
			}; break;
		case '3': {
				calc_3();
				wtf('3');				
			}; break;
		case '4': {
				switch(radio_value(calc.sub_4))	
					{
						case '1': {calc_41(); wtf('41')}; break;
						case '2': {calc_42(); wtf('42')}; break;						
						default: alert("there's no reportage chosen!");
					}
			}; break;
		case '5': {
				calc_5();
				wtf('5');
			}; break;
		default: alert("there's nothing to do with that!");
	}		
	//calc.sel_main.value='0';
	
	//CASE
	
}

function get_back() 
{
//hide_all();
dedesc();
details.innerHTML='';
calc_main.style.display='block';		
back_button.style.display='none';
}


function reset_all()
{
get_back();
hide_all();
calc.give_all.checked=false;
calc.sel_main.value='0';
calc.duration.value='2';
calc.place[0].checked=true;
calc.makeup.checked=false;
calc.print_10.checked=false;
calc.print_a4.checked=false;
calc.photobook.checked=false;
for(i=0;i<=4;i++){calc.w_day_opt[i].checked=true};
calc.w_preoption.checked=false;

}
