var legoId = 4160;
function dmArray() {
	
}
dmArray.prototype.add = function(index, value) {
	if(index - 0 > 0 && value != null && typeof value != 'undefined') {
      eval('this.v'+index+' = "'+value+'";');
	}
}

dmArray.prototype.get = function(index) {
	if(index - 0 > 0) {
	  return eval('this.v'+index);
	}
}

function dmPizza(id) {
	this.id = id;
	this.include = new Object();
	this.exclude = new Object();
	this.free = new Object();
    this.price = 0;
    this.priceAdditions = 0;
    this.count = 0;
    this.format = 0;
	
	this.maxAddition = 99;
	
	this.map = '';
	
    this.fill();
}

dmPizza.prototype.fill = function() {
    if(typeof dmMenu['ELEMENTS'] == 'undefined' || typeof dmMenu['ELEMENTS'][this.id] == 'undefined') return false;
    var pizza = dmMenu['ELEMENTS'][this.id];
    if(!pizza) {
    	return false;
    }
    if(typeof pizza['EXCLUDE'] != 'undefined')
    for(i in pizza['EXCLUDE']) {
		if(typeof dmMenu['ADDITIONS_LISTS'][i] != 'undefined')
	    for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
	        this.exclude[j] = 1;
	    }
	}
    if(typeof pizza['INCLUDE'] != 'undefined')
	for(i in pizza['INCLUDE']) {
		if(typeof dmMenu['ADDITIONS_LISTS'][i] != 'undefined')
	    for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
	        this.include[j] = null; //(pizza['ID'] == legoId ? 1 : null);
	    }
	}
	if(typeof pizza['FREE'] != 'undefined')
	for(i in pizza['FREE']) {
		if(typeof dmMenu['ADDITIONS_LISTS'][i] != 'undefined')
	    for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
	        this.free[j] = null;
	    }
	}
}

dmPizza.prototype.changeAddition = function(type, listId, additionId, direction) {
	if(direction == 0 && type == 'exclude') {
/*
    	if(!els[i].options[els[i].selectedIndex].value) {
    		
    	}
*/
    	if(this.exclude[additionId] > 0) {
    		this.exclude[additionId] = -this.exclude[additionId];
    	}
    	else {
    		this.exclude[additionId] = Math.abs(this.exclude[additionId]);
    	}
    	return true;
    }
	if(!additionId && (type == 'free' || type == 'include')) {
		additionId = listId.id.substring( listId.id.indexOf('_') + 1 );
    }
    switch(type) {
	    case 'exclude': var wrapper = this.exclude; break;
	    case 'include': var wrapper = this.include; break;
	    case 'free': var wrapper = this.free; break;
	    default: return false;
    }
	if(typeof wrapper[additionId] == 'undefined') {
    	wrapper[additionId] = 0;
        //return false;
    }
    if(direction > 0) {
    	wrapper[additionId]++;
    }
    else {
    	wrapper[additionId]--;
    }
    // !!!!!!!!!!!!!!!!!!!!!!
    if(wrapper[additionId] < 1) {
        wrapper[additionId] = 1;
    }
}

dmPizza.prototype.setAddition = function(type, additionId, value) {
	switch(type) {
	    case 'exclude': var wrapper = this.exclude; break;
	    case 'include': var wrapper = this.include; break;
	    case 'free': var wrapper = this.free; break;
	    default: return false;
    }
	if(typeof wrapper[additionId] == 'undefined') {
    	return false;
    }
  	wrapper[additionId] = this.testAdditionValue(value);
  	return true;
}

dmPizza.prototype.getAddition = function(type, additionId) {
	var k;
	if(type == 'exclude' || type == '') {
		for(k in this.exclude) {
	    	if(k == additionId) {
	    		return ['exclude', this.exclude[k]];
	    	}
	    }
	}
	if(type == 'free' || type == '') {
		for(k in this.free) {
	    	if(k == additionId) {
	    		return ['free', this.free[k]];
	    	}
	    }
	}
	if(type == 'include' || type == '') {
		for(k in this.include) {
	    	if(k == additionId) {
	    		return ['include', this.include[k]];
	    	}
	    }
	}
	return false;
}

dmPizza.prototype.testAdditionValue = function(value) {
	if(value < 0) {
		return 0;
	}
	if(value > this.maxAddition) {
		return this.maxAddition;
	}
	return value;
}

dmPizza.prototype.deleteAddition = function(type, addition) {
	switch(type) {
	    case 'exclude': var wrapper = this.exclude; break;
	    case 'include': var wrapper = this.include; break;
	    case 'free': var wrapper = this.free; break;
	    default: return false;
    }
	if(typeof wrapper[addition] == 'undefined') {
    	return false;
    }
  	wrapper[addition] = null;
  	if(type == 'include') {
        $('dmMenuPopupFreeAdd_' + addition).style.display = 'block';
        $('dmMenuPopupFreeAddMore_' + addition).style.display = 'none';
  	}
  	return true;
}



///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
function dmPageClass() {
    this.pizzas = new Object();
    this.basket = new Object();
    this.cookies = new Array();
    this.cookiesOrdered = new Object();
	this.maxAddition = 99;
}

dmPageClass.prototype.init = function() {
    if(!dmMenu) {
        return false;
    }
    if($('dmMenuPopupId')) {
        for(i in dmMenu['ELEMENTS_ALL']) {
            this.pizzas[i] = new dmPizza(i);
        }
    }
    else {
        this.pizzas[1] = new dmPizza();
    }
}

dmPageClass.prototype.initLego = function() {
    if(!dmMenu) {
        return false;
    }
    this.pizzas[legoId] = new dmPizza(legoId);
}

dmPageClass.prototype.getElementId = function() {
    if($('dmMenuPopupId')) {
        var elementId = $('dmMenuPopupId').innerHTML;
    }
    else {
        elementId = legoId;
    }
    return elementId;
}

dmPageClass.prototype.changeAddition = function(type, listId, additionId, direction) {
    var elementId = this.getElementId();
	if(!elementId) {
        return false;
    }
	this.pizzas[elementId].changeAddition(type, listId, additionId, direction);
	this.showPizzaInfo(elementId, 1);
}

dmPageClass.prototype.addAddition = function(type, addition) {
    // Если ноль - бесплатное дополнение
    var quantity = 1;
    if($('dmMenuPopupFreeQuantity')) {
        switch(type) {
            case 'include': quantity = 1; break;
            case 'free': quantity = parseInt($('dmMenuPopupFreeQuantity').value); break;
        }
    }
    if(type == 'popup') {
        type = 'include';
        addition = parseInt($('dmMenuAdditionId').value);
        quantity = parseInt($('dmMenuAdditionQuantity').value);
        $('dmMenuAddition').style.display = 'none';
    }
    if(quantity < 1 || quantity > this.maxAddition) {
        quantity = 1;
    }
	if(type == 'free') {
		var els = $('dmMenuPopup').getElementsByTagName('select');
		for(var i=0; i<els.length; i++) {
            if(els[i].id.indexOf('dmMenuPopupFreeSelect_') > -1 && els[i].style.display != 'none') {
                addition = parseInt(els[i].value);
                var additionName = els[i].options[els[i].selectedIndex].text;
                break;
            }
		}
    }
    else if(type == 'include' && parseInt(addition) > 0) {
    	if(typeof dmMenu['ADDITIONS'][addition]['NAME'] == 'undefined') {
            return false;
        }
        var additionName = dmMenu['ADDITIONS'][addition]['NAME'];
    }
	if(!addition) {
		return false;
	}
	// Проверяем, есть ли такая пицца
    var elementId = this.getElementId();
    if(!parseInt(elementId)) {
        return false;
    }
	var exists = false;
	if(exists = this.pizzas[elementId].getAddition(type, addition)) {
		if(typeof this.pizzas[elementId][exists[0]][addition] == 'undefined') {
			return false;
		}
  	        var wasNull = false;
		
		if(this.pizzas[elementId][exists[0]][addition] == null) {
		    wasNull = true;
		    this.pizzas[elementId][exists[0]][addition] = 0;
		}
		this.pizzas[elementId].setAddition(type, addition, parseInt(this.pizzas[elementId][exists[0]][addition]) + quantity);
		if(!wasNull) {
			this.showPizzaInfo(elementId, 1);
			return true;
		}
	}
    this.addAdditionRow(type, addition, additionName);
    this.showPizzaInfo(elementId, 1);
}

