var time_set = 5000;
function reserveSub()
{
    var name = $.trim($('#reserve').val());
    if (name) {
        if (name.length > 30) {
            $('#info').html('资源名不能包含空格,必须30个汉字以内').show();
            return false;
        }
    } else {
        return false;
    }
    $('#reserve_sub').attr('disabled','disabled');
    var params = $('#reserve_form input').serialize();
    $.ajax({
        url: 'sf_index.php',
        type: 'post',
        data: params,
        success: function(response) {
           $('#reserve_sub').attr('disabled','');
           if (response == 'ok') {
              $('#info').html('资源预约已提交，等待审核！').show();
           } else if(response == 'time_err') {
              $('#info').html('资源预约提交频繁，请20分钟后在预约！').show();
              $('#reserve_sub').attr('disabled','disabled');
              time_set = 1200000;
           } else if(response == 'no_sc') {
              $('#info').html('您所在的学校没有申请过资源站').show();
           } else {
              $('#info').html('服务器繁忙，请稍后在预约！').show();
           }
           $('#reserve').val('');
           setTimeout(function(){$('#info').html('').fadeIn();$('#reserve_sub').attr('disabled','');}, time_set);
        }
    });
    return false;
}
moveHandle = '';
function dragWin(eid){
    window.client={
        width: document.body.clientWidth,
        height: Math.min(document.documentElement.clientHeight, document.body.clientHeight)
    };
    $('#overlay').show();
    $('#drag_parent').show();
    if (window.client.height < $('#'+eid).height()) {
        var _top = 0;
    } else {
        var _top  = parseInt((window.client.height - $('#'+eid).height()) / 2);
    }
    var _left = parseInt((window.client.width - $('#'+eid).width()) / 2);
     _left = _left-160;
    if ($.browser.msie && parseFloat($.browser.version) < 7) {
        _top = (parseInt($(document).scrollTop())) + (parseInt(_top));

        $('#'+eid).css({'left':_left,'top': _top,'position':'absolute'}).show();
    } else {
        $('#'+eid).css({'left': _left, 'top': _top, 'position': 'fixed'}).show();
    }
    moveHandle = setTimeout(function(){$('#overlay').hide();$('#drag_parent').hide();}, 10000);
}
function hideBox() {
    $('#overlay').hide();
    $('#drag_parent').hide();
    clearTimeout(moveHandle);
}
$(function(){dragWin('drag_ad')});
function pubComment(_url)
{
    var name = $.trim($('#nick_name').val());
    var content = $.trim($('#content').val());
    if (name) {
        if (name.length > 5) {
            $('#info').html('姓名必须在5个汉字以内').show();
            return false;
        }
    }
    if (content) {
        if (content.length > 200) {
            $('#info').html('评论内容不能为空，字数200字以内').show();
            return false;
        }
    } else {
        $('#info').html('评论内容不能为空，字数200字以内').show();
        return false;
    }
    $('#sub_comment').attr('disabled','disabled');
    var params = $('#form_comment input,#form_comment textarea').serialize();

    $.ajax({
        url: _url,
        type: 'post',
        data: params,
        success: function(response) {
           $('#sub_comment').attr('disabled','');
           if (response == 'time_err') {
              $('#info').html('操作过快，请5秒后在发表评论').show();
              return false;
           } else {
              $('#comment_list .comment_body').eq(0).before(response);
              $('#info').html('评论发表成功！').show();
              $('#content').val('');
              if ($('#no_comment').html()) {
                  $('#no_comment').remove();
              }
           }
        }
    });
    return false;
}
function delComment(_url, comment_id)
{
    $.ajax({
        url: _url,
        type: 'get',
        success: function(response) {
           if (response == 'ok') {
              $('#'+comment_id).slideUp('fast', function(){ callsel(comment_id)});
           } else {
              alert('服务器繁忙，请稍后在发表评论！');
           }
        }
    });
    return false;
}
var callsel = function callsel (comment_id) {
    $('#'+comment_id).remove();
    if ($("#comment_list .comment_body").html() == null) {
        location=location.href;
    }
}

