//移动位置或者新增
function ajaxSendQuery1(divid, dlid, title, info) {
    title = encodeURIComponent(title);
    info = encodeURIComponent(info);
    var urlData = "id=4&divid=" + divid + "&dlid=" + dlid + "&skytid=" + skytid + "&skycid=" + skycid + "&title=" + title + "&info=" + info;
    //alert(urlData);
    //return;
    $.ajax({
        type: "POST",
        url: "v2courseclassajax.aspx",
        data: urlData,
        success: function(msg) {
            //alert(msg);
            if (msg != "0") {
                goShowError();
            }
        }
    });

}

function ajaxSendQuery2() {

    var title, info, id;
    title = $("#txtTitle").val();
    info = $("#txtInfo").val();
    id = $("#txtID").val();

    var urlData = "id=2&dlid=" + id + "&title=" + encodeURIComponent(title) + "&info=" + encodeURIComponent(info);

    $.ajax({
        type: "POST",
        url: "v2courseclassajax.aspx",
        data: urlData,
        success: function(msg) {
            if (msg == "0") {
                //成功
                $("#" + id + " dt").text(title);
                $("#" + id + " dd").html(info);
                $("#" + id + " dt").append('<span class="options"><a class="up"><img src="res/skyedit.gif" border="0"></a></span>');
                $("#" + id + " dt span a.up").bind("click", function() {
                    AjaxShowTitle(id, title, info);
                });
                disablePopup();
            } else {
            goShowError();
            }
        }
    });


}


function ajaxSendQuery3(CourseID, RoomID, RoomName) {

    var urlData = "id=6&dlid=" + CourseID + "&roomid=" + RoomID + "&info=" + RoomName;
    //alert(urlData);
    //return;
    $.ajax({
        type: "POST",
        url: "v2courseclassajax.aspx",
        data: urlData,
        success: function(msg) {
            //alert(msg);
            if (msg == "0") {
                //成功
                //$("#" + CourseID).parent().find("dd:eq(2)").html(RoomName)
               // $("#" + CourseID).parent().find("dd:eq(2)").css("color", "green")
                //$("#" + CourseID).parent().find("dd:eq(2)").attr("title", RoomID);

                $("#" + CourseID).find("dd:eq(2)").html(RoomName)
                $("#" + CourseID).find("dd:eq(2)").css("color", "green")
                $("#" + CourseID).find("dd:eq(2)").attr("title", RoomID);
            }
            else {
                goShowError();
            }
        }
    });
}

function goShowError() {
    window.alert("对不起，系统提交错误，请联系管理员或者重新登录后操作！");
 }


function randomChar(l) {
    var x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
    var tmp = "";
    for (var i = 0; i < l - 4; i++) {
        tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length);
    }
    return skytid + tmp;
}







function jiaHeight() {
    var divheight = $("#heightdiv").height() + 400;
    $("#heightdiv").height(divheight);
}
function jianHeight() {

    var divheight = $("#heightdiv").height() - 200;
    if (divheight > 0) {
        $("#heightdiv").height(divheight);
    }
    else {
        $("#heightdiv").height(0);
    }
}















function AjaxShowTitle(id, title, info) {

    $("#txtTitle").val(title);
    $("#txtInfo").val(info);
    $("#txtID").val(id);
    //alert(id);


    //alert("1");
    centerPopup();

    //调用函数加载窗口
    loadPopup();
    //alert("2");
}
var popupStatus = 0;
//使用Jquery加载弹窗 
function loadPopup() {
    //仅在开启标志popupStatus为0的情况下加载  
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        //                 $("#backgroundPopup").fadeIn("fast");
        //                 $("#popupContact").fadeIn("fast");

        $("#backgroundPopup").show();
        $("#popupContact").show();
        popupStatus = 1;
    }
}
//使用Jquery去除弹窗效果 
function disablePopup() {
    //仅在开启标志popupStatus为1的情况下去除
    if (popupStatus == 1) {
        //$("#backgroundPopup").fadeOut("fast");
        //$("#popupContact").fadeOut("fast");

        $("#backgroundPopup").hide();
        $("#popupContact").hide();
        popupStatus = 0;
    }
}
//将弹出窗口定位在屏幕的中央
function centerPopup() {
    //获取系统变量
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //居中设置   
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //以下代码仅在IE6下有效

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}
$(document).ready(function() {
    //初始化：是否开启DIV弹出窗口功能
    //0 表示开启; 1 表示不开启;


    //打开弹出窗口   
    //按钮点击事件!
    $("#button").click(function() {
        //调用函数居中窗口
        centerPopup();
        //调用函数加载窗口
        loadPopup();
    });
    //关闭弹出窗口   
    //点击"X"所触发的事件
    $("#popupContactClose").click(function() {
        disablePopup();
    });
    //点击窗口以外背景所触发的关闭窗口事件!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //键盘按下ESC时关闭窗口!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
});