dmPageClass.prototype.addAdditionRow = function(type, addition, additionName) {
    switch(type) {
        case 'free' : TagName = 'Free'; break;
        case 'include' : TagName = 'Include'; break;
        default: return false;
    }
        if($('dmMenuPopupExcludeList')) {
          var els = $('dmMenuPopupExcludeList').getElementsByTagName('div');
	  var maskName = 'Exclude';
	} else {
	  var els = $('dmMenuPopupFreeList').getElementsByTagName('div');
	  var maskName = 'Free';
	}
	for(var i=0; i<els.length; i++) {
		if((maskName == 'Exclude' && els[i].id.indexOf('dmMenuPopupExclude_') > -1) || (maskName == 'Free' && els[i].id.indexOf('dmMenuPopupFree_') > -1)) {
		        if($('dmMenuPopupExcludeList')) {
			  var numbers = els[i].id.replace('dmMenuPopupExclude_', '');
			} else {
			  var numbers = els[i].id.replace('dmMenuPopupFree_', '');
			}
if(!$('dmMenuPopup' + TagName + 'Name_' + addition)) {
			var holder = els[i].cloneNode(true);
			while(holder.innerHTML.indexOf(numbers) > -1) {
			    holder.innerHTML = holder.innerHTML.replace(numbers, 0);
		        }
			holder.id = 'dmMenuPopup' + TagName + '_' + addition;
			holder.style.display = 'none';
			$('dmMenuPopupIncludeHolder').appendChild(holder);
            $('dmMenuPopup' + maskName + 'Name_0').id = 'dmMenuPopup' + TagName + 'Name_' + addition;
			$('dmMenuPopup' + maskName + 'Check_0').id = 'dmMenuPopup' + TagName + 'Check_' + addition;
			$('dmMenuPopup' + maskName + 'Title_0').id = 'dmMenuPopup' + TagName + 'Title_' + addition;
            $('dmMenuPopup' + maskName + 'Change_0').id = 'dmMenuPopup' + TagName + 'Change_' + addition;
            $('dmMenuPopup' + maskName + 'Plus_0').id = 'dmMenuPopup' + TagName + 'Plus_' + addition;
            $('dmMenuPopup' + maskName + 'PlusHolder_0').id = 'dmMenuPopup' + TagName + 'PlusHolder_' + addition;
			$('dmMenuPopup' + maskName + 'Quantity_0').id = 'dmMenuPopup' + TagName + 'Quantity_' + addition;
            $('dmMenuPopup' + maskName + 'Minus_0').id = 'dmMenuPopup' + TagName + 'Minus_' + addition;
            $('dmMenuPopup' + maskName + 'MinusHolder_0').id = 'dmMenuPopup' + TagName + 'MinusHolder_' + addition;
	holder.style.display = 'block';
}
            var img = new Image();
            img.src = '/images/pizza_delete.gif';
            $('dmMenuPopup' + TagName + 'Check_' + addition).parentNode.appendChild(img);
            $('dmMenuPopup' + TagName + 'Check_' + addition).parentNode.removeChild($('dmMenuPopup' + TagName + 'Check_' + addition));
            img.id = 'dmMenuPopup' + TagName + 'Check_' + addition;
            img.style.cursor = 'pointer';
            switch(TagName) {
              case 'Include': var tagNameStr = 'include'; break;
              case 'Exclude': var tagNameStr = 'exclude'; break;
              case 'Free': var tagNameStr = 'free'; break;
              default: var tagNameStr = 'include'; break;
            }
			$('dmMenuPopup' + TagName + 'Title_' + addition).innerHTML = additionName;
			$('dmMenuPopup' + TagName + 'Title_' + addition).setAttribute('for', 'dmMenuPopup' + TagName + 'Check_' + addition); 
//			$('dmMenuPopup' + TagName + 'Check_' + addition).onclick = function() { dmPage.changeAddition(this.id.indexOf('Free') > -1 ? 'free' : 'include', this, 0, 0); };
                        $('dmMenuPopup' + TagName + 'Check_' + addition).onclick = function() { dmPage.deleteAddition(tagNameStr, this.id); };
			$('dmMenuPopup' + TagName + 'Plus_' + addition).onclick = function()  { dmPage.changeAddition(tagNameStr, this, 0, 1); };
			$('dmMenuPopup' + TagName + 'Minus_' + addition).onclick = function() { dmPage.changeAddition(tagNameStr, this, 0, -1); };
			break;

		}
                 
	}
}

dmPageClass.prototype.deleteAddition = function(type, addition) {
	if(!type) {
        return false;
    }
    if(isNaN(addition)) {
        addition = addition.substring(addition.indexOf('_')+1) - 0;
    }
    if(!parseInt(addition)) {
        return false;
    }
	if(type == 'free') {
	    $('dmMenuPopupFree_' + addition).parentNode.removeChild($('dmMenuPopupFree_' + addition));
    }
	else if(type == 'include' && parseInt(addition) > 0) {
	    $('dmMenuPopupInclude_' + addition).parentNode.removeChild($('dmMenuPopupInclude_' + addition));
    }
	// Проверяем, есть ли такая пицца
    var elementId = this.getElementId();
    if(!elementId) {
        return false;
    }
    this.pizzas[elementId].deleteAddition(type, addition);
    this.showPizzaInfo(elementId, 1);
}

