﻿// Script to display last banner and ads
// Used in: master and default page

var constBannerWidthLimit = 920; 
var constAdsWidthLimit = 840;

// handles the body OnResize event
function OnBodyResize() {
    AdjustTopBanners();
    AdjustBottomAds();
}

function GetTopBannerPanelInfo() {
    var result = new Object();
    result.PanelID = 'panelBannerArea';
    result.LastBannerID = 'lastTopBanner';
    return result; 
}

/// Adjust count of the banners in the top
function AdjustTopBanners() {
    var info = GetTopBannerPanelInfo();
    var divPanelBanners = document.getElementById(info.PanelID);
    var tdBannerItem = document.getElementById(info.LastBannerID);
    if (divPanelBanners && tdBannerItem) {
        if (divPanelBanners.offsetWidth >= constBannerWidthLimit) { tdBannerItem.style.display = 'block'; }
        else { tdBannerItem.style.display = 'none'; }
    }
}

// Adjust the count of ads in the bottom
// It depends of "GetAdsPanelInfo"
function AdjustBottomAds() {
    if (typeof GetAdsPanelInfo == 'function') {
        var info = GetAdsPanelInfo();
        var divAdsPanel = document.getElementById(info.PanelID);
        var tdAdsItem = document.getElementById(info.LastAdsID);
        var hfLastVisible = document.getElementById(GetHiddenFieldCurrentAdsCountID());
        if (divAdsPanel && tdAdsItem && hfLastVisible) {
            if (divAdsPanel.offsetWidth >= constAdsWidthLimit) {
                tdAdsItem.style.display = 'block';
                hfLastVisible.value = "1";
            }
            else {
                tdAdsItem.style.display = 'none';
                hfLastVisible.value = "0";
            }
        }
    }
}




// Script to display goods image thumbnail, goods aviability in other cities,...
// Used in: catalog

var __isIE = navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;


// Image Panel
var ImagePanelArea = null; // div area
var ImagePanel = null;     // div image
var ImagePanelOffsetX = 0; // panel X offset from source
var ImagePanelOffsetY = 0; // panel Y offset from source

// Other City Panel
var OtherCityPanelArea = null; // div area
var OtherCityPanelList = null;     // div image
var OtherCityPanelOffsetX = 0; // panel X offset from source
var OtherCityPanelOffsetY = 0; // panel Y offset from source



function __parseBorderWidth(width) {
    var res = 0;
    if (typeof (width) == "string" && width != null && width != "") {
        var p = width.indexOf("px");
        if (p >= 0) { res = parseInt(width.substring(0, p)); } else { res = 1; }
    }
    return res;
}

function __getBorderWidth(element) {
    var res = new Object();
    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
    if (window.getComputedStyle) {
        //for Firefox
        var elStyle = window.getComputedStyle(element, null);
        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));
        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));
        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));
        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));
    }
    else {
        //for other browsers
        res.left = __parseBorderWidth(element.style.borderLeftWidth);
        res.top = __parseBorderWidth(element.style.borderTopWidth);
        res.right = __parseBorderWidth(element.style.borderRightWidth);
        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
    }

    return res;
}

function getElementAbsolutePos(element) {
    var res = new Object();
    res.x = 0;
    res.y = 0;
    res.width = 0;
    res.height = 0;
    if (element != null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;
        res.width = element.offsetWidth;
        res.height = element.offsetHeight;

        var offsetParent = element.offsetParent;
        var parentNode = element.parentNode;
        var borderWidth = null;


        while (offsetParent != null) {
            res.x += offsetParent.offsetLeft;
            res.y += offsetParent.offsetTop;

            var parentTagName = offsetParent.tagName.toLowerCase();

            if ((__isIE && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {
                borderWidth = __getBorderWidth(offsetParent);
                res.x += borderWidth.left;
                res.y += borderWidth.top;
            }

            if (offsetParent != document.body && offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }

            //next lines are necessary to support FireFox problem with offsetParent
            if (!__isIE) {
                while (offsetParent != parentNode && parentNode != null) {
                    res.x -= parentNode.scrollLeft;
                    res.y -= parentNode.scrollTop;

                    if (__isFireFoxOld) {
                        borderWidth = __getBorderWidth(parentNode);
                        res.x += borderWidth.left;
                        res.y += borderWidth.top;
                    }
                    parentNode = parentNode.parentNode;
                }
            }

            parentNode = offsetParent.parentNode;
            offsetParent = offsetParent.offsetParent;
        }
    }
    return res;
}

function GetWindowHeight() {
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        return window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        return document.body.clientHeight;
    }
    else return 0;
}

function GetScrollTopPosition() {
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        return window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        return document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        return document.documentElement.scrollTop;
    }
    else return 0;
}

