var isBackend = false;

function switchPanel(obj, panel)
{
	if (obj.checked)
	{
		$(panel).show();
	}
	else
	{
		$(panel).hide();
	}
}

function initThis()
{
	$$('#'+OldNewID+' input').each(function(el){ Event.observe(el, 'change', setOldNew); });
	$$('#'+TeacherID+' input').each(function(el){ Event.observe(el, 'change', setTeacher); });
	$$('#'+TypeServiceID+' input').each(function(el){ Event.observe(el, 'change', setTypeService); });
	$$('#'+ContractID+' input').each(function(el){ Event.observe(el, 'change', setContract); });
	$$('#'+PromoID+' input').each(function(el){ Event.observe(el, 'change', setPromo); });
	$$('#'+ServicesID).each(function(el){ Event.observe(el, 'change', setServices); });
	
	$$('#'+ContractID+' input')[1].checked = true;
	currentContractValue = 2;
	$$('#'+ContractID+' input')[0].disabled = true;
	$$('#'+ContractID+' input')[0].up().hide();
	
	$$('#'+STBAddonID+' input')[0].disabled = true;
	$$('#'+STBAddonID+' input')[1].disabled = true;
	$$('#'+STBAddonID+' input')[2].disabled = true;
	
	$$('#'+PromoID+' input')[0].disabled = true;
	$$('#'+PromoID+' input')[1].disabled = true;
	$$('#'+PromoID+' input')[2].disabled = true;
	$$('#'+PromoID+' input')[0].up().hide();
	$$('#'+PromoID+' input')[1].up().hide();
	$$('#'+PromoID+' input')[2].up().hide();
	//$$('#'+PromoID+' input')[4].disabled = false;
	//$$('#'+PromoID+' input')[4].up().show();
	
	filterServices();
}