dmPageClass.prototype.showPizzaInfo = function(elementId, recalc) {
	if(!$('dmMenuPopupId')) {
       return this.showLegoInfo();
    }
    $('leftCitySelect').style.display = 'none';
    // Проверяем входные данные
    if(typeof this.pizzas[elementId] == 'undefined') {
        this.pizzas[elementId] = new dmPizza(elementId);
    }
    if(typeof dmMenu == 'undefined' || typeof dmMenu['ELEMENTS'][elementId] == 'undefined') {
        alert('Axtung');
        return false;
    }
    // Если не только пересчет, то выводим все данные
    var pizza = dmMenu['ELEMENTS'][elementId];
    if(!recalc) {
        // Показываем окно и вносим основные данные
        window.document.body.appendChild($('dmMenuPopup'));
        $('dmMenuPopup').style.display = 'block';
        $('dmMenuPopup').style.position = 'absolute';
        
        var formTop = (-20 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop));
        if(formTop > ($('main').scrollHeight - 780)) {
        	formTop = $('main').scrollHeight - 780;
        }

        this.showOverflow();
/*
        if(formTop + $('dmMenuPopup').offsetHeight > $('dmMenuPopupOverflow').offsetHeight) {
        	formTop = ($('dmMenuPopupOverflow').offsetHeight - $('dmMenuPopup').offsetHeight - 0); //-20
        }
*/
        $('dmMenuPopup').style.top = formTop + 'px';
        window.scrollTo(0, formTop-20);
        
        $('dmMenuPopupImage').src = '/resize/width/400/height/280' + pizza['DETAIL_PICTURE'];
        $('dmMenuPopupName').innerHTML = pizza['NAME'];
        $('dmMenuPopupDesc').innerHTML = pizza['PREVIEW_TEXT'];
        $('dmMenuPopupId').innerHTML = elementId;
        // Скрываем все вариабельные поля
        var list = $('dmMenuPopup').getElementsByTagName('div');
        for(i=0; i<list.length; i++) {
            if(list[i].id.indexOf('dmMenuPopupExcludeList_') > -1) {
                list[i].style.display = 'none';
            }
            if(list[i].id.indexOf('dmMenuPopupFormat_') > -1) {
                list[i].style.display = 'none';
            }
            if(list[i].id.indexOf('dmMenuPopupAddition_') > -1) {
                list[i].style.display = 'none';
            }
        }
        $('dmMenuPopupFreeQuantity').value = 1;
        var list = $('dmMenuPopup').getElementsByTagName('select');
        for(i=0; i<list.length; i++) {
            if(list[i].id.indexOf('dmMenuPopupFreeSelect_') > -1) {
                list[i].style.display = 'none';
            }
        }
        // Отображаем нужные исключаемые ингредиенты
        var showed = new Object();
        if(typeof pizza['EXCLUDE'] !== 'undefined') {
            for(i in pizza['EXCLUDE']) {
                $('dmMenuPopupExcludeList_' + i).style.display = 'block';;
                for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
                    if(typeof showed[j] == 'undefined') {
                        showed[j] = 1;
                        $('dmMenuPopupExclude_' + i + '_' + j).style.display = 'block';;
                    }
                    else {
                        showed[j] = 1;
                        $('dmMenuPopupExclude_' + i + '_' + j).style.display = 'none';;
                    }
                }
            }
            $('dmMenuPopupExcludeList').style.display = 'block';;
        }
        else {
            $('dmMenuPopupExcludeList').style.display = 'none';;
        }
        // Отображаем список халявных ингредиентов
        if(pizza['FREE_HASH']) {
            $('dmMenuPopupFreeSelect_' + pizza['FREE_HASH']).style.display = 'block';;
            $('dmMenuPopupFreeList').style.display = 'block';;
        }
        else {
            $('dmMenuPopupFreeList').style.display = 'none';;
        }
        // Отображаем платные дополнения
        if(typeof pizza['INCLUDE'] !== 'undefined') {
            for(i in pizza['INCLUDE']) {
                for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
                    $('dmMenuPopupAddition_' + j).style.display = 'block';
                }
            }
            $('dmMenuPopupIncludeList').style.display = 'block';;
        }
        else {
            $('dmMenuPopupIncludeList').style.display = 'none';;
        }
    }
    // Просчитываем и показываем изменения в комплектации и ценах
    for(i in pizza['EXCLUDE']) {
        for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
            if(
                this.pizzas[elementId].exclude[j] > 0 ||
                (
                        this.pizzas[elementId].exclude[j] == 0 &&
                        $('dmMenuPopupExcludeCheck_' + i + '_' + j).checked
                )
              ) {
                $('dmMenuPopupExcludeChange_' + i + '_' + j).style.display = 'block';;
                $('dmMenuPopupExcludeName_' + i + '_' + j).className = $('dmMenuPopupExcludeName_' + i + '_' + j).className.replace(' disabled', '');
                $('dmMenuPopupExcludeQuantity_' + i + '_' + j).value = this.pizzas[elementId].exclude[j];
                $('dmMenuPopupExcludePlus_' + i + '_' +j).style.display = (this.pizzas[elementId].exclude[j] >= this.maxAddition ? 'none' : 'block');
                $('dmMenuPopupExcludePlusHolder_' + i + '_' +j).style.display = (this.pizzas[elementId].exclude[j] >= this.maxAddition ? 'block' : 'none');
                $('dmMenuPopupExcludeMinus_' + i + '_' + j).style.display = (this.pizzas[elementId].exclude[j] < 2 ? 'none' : 'block');
                $('dmMenuPopupExcludeMinusHolder_' + i + '_' + j).style.display = (this.pizzas[elementId].exclude[j] < 2 ? 'block' : 'none');
            }
            else {
                $('dmMenuPopupExcludeCheck_' + i + '_' + j).checked = false;
                $('dmMenuPopupExcludeChange_' + i + '_' + j).style.display = 'none';;
                $('dmMenuPopupExcludeName_' + i + '_' + j).className += ' disabled';
            }
        }
    }
    for(i in pizza['FREE']) {
        for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {

            if(!$('dmMenuPopupFreeTitle_' + j)) {
            	if(this.pizzas[elementId].free[j]) {
            		this.addAdditionRow('free', j, dmMenu['ADDITIONS'][j]['NAME']);
                }
            	else {
                  continue;
            	}
            }
            if(
                this.pizzas[elementId].free[j] > 0 ||
                (
                        this.pizzas[elementId].free[j] == 0 &&
                        $('dmMenuPopupFreeCheck_' + j).checked
                )
              ) {
            	$('dmMenuPopupFree_' + j).style.display = 'block';
            	$('dmMenuPopupFreeChange_' + j).style.display = 'block';
                $('dmMenuPopupFreeName_' + j).className = $('dmMenuPopupFreeName_' + j).className.replace(' disabled', '');
                $('dmMenuPopupFreeQuantity_' + j).value = this.pizzas[elementId].free[j];
                $('dmMenuPopupFreePlus_' + j).style.display = (this.pizzas[elementId].free[j] >= this.maxAddition ? 'none' : 'block');
                $('dmMenuPopupFreePlusHolder_' + j).style.display = (this.pizzas[elementId].free[j] >= this.maxAddition ? 'block' : 'none');
                $('dmMenuPopupFreeMinus_' + j).style.display = (this.pizzas[elementId].free[j] < 2 ? 'none' : 'block');
                $('dmMenuPopupFreeMinusHolder_' + j).style.display = (this.pizzas[elementId].free[j] == 0 ? 'block' : 'none');
            }
            else {
            	$('dmMenuPopupFree_' + j).style.display = 'none';
            	//$('dmMenuPopupFreeChange_' + j).style.display = 'none';
            }
        }
    }

    for(i in pizza['INCLUDE']) {
        for(j in dmMenu['ADDITIONS_LISTS'][i]['ADDITIONS']) {
            if(!$('dmMenuPopupIncludeTitle_' + j)) {
            	if(this.pizzas[elementId].include[j]) {
            		this.addAdditionRow('include', j, dmMenu['ADDITIONS'][j]['NAME']);
                }
            	else {
                  continue;
            	}
            }
            if(
            		//alert('++' + this.pizzas[elementId].include[j] +'-'+j);
            		this.pizzas[elementId].include[j] > 0
              ) {
            	$('dmMenuPopupInclude_' + j).style.display = 'block';
            	$('dmMenuPopupIncludeChange_' + j).style.display = 'block';
                $('dmMenuPopupIncludeQuantity_' + j).value = this.pizzas[elementId].include[j];
                $('dmMenuPopupIncludePlus_' + j).disabled = (this.pizzas[elementId].include[j] >= this.maxAddition ? true : false);
//                $('dmMenuPopupIncludeMinus_' + j).disabled = (!this.pizzas[elementId].include[j] > 1 ? true : false);
                $('dmMenuPopupIncludeMinus_' + j).style.display = (this.pizzas[elementId].include[j] < 2 ? 'none' : 'block');
                $('dmMenuPopupFreeAdd_' + j).style.display = 'none';
                $('dmMenuPopupFreeAddMore_' + j).style.display = 'block';
            }
            else {
            	$('dmMenuPopupInclude_' + j).style.display = 'none';;
            	/*
                $('dmMenuPopupFreeAdd_' + j).style.display = 'block';
                $('dmMenuPopupFreeAddMore_' + j).style.display = 'none';
            	$('dmMenuPopupIncludeChange_' + j).style.display = 'none';;
            	*/
            }
        }
        /*
         *  ||
                (
                        this.pizzas[elementId].include[j] == 0 &&
                        $('dmMenuPopupIncludeCheck_' + j).checked
                )
         */
    }

    // Считаем количество дополнительных Платных ингредиентов
    var paiedAdditions = 0;
    // Вилка для ингредиентов, которые своят по своему
    var priceDelta = 0;
    var priceDeltaElements = 0;
    var els = $('dmMenuPopupIncludeHolder').getElementsByTagName('input');
    for(var i=0; i<els.length; i++) {
        if(els[i].id.indexOf('dmMenuPopupIncludeQuantity_') > -1 || els[i].id.indexOf('dmMenuPopupFreeQuantity_') > -1) {
            elementId = els[i].id.substr(els[i].id.lastIndexOf('_')+1, 100);
            if(typeof dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE']) > 0) {
            	priceDelta += parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] * els[i].value);
            } else {
            	paiedAdditions += parseInt(els[i].value);
            }
        }
    }
    var els = $('dmMenuPopupExcludeList').getElementsByTagName('input');
    for(var i=0; i<els.length; i++) {
        if(els[i].id.indexOf('dmMenuPopupExcludeQuantity_') > -1 && els[i].value > 1) {
            elementId = els[i].id.substr(els[i].id.lastIndexOf('_')+1, 100);
            var elementCheckbox = els[i].id.replace('dmMenuPopupExcludeQuantity_', 'dmMenuPopupExcludeCheck_');
            if(elementCheckbox && $(elementCheckbox) && !$(elementCheckbox).checked) continue;
            if(typeof dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE']) > 0) {
            	priceDelta += parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] * (parseInt(els[i].value) - 1));
            } else {
            	paiedAdditions += parseInt(els[i].value) - 1;
            }
        }
    }
    // Отображаем форматы и цены
    if(typeof dmMenu['PRICES2LIST'][pizza['ID']] != 'undefined') {
        if(typeof $('dmMenuPopupFormatPieces').innerHTML != 'undefined') {
            var strPieces = $('dmMenuPopupFormatPieces').innerHTML;
        }
        else {
            var strPieces = '';
        }
        for(formatId in dmMenu['PRICES2LIST'][pizza['ID']]) {
            if(typeof dmMenu['PRICES'][dmMenu['PRICES2LIST'][pizza['ID']][formatId]] == 'undefined') {
                continue;
            }
            var price = dmMenu['PRICES'][dmMenu['PRICES2LIST'][pizza['ID']][formatId]];
            if($('dmMenuPopupFormat_' + formatId)) {
                $('dmMenuPopupFormat_' + formatId).style.display = 'block';
                $('dmMenuPopupFormatInupt_' + formatId).value = 1;
            }
            var priceValue = price['NAME'];
            if(paiedAdditions > 0 || priceDelta > 0) {
                priceValue = parseInt(priceValue) + parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']) * paiedAdditions + priceDelta;
            }
            if($('dmMenuPopupFormatPrice_' + formatId)) {
                $('dmMenuPopupFormatPrice_' + formatId).innerHTML = priceValue;
            }
            // Корректируем цены доп. ингредиентов под их уникальные цены
            // Ставим цены дополнительных ингридиентов
            $$('#dmMenuPopupIncludeList b[id^=dmMenuPopupAdditionPrice_]').each(function(el){
//            	el.innerHTML = price['PROPERTY_PRICE_ADDIT_VALUE'];
            	var additionId = parseInt(el.id.replace('dmMenuPopupAdditionPrice_', ''));
            	if(typeof dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] != 'undefined') {
            	    el.innerHTML = dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'];
            	} else {
            		el.innerHTML = dmMenu['PRICES'][priceId]['PROPERTY_PRICE_ADDIT_VALUE'];
            	}
            });
            if(!formatId || !$('dmMenuPopupFormatDimensions_' + formatId) || !document.getElementById('dmMenuPopupFormatDimensions_' + formatId) || typeof document.getElementById('dmMenuPopupFormatDimensions_' + formatId).innerHTML == 'undefined') {
                continue;
            }
            var str = '';
            var format = dmMenu['FORMATS'][formatId];
            if(typeof format['PROPERTY_PIECES_VALUE'] != 'undefined') {
                str = '<strong>' + format['PROPERTY_PIECES_VALUE'] + '</strong> ' + strPieces;
            }
            if(typeof format['PROPERTY_PIECES_VALUE'] != 'undefined' && typeof format['PROPERTY_SIZE_VALUE'] != 'undefined') {
                str += ' / ';
            }
            if(typeof format['PROPERTY_SIZE_VALUE'] != 'undefined' && $('dmMenuPopupFormatDimensions_' + formatId)) {
                str += '&#216; <strong>' + format['PROPERTY_SIZE_VALUE'] + '</strong> ' + $('dmMenuPopupFormatSize').innerHTML;
            }
            if((typeof format['PROPERTY_PIECES_VALUE'] != 'undefined' || typeof format['PROPERTY_SIZE_VALUE'] != 'undefined') && typeof price['PROPERTY_WEIGHT_VALUE'] != 'undefined') {
                str += ' / ';
            }
            if(typeof price['PROPERTY_WEIGHT_VALUE'] != 'undefined' && $('dmMenuPopupFormatDimensions_' + formatId)) {
                str += '<strong>' + price['PROPERTY_WEIGHT_VALUE'] + '</strong> ' + $('dmMenuPopupFormatWeight').innerHTML;
            }
            $('dmMenuPopupFormatDimensions_' + formatId).innerHTML = str;
        }
    }
    //document.location.hash = 'popup';
    this.saveCookies();
}

