//用户登录
function user_login(){
    if(getCookie('uname')!=null){
        if(getCookie('utype')==0){
            $('#login_user_info').html('普通用户： '+getCookie('uname')+' |  <a href="'+'www.csyjx.com'+'register/logout.php">退 出</a>');
        }
        else if(getCookie('utype')==1){
            $('#login_user_info').html('设计师： '+getCookie('uname')+' | <a href="'+'www.csyjx.com'+'user_main/">用户设置</a> | <a href="'+'www.csyjx.com'+getCookie('uname')+'">博客空间</a> | <a href="'+'www.csyjx.com'+'register/logout.php">退 出</a>');
        }
        else if(getCookie('utype')==2){
            $('#login_user_info').html('商 家： '+getCookie('uname')+' | <a href="'+'www.csyjx.com'+'user_main/">信息管理</a> | <a href="'+'www.csyjx.com'+getCookie('uname')+'/">商铺首页</a> | <a href="'+'www.csyjx.com'+'register/logout.php">退 出</a>');
        }
    }
    else{
        $('#login_user_info').html('<label>帐号</lable> <input id="login_user_name" /> <label>密码</lable> <input id="login_user_password" type="password" /><input id="login_send" type="button" value=" "/> <span id="login_loading"></span> <a href="'+'www.csyjx.com'+'index.php/register/">注册</a>&nbsp;&nbsp;&nbsp; <a href="'+'www.csyjx.com'+'index.php/register/forget_password/ ">找回密码</a>');
        $('#login_send').click(function(){
            var isreg=true;
            if(!$('#login_user_name').val().replace(/(^\s+)|\s+$/g,"").match(/^[a-zA-Z0-9]{2,20}$/)){
                alert('请正确填写登录帐号!');
                isreg=false;
            }

            else if(!$('#login_user_password').val().replace(/(^\s+)|\s+$/g,"").match(/^[a-zA-Z0-9]{4,14}$/)){
                alert('请正确填写密码！');
                isreg=false;
            }
            if(isreg){
                $('#login_loading').html('加载中...');
                $.post('www.csyjx.com'+'index.php/register/login/','username='+encodeURI($('#login_user_name').val())+'&password='+encodeURI($('#login_user_password').val()),function(msg){
                    // alert(msg);
                    if(msg==0){
                        $('#login_loading').html('');
                        alert('填写数据不能为空!');
                    }
                    else if(msg==1){
                        $('#login_loading').html('');
                        user_login();

                    }
                    else if(msg==2){
                        $('#login_loading').html('');
                        alert('用户帐号或密码不正确!');
                    }
                });
            }
        });
    }
}

$(function(){

    user_login();


    //搜索分类切换
    $('#search_category span').click(function(){
        $('#search_category span').removeClass("search_category_selected");
        this.className='search_category_selected';
        $('#search_type').val($(this).attr('t'));

    });

    //搜索提交
    function search_submit(){
        if($('#search_keyword').val().replace(/(^\s+)|\s+$/g,"")!=""){
            window.location.href='/search/'+$('#search_type').val()+'/'+getUrlencode($.trim($('#search_keyword').val()))+'/';
        }else{
            window.location.href='/search/news/'+getUrlencode('家居')+'/';
        }
    }
    $('#search_click').click(search_submit);
    $('#search_keyword').keydown(function(){
        if(event.keyCode == 13){
            search_submit();
        }
    });



    //鼠标放到搜索按钮
    $('#search_click').hover(function(){
        $(this).css('background','url(/img/bg.gif) -121px -428px');
    },
    function(){
        $(this).css('background','url(/img/bg.gif) -121px -399px');
    });

    //滑动显示
    $('.box_title a ').mouseover(function(){
        $($(this).siblings()).removeClass('box_a_selected');
        this.className='box_a_selected';
        $($('#'+this.title+'_content').siblings('div')).hide();
        $('#'+this.title+'_content').show();
    });

    $('.box_next_title a ').mouseover(function(){
        $($(this).siblings()).removeClass('box_a_next_selected');
        this.className='box_a_next_selected';
        $($('#'+this.title+'_content').siblings('div')).hide();
        $('#'+this.title+'_content').show();
    });

    //家居分类
    $('#fitment_category > ul > li').hover(function(){

        $(this).children('div').show();
        $(this).css({
            'background-color':"#FD6D01",
            "color":'#fff'
        });
        $('#fitment_category').bgiframe();
    },function(){
        $(this).children('div').hide();
        $(this).css({
            'background-color':"#Fff",
            "color":'#333'
        });
    });


});
//$(function(){
//	$(".box_head").switchable('.box_body > div');
//});



