﻿// JScript 文件

function $(obj)
{
    return document.getElementById(obj);
}

if (window.addEventListener)
{
    window.addEventListener('load', function(event)
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    }, false);
}
else if (window.attachEvent)
{
    window.attachEvent('onload', function()
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    });
}
else
{

    window.onload = function()
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    }
}

//通过咨询单的ID取得对应咨询单处理的相关信息
function GetTable(guid)
{
    Page.GetTreatmentRecordList(guid,GetTableEd)
}

//通过咨询单的ID取得对应咨询单处理的相关信息  加载数据
function GetTableEd(obj)
{
    var list = obj.value;
    if (list != null && list.length > 0)
    {
        for (var i = 0; i < list.length; i++)
        {

            var tr = $("TreatmentRecordTable").insertRow(-1);

            var td1 = tr.insertCell(-1);
            var td2 = tr.insertCell(-1);
            var td4 = tr.insertCell(-1);
            if (list[i].Dealinger != null)
            {
                td1.innerHTML = list[i].Dealinger.Name;
            }
            else
            {
                td1.innerHTML = "";
            }
            td2.innerHTML = list[i].CreateDate.format("yyyy-MM-dd hh:mm:ss");
            td4.style.textAlign = "left";
            if (list[i].Note != null && list[i].Note != "null")
            {
                td4.innerHTML = list[i].Note;
            }
            
            tr.className = (i % 2 > 0) ? "disBlueBg" : "disOranBg";
        }
    }
    var ifm = window.parent.document.getElementById("iframepage");
    ifm.height = document.body.scrollHeight;
}

//设置点击修改背景
function ShowData(index)
{
    var childNodesLength = $("ulList").childNodes.length;
    //数据初始化
    for (var i = 0; i < childNodesLength; i++)
    {
        $("ulList").childNodes[i].className = '';
    }
    $("ulList").childNodes[index].className = 'BgImg';

    //加载对应数据
    var where = null;
    where = GetWhereOql(); //window["SeachPageHelper"].WhereOql;
    if (where.length <= 0)
    {
        where = " 1=1";
    }
    if (index > 0)
    {
        where += " and AdvisorySingleDTO.State='" + index + "'";
    }

    ClearTable();

    window["SeachPageHelper"] = new SeachPageHelper_Class("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", 15, where, loaded);

}

//加载默认条数 0,全部 1，等待处理 2，处理中  3，处理成功  4，放弃处理
function GetTotalCounts()
{
    var childNodesLength = $("ulList").childNodes.length;
    var returnValue = null;
    var where = null;
    
    for (var i = 0; i < childNodesLength; i++)
    {
        where = GetWhereOql();
        if (where.length <= 0)
        {
            where = " 1=1 ";
        }
        if (i > 0)
        {
            where += " and AdvisorySingleDTO.State=" + i;
        }

        returnValue = Page.GetTotal("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", where).value;
        if (i == 0)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "全部";
        }
        else if (i == 1)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "等待处理";
        } else if (i == 2)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "处理中";
        }
        else if (i == 3)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "处理成功";
        }
        else if (i == 4)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "放弃处理";
        }
        if (returnValue != null)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML += "(" + returnValue + ")";
        }
        else
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML += "(0)";
        }
    }
}

//取得右上方页面登录信息
function SetLoginInfo(value)
{
    if (value != null && value.error != null && value.error.Message == 'NoLogin')
    {
        alert('请先登录');
        window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
        return;
    }
    if (value.value == null)
    {
        alert('请先登录');
        window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
        return;
    }
    $("pLoginInfo").innerHTML = value.value.Name + ",您好";
    $("aHelper").href = "javascript:openW('http://chat7.looyu.com/chat/chat/p.do?g=28086&md=2&c=31203&v=e3369d4c36d242bda5510a2802ccdd84&u=791715b91c5a43048f8239d508240c3b&f=75012&site=0&ct=74&refer=&loc=CallCenter:" + encodeURI(encodeURI(value.value.Name)) + "(" + value.value.LoginName + ")')";
    if($("seOwner")!=null)
    {
        $("seOwner").refTextBoxObj.SetValue(value.value.ID, value.value.Name);
    }
}
//取得当前登录者
function GetLoginUserID()
{
    var returnValue = Page.GetLoginer().value;
    var id = "";
    if(returnValue!=null)
    {
        id = returnValue.Name;
    }
    return id;
}