dmPageClass.prototype.showLegoInfo = function(formatId) {
    // Проверяем входные данные
    if(typeof dmMenu['ELEMENTS'] == 'undefined') return false;
    if(typeof dmMenu['ELEMENTS'][legoId] == 'undefined') return false;
    var elementId = legoId;
    if(typeof this.pizzas[elementId] == 'undefined') {
        this.pizzas[elementId] = new dmPizza(elementId);
    }
    if(typeof dmMenu == 'undefined') {
        alert('Axtung');
        return false;
    }
    // Если не только пересчет, то выводим все данные
    var pizza = dmMenu['ELEMENTS'][elementId];
    // Просчитываем и показываем изменения в комплектации и ценах
    var i = 1;
/*
    for(j in dmMenu['EXCLUDE']) {
            if($('dmMenuPopupExcludeCheck_' + i + '_' + j).checked) {
                var value = (typeof this.pizzas[elementId].exclude[j] == 'undefined' || isNaN(this.pizzas[elementId].exclude[j]) ? 0 : this.pizzas[elementId].exclude[j]);
                $('dmMenuPopupExcludeChange_' + i + '_' + j).style.display = 'block';;
                $('dmMenuPopupExcludeName_' + i + '_' + j).className = $('dmMenuPopupExcludeName_' + i + '_' + j).className.replace(' disabled', '');
                $('dmMenuPopupExcludeQuantity_' + i + '_' + j).value = value;
                $('dmMenuPopupExcludePlus_' + i + '_' +j).style.display = (value >= this.maxAddition ? 'none' : 'block');
                $('dmMenuPopupExcludePlusHolder_' + i + '_' +j).style.display = (value >= this.maxAddition ? 'block' : 'none');
                $('dmMenuPopupExcludeMinus_' + i + '_' + j).style.display = (value == 0 ? 'none' : 'block');
                $('dmMenuPopupExcludeMinusHolder_' + i + '_' + j).style.display = (value == 0 ? 'block' : 'none');
            }
            else {
                $('dmMenuPopupExcludeCheck_' + i + '_' + j).checked = false;
                $('dmMenuPopupExcludeChange_' + i + '_' + j).style.display = 'none';;
                $('dmMenuPopupExcludeName_' + i + '_' + j).className += ' disabled';
            }
    }
 */
    for(j in dmMenu['FREE']) {
            if($('dmMenuPopupFreeCheck_' + i + '_' + j).checked) {
                var value = (typeof this.pizzas[elementId].free[j] == 'undefined' || isNaN(this.pizzas[elementId].free[j]) ? 0 : this.pizzas[elementId].free[j]);
                $('dmMenuPopupFreeChange_' + i + '_' + j).style.display = 'block';;
                $('dmMenuPopupFreeName_' + i + '_' + j).className = $('dmMenuPopupFreeName_' + i + '_' + j).className.replace('disabled', '');
                $('dmMenuPopupFreeQuantity_' + i + '_' + j).value = value - 0;
                $('dmMenuPopupFreePlus_' + i + '_' +j).style.display = (value >= this.maxAddition ? 'none' : 'block');
                $('dmMenuPopupFreePlusHolder_' + i + '_' +j).style.display = (value >= this.maxAddition ? 'block' : 'none');
                $('dmMenuPopupFreeMinus_' + i + '_' + j).style.display = (value <= 1 ? 'none' : 'block');
                $('dmMenuPopupFreeMinusHolder_' + i + '_' + j).style.display = (value == 0 ? 'block' : 'none');
            }
            else {
                $('dmMenuPopupFreeChange_' + i + '_' + j).style.display = 'none';;
		if($('dmMenuPopupFreeName_' + i + '_' + j).className.indexOf('disabled') == -1) {
                  $('dmMenuPopupFreeName_' + i + '_' + j).className += ' disabled';
		}
            }
    }
    var i = 1;
    for(j in dmMenu['INCLUDE']) {
            if(!$('dmMenuPopupIncludeTitle_' + j)) {
                continue;
            }
            if(1) {
            //$('dmMenuPopupIncludeCheck_' + j).checked
                var value = (typeof this.pizzas[elementId].include[j] == 'undefined' || isNaN(this.pizzas[elementId].include[j]) ? 0 : this.pizzas[elementId].include[j]);
                //alert(this.pizzas[elementId].include[j]);
                $('dmMenuPopupIncludeChange_' + j).style.display = 'block';;
                $('dmMenuPopupIncludeName_' + j).className = $('dmMenuPopupIncludeName_' + j).className.replace(' disabled', '');
                $('dmMenuPopupIncludeQuantity_' + j).value = value;
                $('dmMenuPopupIncludePlus_' + j).style.display = (value >= this.maxAddition ? 'none' : 'block');
                $('dmMenuPopupIncludePlusHolder_' + j).style.display = (value >= this.maxAddition ? 'block' : 'none');
                $('dmMenuPopupIncludeMinus_' + j).style.display = (value == 0 ? 'none' : 'block');
                $('dmMenuPopupIncludeMinusHolder_' + j).style.display = (value == 0 ? 'block' : 'none');
                $('dmMenuPopupFreeAdd_' + j).style.display = 'none';
                $('dmMenuPopupFreeAddMore_' + j).style.display = 'block';
            }
            else {
                $('dmMenuPopupIncludeChange_' + j).style.display = 'none';;
            }
    }
    
    // Считаем количество дополнительных Платных ингредиентов
    var paiedAdditions = 0;
    var priceDelta = 0;
    var els = $('dmMenuPopupIncludeHolder').getElementsByTagName('input');
    for(var i=0; i<els.length; i++) {
        if(els[i].id.indexOf('dmMenuPopupIncludeQuantity_') > -1) {
        	elementId = els[i].id.substr(els[i].id.lastIndexOf('_')+1, 100);
        	if(typeof dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE']) > 0) {
            	priceDelta += parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] * els[i].value);
            } else {
          	    paiedAdditions += parseInt(els[i].value);
            }
        }
    }
    var els = $('lego').getElementsByTagName('input');
    for(var i=0; i<els.length; i++) {
        if(els[i].id.indexOf('dmMenuPopupFreeQuantity_') > -1 && els[i].value > 0) {
            elementId = els[i].id.substr(els[i].id.lastIndexOf('_')+1, 100);
            if($('dmMenuPopupFreeCheck_1_' + elementId) && $('dmMenuPopupFreeCheck_1_' + elementId).checked) {
                if(typeof dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE']) > 0) {
                	priceDelta += parseInt(dmMenu['ADDITIONS'][elementId]['PROPERTY_PRICE_VALUE'] * (parseInt(els[i].value)));
                } else {
                   	paiedAdditions += parseInt(els[i].value);
                }
            }
        }
    }
    
    // Берем формат пиццы.
    var els = $('right').getElementsByTagName('input');
    var str = '';
    if(typeof formatId == 'undefined' || !formatId) {
    	$$('input[name=pizzaType]').each(function(element) {
    		if(element.checked) {
    			var str = element.id.replace('dmLegoFormat_', '');
    			formatId = str.substr(0, str.indexOf('_'));
    		}
    	});
    }
    for(var i=0; i<els.length; i++) {
    	if(els[i].alt == formatId) {
            priceId = els[i].title;
    	}
    	else if(els[i].id.indexOf('dmMenuPopupFreeQuantity_1_') > -1 && els[i].value > 0) {
            var aid = els[i].id.replace('dmMenuPopupFreeQuantity_1_', '');
            if(!$('dmMenuPopupFreeCheck_1_' + aid).checked) continue;
		    if(els[i].value > 1) {
		      str += els[i].value + 'x';
		    }
            str += dmMenu['ADDITIONS'][aid]['NAME'] + ', ';
        }
        else if(els[i].id.indexOf('dmMenuPopupIncludeQuantity_') > -1 && els[i].value > 0) {
            var aid = els[i].id.replace('dmMenuPopupIncludeQuantity_', '');
		    if(els[i].value > 1) {
		      str += els[i].value + 'x';
		    }
            str += dmMenu['ADDITIONS'][aid]['NAME'] + ', ';
        }
    }
    if(typeof formatId == 'undefined' || typeof priceId == 'undefined') {
    	this.saveCookies();
    	return false;
    }
    var reg = /, $/;
    str = str.replace(reg, '');
    if(typeof formatId != 'undefined')
        $('dmLegoResultName').innerHTML = dmMenu['FORMATS'][formatId]['NAME'];
    if(typeof priceId != 'undefined')
        $('dmLegoResultPrice').innerHTML = parseInt(dmMenu['PRICES'][priceId]['NAME']) + (paiedAdditions * dmMenu['PRICES'][priceId]['PROPERTY_PRICE_ADDIT_VALUE']) + priceDelta;
    $('dmLegoResultComment').innerHTML = str;
    // Подсвечиваем выбранный формат
    $$('#lego div[id^=dmMenuPopupFormat_]').each(function(div) {
    	div.className = 'dmMenuPopupFormatLego';
    });
    $('dmLegoResult').style.display = 'block';
    if($('dmMenuPopupFormat_' + formatId + '_' + priceId)) {
        $('dmMenuPopupFormat_' + formatId + '_' + priceId).className += ' formatLegoSelected';
    }
    // Расставляем цены дополнительных ингридиентов
    //$$('#dmMenuPopupIncludeList b[id^=dmMenuPriceAddition_]').each(function(el) {
    $$('#dmMenuPopupIncludeList span').each(function(el) {
    	//alert(el.id);
    	var additionId = parseInt(el.id.replace('dmMenuPriceAddition_', ''));
    	if(typeof dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] != 'undefined') {
    	    el.innerHTML = dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'];
    	} else {
    		el.innerHTML = dmMenu['PRICES'][priceId]['PROPERTY_PRICE_ADDIT_VALUE'];
    	}
    });
    this.saveCookies();
}