function WhenFloatMouseOver(obj, GoodsID) {
    if (ImagePanelArea && ImagePanel) {
        var pos = getElementAbsolutePos(obj);
        // download image
        ImagePanel.style.backgroundImage = 'url(/GetGoodsImage.aspx?id=' + GoodsID + '&mode=thumb)';

        var winH = GetWindowHeight(); // window Height
        var scrOfY = GetScrollTopPosition(); // window vertical scroll

        if ((pos.y + ImagePanelOffsetY + ImagePanelArea.offsetHeight - scrOfY) > winH) {
            pos.y += (winH - (pos.y + ImagePanelOffsetY + ImagePanelArea.offsetHeight - scrOfY));
        }
        else pos.y += ImagePanelOffsetY;

        pos.x += ImagePanelOffsetX;

        ImagePanelArea.style.left = pos.x + 'px';
        ImagePanelArea.style.top = pos.y + 'px';
        ImagePanelArea.style.visibility = 'visible';
    }
}

function WhenFloatMouseOut() {
    if (ImagePanelArea && ImagePanel) {
        ImagePanelArea.style.visibility = 'hidden';
        ImagePanel.style.backgroundImage = '';
    }
}

function WhenMouseOverOtherCity(obj) {
    if (OtherCityPanelArea && OtherCityPanelList) {

        // copy city list
        OtherCityPanelList.innerHTML = obj.getAttribute('CityList');

        var pos = getElementAbsolutePos(obj);

        var winH = GetWindowHeight(); // window Height
        var scrOfY = GetScrollTopPosition(); // window vertical scroll

        if ((pos.y + OtherCityPanelOffsetY + OtherCityPanelArea.offsetHeight - scrOfY) > winH) {
            pos.y += (winH - (pos.y + OtherCityPanelOffsetY + OtherCityPanelArea.offsetHeight - scrOfY));
        }
        else pos.y += OtherCityPanelOffsetY;

        pos.x += OtherCityPanelOffsetX;

        OtherCityPanelArea.style.left = pos.x + 'px';
        OtherCityPanelArea.style.top = pos.y + 'px';


        OtherCityPanelArea.style.visibility = 'visible';
    }
}

function WhenMouseOutOtherCity() {
    if (OtherCityPanelArea) {
        OtherCityPanelArea.style.visibility = 'hidden';
    }
}


function InitImagePanel(sourceImagePanel, sourceImagePanelImage, OffsetX, OffsetY) {
    // init
    ImagePanelArea = document.getElementById(sourceImagePanel);
    ImagePanel = document.getElementById(sourceImagePanelImage);
    ImagePanelOffsetX = OffsetX;
    ImagePanelOffsetY = OffsetY;
}

function InitOtherCityPanel(sourceOtherCityPanel, sourceOtherCityList, OffsetX, OffsetY) {
    // init
    OtherCityPanelArea = document.getElementById(sourceOtherCityPanel);
    OtherCityPanelList = document.getElementById(sourceOtherCityList);
    OtherCityPanelOffsetX = OffsetX;
    OtherCityPanelOffsetY = OffsetY;
}