function openW(v)
{
    window.open(v, '', 'width=580,height=500,left=200,top=200,status=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,location=no');
}

//系统退出
function LoginOut()
{
    Page.LoginOut(LoginOuted);
}

function LoginOuted(value)
{
    window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
}

//选中所有
function CheckCheckBox(obj)
{
    var checks = window.document.getElementsByName("CheckBox");
    var i = 1;
    while (checks.length >= i)
    {
        checks[i - 1].checked = obj.checked;
        i++;
    }
}

function DeleteCheckBox()
{
    var checks = window.document.getElementsByName("CheckBox");
    var ids = "";
    if (checks.length <= 0)
    {
        alert("请选择要删除的项");
        return;
    }

    for (var i = 0; i < checks.length; i++)
    {
        if (checks[i].checked)
        {
            ids += checks[i].getAttribute("id") + ",";
        }
    }
    if (ids.length <= 0)
    {
        alert("请选择要删除的项");
        return;
    }

    var returnValue = Page.DeleteCheckBox(ids).value;
    //var returnValue = null;
    if (returnValue == "OK")
    {
        alert("删除成功");

        ClearTable();
        GetTotalCounts();
        window["SeachPageHelper"] = new SeachPageHelper_Class("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", 15, window["SeachPageHelper"].WhereOql, loaded);
    }
    else
    {
        alert(returnValue);
    }
}

//共享OnChange(),1.当共享是个人的时候，才显示所属人
function ShareChanged(obj)
{
    if (obj.value == "1")
    {
        $("OwenDiv").style.display = "";
    } else
    {
        $("OwenDiv").style.display = "none";
    }
}

function SetReadonly(objID)
{
    if (objID != null)
    {
        var returnValue = Page.CheckIsOwner(objID).value;
        if (!returnValue)
        {
            var inputEle = document.getElementsByTagName("input");
            for (var i = 0; i < inputEle.length; i++)
            {
                //        inputEle[i].setAttribute("readonly", "true", 0);
                //        inputEle[i].onclick = function setClickFalse() { return false; }
                //        inputEle[i].onfocus = function setFocusFalse() { return false; }
                //        inputEle[i].onblur = function setBlurFalse() { return false; }
                if (inputEle[i].type != "button")
                {
                    inputEle[i].setAttribute("disabled", "disabled");
                }
            }
            // select readonly   
            var selectEle = document.getElementsByTagName("select");
            for (var i = 0; i < selectEle.length; i++)
            {
                selectEle[i].setAttribute("disabled", "disabled");
            }

            // textarea readonly   
            var textareaEle = document.getElementsByTagName("textarea");
            for (var i = 0; i < textareaEle.length; i++)
            {
                if (textareaEle[i].id != "TreatmentRecords")
                {
                    textareaEle[i].setAttribute("disabled", "disabled");
                }
            }
        }
    }
}

//select readonly   
function setSelectReadOnly(obj)
{
    obj.onmouseover = function()
    {
        obj.setCapture();
    }
    obj.onmouseout = function()
    {
        obj.releaseCapture();
    }
    obj.onfocus = function()
    {
        obj.blur();
    }
    
    obj.onbeforeactivate = function()
    {
        return false;
    }
    obj.onclick = function()
    {
        return false;
    }
} 

//创建表格
function CreateTable(Table,RowsLength,CellsLength)
{
    var TableRows = Table.rows;

    if(TableRows.length<=1)
    {
       //构造一个新的Table
       for(var i = 0;i<RowsLength;i++)
       {
            var newRow = Table.insertRow(TableRows.length);
            var Cells = newRow.cells;
            for (var j = 0; j < CellsLength; j++)
            {
                var newCell = TableRows(newRow.rowIndex).insertCell(Cells.length);
                newCell.setAttribute("scope", "col");
            }
       }
    }
}

