﻿function logout() {
    url = "/Web/Pages/LogoutForm.aspx?Action=logout";
    window.location = url;
}

function logout_v2() {
    url = "/Web/Pages/LogoutForm.aspx?Action=logout_v2";
    window.location = url;
}

function login() {

    var login = document.getElementById('txtLogin').value;
    var pass  = document.getElementById('txtPassword').value;
    var store = document.getElementById('chbStore').checked;

    if(login == '' || pass == '')
    {
        alert('Укажите пожалуйста Логин и Пароль!');
        document.getElementById('txtLogin').focus();
        return false;
    }

    return true;

    var req = oXMLHTTP();
    var res = false;

    req.open('GET', '/web/pages/___.aspx?' + 'l=' + login + '&p=' + pass + '&s=' + store, false);
    req.send(null);  // отослать запрос
    try {
        req.onreadystatechange = L(req);
    }
    catch (e) { 
        //alert(e.Description)
    }

    //url = "/Web/Pages/LogoutForm.aspx?Action=logout";
    //window.location = url;
}

function L(req)
{
    if (req.readyState == 4) {
        if (req.status == 200) {
            switch (req.responseText)
            {
                case '1':
                    alert("Ошибка авторизации!");
                    break;
                case '2':
                    alert("Пользователь не найден!");
                    break;
                case '3':
                    alert("Пользователь 3!");
                    break;
                case '4':
                    alert(window.location);
                    window.location = window.location; // '/Web/Pages/SearchPriceListForm.aspx';
                    break;        

            }
            //alert("Ответ сервера: " + req.responseText);
        }
        else {
            alert("Ошибка: " + req.status);        
        }
    }
}

function oXMLHTTP() {
    var res;
    //if (document.all)
    res = new ActiveXObject("Microsoft.XMLHTTP"); 
    //else
    //    res = new XMLHttpRequest();

    return res;
}



function register_guest() {
    url = "/Web/Pages/LogoutForm.aspx?Action=logout_guest";
    window.location = url;
}

function showDiler(idDiler, isDiler) {
    url = "/Web/Pages/DilerInfoForm.aspx?idDiler=" + idDiler + "&isDiler=" + isDiler;
    param = "width:400px;height:200px;center:1;resizable:1;scroll:0;status:0;edge:raised;help:0;";
    param = "directories=no,height=250,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=400";
    window.open(url, null, param);
}

function css_browser_selector(u) {
    var ua = u.toLowerCase(), is = function (t) {
        return ua.indexOf(t) > -1;
    }, g = 'gecko', w = 'webkit', s = 'safari', o = 'opera', h = document.documentElement, b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c;
}
css_browser_selector(navigator.userAgent);

//top menu
function fn_MM(o) {
    if (o.className != 't_m_MA')
        o.className = 't_m_MM';
}

function fn_MO(o) {
    if (o.className != 't_m_MA')
        o.className = 't_m';
}

function fn_MC(o, url) {
    o.className = 't_m_MC';
    document.location = url;
}
//top menu end


function articleSearch() {
    var txtArticle = document.getElementById('menu_txtArticle');
    if (txtArticle.value == "") return;
    window.location = "/Web/Pages/SearchPriceListForm.aspx?Article=" + encodeURI(txtArticle.value);
}

function fnSearch() {
    var o = document.getElementById('txtSearch');
    if (o.value == '' || o.value == 'Номер детали...') {
        alert('Укажите номер детали!');
        o.focus();
        return false;
    }
    //fnLoading();
    //document.getElementById('frmSearch').submit();
    return true;
}

function fnLoading() {
    var oL = document.getElementById('lblLoading');
    oL.style.top = '200px'; //Math.round(screen.height/2 - 100 - document.body.scrollTop)+'px';;
    oL.style.left = Math.round(screen.width / 2 - 160) + 'px'; ;
    //oL.style.top = Math.round(document.body.clientHeight/2 - 100 + document.body.scrollTop)+'px';
    oL.style.left = Math.round(document.body.clientWidth / 2 - 160 + document.body.scrollLeft) + 'px';
    oL.style.visibility = 'visible';
    oL.style.display = 'block';
}

//document.getElementById('txtSearch').focus();

