matPrices = [168,241,320,428,236.5,187.89,300];        //Цены на материалы по порядку. 7 цифр. десятичная часть отделяется точкой

matFactors_1_1 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06]; 
matFactors_2_1 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];         
matFactors_3_1 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];         

matFactors_1_2 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_2 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_2 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

matFactors_1_3 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_3 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_3 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

matFactors_1_4 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_4 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_4 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

matFactors_1_5 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_5 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_5 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

matFactors_1_6 = [1,1,1,1,1,1,1];
matFactors_2_6 = [1,1,1,1,1,1,1];
matFactors_3_6 = [1,1,1,1,1,1,1];

matFactors_1_7 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_7 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_7 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

matFactors_1_8 = [1.05,1.05,1.05,1.05,1.09,1.09,1.06];
matFactors_2_8 = [1.1,1.1,1.1,1.1,1.15,1.15,1.11];
matFactors_3_8 = [1.2,1.2,1.2,1.2,1.3,1.3,1.2];

rooflevel_factors = [1,1,1];

angle_factors = [1,0.5];

middle_factors = [1,1.18];


function SetStatusMessage(msg, status_id)
{
    var Status_Bar = document.getElementById(status_id);
    Status_Bar.innerHTML = msg;
}

function CheckRadioButton(btn_id)
{
    var RadioBtn = document.getElementById(btn_id);
    RadioBtn.checked = true;
	if (btn_id == 'rmat1' || btn_id == 'rmat2' || btn_id == 'rmat3' || btn_id == 'rmat4')
	{	
		
		document.getElementById('roofmaterials_mat1').disabled = false;				
		document.getElementById('roofmaterials_mat3').disabled = false;	
		
	}
	
	if (btn_id == 'rmat5')
	{
		document.getElementById('roofmaterials_mat1').checked = false;
		document.getElementById('roofmaterials_mat1').disabled = true;	
		
		document.getElementById('roofmaterials_mat3').checked = false;
		document.getElementById('roofmaterials_mat3').disabled = true;	
		
		document.getElementById('roofmaterials_edit').value = '';
		document.getElementById('roofmaterials_edit').disabled = true;
		
		document.getElementById('roofmaterials_mat4').disabled = false;
	}
	
	if (btn_id == 'rmat6')
	{
		document.getElementById('roofmaterials_mat1').checked = false;
		document.getElementById('roofmaterials_mat1').disabled = true;	
		
		document.getElementById('roofmaterials_mat4').checked = false;
		document.getElementById('roofmaterials_mat4').disabled = true;	
		
		document.getElementById('roofmaterials_edit').value = '';
		document.getElementById('roofmaterials_edit').disabled = true;
	
		document.getElementById('roofmaterials_mat3').disabled = false;	
	}
	
	if (btn_id == 'rmat7')
	{
		document.getElementById('roofmaterials_mat1').checked = false;
		document.getElementById('roofmaterials_mat1').disabled = true;	
		
		document.getElementById('roofmaterials_mat4').checked = false;
		document.getElementById('roofmaterials_mat4').disabled = true;	
		
		document.getElementById('roofmaterials_edit').value = '';
		document.getElementById('roofmaterials_edit').disabled = true;
	
		document.getElementById('roofmaterials_mat3').disabled = false;	
	}
}

function CheckMansard()
{
    
    document.getElementById('roofmaterials_mat6').disabled = false;    
    document.getElementById('roofmaterials_mat7').disabled = false;
	document.getElementById('roofmaterials_mat8').disabled = false;
        
}

function CheckColdRoof()
{    
    document.getElementById('roofmaterials_mat6').checked = false;
    document.getElementById('roofmaterials_mat6').disabled = true;
    document.getElementById('roofmaterials_mat7').checked = false;
    document.getElementById('roofmaterials_mat7').disabled = true;
	document.getElementById('roofmaterials_mat8').checked = false;
    document.getElementById('roofmaterials_mat8').disabled = true;
	
    
}

function CheckCheckBox(chk_box_id)
{
    var ChkBox = document.getElementById(chk_box_id);

    if (ChkBox.disabled == false)
    {
        if (ChkBox.checked == true)
        {
            ChkBox.checked = false;
        }
        else
        {
            ChkBox.checked = true;
        }
    }
}

function CheckMaterialsGroup(group_name, chk_box_id, need_check)
{

    if (need_check == true)
    { 
        CheckCheckBox(chk_box_id);
    }
}

function CheckRoofmaterialsEdit(chk_box_id, edit_id)
{
    var roof_edit = document.getElementById(edit_id);

    var ChkBox = document.getElementById(chk_box_id);
    if (ChkBox.checked == true)
    {
        roof_edit.disabled = false;
    }
    else
    {
        roof_edit.disabled = true;
        roof_edit.value = '';
        if (chk_box_id == 'roofmaterials_mat1')
        {
            var roofadvmats_edit = document.getElementById('roofadvmats_edit');
            roofadvmats_edit.disabled = true;
        }
    }
}