//取得分页信息
function GetBasePagingInfor(SeachPageHelper,numcenter)
{
    var Paging = $("Paging");
    var html="";
    var currentPage = Number(SeachPageHelper.CurrentPage);
    var totalPage = Number(SeachPageHelper.TotalPage);
    if(currentPage<=0)
    {
        currentpage = 1;
    }
    if(totalPage<=0)
    {
        totalPage = 1;
    }
    if(currentPage>totalPage)
    {
        currentPage = totalPage;
    }
    
    html += "<div class='bb'>共<font color='red'>"+SeachPageHelper.TotalCount+"</font>条记录,每页最多<font color='red'> "+SeachPageHelper.PageSize+"</font> 条，当前 <font color='red'>"+SeachPageHelper.CurrentPage+"</font>/<font color='red'>"+SeachPageHelper.TotalPage+"</font> 页</div>";
    
    html += "<div class='cc'>";
    
    //设置首页
    if(currentPage>1)
    {
        html += "<a class='aGoPageFirstPageEnable' href='javascript:void(0)'  onclick=\"javascript:FirstPage()\"></a>";
    }
    else
    {
       html += "<a disabled='disabled' class='aGoPageFirstPageDisable' href='javascript:void(0)'></a>"; 
    }
    
    //设置上一页
    if(currentPage>1)
    {
        html += "<a  class='aGoPageBeforePageEnable' href='javascript:void(0)' onclick=\"javascript:PreviousPage()\"></a>";
    }
    else
    {
        html += "<a disabled='disabled' class='aGoPageBeforePageDisable' href='javascript:void(0)'></a>";
    }
    
    //设置当前显示的数字
    html += "<span class='NumberStyle'>";
    
    if(totalPage <=numcenter*2)
    {
        for(var i=1;i<=totalPage;i++)
        {
            if(i==currentPage)
            {
                html += "<span >"+currentPage+"</span>";
            }
            else
            {
                html += "<a href='javascript:void(0)' onclick='javascript:SeachPage("+i+")'>"+i+"</a>";
            }
        }
    }
    else
    {
        var begin = currentPage - numcenter;
        var end = currentPage +numcenter;
        
        if(end<numcenter*2)
        {
            end = numcenter *2;
        }
        
        if((totalPage-begin)<numcenter*2)
        {
            begin = totalPage - numcenter*2;
        }
        
        if(begin <=0)
        {
            begin = 1;
        }
        if(end>totalPage)
        {
            end = totalPage;
        }
        
        if(end>begin)
        {
            for( var i= begin ;i<=end;i++)
            {
                if(i==currentPage)
                {
                    html += "<span >"+currentPage+"</span>";
                }
                else
                {
                    html += "<a href='javascript:void(0)' onclick='javascript:SeachPage("+i+")'>"+i+"</a>";
                }
            }
        }
        
    } 
    html += "</span>";
    //设置当前显示的数字结束
    
    //设置下一页
    if(currentPage<totalPage)
    {                 
        html += "<a style='cursor:pointer' href='javascript:void(0)' onclick=\"javascript:NextPage()\"  class='aGoPageNextPageEnable'></a>";
    }
    else
    {
        html += "<a style='cursor:pointer' disabled='disabled' href='javascript:void(0)'  class='aGoPageNextPageDisable'></a>";
    }
    
    //设置最后一页
    if(currentPage<totalPage)
    {
        html += "<a style='cursor:pointer' href='javascript:void(0)' onclick=\"javascript:LastPage()\"  class='aGoPageLastPageEnable'></a>";
    }
    else
    {
        html += "<a style='cursor:pointer' disabled='disabled' href='javascript:void(0)'  class='aGoPageLastPageDisable'></a>";
    }

    //设置Select
    html += "<span class='CooL'>&nbsp;&nbsp;&nbsp;跳转至&nbsp;";
    html += "<select class='SelectT' onchange=\"javascript:SeachPage(this.value)\">";
    for(var i= 1; i<=totalPage;i++)
    {
        if(i == currentPage)
        {
            html += "<option value="+i+" selected='selected'>第"+i+"页</option>";
        }
        else
        {
            html += "<option value="+i+" >第"+i+"页</option>";
        }
    }
    html += " </select>";
    html += "</span>";
    
    html += "</div>";
    
    Paging.innerHTML = html;
}
//取得分页信息
function GetPagingInfo(SeachPageHelper)
{
    GetBasePagingInfor(SeachPageHelper,4);
}

//没有记录的样式
function GetNoPaing()
{
    $("Paging").innerHTML ="<div class='bb'>共有<font color='red'>0</font>条记录</div>";;
}
