var xmlHttp;
var columnno=1;
function GetXmlHttpObject()
{
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
    } catch(e) {// Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");//6.0+
        } catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//5.5+
        }
    }
    if (xmlHttp == null) alert("not support Ajax！");
    return xmlHttp;
}

function AjaxResponse(options)
{
    if(xmlHttp.readyState == 4)
    {
        if (xmlHttp.status == 200)
        {
            options.success(xmlHttp);
            if(Ajax._requestArray.length > 0)
            {
                Ajax._requestArray.shift();
                Ajax._doRequest();
            }
        }
    }
}

function AjaxRequest(url, options)
{
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){ AjaxResponse(options) };
    if(options.method == "GET")
    {
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        return false;
    }
    else if(options.method == "POST")
    {
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");// tell server: request with form params
        xmlHttp.setRequestHeader("X_REQUESTED_WITH", "xmlhttprequest");
        xmlHttp.send(options.params);
        return false;
    }
}

Ajax = {
    _requestArray : [],
    request : AjaxRequest,
    requests : function (url, options) {
        Ajax._requestArray.push([url, options]);
        if(Ajax._requestArray.length == 1)
            Ajax._doRequest();
    },
    _doRequest : function () {
        if(Ajax._requestArray.length > 0)
            AjaxRequest(Ajax._requestArray[0][0], Ajax._requestArray[0][1]);
    } // the last property end should do not have "," IE6 warning!!!
};


function ieversion()
{
    var re = /msie (\d.\d)/;
    var matches = re.exec(navigator.userAgent.toLowerCase());
    return matches ? matches[1] : null;
}


function maskDiv(clickclose)
{
    /*
     * document.getElementById object or null
     */
    var maskdiv = document.getElementById("maskdiv");
    if(maskdiv != null) return false;

    if(document.all) // IE
    {
        if(ieversion() == "6.0") // 6.0
        {
            var body = document.getElementsByTagName("body")[0];
            body.style.cssText = "width:100%;height:100%;";
        }
    }

    var maskdiv = document.createElement("div");
    maskdiv.id = "maskdiv";
    maskdiv.style.cssText = "z-index:999;position:fixed;left:0;top:0;width:100%;height:100%;background-color:#141414;filter:alpha(opacity=30);opacity:0.3;";// filter:alpha(opacity=30) IE, opacity FF

    // register click event
    if(clickclose)
    {
        if(document.all)
            maskdiv.attachEvent('onclick', closeWindow);
        else
            maskdiv.addEventListener("click", closeWindow, false);
    }

    document.body.appendChild(maskdiv);
}


function closeWindow()
{
    var popdiv = document.getElementById("popdiv");
    var maskdiv = document.getElementById("maskdiv");
    var msgdiv = document.getElementById("msgdiv");
    if(popdiv != null)
        document.body.removeChild(popdiv);
    if(maskdiv != null)
        document.body.removeChild(maskdiv);
    if(msgdiv != null)
        document.body.removeChild(msgdiv);
//    if(countdown != null)
//        clearInterval(countdown);
}
/*
 * show message
 * @param message the message that will be show
 * @param mask if show the mask layer, true is show, or not
 */
function showMessage(message, fhurl)
{
    //maskDiv(true);

    var msgdiv = document.getElementById("msgdiv");
    if(msgdiv == null)
    {
        msgdiv = document.createElement("div");
        msgdiv.id = "msgdiv";
        if(document.all && ieversion() == "6.0")
            msgdiv.style.cssText = "position:absolute;left:40%;top:40%";
        else
            msgdiv.style.cssText = "z-index:9999;height:0px;width:0px;position:fixed;left:40%;top:40%;";
        document.body.appendChild(msgdiv);
        if(fhurl==false){
             url="<a href=\"javascript:;\" onclick=\"document.body.removeChild(document.getElementById('msgdiv'));var maskdiv = document.getElementById('maskdiv');\" class=\"btn\">关闭</a>";
        } else {
             url="<a href="+fhurl+" class=\"btn\">返回上一页</a>";
        }
        msgdiv.innerHTML = "<div style=\"width:300px;height:200px;position:absolute;left:-200px;top:-100px;\">"
                           +"<div class=\"wrap\">"
                           +"<div id=\"error_tips\">"
                           +"<h2>信息提示</h2>"
                           +"<div class=\"error_cont\">"
                           +"<ul>"
                           +"<li>"+message+"</li>"
                           +"</ul>"
                           +"<div class=\"error_return\">"+url+"</div>"
                           +"</div>"
                           +"</div>"
                           +"</div>"
                           +"</div>"
                           ;
    }
    var msgbox = document.getElementById("msgbox");
    var msg = document.createElement("div");
    msg.style.cssText = "text-align:center;margin-top:15px;";
    msg.innerHTML = message;
    //msgbox.appendChild(msg);
}

