function onSignUp(){
    if(!confirm( '已确认所有需输入的信息，现在提交申请吗？ \n\n' +
                 '点［确定］，提交申请。\n点［取消］，重新确认一遍。')){
        $(document).scrollTop(160)
        return;
    }
    $('#signUpFormID .post-msg').toggle()
    $('#signUpFormID .submit').attr('disabled', 'true')
    $.post('./signUpSubmit', $("#signUpFormID").serialize(), function(rs){
        if (rs!= '0'){
            $(document).scrollTop(160)
            $('#signUpFormID .post-msg').toggle()
            $('#signUpFormID .submit').attr('disabled', '')
            $('#signUpFormID .f'+rs).select()
            window.setTimeout( function(){
                if(rs=='1'){alert('用户名长度不够或过长，需要至少3个字符，且不能超过16个字符。')}
                if(rs=='2'){alert('用户名格式不符合要求。')}
                if(rs=='3'){alert('密码长度不够，需要6位以上长度。')}
                if(rs=='4'){alert('密码前后不一致，请重新输入...')}
                if(rs=='5'){alert('密码格式不符合要求，可能过于简单，或者有不允许的字符。')}
                if(rs=='13'){alert('该帐号已被注册，请选择其它用户名。')}
            },200)
        }else{
        
            window.setTimeout( function(){
                $(document).scrollTop(0)
                $('#signUpFormID .post-msg').toggle()
                $('#signUpFormID .submit').attr('disabled', '')

                alert('申请提交成功，欢迎加入“绿网空间”计划！\n\n' +
                      '请耐心等待项目小组对您的审核结果，这一般不超过1个工作日。\n'+
                      '请及时登录查看空间的审核状态。\n\n' +
                      '注意：\n\n' +
                      '1. 我们将为你生成一个6位的【用户识别码】，用于登录查看账号信息，并参加各项活动，\n' +
                      '   请务必记录下并保管好！\n\n' +
                      '2. 空间的日常使用和管理需要安装专用的软件，我们推荐你使用【WinSCP】，\n' +
                      '   请按提示及时下载并安装，账号审核通过后，即可用于登录您的空间。')
                window.location = './home?init=1'
            }, 1000 )

        }
    })
}


function onPush(_this,id){
    var url = "./push?id=" + id;
    $(_this).attr('disabled', 'true')
    $.get(url, function(rs){
        window.setTimeout(function(){
            alert('文章已成功推送到首页［自由推荐］榜首!')
        }, 1000)
    })
}

function onFontChange(target, flag){
    $(target).css('font-size', flag + 'px')
}

function onTgUp(){
    if(!confirm( '已确认所有输入的信息，现在提交文章吗？ \n\n' +
                 '点［确定］，提交文章。\n点［取消］，重新确认一遍。')){
        return;
    }
    $('#tgFormID .post-msg').toggle()
    $('#tgFormID .submit').attr('disabled', 'true')
    $.post('./tgSubmit', $("#tgFormID").serialize(), function(rs){
        if (rs>0 && rs<9){
            $(document).scrollTop(160)
            $('#tgFormID .post-msg').toggle()
            $('#tgFormID .submit').attr('disabled', '')
            $('#tgFormID .f'+rs).focus().select()
            window.setTimeout( function(){
                if(rs=='1'){alert('请补充标题')}
                if(rs=='2'){alert('请输入文章内容')}
                if(rs=='3'){alert('请补充地区信息')}
                if(rs=='4'){alert('请补充作者姓名')}
                if(rs=='5'){alert('请补充学校名称')}
                if(rs=='6'){alert('请补充指导老师')}
                if(rs=='8'){alert('请补充年级资料')}
            },200)
        }else{ 
            window.location = './tgSubmit_done?sid=' + rs + '&topic=' + $('#tgFormID .topic_id').val()
        }
    })
}

function onSubmitWorks(){  
    form = '#onSubmitWorksFormID'
    onSubmitFrame('./submitWorks', form, form+' .post-msg', form+' .submit', '提交成功!', './joins',
        function(rs){
            alert('第 ' + rs + ' 个地址格式不符合要求')
        })
}

function onSubmitProfile(){
    form = '#editProfileFormID'
    onSubmitFrame('./editProfileSubmit', form, form+' .post-msg', form+' .submit', '资料已更新!', './home',
        function(rs){
            alert('发生错误，请重试')
        })
}

function onSubmitFrame(submiturl, formid, msgid, submitid, succmsg, redirectURL, failcall){
    if(!confirm( '已确认所有需输入的信息，现在提交吗？ \n\n' +
                 '点［确定］，提交。\n点［取消］，重新确认一遍。')){
        $(document).scrollTop(160)
        return;
    }
    $(msgid).toggle()
    $(submitid).attr('disabled', 'true')
    $.post(submiturl, $(formid).serialize(), function(rs){
        if (rs > 0){
            $(document).scrollTop(160)
            $(msgid).toggle()
            $(submitid).attr('disabled', '')
            $(formid + ' .f'+rs).select()
            window.setTimeout( function(){
                failcall(rs)
            },200)
        }else if (rs < 0){
            $(msgid).toggle()
            alert('ERROR!')
        } else{

            window.setTimeout( function(){
                $(document).scrollTop(0)
                $(msgid).toggle()
                $(submitid).attr('disabled', '')

                alert(succmsg)
                window.location = redirectURL
            }, 1000 )

        }
    })
}


function toDownload(){
    window.setTimeout(function(){
        $(document).scrollTop(220)
        if(!confirm('正在为您下载空间管理软件 WinSCP.exe\n\n' +
            '- 软件大小：  2.9 M\n' +
            '- 相关功能：  登录空间、上传文件、管理相册图片、发布共享资料  \n\n' +
            '需要继续吗?')){
            return;
        }
        $('.blackhole').attr('src', 'http://green.qsn365.com/filebox/downloads/All/WinSCP.exe')
    }, 7000)

}


function onDigg(id, url){
 
    var _this = $('.digg-' + id )
     $(_this).html('发送中...').addClass('b green')
    $.get(url, function(rs){
        window.setTimeout(function(){ 
            if (rs=='3'){
                window.location = './login'
                return
            }
            $(_this).html('已赞哈！').removeClass('green').addClass('b red')
            alert('已赞哈！')
        }, 1000)
    })
}