function calculateThis()
{
	currentServicesValue = $(ServicesID).getValue();
	
	tmpDropDownMSG = dropDownMSG;
	
	var tmpPrice = 0;
	
	var priceMonth = 0;
	var priceDevices = 0;
	
	var basePrice = 0;
	var basePriceDesc = '';
	var contractPrice = 0;
	var teachersPrice = 0;
	var addonDeviceSavingsPrice = 0;
	var addonDevicesPrice = 0;
	var promoSavingsPrice = '';
	var bonusPointsMonths = 1;
	
	var bonusMonth = 'Бонус месец';
	var otherMonths = 0;
	var countMonths = 12;
	
	if(currentServicesValue > 0)
	{
		if(currentTeacherValue == 1)
		{
			if(currentContractValue==3)
			{
				if(currentTypeServiceValue==1)//internet
				{
					basePrice = internetServices[currentServicesValue].price_prepaid;
					basePriceDesc = internetServices[currentServicesValue].title;
					teachersPrice = internetServices[currentServicesValue].price_teachers;
					priceMonth = internetServices[currentServicesValue].price_teachers;
				}
				else
				{
					basePrice = packetServices[currentServicesValue].price_prepaid;
					basePriceDesc = packetServices[currentServicesValue].title+' с '+packetServices[currentServicesValue].shortdesc;
					teachersPrice = packetServices[currentServicesValue].price_teachers;
					priceMonth = packetServices[currentServicesValue].price_teachers;
				}
			}
			else
			{
				if(currentTypeServiceValue==1)//internet
				{
					basePrice = internetServices[currentServicesValue].price_prepaid;
					basePriceDesc = internetServices[currentServicesValue].title;
					contractPrice = currentContractValue==1?internetServices[currentServicesValue].price24:internetServices[currentServicesValue].price;
					priceMonth = currentContractValue==1?internetServices[currentServicesValue].price24:internetServices[currentServicesValue].price;
				}
				else
				{
					basePrice = currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price;
					basePriceDesc = packetServices[currentServicesValue].title+' с '+packetServices[currentServicesValue].shortdesc;
					teachersPrice = packetServices[currentServicesValue].price_teachers;
					priceMonth = packetServices[currentServicesValue].price_teachers;
				}
			}
			
			if(currentTypeServiceValue==2)//tv
			{
				if($$('#'+STBAddonID+' input')[0].checked)
				{
					priceMonth = currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(7);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else if($$('#'+STBAddonID+' input')[1].checked)
				{
					priceMonth = currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(14);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else if($$('#'+STBAddonID+' input')[2].checked)
				{
					priceMonth = currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(21);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else
				{
					priceMonth = packetServices[currentServicesValue].price_teachers;
					//priceMonth = currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price;
				}
			}
		}
		else if(currentContractValue==3)
		{
			if(currentTypeServiceValue==1)//internet
			{
				basePrice = priceMonth = internetServices[currentServicesValue].price_prepaid;
				basePriceDesc = internetServices[currentServicesValue].title;
			}
			else
			{
				basePrice = priceMonth = packetServices[currentServicesValue].price_prepaid;
				basePriceDesc = packetServices[currentServicesValue].title+' с '+packetServices[currentServicesValue].shortdesc;
			}
		}
		else
		{
			if(currentTypeServiceValue==1)//internet
			{
				basePrice = internetServices[currentServicesValue].price_prepaid;
				basePriceDesc = internetServices[currentServicesValue].title;
				contractPrice = currentContractValue==1?internetServices[currentServicesValue].price24:internetServices[currentServicesValue].price;
				priceMonth = currentContractValue==1?internetServices[currentServicesValue].price24:internetServices[currentServicesValue].price;
			}
			else
			{
				basePrice = currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price;
				basePriceDesc = packetServices[currentServicesValue].title+' с '+packetServices[currentServicesValue].shortdesc;
				
				if($$('#'+STBAddonID+' input')[0].checked)
				{
					priceMonth = packetServices[currentServicesValue].price_teachers>0&&currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(7);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else if($$('#'+STBAddonID+' input')[1].checked)
				{
					priceMonth = packetServices[currentServicesValue].price_teachers>0&&currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(14);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else if($$('#'+STBAddonID+' input')[2].checked)
				{
					priceMonth = packetServices[currentServicesValue].price_teachers>0&&currentTeacherValue==1?packetServices[currentServicesValue].price_teachers:(currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price);
					priceDevices = parseFloat(21);
					if(currentTeacherValue==1)
					{
						addonDeviceSavingsPrice = parseFloat(priceMonth) + parseFloat(priceDevices);
					}
					addonDevicesPrice = priceDevices;
				}
				else
				{
					priceMonth = currentContractValue==1?packetServices[currentServicesValue].price24:packetServices[currentServicesValue].price;
				}
			}
		}
		
		if(currentContractValue==3)
		{
			if(currentPromoValue==3)
			{
				promoSavingsPrice = '10=12';
				tmpDropDownMSG = tmpDropDownMSG.replace('%1', '10x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 12x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(10*priceMonth + 12*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', bonusMonth).replace('%8', bonusMonth).replace('%9', bonusMonth).replace('%10', bonusMonth).replace('%11', bonusMonth).replace('%12', bonusMonth);
				priceMonth = (10*priceMonth + 12*priceDevices)/12;
			}
			else if(currentPromoValue==1 || currentPromoValue==2)
			{
				if(currentPromoValue==1)
				{
					promoSavingsPrice = '1+1=3';
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', '2x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 3x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(2*priceMonth + 3*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
				}
				else
				{
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', '5x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 6x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(5*priceMonth + 6*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
					promoSavingsPrice = '5=6';
				}
				priceMonth = (11*priceMonth + 12*priceDevices)/12;
			}
			else
			{
				if(currentServicesValue==16 || currentServicesValue==13)
				{
					promoSavingsPrice = '2=2';
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', '2x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 2x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(2*priceMonth + 2*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
					priceMonth = (12*priceMonth + 12*priceDevices)/12;
				}
				else
				{
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', otherMonths).replace('%2', otherMonths).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
					priceMonth = (12*priceMonth + 12*priceDevices)/12;
				}
			}
		}
		else
		{
			/*if(currentPromoValue==4)
			{
				promoSavingsPrice = '80Mbps за 5лв/м.';
				priceMonth = internetServices[currentServicesValue].price_prepaid;
				contractPrice = 0;
				tmpDropDownMSG = tmpDropDownMSG.replace('%1', parseFloat(5).toFixed(2)+'лв.').replace('%2', parseFloat(5).toFixed(2)+'лв.').replace('%3', parseFloat(5).toFixed(2)+'лв.').replace('%4', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%5', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%6', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%7', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%8', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%9', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%10', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%11', parseFloat(priceMonth).toFixed(2)+'лв.').replace('%12', parseFloat(priceMonth).toFixed(2)+'лв.');
				priceMonth = (3*5 + 9*priceMonth + 12*priceDevices)/12;
			}
			else */
			if(currentPromoValue==3)
			{
				promoSavingsPrice = '10=12';
				otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
				if(currentTypeServiceValue==2 && (currentServicesValue==6 || currentServicesValue==17))
				{
					if(currentContractValue==1)
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '11x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 12x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(11*priceMonth + 12*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', bonusMonth).replace('%8', bonusMonth).replace('%9', bonusMonth).replace('%10', bonusMonth).replace('%11', bonusMonth).replace('%12', bonusMonth).replace('%13', otherMonths).replace('%14', otherMonths).replace('%15', otherMonths).replace('%16', otherMonths).replace('%17', otherMonths).replace('%18', otherMonths).replace('%19', otherMonths).replace('%20', otherMonths).replace('%21', otherMonths).replace('%22', otherMonths).replace('%23', otherMonths).replace('%24', otherMonths);
						if(currentServicesValue==6 || currentServicesValue==17)
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/24;
							tmpDropDownMSG = tmpDropDownMSG.replace('<tr><td>25-ти месец</td><td>%25</td></tr>', '');
							countMonths = 24;
						}
						else
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/25;
							countMonths = 25;
						}
					}
					else 
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '11x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 12x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(11*priceMonth + 12*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', bonusMonth).replace('%8', bonusMonth).replace('%9', bonusMonth).replace('%10', bonusMonth).replace('%11', bonusMonth).replace('%12', bonusMonth);
						priceMonth = (11*priceMonth + 12*priceDevices)/12;
					}
				}
				else
				{
					if(currentContractValue==1)
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '10x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 12x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(10*priceMonth + 12*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', bonusMonth).replace('%8', bonusMonth).replace('%9', bonusMonth).replace('%10', bonusMonth).replace('%11', bonusMonth).replace('%12', bonusMonth).replace('%13', otherMonths).replace('%14', otherMonths).replace('%15', otherMonths).replace('%16', otherMonths).replace('%17', otherMonths).replace('%18', otherMonths).replace('%19', otherMonths).replace('%20', otherMonths).replace('%21', otherMonths).replace('%22', otherMonths).replace('%23', otherMonths).replace('%24', otherMonths);
						priceMonth = (22*priceMonth + 24*priceDevices)/25;
						countMonths = 25;
					}
					else
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '10x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 12x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(10*priceMonth + 12*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', bonusMonth).replace('%8', bonusMonth).replace('%9', bonusMonth).replace('%10', bonusMonth).replace('%11', bonusMonth).replace('%12', bonusMonth);
						priceMonth = (10*priceMonth + 12*priceDevices)/12;
					}
				}
			}
			else if(currentPromoValue==1 || currentPromoValue==2)
			{
				if(currentPromoValue==1)
				{
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					if(currentContractValue==1)
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '2x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 3x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(2*priceMonth + 3*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths).replace('%13', otherMonths).replace('%14', otherMonths).replace('%15', otherMonths).replace('%16', otherMonths).replace('%17', otherMonths).replace('%18', otherMonths).replace('%19', otherMonths).replace('%20', otherMonths).replace('%21', otherMonths).replace('%22', otherMonths).replace('%23', otherMonths).replace('%24', otherMonths);
						if(currentServicesValue==6 || currentServicesValue==17)
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/24;
							tmpDropDownMSG = tmpDropDownMSG.replace('<tr><td>25-ти месец</td><td>%25</td></tr>', '');
							countMonths = 24;
						}
						else
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/25;
							countMonths = 25;
						}
					}
					else
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '2x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 3x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(2*priceMonth + 3*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
						priceMonth = (11*priceMonth + 12*priceDevices)/12;
					}
					promoSavingsPrice = '1+1=2';
				}
				else
				{
					otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
					if(currentContractValue==1)
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '5x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 6x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(5*priceMonth + 6*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths).replace('%13', otherMonths).replace('%14', otherMonths).replace('%15', otherMonths).replace('%16', otherMonths).replace('%17', otherMonths).replace('%18', otherMonths).replace('%19', otherMonths).replace('%20', otherMonths).replace('%21', otherMonths).replace('%22', otherMonths).replace('%23', otherMonths).replace('%24', otherMonths);
						if(currentServicesValue==6 || currentServicesValue==17)
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/24;
							tmpDropDownMSG = tmpDropDownMSG.replace('<tr><td>25-ти месец</td><td>%25</td></tr>', '');
							countMonths = 24;
						}
						else
						{
							priceMonth = (23*priceMonth + 24*priceDevices)/25;
							countMonths = 25;
						}
					}
					else
					{
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '5x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 6x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(5*priceMonth + 6*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', bonusMonth).replace('%4', bonusMonth).replace('%5', bonusMonth).replace('%6', bonusMonth).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
						priceMonth = (11*priceMonth + 12*priceDevices)/12;
					}
					promoSavingsPrice = '5=6';
				}
			}
			else
			{
				otherMonths = parseFloat(parseFloat(priceMonth) + parseFloat(priceDevices)).toFixed(2)+'лв.';
				if(currentContractValue==1)
				{
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', otherMonths).replace('%2', otherMonths).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths).replace('%13', otherMonths).replace('%14', otherMonths).replace('%15', otherMonths).replace('%16', otherMonths).replace('%17', otherMonths).replace('%18', otherMonths).replace('%19', otherMonths).replace('%20', otherMonths).replace('%21', otherMonths).replace('%22', otherMonths).replace('%23', otherMonths).replace('%24', otherMonths);
					if(currentServicesValue==6 || currentServicesValue==17)
					{
						priceMonth = (24*priceMonth + 24*priceDevices)/24;
						tmpDropDownMSG = tmpDropDownMSG.replace('<tr><td>25-ти месец</td><td>%25</td></tr>', '');
						countMonths = 24;
					}
					else
					{
						priceMonth = (24*priceMonth + 24*priceDevices)/25;
						countMonths = 25;
					}
				}
				else if(currentContractValue==2)
				{
					if(currentServicesValue==16 || currentServicesValue==13)
					{
						promoSavingsPrice = '2=2';
						countMonths = 12;
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', '2x'+parseFloat(priceMonth).toFixed(2)+'лв.'+(priceDevices>0?' + 2x'+parseFloat(priceDevices).toFixed(2)+'лв.':'')+' = '+parseFloat(2*priceMonth + 2*priceDevices).toFixed(2)+'лв.').replace('%2', bonusMonth).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
						priceMonth = (12*priceMonth + 12*priceDevices)/12;
					}
					else
					{
						priceMonth = (12*priceMonth + 12*priceDevices)/12;
						countMonths = 12;
						tmpDropDownMSG = tmpDropDownMSG.replace('%1', otherMonths).replace('%2', otherMonths).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
					}
				}
				else
				{
					tmpDropDownMSG = tmpDropDownMSG.replace('%1', otherMonths).replace('%2', otherMonths).replace('%3', otherMonths).replace('%4', otherMonths).replace('%5', otherMonths).replace('%6', otherMonths).replace('%7', otherMonths).replace('%8', otherMonths).replace('%9', otherMonths).replace('%10', otherMonths).replace('%11', otherMonths).replace('%12', otherMonths);
				}
			}
		}
		
		if(currentContractValue==3 || currentContractValue==2)
		{
			for(i=13; i<=25; i++)
			{
				tmpDropDownMSG = tmpDropDownMSG.replace('<tr><td>'+i+'-ти месец</td><td>%'+i+'</td></tr>', '');
			}
		}
		else
		{
			tmpDropDownMSG = tmpDropDownMSG.replace('%25', bonusMonth);
		}
		
		$(Result1ID).hide();
		$(Result2ID).hide();
		$(Result3ID).hide();
		$(Result4ID).hide();
		$(Result5ID).hide();
		$(Result6ID).hide();
		
		if(basePrice > 0)
		{
			$(Result1ID).show();
			$(Result1ID).update(calculateResult1MSG.replace('%1', basePriceDesc).replace('%2', parseFloat(basePrice).toFixed(2)));
		}
		
		if(teachersPrice > 0 && (addonDeviceSavingsPrice <= 0 || (addonDeviceSavingsPrice - addonDevicesPrice) != teachersPrice))
		{
			$(Result2ID).show();
			$(Result2ID).update(calculateResult2MSG.replace('%2', parseFloat(teachersPrice).toFixed(2)));
		}
		
		if(contractPrice > 0)
		{
			$(Result3ID).show();
			$(Result3ID).update(calculateResult3MSG.replace('%2', parseFloat(contractPrice).toFixed(2)));
		}
		
		if(addonDeviceSavingsPrice > 0)
		{
			$(Result4ID).show();
			$(Result4ID).update(calculateResult4MSG.replace('%2', parseFloat(addonDeviceSavingsPrice).toFixed(2)));
		}
		
		if(addonDevicesPrice > 0)
		{
			$(Result5ID).show();
			$(Result5ID).update(calculateResult5MSG.replace('%1', addonDevicesPrice/7).replace('%2',parseFloat(Number(addonDevicesPrice)+Number(basePrice)).toFixed(2)));
		}
		
		if(promoSavingsPrice!='')
		{
			$(Result6ID).show();
			$(Result6ID).update(calculateResult6MSG.replace('%2', promoSavingsPrice));
		}
		
		if(bonusPointsMonths > 0)
		{
			$(Result7ID).show();
			$(Result7ID).update(calculateResult7MSG);
		}
		
		$(ResultID).show();
		$(DropDownBtnID).show();
		$(DropDownID).hide();
		$(ResultID).update(calculateResultMSG.replace('%2', parseFloat(priceMonth).toFixed(2)).replace('%1', countMonths));
		
		$(DropDownID).update(tmpDropDownMSG.replace('%26', parseFloat(priceMonth).toFixed(2)));
	}
	else
	{
		$(Result1ID).hide();
		$(Result2ID).hide();
		$(Result3ID).hide();
		$(Result4ID).hide();
		$(Result5ID).hide();
		$(Result6ID).hide();
		$(Result7ID).hide();
		$(DropDownBtnID).hide();
		$(DropDownID).hide();
		$(ResultID).show();
		$(ResultID).update(noResultMSG);
	}
}