dmPageClass.prototype.showSimpleInfo = function(elementId) {
    var priceAdditional = 0;
    var notPriced = 0;
    var additionId;
    $$('#right input[id^=dmMenuInclude_' + elementId + '_]').each(function(el) {
      
      if(el.checked) {
        additionId = el.id.replace('dmMenuInclude_' + elementId + '_', '') - 0;
        if(additionId) {
          if(dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE']) {
            priceAdditional += dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] - 0;
          } else {
            ++notPriced;
          }
        }
      }
    });
    $$('#right b[id^=dmMenuPrice_' + elementId + '_]').each(function(el) {
      var priceLocal = 0;
      var priceId = el.id.replace('dmMenuPrice_' + elementId + '_', '') - 0;
      if(priceId) {
        var selectName = 'dmMenuFree_' + elementId + '_' + priceId;
        if($(selectName)  && $(selectName).value > 0) {
          additionId = $(selectName).value;
          if(dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE']) {
            //priceAdditional += dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] - 0;
          } else {
            //++notPriced;
          }
        }
//        if(notPriced > 0 && dmMenu['PRICES'][priceId]['PROPERTY_PRICE_ADDIT_VALUE'] > 0) {
        if(notPriced > 0 && dmMenu['PRICES'][priceId]['PROPERTY_ADDIT_PRICE_VALUE'] > 0) {
          priceAdditional += (notPriced * (dmMenu['PRICES'][priceId]['PROPERTY_ADDIT_PRICE_VALUE']-0)) - 0;
        }
        var priceBase = dmMenu['PRICES'][priceId]['NAME'] - 0;

        $('dmMenuPrice_' + elementId + '_' + priceId).innerHTML = priceBase + priceAdditional - 0;
      }
    });
}

dmPageClass.prototype.showBasket = function() {
	if(this.basket.length > 0 || 1) {
	    var price = 0;
	    for(i in this.basket) {
	        if(typeof this.basket[i].price != 'undefined') {
			  price += parseInt(this.basket[i].count-0) * (parseInt(this.basket[i].price-0) + parseInt(this.basket[i].priceAdditions-0));
			}
        }
	if($('basketPrice')) {
	  $('basketPrice').innerHTML = price;
	}
		
	try {
        if(price || Cookie.read('deliveryStreetId')) {
	        $('order').style.display = 'none';
			$('basket').style.display = 'block';
	     }
		else {
  			$('order').style.display = 'block';
			$('basket').style.display = 'none';
		}
		} catch(oh) {}
	}
	else {
		$('basket').style.display = 'none';
		$('order').style.display = 'block';
	}
}

dmPageClass.prototype.addPizza = function(formatId) {
	var elementId = this.getElementId();
    if(!elementId) {
        alert('Ошибка добавления пицы.\nПопробуйте перезагрузить страницу');
    	return false;
    }
    if(!this.pizzas[elementId]) {
        alert('Ошибка добавления пицы.\nПопробуйте перезагрузить страницу');
        return false;
    }
    this.pizzas[elementId].count = $('dmMenuPopupFormatInupt_'+formatId).value;
    this.pizzas[elementId].format = formatId;
    
    var price = dmMenu['PRICES'][dmMenu['PRICES2LIST'][elementId][formatId]];
    this.pizzas[elementId].price = price['NAME'];
    this.pizzas[elementId].priceAdditions = 0;

    for(k in this.pizzas[elementId].free) {
        if(this.pizzas[elementId].free[k] > 0) {
            if(typeof dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']) > 0) {
              this.pizzas[elementId].priceAdditions += parseInt(this.pizzas[elementId].free[k]) * parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']);
            } else {
              this.pizzas[elementId].priceAdditions += parseInt(this.pizzas[elementId].free[k]) * parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']);
            }
        } 
    }
    for(k in this.pizzas[elementId].include) {
        if(this.pizzas[elementId].include[k] > 0) {
            if(typeof dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']) > 0) {
              this.pizzas[elementId].priceAdditions += parseInt(this.pizzas[elementId].include[k]) * parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']);
            } else {
              this.pizzas[elementId].priceAdditions += parseInt(this.pizzas[elementId].include[k]) * parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']);
            }
        } 
    }
    for(k in this.pizzas[elementId].exclude) {
    	if(this.pizzas[elementId].exclude[k] > 1) {
            if(typeof dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']) > 0) {
              this.pizzas[elementId].priceAdditions += (parseInt(this.pizzas[elementId].exclude[k])-1) * parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']);
            } else {
              this.pizzas[elementId].priceAdditions += (parseInt(this.pizzas[elementId].exclude[k])-1) * parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']);
            }
    	} 
    }
    $('dmMenuPopup').style.display = 'none';
    $('leftCitySelect').style.display = 'none';
    //this.hideOverflow();
    this.showPopupOk();
    this.saveCookies();
    this.loadCookies();
    this.showBasket();
    this.pizzas[elementId] = new dmPizza(elementId);
    $$('#dmMenuPopup input[id^=dmMenuPopupFormatInupt_]').each(function(el) {
      el.value = 1;
    });
}

