var tmp;



function my_orders() {
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_orders.php',
        method: 'get',
        update: 'out_block',
        evalScripts: true,
        onRequest: function() 
        {
            set_title("Мои заказы"),
            set_description("Список Ваших заказов с подробным описанием")
        },
        onComplete: function(){ }
    }).send();
}

function my_questions() {
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_questions.php',
        method: 'get',
        update: 'out_block',
        evalScripts: true,
        onRequest: function() 
        {
            set_title("Мои вопросы"),
            set_description("Список заданных Вами вопросов и ответы на них")
        },
        onComplete: function(){ }
    }).send();
}

function my_data() {
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_data.php',
        method: 'get',
        update: 'out_block',
        evalScripts: true,
        onRequest: function()
        {
            set_title("Персональная информация"),
            set_description("Инормация введенная Вами при регистрации. Для изменения заполните необходимые поля и нажмите 'сохранить'")
        },
        
        onComplete: function(){ }
    }).send();
}


//function my_partners() {
//    var myRequest = new Request.HTML({
//        url: 'inc/cabinet/ajax/my_partners.php',
//        method: 'get',
//        update: 'cabinet_out',
//        evalScripts: true,
//        onComplete: function(){ }
//    }).send();
//    $('my_orders').className="vitrina_top2";
//    $('my_questions').className="vitrina_top2";
//    $('my_data').className="vitrina_top2";
//    $('my_partners').className="vitrina_top";
//}

function order_content(order_id, order_sid) {
    var pars = $H({
        order_id:order_id, 
        order_sid:order_sid
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_order_content.php',
        method: 'get',
        update: 'cabinet_out',
        evalScripts: true,
        onComplete: function(){ }
    }).send(pars);
}


function change_reg() {
    var send2 = 1;
    
    var first_name = document.getElementById('first_name');
    var first_name2 = first_name.value;
    var user_email = document.getElementById('user_email');
    var user_email2 = user_email.value;
    var user_phone = document.getElementById('user_phone');
    var user_phone2 = user_phone.value;
    //var user_adress = document.getElementById('user_adress');
    var user_adress2 = '';//user_adress.value;
    //var user_city = document.getElementById('user_city');
    var user_city2 = '';//user_city.value;


    var pars = $H({ 
        first_name:first_name2, 
        user_email:user_email2, 
        user_phone:user_phone2,
        user_adress:user_adress2,
        user_city:user_city2,
        send:send2
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_data_change.php',
        method: 'get',
        update: 'out_reg_info',
        evalScripts: true,
        onComplete: function(){
            $('out_reg_info').fade('out');
            $('out_reg_info').fade(0.0);
            $('out_reg_info').fade('hide');
            $('out_reg_info').fade(1.0);
    
        }
    }).send(pars);
}

function change_psw() {
    var send2 = 2;
    var psw_new = document.getElementById('user_pass_new1');
    var psw_new2 = psw_new.value;
    var psw_new_2 = document.getElementById('user_pass_new2');
    var psw_new_22 = psw_new_2.value;

    var pars = $H({ 
        psw_new:psw_new2,
        psw_new2:psw_new_22,
        send:send2
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/my_data_change.php',
        method: 'get',
        update: 'out_reg_info2',
        evalScripts: true,
        onComplete: function(){ 
            $('out_reg_info2').fade('out');
            $('out_reg_info2').fade(0.0);
            $('out_reg_info2').fade('hide');
            $('out_reg_info2').fade(1.0);
    
        }
    }).send(pars);
}

         