// Shows "change City" panel
function ShowChangeCityPanel() {

    var panel = document.getElementById('pnChangeCityPanel');
    var cityPanel = document.getElementById('pnCurrentCityPanel');
    if (panel && cityPanel) {
        if (panel.style.visibility == 'visible') {
            cityPanel.setAttribute('class', 'page_header_currentCity_area');
            panel.style.visibility = 'hidden';
            panel.style.display = 'none';
        }
        else {
            var pos = getElementAbsolutePos(cityPanel);
            panel.style.left = pos.x + (pos.width - 163) + 'px';
            panel.style.top = pos.y + pos.height + 1 + 'px';

            cityPanel.setAttribute('class', 'page_header_currentCity_areaFocused');
            panel.style.visibility = 'visible';
            panel.style.display = 'inline';
        }
    }

    return false;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

//------------------------------------------------------------------
// Shop Cart section

var _neuronShopDialog = null;
var _neuronShopDialogGoodsID = -1;
var _neuronShopDialogGoodsQty = 0;
var _neuronShopDialogGoodsQtyINPUT = 0;
var _neuronShopDialogGoodsSumLabel = null;
var _neuronShopDialogGoodsPrice1 = 0.0;
var _neuronShopDialogGoodsPrice2 = 0.0;
var _neuronShopDialogInProgress = 1;
var _neuronShopDialogSource = 0;
var _neuronShopDialogSourceObject = null;
var _neuronShopDialogGoodsChanged = 0;
var _neuronShopDialogPriceColumn = 1; // 1=fizic, 2=juridic

function CloseShopPanel() {
    if (_neuronShopDialog) {
        _neuronShopDialog.style.display = 'none';
        _neuronShopDialog = null;
        _neuronShopDialogGoodsQtyINPUT = null;
        _neuronShopDialogGoodsSumLabel = null;
    }
}

function ShopCartIncGoodsCount() {
    if (_neuronShopDialogGoodsQty && _neuronShopDialogInProgress==0) {
        _neuronShopDialogGoodsQty++;
        if (_neuronShopDialogGoodsQty > 9999) _neuronShopDialogGoodsQty = 9999;
        ShopCartQtyChanged();
    }
}

function ShopCartDecGoodsCount() {
    if (_neuronShopDialogGoodsQty && _neuronShopDialogInProgress==0) {
        _neuronShopDialogGoodsQty--;
        if (_neuronShopDialogGoodsQty <= 0) _neuronShopDialogGoodsQty = 1;
        ShopCartQtyChanged();
    }
}

function ShopCartUserQtyChanged() {
    if (_neuronShopDialogGoodsQtyINPUT && _neuronShopDialogInProgress==0) {
        var n = 1;
        n = parseInt(_neuronShopDialogGoodsQtyINPUT.value);
        if (!n || n <= 0) n = 1;
        if (n > 9999) n = 1;
        _neuronShopDialogGoodsQty = n;
        ShopCartQtyChanged();
    }
}

function ShopCartQtyChanged() {
    if (_neuronShopDialog && _neuronShopDialogGoodsQtyINPUT && _neuronShopDialogGoodsSumLabel) {
        var sum = 0.0;
        if (_neuronShopDialogPriceColumn==1)
        sum = _neuronShopDialogGoodsQty * _neuronShopDialogGoodsPrice2; // fizic
        else
            sum = _neuronShopDialogGoodsQty * _neuronShopDialogGoodsPrice1; // juridic

        //round to two decimals
        sum = Math.round(sum * 100) / 100;
        
        // display values
        _neuronShopDialogGoodsQtyINPUT.value = _neuronShopDialogGoodsQty;
        _neuronShopDialogGoodsSumLabel.innerHTML = '$' + sum;
        _neuronShopDialogGoodsChanged = 1;
    }
}

function ShowShopCartDialog(GoodsID, Qty, Mode, Source, SourceObject) {
    // GoodsID - goods id
    // Qty - current qty of the goods in shop cart
    // Mode - display mode: 0 - not yet added, 1 - already in the shop cart

    // check if already opened
    if (_neuronShopDialog) {
        var tmpGoodsID = _neuronShopDialogGoodsID;
        CloseShopPanel();
        if (tmpGoodsID==GoodsID) return;
    }

    // prepare dialog
    _neuronShopDialog = document.getElementById('idShopCartDialog');
    if (_neuronShopDialog) {
        _neuronShopDialogGoodsID = GoodsID;
        // collect goods info: Title, Price1, Price2
        var titleObj = document.getElementById('siT_' + GoodsID);
        var price1Obj = document.getElementById('siP1_' + GoodsID);
        var price2Obj = document.getElementById('siP2_' + GoodsID);

        var goodsTitle = "[noname]"; if (titleObj) goodsTitle = titleObj.innerHTML;
        _neuronShopDialogGoodsPrice1 = 0.00;
        if (price1Obj) {
            var s = price1Obj.innerHTML;
            s = s.replace('&nbsp;', '');
            s = s.replace(' ', '');
            _neuronShopDialogGoodsPrice1 = parseFloat(s);
        }
        if (!_neuronShopDialogGoodsPrice1) _neuronShopDialogGoodsPrice1 = 0;
        _neuronShopDialogGoodsPrice2 = 0.00;
        if (price2Obj) {
            var s = price2Obj.innerHTML;
            s = s.replace('&nbsp;', '');
            s = s.replace(' ', '');
            _neuronShopDialogGoodsPrice2 = parseFloat(s);
        }
        if (!_neuronShopDialogGoodsPrice2) _neuronShopDialogGoodsPrice2 = 0;
        if (Mode == 0) Qty = 1;
        _neuronShopDialogGoodsQty = Qty;
        _neuronShopDialogGoodsQtyINPUT = document.getElementById('idShopCartDialog_txtQTY');
        _neuronShopDialogGoodsSumLabel = document.getElementById('idShopCartDialog_lbSUM');

        // get current price column
        _neuronShopDialogPriceColumn = 1;
        var cookiePriceColumn = getCookie('ShopCartPaymentType');
        if (cookiePriceColumn) {
            var k = cookiePriceColumn.indexOf('VALUE=');
            if (k != -1) {
                cookiePriceColumn = cookiePriceColumn.substr(k + 6, 1);
                if (cookiePriceColumn == '2') _neuronShopDialogPriceColumn = 2;
            }
        }

        // hide progress
        var progress = document.getElementById('idShopCartDialog_Progress');
        progress.style.visibility = 'hidden';

        var s = 'Добавить в корзину';
        // setup titles & buttons
        if (Mode == 1) s = 'В корзине';

        titleObj = document.getElementById('idShopCartDialogTitle');
        titleObj.innerHTML = s;

        titleObj = document.getElementById('idShopCartDialogGoodsTitle');
        titleObj.innerHTML = goodsTitle;

        var button = document.getElementById('idShopCartDialogBtnOk');
        if (button) button.style.visibility = 'visible';
        button = document.getElementById('idShopCartDialogBtnDelete');
        if (button) {
            if (Mode == 0) button.style.visibility = 'hidden'; else button.style.visibility = 'visible';
        }

        // calc qty & sum
        ShopCartQtyChanged();

        // adjust position
        if (Source==1) {
            // catalog
            var pos = getElementAbsolutePos(SourceObject);
            _neuronShopDialog.style.left = pos.x - 210 + 'px';
            _neuronShopDialog.style.top =  pos.y - 12 + 'px';
        }
        else {
            // product details, fixed offset from Buy button
            var pos = getElementAbsolutePos(document.getElementById('idProductShopButton'));
            _neuronShopDialog.style.left = pos.x + 197 + 'px';
            _neuronShopDialog.style.top =  pos.y - 210 + 'px';
        }
        _neuronShopDialogSource = Source;
        _neuronShopDialogSourceObject = SourceObject;

        // show panel
        if (Mode == 0) _neuronShopDialogGoodsChanged = 1; else _neuronShopDialogGoodsChanged = 0;
        _neuronShopDialogInProgress = 0;
        _neuronShopDialog.style.display = 'inline';
    }
    else alert('Internal error! Sorry.');
}

function ShopCartButtonOkClick() {
    if (_neuronShopDialog && _neuronShopDialogInProgress == 0) {

        if (_neuronShopDialogGoodsChanged == 0) {
            CloseShopPanel();
            return;
        }

        _neuronShopDialogInProgress = 1;
        // show progress
        var progress = document.getElementById('idShopCartDialog_Progress');
        progress.style.visibility = 'visible';
        var button = document.getElementById('idShopCartDialogBtnDelete');
        if (button) button.style.visibility = 'hidden';
        button = document.getElementById('idShopCartDialogBtnOk');
        if (button) button.style.visibility = 'hidden';

        // send info to server
        ShopCartAddGoodsToShopCart(_neuronShopDialogGoodsID, _neuronShopDialogGoodsQty);
    }
}

function ShopCartButtonRemoveClick() {
    if (_neuronShopDialog && _neuronShopDialogInProgress == 0) {

        // show progress
        _neuronShopDialogInProgress = 1;
        // show progress
        var progress = document.getElementById('idShopCartDialog_Progress');
        progress.style.visibility = 'visible';
        var button = document.getElementById('idShopCartDialogBtnDelete');
        if (button) button.style.visibility = 'hidden';
        button = document.getElementById('idShopCartDialogBtnOk');
        if (button) button.style.visibility = 'hidden';

        // send info to server
        ShopCartAddGoodsToShopCart(_neuronShopDialogGoodsID, 0);
    }
}

function ShopCartAddCreateBuyButton() {
    if (_neuronShopDialogSourceObject) {
        // get parent
        var parentObj = _neuronShopDialogSourceObject.parentNode;
        // delete source obj
        parentObj.removeChild(_neuronShopDialogSourceObject);
        _neuronShopDialogSourceObject = null;

        var div = document.createElement('div');
        div.setAttribute('id', 'idProductShopButton');
        if (_neuronShopDialogSource == 0) {
            // product details
            div.setAttribute('class','product_ShopButton');
            div.setAttribute('onclick', 'ShowShopCartDialog(' + _neuronShopDialogGoodsID + ',1,0,0,this);');
            div.innerHTML = 'купить';
        }
        else {
            // catalog
            div.setAttribute('class','goods_is_for_sell');
            div.setAttribute('onclick', 'ShowShopCartDialog(' + _neuronShopDialogGoodsID + ',1,0,1,this);');
        }
        parentObj.appendChild(div);
    }
}

function ShopCartAddCreateEditButton(GoodsQty) {
    if (_neuronShopDialogSourceObject) {
        // get parent
        var parentObj = _neuronShopDialogSourceObject.parentNode;
        // delete source obj
        parentObj.removeChild(_neuronShopDialogSourceObject);
        _neuronShopDialogSourceObject = null;
        var div = document.createElement('div');
        div.setAttribute('id', 'idProductShopButton');
        if (_neuronShopDialogSource == 0) {
            // product details
            div.setAttribute('class', 'product_ShopButton');
            div.setAttribute('onclick', 'ShowShopCartDialog(' + _neuronShopDialogGoodsID + ',' + GoodsQty + ',1,0,this);');
            div.innerHTML = 'в корзине ('+GoodsQty+')';
        }
        else {
            // catalog
            div.setAttribute('class', 'goods_is_for_Remove');
            div.setAttribute('onclick', 'ShowShopCartDialog(' + _neuronShopDialogGoodsID + ',' + GoodsQty + ',1,1,this);');
            div.innerHTML = GoodsQty;
        }
        parentObj.appendChild(div);
    }
}

function UpdateShopCartTotalsButton() {
    try 
    {
        PageMethods.WebGetShopCartTotals(WhenGetShopCartTotalsSuccess, WhenGetShopCartTotalsFailed);
    }
    catch (err) {
    }    
}

function WhenGetShopCartTotalsSuccess(result, userContext, methodName) {
    var obj = document.getElementById('idShopCartTotals');
    obj.innerHTML = result;
}

function WhenGetShopCartTotalsFailed(error, userContext, methodName) {
    var obj = document.getElementById('idShopCartTotals');
    obj.innerHTML = '';
}

function ShopCartAddGoodsToShopCart(GoodsID, Qty) {
    try
    {
        PageMethods.WebAddGoodsToShopCart(GoodsID, Qty, WhenGoodsAddedSuccess, WhenGoodsAddedFailed);
    }
    catch(err)
    {
        CloseShopPanel();
        alert("Ошибка сервера (2)!\nРабота с корзиной временно недоступна.\nПросим прощения.")
    }
}

function WhenGoodsAddedSuccess(result, userContext, methodName) {
    CloseShopPanel();
    if (result == 0) {
        // goods was removed, put button: "buy"
        ShopCartAddCreateBuyButton();
    }
    else {
        // goods qty changed, put button "shop cart XX"
        ShopCartAddCreateEditButton(result);
    }
    UpdateShopCartTotalsButton(result);
}

function WhenGoodsAddedFailed(error, userContext, methodName) {
    CloseShopPanel();
    alert("Ошибка сервера (1)!\nРабота с корзиной временно недоступна.\nПросим прощения.")
}


//------------------------------------------------------------------

// User Account panel
function ShowAccountActionsPanel(Sender) {
    var pos = getElementAbsolutePos(Sender);
    var panel = document.getElementById('idAccountActionsPanel');
    if (panel && pos) {
        if (panel.style.visibility == 'visible') {
            Sender.setAttribute('class', 'pageHeader_myAccountButton2');
            panel.style.visibility = 'hidden';
            panel.style.display = 'none';
        }
        else {
            Sender.setAttribute('class', 'pageHeader_myAccountButton2Hot');

            panel.style.left = pos.x + (pos.width - 173) + 'px';
            panel.style.top = pos.y + pos.height + 1 + 'px';

            panel.style.visibility = 'visible';
            panel.style.display = 'inline';
        }
    }
}

//------------------------------------------------------------------
// Product Ask Dialog

function CloseProductAskDialog() {
    var panel = document.getElementById("idProductAskDialog");
    if (!panel) return;
    panel.style.display = 'none';
}

function ShowProductAskDialog(Sender) {
    var panel = document.getElementById("idProductAskDialog");
    if (!panel) return;

    // check if panel is visible already
    if (panel.style.display == 'inline') {
        CloseProductAskDialog();
        return;
    }

    // adjust panel postion close to Sender
    var pos = getElementAbsolutePos(Sender);
    var winH = GetWindowHeight(); // window Height
    var scrOfY = GetScrollTopPosition(); // window vertical scroll
    var x = pos.x - 10;
    var y = pos.y - 10;
    if ((y + 350 - scrOfY) > winH) y = pos.y - 300;
    panel.style.left = x + "px";
    panel.style.top = y + "px";

    // prepare before show
    // clear editors
    var Editor = document.getElementById("idProductAskDialog_txtName");
    if (Editor) Editor.value = "";
    Editor = document.getElementById("idProductAskDialog_txtEMail");
    if (Editor) Editor.value = "";
    Editor = document.getElementById("idProductAskDialog_txtQuestion");
    if (Editor) Editor.value = "";
    // hide progress
    Editor = document.getElementById("idProductAskDialog_Progress");
    if (Editor) Editor.style.visibility = 'hidden';
    // show ok button
    var button = document.getElementById("idProductAskDialogBtnOk");
    if (button) button.style.visibility = 'visible';


    // show panel
    panel.style.display = 'inline';

    // do after show
    var defEditor = document.getElementById("idProductAskDialog_txtName");
    defEditor.focus();
}


function ProductAskDialogButtonOkClick() {
    // verify input text
    var ErrorStr = "";
    var userName = "";
    var userEmail = "";
    var userQuestion = "";
    var Editor = document.getElementById("idProductAskDialog_txtName");
    if (Editor) {
        userName = Editor.value;
        if (userName == "") ErrorStr += "Ваше имя? ";
     }
    Editor = document.getElementById("idProductAskDialog_txtEMail");
    if (Editor) {
        // check if mail address is valid by syntax
        var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
        if (Editor.value.search(emailRegEx) == -1) ErrorStr += "Ваш е-мэйл? "; else userEmail = Editor.value;
    }
    Editor = document.getElementById("idProductAskDialog_txtQuestion");
    if (Editor)
    {
        userQuestion = Editor.value;
        if (userQuestion == "") ErrorStr += "Ваш вопрос? ";
     }

    if (ErrorStr != "") {
        alert(ErrorStr);
        return;
    }

    // show progress, hide button
    Editor = document.getElementById("idProductAskDialog_Progress");
    if (Editor) Editor.style.visibility = 'visible';
    var button = document.getElementById("idProductAskDialogBtnOk");
    if (button) button.style.visibility = 'hidden';

    // send info to server
    try {
        var prodUrl = encodeURIComponent(document.location);
        PageMethods.WebProductAskQuestion(userName, userEmail, userQuestion, prodUrl, WhenAskQuestionSuccess, WhenAskQuestionFailed);
    }
    catch (err) {
        alert("Ошибка сервера (2)!\nРабота с вопросами временно недоступно.\nПросим прощения.")
        CloseProductAskDialog();
    }
}

function WhenAskQuestionSuccess() {
    CloseProductAskDialog();
}

function WhenAskQuestionFailed() {
    CloseProductAskDialog();
    alert("Ошибка сервера (1)!\nРабота с вопросами временно недоступно.\nПросим прощения.")
}

//------------------------------------------------------------------


// Adjust ads
AdjustTopBanners();
AdjustBottomAds();

// init panels
InitImagePanel('imagePanel', 'imagePanelImage', 35, 35);
InitOtherCityPanel('otherCityPanel', 'otherCityList', -220, 18);

