// JavaScript Document
function show_hide_info(div_id)
{
	if(document.getElementById(div_id).style.display == 'none')
		document.getElementById(div_id).style.display = 'block';
	else
		document.getElementById(div_id).style.display = 'none';
}
function show_info(div_id)
{
	document.getElementById(div_id).style.display = 'block';
}
function hide_info(div_id)
{
	document.getElementById(div_id).style.display = 'none';
}

/* Проверка текстовых полей на ввод цифр */
function check_text(element)
{
	if (element.value.match(/\D/) || element.value == '') {
		element.value = 1;
	}
}

/*получение value для любого элемента типа radio button*/
function get_value(element)
{
	for (var i=0; i < element.length; i++)
	{
		if (element[i].checked)
			return element[i].value;	
	}
	return false;
}

function ke_b2w_address(form,num)
{
	//document.getElementById('ke_install_ip').value = document.getElementById('b2w_install_adress').value;
	
	for (Count = 0; Count < 3; Count++) 
	{
		if ((num==1)&&(form.b2w_install_adress[Count].checked))
			{
				form.ke_install_ip[Count].checked = true;
				form.ke_install[Count].checked = true;
			}
		if ((num==2)&&(form.ke_install_ip[Count].checked))
			{
				form.b2w_install_adress[Count].checked = true;
				form.ke_install[Count].checked = true;
			}
		if ((num==3)&&(form.ke_install[Count].checked))
			{
				form.b2w_install_adress[Count].checked = true;
				form.ke_install_ip[Count].checked = true;
			}
	}
}
function dopol(form)
{
	;
	
	if((form.b2w_type.value == 'USNO')||(form.b2w_type.value == 'businessman'))
		{
			document.getElementById('b2w_additional_version_formblock').style.display = 'none';
			//document.getElementById('b2w_additional_version_formblock').innerHTML = "none"
		}
		else
		{
			document.getElementById('b2w_additional_version_formblock').style.display = 'block';
			//document.getElementById('b2w_additional_version_formblock').innerHTML = form.b2w_type.value;
		}
}
/* расчет стоимости */
function calc(form)
{
	dopol(form);
	
	var price_soft = 0;
	var price_soft_b2w = 0;
	var price_install = 0;
	var price_install_b2w = 0;
	var price_install_error = '';
	var price_error = '';
	/* Телефон отдела продаж */
	var phone = '+7 (495) 660-2937';
	/* <Выбрана галка B2W> */
	if(form.b2w.checked)
	{

		/* <Для локальной версии> */
		if(get_value(form.version_type) == 'local')
		{
			/* <Указаны доп. лицензии> */
			if(form.b2w_additional_version.checked && (form.b2w_additional_version_number.value != '' || form.b2w_additional_version_number.value != 0))
			{
				price_soft_b2w = price_soft_b2w + price['b2w_type'][get_value(form.version_type)][form.b2w_type.value][get_value(form.licence_type)][get_value(form.licence_period)] + (price['b2w_type'][get_value(form.version_type)][form.b2w_type.value]['add']['12'] * form.b2w_additional_version_number.value);
			}
			else
			{
				price_soft_b2w = price_soft_b2w + price['b2w_type'][get_value(form.version_type)][form.b2w_type.value][get_value(form.licence_type)][get_value(form.licence_period)];
			}
		}
		/* <Для сетевой версии> */
		if(get_value(form.version_type) == 'net')
		{
			/* <Указаны доп. лицензии> */
			if(form.b2w_additional_version.checked && (form.b2w_additional_version_number.value != '' || form.b2w_additional_version_number.value != 0))
			{
				price_soft_b2w = price_soft_b2w + price['b2w_type'][get_value(form.version_type)][form.b2w_type.value][get_value(form.licence_type)][get_value(form.licence_period)][get_value(form.web_version_work_place)] + (price['b2w_type'][get_value(form.version_type)][form.b2w_type.value]['add']['12'][get_value(form.web_version_work_place)] * form.b2w_additional_version_number.value);
			}
			else
			{
				price_soft_b2w = price_soft_b2w + price['b2w_type'][get_value(form.version_type)][form.b2w_type.value][get_value(form.licence_type)][get_value(form.licence_period)][get_value(form.web_version_work_place)];
			}
		}

		/* <Скидка при покупке в интернет магазине> */
		if(form.type_buy.value == 'internet_shop')
		{
			price_soft_b2w = price_soft_b2w * 0.95;
		}
		/* <Офис продаж, заказ выезда инженера> */
		//if(form.type_buy.value == 'sales_office')
		//{
			/* <Для локальной версии> */
			if(get_value(form.version_type) == 'local')
			{
				if(form.b2w_install.checked)
				{
					if(get_value(form.b2w_install_adress) != 'region')
					{
						price_install_b2w = price_install_b2w + price['b2w_type']['local']['install'][get_value(form.b2w_install_adress)];
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
			/* <Для сетевой версии> */
			if(get_value(form.version_type) == 'net')
			{
				if(form.b2w_install.checked)
				{
					if(get_value(form.b2w_install_adress) != 'region')
					{
						price_install_b2w = price_install_b2w + price['b2w_type']['net']['install'][get_value(form.web_version_work_place)][get_value(form.b2w_install_adress)];
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
		//}
		
	}/* </Выбрана галка B2W> */

	/* <Выбрана галка Контур экстерн> */
	if(form.kontur_extern.checked)
	{
		/* Выбрано юридическое лицо */
		if(get_value(form.client) == 'company')
		{
			//alert('Юр. лицо');
			/* Юридическое лицо - основной абонент */
			if(get_value(form.company_subscriber) == 'first')
			{
				//alert('Основной');
				/* Юридическое лицо - основной абонент - тарифный план */
				//alert('Тариф: ' + form.ke_tariff.value);
				price_soft = price_soft + price['ke_type']['company'][form.ke_tariff.value]['first'];
				//alert(price_soft);
				/* Юридическое лицо - основной абонент - доп. раб. место */
				if(form.ke_additional_wp.checked)
				{
					/* Юридическое лицо - основной абонент - доп. раб. место кол-во */
					//alert('Доп. раб. места: ' + form.ke_additional_work_place_number.value);
					price_soft = price_soft + (price['ke_type']['additional']['work_place']['price'] * form.ke_additional_work_place_number.value);
					//alert(price_soft);

					if(form.ke_installation.checked)
					{
						if(get_value(form.ke_install) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['additional']['work_place']['install'] * form.ke_additional_work_place_number.value * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install) == 'out_mkad')
						{
							price_install = price_install + (price['ke_type']['additional']['work_place']['install'] * form.ke_additional_work_place_number.value * price['ke_type']['install']['normochas'] * 2);
						}
					}
				}
				/* Юридическое лицо - основной абонент - установка */
				if(form.ke_installation.checked)
				{
					//alert('Где ставить: ' + get_value(form.ke_install));
					if(get_value(form.ke_install) != 'region')
					{
						if(get_value(form.ke_install) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['company']['install']['first'] * price['ke_type']['install']['normochas']);
							//alert(price_install);
						}
						if(get_value(form.ke_install) == 'out_mkad')
						{
							price_install = price_install + ((price['ke_type']['company']['install']['first'] * price['ke_type']['install']['normochas']) * 2);
							//alert(price_install);
						}
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
			/* Юридическое лицо - дополнительный абонент */
			if(get_value(form.company_subscriber) == 'second')
			{
				//alert('Дополнительный');
				/* Юридическое лицо - основной абонент - тарифный план */
				//alert('Тариф: ' + form.ke_tariff.value);
				price_soft = price_soft + price['ke_type']['company'][form.ke_tariff.value]['second'];
				/* Юридическое лицо - основной абонент - доп. раб. место */
				if(form.ke_additional_wp.checked)
				{
					/* Юридическое лицо - основной абонент - доп. раб. место кол-во */
					//alert('Доп. раб. места: ' + form.ke_additional_work_place_number.value);
					price_soft = price_soft + (price['ke_type']['additional']['work_place']['price'] * form.ke_additional_work_place_number.value);
					//price_install = price_install + (price['ke_type']['additional']['work_place']['install'] * form.ke_additional_work_place_number.value * price['ke_type']['install']['normochas']);
				}
				/* Юридическое лицо - основной абонент - установка */
				if(form.ke_installation.checked)
				{
					//alert('Где ставить: ' + get_value(form.ke_install));
					if(get_value(form.ke_install) != 'region')
					{
						if(get_value(form.ke_install) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['company']['install']['second'] * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install) == 'out_mkad')
						{
							price_install = price_install + ((price['ke_type']['company']['install']['second'] * price['ke_type']['install']['normochas']) * 2);
						}
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
			/* Юридическое лицо - обслуживающая бухгалтерия*/
			if(get_value(form.company_subscriber) == 'buh')
			{
				//alert('Обсл. бух');
				/* Юридическое лицо - обслуживающая бухгалтерия - тарифный план */
				/*alert('Тариф: ' + form.ke_tariff_buh.value);*/
				/* Юридическое лицо - обслуживающая бухгалтерия - кол-во орг-ций */
				//alert('Орг-ций: ' + form.service_bookkeeping_number.value);
				price_soft = price_soft + price['ke_type']['buh'][form.service_bookkeeping_number.value][form.ke_tariff_buh.value];
				/* Юридическое лицо - обслуживающая бухгалтерия - Лицензии +5 */
				if(form.service_bookkeeping_additional_licence.checked)
				{
					//alert('Лицензия +5');
					price_soft = price_soft + (price['ke_type']['buh']['plus_5'][form.ke_tariff_buh.value] * form.service_bookkeeping_additional_licence_number.value);
				}
				/* Юридическое лицо - обслуживающая бухгалтерия - доп. раб. место */
				if(form.ke_additional_wp.checked)
				{
					//alert('Доп. раб. место');
					price_soft = price_soft + (price['ke_type']['additional']['work_place']['price'] * form.ke_additional_work_place_number.value);
					if(form.ke_installation.checked)
					{
						if(get_value(form.ke_install) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['buh']['work_place']['install'] * form.ke_additional_work_place_number.value * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install) == 'out_mkad')
						{
							price_install = price_install + (price['ke_type']['buh']['work_place']['install'] * form.ke_additional_work_place_number.value * price['ke_type']['install']['normochas'] * 2);
						}
					}
				}
				/* Юридическое лицо - обслуживающая бухгалтерия - установка */
				if(form.ke_installation.checked)
				{
					//alert('Где ставить: ' + get_value(form.ke_install));
					if(get_value(form.ke_install) != 'region')
					{
						if(get_value(form.ke_install) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['buh'][form.service_bookkeeping_number.value]['install'] * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install) == 'out_mkad')
						{
							price_install = price_install + ((price['ke_type']['buh'][form.service_bookkeeping_number.value]['install'] * price['ke_type']['install']['normochas']) * 2);
						}
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
		}
		/* Выбран индивидуальный предприниматель */
		if(get_value(form.client) == 'ip')
		{
			//alert('Индивидуальный');
			/* Индивидуальный предприниматель - основной */
/*			if(get_value(form.company_subscriber_ip) == 'first')
			{
	*/			//alert('Основной');
				//alert('Тариф: ' + form.ke_tariff_ip.value);
				price_soft = price_soft + price['ke_type']['ip'][form.ke_tariff_ip.value]['first'];
				/* Индивидуальный предприниматель - основной - установка */
				if(form.ke_installation_ip.checked)
				{
					//alert('Где ставить: ' + get_value(form.ke_install_ip));
					if(get_value(form.ke_install_ip) != 'region')
					{
						if(get_value(form.ke_install_ip) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['ip']['install']['first'] * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install_ip) == 'out_mkad')
						{
							price_install = price_install + ((price['ke_type']['ip']['install']['first'] * price['ke_type']['install']['normochas']) * 2);
						}
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
//		}
			/* Индивидуальный предприниматель - дополнительный */
	if(get_value(form.company_subscriber_ip) == 'second')
			{
				//alert('Дополнительный');
				//alert('Тариф: ' + form.ke_tariff_ip.value);
				price_soft = price_soft + price['ke_type']['ip'][form.ke_tariff_ip.value]['second'];
				/* Индивидуальный предприниматель - дополнительный - установка */
				if(form.ke_installation_ip.checked)
				{
					//alert('Где ставить: ' + get_value(form.ke_install_ip));
					if(get_value(form.ke_install_ip) != 'region')
					{
						if(get_value(form.ke_install_ip) == 'in_mkad')
						{
							price_install = price_install + (price['ke_type']['ip']['install']['second'] * price['ke_type']['install']['normochas']);
						}
						if(get_value(form.ke_install_ip) == 'out_mkad')
						{
							price_install = price_install + ((price['ke_type']['ip']['install']['second'] * price['ke_type']['install']['normochas']) * 2);
						}
					}
					else
					{
						price_install_error = 'Стоимость установки в Московской области уточняйте в отделе продаж по тел.:' + phone + '!';
					}
				}
			}
		}
	}
	
	/* Вывод результатов подсчета на страницу */
	/* Если не выбран ни один программный продукт, то поле результатов не показываем */
	if(form.b2w.checked || form.kontur_extern.checked)
	{
		/* Отображение блока с результатами */
		document.getElementById('calc_value').style.display = 'block';
		/* Отображение стоимости ПО */
		document.getElementById('soft_value').innerHTML = (price_soft + price_soft_b2w) + '&nbsp;руб.';
		/* Проверка ошибок при выборе установки ПО в области */
		if(price_install_error == '')
		{
			if(price_install != 0 || price_install_b2w != 0)
			{
				document.getElementById('install_value').innerHTML = 'от ' + (price_install + price_install_b2w) + '&nbsp;руб.';
			}
			else
			{
				document.getElementById('install_value').innerHTML = 'не выбрана';
			}
			document.getElementById('itogo_value').innerHTML = (price_install + price_soft + price_install_b2w + price_soft_b2w) + '&nbsp;руб.';
			document.getElementById('itogo').style.display = 'block';
		}
		else
		{
			document.getElementById('install_value').innerHTML = '<span style="color:#ff0000; font-weight:bold;">' + price_install_error + '</span>';
			document.getElementById('itogo').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('calc_value').style.display = 'none';
	}
}