function showWindow(url)
{
    if(!document.all) maskDiv(true);
    else
        if(ieversion() != "6.0")
            maskDiv(true);

    var popdiv = document.getElementById("popdiv");
    if(popdiv == null)
    {
        popdiv = document.createElement("div");
        popdiv.id = "popdiv";
        popdiv.style.className = "popdiv";
        if(document.all && ieversion() == "6.0")
            popdiv.style.cssText = "position:absolute;left:50%;top:50%";
        document.body.appendChild(popdiv);
    }

    var options = {
        method : "POST",
        success : function (xmlHttp)
        {
            popdiv.innerHTML = unescape(xmlHttp.responseText);
        },
        failure : function () {},
        params : ""
    };
    Ajax.request(url, options);
}

function checkup(yversion)
{
    var ym=window.location.host;
    var url = "main.php?action=checkupdate";
    var options = {
        method : "GET",
        success : function (xmlHttp) {
            var message = xmlHttp.responseText;
            try {
               if(message==yversion){
                      showMessage('当前已经是最新版本！','');
               }else{
                      showMessage('当前最新版本为：<font color=red>'+message+'</font><br><br><a href="http://www.chshcms.cn/vip/downrar.php?ym='+ym+'" target="_blank">点击手动升级包升级</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="updata.php">点击自动在线升级</a>','');
               }
            } catch(e) {}
        },
        failure : function () {},
        params : ""
    };
    Ajax.requests(url, options);
}

function DelInfo2(theform) {
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
        }
    }
    if (checkCount == 0) {
        alert("请选中要入库的数据!");
        return false;

    } else {
        if (confirm("您确定要入库这 " + checkCount + " 条记录吗?")) {
            theform.action.value="del";
			theform.submit();
            return true;
        } else {
            return false;
        }
    }
}


function DelInfo(theform) {
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        if (confirm("您确定要删除这 " + checkCount + " 条记录吗?")) {
            theform.action.value="del";
			theform.submit();
            return true;
        } else {
            return false;
        }
    }
}

function EditInfo(theform,sid) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");
    if(sid=='dance'){
        var title = '歌曲';
    }else{
        var title = '文章';
    }
    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
        Popsboxif(title+'批量操作',450,520,sid+'_pl.php?op=1&id='+idss+'');
    }
}

function MarkInfo(theform,sid) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
        window.location='../html/html_'+sid+'.php?ac=xuan&id='+idss;
    }
}

function SHInfo(theform,sid) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
        window.location='./'+sid+'.php?op=plsh&id='+idss;
    }
}

function DBInfo(theform,sid) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
        window.location='dbbase.php?op='+sid+'&id='+idss;
    }
}


function XgInfo(theform) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
        window.location='skins.php?op=edit&id='+idss;
    }
}


function UserInfo(theform,sid) {
    var v = [];
    var checkCount = 0;
    var ids = document.getElementsByName("CS_ID[]");

    for(i=0; i<ids.length; i ++) {
        if (ids[i].checked) {
            checkCount ++;
            v.push(ids[i].value);
        }
    }
    if (checkCount == 0) {
        alert("请选中要进行操作的数据!");
        return false;

    } else {
        var idss=v.join(',')
      if(sid=='xiaoxi'){
        window.location='user_'+sid+'.php?id='+idss;
      }else{
        Popsboxif('发送邮件',450,470,'user_mail.php?id='+idss);
      }
    }
}

function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')       
	e.checked = form.chkall.checked; 
   }
}		