// top menu for IE6 -------------------------------
function hmenuhover()
{
    if(!document.getElementById("hmenu"))
        return;
    var lis = document.getElementById("hmenu").getElementsByTagName("LI");
    for (var i=0;i<lis.length;i++)
    {
        lis[i].onmouseover=function(){
            this.className+=" iehover";
        }
        lis[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }
}
if (window.attachEvent)
    window.attachEvent("onload", hmenuhover);


//--------------------------- superuser actions -----------------------------
function out_block_top_close()
{
    $('out_block_top').set('text', '');
    if ($('prod_panel_select'))
        $('prod_panel_select').destroy();
}
function out_block_close()
{
    $('out_block').set('text', '');
}





function order_content(order_id)
{
    var pars = $H({ 
        order_id:order_id
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/order_content.php',
        method: 'get',
        update: 'out_block',
        evalScripts: true,
        onComplete: function(){}
        
    }).send(pars);
}


function goods_report(param)
{
    if (typeof(param) != 'undefined') 
    {
        if (param == 1)
            param = $('start_year').value + "-" + $('start_month').value + "-" + $('start_day').value + "to" + $('end_year').value + "-" + $('end_month').value + "-" + $('end_day').value + "to" + '1';    
        else if (param == 2)
            param = $('start_year').value + "-" + $('start_month').value + "-" + $('start_day').value + "to" + $('end_year').value + "-" + $('end_month').value + "-" + $('end_day').value + "to" + '2';    
        else
            param = $('start_year').value + "-" + $('start_month').value + "-" + $('start_day').value + "to" + $('end_year').value + "-" + $('end_month').value + "-" + $('end_day').value + "to" + $('sort_list').value;    
    }
    else
        param = 'null';

    var pars = $H({ 
        param:param
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/goods_report.php',
        method: 'get',
        update: 'out_block',
        evalScripts: true,
        onRequest: function()
        {
            out_block_close();
            out_block_top_close();
        },
        onComplete: function(){}
    }).send(pars);
}



//--------------------------------------------- questions -----------------
function questions(param)
{
    var out = 'out_block';
    var q_id = '';
    var q_email = '';
    var q_quest = '';
    var q_answer = '';
    var q_author = '';
    var a_author = '';
    var a_check = '';
    
   
    if (typeof(param) != 'undefined') 
    {
        if (param == 'save')
        {
            q_id = document.getElementById('q_id').value;
            ;
            q_email = document.getElementById('q_email').value;
            q_quest = document.getElementById('q_quest').value;
            q_answer = document.getElementById('q_answer').value;
            q_author = document.getElementById('q_author').value;
            a_author = document.getElementById('a_author').value;
            a_check = document.getElementById('a_check').value;
        }
        
        out_block_top_close();
        out = 'out_block_top';
        
        
    }
    else
    {
        param = 'null';
        out_block_top_close();
        out_block_close();
    }

    var pars = $H({ 
        param:param,
        q_id:q_id,
        q_email:q_email,
        q_quest:q_quest,
        q_answer:q_answer,
        q_author:q_author,
        a_author:a_author,
        a_check:a_check
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/questions.php',
        method: 'get',
        update: out,
        evalScripts: true,
        onComplete: function(){
            questions_show();
            
        }
        
    }).send(pars);
}

function questions_show()
{
    var out = 'out_block';
    var pars = $H({ 
        param:'null'
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/questions.php',
        method: 'get',
        update: out,
        evalScripts: true,
        onComplete: function(){}
        
    }).send(pars);
}


function mods(action,name)
{
    var out = 'out_block';
    var pars = $H({ 
        action:action,
        name:name
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'inc/cabinet/ajax/mods.php',
        method: 'get',
        update: out,
        evalScripts: true,
        onComplete: function(){
          if (action!==null)
          var myRequest_ = new Request.HTML({
                url: 'inc/cabinet/user_actions.inc.php?user_menu_block',
                method: 'get',
                update: 'user_menu_block',
                evalScripts: true,
                onComplete: function(){
                    cabinet_history();
                }
        
            }).send();
        }
        
    }).send(pars);
    
       
}
//-----------------------------------------------partition_manager-------

function partition_links() {
    var nodeList = document.getElementsByTagName("a");
    var p_link = null;
    for (var i = 0; i < nodeList.length; i++)
    {
        p_link = nodeList[i];
        var iof = p_link.href.indexOf('partition_manager');
        if (iof!==-1)        
        {
            p_link.addEvent('click', function(e)
            {
                e.stop();
                var myRequest = new Request.HTML({
                    url: this.href,
                    method: 'get',
                    update: 'partition_out',
                    evalScripts: true,
                    onComplete: function()
                    {
                        $('form_30876').addEvent('submit', function(e) {
                            e.stop();
                            this.set('send', {
                                evalScripts: true,
                                onComplete: function() {
                                    get_my_content("partition_manager");
                                }
                            });
                            this.send();

                        });
                    }
                }).send();

            });
        }
    }
    return i;
}




/*--------------------------------------------------------------------------*/
// История переходов по кабинету
function set_title(title)
{
    $('out_block_title').set('text', title);
    if (title!=='')
        Cookie.write("lastpage", title);
    out_block_close();
    out_block_top_close();
}

function set_description(text)
{
    $('out_block_description').set('text', text);
}


function cabinet_history()
{
        if ($('user_menu_block')!==null)
    {
        var nodeList = $('user_menu_block').getElementsByTagName("a");
        var p_link = null;
        for (var i = 0; i < nodeList.length; i++)
        {
            p_link = nodeList[i];
            {
                p_link.addEvent('click', function(e)
                {
                    e.stop();
                    set_title(this.innerHTML);
                    show_user_actions();
                });
            }
        }
    
        if ($('out_block_title')!==null)
        {
        //   if ($('out_block_title').innerHTML.length==0)
        {
            var lastpage = Cookie.read("lastpage");
            if (lastpage!==null)
            {
                if (lastpage.length!==0)

                {
                    var nodeList = $('user_menu_block').getElementsByTagName('a');
                    for (var i = 0; i < nodeList.length; i++)
                    {
                        var text = nodeList[i].innerHTML;
                        if (lastpage == text)
                        {
                            nodeList[i].onclick();
                        }
                    }
                }
            } else show_user_actions();
        }
        }
    }
}
window.addEvent('domready', function() 
{
    cabinet_history();
});


// История переходов по кабинету конец
/*--------------------------------------------------------------------------*/



//вылетающее меню пользователя
function show_user_actions()
{
    var action = $('show_user_menu').get('class');
    if(action == 'btn_slide')
    {
        fadeIn($('user_menu_block'));
        $('show_user_menu').set('class', 'btn_slide_in');
        $('show_user_menu').set('title', 'cвернуть меню');
 //       $('lbCenter').innerHTML = "<style>#user_menu_block{width:"+getStyle_($('user_menu'),'width')+"}</style>";
    }
    else
    {
        fadeOut($('user_menu_block'));
        $('show_user_menu').set('class', 'btn_slide');
        $('show_user_menu').set('title', 'развернуть меню');
    }
    
}