function setOldNew()
{
	if($$('#'+OldNewID+' input')[0].checked && currentOldNewValue==0)
	{
		currentOldNewValue = 1;
		
		filterPromos();
	}
	else if($$('#'+OldNewID+' input')[1].checked && currentOldNewValue==1)
	{
		currentOldNewValue = 0;
		
		filterPromos();
	}
}

function setTeacher()
{
	if($$('#'+TeacherID+' input')[0].checked && currentTeacherValue==1)
	{
		currentTeacherValue = 0;
		setTypeService();
		filterServices();
	}
	else if($$('#'+TeacherID+' input')[1].checked && currentTeacherValue==0)
	{
		currentTeacherValue = 1;
		setTypeService();
		filterServices();
	}
}

function setTypeService()
{
	if(currentTeacherValue==1)
	{
		currentTypeServiceValue = 2;
		$$('#'+TypeServiceID+' input')[0].checked = true;
		$$('#'+TypeServiceID+' input')[1].disabled = true;
	}
	else
	{
		$$('#'+TypeServiceID+' input')[1].disabled = false;
	}
	
	if($$('#'+TypeServiceID+' input')[0].checked && currentTypeServiceValue==2)
	{
		currentTypeServiceValue = 1;
		
		if(currentContractValue==1)
		{
			$$('#'+ContractID+' input')[1].checked = true;
		}
		$$('#'+ContractID+' input')[0].disabled = true;
		$$('#'+ContractID+' input')[0].up().hide();
		$$('#'+ContractID+' input')[2].disabled = false;
		setContract();
		
		if(currentOldNewValue == 0)
		{
			$$('#'+PromoID+' input')[0].disabled = true;
			$$('#'+PromoID+' input')[0].up().hide();
			if($$('#'+PromoID+' input')[0].checked)
			{
				$$('#'+PromoID+' input')[3].checked = true
				currentPromoValue = 0
			}
		}
		
		$$('#'+STBAddonID+' input')[3].checked = true;
		$$('#'+STBAddonID+' input')[0].disabled = true;
		$$('#'+STBAddonID+' input')[1].disabled = true;
		$$('#'+STBAddonID+' input')[2].disabled = true;
		currentSTBAddonValue = 0;
		
		$('stb_question').hide();
		
		filterServices();
		filterPromos();
	}
	else if($$('#'+TypeServiceID+' input')[1].checked && currentTypeServiceValue==1)
	{
		currentTypeServiceValue = 2;
		$$('#'+ContractID+' input')[2].disabled = true;
		$$('#'+ContractID+' input')[0].disabled = false;
		$$('#'+ContractID+' input')[0].up().show();
		if($$('#'+ContractID+' input')[2].checked)
		{
			$$('#'+ContractID+' input')[0].checked = true
			currentContractValue = 1;
		}
		
		$$('#'+STBAddonID+' input')[0].disabled = false;
		$$('#'+STBAddonID+' input')[1].disabled = false;
		$$('#'+STBAddonID+' input')[2].disabled = false;
		
		$('promo_question').show();
		
		$('stb_question').show();
		
		filterServices();
		filterPromos();
	}
}

