/*
		Калькулятор рассчета стоимости пластикового окна
		версия 0.2.0a от 12.05.2010

		(c) SiteLeader, 2005-2010 || http://www.siteleader.ru/
		$Id: feba.calc.js 10 2010-05-12 16:23:52Z Coolmen $
*/


/*
	Типизация окон/дверей
		0 - глухое окно;
		1 - с поворотной створкой;
		2 - с откидной створкой;
		3 - с поворотно-откидной створкой;
		4 - дверь;
		
		frame	- рама;
		slot	- створка;
*/


function feba_calc( type, e, d ) {
	
	//
	//
	//	in:
	//		t - тип окна (см. типизацию);
	//		e - елемент, на котрый вешается;
	//		d - хэш данных;
	//
	this.init = function(t,e,d ) {
		this.maxSlot = 3;										// максимальное кол створок

		this.slotType = t;										// строка типа окна
		this._slotType = t.split('.');							// массива типов створок
		
		this._previewSlotWidth = new Array();					// массив input ширин створок
		this._previewSlotHeight = null;							// input высоты окна

		this.previewWin = false;								// флаг отрисовки окна

		this.calcTemplate = document.getElementById('feba-calc-template').innerHTML;
		document.getElementById('feba-calc-template').innerHTML;

		this.previewBox = document.getElementById(e);			// куда показывать
		this.previewBox.innerHTML = this.calcTemplate;

		document.getElementById('calc_win_type').value = t;		// тип окна для серевера
		
		this.pr = document.getElementById('calc_pr');			// блок производителей		
		this.sp = document.getElementById('calc_sp');			// блок стеклопакетов
		this.pd = document.getElementById('calc_pd');			// блок подоконников
		this.otl = document.getElementById('calc_otl');			// блок отливов
		this.otk = document.getElementById('calc_otk');			// блок откосов
		this.ms = document.getElementById('calc_ms');			// блок москитной сетки
		this.fk = document.getElementById('calc_fk');			// блок фиксаторов
		this.mn = document.getElementById('calc_mn');			// блок фиксаторов

		this.win_amount = document.getElementById('calc_win_amount');	// блок колличества

		this.priceBox = document.getElementById('calc_price_box');	// блок для отображения цены
		this.reductionBox = document.getElementById('calc_reduction_box');	// блок для отображения скидки

		if ( d ) this.dataHash = d;								// данные

		// Рисую интерфейс

		// Производители
		var check = 1;
		for ( k in d ) {
			// Дефолтовый производитель 
			this._add_radiobutton( this.pr, k, 'pr', k, k=='Brusbox' ? true : false );
			check = 0;
		}
		
// this._get_radio_value('calc_sp') == 2
//( this._get_radio_value('calc_sp') == 2 ? ' !' : ' !' )

		// Стеклопакеты
		check = 1;
		var pr = this._get_radio_value('pr');

		this._create_controls( d[pr] );

	},		// end of method feda_calc.init()


	this._create_controls = function( d ) {
		
		var msg = '', check, k, k1;
		
		for ( k in d ) {
			if ( k != 'price' && k != 'add' ) {
				msg += k+"(";
				check = 1;
				
				if ( d[k].control == 'select' ) {
					// Контейнер
					var c = document.createElement('div');
					c.className = "feba-calc-select";
					var s = document.createElement('select');
					var id = "l_"+k+"_"+name;
					s.setAttribute("name", "calc_"+k);
					s.setAttribute("id", id);

					for ( k1 in d[k] ) {
						if ( k1 != 'control' )
							this._add_option(s, k1, d[k][k1]);
					}

					// Подсаживаю в документ
					c.appendChild(s);
					this[k].appendChild(c);

					// Делаю выбранным, если надо
//					if ( check ) i.setAttribute("checked", true);
		
					// Вешаю событие
					s.calc = this;
					s.onclick = function(){this.calc.preview(); };
				}
				else if ( d[k].control == 'checkbox' ) {
					for ( k1 in d[k] ) {
						if ( k1 != 'control' )
							this._add_checkbox( this[k], k1, "calc_"+k, d[k][k1], check );
						check=0;
					}				
				}
				else {
					for ( k1 in d[k] ) {
						msg += k1+",";
						this._add_radiobutton( this[k], k1, "calc_"+k, d[k][k1], check );
						check=0;
					}
				}

				msg += "), ";
			}
		}
//		alert ( msg );
		
	},

	this._add_checkbox = function(el, val, name, lab, check) {
		
		// Контейнер
		var s = document.createElement('div');
		s.className = "feba-calc-radiobutton";

		var i = document.createElement('input');
		var id = "l_"+val+"_"+name;
		i.setAttribute("type", "checkbox");
		i.setAttribute("name", name+"_"+val );
		i.setAttribute("id", id);
		i.setAttribute("value", val);

		// Метка
		var l = document.createElement('label');
		l.setAttribute("htmlFor", id);
		l.setAttribute("for", id);							// персонально для FireFox
		l.appendChild(document.createTextNode(lab));

		// Подсаживаю в документ
		s.appendChild(i);
		s.appendChild(l);
		el.appendChild(s);

		// Вешаю событие
		i.calc = this;
		i.onclick = function(){this.calc.preview(); };

	},

	this._add_option = function(el, val, txt) {
		
			var o = document.createElement('option');
			o.setAttribute("value", val);
			o.appendChild(document.createTextNode(txt));
			el.appendChild(o);		
	},


	/*
		Делаем радиобатон
	
		in:	e - нода, к которой прибиваем радиобатон;
			v - radiobutton.value;
			n - radiobutton.name;
			l - текст лабела;
			c - checked ? true | false;
	*/
	this._add_radiobutton = function(el, val, name, lab, check) {

//		alert( el + ", " + name );	
	
		// Контейнер
		var s = document.createElement('div');
		s.className = "feba-calc-radiobutton";

		var i = null;
		try {
			// Для IE, непонимающего input.name
			i = document.createElement('<input name="'+name+'">');
			// Для опер&нетскейпов
//			if ( !i || navigator.appName != "Microsoft Internet Explorer" ) i = document.createElement('input');
		}
		catch (e) {	}
		// Для опер&нетскейпов
		if ( !i || navigator.appName != "Microsoft Internet Explorer" ) i = document.createElement('input');
		var id = "l_"+val+"_"+name;
		i.setAttribute("type", "radio");
		i.setAttribute("name", name);
		i.setAttribute("id", id);
		i.setAttribute("value", val);

		// Метка
		var l = document.createElement('label');
		l.setAttribute("htmlFor", id);
		l.setAttribute("for", id);							// персонально для FireFox
		l.appendChild(document.createTextNode(lab));

		// Подсаживаю в документ
		s.appendChild(i);
		s.appendChild(l);
		el.appendChild(s);

		// Делаю выбранным, если надо
		if ( check ) i.setAttribute("checked", true);
		
		// Вешаю событие
		i.calc = this;
		i.onclick = function(){this.calc.preview(); };

	},		// end of method _add_radiobutton();


	/*
		Рисуем окошко		
	*/
	this.preview = function() {
		
		var type, st, slot_type, clot_count;

		slot_type = ( this._slotType.length == 1 ) ? new Array('l','l','l') : new Array('r','l','l');
		slot_count = this._slotType.length;

		// Размеры в название профилей
		var check = this._get_radio_value('pr');
		this.pr.innerHTML = '';
		for ( k in this.dataHash ) {
			this._add_radiobutton( this.pr, k, 'pr', k + ( this._get_radio_value('calc_sp') == 2 ?  this.dataHash[k].add : '' ),  k==check ? true : false );
		}

		// Делаю таблицу, если она еще не создана
		if ( !this.previewWin ) {
			// Рисую все створки
			for ( var c in this._slotType ) {

				type = this._slotType[c];
				st = slot_type[c];

				// Верх рамы
				setElement( 'top-frame-'+c, c == 0 ? 'preview-frame-left-top' : 'preview-frame-center-top' );
				setElement( 'top-frame-'+c+'a', 'preview-frame-top' );
				// Створки
				setElement( 'top-slot-'+c, c == 0 ? 'preview-frame-left' : 'preview-frame-center' );
				setElement( 'top-slot-'+c+'a', 'preview-slot' );
				// Типизация створок
				document.getElementById('type-'+c).src = '/feba.calc/type.'+this._slotType[c]+'.'+st+'.gif';

				// Ручки
				if ( slot_count == 1 && type != 0 ) {
					document.getElementById('slot-knob-0').src = '/feba.calc/win.knob.gif';
					// Прячу общую ширину окна
					setElement( 'all_width', 'hidden' );
				}
				else if ( c == 1 ){
					if ( this._slotType[0] != 0 && type != 0 ) {
						document.getElementById('slot-knob-1').src = '/feba.calc/win.knob.2.gif';
					}
					else if ( this._slotType[0] != 0 && type == 0 ) {
						document.getElementById('slot-knob-1').src = '/feba.calc/win.knob.gif';
					}
					else if ( this._slotType[0] == 0 && type != 0 ) {
						document.getElementById('slot-knob-1').src = '/feba.calc/win.knob.1.gif';
					}
					document.getElementById('slot-knob-0').src = '/feba.calc/spacer.gif';
				}
				else if ( c == 2 ){
					if ( type != 0 ) {
						document.getElementById('slot-knob-2').src = '/feba.calc/win.knob.1.gif';
					}
					else {
						document.getElementById('slot-knob-2').src = '/feba.calc/spacer.gif';
					}
				}
				else {
					document.getElementById('slot-knob-'+c).src = '/feba.calc/spacer.gif';					
				}

				// Дверь
				if ( type == 4 ) {
					// Нижняя часть рамы
					setElement( 'center-frame-'+c, c == 0 ? 'preview-door-frame-left-center' : 'preview-door-frame-center-center' );
					setElement( 'center-frame-'+c+"a", 'preview-door-frame-center' );
					setElement( 'bottom-slot-'+c, c == 0 ? 'preview-door-slot-left' : 'preview-door-slot-center' );
					setElement( 'bottom-slot-'+c+"a", 'preview-door-slot-center' );
					setElement( 'bottom-frame-'+c, c == 0 ? 'preview-door-frame-left-bottom' : 'preview-door-slot-center' );
					setElement( 'bottom-frame-'+c+"a", 'preview-door-frame-bottom' );
					document.getElementById('type-'+c).src = '/feba.calc/spacer.gif';			
				}
				// Окна
				else {
					// Нижняя часть рамы
					setElement( 'center-frame-'+c, c == 0 ? 'preview-frame-left-bottom' : 'preview-frame-center-bottom' );
					setElement( 'center-frame-'+c+"a", 'preview-frame-bottom' );
					setElement( 'bottom-slot-'+c, 'hidden' );
					setElement( 'bottom-slot-'+c+"a", 'hidden' );
					setElement( 'bottom-frame-'+c, 'hidden' );
					setElement( 'bottom-frame-'+c+"a", 'hidden' );
				}
				// Инпуты ширины строк
				setElement( 'input-width-'+c, c == 0 ? 'preview-slot-left-input' : 'preview-slot-center-input ' );
				setElement( 'input-width-'+c+'a', 'preview-slot-input' );
			}
			c++;
			// Закрываю верх рамы
			setElement( 'top-frame-'+c, 'preview-frame-right-top' );
			setElement( 'top-slot-'+c, 'preview-frame-right' );
			
			if ( type == 4 ) {
				setElement( 'center-frame-'+c, 'preview-door-frame-right-center' );			
				setElement( 'bottom-slot-'+c, 'preview-door-slot-right' );			
				setElement( 'bottom-frame-'+c, 'preview-door-frame-right-bottom' );
				document.getElementById('frame-height').value = 2100;
			}
			else {
				setElement( 'center-frame-'+c, 'preview-frame-right-bottom' );
			}
			
			// Закрываю инпуты ширин строк
			setElement( 'input-width-'+c, 'preview-slot-right-input' );

			// Вытягиваю ширину *ширины рамы*
			document.getElementById('frame-width-1').colSpan = (c*2)-1;
			// Вытягиваю высоту *высоты рамы*
			document.getElementById('frame-height-input').rowSpan = 1;
			setElement( "frame-height-2", "frame-height-bottom" );
			// Убиваю ручки для дверей
			if ( type == 4 ) {
				setElement( 'slot-knob-0', 'hidden' );
				setElement( 'slot-knob-1', 'hidden' );
				setElement( 'slot-knob-2', 'hidden' );

				document.getElementById('frame-height-input').rowSpan = 3;
				setElement( "frame-height-4", "frame-height-bottom" );

			}
			// Убираю лишнии вертикальные размеры
			else {
				setElement( 'door-type', 'hidden' );				
				setElement( 'door-1', 'hidden' );
				setElement( 'door-2', 'hidden' );
			}

			var f=false;

			// Прячу незаюзанные блоки
			for ( c; c <= this.maxSlot; c++ ) {
				if ( f ) {
					setElement( 'top-frame-'+c, 'hidden' );
					setElement( 'top-slot-'+c, 'hidden' );
					setElement( 'center-frame-'+c, 'hidden' );
					setElement( 'input-width-'+c, 'hidden' );
					setElement( 'bottom-slot-'+c, 'hidden' );
					setElement( 'bottom-frame-'+c, 'hidden' );
				}
				if ( c != 3 ) {
					// Верх рамы
					setElement( 'top-frame-'+c+'a', 'hidden' );
					// Створки
					setElement( 'top-slot-'+c+'a', 'hidden' );
					// Ручки
					setElement( 'slot-knob-'+c, 'hidden' );
					// Нижняя часть рамы
					setElement( 'center-frame-'+c+'a', 'hidden' );
					// Высота вертикального размера
					setElement( 'input-width-'+c+'a', 'hidden' );
				
					setElement( 'bottom-slot-'+c+"a", 'hidden' );
								
					setElement( 'bottom-frame-'+c+"a", 'hidden' );
				}
				f=true;
			}
			
	        // Получаю input ширин створок
			for ( c in this._slotType ) {
				this._previewSlotWidth[c] = document.getElementById('slot-'+c+'-width');
				this._previewSlotWidth[c].calc = this;
	        }
	        document.getElementById('frame-height').calc = this;

			// Ставлю дефолтовые ширины створок
			if ( this._slotType.length == 2 ) {
				this._previewSlotWidth[0].value = 500;
				this._previewSlotWidth[1].value = 950;
			}
			else if ( this._slotType.length == 3 ) {
				this._previewSlotWidth[0].value = 500;
				this._previewSlotWidth[1].value = 500;
				this._previewSlotWidth[2].value = 760;				
			}
			
			this.previewWin = true;
		}

		var sum = 0;

		// Resize
		for ( c in this._slotType ) {

			type = this._slotType[c]
			
			w = this._previewSlotWidth[c].value;
			if (window.RegExp ) {
				if ( !w.match( /^\d*$/ ) ) {
					alert('Введите размеры в миллиметрах использаю цифры');
					this._previewSlotWidth[c].value = 500;
					return;
				}
			}

			// !!! HACK !!!
			// для горизонтальных размеров створок
			if ( this._previewSlotWidth[c].value != 0 ) {
				document.getElementById('top-slot-'+c+'a').style.width = ( this._previewSlotWidth[c].value / 10 )+ 'px';
				document.getElementById('door-type').style.width = ( this._previewSlotWidth[c].value / 10 + 5)+ 'px';
				sum += parseInt(this._previewSlotWidth[c].value);
			}
		}
		
		// !!! HACK !!!
		// для вертикальных размеров створок
		if ( document.getElementById('frame-height').value != 0 ) {
			if ( type == 4 ) {
				document.getElementById('top-slot-0a').style.height = ( document.getElementById('frame-height').value / 30 * 2 )+ 'px';
				document.getElementById('bottom-slot-0a').style.height = ( document.getElementById('frame-height').value / 30 )+ 'px';
				document.getElementById('door-type').style.height = ( document.getElementById('frame-height').value / 10 + 21 )+ 'px';
			}
			else {
				document.getElementById('top-slot-0a').style.height = ( document.getElementById('frame-height').value / 10 )+ 'px';
				document.getElementById('top-slot-1a').style.height = ( document.getElementById('frame-height').value / 10 )+ 'px';
				document.getElementById('top-slot-2a').style.height = ( document.getElementById('frame-height').value / 10 )+ 'px';
			}
//			sum += parseInt(this._previewSlotWidth[c].value);
		}
		
		// Выставляю общий размер рамы
		document.getElementById('frame-width').value = sum;

		function setElement( e, c ) {
			var el = document.getElementById(e);			
			el.className = c;
		
		}
	
		this.calculate();
	
	},

	//
	//	Считаемся
	//
	this.calculate = function() {

		var slots = new Array();
		var w=0, r=0, h=0, t=0, c=0, tw=0, price, tp = 0, reduction = 0;

		// Производитель
		var pr = this._get_radio_value('pr');
		// Высота створок
		h = parseInt(document.getElementById('frame-height').value);
		
		var type;

		// Ширины створок
		for ( c in this._slotType ) {
			t = this._previewSlotWidth[c].value;
			w = parseInt(t);
			slots[c] = w;
			tw += w;
			price = 0;

			// Для створки 0-го типа (глухая)
			if ( this._slotType[c] == 0 ) {

				// Профиля рамы
				price += Math.ceil( this.dataHash[pr].price.profil_frame * ( ( h + w ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Шпатик рамы
				price += Math.ceil( this.dataHash[pr].price.shpatik_frame * ( ( h + w - 192 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Армирование рамы
				price += Math.ceil( this.dataHash[pr].price.armirov_frame * ( ( h + w - 180 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Уплотнители под стеклопакет
				price += Math.ceil( this.dataHash[pr].price.uplotn_sp * ( (  h + w - 192 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Прокладки под стеклопакет (4)
				price += Math.ceil( 4 * this.dataHash[pr].price.podkladka_sp2 * 100 ) / 100;
				// Заглушки (2)
				price += Math.ceil( this.dataHash[pr].price.zaglushka * 2 * 1.1 * 100 ) / 100;
				// Шурупы для армирования (8)
				price += Math.ceil( this.dataHash[pr].price.armirov_shurup * 8 * 1.1 * 100 ) / 100;

				// Стеклопакет
				price +=  Math.ceil( this.dataHash[pr].price.sp[1] * ( ( h-118 ) * ( w-118 ) / 1000000 ) * 100 ) / 100;

				price = Math.ceil(price * 2);
				
				if ( this._get_radio_value('calc_sp') == 2 ) {
					price += Math.ceil( this.dataHash[pr].price.sp[2] * ( ( h-118 ) * ( w-118 ) / 1000000 ) * 100 ) / 100;
				}
			}
			// Для 1-го типа створки (поворотной)
			else if ( this._slotType[c] == 1 ) {
				
				// Профиля рамы
				price += Math.ceil( this.dataHash[pr].price.profil_frame * ( ( h + w ) * 2 / 1000 ) * 1.1* 100 ) / 100;
				// Профиль створки ( 136 = ( h - 68 + w - 68 ) -- размеры, на которые створка меньше рамы)
				price += Math.ceil( this.dataHash[pr].price.profil_slot * ( ( h + w - 136) * 2 / 1000 ) * 1.1* 100 ) / 100;
				// Шпатик для створки
				price += Math.ceil( this.dataHash[pr].price.shpatik_slot * ( ( h + w - 136 - 224 ) * 2 / 1000 ) * 1.1* 100 ) / 100;

				// Армирование рамы
				price += Math.ceil( this.dataHash[pr].price.armirov_frame * ( ( h + w - 180 ) * 2 / 1000 ) * 1.1* 100 ) / 100;
				// Армирование створки
				price += Math.ceil( this.dataHash[pr].price.armirov_slot * ( ( h + w - 136 - 230 ) * 2 / 1000 ) * 1.1* 100 ) / 100;

				// Уплотнители внешние
				price += Math.ceil( this.dataHash[pr].price.uplotn_vn * ( ( h + w - 136 ) * 2 / 1000 ) * 1.1* 100 ) / 100;
				// Уплотнители под стеклопакет
				price += Math.ceil( this.dataHash[pr].price.uplotn_sp * ( (  h + w - 136 - 224 ) * 2 / 1000 ) * 1.1* 100 ) / 100;
				// Прокладки под стеклопакет (4)
				price += 4 * this.dataHash[pr].price.podkladka_sp2;
				// Заглушки (2)
				price += Math.ceil( this.dataHash[pr].price.zaglushka * 2 * 1.1 * 100 ) / 100;
				// Шурупы для армирования (16)
				price += Math.ceil( this.dataHash[pr].price.armirov_shurup * 16 * 1.1 * 100 ) / 100;
				// Шурупы для фурнитуры (30)
				price += Math.ceil( this.dataHash[pr].price.furn_shurup * 30 * 1.1 * 100 ) / 100;
				// Фурнитура
				price += this.dataHash[pr].price.furn_kompl * 1.1;
				// Ручка
				price += this.dataHash[pr].price.furn_ruchka * 1.1;

				// Стеклопакет
				price += Math.ceil( this.dataHash[pr].price.sp[1] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100;
				
				price = Math.round(price) * 2;
				
				if ( this._get_radio_value('calc_sp') == 2 ) {
					price += Math.ceil( this.dataHash[pr].price.sp[2] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100;
				}				
			}

			// Для 2-го типа створок (откидных)
			else if ( this._slotType[c] == 2 || this._slotType[c] == 3 ) {

				// Профиля рамы
				price += Math.ceil( this.dataHash[pr].price.profil_frame * ( ( h + w ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Профиль створки ( 136 = ( h - 68 + w - 68 ) -- размеры, на которые створка меньше рамы)
				price += Math.ceil( this.dataHash[pr].price.profil_slot * ( ( h + w - 136) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Шпатик для створки
				price += Math.ceil( this.dataHash[pr].price.shpatik_slot * ( ( h + w - 136 - 224 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;

				// Армирование рамы
				price += Math.ceil( this.dataHash[pr].price.armirov_frame * ( ( h + w - 180 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;												
				// Армирование створки
				price += Math.ceil( this.dataHash[pr].price.armirov_slot * ( ( h + w - 136 - 230 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;

				// Уплотнители внешние
				price += Math.ceil( this.dataHash[pr].price.uplotn_vn * ( ( h + w - 136 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Уплотнители под стеклопакет
				price += Math.ceil( this.dataHash[pr].price.uplotn_sp * ( (  h + w - 136 - 224 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Прокладки под стеклопакет (5)
				price += Math.ceil( 5 * this.dataHash[pr].price.podkladka_sp2 * 100 ) / 100;
				// Заглушки (2)
				price += Math.ceil( this.dataHash[pr].price.zaglushka * 2 * 1.1 * 100 ) / 100;
				// Шурупы для армирования (16)
				price += Math.ceil( this.dataHash[pr].price.armirov_shurup * 16 * 1.1 * 100 ) / 100;
				// Шурупы для фурнитуры (30)
				price += Math.ceil( this.dataHash[pr].price.furn_shurup * 30 * 1.1 * 100 ) / 100;
				// Фурнитура
				price += Math.ceil( this.dataHash[pr].price.furn_kompl_1 * 1.1 * 100 ) / 100;
				// Ручка
				price += Math.ceil( this.dataHash[pr].price.furn_ruchka * 1.1 * 100 ) / 100;

				// Стеклопакет
				price += Math.ceil( this.dataHash[pr].price.sp[1] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100;
				
				price = Math.ceil(price) * 2;
				
				if ( this._get_radio_value('calc_sp') == 2 ) {
					price += Math.ceil( this.dataHash[pr].price.sp[2] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100;
				}
			}
			// Дверь
			else if ( this._slotType[c] == 4 ) {
				
				type = 4;
				
				// Профиля рамы
				price += Math.ceil( this.dataHash[pr].price.profil_frame * ( ( h + w ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Профиль створки ( 136 = ( h - 68 + w - 68 ) -- размеры, на которые створка меньше рамы)
				price += Math.ceil( this.dataHash[pr].price.profil_slot * ( ( h + w - 136) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Шпатик для створки
				price += Math.ceil( this.dataHash[pr].price.shpatik_slot * ( ( h + w - 136 - 224 ) * 2 / 1000 ) * 1.1* 100 ) / 100;

				// Армирование рамы
				price += Math.ceil( this.dataHash[pr].price.armirov_frame * ( ( h + w - 180 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;												
				// Армирование створки
				price += Math.ceil( this.dataHash[pr].price.armirov_slot * ( ( h + w - 136 - 230 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Уплотнители внешние
				price += Math.ceil( this.dataHash[pr].price.uplotn_vn * ( ( h + w - 136 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;
				// Уплотнители под стеклопакет
				price += Math.ceil( this.dataHash[pr].price.uplotn_sp * ( (  h + w - 136 - 224 ) * 2 / 1000 ) * 1.1 * 100 ) / 100;

				// Прокладки под стеклопакет (4)
				price += Math.ceil( 4 * this.dataHash[pr].price.podkladka_sp2 * 100 ) / 100;

				// Заглушки (2)
				price += Math.ceil( this.dataHash[pr].price.zaglushka * 2 * 1.1 * 100 ) / 100;
				// Шурупы для армирования (16)
				price += Math.ceil( this.dataHash[pr].price.armirov_shurup * 16 * 1.1 * 100 ) / 100;
				// Шурупы для фурнитуры (30)
				price += Math.ceil( this.dataHash[pr].price.furn_shurup * 30 * 1.1 * 100 ) / 100;

				// Фурнитура
				price += Math.ceil( this.dataHash[pr].price.furn_kompl * 1.1 * 100 ) / 100;
				// Ручка
				price += Math.ceil( this.dataHash[pr].price.furn_ruchka * 1.1 * 100 ) / 100;

				// Стеклопакет
				price += Math.ceil( this.dataHash[pr].price.sp[1] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100;
				price = Math.round(price);
				
				if ( this._get_radio_value('calc_sp') == 2 ) {
					price += ( Math.ceil( this.dataHash[pr].price.sp[2] * ( Math.ceil(((h-190)*( w-190)/1000000)*100)/100 ) * 100 ) / 100 );
				}

				price *= 0.75;				
				price *= 2;

			}
//			this.debug_message( c+" ("+this._slotType[c]+") price: "+Math.ceil(price) );
//			tp += Math.ceil(price);
			tp += price;

		}
		
		var add = 0;
		price = tp;
		
		// Считаем подстановочный профиль (округляя до целого)
		add += Math.ceil(this.dataHash[pr].price.profil_podst * tw / 1000);

		// Монтаж
		if ( this._get_radio_value('calc_mn_y') )
			price += this.dataHash[pr].price.montaj * ( h * tw ) / 1000000;
		
		// Москитная сетка !!!! Уточнить рассчет !!!
		add += Math.ceil(this._get_radio_value('calc_ms') * this.dataHash[pr].price.ms * h / 1000000);
		
		// Подоконник
		add += ( (tw * this._get_radio_value('calc_pd') ) / 1000000 ) * this.dataHash[pr].price.pd;
		// Отлив
		add += ( (tw * this._get_radio_value('calc_otl') ) / 1000000 ) * this.dataHash[pr].price.otl;
		// Откос
		add += ( (tw + h * 2) / 1000000 ) * this._get_radio_value('calc_otk') * this.dataHash[pr].price.otk;

		// Для дверей
		if ( type == 4 )
		{			
			add = price;
		}

		// Какой-то коэффициент
		price += add * 0.95;

		price = price * this._get_radio_value('calc_win_amount');


		if ( this._get_radio_value('calc_fk_n') )
			price += 5;

		if ( this._get_radio_value('calc_fk_i') )
			price += 12;


		// Округляем до сотых с пересчетом в рубли
		price = Math.ceil(price * this.dataHash[pr].price.euro * 100)/100;

		if ( type != 4 ) {
			reduction = price;
			price *= this.dataHash[pr].price.koef;
			reduction -= price;
		}

		// Рисую на экран
		if (this.priceBox) this.priceBox.innerHTML = Math.ceil(price) + " руб.";
		if (this.reductionBox) this.reductionBox.innerHTML = Math.ceil(reduction) + " руб.";
		document.getElementById('calc_win_price').value = Math.ceil(price);
		
//		alert([slots, w, frame_perimeter, price ]);
			
	},


	this.inteface = function() {
		
	},

	this.destroy = function() {
		
	},

	//
	// Получение значения радиобатонов
	//
	// in:		name	- имя контейнера, содежащего радиобатоны;
	// return:	value checked radiobutton;
	//		
	this._get_radio_value = function(name) {

		// Просматриваю радиобатоны
		var l = document.getElementsByTagName('input');

		for ( e=0;e<l.length;e++) {
			if ( l[e].name == name && l[e].checked ) return l[e].value;
		}

		// Просматриваю селекты
		var l = document.getElementsByTagName('select');

		for ( e=0;e<l.length;e++) {
			if ( l[e].name == name ) return l[e].value;
		}
			
	},
	
	this.debug_message = function(m) {
		if ( d = document.getElementById("debug") ) {
			d.value += m + "\n";
		}
	}
	
//	this.init(type,e);

}