dmPageClass.prototype.addLego = function() {
    if(!this.pizzas[legoId]) {
        alert('Ошибка добавления пицы.\nПопробуйте перезагрузить страницу');
        return false;
    }
    var formatId;
    this.pizzas[legoId].count = 1;
    $$('#lego input[id^=dmLegoFormat_]').each(function(inp) {
    	if(inp.checked) {
    	  var str = inp.id.replace('dmLegoFormat_', '');
    	  formatId = str.substr(0, str.indexOf('_'));
    	  priceId = str.substr(str.indexOf('_')+1, 100);
    	}
    });
    this.pizzas[legoId].format = formatId;
//    alert(legoId);
//    alert(print_r(dmMenu['PRICES2LIST'][legoId]));
    if(typeof dmMenu['PRICES2LIST'][legoId] == 'undefined') {
        return false;
    }
    var price = dmMenu['PRICES'][dmMenu['PRICES2LIST'][legoId][formatId]];
    this.pizzas[legoId].price = price['NAME'];
    this.pizzas[legoId].priceAdditions = 0;
    for(k in this.pizzas[legoId].include) {
            if(typeof dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']) > 0) {
      	      this.pizzas[legoId].priceAdditions += parseInt(this.pizzas[legoId].include[k]-0) * parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']-0);
            } else {
              this.pizzas[legoId].priceAdditions += parseInt(this.pizzas[legoId].include[k]-0) * parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']-0);
            }
    }
    for(k in this.pizzas[legoId].free) {
    	if(this.pizzas[legoId].free[k] > 0 && $('dmMenuPopupFreeCheck_1_' + k) && $('dmMenuPopupFreeCheck_1_' + k).checked) {
            if(typeof dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']) > 0) {
           	  this.pizzas[legoId].priceAdditions += (parseInt(this.pizzas[legoId].free[k])-0) * parseInt(dmMenu['ADDITIONS'][k]['PROPERTY_PRICE_VALUE']-0);
            } else {
              this.pizzas[legoId].priceAdditions += (parseInt(this.pizzas[legoId].free[k])-0) * parseInt(price['PROPERTY_PRICE_ADDIT_VALUE']-0);
            }
    	} 
    }
    //$('dmMenuPopup').style.display = 'none';
    //$('dmMenuPopupOverflow').style.display = 'none';
    //$('leftCitySelect').style.display = 'none';
    this.showPopupOk();
    this.saveCookies();
    this.loadCookies();
    this.showBasket();
    this.pizzas[legoId] = new dmPizza(legoId);
    this.showLegoInfo();
    //document.location = '/ru/menu/lego/ok/';
}

dmPageClass.prototype.addNonPizza = function(elementId, priceId) {
	if(typeof this.pizzas[elementId] == 'undefined') {
    	this.pizzas[elementId] = new dmPizza(elementId);
    }
	if(!this.pizzas[elementId]) {
        alert('Ошибка добавления.\nПопробуйте перезагрузить страницу');
        return false;
    }
    this.pizzas[elementId].count = $('dmMenuPriceCount_'+elementId+'_'+priceId).value;
    this.pizzas[elementId].format = -priceId;

    var price = dmMenu['PRICES'][dmMenu['PRICES2LIST'][elementId][-priceId]];
    this.pizzas[elementId].price = price['NAME'];
    this.pizzas[elementId].priceAdditions = 0;
    $$('input[id^=dmMenuInclude_'+elementId+'_]').each(function(el) {
    	if(el.checked) {
    		var additionId = el.id.replace('dmMenuInclude_'+elementId+'_', '') - 0;
    		if(additionId) {
                if(typeof price['PROPERTY_PRICE_ADDIT_VALUE'] != 'undefined' || 1) {
    		        if(typeof dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE']) > 0) {
    		          dmPage.pizzas[elementId].priceAdditions += dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] - 0;
   		            } else {
   		              dmPage.pizzas[elementId].priceAdditions += price['PROPERTY_PRICE_ADDIT_VALUE'] - 0;;
    		        }
    			}
    			//dmPage.pizzas[elementId].setAddition('include', additionId, 1);
    			dmPage.pizzas[elementId].include[additionId] = 1;
    		}
    	}
    });
    $$('input[id^=dmMenuExclude_'+elementId+'_]').each(function(el) {
		var additionId = el.id.replace('dmMenuExclude_'+elementId+'_', '') - 0;
		if(additionId) {
        	if(el.checked) {
    			//dmPage.pizzas[elementId].setAddition('exclude', additionId, 1);
    			dmPage.pizzas[elementId].exclude[additionId] = -1;
    		}
        	else {
        		dmPage.pizzas[elementId].exclude[additionId] = 0;
        	}
    	}
    });
    if($('dmMenuFree_'+elementId+'_'+priceId) && $('dmMenuFree_'+elementId+'_'+priceId).value-0) {
        additionId = $('dmMenuFree_'+elementId+'_'+priceId).value-0;
    	dmPage.pizzas[elementId].free[additionId] = 1;
        if(typeof dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] != 'undefined' && parseInt(dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE']) > 0) {
            dmPage.pizzas[elementId].priceAdditions += dmMenu['ADDITIONS'][additionId]['PROPERTY_PRICE_VALUE'] - 0;
        } else {
            dmPage.pizzas[elementId].priceAdditions += price['PROPERTY_PRICE_ADDIT_VALUE'] - 0;;
        }

    	//dmPage.pizzas[elementId].setAddition('free', $('dmMenuFree_'+elementId).value-0, 1);
    }
    this.showPopupOk();
    this.saveCookies();
    this.loadCookies();
    this.showBasket();
    this.pizzas[elementId] = new dmPizza(elementId);
}


dmPageClass.prototype.tryShowOverflow = function() {
	if($('dmMenuPopupOverflow').style.display == 'block') {
      $('dmMenuPopupOverflow').style.display = 'none';
	  //$('dmMenuPopupOverflow').style.height = (document.documentElement.scrollHeight + 42) + 'px';
       $('dmMenuPopupOverflow').style.height = (document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement. scrollHeight : document.body. scrollHeight); 
      //$('dmMenuPopupOverflow').style.height = ($('main').scrollHeight + 42) + 'px';
	  $('dmMenuPopupOverflow').style.display = 'block';
	}
}

dmPageClass.prototype.showOverflow = function() {
	$('dmMenuPopupOverflow').style.display = 'block';
	$('dmMenuPopupOverflow').style.height = ($('main').scrollHeight + 42) + 'px';
}

dmPageClass.prototype.hideOverflow = function() {
	$('dmMenuPopupOverflow').style.display = 'none';        
}

dmPageClass.prototype.showPopupOk = function() {
	this.showOverflow();
	var formTop = (140 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop));
    if(formTop > ($('main').scrollHeight - 720)) {
    	formTop = $('main').scrollHeight - 720;
    }
    $('dmMenuPopupOk').style.top = formTop + 'px';
	$('dmMenuPopupOk').style.display = 'block';
}

dmPageClass.prototype.hidePopupOk = function() {
	if($('dmMenuPopupOk')) {
                if(document.location.href.indexOf('/menu/lego') > -1) {
                    document.documentElement.style.cursor = 'wait';
                    $('dmMenuPopupOverflow').style.cursor = 'wait';
                    setTimeout('document.location = document.location;', 0);
                    //this.showLegoInfo(6);
                } else {
    		    
                }
                $('dmMenuPopupOk').style.display = 'none';
	}
}

//pizzaId, formatId, hash
dmPageClass.prototype.removePizza = function(key) {
	Cookie.dispose('po_'+key, {path: '/'});
	var cookie = JSON.decode(Cookie.read('dmPizzaListOrderedList'));
	for(var i in cookie) {
		if(cookie[i] == 'po_'+key) {
		  delete cookie[i];
		}
	}
	Cookie.write('dmPizzaListOrderedList', JSON.encode(cookie), {path: '/'});
        //this.loadCookies();
	document.location = document.location;
}

dmPageClass.prototype.removePizzaAll = function() {
    var cookie = JSON.decode(Cookie.read('dmPizzaListOrderedList'));
	for(var i in cookie) {
	    if(typeof cookie[i] == 'string' && cookie[i].indexOf('po_') > -1) {  
            Cookie.dispose(cookie[i], {path: '/'});
        }
	}
	Cookie.write('dmPizzaListOrderedList', '[]', {path: '/'});
	document.location = document.location; 
}

dmPageClass.prototype.recount = function() {
    var cookie = JSON.decode(Cookie.read('dmPizzaListOrderedList'));
    var pizza;
	for(var i in cookie) {
		if($('pizzaOrderedCount_' + cookie[i])) {
			pizza = JSON.decode(Cookie.read(cookie[i]));
			pizza.co = new Number($('pizzaOrderedCount_' + cookie[i]).value);
			if(pizza.count < 1) {
				pizza.count = 1;
			}
			Cookie.write(cookie[i], JSON.encode(pizza), {path: '/'});
		}
	      //Cookie.dispose(cookie[i]);
	}
//	Cookie.write('dmPizzaListOrderedList', JSON.encode(new Array()), {path: '/'});
	document.location = document.location;
}