function CheckBoxesGroups(group_name, need_check)
{	
	var check_group = document.getElementsByName(group_name);
    if (need_check == false)
    {
        for (i = 0; i < check_group.length; i++)
        {
			if (check_group[i].disabled != true)
			{
				check_group[i].checked = false;
				
				if (check_group[i].id == 'roofmaterials_mat1')
				{
					document.getElementById('roofmaterials_edit').disabled = true;
				}
				
				if (check_group[i].id == 'roofadvmats_mat1')
				{
					document.getElementById('roofadvmats_edit_1').disabled = true;
				}
				
				if (check_group[i].id == 'roofadvmats_mat2')
				{
					document.getElementById('roofadvmats_edit_2').disabled = true;
				}
				
			}
        }
    }
	else
	{
		for (i = 0; i < check_group.length; i++)
        {
			if (check_group[i].disabled != true)
			{
				check_group[i].checked = true;
				
				if (check_group[i].id == 'roofmaterials_mat1')
				{
					document.getElementById('roofmaterials_edit').disabled = false;
				}
				
				if (check_group[i].id == 'roofadvmats_mat1')
				{
					document.getElementById('roofadvmats_edit_1').disabled = false;
				}
				
				if (check_group[i].id == 'roofadvmats_mat2')
				{
					document.getElementById('roofadvmats_edit_2').disabled = false;
				}
				
			}
        }
	}
	true;
}


function CheckCheckBox_adv(group_name, chk_box_id)
{   
        CheckCheckBox(chk_box_id);   
}

function onclickCheckCheckBox_adv(group_name, chk_box_id)
{
    var result = advCheck_Materials_Group(group_name); 
}


function setEditFocus(edit_id)
{
    var my_edit = document.getElementById(edit_id);
    if (my_edit.disabled == false)
    {
        my_edit.focus();
    }
}

function clearInfopanel()
{    
    var infopanel = document.getElementById('infopanel');
    infopanel.innerHTML = '&nbsp;'
}