function setContract()
{
	if($$('#'+ContractID+' input')[0].checked && currentContractValue!=1)
	{
		currentContractValue = 1;
		
		filterServices();
		filterPromos();
	}
	if($$('#'+ContractID+' input')[1].checked && currentContractValue!=2)
	{
		currentContractValue = 2;
		
		filterServices();
		filterPromos();
	}
	else if($$('#'+ContractID+' input')[2].checked && currentContractValue!=3)
	{
		currentContractValue = 3;
		
		filterServices();
		filterPromos();
		$('promo_question').show();
	}
}

function setPromo()
{
	if($$('#'+PromoID+' input')[3].checked && currentPromoValue!=0)
	{
		currentPromoValue = 0;
	}
	else if($$('#'+PromoID+' input')[0].checked && currentPromoValue!=1)
	{
		currentPromoValue = 1;
	}
	else if($$('#'+PromoID+' input')[1].checked && currentPromoValue!=2)
	{
		currentPromoValue = 2;
	}
	else if($$('#'+PromoID+' input')[2].checked && currentPromoValue!=3)
	{
		currentPromoValue = 3;
	}
	/*else if($$('#'+PromoID+' input')[4].checked && currentPromoValue!=4)
	{
		currentPromoValue = 4;
	}*/
}

function setServices()
{
	currentServicesValue = $(ServicesID).getValue();
	filterPromos();
}

