/**
 * Created by chenbiao on 2017/11/30.
 */
console.log(fn.getUserName());
if(fn.getUserName()==''|| fn.getUserName()==undefined||fn.getUserName()==null){

    $('#topbar_userMsg').hide();
    $('#topbar_tologin').show();
}else{
    $('#topbar_tologin').hide();
    $('#topbar_userMsg').show().find('#userId').text(fn.getUserName());
}
//用户退出登录
$('#login_out_btn').on('click', function () {
    // console.log("token:" + fn.getToken());
    fn.loginOut();
});

//加盟弹窗
$('#join_btn').on('click', function () {
    $('#porNames_inp').val('');
    $('#personNames_inp').val('');
    $('#personDuties_inp').val('');
    $('#userTel_inp').val('');
    $('#userEmail_inp').val('');
    $('#userAddr_inp').val('');
    $('#write_rule').addClass('display-none').text('');
    $('#openmodel').modal('show');
})
//提交信息
$('#write-submit').on('click', function () {
    var porNames= $.trim($('#porNames_inp').val());
    var personNames=$.trim($('#personNames_inp').val());
    var personDuties=$.trim($('#personDuties_inp').val());
    var userTel=$.trim($('#userTel_inp').val());
    var userEmail=$.trim($('#userEmail_inp').val());
    var userAddr=$.trim($('#userAddr_inp').val());
    if(porNames == '' || porNames == undefined || porNames == null) {
        $('#write_rule').removeClass('display-none').text('请输入公司名称');
        return;
    }else if(personNames == '' || personNames == undefined || personNames == null) {
        $('#write_rule').removeClass('display-none').text('请输入联系人姓名');
        return;
    }else if(personDuties == '' || personDuties == undefined || personDuties == null) {
        $('#write_rule').removeClass('display-none').text('请输入联系人职务');
        return;
    }else if(userTel == '' || userTel == undefined || userTel == null) {
        $('#write_rule').removeClass('display-none').text('请输入手机号');
        return;
    }else if(!/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(userTel)||userTel.length!=11) {
        $('#write_rule').removeClass('display-none').text('请输入正确手机号');
        return;
    }else if(userEmail == '' || userEmail == undefined || userEmail == null) {
        $('#write_rule').removeClass('display-none').text('请输入邮箱');
        return;
    }else if(!/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/.test(userEmail)) {
        $('#write_rule').removeClass('display-none').text('请输入正确邮箱');
        return;
    }else if(userAddr == '' || userAddr == undefined || userAddr == null){
        $('#write_rule').removeClass('display-none').text('请输入通讯地址');
        return;
    }else{
        $('#write_rule').addClass('display-none').text('');
        //ajax
        $('#openmodel').modal('hide');
    }
})



//无缝轮播
$(document).ready(function(){
    var timejg=3000;//轮播间隔时间
    var size = $('.box_img ul li').size();
    for(var i=1;i<=size;i++){
        $('.box_tab').append('<a href="javascript:void(0)"></a>')
    }

    $('.box_img ul li').eq(0).show();
    $('.box_tab a').eq(0).addClass('active')
    $('.box_tab a').mouseover(function(){
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(this).index();
        i=index;
        $('.box_img ul li').eq(index).stop().fadeIn(300).siblings().stop().fadeOut(300);
    });

    var i = 0;
    var time = setInterval(move,timejg);

    function move(){
        i++;
        if(i==size){
            i=0;
        }

        $('.box_tab a').eq(i).addClass('active').siblings().removeClass('active');
        $('.box_img ul li').eq(i).fadeIn(300).siblings().fadeOut(300);
    }

    $('.box').hover(function(){
        clearInterval(time);
    },function(){
        time = setInterval(move,timejg);
    });
});