function ClearResult()
{
	document.getElementById('pricepanel').innerHTML = '&nbsp;<sup>&nbsp;</sup>';
	document.getElementById('common_price').innerHTML = '&nbsp;';
}
function evaluateRoof()
{

    var infopanel = document.getElementById('infopanel');
    
	
	
    var roofType_edit = document.getElementById('rooftype_edit');
    var roofMaterials_edit = document.getElementById('roofmaterials_edit');
    var roofadvMaterials_edit_1 =  document.getElementById('roofadvmats_edit_1');
	var roofadvMaterials_edit_2 =  document.getElementById('roofadvmats_edit_2');
	
    
    var can_calc = true;
    if (roofType_edit.value == '')
    {
        infopanel.innerHTML = '<font color="#ff2222">Внимание:</font> введите площадь крыши';
        roofType_edit.focus();
        can_calc = false;
        setTimeout("clearInfopanel();", 4000);
    }
    
    if (document.getElementById('roofmaterials_mat1').checked == true)
    {
        if (roofMaterials_edit.value == '')
        {
            infopanel.innerHTML = '<font color="#ff2222">Внимание:</font> введите уклон крыши';
            roofMaterials_edit.focus();
            can_calc = false;
            setTimeout("clearInfopanel();", 4000);
        }
    }
    
    if (document.getElementById('roofadvmats_mat1').checked == true)
    {
        if (roofadvMaterials_edit_1.value == '')
        {
            infopanel.innerHTML = '<font color="#ff2222">Внимание:</font> введите среднюю высоту от отмостки до карниза';
            roofadvMaterials_edit_1.focus();
            can_calc = false;
            setTimeout("clearInfopanel();", 4000);
        }
    }
	
	if (document.getElementById('roofadvmats_mat2').checked == true)
    {
        if (roofadvMaterials_edit_2.value == '')
        {
            infopanel.innerHTML = '<font color="#ff2222">Внимание:</font> введите количество мансардных окон';
            roofadvMaterials_edit_2.focus();
            can_calc = false;
            setTimeout("clearInfopanel();", 4000);
        }
    }

    if (can_calc == true)
    {
		var n_level = 0;
        var roof_level = document.getElementsByName('rooflevel');
        for (i = 0; i < roof_level.length; i++)
        {
            if (roof_level[i].checked == true)
            {
                n_level = i;
                break;
            }        
        }
		
		var n_mat = 0;
        var mat_group = document.getElementsByName('materials_name');
        for (i = 0; i < mat_group.length; i++)
        {
            if (mat_group[i].checked == true)
            {
                n_mat = i;
                break;
            }        
        }		
		var rooflevel = n_level;
		
		var rooflevel_factor = rooflevel_factors[roof_level[n_level].value];				
			
		var material_factor = 0;
		
		if (rooflevel == 0)
		{
			material_factor_1 = matFactors_1_1[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_1 = matFactors_2_1[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_1 = matFactors_3_1[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_2 = matFactors_1_2[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_2 = matFactors_2_2[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_2 = matFactors_3_2[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_3 = matFactors_1_3[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_3 = matFactors_2_3[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_3 = matFactors_3_3[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_4 = matFactors_1_4[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_4 = matFactors_2_4[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_4 = matFactors_3_4[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_5 = matFactors_1_5[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_5 = matFactors_2_5[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_5 = matFactors_3_5[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_6 = matFactors_1_6[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_6 = matFactors_2_6[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_6 = matFactors_3_6[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_7 = matFactors_1_7[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_7 = matFactors_2_7[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_7 = matFactors_3_7[mat_group[i].value];		
		}
		
		if (rooflevel == 0)
		{
			material_factor_8 = matFactors_1_8[mat_group[i].value];			
			
		}
		if (rooflevel == 1)
		{
			material_factor_8 = matFactors_2_8[mat_group[i].value];
			
		}
		if (rooflevel == 2)
		{
			
			material_factor_8 = matFactors_3_8[mat_group[i].value];		
		}
		
		
		var material_price = matPrices[mat_group[i].value];

		
		var n_level = 0;
        var roof_level = document.getElementsByName('rooflevel');
        for (i = 0; i < roof_level.length; i++)
        {
            if (roof_level[i].checked == true)
            {
                n_level = i;
                break;
            }        
        }		
		
		
		var down_layer = 0;
		if (document.getElementById('roofmaterials_mat1').checked == true)
		{
			down_layer = document.getElementById('roofmaterials_mat1').value
		}
		
		var accesories = 0;
		if (document.getElementById('roofmaterials_mat2').checked == true)
		{			
			accesories = document.getElementById('roofmaterials_mat2').value;
		}

		
		var solid_base = 0;		
		if (document.getElementById('roofmaterials_mat3').checked == true)
		{
			solid_base = document.getElementById('roofmaterials_mat3').value;
		}
		
		var lattice = 0;		
		if (document.getElementById('roofmaterials_mat4').checked == true)
		{
			lattice = document.getElementById('roofmaterials_mat4').value;
		}
		
		var kontr_bus = 0;		
		if (document.getElementById('roofmaterials_mat5').checked == true)
		{
			kontr_bus = document.getElementById('roofmaterials_mat5').value;
		}
		
		var heat_holder = 0;		
		if (document.getElementById('roofmaterials_mat6').checked == true)
		{
			heat_holder = document.getElementById('roofmaterials_mat6').value;
		}

		var vapour_isolate = 0;
		
		if (document.getElementById('roofmaterials_mat7').checked == true)
		{
			vapour_isolate = document.getElementById('roofmaterials_mat7').value;
		}
		
		var membran = 0;		
		if (document.getElementById('roofmaterials_mat8').checked == true)
		{
			membran = document.getElementById('roofmaterials_mat8').value;
		}
		
		var water_release = 0;		
		if (document.getElementById('roofadvmats_mat1').checked == true)
		{
			water_release  = document.getElementById('roofadvmats_mat1').value;
		}
		
		var mansard_window = 0;		
		if (document.getElementById('roofadvmats_mat2').checked == true)
		{
			mansard_window  = document.getElementById('roofadvmats_mat2').value;
		}
		
		var snow_hold = 0;
		if (document.getElementById('roofadvmats_mat3').checked == true)
		{	
			snow_hold  = document.getElementById('roofadvmats_mat3').value;
		}
		

		var angle_factor = 0;
		if (document.getElementById('roofmaterials_edit').value < 29)
		{
			angle_factor = angle_factors[0];
		}
		else
		{
			angle_factor = angle_factors[1];
		}
		
		var middle_factor = 0;
		if (document.getElementById('roofadvmats_mat1').checked == true)
		{
			if (document.getElementById('roofadvmats_edit_1').value < 5)
			{
				middle_factor = middle_factors[0];
			}
			else
			{
				middle_factor = middle_factors[1];
			}
		}

		var windows_count = 0;
		if (document.getElementById('roofadvmats_mat2').checked == true)
		{
			windows_count = document.getElementById('roofadvmats_edit_2').value;
		}
       
        var result = 0;

		result = (((material_price*material_factor_1)+(down_layer*angle_factor)+(accesories*material_factor_2)+(solid_base*material_factor_3)+(lattice*material_factor_4)+(kontr_bus*material_factor_4)+(water_release*middle_factor*material_factor_5)+(snow_hold*material_factor_7)+(heat_holder*material_factor_8+vapour_isolate*material_factor_8+membran*material_factor_8))*roofType_edit.value)+mansard_window*windows_count*material_factor_6
		
		document.getElementById('common_price').innerHTML = 'Цена комплектации: <font color="#ff2222" size="+1">'+Math.round(result)+'</font> р.';
	   
        document.getElementById('pricepanel').innerHTML = 'Цена за 1 м<sup>2</sup>: <font color="#ff2222" size="+1">'+Math.round(result/roofType_edit.value)+'</font> р.';
        
        document.getElementById('pricepanel').innerHTML = 'Цена за 1 м<sup>2</sup>: <font color="#ff2222" size="+1">'+Math.round(result/roofType_edit.value)+'</font> р.';
        
    }
}