function filterPromos()
{
	if(currentTypeServiceValue==1 && (currentServicesValue==16 || currentContractValue!=3))
	{
		if($$('#'+PromoID+' input')[0].checked || $$('#'+PromoID+' input')[1].checked || $$('#'+PromoID+' input')[2].checked)
		{
			$$('#'+PromoID+' input')[0].checked = false;
			$$('#'+PromoID+' input')[1].checked = false;
			$$('#'+PromoID+' input')[2].checked = false;
			$$('#'+PromoID+' input')[3].checked = true;
			currentPromoValue = 0;
		}
		$$('#'+PromoID+' input')[0].disabled = true;
		$$('#'+PromoID+' input')[0].up().hide();
		$$('#'+PromoID+' input')[1].disabled = true;
		$$('#'+PromoID+' input')[1].up().hide();
		$$('#'+PromoID+' input')[2].disabled = true;
		$$('#'+PromoID+' input')[2].up().hide();
	}
	else if(currentTypeServiceValue==1)
	{
		$$('#'+PromoID+' input')[0].disabled = false;
		$$('#'+PromoID+' input')[0].up().show();
		$$('#'+PromoID+' input')[1].disabled = false;
		$$('#'+PromoID+' input')[1].up().show();
		$$('#'+PromoID+' input')[2].disabled = false;
		$$('#'+PromoID+' input')[2].up().show();
		
		if(currentOldNewValue == 0)
		{
			if($$('#'+PromoID+' input')[0].checked)
			{
				$$('#'+PromoID+' input')[3].checked = true;
				currentPromoValue = 0;
			} 
			$$('#'+PromoID+' input')[0].disabled = true;
			$$('#'+PromoID+' input')[0].up().hide();
		}
	}
	else if(currentTypeServiceValue==2 && (currentServicesValue==6 || currentServicesValue==17))
	{
		if($$('#'+PromoID+' input')[0].checked || $$('#'+PromoID+' input')[1].checked)
		{
			$$('#'+PromoID+' input')[0].checked = false;
			$$('#'+PromoID+' input')[1].checked = false;
			$$('#'+PromoID+' input')[3].checked = true;
			currentPromoValue = 0;
		}
		$$('#'+PromoID+' input')[0].disabled = true;
		$$('#'+PromoID+' input')[0].up().hide();
		$$('#'+PromoID+' input')[1].disabled = true;
		$$('#'+PromoID+' input')[1].up().hide();
		$$('#'+PromoID+' input')[2].disabled = false;
		$$('#'+PromoID+' input')[2].up().show();
	}
	else if(currentTypeServiceValue==2)
	{
		$$('#'+PromoID+' input')[0].disabled = false;
		$$('#'+PromoID+' input')[0].up().show();
		$$('#'+PromoID+' input')[1].disabled = false;
		$$('#'+PromoID+' input')[1].up().show();
		$$('#'+PromoID+' input')[2].disabled = false;
		$$('#'+PromoID+' input')[2].up().show();
	}
}

function filterServices()
{
	var dataServices = {};
	dataServices[0] = {
		'id': '0',
		'title': '-',
		'price': '0',
		'price_prepaid': '0',
		'price_teachers': '0'
	};
	var item;
	
	if(currentTypeServiceValue==1)
	{
		for(item in internetServices)
		{
			if(
				(currentTeacherValue==1 && currentContractValue==3 && internetServices[item].price_teachers == 0)
				||
				(currentContractValue!=3 && internetServices[item].price_prepaid == 0)
			)
			{
				
			}
			else
			{
				dataServices[internetServices[item].id] = internetServices[item];
			}
		}
	}
	else
	{
		for(item in packetServices)
		{
			if(
				(currentTeacherValue==1 && packetServices[item].price_teachers == 0)
				||
				(currentContractValue==3 && packetServices[item].price_prepaid == 0)
			)
			{
				
			}
			else
			{
				dataServices[packetServices[item].id] = packetServices[item];
			}
		}
	}
	
	var txt = '';
	for(item in dataServices)
	{
		txt += "<option value='"+dataServices[item].id+"'>"+dataServices[item].title+"</option>";
	}
	$(ServicesID).update('');
	$(ServicesID).update(txt);
}