dmPageClass.prototype.saveCookies = function(formatId) {
	if(typeof this.cookies == 'undefined' || this.cookies == null) {
        this.cookies = new Array();
    }
    for(var i in this.pizzas) {
        if(typeof this.pizzas[i].id == 'undefined') {
            continue;
        }
        var elementId = i;
        // Сжимаем пиццу
        var savePizza = new Object();
        savePizza.id = this.pizzas[elementId].id;
        //savePizza.th = this.pizzas[elementId].id;
	    if(this.pizzas[elementId].price) {
          savePizza.pr = this.pizzas[elementId].price;
	    }
	    if(this.pizzas[elementId].priceAdditions) {
          savePizza.pa = this.pizzas[elementId].priceAdditions;
	    }
	    if(this.pizzas[elementId].format) {
          savePizza.fo = this.pizzas[elementId].format;
	    }
	    if(this.pizzas[elementId].count) {
          savePizza.co = this.pizzas[elementId].count;
	    }	
        for(j in this.pizzas[elementId].include) {
            if(this.pizzas[elementId].include[j] != null && this.pizzas[elementId].include[j] != '') {
		      if(typeof savePizza.ic == 'undefined') savePizza.ic = new Object();
        	  savePizza.ic[j] = this.pizzas[elementId].include[j];
        	}
        }
        for(j in this.pizzas[elementId].exclude) {
        	if(this.pizzas[elementId].exclude[j] != null && this.pizzas[elementId].exclude[j] != 1) {
		  if(typeof savePizza.ex == 'undefined') savePizza.ex = new Object();
        	  savePizza.ex[j] = this.pizzas[elementId].exclude[j];
        	}
        }
        for(j in this.pizzas[elementId].free) {
        	if(this.pizzas[elementId].free[j] != null && this.pizzas[elementId].free[j] != '') {
		  if(typeof savePizza.fr == 'undefined') savePizza.fr = new Object();
        	  savePizza.fr[j] = this.pizzas[elementId].free[j];
        	}
        }
        // Если это заказ
        if(this.pizzas[elementId].count) {
            var nc = (new String((new Date).getTime())).substr(8,4);
	        this.cookiesOrdered.push('po_'+elementId+'_'+this.pizzas[elementId].format+'_'+nc);
            Cookie.write('po_'+elementId+'_'+this.pizzas[elementId].format+'_'+nc, JSON.encode(savePizza), {path: '/'});
            Cookie.write('dmPizzaListOrderedList', JSON.encode(this.cookiesOrdered), {path: '/'});
            this.pizzas[elementId].count = 0;
            //savePizza.co = 0;
	    //Cookie.dispose('dmPizza_'+elementId);
	    this.pizzas[elementId] = new dmPizza(elementId);	    
	    savePizza = {'id':elementId};
	    
        }
        var isInList = false;
        for(var j=0; j<this.cookies.length; j++) {
        	if(this.cookies[j] == 'dmPizza_'+elementId) {
        		isInList = true;
        		break;
        	} 
        }
        if(!isInList) {
            this.cookies.push('dmPizza_'+elementId);
        }
        Cookie.write('dmPizza_'+elementId, JSON.encode(savePizza), {path: '/'});
        Cookie.write('dmPizzaList', JSON.encode(this.cookies), {path: '/'});
    }
}

dmPageClass.prototype.loadCookies = function() {
	//return false;
    this.cookies = JSON.decode(Cookie.read('dmPizzaList'));
    if(!this.cookies) {
        this.cookies = new Array();
    }
    this.cookiesOrdered = JSON.decode(Cookie.read('dmPizzaListOrderedList'));
    if(!this.cookiesOrdered) {
        this.cookiesOrdered = new Array();
    }
    var pizza;
    var data;
    for(var i=0; i<this.cookies.length; i++) {
        pizza = JSON.decode(Cookie.read(this.cookies[i]));
        if(pizza.id) {
            //this.pizzas[pizza.id] = pizza;
            this.pizzas[pizza.id] = new dmPizza(pizza.id);
            for(k in pizza) {
            	if(k == 'id') this.pizzas[pizza.id].id = pizza[k];
            	if(k == 'pr') this.pizzas[pizza.id].price = pizza[k];
            	if(k == 'pa') this.pizzas[pizza.id].priceAdditions = pizza[k];
            	if(k == 'fo') this.pizzas[pizza.id].format = pizza[k];
            	if(k == 'co') this.pizzas[pizza.id].count = pizza[k];
            	if(k == 'id') this.pizzas[pizza.id].id = pizza[k];
            	if(k == 'ic') { 
	                for(j in pizza.ic) {
	                	this.pizzas[pizza.id].include[j] = pizza.ic[j];
	                }
            	}
            	if(k == 'ex') { 
	                for(j in pizza.ex) {
	                	this.pizzas[pizza.id].exclude[j] = pizza.ex[j];
	                }
            	}
            	if(k == 'fr') { 
	                for(j in pizza.fr) {
	                	this.pizzas[pizza.id].free[j] = pizza.fr[j];
	                }
            	}
/*
            	if(k == 'excludeObj') {
            		//this.pizzas[pizza.id].exclude = new Array();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.pizzas[pizza.id].exclude[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
            	}
            	else if(k == 'includeObj') {
            		//this.pizzas[pizza.id].include = new Array();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.pizzas[pizza.id].include[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
            	}
            	else if(k == 'freeObj') {
            		//this.pizzas[pizza.id].free = new Array();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.pizzas[pizza.id].free[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
                    //alert(print_r(this.pizzas[pizza.id].free));
            	}
            	else {
*/
              	  //this.pizzas[pizza.id][k] = pizza[k];
//            	}
            }
        }
    }
    this.basket = new Array();
    for(var i=0; i<this.cookiesOrdered.length; i++) {
        if(typeof this.cookiesOrdered[i] == 'undefined' || this.cookiesOrdered[i] == '' || this.cookiesOrdered[i] == null) continue;
    	var hash = this.cookiesOrdered[i].substr(this.cookiesOrdered[i].lastIndexOf('_')+1, 5);
    	//this.cookiesOrdered[i] = this.cookiesOrdered[i].replace('_'+hash, '');
	if(typeof this.cookiesOrdered[i] == 'undefined') continue;
    	pizza = JSON.decode(Cookie.read(this.cookiesOrdered[i]));
        if(pizza && pizza.id && pizza.co) {
	    var elementId = 'v' + pizza.id + '_' + pizza.fo+'_'+hash;
	    this.basket[elementId] = new dmPizza(pizza.id);
            for(k in pizza) {
            	if(k == 'id') this.basket[elementId].id = pizza[k];
            	if(k == 'pr') this.basket[elementId].price = pizza[k];
            	if(k == 'pa') this.basket[elementId].priceAdditions = pizza[k];
            	if(k == 'fo') this.basket[elementId].format = pizza[k];
            	if(k == 'co') this.basket[elementId].count = pizza[k];
            	if(k == 'id') this.basket[elementId].id = pizza[k];
            	if(k == 'ic') { 
	                for(j in pizza.ic) {
	                	this.basket[elementId].include[j] = pizza.ic[j];
	                }
            	}
            	if(k == 'ex') { 
	                for(j in pizza.ex) {
	                	this.basket[elementId].exclude[j] = pizza.ex[j];
	                }
            	}
            	if(k == 'fr') { 
	                for(j in pizza.fr) {
	                	this.basket[elementId].free[j] = pizza.fr[j];
	                }
            	}
/*
            	if(k == 'excludeObj') {
            		this.basket[elementId].exclude = new Object();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.basket[elementId].exclude[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
            	}
            	else if(k == 'includeObj') {
            		this.basket[elementId].include = new Object();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.basket[elementId].include[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
            	}
            	else if(k == 'freeObj') {
            		this.basket[elementId].free = new Object();
            		for(l in pizza[k]) {
            	      if(l.indexOf('v') == 0) {
            	    	  this.basket[elementId].free[l.replace('v', '')] = pizza[k][l];
            	      }
            		}
            	}
            	else {
*/
//              	  this.basket[elementId][k] = pizza[k];
//            	}
            }
/*
        	this.basket[pizza.id] = new dmPizza(pizza.id);
            this.basket[pizza.id].include = pizza.include;
            this.basket[pizza.id].exclude = pizza.exclude;
            this.basket[pizza.id].free = pizza.free;

            this.basket[pizza.id].price = 0;
            this.basket[pizza.id].priceAdditions = 0;
            this.basket[pizza.id].count = 0;
            this.basket[pizza.id].format = 0;
*/
/*
            this.include = pizza.include;
            this.exclude = pizza.exclude;
            this.free = pizza.free;

            this.price = 0;
            this.priceAdditions = 0;
            this.count = 0;
            this.format = 0;
*/
        }
    }
    
    this.showBasket();
}

dmPageClass.prototype.showAddition = function(id) {
    if(typeof dmMenu['ADDITIONS'][id] == 'undefined') {
        return false;
    }
    var element = dmMenu['ADDITIONS'][id];
    $('dmMenuAdditionId').value = id;
    $('dmMenuAdditionText').innerHTML = element['NAME'];
    $('dmMenuAdditionImage').src = '/resize/square/70' + element['PREVIEW_PICTURE'];
    $('dmMenuAdditionQuantity').value = 1;
    if($('dmMenuPopupIncludeQuantity_' + id)) {
    	$('dmMenuAdditionQuantity').value = $('dmMenuPopupIncludeQuantity_' + id).value;
    }
    if($('dmMenuAdditionQuantity').value > 1) {
        $('dmMenuAdditionMinus').style.display = 'block';
        $('dmMenuAdditionMinusHolder').style.display = 'none';
    } else {
        $('dmMenuAdditionMinus').style.display = 'none';
        $('dmMenuAdditionMinusHolder').style.display = 'block';
    }
    if($('dmMenuAdditionQuantity').value < this.maxAddition) {
        $('dmMenuAdditionPlus').style.display = 'block';
        $('dmMenuAdditionPlusHolder').style.display = 'none';
    } else {
        $('dmMenuAdditionPlus').style.display = 'none';
        $('dmMenuAdditionPlusHolder').style.display = 'block';
    }
    $('dmMenuAddition').style.display = 'block';
    if(!$('dmMenuAdditionOverlay')) {
        var of = document.createElement('div');
        of.id = 'overflowModal';
        of.className = 'dmMenuPopupOverflowClass';
        of.innerHTML = '&nbsp;'
        of.style.display = 'block';
        of.style.zIndex = '5';
        of.onclick = function() {
            $('dmMenuAddition').style.display = 'none';
            this.style.display = 'none';
            $$('select[id^=dmMenuPopupFreeSelect_').each(function(el) {
                el.style.display = 'block';
            });

        }
        of.id = 'dmMenuAdditionOverlay';
        document.body.appendChild(of);
    } else {
        $('dmMenuAdditionOverlay').style.display = 'block';
    }
    var t = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var h = (document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight); 
    var a = (document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement. scrollHeight : document.body. scrollHeight); 
    $('dmMenuAddition').style.top = Math.round(h/2) + t - 100 + 'px';
    $('dmMenuAdditionOverlay').style.height = a + 'px';
    document.body.appendChild($('dmMenuAddition'));
    $$('select[id^=dmMenuPopupFreeSelect_').each(function(el) {
        el.style.display = 'none';
    });
}

dmPageClass.prototype.changePopupAddition = function(div) {
    $('dmMenuAdditionQuantity').value = parseInt($('dmMenuAdditionQuantity').value) + parseInt(div);
    if($('dmMenuAdditionQuantity').value > 1) {
        $('dmMenuAdditionMinus').style.display = 'block';;
        $('dmMenuAdditionMinusHolder').style.display = 'none';;
    }
    else {
        $('dmMenuAdditionMinus').style.display = 'none';;
        $('dmMenuAdditionMinusHolder').style.display = 'block';;
    }
    if($('dmMenuAdditionQuantity').value < this.maxAddition) {
        $('dmMenuAdditionPlus').style.display = 'block';;
        $('dmMenuAdditionPlusHolder').style.display = 'none';;
    }
    else {
        $('dmMenuAdditionPlus').style.display = 'none';;
        $('dmMenuAdditionPlusHolder').style.display = 'block';;
    }
}

function mapSimpleOverlay(geoPoint, name, link) {
    var map, _this = this, offset = new YMaps.Point(-10, -29);

    this.onAddToMap = function (pMap, parentContainer) {
        map = pMap;
        parentContainer.appendChild(getElement());
        this.onMapUpdate();
    };

    this.onRemoveFromMap = function () {
        if (getElement().parentNode) {
            getElement().parentNode.removeChild(getElement());
        }
    };

    this.onMapUpdate = function () {
        var position = map.converter.coordinatesToMapPixels(geoPoint).moveBy(offset);
        getElement().style.left = position.x + 'px';
        getElement().style.top = position.y + 'px';
    };

    this.openBalloon = function () {
        link.className = "active";
        getElement().style.display = "none";
        map.openBalloon(geoPoint, name, {onClose: function () {
            link.className = getElement().style.display = "";
        }});
    };

    function getElement () {
        var element = document.createElement('div');
        element.className = 'overlay';
        element.onclick = function () {
            _this.openBalloon();
        }
        return (getElement = function () {return element})();
    }
}

dmPageClass.prototype.mapCreateOverlay = function(place) {
    var link = document.createElement('a');
    var newOverlay = new mapSimpleOverlay(place.point, place.name, link);
    link.href = '#';
    link.innerHTML = place.name;
    link.onclick = function () {
        if (link.className == "active") return;
        newOverlay.openBalloon();
    };
    return newOverlay;
}

dmPageClass.prototype.mapShowList = function(coords) {
    this.map = new YMaps.Map(document.getElementById("dmMap"));
    
//    var spans = new Array();
    if(typeof coords == 'object' && coords.length > 0) {
	    var bounds = new YMaps.GeoCollectionBounds;
	    for(var i=0; i<coords.length; i++) {
    		bounds.add(new YMaps.GeoPoint(coords[i][1], coords[i][0]));
	    }
        if(coords.length == 1) {
            var zoom = 11;
        }
        else {
            var zoom = bounds.getMapZoom(this.map);
        }
	    this.map.setCenter(bounds.getCenter(), zoom);
	    this.map.addControl(new YMaps.TypeControl());
	    this.map.addControl(new YMaps.ToolBar());
	    this.map.addControl(new YMaps.Zoom());
	    this.map.addControl(new YMaps.ScaleLine());

	    var placemarks = new Array();
	    for(var i=0; i<coords.length; i++) {
            var point = new YMaps.GeoPoint(coords[i][1], coords[i][0]);
            var placemark = new YMaps.Placemark(point);
            placemark.name = coords[i][2];
            this.map.addOverlay(placemark);  
	    	//	    	this.map.addOverlay(this.mapCreateOverlay({point:new YMaps.Placemark(new YMaps.GeoPoint(coords[i][1], coords[i][0])), name:coords[i][2]}));
	    }
//	    this.map.addOverlay(placemarks);
	    
/*
//		this.map.openBalloon(new YMaps.GeoPoint(coords[i][1], coords[i][0]), document.createElement('span').innerHTML=coords[i][2]);
*/
    
    }
    else {
    	this.map.setCenter(new YMaps.GeoPoint(37.64, 55.76), 10);
    }
}

dmPageClass.prototype.showAddress = function(cityHolder, street) {
/*
	if(!$(streetHolder)) {
		return true;
	}
	var street = $(streetHolder).value;
	if(street.length < 2) {
		return false;
	}
	var cityId = $(cityHolder).value;
	if(!cityId) {
		return false;
	}
	var jsonRequest = new Request.JSON({url: "/ajax.php", onSuccess: function(streets){
		if(streets) {
			var div = document.createElement('div');
			var.style.position = 'absolute';
			var.style.left = 'absolute';
		}
	}}).get({'CITY': cityId, 'NAME': street});
*/
}

dmPageClass.prototype.go2Delivery = function() {
  Cookie.write('orderName', $('orderName').value, {path : '/'});
  Cookie.write('orderEmail', $('orderEmail').value, {path : '/'});
  Cookie.write('orderPhone', $('orderPhone').value, {path : '/'});
  document.location.href  = '/ru/delivery/?CITY_ID='+$('orderCity').value+'&STREET='+($('orderStreetName').value);
}

function dmPreloaderClass() {
  this.images = new Array(); 
}

dmPreloaderClass.prototype.load = function(src) {
  var img = new Image();
  img.src = src;
  this.images.push(img);
}

function print_r(arr, level) {
    var print_red_text = "";
    if(!level) level = 0;
    var level_padding = "";
    for(var j=0; j<level+1; j++) level_padding += "    ";
    if(typeof(arr) == 'object') {
        for(var item in arr) {
            var value = arr[item];
            if(typeof(value) == 'object') {
                print_red_text += level_padding + "'" + item + "' :\n";
                print_red_text += print_r(value,level+1);
		} 
            else 
                print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
        }
    } 

    else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
    return print_red_text;
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/images/image.text.php?text=Обзор&type=8';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		//if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

var dmPage = new dmPageClass();
var dmPreloader = new dmPreloaderClass();
setTimeout("dmPreloader.load('/images/topmenu_1_1.gif');", 1000);
setTimeout("dmPreloader.load('/images/topmenu_2_1.gif');", 1000);
setTimeout("dmPreloader.load('/images/topmenu_3_1.gif');", 1000);
setTimeout("dmPreloader.load('/images/topmenu_4_1.gif');", 1000);
setTimeout("dmPreloader.load('/images/topmenu_5_1.gif');", 1000);
setTimeout("dmPreloader.load('/images/pizza_delete.gif');", 2000);
